Skip to content

Commit 7ca4525

Browse files
Junio C HamanoLinus Torvalds
authored andcommitted
[PATCH] Simplify "reverse-diff" logic in the diff core.
Instead of swapping the arguments just before output, this patch makes the swapping happen on the input side of the diff core, when "reverse-diff" is in effect. This greatly simplifies the logic, but more importantly it is necessary for upcoming "copy detection" work. Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 4117469 commit 7ca4525

File tree

1 file changed

+15
-23
lines changed

1 file changed

+15
-23
lines changed

diff.c

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -350,15 +350,6 @@ static void run_external_diff(const char *name,
350350
int status;
351351
static int atexit_asked = 0;
352352

353-
if (reverse_diff) {
354-
struct diff_spec *tmp_spec;
355-
tmp_spec = one; one = two; two = tmp_spec;
356-
if (other) {
357-
const char *tmp;
358-
tmp = name; name = other; other = tmp;
359-
}
360-
}
361-
362353
if (!matches_pathspec(name) && (!other || !matches_pathspec(other)))
363354
return;
364355

@@ -765,11 +756,12 @@ void diff_addremove(int addremove, unsigned mode,
765756
char concatpath[PATH_MAX];
766757
struct diff_spec spec[2], *one, *two;
767758

759+
if (reverse_diff)
760+
addremove = (addremove == '+' ? '-' : '+');
761+
768762
if (0 <= diff_raw_output) {
769763
if (!path)
770764
path = "";
771-
if (reverse_diff)
772-
addremove = (addremove == '+' ? '-' : '+');
773765
printf("%c%06o %s %s %s%s%c",
774766
addremove,
775767
mode,
@@ -806,24 +798,24 @@ void diff_change(unsigned old_mode, unsigned new_mode,
806798
char concatpath[PATH_MAX];
807799
struct diff_spec spec[2];
808800

801+
if (reverse_diff) {
802+
unsigned tmp;
803+
const unsigned char *tmp_c;
804+
tmp = old_mode; old_mode = new_mode; new_mode = tmp;
805+
tmp_c = old_sha1; old_sha1 = new_sha1; new_sha1 = tmp_c;
806+
}
807+
809808
if (0 <= diff_raw_output) {
810809
char old_hex[41];
811810
strcpy(old_hex, sha1_to_hex(old_sha1));
812811

813812
if (!path)
814813
path = "";
815-
if (reverse_diff)
816-
printf("*%06o->%06o %s %s->%s %s%s%c",
817-
new_mode, old_mode,
818-
git_object_type(new_mode),
819-
sha1_to_hex(new_sha1), old_hex,
820-
base, path, diff_raw_output);
821-
else
822-
printf("*%06o->%06o %s %s->%s %s%s%c",
823-
old_mode, new_mode,
824-
git_object_type(new_mode),
825-
old_hex, sha1_to_hex(new_sha1),
826-
base, path, diff_raw_output);
814+
printf("*%06o->%06o %s %s->%s %s%s%c",
815+
old_mode, new_mode,
816+
git_object_type(new_mode),
817+
old_hex, sha1_to_hex(new_sha1),
818+
base, path, diff_raw_output);
827819
return;
828820
}
829821
if (S_ISDIR(new_mode))

0 commit comments

Comments
 (0)