From: Thomas Rast <trast@student.ethz.ch>
To: <git@vger.kernel.org>
Cc: Bo Yang <struggleyb.nku@gmail.com>
Subject: [PATCH 6/8] log -L: add --graph prefix before output
Date: Tue, 14 Dec 2010 03:03:29 +0100 [thread overview]
Message-ID: <2bb97e8f1eb50542a2722d4800b68c048c9cfdd9.1292291624.git.trast@student.ethz.ch> (raw)
In-Reply-To: <cover.1292291624.git.trast@student.ethz.ch>
From: Bo Yang <struggleyb.nku@gmail.com>
Makes the line level log output look good when used
with the '--graph' option.
Signed-off-by: Bo Yang <struggleyb.nku@gmail.com>
Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
line.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 48 insertions(+), 18 deletions(-)
diff --git a/line.c b/line.c
index e766607..0b297e4 100644
--- a/line.c
+++ b/line.c
@@ -1242,6 +1242,13 @@ static void flush_lines(struct diff_options *opt, const char **ptr, const char *
const char *p = *ptr;
struct strbuf buf = STRBUF_INIT;
const char *reset;
+ char *line_prefix = "";
+ struct strbuf *msgbuf;
+
+ if (opt && opt->output_prefix) {
+ msgbuf = opt->output_prefix(opt, opt->output_prefix_data);
+ line_prefix = msgbuf->buf;
+ }
if (*color)
reset = diff_get_color_opt(opt, DIFF_RESET);
@@ -1264,7 +1271,7 @@ static void flush_lines(struct diff_options *opt, const char **ptr, const char *
while (*ptr < end && *lno <= elno) {
if (**ptr == '\n') {
- fprintf(opt->file, "%s", buf.buf);
+ fprintf(opt->file, "%s%s", line_prefix, buf.buf);
if (*ptr - p)
fwrite(p, *ptr - p, 1, opt->file);
fprintf(opt->file, "%s\n", reset);
@@ -1274,7 +1281,7 @@ static void flush_lines(struct diff_options *opt, const char **ptr, const char *
(*ptr)++;
}
if (*lno <= elno) {
- fprintf(opt->file, "%s", buf.buf);
+ fprintf(opt->file, "%s%s", line_prefix, buf.buf);
if (*ptr - p)
fwrite(p, *ptr - p, 1, opt->file);
fprintf(opt->file, "%s\n", reset);
@@ -1316,8 +1323,15 @@ static void diff_flush_chunks(struct diff_options *opt, struct line_chunk *chunk
struct diff_line_range *range = chunk->range;
const char *set = diff_get_color_opt(opt, DIFF_FRAGINFO);
const char *reset = diff_get_color_opt(opt, DIFF_RESET);
+ char *line_prefix = "";
+ struct strbuf *msgbuf;
int i;
+ if (opt && opt->output_prefix) {
+ msgbuf = opt->output_prefix(opt, opt->output_prefix_data);
+ line_prefix = msgbuf->buf;
+ }
+
for (i = 0; i < range->nr; i++) {
struct line_range *r = range->ranges + i;
long lenp = r->pend - r->pstart + 1, pstart = r->pstart;
@@ -1325,8 +1339,8 @@ static void diff_flush_chunks(struct diff_options *opt, struct line_chunk *chunk
if (pstart == 0)
lenp = 0;
- fprintf(opt->file, "%s@@ -%ld,%ld +%ld,%ld @@%s\n",
- set, pstart, lenp, r->start, len, reset);
+ fprintf(opt->file, "%s%s@@ -%ld,%ld +%ld,%ld @@%s\n",
+ line_prefix, set, pstart, lenp, r->start, len, reset);
diff_flush_range(opt, chunk, r);
}
@@ -1345,6 +1359,13 @@ static void diff_flush_filepair(struct rev_info *rev, struct diff_line_range *ra
const char *reset = diff_get_color_opt(opt, DIFF_RESET);
struct line_chunk chunk;
int must_show_header;
+ char *line_prefix = "";
+ struct strbuf *msgbuf;
+
+ if (opt && opt->output_prefix) {
+ msgbuf = opt->output_prefix(opt, opt->output_prefix_data);
+ line_prefix = msgbuf->buf;
+ }
/*
* the ranges that touch no different file, in this case
@@ -1378,21 +1399,26 @@ static void diff_flush_filepair(struct rev_info *rev, struct diff_line_range *ra
b_two = quote_two(b_prefix, name_b + (*name_b == '/'));
lbl[0] = DIFF_FILE_VALID(one) ? a_one : "/dev/null";
lbl[1] = DIFF_FILE_VALID(two) ? b_two : "/dev/null";
- strbuf_addf(&header, "%sdiff --git %s %s%s\n", set, a_one, b_two, reset);
+ strbuf_addf(&header, "%s%sdiff --git %s %s%s\n", line_prefix,
+ set, a_one, b_two, reset);
if (lbl[0][0] == '/') {
- strbuf_addf(&header, "%snew file mode %06o%s\n", set, two->mode, reset);
+ strbuf_addf(&header, "%s%snew file mode %06o%s\n",
+ line_prefix, set, two->mode, reset);
} else if (lbl[1][0] == '/') {
- strbuf_addf(&header, "%sdeleted file mode %06o%s\n", set, one->mode, reset);
+ strbuf_addf(&header, "%s%sdeleted file mode %06o%s\n",
+ line_prefix, set, one->mode, reset);
} else if (one->mode != two->mode) {
- strbuf_addf(&header, "%sold mode %06o%s\n", set, one->mode, reset);
- strbuf_addf(&header, "%snew mode %06o%s\n", set, two->mode, reset);
+ strbuf_addf(&header, "%s%sold mode %06o%s\n",
+ line_prefix, set, one->mode, reset);
+ strbuf_addf(&header, "%s%snew mode %06o%s\n",
+ line_prefix, set, two->mode, reset);
}
fprintf(opt->file, "%s%s", header.buf, meta.buf);
strbuf_release(&meta);
strbuf_release(&header);
- fprintf(opt->file, "%s--- %s%s\n", set, lbl[0], reset);
- fprintf(opt->file, "%s+++ %s%s\n", set, lbl[1], reset);
+ fprintf(opt->file, "%s%s--- %s%s\n", line_prefix, set, lbl[0], reset);
+ fprintf(opt->file, "%s%s+++ %s%s\n", line_prefix, set, lbl[1], reset);
free((void *)a_one);
free((void *)b_two);
@@ -1446,12 +1472,13 @@ static void flush_nontrivial_merge(struct rev_info *rev,
meta, range->spec->path, reset);
for (; i < range->nr; i++) {
struct line_range *r = range->ranges + i;
- fprintf(opt->file, "%s@@ %ld,%ld @@%s\n", frag, r->start,
+ fprintf(opt->file, "%s%s@@ %ld,%ld @@%s\n",
+ line_prefix, frag, r->start,
r->end - r->start + 1, reset);
flush_lines(opt, &ptr, end, r->start, r->end,
&lno, new, ' ');
}
- fprintf(opt->file, "\n");
+ fprintf(opt->file, "%s\n", line_prefix);
}
range = range->next;
}
@@ -1464,6 +1491,8 @@ static void line_log_flush(struct rev_info *rev, struct commit *c)
&c->object);
struct log_info log;
struct diff_options *opt = &rev->diffopt;
+ char *line_prefix = "";
+ struct strbuf *msgbuf;
if (!range || !(c->object.flags & NONTRIVIAL_MERGE ||
c->object.flags & NEED_PRINT))
@@ -1476,11 +1505,12 @@ static void line_log_flush(struct rev_info *rev, struct commit *c)
rev->loginfo = &log;
show_log(rev);
rev->loginfo = NULL;
- /*
- * Add a new line after each commit message, of course we should
- * add --graph alignment later when the patches comes to master.
- */
- fprintf(rev->diffopt.file, "\n");
+
+ if (opt && opt->output_prefix) {
+ msgbuf = opt->output_prefix(opt, opt->output_prefix_data);
+ line_prefix = msgbuf->buf;
+ }
+ fprintf(rev->diffopt.file, "%s\n", line_prefix);
if (c->object.flags & NONTRIVIAL_MERGE)
flush_nontrivial_merge(rev, nontrivial);
--
1.7.3.3.811.g76615
next prev parent reply other threads:[~2010-12-14 2:03 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-14 2:03 [PATCH v6 0/8] git log -L, cleaned up and (hopefully) fixed Thomas Rast
2010-12-14 2:03 ` [PATCH 1/8] Refactor parse_loc Thomas Rast
2010-12-14 22:57 ` Junio C Hamano
2010-12-14 23:06 ` Thomas Rast
2010-12-14 23:20 ` Junio C Hamano
2010-12-14 2:03 ` [PATCH 2/8] Export three functions from diff.c Thomas Rast
2010-12-14 23:08 ` Junio C Hamano
2010-12-14 2:03 ` [PATCH 3/8] Export rewrite_parents() for 'log -L' Thomas Rast
2010-12-14 2:03 ` [PATCH 4/8] Implement line-history search (git log -L) Thomas Rast
2010-12-14 2:03 ` [PATCH 5/8] log -L: support parent rewriting Thomas Rast
2010-12-14 2:03 ` Thomas Rast [this message]
2010-12-14 2:03 ` [PATCH 7/8] log -L: add --full-line-diff option Thomas Rast
2010-12-14 2:03 ` [PATCH 8/8] log -L: implement move/copy detection (-M/-C) Thomas Rast
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2bb97e8f1eb50542a2722d4800b68c048c9cfdd9.1292291624.git.trast@student.ethz.ch \
--to=trast@student.ethz.ch \
--cc=git@vger.kernel.org \
--cc=struggleyb.nku@gmail.com \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).