From: Bo Yang <struggleyb.nku@gmail.com>
To: git@vger.kernel.org
Subject: [WIP PATCH 16/22] Add --graph prefix before line history output
Date: Sat, 24 Jul 2010 23:13:48 +0800 [thread overview]
Message-ID: <1279984434-28933-17-git-send-email-struggleyb.nku@gmail.com> (raw)
In-Reply-To: <1279984434-28933-1-git-send-email-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>
---
line.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++----------------
1 files changed, 59 insertions(+), 20 deletions(-)
diff --git a/line.c b/line.c
index cc8be97..c8c9ad3 100644
--- a/line.c
+++ b/line.c
@@ -1007,6 +1007,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);
@@ -1029,7 +1036,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);
}
@@ -1040,7 +1047,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);
}
@@ -1083,8 +1090,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 range *r = range->ranges + i;
long lenp = r->pend - r->pstart + 1, pstart = r->pstart;
@@ -1092,8 +1106,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);
}
@@ -1112,6 +1126,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
@@ -1153,21 +1174,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);
@@ -1189,8 +1215,15 @@ static void flush_nontrivial_merge(struct rev_info *rev, struct diff_line_range
const char *frag = diff_get_color_opt(opt, DIFF_FRAGINFO);
const char *meta = diff_get_color_opt(opt, DIFF_METAINFO);
const char *new = diff_get_color_opt(opt, DIFF_FILE_NEW);
+ char *line_prefix = "";
+ struct strbuf *msgbuf;
- fprintf(opt->file, "%s%s%s\n", meta, EVIL_MERGE_STR, reset);
+ if (opt && opt->output_prefix) {
+ msgbuf = opt->output_prefix(opt, opt->output_prefix_data);
+ line_prefix = msgbuf->buf;
+ }
+
+ fprintf(opt->file, "%s%s%s%s\n", line_prefix, meta, EVIL_MERGE_STR, reset);
while (range) {
if (range->nr) {
@@ -1198,15 +1231,17 @@ static void flush_nontrivial_merge(struct rev_info *rev, struct diff_line_range
const char *ptr = range->spec->data;
const char *end = range->spec->data + range->spec->size;
int i = 0;
- fprintf(opt->file, "%s%s%s\n\n", meta, range->spec->path, reset);
+ fprintf(opt->file, "%s%s%s%s\n%s\n", line_prefix,
+ meta, range->spec->path, reset, line_prefix);
for (; i < range->nr; i++) {
struct 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;
}
@@ -1217,6 +1252,9 @@ static void line_log_flush(struct rev_info *rev, struct commit *c)
struct diff_line_range *range = lookup_line_range(rev, c);
struct diff_line_range *nontrivial = lookup_decoration(&rev->nontrivial_merge, &c->object);
struct log_info log;
+ struct diff_options *opt = &rev->diffopt;
+ char *line_prefix = "";
+ struct strbuf *msgbuf;
if (range == NULL)
return;
@@ -1226,11 +1264,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 & EVIL_MERGE)
return flush_nontrivial_merge(rev, nontrivial);
--
1.7.0.2.273.gc2413.dirty
next prev parent reply other threads:[~2010-07-24 15:15 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-24 15:13 [WIP PATCH 00/22] Some updates since v3 Bo Yang
2010-07-24 15:13 ` [WIP PATCH 01/22] parse-options: enhance STOP_AT_NON_OPTION Bo Yang
2010-07-24 15:13 ` [WIP PATCH 02/22] parse-options: add two helper functions Bo Yang
2010-07-24 15:13 ` [WIP PATCH 03/22] Add the basic data structure for line level history Bo Yang
2010-07-24 15:13 ` [WIP PATCH 04/22] Refactor parse_loc Bo Yang
2010-07-24 15:13 ` [WIP PATCH 05/22] Parse the -L options Bo Yang
2010-07-24 15:13 ` [WIP PATCH 06/22] Export three functions from diff.c Bo Yang
2010-07-24 15:13 ` [WIP PATCH 07/22] Add range clone functions Bo Yang
2010-07-24 15:13 ` [WIP PATCH 08/22] map/take range to the parent of commits Bo Yang
2010-07-24 15:13 ` [WIP PATCH 09/22] Print the line log Bo Yang
2010-07-24 15:13 ` [WIP PATCH 10/22] Hook line history into cmd_log, ensuring a topo-ordered walk Bo Yang
2010-07-24 15:13 ` [WIP PATCH 11/22] Add --full-line-diff option Bo Yang
2010-07-24 15:13 ` [WIP PATCH 12/22] Add tests for line history browser Bo Yang
2010-07-24 22:14 ` Thomas Rast
2010-07-24 15:13 ` [WIP PATCH 13/22] Document " Bo Yang
2010-07-24 15:13 ` [WIP PATCH 14/22] Make rewrite_parents public to other part of git Bo Yang
2010-07-24 15:13 ` [WIP PATCH 15/22] Add parent rewriting to line history browser Bo Yang
2010-07-24 15:13 ` Bo Yang [this message]
2010-07-24 15:13 ` [WIP PATCH 17/22] Add test cases for '--graph' of line level log Bo Yang
2010-07-24 15:13 ` [WIP PATCH 18/22] a fast fix Bo Yang
2010-07-24 15:13 ` [WIP PATCH 19/22] Make graph_next_line external to other part of git Bo Yang
2010-07-24 15:13 ` [WIP PATCH 20/22] some changes Bo Yang
2010-07-24 15:13 ` [WIP PATCH 21/22] commit parents prunning code Bo Yang
2010-07-24 15:13 ` [WIP PATCH 22/22] A merge should not be printed anyway Bo Yang
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=1279984434-28933-17-git-send-email-struggleyb.nku@gmail.com \
--to=struggleyb.nku@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).