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

[PATCH v4 2/3] blame: extract find_single_final

From
Max Kirillov <max@max630.net>
Date
Oct 26, 2015, 05:26 UTC
Message-ID
<1445837217-4252-4-git-send-email-max@max630.net>
In-Reply-To
<1445837217-4252-1-git-send-email-max@max630.net>
Signed-off-by: Max Kirillov <max@max630.net>
---
 builtin/blame.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)
diff --git a/builtin/blame.c b/builtin/blame.c
index 295ce92..38f6267 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -2401,16 +2401,11 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
 	return commit;
 }
 
-static char *prepare_final(struct scoreboard *sb)
+static struct object_array_entry *find_single_final(struct rev_info *revs)
 {
 	int i;
-	const char *final_commit_name = NULL;
-	struct rev_info *revs = sb->revs;
+	struct object_array_entry *found = NULL;
 
-	/*
-	 * There must be one and only one positive commit in the
-	 * revs->pending array.
-	 */
 	for (i = 0; i < revs->pending.nr; i++) {
 		struct object *obj = revs->pending.objects[i].item;
 		if (obj->flags & UNINTERESTING)
@@ -2419,14 +2414,24 @@ static char *prepare_final(struct scoreboard *sb)
 			obj = deref_tag(obj, NULL, 0);
 		if (obj->type != OBJ_COMMIT)
 			die("Non commit %s?", revs->pending.objects[i].name);
-		if (sb->final)
+		if (found)
 			die("More than one commit to dig from %s and %s?",
 			    revs->pending.objects[i].name,
-			    final_commit_name);
-		sb->final = (struct commit *) obj;
-		final_commit_name = revs->pending.objects[i].name;
+			    found->name);
+		found = &(revs->pending.objects[i]);
+	}
+	return found;
+}
+
+static char *prepare_final(struct scoreboard *sb)
+{
+	struct object_array_entry *found = find_single_final(sb->revs);
+	if (found) {
+		sb->final = (struct commit *) found->item;
+		return xstrdup(found->name);
+	} else {
+		return NULL;
 	}
-	return xstrdup_or_null(final_commit_name);
 }
 
 static char *prepare_initial(struct scoreboard *sb)
-- 
2.3.4.2801.g3d0809b
Previous: Junio C HamanoNext: Max Kirillov
Message 12 of 13 in “blame: allow blame --reverse --first-parent when it makes sense”
  1. 0/2 blame: allow blame --reverse --first-parent when it makes senseMax Kirillov, Oct 22, 2015
  2. 1/2 Add test to describe expectation of blame --reverse with branched historyMax Kirillov, Oct 22, 2015
  3. 2/2 blame: allow blame --reverse --first-parent when it makes senseMax Kirillov, Oct 22, 2015
  4. 0/4 blame: allow blame --reverse --first-parent when it makes senseMax Kirillov, Oct 26, 2015
  5. 0/4 blame: allow blame --reverse --first-parent when it makes senseMax Kirillov, Oct 26, 2015
  6. Max KirillovOct 26, 2015
  7. 1/3 Add test to describe expectation of blame --reverse with branched historyMax Kirillov, Oct 26, 2015
  8. Max KirillovOct 26, 2015
  9. Junio C HamanoOct 26, 2015
  10. Max KirillovOct 27, 2015
  11. Junio C HamanoOct 27, 2015
  12. 2/3 blame: extract find_single_finalMax Kirillov, Oct 26, 2015
  13. 3/3 blame: allow blame --reverse --first-parent when it makes senseMax Kirillov, Oct 26, 2015

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.