git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 7/6] Leftover bits.

From
Junio C Hamano <junkio@cox.net>
Date
Apr 27, 2005, 08:17 UTC
Message-ID
<7v4qdsiqgl.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<7vekcwkagr.fsf@assigned-by-dhcp.cox.net>

This is a minor cleanup to be applied on top of the last 6 patches (the 6th is an alternate so the count actually is five).

It makes sure that external diff interface functions are called even when diff-tree detects directory changes. Since it is not clear what to pass GIT_EXTERNAL_DIFF when we do see directory changes, such calls are still currently dropped at the diff.c interface function level, but whatever we will decide to do later, the interface users should be cleaned up first anyway, and that is primarily what this patch is about.

It also adds code to unlink temporary files used to call the external diff command upon SIGNIT.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---

diff-tree.c | 9 +++------ diff.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-)

# - 04/26 23:58 Mark the last of '-p' (patch) work. # + working tree --- k/diff-tree.c +++ l/diff-tree.c

@@ -82,8 +82,7 @@ static void show_file(const char *prefix
 	}
 
 	if (generate_patch) {
-		if (!S_ISDIR(mode))
-			diff_addremove(prefix[0], mode, sha1, base, path);
+		diff_addremove(prefix[0], mode, sha1, base, path);
 	}
 	else
 		printf("%s%06o\t%s\t%s\t%s%s%c", prefix, mode,
@@ -135,10 +134,8 @@ static int compare_tree_entry(void *tree
 		return retval;
 	}
 
-	if (generate_patch) {
-		if (!S_ISDIR(mode1))
-			diff_change(mode1, mode2, sha1, sha2, base, path1);
-	}
+	if (generate_patch)
+		diff_change(mode1, mode2, sha1, sha2, base, path1);
 	else {
 		strcpy(old_sha1_hex, sha1_to_hex(sha1));
 		printf("*%06o->%06o\t%s\t%s->%s\t%s%s%c", mode1, mode2,
--- k/diff.c
+++ l/diff.c
@@ -127,6 +127,7 @@ static void prepare_temp_file(const char
 
 	if (one->sha1_valid &&
 	    !memcmp(one->u.sha1, null_sha1, sizeof(null_sha1))) {
+		/* "It is valid but please go to the filesystem." */
 		one->sha1_valid = 0;
 		one->u.name = name;
 	}
@@ -180,6 +181,11 @@ static void remove_tempfile(void)
 		}
 }
 
+static void remove_tempfile_on_signal(int signo)
+{
+	remove_tempfile();
+}
+
 /* An external diff command takes:
  *
  * diff-cmd name infile1 infile1-sha1 infile1-mode \
@@ -202,6 +208,7 @@ void run_external_diff(const char *name,
 		     temp[1].name == temp[1].tmp_path)) {
 			atexit_asked = 1;
 			atexit(remove_tempfile);
+			signal(SIGINT, remove_tempfile_on_signal);
 		}
 	}
 
@@ -211,6 +218,7 @@ void run_external_diff(const char *name,
 		die("unable to fork");
 	if (!pid) {
 		const char *pgm = external_diff();
+
 		if (pgm) {
 			if (one && two)
 				execlp(pgm, pgm,
@@ -243,6 +251,9 @@ void diff_addremove(int addremove, unsig
 	char concatpath[PATH_MAX];
 	struct diff_spec spec[2], *one, *two;
 
+	if (S_ISDIR(mode))
+		return;
+
 	memcpy(spec[0].u.sha1, sha1, 20);
 	spec[0].mode = mode;
 	spec[0].sha1_valid = spec[0].file_valid = 1;
@@ -269,6 +280,9 @@ void diff_change(unsigned old_mode, unsi
 	char concatpath[PATH_MAX];
 	struct diff_spec spec[2];
 
+	if (S_ISDIR(old_mode) || S_ISDIR(new_mode))
+		return;
+
 	memcpy(spec[0].u.sha1, old_sha1, 20);
 	spec[0].mode = old_mode;
 	memcpy(spec[1].u.sha1, new_sha1, 20);
Previous: Junio C HamanoNext: Linus Torvalds
Message 8 of 9 in “External diff interface for diff-cache and friends.”
  1. 0/6 External diff interface for diff-cache and friends.Junio C Hamano, Apr 27, 2005
  2. 1/6 Reworked external diff interface.Junio C Hamano, Apr 27, 2005
  3. 2/6 Reactivate show-diff patch generationJunio C Hamano, Apr 27, 2005
  4. 3/6 Add -p (patch) to diff-tree.Junio C Hamano, Apr 27, 2005
  5. 4/6 Add -p (patch) to diff-cache.Junio C Hamano, Apr 27, 2005
  6. 5/6 Teach diff-tree-helper to handle unmerged paths.Junio C Hamano, Apr 27, 2005
  7. 6/6 Alternative patch to diff-cache.cJunio C Hamano, Apr 27, 2005
  8. 7/6 Leftover bits.Junio C Hamano, Apr 27, 2005
  9. Linus TorvaldsApr 27, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.