* [PATCH v1 3/4] line.c output the '--graph' padding before each line
2010-07-11 6:27 [PATCH v1 0/4] add parent rewrite feature to line level log Bo Yang
2010-07-11 6:27 ` [PATCH v1 1/4] make rewrite_parents an external function Bo Yang
2010-07-11 6:27 ` [PATCH v1 2/4] add parent rewrite feature to line level log Bo Yang
@ 2010-07-11 6:27 ` Bo Yang
2010-07-13 20:49 ` Junio C Hamano
2010-07-11 6:27 ` [PATCH v1 4/4] add test cases for '--graph' of line level log Bo Yang
3 siblings, 1 reply; 8+ messages in thread
From: Bo Yang @ 2010-07-11 6:27 UTC (permalink / raw)
To: git; +Cc: gitster, Jens.Lehmann, trast
Make line level log output looks well with '--graph'
option.
Signed-off-by: Bo Yang <struggleyb.nku@gmail.com>
---
line.c | 83 +++++++++++++++++++++++++++++++++++++++++++++------------------
1 files changed, 59 insertions(+), 24 deletions(-)
diff --git a/line.c b/line.c
index 0d62732..04a3500 100644
--- a/line.c
+++ b/line.c
@@ -967,6 +967,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 (strcmp(color, ""))
reset = "";
@@ -987,13 +994,9 @@ static void flush_lines(struct diff_options *opt, const char **ptr, const char *
assert(*ptr <= end);
p = *ptr;
- /*
- * todo: when --graph landed on master, this should be changed
- * a little.
- */
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);
}
@@ -1004,7 +1007,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);
}
@@ -1047,8 +1050,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;
@@ -1056,8 +1066,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);
}
@@ -1076,6 +1086,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
@@ -1117,21 +1134,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);
@@ -1153,24 +1175,33 @@ 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) {
- 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);
int lno = 1;
const char *ptr = range->spec->data;
const char *end = range->spec->data + range->spec->size;
int i = 0;
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;
}
@@ -1181,6 +1212,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;
@@ -1190,11 +1224,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
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v1 4/4] add test cases for '--graph' of line level log
2010-07-11 6:27 [PATCH v1 0/4] add parent rewrite feature to line level log Bo Yang
` (2 preceding siblings ...)
2010-07-11 6:27 ` [PATCH v1 3/4] line.c output the '--graph' padding before each line Bo Yang
@ 2010-07-11 6:27 ` Bo Yang
3 siblings, 0 replies; 8+ messages in thread
From: Bo Yang @ 2010-07-11 6:27 UTC (permalink / raw)
To: git; +Cc: gitster, Jens.Lehmann, trast
t/t4301-log-line-single-history.sh:
test the linear line of history with '--graph' option;
t/t4302-log-line-merge-history.sh:
test the case that there are merges in the history with
'--graph' option.
Note that, '--always-print' option will take no effect when
'--graph' is also given.
Signed-off-by: Bo Yang <struggleyb.nku@gmail.com>
---
Documentation/git-log.txt | 2 +
t/t4301-log-line-single-history.sh | 225 ++++++++++++++++++++++++++++++++++++
t/t4302-log-line-merge-history.sh | 51 ++++++++-
3 files changed, 277 insertions(+), 1 deletions(-)
diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt
index 14a9703..96ae0fe 100644
--- a/Documentation/git-log.txt
+++ b/Documentation/git-log.txt
@@ -101,6 +101,8 @@ of lines before or after the line given by <start>.
--always-print::
Always print the interesting range even if the current commit
does not change any line of the range.
+ Note that this option will take no effect when '--graph' is
+ also given.
include::rev-list-options.txt[]
diff --git a/t/t4301-log-line-single-history.sh b/t/t4301-log-line-single-history.sh
index 9981496..29091af 100755
--- a/t/t4301-log-line-single-history.sh
+++ b/t/t4301-log-line-single-history.sh
@@ -339,4 +339,229 @@ test_expect_success \
test_cmp current-linenum expected-linenum &&
test_cmp current-always expected-always'
+# Rerun all log with graph
+test_expect_success \
+ 'Show the line level log of path0 with --graph' \
+ 'git log --pretty=format:%s%n%b --graph -L /func/,/^}/ path0 > current-path0-graph'
+
+test_expect_success \
+ 'Show the line level log of path1 with --graph' \
+ 'git log --pretty=format:%s%n%b --graph -L /output/,/^}/ path1 > current-path1-graph'
+
+test_expect_success \
+ 'Show the line level log of two files with --graph' \
+ 'git log --pretty=format:%s%n%b --graph -L /func/,/^}/ path0 --graph -L /output/,/^}/ path1 > current-pathall-graph'
+
+test_expect_success \
+ 'Test the line number argument with --graph' \
+ 'git log --pretty=format:%s%n%b --graph -L 1,2 path0 > current-linenum-graph'
+
+test_expect_success \
+ 'Test the --always-print option with --graph option' \
+ 'git log --pretty=format:%s%n%b --always-print --graph -L 1,2 path0 > current-always-graph'
+
+cat > expected-path0-graph <<\EOF
+* Final change of path0
+|
+| diff --git a/path0 b/path0
+| index 44db133..1518c15 100644
+| --- a/path0
+| +++ b/path0
+| @@ -1,6 +1,5 @@
+| void func(){
+| int a = 10;
+| int b = 11;
+| - int c;
+| - c = 10 * (a + b);
+| + printf("%d", a - b);
+| }
+|
+* Change the 5th line of path0
+|
+| diff --git a/path0 b/path0
+| index 9ef1692..44db133 100644
+| --- a/path0
+| +++ b/path0
+| @@ -1,6 +1,6 @@
+| void func(){
+| int a = 10;
+| int b = 11;
+| int c;
+| - c = a + b;
+| + c = 10 * (a + b);
+| }
+|
+* Change 2,3 lines of path0 and path1
+|
+| diff --git a/path0 b/path0
+| index aabffdf..9ef1692 100644
+| --- a/path0
+| +++ b/path0
+| @@ -1,6 +1,6 @@
+| void func(){
+| - int a = 0;
+| - int b = 1;
+| + int a = 10;
+| + int b = 11;
+| int c;
+| c = a + b;
+| }
+|
+* Base commit
+
+ diff --git a/path0 b/path0
+ new file mode 100644
+ index 0000000..aabffdf
+ --- /dev/null
+ +++ b/path0
+ @@ -0,0 +1,6 @@
+ +void func(){
+ + int a = 0;
+ + int b = 1;
+ + int c;
+ + c = a + b;
+ +}
+EOF
+
+cat > expected-path1-graph <<\EOF
+* Change 2,3 lines of path0 and path1
+|
+| diff --git a/path1 b/path1
+| index 997d841..1d711b5 100644
+| --- a/path1
+| +++ b/path1
+| @@ -1,3 +1,4 @@
+| void output(){
+| - printf("hello world");
+| + const char *str = "hello world!";
+| + printf("%s", str);
+| }
+|
+* Base commit
+
+ diff --git a/path1 b/path1
+ new file mode 100644
+ index 0000000..997d841
+ --- /dev/null
+ +++ b/path1
+ @@ -0,0 +1,3 @@
+ +void output(){
+ + printf("hello world");
+ +}
+EOF
+
+cat > expected-pathall-graph <<\EOF
+* Final change of path0
+|
+| diff --git a/path0 b/path0
+| index 44db133..1518c15 100644
+| --- a/path0
+| +++ b/path0
+| @@ -1,6 +1,5 @@
+| void func(){
+| int a = 10;
+| int b = 11;
+| - int c;
+| - c = 10 * (a + b);
+| + printf("%d", a - b);
+| }
+|
+* Change the 5th line of path0
+|
+| diff --git a/path0 b/path0
+| index 9ef1692..44db133 100644
+| --- a/path0
+| +++ b/path0
+| @@ -1,6 +1,6 @@
+| void func(){
+| int a = 10;
+| int b = 11;
+| int c;
+| - c = a + b;
+| + c = 10 * (a + b);
+| }
+|
+* Change 2,3 lines of path0 and path1
+|
+| diff --git a/path0 b/path0
+| index aabffdf..9ef1692 100644
+| --- a/path0
+| +++ b/path0
+| @@ -1,6 +1,6 @@
+| void func(){
+| - int a = 0;
+| - int b = 1;
+| + int a = 10;
+| + int b = 11;
+| int c;
+| c = a + b;
+| }
+| diff --git a/path1 b/path1
+| index 997d841..1d711b5 100644
+| --- a/path1
+| +++ b/path1
+| @@ -1,3 +1,4 @@
+| void output(){
+| - printf("hello world");
+| + const char *str = "hello world!";
+| + printf("%s", str);
+| }
+|
+* Base commit
+
+ diff --git a/path0 b/path0
+ new file mode 100644
+ index 0000000..aabffdf
+ --- /dev/null
+ +++ b/path0
+ @@ -0,0 +1,6 @@
+ +void func(){
+ + int a = 0;
+ + int b = 1;
+ + int c;
+ + c = a + b;
+ +}
+ diff --git a/path1 b/path1
+ new file mode 100644
+ index 0000000..997d841
+ --- /dev/null
+ +++ b/path1
+ @@ -0,0 +1,3 @@
+ +void output(){
+ + printf("hello world");
+ +}
+EOF
+
+cat > expected-linenum-graph <<\EOF
+* Change 2,3 lines of path0 and path1
+|
+| diff --git a/path0 b/path0
+| index aabffdf..9ef1692 100644
+| --- a/path0
+| +++ b/path0
+| @@ -1,2 +1,2 @@
+| void func(){
+| - int a = 0;
+| + int a = 10;
+|
+* Base commit
+
+ diff --git a/path0 b/path0
+ new file mode 100644
+ index 0000000..aabffdf
+ --- /dev/null
+ +++ b/path0
+ @@ -0,0 +1,2 @@
+ +void func(){
+ + int a = 0;
+EOF
+
+test_expect_success \
+ 'validate the output.' \
+ 'test_cmp current-path0-graph expected-path0-graph &&
+ test_cmp current-path1-graph expected-path1-graph &&
+ test_cmp current-pathall-graph expected-pathall-graph &&
+ test_cmp current-linenum-graph expected-linenum-graph &&
+ test_cmp current-always-graph expected-linenum-graph'
+
test_done
diff --git a/t/t4302-log-line-merge-history.sh b/t/t4302-log-line-merge-history.sh
index 02e7439..cd417d3 100755
--- a/t/t4302-log-line-merge-history.sh
+++ b/t/t4302-log-line-merge-history.sh
@@ -107,8 +107,57 @@ index 0000000..f628dea
+ printf("hello");
+}
EOF
+
+cat > expected-graph <<\EOF
+* Merge two branches
+|\
+| |
+| | nontrivial merge found
+| | path0
+| |
+| | @@ 2,1 @@
+| | printf("hello earth and moon");
+| |
+| |
+| * Change path0 in master
+| |
+| | diff --git a/path0 b/path0
+| | index f628dea..bef7fa3 100644
+| | --- a/path0
+| | +++ b/path0
+| | @@ -2,1 +2,1 @@
+| | - printf("hello");
+| | + printf("hello earth");
+| |
+* | Change path0 in feature
+|/
+|
+| diff --git a/path0 b/path0
+| index f628dea..a940ef6 100644
+| --- a/path0
+| +++ b/path0
+| @@ -2,1 +2,1 @@
+| - printf("hello");
+| + print("hello moon");
+|
+* Base commit
+
+ diff --git a/path0 b/path0
+ new file mode 100644
+ index 0000000..f628dea
+ --- /dev/null
+ +++ b/path0
+ @@ -0,0 +2,1 @@
+ + printf("hello");
+EOF
+
+test_expect_success \
+ 'Show the line log of the 2 line of path0 with graph' \
+ 'git log --pretty=format:%s%n%b --graph -L 2,+1 path0 > current-graph'
+
test_expect_success \
'validate the output.' \
- 'test_cmp current expected'
+ 'test_cmp current expected &&
+ test_cmp current-graph expected-graph'
test_done
--
1.7.0.2.273.gc2413.dirty
^ permalink raw reply related [flat|nested] 8+ messages in thread