From: Jakub Narebski <jnareb@gmail.com>
To: git@vger.kernel.org
Subject: [PATCH] diff: Make numstat machine friendly also for renames (and copies)
Date: Mon, 10 Dec 2007 23:32:51 +0100 [thread overview]
Message-ID: <200712102332.53114.jnareb@gmail.com> (raw)
"git diff --numstat" used the same format as "git diff --stat" for
renamed (and copied) files, except that filenames were not shortened
when they didn't fit in the column width. This format is suitable for
human consumption, but it cannot be unambiguously parsed.
Instead of that always use final file name ("to" name) for numstat.
It is possible to find name before rename when name after is known.
This required to use pprint_rename (pretty print rename) during output
(in the show_stats function) and not during parsing (in diffstat_add
function).
Adding from_name field to struct diffstat_t makes is_renamed bitfield
redundant; nevertheless for the sake of clarity, readability and
making this patch minimal (and because it would not reduce memory
footprint) it was not removed, and its used not replaced by checking
from_name field.
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
This would be useful for gitweb, later.
I hope I have made it in time before feature freeze...
diff.c | 15 ++++++++++++---
1 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/diff.c b/diff.c
index f780e3e..38b9367 100644
--- a/diff.c
+++ b/diff.c
@@ -735,6 +735,7 @@ struct diffstat_t {
int alloc;
struct diffstat_file {
char *name;
+ char *from_name;
unsigned is_unmerged:1;
unsigned is_binary:1;
unsigned is_renamed:1;
@@ -755,11 +756,14 @@ static struct diffstat_file *diffstat_add(struct diffstat_t *diffstat,
}
diffstat->files[diffstat->nr++] = x;
if (name_b) {
- x->name = pprint_rename(name_a, name_b);
+ x->from_name = xstrdup(name_a);
+ x->name = xstrdup(name_b);
x->is_renamed = 1;
}
- else
+ else {
+ x->from_name = NULL;
x->name = xstrdup(name_a);
+ }
return x;
}
@@ -837,7 +841,7 @@ static void show_stats(struct diffstat_t* data, struct diff_options *options)
struct diffstat_file *file = data->files[i];
int change = file->added + file->deleted;
- if (!file->is_renamed) { /* renames are already quoted by pprint_rename */
+ if (!file->is_renamed) { /* renames will be quoted by pprint_rename */
struct strbuf buf;
strbuf_init(&buf, 0);
if (quote_c_style(file->name, &buf, NULL, 0)) {
@@ -846,6 +850,11 @@ static void show_stats(struct diffstat_t* data, struct diff_options *options)
} else {
strbuf_release(&buf);
}
+ } else {
+ char *qname = pprint_rename(file->from_name, file->name);
+ free(file->name);
+ free(file->from_name);
+ file->name = qname;
}
len = strlen(file->name);
--
1.5.3.7
next reply other threads:[~2007-12-10 22:33 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-10 22:32 Jakub Narebski [this message]
2007-12-10 22:55 ` [PATCH (amend)] diff: Make numstat machine friendly also for renames (and copies) Jakub Narebski
2007-12-11 1:06 ` Junio C Hamano
2007-12-11 1:26 ` Jakub Narebski
2007-12-11 2:50 ` Junio C Hamano
2007-12-11 23:09 ` Jakub Narebski
2007-12-12 7:46 ` Junio C Hamano
2007-12-12 10:21 ` Jakub Narebski
2007-12-12 10:31 ` Jakub Narebski
2007-12-12 19:07 ` Junio C Hamano
2007-12-10 23:00 ` [PATCH] " Junio C Hamano
2007-12-10 23:14 ` Jakub Narebski
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=200712102332.53114.jnareb@gmail.com \
--to=jnareb@gmail.com \
--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).