{"thread":{"id":"6961","subject":"[PATCH 5/8] diff --no-index: support /dev/null as filename","startedAt":"2007-02-25T22:36:31Z","lastAt":"2007-02-25T22:36:31Z","messageCount":1,"participants":["Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":8},"messages":[{"id":"35467","messageId":"Pine.LNX.4.63.0702252336190.22628@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"6961","inReplyTo":null,"subject":"[PATCH 5/8] diff --no-index: support /dev/null as filename","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-02-25T22:36:31Z","receivedAt":"2007-02-25T22:36:31Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nThis allows us to create \"new file\" and \"delete file\" patches.\nIt also cleans up the code.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n diff-lib.c |   34 +++++++++++++++++-----------------\n 1 files changed, 17 insertions(+), 17 deletions(-)\n\ndiff --git a/diff-lib.c b/diff-lib.c\nindex 089c94c..43907c2 100644\n--- a/diff-lib.c\n+++ b/diff-lib.c\n@@ -30,28 +30,28 @@ static int read_directory(const char *path, struct path_list *list)\n \treturn 0;\n }\n \n+static int get_mode(const char *path, int *mode)\n+{\n+\tstruct stat st;\n+\n+\tif (!path || !strcmp(path, \"/dev/null\"))\n+\t\t*mode = 0;\n+\telse if (!strcmp(path, \"-\"))\n+\t\t*mode = 0644;\n+\telse if (stat(path, &st))\n+\t\treturn error(\"Could not access '%s'\", path);\n+\telse\n+\t\t*mode = st.st_mode;\n+\treturn 0;\n+}\n+\n static int queue_diff(struct diff_options *o,\n \t\tconst char *name1, const char *name2)\n {\n-\tstruct stat st;\n \tint mode1 = 0, mode2 = 0;\n \n-\tif (name1) {\n-\t\tif (!strcmp(name1, \"-\"))\n-\t\t\tmode1 = 0644;\n-\t\telse if (stat(name1, &st))\n-\t\t\treturn error(\"Could not access '%s'\", name1);\n-\t\telse\n-\t\t\tmode1 = st.st_mode;\n-\t}\n-\tif (name2) {\n-\t\tif (!strcmp(name2, \"-\"))\n-\t\t\tmode2 = 0644;\n-\t\telse if (stat(name2, &st))\n-\t\t\treturn error(\"Could not access '%s'\", name2);\n-\t\telse\n-\t\t\tmode2 = st.st_mode;\n-\t}\n+\tif (get_mode(name1, &mode1) || get_mode(name2, &mode2))\n+\t\treturn -1;\n \n \tif (mode1 && mode2 && S_ISDIR(mode1) != S_ISDIR(mode2))\n \t\treturn error(\"file/directory conflict: %s, %s\", name1, name2);\n-- \n1.5.0.1.788.g8ca52\n"}]}