git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] diff: Fix rename pretty-print when suffix and prefix overlap
@ 2013-02-23 16:48 Antoine Pelisse
  2013-02-24  9:15 ` Junio C Hamano
  2013-02-26 20:47 ` [PATCH] diff: prevent pprint_rename from underrunning input Thomas Rast
  0 siblings, 2 replies; 16+ messages in thread
From: Antoine Pelisse @ 2013-02-23 16:48 UTC (permalink / raw)
  To: git; +Cc: Antoine Pelisse

When considering a rename for two files that have a suffix and a prefix
that can overlap, a confusing line is shown. As an example, renaming
"a/b/b/c" to "a/b/c" shows "a/b/{ => }/b/c".

Currently, what we do is calculate the common prefix ("a/b/"), and the
common suffix ("/b/c"), but the same "/b/" is actually counted both in
prefix and suffix. Then when calculating the size of the non-common part,
we end-up with a negative value which is reset to 0, thus the "{ => }".

Do not allow the common suffix to overlap the common prefix and stop
when reaching a "/" that would be in both.

Signed-off-by: Antoine Pelisse <apelisse@gmail.com>
---
 diff.c |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/diff.c b/diff.c
index 156fec4..80f4752 100644
--- a/diff.c
+++ b/diff.c
@@ -1290,7 +1290,16 @@ static char *pprint_rename(const char *a, const char *b)
 	old = a + len_a;
 	new = b + len_b;
 	sfx_length = 0;
-	while (a <= old && b <= new && *old == *new) {
+	/*
+	 * Note:
+	 * if pfx_length is 0, old/new will never reach a - 1 because it
+	 * would mean the whole string is common suffix. But then, the
+	 * whole string would also be a common prefix, and we would not
+	 * have pfx_length equals 0.
+	 */
+	while (a + pfx_length - 1 <= old &&
+	       b + pfx_length - 1 <= new &&
+	       *old == *new) {
 		if (*old == '/')
 			sfx_length = len_a - (old - a);
 		old--;
--
1.7.9.5

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

end of thread, other threads:[~2013-03-06 22:04 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-23 16:48 [PATCH] diff: Fix rename pretty-print when suffix and prefix overlap Antoine Pelisse
2013-02-24  9:15 ` Junio C Hamano
2013-02-25 19:50   ` Antoine Pelisse
2013-02-25 22:36     ` Philip Oakley
2013-02-25 22:41       ` Antoine Pelisse
2013-02-28 21:55     ` Antoine Pelisse
2013-02-28 22:14       ` Thomas Rast
2013-02-28 22:22         ` Antoine Pelisse
2013-02-28 22:29       ` Junio C Hamano
2013-03-02 14:38         ` [PATCH] tests: make sure rename pretty print works Antoine Pelisse
2013-03-03  6:50           ` Junio C Hamano
2013-03-06 21:36           ` [PATCH v2] " Antoine Pelisse
2013-03-06 22:03             ` Junio C Hamano
2013-02-26 20:47 ` [PATCH] diff: prevent pprint_rename from underrunning input Thomas Rast
2013-02-26 21:44   ` Junio C Hamano
2013-02-27 13:27     ` Antoine Pelisse

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).