aboutsummaryrefslogtreecommitdiff
path: root/diff-lib.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2007-03-10 23:26:33 -0800
committerJunio C Hamano <junkio@cox.net>2007-03-10 23:26:33 -0800
commitcf6981d4932007555689052cbc255b911674b01c (patch)
tree780cfe523171d98ecded8e4d8509db507707e1f3 /diff-lib.c
parent8509fed75d576023f5f2db8542fad102fcc62d4d (diff)
parent5bd74506cd30e897d1493639b7438c6cc80dea8e (diff)
downloadgit-cf6981d4932007555689052cbc255b911674b01c.tar.gz
git-cf6981d4932007555689052cbc255b911674b01c.tar.xz
Merge branch 'js/diff-ni'
* js/diff-ni: Get rid of the dependency to GNU diff in the tests diff --no-index: support /dev/null as filename diff-ni: fix the diff with standard input diff: support reading a file from stdin via "-"
Diffstat (limited to 'diff-lib.c')
-rw-r--r--diff-lib.c42
1 files changed, 27 insertions, 15 deletions
diff --git a/diff-lib.c b/diff-lib.c
index 778cf5824..6abb98153 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -30,22 +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 = ntohl(create_ce_mode(0666));
+ 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 (stat(name1, &st))
- return error("Could not access '%s'", name1);
- mode1 = st.st_mode;
- }
- if (name2) {
- if (stat(name2, &st))
- return error("Could not access '%s'", name2);
- 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);
@@ -224,7 +230,7 @@ int setup_diff_no_index(struct rev_info *revs,
{
int i;
for (i = 1; i < argc; i++)
- if (argv[i][0] != '-')
+ if (argv[i][0] != '-' || argv[i][1] == '\0')
break;
else if (!strcmp(argv[i], "--")) {
i++;
@@ -254,9 +260,15 @@ int setup_diff_no_index(struct rev_info *revs,
revs->diffopt.paths = xcalloc(2, sizeof(char*));
for (i = 0; i < 2; i++) {
- const char *p;
- p = prefix_filename(prefix, len, argv[argc - 2 + i]);
- revs->diffopt.paths[i] = xstrdup(p);
+ const char *p = argv[argc - 2 + i];
+ /*
+ * stdin should be spelled as '-'; if you have
+ * path that is '-', spell it as ./-.
+ */
+ p = (strcmp(p, "-")
+ ? xstrdup(prefix_filename(prefix, len, p))
+ : p);
+ revs->diffopt.paths[i] = p;
}
}
else