git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] diff: remove dead code that flips arguments order
@ 2011-03-23 21:36 Junio C Hamano
  2011-03-23 21:45 ` [PATCH] warn use of "git diff A..B" Junio C Hamano
  0 siblings, 1 reply; 10+ messages in thread
From: Junio C Hamano @ 2011-03-23 21:36 UTC (permalink / raw)
  To: git; +Cc: Linus Torvalds

In the olden days, "git cmd A..B" used to push ^A and then B into the list
of parsed revisions. The output from "git rev-list A..B" still does this,
and shows "B" first and then "^A" for backward compatibility.

The command line parser for "git diff A..B" was written originally to take
this swappage into account; when it internally sees an uninteresting
commit as its second input argument, it swapped the arguments to make it
the origin of the comparison, and the other one the destination.

These days, there is no need for this swappage, as the internal machinery
feeds ^A and then B to builtin_diff_tree().  Remove the dead code.

The funny thing is, I think this was a dead code from day one when it
was first written 6505602 (built-in diff., 2006-04-28); the author of
that patch must have known the implementation of the scripted version
that needed to deal with the swapped output from rev-parse too deeply
and didn't realize that the gotcha the dead code attempts to protect
him from didn't even apply to this codepath.

This change _will_ regress if somebody is insane enough to manually call
"git diff B ^A", but that is simply too insane for me to care.

There is exactly the same tree swapping code in diff-tree; that is not to
be changed not to break "git diff-tree B ^A" issued by Porcelain scripts,
but reword the comment to explain why we swap trees a bit better.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---

 builtin/diff-tree.c |    4 ++--
 builtin/diff.c      |   13 +------------
 2 files changed, 3 insertions(+), 14 deletions(-)

diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c
index 0d2a3e9..c843546 100644
--- a/builtin/diff-tree.c
+++ b/builtin/diff-tree.c
@@ -133,8 +133,8 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
 	}
 
 	/*
-	 * NOTE! We expect "a ^b" to be equal to "a..b", so we
-	 * reverse the order of the objects if the second one
+	 * NOTE! We expect "b ^a" to have come from "rev-parse a..b",
+	 * so we reverse the order of the objects if the second one
 	 * is marked UNINTERESTING.
 	 */
 	nr_sha1 = opt->pending.nr;
diff --git a/builtin/diff.c b/builtin/diff.c
index 4c9deb2..86614d4 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -146,20 +146,9 @@ static int builtin_diff_tree(struct rev_info *revs,
 			     int argc, const char **argv,
 			     struct object_array_entry *ent)
 {
-	const unsigned char *(sha1[2]);
-	int swap = 0;
-
 	if (argc > 1)
 		usage(builtin_diff_usage);
-
-	/* We saw two trees, ent[0] and ent[1].
-	 * if ent[1] is uninteresting, they are swapped
-	 */
-	if (ent[1].item->flags & UNINTERESTING)
-		swap = 1;
-	sha1[swap] = ent[0].item->sha1;
-	sha1[1-swap] = ent[1].item->sha1;
-	diff_tree_sha1(sha1[0], sha1[1], "", &revs->diffopt);
+	diff_tree_sha1(ent[0].item->sha1, ent[1].item->sha1, "", &revs->diffopt);
 	log_tree_diff_flush(revs);
 	return 0;
 }

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2011-03-28 16:54 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-23 21:36 [PATCH] diff: remove dead code that flips arguments order Junio C Hamano
2011-03-23 21:45 ` [PATCH] warn use of "git diff A..B" Junio C Hamano
2011-03-24 15:44   ` Jakub Narebski
2011-03-25  8:27     ` Johannes Sixt
2011-03-24 18:11   ` Jay Soffian
2011-03-24 18:16     ` Jay Soffian
2011-03-24 18:33     ` Junio C Hamano
2011-03-25  9:06   ` Ævar Arnfjörð Bjarmason
2011-03-27 20:03   ` Alex Riesen
2011-03-28 16:53     ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).