git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexandre Julliard <julliard@winehq.org>
To: git@vger.kernel.org
Subject: [PATCH] diff.c: Reuse the pprint_rename function for diff --summary output.
Date: Sat, 10 Feb 2007 15:36:47 +0100	[thread overview]
Message-ID: <87mz3mdqps.fsf@wine.dyndns.org> (raw)

This avoids some code duplication, and yields more readable results
for directory renames.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
---
 diff.c |   31 ++++---------------------------
 1 files changed, 4 insertions(+), 27 deletions(-)

diff --git a/diff.c b/diff.c
index ad476f7..4c642d7 100644
--- a/diff.c
+++ b/diff.c
@@ -2430,34 +2430,11 @@ static void show_mode_change(struct diff_filepair *p, int show_name)
 
 static void show_rename_copy(const char *renamecopy, struct diff_filepair *p)
 {
-	const char *old, *new;
+	char *names = pprint_rename(p->one->path, p->two->path);
 
-	/* Find common prefix */
-	old = p->one->path;
-	new = p->two->path;
-	while (1) {
-		const char *slash_old, *slash_new;
-		slash_old = strchr(old, '/');
-		slash_new = strchr(new, '/');
-		if (!slash_old ||
-		    !slash_new ||
-		    slash_old - old != slash_new - new ||
-		    memcmp(old, new, slash_new - new))
-			break;
-		old = slash_old + 1;
-		new = slash_new + 1;
-	}
-	/* p->one->path thru old is the common prefix, and old and new
-	 * through the end of names are renames
-	 */
-	if (old != p->one->path)
-		printf(" %s %.*s{%s => %s} (%d%%)\n", renamecopy,
-		       (int)(old - p->one->path), p->one->path,
-		       old, new, (int)(0.5 + p->score * 100.0/MAX_SCORE));
-	else
-		printf(" %s %s => %s (%d%%)\n", renamecopy,
-		       p->one->path, p->two->path,
-		       (int)(0.5 + p->score * 100.0/MAX_SCORE));
+	printf(" %s %s (%d%%)\n", renamecopy, names,
+	       (int)(0.5 + p->score * 100.0/MAX_SCORE));
+	free(names);
 	show_mode_change(p, 0);
 }
 
-- 
1.5.0.rc4.31.g6289

-- 
Alexandre Julliard
julliard@winehq.org

                 reply	other threads:[~2007-02-10 14:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=87mz3mdqps.fsf@wine.dyndns.org \
    --to=julliard@winehq.org \
    --cc=git@vger.kernel.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 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).