Merge branch 'bw/submodule-has-commits-update'
[gitweb.git] / diff-no-index.c
index 03daadb25af835a695c7d0baf466b0e1f82b58c4..79229382b06cefc98aa8926065f0fb999ad1da2e 100644 (file)
@@ -65,8 +65,7 @@ static int populate_from_stdin(struct diff_filespec *s)
        size_t size = 0;
 
        if (strbuf_read(&buf, 0, 0) < 0)
-               return error("error while reading from stdin %s",
-                                    strerror(errno));
+               return error_errno("error while reading from stdin");
 
        s->should_munmap = 0;
        s->data = strbuf_detach(&buf, &size);
@@ -186,10 +185,8 @@ static int queue_diff(struct diff_options *o,
                struct diff_filespec *d1, *d2;
 
                if (DIFF_OPT_TST(o, REVERSE_DIFF)) {
-                       unsigned tmp;
-                       const char *tmp_c;
-                       tmp = mode1; mode1 = mode2; mode2 = tmp;
-                       tmp_c = name1; name1 = name2; name2 = tmp_c;
+                       SWAP(mode1, mode2);
+                       SWAP(name1, name2);
                }
 
                d1 = noindex_filespec(name1, mode1);
@@ -239,7 +236,7 @@ static void fixup_paths(const char **path, struct strbuf *replacement)
 void diff_no_index(struct rev_info *revs,
                   int argc, const char **argv)
 {
-       int i, prefixlen;
+       int i;
        const char *paths[2];
        struct strbuf replacement = STRBUF_INIT;
        const char *prefix = revs->prefix;
@@ -260,7 +257,6 @@ void diff_no_index(struct rev_info *revs,
                }
        }
 
-       prefixlen = prefix ? strlen(prefix) : 0;
        for (i = 0; i < 2; i++) {
                const char *p = argv[argc - 2 + i];
                if (!strcmp(p, "-"))
@@ -269,8 +265,8 @@ void diff_no_index(struct rev_info *revs,
                         * path that is "-", spell it as "./-".
                         */
                        p = file_from_standard_input;
-               else if (prefixlen)
-                       p = xstrdup(prefix_filename(prefix, prefixlen, p));
+               else if (prefix)
+                       p = prefix_filename(prefix, p);
                paths[i] = p;
        }
 
@@ -282,6 +278,9 @@ void diff_no_index(struct rev_info *revs,
 
        DIFF_OPT_SET(&revs->diffopt, NO_INDEX);
 
+       DIFF_OPT_SET(&revs->diffopt, RELATIVE_NAME);
+       revs->diffopt.prefix = prefix;
+
        revs->max_count = -2;
        diff_setup_done(&revs->diffopt);