Merge branch 'sg/doc-pretty-formats' into maint
[gitweb.git] / builtin / diff.c
index 8b276ae5752c799f209a29acd583c4b67a18d7c8..5e7c6428c91203fa1f3fb0c7790364987a623fc0 100644 (file)
 static const char builtin_diff_usage[] =
 "git diff [<options>] [<commit> [<commit>]] [--] [<path>...]";
 
+static const char *blob_path(struct object_array_entry *entry)
+{
+       return entry->path ? entry->path : entry->name;
+}
+
 static void stuff_change(struct diff_options *opt,
                         unsigned old_mode, unsigned new_mode,
                         const struct object_id *old_oid,
                         const struct object_id *new_oid,
                         int old_oid_valid,
                         int new_oid_valid,
-                        const char *old_name,
-                        const char *new_name)
+                        const char *old_path,
+                        const char *new_path)
 {
        struct diff_filespec *one, *two;
 
@@ -41,16 +46,16 @@ static void stuff_change(struct diff_options *opt,
        if (DIFF_OPT_TST(opt, REVERSE_DIFF)) {
                SWAP(old_mode, new_mode);
                SWAP(old_oid, new_oid);
-               SWAP(old_name, new_name);
+               SWAP(old_path, new_path);
        }
 
        if (opt->prefix &&
-           (strncmp(old_name, opt->prefix, opt->prefix_length) ||
-            strncmp(new_name, opt->prefix, opt->prefix_length)))
+           (strncmp(old_path, opt->prefix, opt->prefix_length) ||
+            strncmp(new_path, opt->prefix, opt->prefix_length)))
                return;
 
-       one = alloc_filespec(old_name);
-       two = alloc_filespec(new_name);
+       one = alloc_filespec(old_path);
+       two = alloc_filespec(new_path);
        fill_filespec(one, old_oid->hash, old_oid_valid, old_mode);
        fill_filespec(two, new_oid->hash, new_oid_valid, new_mode);
 
@@ -85,7 +90,8 @@ static int builtin_diff_b_f(struct rev_info *revs,
                     blob[0]->mode, canon_mode(st.st_mode),
                     &blob[0]->item->oid, &null_oid,
                     1, 0,
-                    path, path);
+                    blob[0]->path ? blob[0]->path : path,
+                    path);
        diffcore_std(&revs->diffopt);
        diff_flush(&revs->diffopt);
        return 0;
@@ -110,7 +116,7 @@ static int builtin_diff_blobs(struct rev_info *revs,
                     blob[0]->mode, blob[1]->mode,
                     &blob[0]->item->oid, &blob[1]->item->oid,
                     1, 1,
-                    blob[0]->name, blob[1]->name);
+                    blob_path(blob[0]), blob_path(blob[1]));
        diffcore_std(&revs->diffopt);
        diff_flush(&revs->diffopt);
        return 0;