From: Junio C Hamano <junkio@cox.net>
To: Linus Torvalds <torvalds@osdl.org>
Cc: git@vger.kernel.org
Subject: [PATCH] Simplify "reverse-diff" logic in the diff core.
Date: Fri, 20 May 2005 09:54:07 -0700 [thread overview]
Message-ID: <7vfywhu9cg.fsf_-_@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: <Pine.LNX.4.58.0505200806150.2206@ppc970.osdl.org> (Linus Torvalds's message of "Fri, 20 May 2005 08:20:21 -0700 (PDT)")
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>
---
diff.c | 38 +++++++++++++++-----------------------
1 files changed, 15 insertions(+), 23 deletions(-)
diff --git a/diff.c b/diff.c
--- a/diff.c
+++ b/diff.c
@@ -350,15 +350,6 @@ static void run_external_diff(const char
int status;
static int atexit_asked = 0;
- if (reverse_diff) {
- struct diff_spec *tmp_spec;
- tmp_spec = one; one = two; two = tmp_spec;
- if (other) {
- const char *tmp;
- tmp = name; name = other; other = tmp;
- }
- }
-
if (!matches_pathspec(name) && (!other || !matches_pathspec(other)))
return;
@@ -765,11 +756,12 @@ void diff_addremove(int addremove, unsig
char concatpath[PATH_MAX];
struct diff_spec spec[2], *one, *two;
+ if (reverse_diff)
+ addremove = (addremove == '+' ? '-' : '+');
+
if (0 <= diff_raw_output) {
if (!path)
path = "";
- if (reverse_diff)
- addremove = (addremove == '+' ? '-' : '+');
printf("%c%06o %s %s %s%s%c",
addremove,
mode,
@@ -806,24 +798,24 @@ void diff_change(unsigned old_mode, unsi
char concatpath[PATH_MAX];
struct diff_spec spec[2];
+ if (reverse_diff) {
+ unsigned tmp;
+ const unsigned char *tmp_c;
+ tmp = old_mode; old_mode = new_mode; new_mode = tmp;
+ tmp_c = old_sha1; old_sha1 = new_sha1; new_sha1 = tmp_c;
+ }
+
if (0 <= diff_raw_output) {
char old_hex[41];
strcpy(old_hex, sha1_to_hex(old_sha1));
if (!path)
path = "";
- if (reverse_diff)
- printf("*%06o->%06o %s %s->%s %s%s%c",
- new_mode, old_mode,
- git_object_type(new_mode),
- sha1_to_hex(new_sha1), old_hex,
- base, path, diff_raw_output);
- else
- printf("*%06o->%06o %s %s->%s %s%s%c",
- old_mode, new_mode,
- git_object_type(new_mode),
- old_hex, sha1_to_hex(new_sha1),
- base, path, diff_raw_output);
+ printf("*%06o->%06o %s %s->%s %s%s%c",
+ old_mode, new_mode,
+ git_object_type(new_mode),
+ old_hex, sha1_to_hex(new_sha1),
+ base, path, diff_raw_output);
return;
}
if (S_ISDIR(new_mode))
------------------------------------------------
prev parent reply other threads:[~2005-05-20 16:54 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-05-20 14:56 "git-diff-tree -R A B == git-diff-tree B A"? Junio C Hamano
2005-05-20 15:20 ` Linus Torvalds
2005-05-20 15:29 ` Junio C Hamano
2005-05-20 15:32 ` Junio C Hamano
2005-05-20 15:53 ` Linus Torvalds
2005-05-20 15:57 ` Linus Torvalds
2005-05-20 16:19 ` Linus Torvalds
2005-05-20 16:48 ` Junio C Hamano
2005-05-20 16:54 ` Junio C Hamano [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7vfywhu9cg.fsf_-_@assigned-by-dhcp.cox.net \
--to=junkio@cox.net \
--cc=git@vger.kernel.org \
--cc=torvalds@osdl.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.