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

[PATCH 5/8] diff --no-index: support /dev/null as filename

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Feb 25, 2007, 22:36 UTC
Message-ID
<Pine.LNX.4.63.0702252336190.22628@wbgn013.biozentrum.uni-wuerzburg.de>

This allows us to create "new file" and "delete file" patches. It also cleans up the code.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 diff-lib.c |   34 +++++++++++++++++-----------------
 1 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/diff-lib.c b/diff-lib.c
index 089c94c..43907c2 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -30,28 +30,28 @@ static int read_directory(const char *path, struct path_list *list)
 	return 0;
 }
 
+static int get_mode(const char *path, int *mode)
+{
+	struct stat st;
+
+	if (!path || !strcmp(path, "/dev/null"))
+		*mode = 0;
+	else if (!strcmp(path, "-"))
+		*mode = 0644;
+	else if (stat(path, &st))
+		return error("Could not access '%s'", path);
+	else
+		*mode = st.st_mode;
+	return 0;
+}
+
 static int queue_diff(struct diff_options *o,
 		const char *name1, const char *name2)
 {
-	struct stat st;
 	int mode1 = 0, mode2 = 0;
 
-	if (name1) {
-		if (!strcmp(name1, "-"))
-			mode1 = 0644;
-		else if (stat(name1, &st))
-			return error("Could not access '%s'", name1);
-		else
-			mode1 = st.st_mode;
-	}
-	if (name2) {
-		if (!strcmp(name2, "-"))
-			mode2 = 0644;
-		else if (stat(name2, &st))
-			return error("Could not access '%s'", name2);
-		else
-			mode2 = st.st_mode;
-	}
+	if (get_mode(name1, &mode1) || get_mode(name2, &mode2))
+		return -1;
 
 	if (mode1 && mode2 && S_ISDIR(mode1) != S_ISDIR(mode2))
 		return error("file/directory conflict: %s, %s", name1, name2);
-- 
1.5.0.1.788.g8ca52
Message 1 of 1 in “diff --no-index: support /dev/null as filename”
  1. 5/8 diff --no-index: support /dev/null as filenameJohannes Schindelin, Feb 25, 2007

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.