summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e86226e)
raw | patch | inline | side by side (parent: e86226e)
author | Jeff King <peff@peff.net> | |
Mon, 9 May 2011 13:34:42 +0000 (09:34 -0400) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 9 May 2011 22:27:50 +0000 (15:27 -0700) |
This is just like --porcelain, except that we always output
the commit information for each line, not just the first
time it is referenced. This can make quick and dirty scripts
much easier to write; see the example added to the blame
documentation.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
the commit information for each line, not just the first
time it is referenced. This can make quick and dirty scripts
much easier to write; see the example added to the blame
documentation.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/blame-options.txt | patch | blob | history | |
Documentation/git-blame.txt | patch | blob | history | |
builtin/blame.c | patch | blob | history | |
t/t8008-blame-formats.sh | patch | blob | history |
index 16e3c685762a311eda1bbc39adb8ab19e000ec97..e76195ac9721277e9ef270be8eb97dba2462bc37 100644 (file)
--porcelain::
Show in a format designed for machine consumption.
+--line-porcelain::
+ Show the porcelain format, but output commit information for
+ each line, not just the first time a commit is referenced.
+ Implies --porcelain.
+
--incremental::
Show the result incrementally in a format designed for
machine consumption.
index bb8edb4abc5adc8a7b9d46d839415997919871af..9516914236bbfa675006994620b1c8f61855de1d 100644 (file)
header, prefixed by a TAB. This is to allow adding more
header elements later.
+The porcelain format generally suppresses commit information that has
+already been seen. For example, two lines that are blamed to the same
+commit will both be shown, but the details for that commit will be shown
+only once. This is more efficient, but may require more state be kept by
+the reader. The `--line-porcelain` option can be used to output full
+commit information for each line, allowing simpler (but less efficient)
+usage like:
+
+ # count the number of lines attributed to each author
+ git blame --line-porcelain file |
+ sed -n 's/^author //p' |
+ sort | uniq -c | sort -rn
+
SPECIFYING RANGES
-----------------
diff --git a/builtin/blame.c b/builtin/blame.c
index 1a45463ea4952833ca0033bd862a35e675642d62..26a5d424b8ceb0fd403a492e46e3637fd35068ba 100644 (file)
--- a/builtin/blame.c
+++ b/builtin/blame.c
#define OUTPUT_SHOW_SCORE 0100
#define OUTPUT_NO_AUTHOR 0200
#define OUTPUT_SHOW_EMAIL 0400
+#define OUTPUT_LINE_PORCELAIN 01000
static void emit_porcelain_details(struct origin *suspect, int repeat)
{
static void emit_porcelain(struct scoreboard *sb, struct blame_entry *ent,
int opt)
{
+ int repeat = opt & OUTPUT_LINE_PORCELAIN;
int cnt;
const char *cp;
struct origin *suspect = ent->suspect;
ent->s_lno + 1,
ent->lno + 1,
ent->num_lines);
- emit_porcelain_details(suspect, 0);
+ emit_porcelain_details(suspect, repeat);
cp = nth_line(sb, ent->lno);
for (cnt = 0; cnt < ent->num_lines; cnt++) {
char ch;
- if (cnt)
+ if (cnt) {
printf("%s %d %d\n", hex,
ent->s_lno + 1 + cnt,
ent->lno + 1 + cnt);
+ if (repeat)
+ emit_porcelain_details(suspect, 1);
+ }
putchar('\t');
do {
ch = *cp++;
OPT_BIT('f', "show-name", &output_option, "Show original filename (Default: auto)", OUTPUT_SHOW_NAME),
OPT_BIT('n', "show-number", &output_option, "Show original linenumber (Default: off)", OUTPUT_SHOW_NUMBER),
OPT_BIT('p', "porcelain", &output_option, "Show in a format designed for machine consumption", OUTPUT_PORCELAIN),
+ OPT_BIT(0, "line-porcelain", &output_option, "Show porcelain format with per-line commit information", OUTPUT_PORCELAIN|OUTPUT_LINE_PORCELAIN),
OPT_BIT('c', NULL, &output_option, "Use the same output mode as git-annotate (Default: off)", OUTPUT_ANNOTATE_COMPAT),
OPT_BIT('t', NULL, &output_option, "Show raw timestamp (Default: off)", OUTPUT_RAW_TIMESTAMP),
OPT_BIT('l', NULL, &output_option, "Show long commit SHA1 (Default: off)", OUTPUT_LONG_OBJECT_NAME),
index 387d1a6b9877409b9166644993c963334ca3498c..d15f8b3d473416eaed24ed92396d567aa785c3d8 100755 (executable)
--- a/t/t8008-blame-formats.sh
+++ b/t/t8008-blame-formats.sh
test_cmp expect actual
'
+cat >expect <<EOF
+$ID1 1 1 1
+$COMMIT1
+ a
+$ID2 2 2 3
+$COMMIT2
+ b
+$ID2 3 3
+$COMMIT2
+ c
+$ID2 4 4
+$COMMIT2
+ d
+EOF
+test_expect_success 'blame --line-porcelain output' '
+ git blame --line-porcelain file >actual &&
+ test_cmp expect actual
+'
+
test_done