Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> writes: > On Sat, 27 Jan 2007, Junio C Hamano wrote: >> >> I would think we probably should reuse the --porcelain output, >> perhaps enhancing it even more. > > I looked at using "emit_porcelain()" directly, but that format doesn't > seem to actually be usable for incremental blame. I agree the code itself wouldn't be for the reasons you stated. > Also, for the incremental blame, it makes no sense to actually print out > the actual blame buffer: anybody who uses the incremental blame thing > really needs to get the original buffer separately set up anyway. Yes and no -- it might be interesting to start from a blank canvas, and insert the lines as they are received at appropriate places (recorded as ent->lno), although in general I agree the GUI would have the way and the need to grab the blob contents without us giving it in the --incremental output. I think it is sensible to do the attached on top of your patch. -- >8 -- [PATCH] Update blame --incremental output format. It makes the output show the origin information in the same format as the porcelain format. The first line has commit object name, the line number of the first line in the group in the original file, the line number of that file in the final image, and number of lines in the group. Then subsequent lines show the metainformation for the commit when the commit is shown for the first time, except the filename information is always shown (we cannot even make it conditional to -C option as blame always follows the renaming of the file wholesale). Two things I updated are (1) line numbers start at 1, not 0, to make it consistent with other formats, (2) filename is C-quoted if needed. The latter should be done to fix the original porcelain output; it was an oversight. builtin-blame.c | 67 +++++++++++++++++++++++++++++++++++++------------------ 1 files changed, 45 insertions(+), 22 deletions(-) diff --git a/builtin-blame.c b/builtin-blame.c index 7d97ae9..967e30d 100644 --- a/builtin-blame.c +++ b/builtin-blame.c @@ -13,6 +13,7 @@ #include "diff.h" #include "diffcore.h" #include "revision.h" +#include "quote.h" #include "xdiff-interface.h" static char blame_usage[] = @@ -1071,18 +1072,56 @@ static void pass_blame(struct scoreboard *sb, struct origin *origin, int opt) origin_decref(parent_origin[i]); } +struct commit_info +{ + char *author; + char *author_mail; + unsigned long author_time; + char *author_tz; + + /* filled only when asked for details */ + char *committer; + char *committer_mail; + unsigned long committer_time; + char *committer_tz; + + char *summary; +}; + +static void get_commit_info(struct commit *commit, + struct commit_info *ret, + int detailed); + static void found_guilty_entry(struct blame_entry *ent) { if (ent->guilty) return; ent->guilty = 1; if (incremental) { - struct origin *origin = ent->suspect; - printf("%d %d %s:%s:%d\n", - ent->lno, ent->num_lines, - sha1_to_hex(origin->commit->object.sha1), - origin->path, - ent->s_lno); + struct origin *suspect = ent->suspect; + + printf("%s %d %d %d\n", + sha1_to_hex(suspect->commit->object.sha1), + ent->s_lno + 1, ent->lno + 1, ent->num_lines); + if (!(suspect->commit->object.flags & METAINFO_SHOWN)) { + struct commit_info ci; + suspect->commit->object.flags |= METAINFO_SHOWN; + get_commit_info(suspect->commit, &ci, 1); + printf("author %s\n", ci.author); + printf("author-mail %s\n", ci.author_mail); + printf("author-time %lu\n", ci.author_time); + printf("author-tz %s\n", ci.author_tz); + printf("committer %s\n", ci.committer); + printf("committer-mail %s\n", ci.committer_mail); + printf("committer-time %lu\n", ci.committer_time); + printf("committer-tz %s\n", ci.committer_tz); + printf("summary %s\n", ci.summary); + if (suspect->commit->object.flags & UNINTERESTING) + printf("boundary\n"); + } + printf("filename "); + write_name_quoted(NULL, 0, suspect->path, 1, stdout); + putchar('\n'); } } @@ -1152,22 +1191,6 @@ static const char *format_time(unsigned long time, const char *tz_str, return time_buf; } -struct commit_info -{ - char *author; - char *author_mail; - unsigned long author_time; - char *author_tz; - - /* filled only when asked for details */ - char *committer; - char *committer_mail; - unsigned long committer_time; - char *committer_tz; - - char *summary; -}; - static void get_ac_line(const char *inbuf, const char *what, int bufsz, char *person, char **mail, unsigned long *time, char **tz) - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html