git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH v1 0/4] add parent rewrite feature to line level log
@ 2010-07-11  6:27 Bo Yang
  2010-07-11  6:27 ` [PATCH v1 1/4] make rewrite_parents an external function Bo Yang
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Bo Yang @ 2010-07-11  6:27 UTC (permalink / raw
  To: git; +Cc: gitster, Jens.Lehmann, trast

With this series of patches, one can provide options such as '--graph', '--parents', '--simplify-merges' and etc to 'git log -L' command and get the right result.
Note that, this series is based on the previous series 'the version 3 of 13 commits just posted to the list'. :-)

Bo Yang (4):
  make rewrite_parents a external function
  add parent rewrite feature to line level log
  line.c output the '--graph' padding before each line
  add test cases for '--graph' of line level log

 Documentation/git-log.txt          |    2 +
 line.c                             |  177 ++++++++++++++++++++++++-----
 line.h                             |    2 +
 revision.c                         |   14 +--
 revision.h                         |   10 ++
 t/t4301-log-line-single-history.sh |  225 ++++++++++++++++++++++++++++++++++++
 t/t4302-log-line-merge-history.sh  |   51 ++++++++-
 7 files changed, 445 insertions(+), 36 deletions(-)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v1 1/4] make rewrite_parents an external function
  2010-07-11  6:27 [PATCH v1 0/4] add parent rewrite feature to line level log Bo Yang
@ 2010-07-11  6:27 ` Bo Yang
  2010-07-14 19:10   ` Junio C Hamano
  2010-07-11  6:27 ` [PATCH v1 2/4] add parent rewrite feature to line level log Bo Yang
                   ` (2 subsequent siblings)
  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

The function rewrite_one is used to rewrite a single
parent of the current commit, and is used by rewrite_parents
to rewrite all the parents.
This commit decouple the dependence between them, make
rewrite_one as a callback function and be passed to
rewrite_parents. Make rewrite_parents public to other
part of git.
We will use this function in line.c.

Signed-off-by: Bo Yang <struggleyb.nku@gmail.com>
---
 revision.c |   11 +++--------
 revision.h |   10 ++++++++++
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/revision.c b/revision.c
index 63f37ea..72d9654 100644
--- a/revision.c
+++ b/revision.c
@@ -1893,12 +1893,6 @@ int prepare_revision_walk(struct rev_info *revs)
 	return 0;
 }
 
-enum rewrite_result {
-	rewrite_one_ok,
-	rewrite_one_noparents,
-	rewrite_one_error
-};
-
 static enum rewrite_result rewrite_one(struct rev_info *revs, struct commit **pp)
 {
 	struct commit_list *cache = NULL;
@@ -1920,7 +1914,8 @@ static enum rewrite_result rewrite_one(struct rev_info *revs, struct commit **pp
 	}
 }
 
-static int rewrite_parents(struct rev_info *revs, struct commit *commit)
+int rewrite_parents(struct rev_info *revs, struct commit *commit,
+	rewrite_parent rewrite_one)
 {
 	struct commit_list **pp = &commit->parents;
 	while (*pp) {
@@ -1993,7 +1988,7 @@ enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)
 	if (action == commit_show &&
 	    !revs->show_all &&
 	    revs->prune && revs->dense && want_ancestry(revs)) {
-		if (rewrite_parents(revs, commit) < 0)
+		if (rewrite_parents(revs, commit, rewrite_one) < 0)
 			return commit_error;
 	}
 	return action;
diff --git a/revision.h b/revision.h
index 433da9a..9b8e3d9 100644
--- a/revision.h
+++ b/revision.h
@@ -200,4 +200,14 @@ enum commit_action {
 extern enum commit_action get_commit_action(struct rev_info *revs, struct commit *commit);
 extern enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit);
 
+enum rewrite_result {
+	rewrite_one_ok,
+	rewrite_one_noparents,
+	rewrite_one_error
+};
+
+typedef enum rewrite_result (*rewrite_parent)(struct rev_info *revs, struct commit **pp);
+
+extern int rewrite_parents(struct rev_info *revs, struct commit *commit,
+	rewrite_parent rewrite_one);
 #endif
-- 
1.7.0.2.273.gc2413.dirty

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v1 2/4] add parent rewrite feature to line level log
  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 ` Bo Yang
  2010-07-13 20:47   ` Junio C Hamano
  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 ` [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

Two kinds of commit are qualified as a parent:
 1. The commit touch some lines of the current
    interesting range;
 2. The commit is a merge commit.

So, there will be more commits output than the
situation which parent rewrite is not set on.

Signed-off-by: Bo Yang <struggleyb.nku@gmail.com>
---
 line.c     |   94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 line.h     |    2 +
 revision.c |    3 ++
 3 files changed, 96 insertions(+), 3 deletions(-)

diff --git a/line.c b/line.c
index c08b510..0d62732 100644
--- a/line.c
+++ b/line.c
@@ -10,6 +10,9 @@
 #include "xdiff-interface.h"
 #include "strbuf.h"
 #include "log-tree.h"
+#include "graph.h"
+
+static int limited = 0;
 
 static void cleanup(struct diff_line_range *r)
 {
@@ -1213,12 +1216,12 @@ int cmd_line_log_walk(struct rev_info *rev)
 		die("revision walk prepare failed");
 
 	list = rev->commits;
-	if (list) {
+	if (list && !limited) {
 		list->item->object.flags |= RANGE_UPDATE;
 		list = list->next;
 	}
 	/* Clear the flags */
-	while (list) {
+	while (list && !limited) {
 		list->item->object.flags &= 0x0;
 		list = list->next;
 	}
@@ -1232,7 +1235,9 @@ int cmd_line_log_walk(struct rev_info *rev)
 			assign_parents_range(rev, commit);
 		}
 
-		if (commit->object.flags & NEED_PRINT || rev->always_print) {
+		if (commit->object.flags & NEED_PRINT || rev->always_print || rev->graph) {
+			if (rev->graph)
+				graph_update(rev->graph, commit);
 			line_log_flush(rev, commit);
 		}
 
@@ -1257,3 +1262,86 @@ int cmd_line_log_walk(struct rev_info *rev)
 	return 0;
 }
 
+static enum rewrite_result rewrite_one(struct rev_info *rev, struct commit **pp)
+{
+	struct diff_line_range *r = NULL;
+	struct commit *p;
+	while (1) {
+		p = *pp;
+		if (p->object.flags & RANGE_UPDATE)
+			assign_parents_range(rev, p);
+		if (p->parents && p->parents->next)
+			return rewrite_one_ok;
+		if (p->object.flags & NEED_PRINT)
+			return rewrite_one_ok;
+		if (!p->parents)
+			return rewrite_one_noparents;
+
+		r = lookup_line_range(rev, p);
+		if (!r)
+			return rewrite_one_noparents;
+		*pp = p->parents->item;
+	}
+}
+
+/* The rev->commits must be sorted in topologically order */
+void limit_list_line(struct rev_info *rev)
+{
+	struct commit_list *list = rev->commits;
+	struct commit_list *commits = xmalloc(sizeof(struct commit_list));
+	struct commit_list *out = commits, *prev = commits;
+	struct commit *c;
+	struct diff_line_range *r;
+
+	if (list) {
+		list->item->object.flags |= RANGE_UPDATE;
+		list = list->next;
+	}
+	/* Clear the flags */
+	while (list) {
+		list->item->object.flags &= 0x0;
+		list = list->next;
+	}
+
+	list = rev->commits;
+	while (list) {
+		c = list->item;
+
+		if (c->object.flags & RANGE_UPDATE)
+			assign_parents_range(rev, c);
+
+		if (c->object.flags & NEED_PRINT ||
+			(c->parents && c->parents->next)) {
+			if (rewrite_parents(rev, c, rewrite_one))
+				die("Can't rewrite parent for commit %s",
+					sha1_to_hex(c->object.sha1));
+			commits->item = c;
+			commits->next = xmalloc(sizeof(struct commit_list));
+			prev = commits;
+			commits = commits->next;
+		} else {
+			r = lookup_line_range(rev, c);
+			if (r) {
+				cleanup(r);
+				r = NULL;
+				add_line_range(rev, c, r);
+			}
+		}
+
+		list = list->next;
+	}
+
+	prev->next = NULL;
+	free(commits);
+
+	list = rev->commits;
+	while (list) {
+		struct commit_list *l = list;
+		list = list->next;
+		free(l);
+	}
+
+	rev->commits = out;
+	limited = 1;
+}
+
diff --git a/line.h b/line.h
index b293894..90d7c1a 100644
--- a/line.h
+++ b/line.h
@@ -130,4 +130,6 @@ const char *parse_loc(const char *spec, nth_line_fn_t nth_line,
 
 extern int cmd_line_log_walk(struct rev_info *rev);
 
+extern void limit_list_line(struct rev_info *rev);
+
 #endif
diff --git a/revision.c b/revision.c
index 72d9654..659cec7 100644
--- a/revision.c
+++ b/revision.c
@@ -13,6 +13,7 @@
 #include "decorate.h"
 #include "log-tree.h"
 #include "string-list.h"
+#include "line.h"
 
 volatile show_early_output_fn_t show_early_output;
 
@@ -1886,6 +1887,8 @@ int prepare_revision_walk(struct rev_info *revs)
 			return -1;
 	if (revs->topo_order)
 		sort_in_topological_order(&revs->commits, revs->lifo);
+	if (revs->rewrite_parents && revs->line)
+		limit_list_line(revs);
 	if (revs->simplify_merges)
 		simplify_merges(revs);
 	if (revs->children.name)
-- 
1.7.0.2.273.gc2413.dirty

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [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

* Re: [PATCH v1 2/4] add parent rewrite feature to line level log
  2010-07-11  6:27 ` [PATCH v1 2/4] add parent rewrite feature to line level log Bo Yang
@ 2010-07-13 20:47   ` Junio C Hamano
  0 siblings, 0 replies; 8+ messages in thread
From: Junio C Hamano @ 2010-07-13 20:47 UTC (permalink / raw
  To: Bo Yang; +Cc: git, Jens.Lehmann, trast

Bo Yang <struggleyb.nku@gmail.com> writes:

> Two kinds of commit are qualified as a parent:
>  1. The commit touch some lines of the current
>     interesting range;
>  2. The commit is a merge commit.
>
> So, there will be more commits output than the
> situation which parent rewrite is not set on.

Sorry, but -ECANTPARSEATALL.  What do you mean by "qualified" and in what
context?  What makes these two conditions significant?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 3/4] line.c output the '--graph' padding before each line
  2010-07-11  6:27 ` [PATCH v1 3/4] line.c output the '--graph' padding before each line Bo Yang
@ 2010-07-13 20:49   ` Junio C Hamano
  0 siblings, 0 replies; 8+ messages in thread
From: Junio C Hamano @ 2010-07-13 20:49 UTC (permalink / raw
  To: Bo Yang; +Cc: git, Jens.Lehmann, trast

Bo Yang <struggleyb.nku@gmail.com> writes:

> Make line level log output looks well with '--graph'
> option.

This is probably better done as part of rebasing the previous line-range
series to a more recent codebase that already has the --graph fixes, not
as a separate "oops, my codebase was stale--here is a fix-up" patch.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 1/4] make rewrite_parents an external function
  2010-07-11  6:27 ` [PATCH v1 1/4] make rewrite_parents an external function Bo Yang
@ 2010-07-14 19:10   ` Junio C Hamano
  0 siblings, 0 replies; 8+ messages in thread
From: Junio C Hamano @ 2010-07-14 19:10 UTC (permalink / raw
  To: Bo Yang; +Cc: git, Jens.Lehmann, trast

Bo Yang <struggleyb.nku@gmail.com> writes:

> The function rewrite_one is used to rewrite a single
> parent of the current commit, and is used by rewrite_parents
> to rewrite all the parents.
> This commit decouple the dependence between them, make
> rewrite_one as a callback function and be passed to
> rewrite_parents. Make rewrite_parents public to other
> part of git.
> We will use this function in line.c.

Sorry, but -ECANTREALLYPARSE.

This particular refactoring is probably harmless, but we would need to see
how it is used to convince ourselves it is a good change.

> @@ -1920,7 +1914,8 @@ static enum rewrite_result rewrite_one(struct rev_info *revs, struct commit **pp
>  	}
>  }
>  
> -static int rewrite_parents(struct rev_info *revs, struct commit *commit)
> +int rewrite_parents(struct rev_info *revs, struct commit *commit,
> +	rewrite_parent rewrite_one)
>  {
>  	struct commit_list **pp = &commit->parents;
>  	while (*pp) {
> @@ -1993,7 +1988,7 @@ enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)
>  	if (action == commit_show &&
>  	    !revs->show_all &&
>  	    revs->prune && revs->dense && want_ancestry(revs)) {
> -		if (rewrite_parents(revs, commit) < 0)
> +		if (rewrite_parents(revs, commit, rewrite_one) < 0)
>  			return commit_error;
>  	}
>  	return action;

It would probably make sense to rename this "rewrite_one" (local function
pointer variable) not to collide with the "rewrite_one" (static function)
for readability.

> diff --git a/revision.h b/revision.h
> index 433da9a..9b8e3d9 100644
> --- a/revision.h
> +++ b/revision.h
> @@ -200,4 +200,14 @@ enum commit_action {
>  extern enum commit_action get_commit_action(struct rev_info *revs, struct commit *commit);
>  extern enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit);
>  
> +enum rewrite_result {
> +	rewrite_one_ok,
> +	rewrite_one_noparents,
> +	rewrite_one_error
> +};
> +
> +typedef enum rewrite_result (*rewrite_parent)(struct rev_info *revs, struct commit **pp);

Yikes; at least name the type rewrite_parent_fn or something for readability.


> +extern int rewrite_parents(struct rev_info *revs, struct commit *commit,
> +	rewrite_parent rewrite_one);
>  #endif
> -- 
> 1.7.0.2.273.gc2413.dirty

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-07-14 19:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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-14 19:10   ` Junio C Hamano
2010-07-11  6:27 ` [PATCH v1 2/4] add parent rewrite feature to line level log Bo Yang
2010-07-13 20:47   ` Junio C Hamano
2010-07-11  6:27 ` [PATCH v1 3/4] line.c output the '--graph' padding before each line 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

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).