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

[PATCH 2/2] merge-recursive: move make_virtual_commit()'s virtual_id to merge_options

From
Miklos Vajna <vmiklos@frugalware.org>
Date
Sep 3, 2008, 17:34 UTC
Message-ID
<f2a1ff8d2fe354265a80534cd7beaaa95c2ffc54.1220463034.git.vmiklos@frugalware.org>
In-Reply-To
<e3e7f1cbf3746e7d2ef2c77227c9367a361c10b9.1220463034.git.vmiklos@frugalware.org>

This is the last patch in this series, now all static variables in merge-recursive.c are moved to struct merge_options.

Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
---
 merge-recursive.c |   24 ++++++++++++++----------
 merge-recursive.h |    1 +
 2 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/merge-recursive.c b/merge-recursive.c
index 964b8f3..4fa3308 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -40,13 +40,14 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two)
  * - *(int *)commit->object.sha1 set to the virtual id.
  */
 
-struct commit *make_virtual_commit(struct tree *tree, const char *comment)
+struct commit *make_virtual_commit(struct merge_options *o,
+				   struct tree *tree,
+				   const char *comment)
 {
 	struct commit *commit = xcalloc(1, sizeof(struct commit));
-	static unsigned virtual_id = 1;
 	commit->tree = tree;
 	commit->util = (void*)comment;
-	*(int*)commit->object.sha1 = virtual_id++;
+	*(int*)commit->object.sha1 = o->virtual_id++;
 	/* avoid warnings */
 	commit->object.parsed = 1;
 	return commit;
@@ -1245,7 +1246,7 @@ int merge_recursive(struct merge_options *o,
 		tree->object.parsed = 1;
 		tree->object.type = OBJ_TREE;
 		pretend_sha1_file(NULL, 0, OBJ_TREE, tree->object.sha1);
-		merged_common_ancestors = make_virtual_commit(tree, "ancestor");
+		merged_common_ancestors = make_virtual_commit(o, tree, "ancestor");
 	}
 
 	for (iter = ca; iter; iter = iter->next) {
@@ -1281,7 +1282,7 @@ int merge_recursive(struct merge_options *o,
 			    &mrtree);
 
 	if (o->call_depth) {
-		*result = make_virtual_commit(mrtree, "merged tree");
+		*result = make_virtual_commit(o, mrtree, "merged tree");
 		commit_list_insert(h1, &(*result)->parents);
 		commit_list_insert(h2, &(*result)->parents->next);
 	}
@@ -1289,7 +1290,9 @@ int merge_recursive(struct merge_options *o,
 	return clean;
 }
 
-static struct commit *get_ref(const unsigned char *sha1, const char *name)
+static struct commit *get_ref(struct merge_options *o,
+			      const unsigned char *sha1,
+			      const char *name)
 {
 	struct object *object;
 
@@ -1297,7 +1300,7 @@ static struct commit *get_ref(const unsigned char *sha1, const char *name)
 	if (!object)
 		return NULL;
 	if (object->type == OBJ_TREE)
-		return make_virtual_commit((struct tree*)object, name);
+		return make_virtual_commit(o, (struct tree*)object, name);
 	if (object->type != OBJ_COMMIT)
 		return NULL;
 	if (parse_commit((struct commit *)object))
@@ -1314,15 +1317,15 @@ int merge_recursive_generic(struct merge_options *o,
 {
 	int clean, index_fd;
 	struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
-	struct commit *head_commit = get_ref(head, o->branch1);
-	struct commit *next_commit = get_ref(merge, o->branch2);
+	struct commit *head_commit = get_ref(o, head, o->branch1);
+	struct commit *next_commit = get_ref(o, merge, o->branch2);
 	struct commit_list *ca = NULL;
 
 	if (base_list) {
 		int i;
 		for (i = 0; i < num_base_list; ++i) {
 			struct commit *base;
-			if (!(base = get_ref(base_list[i], sha1_to_hex(base_list[i]))))
+			if (!(base = get_ref(o, base_list[i], sha1_to_hex(base_list[i]))))
 				return error("Could not parse object '%s'",
 					sha1_to_hex(base_list[i]));
 			commit_list_insert(base, &ca);
@@ -1376,4 +1379,5 @@ void init_merge_options(struct merge_options *o)
 	o->current_file_set.strdup_strings = 1;
 	memset(&o->current_directory_set, 0, sizeof(struct string_list));
 	o->current_directory_set.strdup_strings = 1;
+	o->virtual_id = 1;
 }
diff --git a/merge-recursive.h b/merge-recursive.h
index fd138ca..bc23fe0 100644
--- a/merge-recursive.h
+++ b/merge-recursive.h
@@ -15,6 +15,7 @@ struct merge_options {
 	struct strbuf obuf;
 	struct string_list current_file_set;
 	struct string_list current_directory_set;
+	unsigned virtual_id;
 };
 
 /* merge_trees() but with recursive ancestor consolidation */
-- 
1.6.0.1
Previous: Miklos VajnaNext: Junio C Hamano
Message 12 of 15 in “Move call_depth and index_only to struct merge_options”
  1. 0/2 Move call_depth and index_only to struct merge_optionsMiklos Vajna, Sep 2, 2008
  2. 1/2 merge-recursive: move call_depth to struct merge_optionsMiklos Vajna, Sep 2, 2008
  3. 2/2 merge-recursive: move index_only to struct merge_optionsMiklos Vajna, Sep 2, 2008
  4. Makefile: add merge_recursive.h to LIB_HMiklos Vajna, Sep 2, 2008
  5. Junio C HamanoSep 2, 2008
  6. Makefile: add merge_recursive.h to LIB_HMiklos Vajna, Sep 2, 2008
  7. Junio C HamanoSep 2, 2008
  8. merge-recursive: get rid of the index_only global variableMiklos Vajna, Sep 3, 2008
  9. merge-recursive: move the global obuf to struct merge_optionsMiklos Vajna, Sep 3, 2008
  10. Miklos VajnaSep 3, 2008
  11. 1/2 merge-recursive: move current_{file,directory}_set to struct merge_optionsMiklos Vajna, Sep 3, 2008
  12. 2/2 merge-recursive: move make_virtual_commit()'s virtual_id to merge_optionsMiklos Vajna, Sep 3, 2008
  13. Junio C HamanoSep 4, 2008
  14. merge-recursive: get rid of virtual_idMiklos Vajna, Sep 5, 2008
  15. Junio C HamanoSep 4, 2008

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.