git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/8] Export rewrite_parents() for 'log -L'

From
Thomas Rast <trast@student.ethz.ch>
Date
Dec 14, 2010, 02:03 UTC
Message-ID
<fb904e7dc0298c3efa8bb8cd25f62b5e83f59918.1292291624.git.trast@student.ethz.ch>
In-Reply-To
<cover.1292291624.git.trast@student.ethz.ch>
From: Bo Yang <struggleyb.nku@gmail.com>

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.

Decouple the dependence between them by making rewrite_one a callback function that is passed to rewrite_parents. Then export rewrite_parents for reuse by the line history browser.

We will use this function in line.c.
Signed-off-by: Bo Yang <struggleyb.nku@gmail.com>
Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
 revision.c |   13 ++++---------
 revision.h |   10 ++++++++++
 2 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/revision.c b/revision.c
index ded8812..6465c45 100644
--- a/revision.c
+++ b/revision.c
@@ -1912,12 +1912,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;
@@ -1939,12 +1933,13 @@ 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_fn_t rewrite_parent)
 {
 	struct commit_list **pp = &commit->parents;
 	while (*pp) {
 		struct commit_list *parent = *pp;
-		switch (rewrite_one(revs, &parent->item)) {
+		switch (rewrite_parent(revs, &parent->item)) {
 		case rewrite_one_ok:
 			break;
 		case rewrite_one_noparents:
@@ -2012,7 +2007,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 05659c6..8897368 100644
--- a/revision.h
+++ b/revision.h
@@ -193,4 +193,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_fn_t)(struct rev_info *revs, struct commit **pp);
+
+extern int rewrite_parents(struct rev_info *revs, struct commit *commit,
+	rewrite_parent_fn_t rewrite_parent);
 #endif
-- 
1.7.3.3.811.g76615
Previous: Junio C HamanoNext: Thomas Rast
Message 8 of 13 in “git log -L, cleaned up and (hopefully) fixed”
  1. 0/8 git log -L, cleaned up and (hopefully) fixedThomas Rast, Dec 14, 2010
  2. 1/8 Refactor parse_locThomas Rast, Dec 14, 2010
  3. Junio C HamanoDec 14, 2010
  4. Thomas RastDec 14, 2010
  5. Junio C HamanoDec 14, 2010
  6. 2/8 Export three functions from diff.cThomas Rast, Dec 14, 2010
  7. Junio C HamanoDec 14, 2010
  8. 3/8 Export rewrite_parents() for 'log -L'Thomas Rast, Dec 14, 2010
  9. 4/8 Implement line-history search (git log -L)Thomas Rast, Dec 14, 2010
  10. 5/8 log -L: support parent rewritingThomas Rast, Dec 14, 2010
  11. 6/8 log -L: add --graph prefix before outputThomas Rast, Dec 14, 2010
  12. 7/8 log -L: add --full-line-diff optionThomas Rast, Dec 14, 2010
  13. 8/8 log -L: implement move/copy detection (-M/-C)Thomas Rast, Dec 14, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.