Skip to contentSkip to conversation

Moving global state into the repository object

RFC PATCH In review Stefan Beller 10 participants 239 messages Feb 5, 2018 – Feb 14, 2018 Kbuild Page 2 of 3

lore
Share & tools
lore
#117 lore raw

PATCH 85/194 tree: add repository argument to lookup_tree

In reply to Stefan Beller

Add a repository argument to allow the callers of lookup_tree to be more specific about which repository to act on. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet.

As with the previous commits, use a macro to catch callers passing a repository other than the_repository at compile time.

Add the cocci patch that converted the callers.

---
 builtin/am.c                           | 6 ++++--
 builtin/diff-tree.c                    | 2 +-
 builtin/diff.c                         | 3 ++-
 builtin/reflog.c                       | 2 +-
 cache-tree.c                           | 3 ++-
 commit.c                               | 2 +-
 contrib/coccinelle/object_parser.cocci | 8 ++++++++
 fsck.c                                 | 2 +-
 http-push.c                            | 3 ++-
 list-objects.c                         | 2 +-
 merge-recursive.c                      | 6 +++---
 object.c                               | 2 +-
 reachable.c                            | 2 +-
 revision.c                             | 4 ++--
 sequencer.c                            | 2 +-
 tag.c                                  | 2 +-
 tree.c                                 | 4 ++--
 tree.h                                 | 3 ++-
 walker.c                               | 3 ++-
 19 files changed, 38 insertions(+), 23 deletions(-)
builtin/am.c +4 -2
index acfe9d3c8c..32002a8661 100644
@@ -32,6 +32,7 @@
 #include "apply.h"
 #include "string-list.h"
 #include "packfile.h"
+#include "repository.h"
 
 /**
  * Returns 1 if the file is empty or does not exist, 0 otherwise.
@@ -1398,9 +1399,10 @@ static void write_index_patch(const struct am_state *state)
 	FILE *fp;
 
 	if (!get_oid_tree("HEAD", &head))
-		tree = lookup_tree(&head);
+		tree = lookup_tree(the_repository, &head);
 	else
-		tree = lookup_tree(the_hash_algo->empty_tree);
+		tree = lookup_tree(the_repository,
+				   the_repository->hash_algo->empty_tree);
 
 	fp = xfopen(am_path(state, "patch"), "w");
 	init_revisions(&rev_info, NULL);
builtin/diff-tree.c +1 -1
index 1f78308e33..ab491efa9e 100644
@@ -46,7 +46,7 @@ static int stdin_diff_trees(struct tree *tree1, const char *p)
 	struct tree *tree2;
 	if (!isspace(*p++) || parse_oid_hex(p, &oid, &p) || *p)
 		return error("Need exactly two trees, separated by a space");
-	tree2 = lookup_tree(&oid);
+	tree2 = lookup_tree(the_repository, &oid);
 	if (!tree2 || parse_tree(tree2))
 		return -1;
 	printf("%s %s\n", oid_to_hex(&tree1->object.oid),
builtin/diff.c +2 -1
index ed6092ef1a..0b7d0d612d 100644
@@ -379,7 +379,8 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
 				add_head_to_pending(&rev);
 				if (!rev.pending.nr) {
 					struct tree *tree;
-					tree = lookup_tree(the_hash_algo->empty_tree);
+					tree = lookup_tree(the_repository,
+							   the_repository->hash_algo->empty_tree);
 					add_pending_object(&rev, &tree->object, "HEAD");
 				}
 				break;
builtin/reflog.c +1 -1
index 18145d5494..335525bb15 100644
@@ -65,7 +65,7 @@ static int tree_is_complete(const struct object_id *oid)
 	int complete;
 	struct tree *tree;
 
-	tree = lookup_tree(oid);
+	tree = lookup_tree(the_repository, oid);
 	if (!tree)
 		return 0;
 	if (tree->object.flags & SEEN)
cache-tree.c +2 -1
index 2a98b15b92..75ff93abc7 100644
@@ -671,7 +671,8 @@ static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
 			cnt++;
 		else {
 			struct cache_tree_sub *sub;
-			struct tree *subtree = lookup_tree(entry.oid);
+			struct tree *subtree = lookup_tree(the_repository,
+							   entry.oid);
 			if (!subtree->object.parsed)
 				parse_tree(subtree);
 			sub = cache_tree_sub(it, entry.path);
commit.c +1 -1
index 68967e6c59..253a906124 100644
@@ -339,7 +339,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
 	if (get_sha1_hex(bufptr + 5, parent.hash) < 0)
 		return error("bad tree pointer in commit %s",
 			     oid_to_hex(&item->object.oid));
-	item->tree = lookup_tree(&parent);
+	item->tree = lookup_tree(the_repository, &parent);
 	bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */
 	pptr = &item->parents;
 
contrib/coccinelle/object_parser.cocci +8 -0
index 3bc38d2faa..e5ce73fe13 100644
@@ -5,6 +5,14 @@ expression E;
 +the_repository,
  E)
 
+@@
+expression E;
+@@
+ lookup_tree(
++the_repository,
+ E)
+
+
 @@
 expression E;
 @@
fsck.c +1 -1
index 6d04981735..54943b7dee 100644
@@ -360,7 +360,7 @@ static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *op
 			continue;
 
 		if (S_ISDIR(entry.mode)) {
-			obj = (struct object *)lookup_tree(entry.oid);
+			obj = (struct object *)lookup_tree(the_repository, entry.oid);
 			if (name && obj)
 				put_object_name(options, obj, "%s%s/", name,
 					entry.path);
http-push.c +2 -1
index 6c60b12ad1..83117770a3 100644
@@ -1307,7 +1307,8 @@ static struct object_list **process_tree(struct tree *tree,
 	while (tree_entry(&desc, &entry))
 		switch (object_type(entry.mode)) {
 		case OBJ_TREE:
-			p = process_tree(lookup_tree(entry.oid), p);
+			p = process_tree(lookup_tree(the_repository, entry.oid),
+					 p);
 			break;
 		case OBJ_BLOB:
 			p = process_blob(lookup_blob(the_repository, entry.oid),
list-objects.c +1 -1
index c11dc1281b..0db8fc15c2 100644
@@ -130,7 +130,7 @@ static void process_tree(struct rev_info *revs,
 
 		if (S_ISDIR(entry.mode))
 			process_tree(revs,
-				     lookup_tree(entry.oid),
+				     lookup_tree(the_repository, entry.oid),
 				     show, base, entry.path,
 				     cb_data, filter_fn, filter_data);
 		else if (S_ISGITLINK(entry.mode))
merge-recursive.c +3 -3
index e2c434c305..181ab36c36 100644
@@ -95,7 +95,7 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two,
 	}
 	if (!oidcmp(&two->object.oid, &shifted))
 		return two;
-	return lookup_tree(&shifted);
+	return lookup_tree(the_repository, &shifted);
 }
 
 static struct commit *make_virtual_commit(struct tree *tree, const char *comment)
@@ -332,7 +332,7 @@ struct tree *write_tree_from_memory(struct merge_options *o)
 		return NULL;
 	}
 
-	result = lookup_tree(&active_cache_tree->oid);
+	result = lookup_tree(the_repository, &active_cache_tree->oid);
 
 	return result;
 }
@@ -2091,7 +2091,7 @@ int merge_recursive(struct merge_options *o,
 		/* if there is no common ancestor, use an empty tree */
 		struct tree *tree;
 
-		tree = lookup_tree(the_hash_algo->empty_tree);
+		tree = lookup_tree(the_repository, the_repository->hash_algo->empty_tree);
 		merged_common_ancestors = make_virtual_commit(tree, "ancestor");
 	}
 
object.c +1 -1
index e0dac087c8..5ddbe91a38 100644
@@ -197,7 +197,7 @@ struct object *parse_object_buffer(const struct object_id *oid, enum object_type
 			obj = &blob->object;
 		}
 	} else if (type == OBJ_TREE) {
-		struct tree *tree = lookup_tree(oid);
+		struct tree *tree = lookup_tree(the_repository, oid);
 		if (tree) {
 			obj = &tree->object;
 			if (!tree->buffer)
reachable.c +1 -1
index 943e4518c2..44a9328c0e 100644
@@ -89,7 +89,7 @@ static void add_recent_object(const struct object_id *oid,
 		obj = parse_object_or_die(oid, NULL);
 		break;
 	case OBJ_TREE:
-		obj = (struct object *)lookup_tree(oid);
+		obj = (struct object *)lookup_tree(the_repository, oid);
 		break;
 	case OBJ_BLOB:
 		obj = (struct object *)lookup_blob(the_repository, oid);
revision.c +2 -2
index a7b57e3452..629af0dca5 100644
@@ -64,7 +64,7 @@ static void mark_tree_contents_uninteresting(struct tree *tree)
 	while (tree_entry(&desc, &entry)) {
 		switch (object_type(entry.mode)) {
 		case OBJ_TREE:
-			mark_tree_uninteresting(lookup_tree(entry.oid));
+			mark_tree_uninteresting(lookup_tree(the_repository, entry.oid));
 			break;
 		case OBJ_BLOB:
 			mark_blob_uninteresting(lookup_blob(the_repository, entry.oid));
@@ -1295,7 +1295,7 @@ static void add_cache_tree(struct cache_tree *it, struct rev_info *revs,
 	int i;
 
 	if (it->entry_count >= 0) {
-		struct tree *tree = lookup_tree(&it->oid);
+		struct tree *tree = lookup_tree(the_repository, &it->oid);
 		add_pending_object_with_path(revs, &tree->object, "",
 					     040000, path->buf);
 	}
sequencer.c +1 -1
index 311f00acda..6533b97138 100644
@@ -349,7 +349,7 @@ static int read_oneliner(struct strbuf *buf,
 
 static struct tree *empty_tree(void)
 {
-	return lookup_tree(the_hash_algo->empty_tree);
+	return lookup_tree(the_repository, the_repository->hash_algo->empty_tree);
 }
 
 static int error_dirty_index(struct replay_opts *opts)
tag.c +1 -1
index 4cf449303b..ba1df1c695 100644
@@ -148,7 +148,7 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
 	if (!strcmp(type, blob_type)) {
 		item->tagged = (struct object *)lookup_blob(the_repository, &oid);
 	} else if (!strcmp(type, tree_type)) {
-		item->tagged = (struct object *)lookup_tree(&oid);
+		item->tagged = (struct object *)lookup_tree(the_repository, &oid);
 	} else if (!strcmp(type, commit_type)) {
 		item->tagged = (struct object *)lookup_commit(&oid);
 	} else if (!strcmp(type, tag_type)) {
tree.c +2 -2
index 8f0ee6c8c0..b0d8610c41 100644
@@ -119,7 +119,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
 		len = tree_entry_len(&entry);
 		strbuf_add(base, entry.path, len);
 		strbuf_addch(base, '/');
-		retval = read_tree_1(lookup_tree(&oid),
+		retval = read_tree_1(lookup_tree(the_repository, &oid),
 				     base, stage, pathspec,
 				     fn, context);
 		strbuf_setlen(base, oldlen);
@@ -194,7 +194,7 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match,
 	return 0;
 }
 
-struct tree *lookup_tree(const struct object_id *oid)
+struct tree *lookup_tree_the_repository(const struct object_id *oid)
 {
 	struct object *obj = lookup_object(the_repository, oid->hash);
 	if (!obj)
tree.h +2 -1
index 744e6dc2ac..8195db473f 100644
@@ -12,7 +12,8 @@ struct tree {
 	unsigned long size;
 };
 
-struct tree *lookup_tree(const struct object_id *oid);
+#define lookup_tree(r, oid) lookup_tree_##r(oid)
+struct tree *lookup_tree_the_repository(const struct object_id *oid);
 
 int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size);
 
walker.c +2 -1
index f5a221d48e..5cfd2316a8 100644
@@ -49,7 +49,8 @@ static int process_tree(struct walker *walker, struct tree *tree)
 		if (S_ISGITLINK(entry.mode))
 			continue;
 		if (S_ISDIR(entry.mode)) {
-			struct tree *tree = lookup_tree(entry.oid);
+			struct tree *tree = lookup_tree(the_repository,
+							entry.oid);
 			if (tree)
 				obj = &tree->object;
 		}
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#118 lore raw

PATCH 86/194 tag: add repository argument to lookup_tag

In reply to Stefan Beller

Add a repository argument to allow the callers of lookup_tag to be more specific about which repository to act on. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet.

As with the previous commits, use a macro to catch callers passing a repository other than the_repository at compile time.

Add the cocci patch that converted the callers.

---
 builtin/describe.c                     | 6 +++---
 builtin/pack-objects.c                 | 2 +-
 builtin/replace.c                      | 2 +-
 contrib/coccinelle/object_parser.cocci | 7 +++++++
 log-tree.c                             | 2 +-
 object.c                               | 2 +-
 sha1_name.c                            | 2 +-
 tag.c                                  | 4 ++--
 tag.h                                  | 4 ++--
 9 files changed, 19 insertions(+), 12 deletions(-)
builtin/describe.c +3 -3
index 2add1e8d83..2589872322 100644
@@ -88,13 +88,13 @@ static int replace_name(struct commit_name *e,
 		struct tag *t;
 
 		if (!e->tag) {
-			t = lookup_tag(&e->oid);
+			t = lookup_tag(the_repository, &e->oid);
 			if (!t || parse_tag(t))
 				return 1;
 			e->tag = t;
 		}
 
-		t = lookup_tag(oid);
+		t = lookup_tag(the_repository, oid);
 		if (!t || parse_tag(t))
 			return 0;
 		*tag = t;
@@ -262,7 +262,7 @@ static unsigned long finish_depth_computation(
 static void append_name(struct commit_name *n, struct strbuf *dst)
 {
 	if (n->prio == 2 && !n->tag) {
-		n->tag = lookup_tag(&n->oid);
+		n->tag = lookup_tag(the_repository, &n->oid);
 		if (!n->tag || parse_tag(n->tag))
 			die(_("annotated tag %s not available"), n->path);
 	}
builtin/pack-objects.c +1 -1
index 4e59e496dc..6348a5e721 100644
@@ -2371,7 +2371,7 @@ static void add_tag_chain(const struct object_id *oid)
 	if (packlist_find(&to_pack, oid->hash, NULL))
 		return;
 
-	tag = lookup_tag(oid);
+	tag = lookup_tag(the_repository, oid);
 	while (1) {
 		if (!tag || parse_tag(tag) || !tag->tagged)
 			die("unable to pack objects reachable from tag %s",
builtin/replace.c +1 -1
index 25322d2f73..b79dd15fdb 100644
@@ -360,7 +360,7 @@ static void check_one_mergetag(struct commit *commit,
 	int i;
 
 	hash_sha1_file(extra->value, extra->len, typename(OBJ_TAG), tag_oid.hash);
-	tag = lookup_tag(&tag_oid);
+	tag = lookup_tag(the_repository, &tag_oid);
 	if (!tag)
 		die(_("bad mergetag in commit '%s'"), ref);
 	if (parse_tag_buffer(tag, extra->value, extra->len))
contrib/coccinelle/object_parser.cocci +7 -0
index e5ce73fe13..8b9b1c717a 100644
@@ -13,6 +13,13 @@ expression E;
  E)
 
 
+@@
+expression E;
+@@
+ lookup_tag(
++the_repository,
+ E)
+
 @@
 expression E;
 @@
log-tree.c +1 -1
index 57d5e5f56d..ff64a61e57 100644
@@ -502,7 +502,7 @@ static void show_one_mergetag(struct commit *commit,
 	size_t payload_size, gpg_message_offset;
 
 	hash_sha1_file(extra->value, extra->len, typename(OBJ_TAG), oid.hash);
-	tag = lookup_tag(&oid);
+	tag = lookup_tag(the_repository, &oid);
 	if (!tag)
 		return; /* error message already given */
 
object.c +1 -1
index 5ddbe91a38..5ebbb32a92 100644
@@ -220,7 +220,7 @@ struct object *parse_object_buffer(const struct object_id *oid, enum object_type
 			obj = &commit->object;
 		}
 	} else if (type == OBJ_TAG) {
-		struct tag *tag = lookup_tag(oid);
+		struct tag *tag = lookup_tag(the_repository, oid);
 		if (tag) {
 			if (parse_tag_buffer(tag, buffer, size))
 			       return NULL;
sha1_name.c +1 -1
index 0139b480a3..717b31359a 100644
@@ -379,7 +379,7 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)
 			format_commit_message(commit, " %ad - %s", &desc, &pp);
 		}
 	} else if (type == OBJ_TAG) {
-		struct tag *tag = lookup_tag(oid);
+		struct tag *tag = lookup_tag(the_repository, oid);
 		if (!parse_tag(tag) && tag->tag)
 			strbuf_addf(&desc, " %s", tag->tag);
 	}
tag.c +2 -2
index ba1df1c695..8935f3c8c9 100644
@@ -92,7 +92,7 @@ struct object *deref_tag_noverify(struct object *o)
 	return o;
 }
 
-struct tag *lookup_tag(const struct object_id *oid)
+struct tag *lookup_tag_the_repository(const struct object_id *oid)
 {
 	struct object *obj = lookup_object(the_repository, oid->hash);
 	if (!obj)
@@ -152,7 +152,7 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
 	} else if (!strcmp(type, commit_type)) {
 		item->tagged = (struct object *)lookup_commit(&oid);
 	} else if (!strcmp(type, tag_type)) {
-		item->tagged = (struct object *)lookup_tag(&oid);
+		item->tagged = (struct object *)lookup_tag(the_repository, &oid);
 	} else {
 		error("Unknown type %s", type);
 		item->tagged = NULL;
tag.h +2 -2
index d469534e82..97d58ebf7b 100644
@@ -11,8 +11,8 @@ struct tag {
 	char *tag;
 	timestamp_t date;
 };
-
-extern struct tag *lookup_tag(const struct object_id *oid);
+#define lookup_tag(r, o) lookup_tag_##r(o)
+extern struct tag *lookup_tag_the_repository(const struct object_id *oid);
 extern int parse_tag_buffer(struct tag *item, const void *data, unsigned long size);
 extern int parse_tag(struct tag *item);
 extern struct object *deref_tag(struct object *, const char *, int);
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#119 lore raw

PATCH 87/194 tag: add repository argument to parse_tag_buffer

In reply to Stefan Beller

Add a repository argument to allow the callers of parse_tag_buffer to be more specific about which repository to act on. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet.

As with the previous commits, use a macro to catch callers passing a repository other than the_repository at compile time.

Add the cocci patch that converted the callers.

---
 builtin/replace.c                      | 2 +-
 contrib/coccinelle/object_parser.cocci | 9 +++++++++
 log-tree.c                             | 2 +-
 object.c                               | 2 +-
 sha1_file.c                            | 2 +-
 tag.c                                  | 4 ++--
 tag.h                                  | 3 ++-
 7 files changed, 17 insertions(+), 7 deletions(-)
builtin/replace.c +1 -1
index b79dd15fdb..d1a939c17b 100644
@@ -363,7 +363,7 @@ static void check_one_mergetag(struct commit *commit,
 	tag = lookup_tag(the_repository, &tag_oid);
 	if (!tag)
 		die(_("bad mergetag in commit '%s'"), ref);
-	if (parse_tag_buffer(tag, extra->value, extra->len))
+	if (parse_tag_buffer(the_repository, tag, extra->value, extra->len))
 		die(_("malformed mergetag in commit '%s'"), ref);
 
 	/* iterate over new parents */
contrib/coccinelle/object_parser.cocci +9 -0
index 8b9b1c717a..0e2ebdfccb 100644
@@ -20,6 +20,15 @@ expression E;
 +the_repository,
  E)
 
+@@
+expression E;
+expression F;
+expression G;
+@@
+ parse_tag_buffer(
++the_repository,
+ E, F, G)
+
 @@
 expression E;
 @@
log-tree.c +1 -1
index ff64a61e57..1137506884 100644
@@ -507,7 +507,7 @@ static void show_one_mergetag(struct commit *commit,
 		return; /* error message already given */
 
 	strbuf_init(&verify_message, 256);
-	if (parse_tag_buffer(tag, extra->value, extra->len))
+	if (parse_tag_buffer(the_repository, tag, extra->value, extra->len))
 		strbuf_addstr(&verify_message, "malformed mergetag\n");
 	else if (is_common_merge(commit) &&
 		 !oidcmp(&tag->tagged->oid,
object.c +1 -1
index 5ebbb32a92..c9ce89cf37 100644
@@ -222,7 +222,7 @@ struct object *parse_object_buffer(const struct object_id *oid, enum object_type
 	} else if (type == OBJ_TAG) {
 		struct tag *tag = lookup_tag(the_repository, oid);
 		if (tag) {
-			if (parse_tag_buffer(tag, buffer, size))
+			if (parse_tag_buffer(the_repository, tag, buffer, size))
 			       return NULL;
 			obj = &tag->object;
 		}
sha1_file.c +1 -1
index c296b76329..df8bd4c260 100644
@@ -1759,7 +1759,7 @@ static void check_tag(const void *buf, size_t size)
 {
 	struct tag t;
 	memset(&t, 0, sizeof(t));
-	if (parse_tag_buffer(&t, buf, size))
+	if (parse_tag_buffer(the_repository, &t, buf, size))
 		die("corrupt tag");
 }
 
tag.c +2 -2
index 8935f3c8c9..7ff9943847 100644
@@ -118,7 +118,7 @@ static timestamp_t parse_tag_date(const char *buf, const char *tail)
 	return parse_timestamp(dateptr, NULL, 10);
 }
 
-int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
+int parse_tag_buffer_the_repository(struct tag *item, const void *data, unsigned long size)
 {
 	struct object_id oid;
 	char type[20];
@@ -195,7 +195,7 @@ int parse_tag(struct tag *item)
 		return error("Object %s not a tag",
 			     oid_to_hex(&item->object.oid));
 	}
-	ret = parse_tag_buffer(item, data, size);
+	ret = parse_tag_buffer(the_repository, item, data, size);
 	free(data);
 	return ret;
 }
tag.h +2 -1
index 97d58ebf7b..31498e788a 100644
@@ -13,7 +13,8 @@ struct tag {
 };
 #define lookup_tag(r, o) lookup_tag_##r(o)
 extern struct tag *lookup_tag_the_repository(const struct object_id *oid);
-extern int parse_tag_buffer(struct tag *item, const void *data, unsigned long size);
+#define parse_tag_buffer(r, i, d, s) parse_tag_buffer_##r(i, d, s)
+extern int parse_tag_buffer_the_repository(struct tag *item, const void *data, unsigned long size);
 extern int parse_tag(struct tag *item);
 extern struct object *deref_tag(struct object *, const char *, int);
 extern struct object *deref_tag_noverify(struct object *);
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#120 lore raw

PATCH 88/194 tag: add repository argument to deref_tag

In reply to Stefan Beller

Add a repository argument to allow the callers of deref_tag to be more specific about which repository to act on. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet.

As with the previous commits, use a macro to catch callers passing a repository other than the_repository at compile time.

Add the cocci patch that converted the callers.

---
 blame.c                                |  6 +++---
 builtin/diff.c                         |  2 +-
 builtin/fmt-merge-msg.c                |  3 ++-
 builtin/grep.c                         |  3 ++-
 builtin/name-rev.c                     |  3 ++-
 commit.c                               |  3 ++-
 contrib/coccinelle/object_parser.cocci |  9 +++++++++
 fetch-pack.c                           |  9 ++++++---
 http-backend.c                         |  2 +-
 http-push.c                            |  2 +-
 line-log.c                             |  2 +-
 merge-recursive.c                      |  3 ++-
 remote.c                               |  6 ++++--
 server-info.c                          |  2 +-
 sha1_name.c                            | 11 +++++++----
 shallow.c                              |  4 +++-
 tag.c                                  |  2 +-
 tag.h                                  |  3 ++-
 upload-pack.c                          |  2 +-
 19 files changed, 51 insertions(+), 26 deletions(-)
blame.c +3 -3
index f95a53898d..02cd0ba498 100644
@@ -1655,7 +1655,7 @@ static struct commit *find_single_final(struct rev_info *revs,
 		struct object *obj = revs->pending.objects[i].item;
 		if (obj->flags & UNINTERESTING)
 			continue;
-		obj = deref_tag(obj, NULL, 0);
+		obj = deref_tag(the_repository, obj, NULL, 0);
 		if (obj->type != OBJ_COMMIT)
 			die("Non commit %s?", revs->pending.objects[i].name);
 		if (found)
@@ -1686,7 +1686,7 @@ static struct commit *dwim_reverse_initial(struct rev_info *revs,
 
 	/* Is that sole rev a committish? */
 	obj = revs->pending.objects[0].item;
-	obj = deref_tag(obj, NULL, 0);
+	obj = deref_tag(the_repository, obj, NULL, 0);
 	if (obj->type != OBJ_COMMIT)
 		return NULL;
 
@@ -1721,7 +1721,7 @@ static struct commit *find_single_initial(struct rev_info *revs,
 		struct object *obj = revs->pending.objects[i].item;
 		if (!(obj->flags & UNINTERESTING))
 			continue;
-		obj = deref_tag(obj, NULL, 0);
+		obj = deref_tag(the_repository, obj, NULL, 0);
 		if (obj->type != OBJ_COMMIT)
 			die("Non commit %s?", revs->pending.objects[i].name);
 		if (found)
builtin/diff.c +1 -1
index 0b7d0d612d..1dd7dd4a26 100644
@@ -395,7 +395,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
 		int flags = (obj->flags & UNINTERESTING);
 		if (!obj->parsed)
 			obj = parse_object(the_repository, &obj->oid);
-		obj = deref_tag(obj, NULL, 0);
+		obj = deref_tag(the_repository, obj, NULL, 0);
 		if (!obj)
 			die(_("invalid object '%s' given."), name);
 		if (obj->type == OBJ_COMMIT)
builtin/fmt-merge-msg.c +2 -1
index dd74251690..49fd7ea1d2 100644
@@ -344,7 +344,8 @@ static void shortlog(const char *name,
 	const struct object_id *oid = &origin_data->oid;
 	int limit = opts->shortlog_len;
 
-	branch = deref_tag(parse_object(the_repository, oid), oid_to_hex(oid),
+	branch = deref_tag(the_repository, parse_object(the_repository, oid),
+			   oid_to_hex(oid),
 			   GIT_SHA1_HEXSZ);
 	if (!branch || branch->type != OBJ_COMMIT)
 		return;
builtin/grep.c +2 -1
index 1c71dff341..2c43307f02 100644
@@ -641,7 +641,8 @@ static int grep_objects(struct grep_opt *opt, const struct pathspec *pathspec,
 
 	for (i = 0; i < nr; i++) {
 		struct object *real_obj;
-		real_obj = deref_tag(list->objects[i].item, NULL, 0);
+		real_obj = deref_tag(the_repository, list->objects[i].item,
+				     NULL, 0);
 
 		/* load the gitmodules file for this rev */
 		if (recurse_submodules) {
builtin/name-rev.c +2 -1
index 45ec5515cc..2cbb702c2c 100644
@@ -438,7 +438,8 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
 		commit = NULL;
 		object = parse_object(the_repository, &oid);
 		if (object) {
-			struct object *peeled = deref_tag(object, *argv, 0);
+			struct object *peeled = deref_tag(the_repository,
+							  object, *argv, 0);
 			if (peeled && peeled->type == OBJ_COMMIT)
 				commit = (struct commit *)peeled;
 		}
commit.c +2 -1
index 253a906124..1b0e37f6f0 100644
@@ -23,7 +23,8 @@ const char *commit_type = "commit";
 struct commit *lookup_commit_reference_gently(const struct object_id *oid,
 					      int quiet)
 {
-	struct object *obj = deref_tag(parse_object(the_repository, oid),
+	struct object *obj = deref_tag(the_repository,
+				       parse_object(the_repository, oid),
 				       NULL, 0);
 
 	if (!obj)
contrib/coccinelle/object_parser.cocci +9 -0
index 0e2ebdfccb..7ddd9f11ce 100644
@@ -29,6 +29,15 @@ expression G;
 +the_repository,
  E, F, G)
 
+@@
+expression E;
+expression F;
+expression G;
+@@
+ deref_tag(
++the_repository,
+ E, F, G)
+
 @@
 expression E;
 @@
fetch-pack.c +6 -3
index 02ac850967..ee1e65688a 100644
@@ -124,7 +124,8 @@ static void rev_list_push(struct commit *commit, int mark)
 
 static int rev_list_insert_ref(const char *refname, const struct object_id *oid)
 {
-	struct object *o = deref_tag(parse_object(the_repository, oid),
+	struct object *o = deref_tag(the_repository,
+				     parse_object(the_repository, oid),
 				     refname, 0);
 
 	if (o && o->type == OBJ_COMMIT)
@@ -142,7 +143,8 @@ static int rev_list_insert_ref_oid(const char *refname, const struct object_id *
 static int clear_marks(const char *refname, const struct object_id *oid,
 		       int flag, void *cb_data)
 {
-	struct object *o = deref_tag(parse_object(the_repository, oid),
+	struct object *o = deref_tag(the_repository,
+				     parse_object(the_repository, oid),
 				     refname, 0);
 
 	if (o && o->type == OBJ_COMMIT)
@@ -751,7 +753,8 @@ static int everything_local(struct fetch_pack_args *args,
 	 * Don't mark them common yet; the server has to be told so first.
 	 */
 	for (ref = *refs; ref; ref = ref->next) {
-		struct object *o = deref_tag(lookup_object(the_repository, ref->old_oid.hash),
+		struct object *o = deref_tag(the_repository,
+					     lookup_object(the_repository, ref->old_oid.hash),
 					     NULL, 0);
 
 		if (!o || o->type != OBJ_COMMIT || !(o->flags & COMPLETE))
http-backend.c +1 -1
index b76c8c4f3d..609faf93d4 100644
@@ -441,7 +441,7 @@ static int show_text_ref(const char *name, const struct object_id *oid,
 
 	strbuf_addf(buf, "%s\t%s\n", oid_to_hex(oid), name_nons);
 	if (o->type == OBJ_TAG) {
-		o = deref_tag(o, name, 0);
+		o = deref_tag(the_repository, o, name, 0);
 		if (!o)
 			return 0;
 		strbuf_addf(buf, "%s\t%s^{}\n", oid_to_hex(&o->oid),
http-push.c +1 -1
index 83117770a3..de5e70ea7b 100644
@@ -1473,7 +1473,7 @@ static void add_remote_info_ref(struct remote_ls_ctx *ls)
 		    oid_to_hex(&ref->old_oid), ls->dentry_name);
 
 	if (o->type == OBJ_TAG) {
-		o = deref_tag(o, ls->dentry_name, 0);
+		o = deref_tag(the_repository, o, ls->dentry_name, 0);
 		if (o)
 			strbuf_addf(buf, "%s\t%s^{}\n",
 				    oid_to_hex(&o->oid), ls->dentry_name);
line-log.c +1 -1
index 545ad0f28b..653c7279f3 100644
@@ -479,7 +479,7 @@ static struct commit *check_single_commit(struct rev_info *revs)
 		struct object *obj = revs->pending.objects[i].item;
 		if (obj->flags & UNINTERESTING)
 			continue;
-		obj = deref_tag(obj, NULL, 0);
+		obj = deref_tag(the_repository, obj, NULL, 0);
 		if (obj->type != OBJ_COMMIT)
 			die("Non commit %s?", revs->pending.objects[i].name);
 		if (commit)
merge-recursive.c +2 -1
index 181ab36c36..8b6984cdd7 100644
@@ -2152,7 +2152,8 @@ static struct commit *get_ref(const struct object_id *oid, const char *name)
 {
 	struct object *object;
 
-	object = deref_tag(parse_object(the_repository, oid), name,
+	object = deref_tag(the_repository, parse_object(the_repository, oid),
+			   name,
 			   strlen(name));
 	if (!object)
 		return NULL;
remote.c +4 -2
index 2abc6baf84..8d84e26dd4 100644
@@ -1980,12 +1980,14 @@ int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid)
 	 * Both new and old must be commit-ish and new is descendant of
 	 * old.  Otherwise we require --force.
 	 */
-	o = deref_tag(parse_object(the_repository, old_oid), NULL, 0);
+	o = deref_tag(the_repository, parse_object(the_repository, old_oid),
+		      NULL, 0);
 	if (!o || o->type != OBJ_COMMIT)
 		return 0;
 	old = (struct commit *) o;
 
-	o = deref_tag(parse_object(the_repository, new_oid), NULL, 0);
+	o = deref_tag(the_repository, parse_object(the_repository, new_oid),
+		      NULL, 0);
 	if (!o || o->type != OBJ_COMMIT)
 		return 0;
 	new = (struct commit *) o;
server-info.c +1 -1
index fd7ed2a383..ee4491b73a 100644
@@ -64,7 +64,7 @@ static int add_info_ref(const char *path, const struct object_id *oid,
 		return -1;
 
 	if (o->type == OBJ_TAG) {
-		o = deref_tag(o, path, 0);
+		o = deref_tag(the_repository, o, path, 0);
 		if (o)
 			if (fprintf(fp, "%s	%s^{}\n",
 				oid_to_hex(&o->oid), path) < 0)
sha1_name.c +7 -4
index 717b31359a..117c080fd4 100644
@@ -259,7 +259,8 @@ static int disambiguate_committish_only(const struct object_id *oid, void *cb_da
 		return 0;
 
 	/* We need to do this the hard way... */
-	obj = deref_tag(parse_object(the_repository, oid), NULL, 0);
+	obj = deref_tag(the_repository, parse_object(the_repository, oid),
+			NULL, 0);
 	if (obj && obj->type == OBJ_COMMIT)
 		return 1;
 	return 0;
@@ -283,7 +284,8 @@ static int disambiguate_treeish_only(const struct object_id *oid, void *cb_data_
 		return 0;
 
 	/* We need to do this the hard way... */
-	obj = deref_tag(parse_object(the_repository, oid), NULL, 0);
+	obj = deref_tag(the_repository, parse_object(the_repository, oid),
+			NULL, 0);
 	if (obj && (obj->type == OBJ_TREE || obj->type == OBJ_COMMIT))
 		return 1;
 	return 0;
@@ -971,7 +973,7 @@ static int peel_onion(const char *name, int len, struct object_id *oid,
 	if (!o)
 		return -1;
 	if (!expected_type) {
-		o = deref_tag(o, name, sp - name - 2);
+		o = deref_tag(the_repository, o, name, sp - name - 2);
 		if (!o || (!o->parsed && !parse_object(the_repository, &o->oid)))
 			return -1;
 		oidcpy(oid, &o->oid);
@@ -1103,7 +1105,8 @@ static int handle_one_ref(const char *path, const struct object_id *oid,
 	if (!object)
 		return 0;
 	if (object->type == OBJ_TAG) {
-		object = deref_tag(object, path, strlen(path));
+		object = deref_tag(the_repository, object, path,
+				   strlen(path));
 		if (!object)
 			return 0;
 	}
shallow.c +3 -1
index c2f81a5a5a..aa6d04992c 100644
@@ -89,7 +89,9 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
 		if (!commit) {
 			if (i < heads->nr) {
 				commit = (struct commit *)
-					deref_tag(heads->objects[i++].item, NULL, 0);
+					deref_tag(the_repository,
+						  heads->objects[i++].item,
+						  NULL, 0);
 				if (!commit || commit->object.type != OBJ_COMMIT) {
 					commit = NULL;
 					continue;
tag.c +1 -1
index 7ff9943847..d8174e0405 100644
@@ -64,7 +64,7 @@ int gpg_verify_tag(const struct object_id *oid, const char *name_to_report,
 	return ret;
 }
 
-struct object *deref_tag(struct object *o, const char *warn, int warnlen)
+struct object *deref_tag_the_repository(struct object *o, const char *warn, int warnlen)
 {
 	while (o && o->type == OBJ_TAG)
 		if (((struct tag *)o)->tagged)
tag.h +2 -1
index 31498e788a..4f45695e1e 100644
@@ -16,7 +16,8 @@ extern struct tag *lookup_tag_the_repository(const struct object_id *oid);
 #define parse_tag_buffer(r, i, d, s) parse_tag_buffer_##r(i, d, s)
 extern int parse_tag_buffer_the_repository(struct tag *item, const void *data, unsigned long size);
 extern int parse_tag(struct tag *item);
-extern struct object *deref_tag(struct object *, const char *, int);
+#define deref_tag(r, o, w, l) deref_tag_##r(o, w, l)
+extern struct object *deref_tag_the_repository(struct object *, const char *, int);
 extern struct object *deref_tag_noverify(struct object *);
 extern int gpg_verify_tag(const struct object_id *oid,
 		const char *name_to_report, unsigned flags);
upload-pack.c +1 -1
index 8716e28d4f..469a843669 100644
@@ -368,7 +368,7 @@ static int ok_to_give_up(void)
 
 		if (want->flags & COMMON_KNOWN)
 			continue;
-		want = deref_tag(want, "a want line", 0);
+		want = deref_tag(the_repository, want, "a want line", 0);
 		if (!want || want->type != OBJ_COMMIT) {
 			/* no way to tell if this is reachable by
 			 * looking at the ancestry chain alone, so
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#121 lore raw

PATCH 89/194 object: add repository argument to lookup_commit_reference_gently

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

Add a repository argument to allow callers of lookup_commit_reference_gently to be more specific about which repository to handle. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet.

As with the previous commits, use a macro to catch callers passing a repository other than the_repository at compile time.

The included coccinelle semantic patch will adapt any new callers in the diff produced by make coccicheck.

---
 archive.c                              |  2 +-
 blame.c                                |  3 ++-
 builtin/checkout.c                     |  7 ++++---
 builtin/describe.c                     |  5 +++--
 builtin/fetch.c                        |  9 ++++++---
 builtin/reflog.c                       | 10 ++++++----
 builtin/show-branch.c                  |  3 ++-
 commit.c                               |  9 +++++----
 commit.h                               |  5 ++++-
 contrib/coccinelle/object_parser.cocci |  8 ++++++++
 fast-import.c                          |  6 ++++--
 notes-cache.c                          |  3 ++-
 ref-filter.c                           |  6 ++++--
 remote.c                               |  9 +++++----
 sequencer.c                            |  2 +-
 sha1_name.c                            |  4 ++--
 shallow.c                              |  9 ++++++---
 walker.c                               |  3 ++-
 wt-status.c                            |  2 +-
 19 files changed, 68 insertions(+), 37 deletions(-)
archive.c +1 -1
index 9b47041a6c..2aeafe647d 100644
@@ -380,7 +380,7 @@ static void parse_treeish_arg(const char **argv,
 	if (get_oid(name, &oid))
 		die("Not a valid object name");
 
-	commit = lookup_commit_reference_gently(&oid, 1);
+	commit = lookup_commit_reference_gently(the_repository, &oid, 1);
 	if (commit) {
 		commit_sha1 = commit->object.oid.hash;
 		archive_time = commit->date;
blame.c +2 -1
index 02cd0ba498..98761c32d5 100644
@@ -1693,7 +1693,8 @@ static struct commit *dwim_reverse_initial(struct rev_info *revs,
 	/* Do we have HEAD? */
 	if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL))
 		return NULL;
-	head_commit = lookup_commit_reference_gently(&head_oid, 1);
+	head_commit = lookup_commit_reference_gently(the_repository,
+						     &head_oid, 1);
 	if (!head_commit)
 		return NULL;
 
builtin/checkout.c +4 -3
index c7271ed43f..cef2b4f2ad 100644
@@ -380,7 +380,7 @@ static int checkout_paths(const struct checkout_opts *opts,
 		die(_("unable to write new index file"));
 
 	read_ref_full("HEAD", 0, &rev, NULL);
-	head = lookup_commit_reference_gently(&rev, 1);
+	head = lookup_commit_reference_gently(the_repository, &rev, 1);
 
 	errs |= post_checkout_hook(head, head, 0);
 	return errs;
@@ -835,7 +835,8 @@ static int switch_branches(const struct checkout_opts *opts,
 	memset(&old, 0, sizeof(old));
 	old.path = path_to_free = resolve_refdup("HEAD", 0, &rev, &flag);
 	if (old.path)
-		old.commit = lookup_commit_reference_gently(&rev, 1);
+		old.commit = lookup_commit_reference_gently(the_repository,
+							    &rev, 1);
 	if (!(flag & REF_ISSYMREF))
 		old.path = NULL;
 
@@ -1009,7 +1010,7 @@ static int parse_branchname_arg(int argc, const char **argv,
 	else
 		new->path = NULL; /* not an existing branch */
 
-	new->commit = lookup_commit_reference_gently(rev, 1);
+	new->commit = lookup_commit_reference_gently(the_repository, rev, 1);
 	if (!new->commit) {
 		/* not a commit */
 		*source_tree = parse_tree_indirect(rev);
builtin/describe.c +3 -2
index 2589872322..f1172a8bf0 100644
@@ -320,7 +320,8 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst)
 		struct commit *c;
 		struct commit_name *n = hashmap_iter_first(&names, &iter);
 		for (; n; n = hashmap_iter_next(&iter)) {
-			c = lookup_commit_reference_gently(&n->peeled, 1);
+			c = lookup_commit_reference_gently(the_repository,
+							   &n->peeled, 1);
 			if (c)
 				c->util = n;
 		}
@@ -495,7 +496,7 @@ static void describe(const char *arg, int last_one)
 
 	if (get_oid(arg, &oid))
 		die(_("Not a valid object name %s"), arg);
-	cmit = lookup_commit_reference_gently(&oid, 1);
+	cmit = lookup_commit_reference_gently(the_repository, &oid, 1);
 
 	if (cmit)
 		describe_commit(&oid, &sb);
builtin/fetch.c +6 -3
index 276beebbb1..904496fa33 100644
@@ -660,8 +660,10 @@ static int update_local_ref(struct ref *ref,
 		return r;
 	}
 
-	current = lookup_commit_reference_gently(&ref->old_oid, 1);
-	updated = lookup_commit_reference_gently(&ref->new_oid, 1);
+	current = lookup_commit_reference_gently(the_repository,
+						 &ref->old_oid, 1);
+	updated = lookup_commit_reference_gently(the_repository,
+						 &ref->new_oid, 1);
 	if (!current || !updated) {
 		const char *msg;
 		const char *what;
@@ -794,7 +796,8 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
 				continue;
 			}
 
-			commit = lookup_commit_reference_gently(&rm->old_oid,
+			commit = lookup_commit_reference_gently(the_repository,
+								&rm->old_oid,
 								1);
 			if (!commit)
 				rm->fetch_head_status = FETCH_HEAD_NOT_FOR_MERGE;
builtin/reflog.c +6 -4
index 335525bb15..e12b99e9cb 100644
@@ -195,7 +195,7 @@ static int keep_entry(struct commit **it, struct object_id *oid)
 
 	if (is_null_oid(oid))
 		return 1;
-	commit = lookup_commit_reference_gently(oid, 1);
+	commit = lookup_commit_reference_gently(the_repository, oid, 1);
 	if (!commit)
 		return 0;
 
@@ -264,7 +264,8 @@ static int unreachable(struct expire_reflog_policy_cb *cb, struct commit *commit
 		if (is_null_oid(oid))
 			return 0;
 
-		commit = lookup_commit_reference_gently(oid, 1);
+		commit = lookup_commit_reference_gently(the_repository, oid,
+							1);
 
 		/* Not a commit -- keep it */
 		if (!commit)
@@ -321,7 +322,7 @@ static int push_tip_to_list(const char *refname, const struct object_id *oid,
 	struct commit *tip_commit;
 	if (flags & REF_ISSYMREF)
 		return 0;
-	tip_commit = lookup_commit_reference_gently(oid, 1);
+	tip_commit = lookup_commit_reference_gently(the_repository, oid, 1);
 	if (!tip_commit)
 		return 0;
 	commit_list_insert(tip_commit, list);
@@ -338,7 +339,8 @@ static void reflog_expiry_prepare(const char *refname,
 		cb->tip_commit = NULL;
 		cb->unreachable_expire_kind = UE_HEAD;
 	} else {
-		cb->tip_commit = lookup_commit_reference_gently(oid, 1);
+		cb->tip_commit = lookup_commit_reference_gently(the_repository,
+								oid, 1);
 		if (!cb->tip_commit)
 			cb->unreachable_expire_kind = UE_ALWAYS;
 		else
builtin/show-branch.c +2 -1
index e8a4aa40cb..fb90c9ab3e 100644
@@ -360,7 +360,8 @@ static void sort_ref_range(int bottom, int top)
 static int append_ref(const char *refname, const struct object_id *oid,
 		      int allow_dups)
 {
-	struct commit *commit = lookup_commit_reference_gently(oid, 1);
+	struct commit *commit = lookup_commit_reference_gently(the_repository,
+							       oid, 1);
 	int i;
 
 	if (!commit)
commit.c +5 -4
index 1b0e37f6f0..b6e253f1af 100644
@@ -20,8 +20,8 @@ int save_commit_buffer = 1;
 
 const char *commit_type = "commit";
 
-struct commit *lookup_commit_reference_gently(const struct object_id *oid,
-					      int quiet)
+struct commit *lookup_commit_reference_gently_the_repository(
+		const struct object_id *oid, int quiet)
 {
 	struct object *obj = deref_tag(the_repository,
 				       parse_object(the_repository, oid),
@@ -34,7 +34,7 @@ struct commit *lookup_commit_reference_gently(const struct object_id *oid,
 
 struct commit *lookup_commit_reference(const struct object_id *oid)
 {
-	return lookup_commit_reference_gently(oid, 0);
+	return lookup_commit_reference_gently(the_repository, oid, 0);
 }
 
 struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref_name)
@@ -571,7 +571,8 @@ void clear_commit_marks_for_object_array(struct object_array *a, unsigned mark)
 
 	for (i = 0; i < a->nr; i++) {
 		object = a->objects[i].item;
-		commit = lookup_commit_reference_gently(&object->oid, 1);
+		commit = lookup_commit_reference_gently(the_repository,
+							&object->oid, 1);
 		if (commit)
 			clear_commit_marks(commit, mark);
 	}
commit.h +4 -1
index 8c68ca1a5a..2ce5597066 100644
@@ -48,7 +48,10 @@ const struct name_decoration *get_name_decoration(const struct object *obj);
 
 struct commit *lookup_commit(const struct object_id *oid);
 struct commit *lookup_commit_reference(const struct object_id *oid);
-struct commit *lookup_commit_reference_gently(const struct object_id *oid,
+#define lookup_commit_reference_gently(r, o, q) \
+		lookup_commit_reference_gently_##r(o, q)
+struct commit *lookup_commit_reference_gently_the_repository(
+					      const struct object_id *oid,
 					      int quiet);
 struct commit *lookup_commit_reference_by_name(const char *name);
 
contrib/coccinelle/object_parser.cocci +8 -0
index 7ddd9f11ce..7c1ef62e6d 100644
@@ -59,3 +59,11 @@ expression E;
  lookup_object(
 +the_repository,
  E)
+
+@@
+expression E;
+expression F;
+@@
+ lookup_commit_reference_gently(
++the_repository,
+ E, F)
fast-import.c +4 -2
index 5618087015..54c2e10656 100644
@@ -1765,8 +1765,10 @@ static int update_branch(struct branch *b)
 	if (!force_update && !is_null_oid(&old_oid)) {
 		struct commit *old_cmit, *new_cmit;
 
-		old_cmit = lookup_commit_reference_gently(&old_oid, 0);
-		new_cmit = lookup_commit_reference_gently(&b->oid, 0);
+		old_cmit = lookup_commit_reference_gently(the_repository,
+							  &old_oid, 0);
+		new_cmit = lookup_commit_reference_gently(the_repository,
+							  &b->oid, 0);
 		if (!old_cmit || !new_cmit)
 			return error("Branch %s is missing commits.", b->name);
 
notes-cache.c +2 -1
index ee513e87a9..6348baeb07 100644
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "notes-cache.h"
 #include "object-store.h"
+#include "repository.h"
 #include "commit.h"
 #include "refs.h"
 
@@ -15,7 +16,7 @@ static int notes_cache_match_validity(const char *ref, const char *validity)
 	if (read_ref(ref, &oid) < 0)
 		return 0;
 
-	commit = lookup_commit_reference_gently(&oid, 1);
+	commit = lookup_commit_reference_gently(the_repository, &oid, 1);
 	if (!commit)
 		return 0;
 
ref-filter.c +4 -2
index 1d0bad5e36..b4b6f8801c 100644
@@ -1914,7 +1914,8 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
 	 * non-commits early. The actual filtering is done later.
 	 */
 	if (filter->merge_commit || filter->with_commit || filter->no_commit || filter->verbose) {
-		commit = lookup_commit_reference_gently(oid, 1);
+		commit = lookup_commit_reference_gently(the_repository, oid,
+							1);
 		if (!commit)
 			return 0;
 		/* We perform the filtering for the '--contains' option... */
@@ -2251,7 +2252,8 @@ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset)
 	if (get_oid(arg, &oid))
 		die(_("malformed object name %s"), arg);
 
-	rf->merge_commit = lookup_commit_reference_gently(&oid, 0);
+	rf->merge_commit = lookup_commit_reference_gently(the_repository,
+							  &oid, 0);
 	if (!rf->merge_commit)
 		return opterror(opt, "must point to a commit", 0);
 
remote.c +5 -4
index 8d84e26dd4..a9386476fe 100644
@@ -1323,7 +1323,7 @@ static void add_to_tips(struct tips *tips, const struct object_id *oid)
 
 	if (is_null_oid(oid))
 		return;
-	commit = lookup_commit_reference_gently(oid, 1);
+	commit = lookup_commit_reference_gently(the_repository, oid, 1);
 	if (!commit || (commit->object.flags & TMP_MARK))
 		return;
 	commit->object.flags |= TMP_MARK;
@@ -1385,7 +1385,8 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds
 
 			if (is_null_oid(&ref->new_oid))
 				continue;
-			commit = lookup_commit_reference_gently(&ref->new_oid,
+			commit = lookup_commit_reference_gently(the_repository,
+								&ref->new_oid,
 								1);
 			if (!commit)
 				/* not pushing a commit, which is not an error */
@@ -1613,8 +1614,8 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
 				reject_reason = REF_STATUS_REJECT_ALREADY_EXISTS;
 			else if (!has_object_file(&ref->old_oid))
 				reject_reason = REF_STATUS_REJECT_FETCH_FIRST;
-			else if (!lookup_commit_reference_gently(&ref->old_oid, 1) ||
-				 !lookup_commit_reference_gently(&ref->new_oid, 1))
+			else if (!lookup_commit_reference_gently(the_repository, &ref->old_oid, 1) ||
+				 !lookup_commit_reference_gently(the_repository, &ref->new_oid, 1))
 				reject_reason = REF_STATUS_REJECT_NEEDS_FORCE;
 			else if (!ref_newer(&ref->new_oid, &ref->old_oid))
 				reject_reason = REF_STATUS_REJECT_NONFASTFORWARD;
sequencer.c +1 -1
index 6533b97138..d0c3c808aa 100644
@@ -2347,7 +2347,7 @@ int sequencer_pick_revisions(struct replay_opts *opts)
 			continue;
 
 		if (!get_oid(name, &oid)) {
-			if (!lookup_commit_reference_gently(&oid, 1)) {
+			if (!lookup_commit_reference_gently(the_repository, &oid, 1)) {
 				enum object_type type = sha1_object_info(the_repository,
 									 oid.hash,
 									 NULL);
sha1_name.c +2 -2
index 117c080fd4..160fec7062 100644
@@ -1257,13 +1257,13 @@ int get_oid_mb(const char *name, struct object_id *oid)
 	}
 	if (st)
 		return st;
-	one = lookup_commit_reference_gently(&oid_tmp, 0);
+	one = lookup_commit_reference_gently(the_repository, &oid_tmp, 0);
 	if (!one)
 		return -1;
 
 	if (get_oid_committish(dots[3] ? (dots + 3) : "HEAD", &oid_tmp))
 		return -1;
-	two = lookup_commit_reference_gently(&oid_tmp, 0);
+	two = lookup_commit_reference_gently(the_repository, &oid_tmp, 0);
 	if (!two)
 		return -1;
 	mbs = get_merge_bases(one, two);
shallow.c +6 -3
index aa6d04992c..b62dd2c5fb 100644
@@ -474,7 +474,8 @@ static void paint_down(struct paint_info *info, const struct object_id *oid,
 	struct commit_list *head = NULL;
 	int bitmap_nr = DIV_ROUND_UP(info->nr_bits, 32);
 	size_t bitmap_size = st_mult(sizeof(uint32_t), bitmap_nr);
-	struct commit *c = lookup_commit_reference_gently(oid, 1);
+	struct commit *c = lookup_commit_reference_gently(the_repository, oid,
+							  1);
 	uint32_t *tmp; /* to be freed before return */
 	uint32_t *bitmap;
 
@@ -536,7 +537,8 @@ static void paint_down(struct paint_info *info, const struct object_id *oid,
 static int mark_uninteresting(const char *refname, const struct object_id *oid,
 			      int flags, void *cb_data)
 {
-	struct commit *commit = lookup_commit_reference_gently(oid, 1);
+	struct commit *commit = lookup_commit_reference_gently(the_repository,
+							       oid, 1);
 	if (!commit)
 		return 0;
 	commit->object.flags |= UNINTERESTING;
@@ -646,7 +648,8 @@ static int add_ref(const char *refname, const struct object_id *oid,
 {
 	struct commit_array *ca = cb_data;
 	ALLOC_GROW(ca->commits, ca->nr + 1, ca->alloc);
-	ca->commits[ca->nr] = lookup_commit_reference_gently(oid, 1);
+	ca->commits[ca->nr] = lookup_commit_reference_gently(the_repository,
+							     oid, 1);
 	if (ca->commits[ca->nr])
 		ca->nr++;
 	return 0;
walker.c +2 -1
index 5cfd2316a8..2b6bd9da81 100644
@@ -210,7 +210,8 @@ static int interpret_target(struct walker *walker, char *target, struct object_i
 static int mark_complete(const char *path, const struct object_id *oid,
 			 int flag, void *cb_data)
 {
-	struct commit *commit = lookup_commit_reference_gently(oid, 1);
+	struct commit *commit = lookup_commit_reference_gently(the_repository,
+							       oid, 1);
 
 	if (commit) {
 		commit->object.flags |= COMPLETE;
wt-status.c +1 -1
index ef26f07446..6655bc6f67 100644
@@ -1458,7 +1458,7 @@ static void wt_status_get_detached_from(struct wt_status_state *state)
 	    /* sha1 is a commit? match without further lookup */
 	    (!oidcmp(&cb.noid, &oid) ||
 	     /* perhaps sha1 is a tag, try to dereference to a commit */
-	     ((commit = lookup_commit_reference_gently(&oid, 1)) != NULL &&
+	     ((commit = lookup_commit_reference_gently(the_repository, &oid, 1)) != NULL &&
 	      !oidcmp(&cb.noid, &commit->object.oid)))) {
 		const char *from = ref;
 		if (!skip_prefix(from, "refs/tags/", &from))
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#122 lore raw

PATCH 90/194 object: add repository argument to lookup_commit_reference

In reply to Stefan Beller

Add a repository argument to allow callers of lookup_commit_reference to be more specific about which repository to handle. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet.

As with the previous commits, use a macro to catch callers passing a repository other than the_repository at compile time.

The included coccinelle semantic patch will adapt any new callers in the diff produced by make coccicheck.

---
 bisect.c                               |  2 +-
 blame.c                                |  2 +-
 branch.c                               |  2 +-
 builtin/branch.c                       |  7 ++++---
 builtin/clone.c                        |  3 ++-
 builtin/describe.c                     |  2 +-
 builtin/diff-tree.c                    |  2 +-
 builtin/log.c                          |  7 ++++---
 builtin/merge-base.c                   |  5 +++--
 builtin/notes.c                        |  3 ++-
 builtin/pull.c                         | 15 ++++++++++-----
 builtin/reset.c                        |  4 ++--
 builtin/rev-parse.c                    |  6 +++---
 builtin/show-branch.c                  |  2 +-
 builtin/tag.c                          |  2 +-
 bundle.c                               |  3 ++-
 commit.c                               |  6 +++---
 commit.h                               |  4 +++-
 contrib/coccinelle/object_parser.cocci |  7 +++++++
 notes-merge.c                          |  5 +++--
 parse-options-cb.c                     |  2 +-
 remote.c                               |  4 ++--
 revision.c                             |  4 ++--
 sequencer.c                            |  4 ++--
 sha1_name.c                            |  4 ++--
 submodule.c                            | 10 +++++-----
 26 files changed, 69 insertions(+), 48 deletions(-)
bisect.c +1 -1
index 2f3008b078..c3066bd972 100644
@@ -717,7 +717,7 @@ static int bisect_checkout(const struct object_id *bisect_rev, int no_checkout)
 
 static struct commit *get_commit_reference(const struct object_id *oid)
 {
-	struct commit *r = lookup_commit_reference(oid);
+	struct commit *r = lookup_commit_reference(the_repository, oid);
 	if (!r)
 		die(_("Not a valid commit name %s"), oid_to_hex(oid));
 	return r;
blame.c +1 -1
index 98761c32d5..1aab6228cc 100644
@@ -101,7 +101,7 @@ static struct commit_list **append_parent(struct commit_list **tail, const struc
 {
 	struct commit *parent;
 
-	parent = lookup_commit_reference(oid);
+	parent = lookup_commit_reference(the_repository, oid);
 	if (!parent)
 		die("no such commit %s", oid_to_hex(oid));
 	return &commit_list_insert(parent, tail)->next;
branch.c +1 -1
index 2672054f0b..0b7aaa1aca 100644
@@ -301,7 +301,7 @@ void create_branch(const char *name, const char *start_name,
 		break;
 	}
 
-	if ((commit = lookup_commit_reference(&oid)) == NULL)
+	if ((commit = lookup_commit_reference(the_repository, &oid)) == NULL)
 		die(_("Not a valid branch point: '%s'."), start_name);
 	oidcpy(&oid, &commit->object.oid);
 
builtin/branch.c +4 -3
index 8dcc2ed058..2d752c6614 100644
@@ -126,7 +126,8 @@ static int branch_merged(int kind, const char *name,
 		    (reference_name = reference_name_to_free =
 		     resolve_refdup(upstream, RESOLVE_REF_READING,
 				    &oid, NULL)) != NULL)
-			reference_rev = lookup_commit_reference(&oid);
+			reference_rev = lookup_commit_reference(the_repository,
+								&oid);
 	}
 	if (!reference_rev)
 		reference_rev = head_rev;
@@ -159,7 +160,7 @@ static int check_branch_commit(const char *branchname, const char *refname,
 			       const struct object_id *oid, struct commit *head_rev,
 			       int kinds, int force)
 {
-	struct commit *rev = lookup_commit_reference(oid);
+	struct commit *rev = lookup_commit_reference(the_repository, oid);
 	if (!rev) {
 		error(_("Couldn't look up commit object for '%s'"), refname);
 		return -1;
@@ -213,7 +214,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
 	}
 
 	if (!force) {
-		head_rev = lookup_commit_reference(&head_oid);
+		head_rev = lookup_commit_reference(the_repository, &head_oid);
 		if (!head_rev)
 			die(_("Couldn't look up commit object for HEAD"));
 	}
builtin/clone.c +2 -1
index ecd71b9444..6efe189846 100644
@@ -690,7 +690,8 @@ static void update_head(const struct ref *our, const struct ref *remote,
 			install_branch_config(0, head, option_origin, our->name);
 		}
 	} else if (our) {
-		struct commit *c = lookup_commit_reference(&our->old_oid);
+		struct commit *c = lookup_commit_reference(the_repository,
+							   &our->old_oid);
 		/* --branch specifies a non-branch (i.e. tags), detach HEAD */
 		update_ref(msg, "HEAD", &c->object.oid, NULL, REF_NO_DEREF,
 			   UPDATE_REFS_DIE_ON_ERR);
builtin/describe.c +1 -1
index f1172a8bf0..5bd0920ebd 100644
@@ -295,7 +295,7 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst)
 	unsigned long seen_commits = 0;
 	unsigned int unannotated_cnt = 0;
 
-	cmit = lookup_commit_reference(oid);
+	cmit = lookup_commit_reference(the_repository, oid);
 
 	n = find_commit_name(&cmit->object.oid);
 	if (n && (tags || all || n->prio == 2)) {
builtin/diff-tree.c +1 -1
index ab491efa9e..603f619532 100644
@@ -11,7 +11,7 @@ static struct rev_info log_tree_opt;
 
 static int diff_tree_commit_oid(const struct object_id *oid)
 {
-	struct commit *commit = lookup_commit_reference(oid);
+	struct commit *commit = lookup_commit_reference(the_repository, oid);
 	if (!commit)
 		return -1;
 	return log_tree_commit(&log_tree_opt, commit);
builtin/log.c +4 -3
index 2c3579b1f7..529e19ce6f 100644
@@ -901,8 +901,8 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids)
 	o2 = rev->pending.objects[1].item;
 	flags1 = o1->flags;
 	flags2 = o2->flags;
-	c1 = lookup_commit_reference(&o1->oid);
-	c2 = lookup_commit_reference(&o2->oid);
+	c1 = lookup_commit_reference(the_repository, &o1->oid);
+	c2 = lookup_commit_reference(the_repository, &o2->oid);
 
 	if ((flags1 & UNINTERESTING) == (flags2 & UNINTERESTING))
 		die(_("Not a range."));
@@ -1850,7 +1850,8 @@ static int add_pending_commit(const char *arg, struct rev_info *revs, int flags)
 {
 	struct object_id oid;
 	if (get_oid(arg, &oid) == 0) {
-		struct commit *commit = lookup_commit_reference(&oid);
+		struct commit *commit = lookup_commit_reference(the_repository,
+								&oid);
 		if (commit) {
 			commit->object.flags |= flags;
 			add_pending_object(revs, &commit->object, arg);
builtin/merge-base.c +3 -2
index 3b7600150b..bbead6f33e 100644
@@ -6,6 +6,7 @@
 #include "diff.h"
 #include "revision.h"
 #include "parse-options.h"
+#include "repository.h"
 
 static int show_merge_base(struct commit **rev, int rev_nr, int show_all)
 {
@@ -42,7 +43,7 @@ static struct commit *get_commit_reference(const char *arg)
 
 	if (get_oid(arg, &revkey))
 		die("Not a valid object name %s", arg);
-	r = lookup_commit_reference(&revkey);
+	r = lookup_commit_reference(the_repository, &revkey);
 	if (!r)
 		die("Not a valid commit name %s", arg);
 
@@ -171,7 +172,7 @@ static int handle_fork_point(int argc, const char **argv)
 	if (get_oid(commitname, &oid))
 		die("Not a valid object name: '%s'", commitname);
 
-	derived = lookup_commit_reference(&oid);
+	derived = lookup_commit_reference(the_repository, &oid);
 	memset(&revs, 0, sizeof(revs));
 	revs.initial = 1;
 	for_each_reflog_ent(refname, collect_one_reflog_ent, &revs);
builtin/notes.c +2 -1
index 1bd3994caa..18128eb439 100644
@@ -12,6 +12,7 @@
 #include "builtin.h"
 #include "notes.h"
 #include "object-store.h"
+#include "repository.h"
 #include "blob.h"
 #include "pretty.h"
 #include "refs.h"
@@ -711,7 +712,7 @@ static int merge_commit(struct notes_merge_options *o)
 
 	if (get_oid("NOTES_MERGE_PARTIAL", &oid))
 		die(_("failed to read ref NOTES_MERGE_PARTIAL"));
-	else if (!(partial = lookup_commit_reference(&oid)))
+	else if (!(partial = lookup_commit_reference(the_repository, &oid)))
 		die(_("could not find commit from NOTES_MERGE_PARTIAL."));
 	else if (parse_commit(partial))
 		die(_("could not parse commit from NOTES_MERGE_PARTIAL."));
builtin/pull.c +10 -5
index 511dbbe0f6..90aa922260 100644
@@ -758,10 +758,13 @@ static int get_octopus_merge_base(struct object_id *merge_base,
 {
 	struct commit_list *revs = NULL, *result;
 
-	commit_list_insert(lookup_commit_reference(curr_head), &revs);
-	commit_list_insert(lookup_commit_reference(merge_head), &revs);
+	commit_list_insert(lookup_commit_reference(the_repository, curr_head),
+			   &revs);
+	commit_list_insert(lookup_commit_reference(the_repository, merge_head),
+			   &revs);
 	if (!is_null_oid(fork_point))
-		commit_list_insert(lookup_commit_reference(fork_point), &revs);
+		commit_list_insert(lookup_commit_reference(the_repository, fork_point),
+				   &revs);
 
 	result = get_octopus_merge_bases(revs);
 	free_commit_list(revs);
@@ -935,9 +938,11 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
 			struct commit_list *list = NULL;
 			struct commit *merge_head, *head;
 
-			head = lookup_commit_reference(&orig_head);
+			head = lookup_commit_reference(the_repository,
+						       &orig_head);
 			commit_list_insert(head, &list);
-			merge_head = lookup_commit_reference(&merge_heads.oid[0]);
+			merge_head = lookup_commit_reference(the_repository,
+							     &merge_heads.oid[0]);
 			if (is_descendant_of(merge_head, list)) {
 				/* we can fast-forward this without invoking rebase */
 				opt_ff = "--ff-only";
builtin/reset.c +2 -2
index e15f595799..ea600bc62a 100644
@@ -327,7 +327,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
 		struct commit *commit;
 		if (get_oid_committish(rev, &oid))
 			die(_("Failed to resolve '%s' as a valid revision."), rev);
-		commit = lookup_commit_reference(&oid);
+		commit = lookup_commit_reference(the_repository, &oid);
 		if (!commit)
 			die(_("Could not parse object '%s'."), rev);
 		oidcpy(&oid, &commit->object.oid);
@@ -404,7 +404,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
 		update_ref_status = reset_refs(rev, &oid);
 
 		if (reset_type == HARD && !update_ref_status && !quiet)
-			print_new_head_line(lookup_commit_reference(&oid));
+			print_new_head_line(lookup_commit_reference(the_repository, &oid));
 	}
 	if (!pathspec.nr)
 		remove_branch_state();
builtin/rev-parse.c +3 -3
index 74aa644cbb..b5515df1ae 100644
@@ -280,8 +280,8 @@ static int try_difference(const char *arg)
 		if (symmetric) {
 			struct commit_list *exclude;
 			struct commit *a, *b;
-			a = lookup_commit_reference(&oid);
-			b = lookup_commit_reference(&end);
+			a = lookup_commit_reference(the_repository, &oid);
+			b = lookup_commit_reference(the_repository, &end);
 			exclude = get_merge_bases(a, b);
 			while (exclude) {
 				struct commit *commit = pop_commit(&exclude);
@@ -333,7 +333,7 @@ static int try_parent_shorthands(const char *arg)
 		return 0;
 	}
 
-	commit = lookup_commit_reference(&oid);
+	commit = lookup_commit_reference(the_repository, &oid);
 	if (exclude_parent &&
 	    exclude_parent > commit_list_count(commit->parents)) {
 		*dotdot = '^';
builtin/show-branch.c +1 -1
index fb90c9ab3e..03c98efbe5 100644
@@ -811,7 +811,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
 			       MAX_REVS), MAX_REVS);
 		if (get_oid(ref_name[num_rev], &revkey))
 			die(_("'%s' is not a valid ref."), ref_name[num_rev]);
-		commit = lookup_commit_reference(&revkey);
+		commit = lookup_commit_reference(the_repository, &revkey);
 		if (!commit)
 			die(_("cannot find commit %s (%s)"),
 			    ref_name[num_rev], oid_to_hex(&revkey));
builtin/tag.c +1 -1
index 014d7c9e9b..1fad1e6733 100644
@@ -309,7 +309,7 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb)
 		}
 		free(buf);
 
-		if ((c = lookup_commit_reference(oid)) != NULL)
+		if ((c = lookup_commit_reference(the_repository, oid)) != NULL)
 			strbuf_addf(sb, ", %s", show_date(c->date, 0, DATE_MODE(SHORT)));
 		break;
 	case OBJ_TREE:
bundle.c +2 -1
index 1b5f1beb3b..d9579f851e 100644
@@ -378,7 +378,8 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
 			 * in terms of a tag (e.g. v2.0 from the range
 			 * "v1.0..v2.0")?
 			 */
-			struct commit *one = lookup_commit_reference(&oid);
+			struct commit *one = lookup_commit_reference(the_repository,
+								     &oid);
 			struct object *obj;
 
 			if (e->item == &(one->object)) {
commit.c +3 -3
index b6e253f1af..b943b97aee 100644
@@ -32,14 +32,14 @@ struct commit *lookup_commit_reference_gently_the_repository(
 	return object_as_type(obj, OBJ_COMMIT, quiet);
 }
 
-struct commit *lookup_commit_reference(const struct object_id *oid)
+struct commit *lookup_commit_reference_the_repository(const struct object_id *oid)
 {
 	return lookup_commit_reference_gently(the_repository, oid, 0);
 }
 
 struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref_name)
 {
-	struct commit *c = lookup_commit_reference(oid);
+	struct commit *c = lookup_commit_reference(the_repository, oid);
 	if (!c)
 		die(_("could not parse %s"), ref_name);
 	if (oidcmp(oid, &c->object.oid)) {
@@ -65,7 +65,7 @@ struct commit *lookup_commit_reference_by_name(const char *name)
 
 	if (get_oid_committish(name, &oid))
 		return NULL;
-	commit = lookup_commit_reference(&oid);
+	commit = lookup_commit_reference(the_repository, &oid);
 	if (parse_commit(commit))
 		return NULL;
 	return commit;
commit.h +3 -1
index 2ce5597066..9159165fde 100644
@@ -47,7 +47,9 @@ void add_name_decoration(enum decoration_type type, const char *name, struct obj
 const struct name_decoration *get_name_decoration(const struct object *obj);
 
 struct commit *lookup_commit(const struct object_id *oid);
-struct commit *lookup_commit_reference(const struct object_id *oid);
+#define lookup_commit_reference(r, o) \
+		lookup_commit_reference_##r(o)
+struct commit *lookup_commit_reference_the_repository(const struct object_id *oid);
 #define lookup_commit_reference_gently(r, o, q) \
 		lookup_commit_reference_gently_##r(o, q)
 struct commit *lookup_commit_reference_gently_the_repository(
contrib/coccinelle/object_parser.cocci +7 -0
index 7c1ef62e6d..bc00029f8c 100644
@@ -67,3 +67,10 @@ expression F;
  lookup_commit_reference_gently(
 +the_repository,
  E, F)
+
+@@
+expression E;
+@@
+ lookup_commit_reference(
++the_repository,
+ E)
notes-merge.c +3 -2
index 1053c65e83..ea701827ba 100644
@@ -2,6 +2,7 @@
 #include "commit.h"
 #include "refs.h"
 #include "object-store.h"
+#include "repository.h"
 #include "diff.h"
 #include "diffcore.h"
 #include "xdiff-interface.h"
@@ -553,7 +554,7 @@ int notes_merge(struct notes_merge_options *o,
 	else if (!check_refname_format(o->local_ref, 0) &&
 		is_null_oid(&local_oid))
 		local = NULL; /* local_oid == null_oid indicates unborn ref */
-	else if (!(local = lookup_commit_reference(&local_oid)))
+	else if (!(local = lookup_commit_reference(the_repository, &local_oid)))
 		die("Could not parse local commit %s (%s)",
 		    oid_to_hex(&local_oid), o->local_ref);
 	trace_printf("\tlocal commit: %.7s\n", oid_to_hex(&local_oid));
@@ -571,7 +572,7 @@ int notes_merge(struct notes_merge_options *o,
 			die("Failed to resolve remote notes ref '%s'",
 			    o->remote_ref);
 		}
-	} else if (!(remote = lookup_commit_reference(&remote_oid))) {
+	} else if (!(remote = lookup_commit_reference(the_repository, &remote_oid))) {
 		die("Could not parse remote commit %s (%s)",
 		    oid_to_hex(&remote_oid), o->remote_ref);
 	}
parse-options-cb.c +1 -1
index c6679cb2cd..624fcee6f4 100644
@@ -87,7 +87,7 @@ int parse_opt_commits(const struct option *opt, const char *arg, int unset)
 		return -1;
 	if (get_oid(arg, &oid))
 		return error("malformed object name %s", arg);
-	commit = lookup_commit_reference(&oid);
+	commit = lookup_commit_reference(the_repository, &oid);
 	if (!commit)
 		return error("no such commit %s", arg);
 	commit_list_insert(commit, opt->value);
remote.c +2 -2
index a9386476fe..ecfa60a975 100644
@@ -2039,13 +2039,13 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
 	/* Cannot stat if what we used to build on no longer exists */
 	if (read_ref(base, &oid))
 		return -1;
-	theirs = lookup_commit_reference(&oid);
+	theirs = lookup_commit_reference(the_repository, &oid);
 	if (!theirs)
 		return -1;
 
 	if (read_ref(branch->refname, &oid))
 		return -1;
-	ours = lookup_commit_reference(&oid);
+	ours = lookup_commit_reference(the_repository, &oid);
 	if (!ours)
 		return -1;
 
revision.c +2 -2
index 629af0dca5..5c5375ac54 100644
@@ -1563,8 +1563,8 @@ static int handle_dotdot_1(const char *arg, char *dotdot,
 		struct commit *a, *b;
 		struct commit_list *exclude;
 
-		a = lookup_commit_reference(&a_obj->oid);
-		b = lookup_commit_reference(&b_obj->oid);
+		a = lookup_commit_reference(the_repository, &a_obj->oid);
+		b = lookup_commit_reference(the_repository, &b_obj->oid);
 		if (!a || !b)
 			return dotdot_missing(arg, dotdot, revs, symmetric);
 
sequencer.c +2 -2
index d0c3c808aa..d24586bc6f 100644
@@ -857,7 +857,7 @@ static int update_squash_messages(enum todo_command command,
 
 		if (get_oid("HEAD", &head))
 			return error(_("need a HEAD to fixup"));
-		if (!(head_commit = lookup_commit_reference(&head)))
+		if (!(head_commit = lookup_commit_reference(the_repository, &head)))
 			return error(_("could not read HEAD"));
 		if (!(head_message = get_commit_buffer(head_commit, NULL)))
 			return error(_("could not read HEAD's commit message"));
@@ -1300,7 +1300,7 @@ static int parse_insn_line(struct todo_item *item, const char *bol, char *eol)
 	if (status < 0)
 		return -1;
 
-	item->commit = lookup_commit_reference(&commit_oid);
+	item->commit = lookup_commit_reference(the_repository, &commit_oid);
 	return !item->commit;
 }
 
sha1_name.c +2 -2
index 160fec7062..ea169a28c1 100644
@@ -849,7 +849,7 @@ static int get_parent(const char *name, int len,
 
 	if (ret)
 		return ret;
-	commit = lookup_commit_reference(&oid);
+	commit = lookup_commit_reference(the_repository, &oid);
 	if (parse_commit(commit))
 		return -1;
 	if (!idx) {
@@ -877,7 +877,7 @@ static int get_nth_ancestor(const char *name, int len,
 	ret = get_oid_1(name, len, &oid, GET_OID_COMMITTISH);
 	if (ret)
 		return ret;
-	commit = lookup_commit_reference(&oid);
+	commit = lookup_commit_reference(the_repository, &oid);
 	if (!commit)
 		return -1;
 
submodule.c +5 -5
index 1504812842..aec62e6c7d 100644
@@ -515,8 +515,8 @@ static void show_submodule_header(struct diff_options *o, const char *path,
 	 * Attempt to lookup the commit references, and determine if this is
 	 * a fast forward or fast backwards update.
 	 */
-	*left = lookup_commit_reference(one);
-	*right = lookup_commit_reference(two);
+	*left = lookup_commit_reference(the_repository, one);
+	*right = lookup_commit_reference(the_repository, two);
 
 	/*
 	 * Warn about missing commits in the submodule project, but only if
@@ -1820,9 +1820,9 @@ int merge_submodule(struct object_id *result, const char *path,
 		return 0;
 	}
 
-	if (!(commit_base = lookup_commit_reference(base)) ||
-	    !(commit_a = lookup_commit_reference(a)) ||
-	    !(commit_b = lookup_commit_reference(b))) {
+	if (!(commit_base = lookup_commit_reference(the_repository, base)) ||
+	    !(commit_a = lookup_commit_reference(the_repository, a)) ||
+	    !(commit_b = lookup_commit_reference(the_repository, b))) {
 		MERGE_WARNING(path, "commits not present");
 		return 0;
 	}
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#123 lore raw

PATCH 91/194 object: add repository argument to lookup_commit

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

Add a repository argument to allow callers of lookup_commit to be more specific about which repository to handle. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet.

As with the previous commits, use a macro to catch callers passing a repository other than the_repository at compile time.

The included coccinelle semantic patch will adapt any new callers in the diff produced by make coccicheck.

---
 builtin/am.c                           |  3 ++-
 builtin/commit-tree.c                  |  4 +++-
 builtin/commit.c                       |  2 +-
 builtin/diff-tree.c                    |  2 +-
 builtin/fast-export.c                  |  2 +-
 builtin/fmt-merge-msg.c                |  2 +-
 builtin/merge-base.c                   |  2 +-
 builtin/verify-commit.c                |  4 +++-
 commit.c                               |  7 ++++---
 commit.h                               |  3 ++-
 contrib/coccinelle/object_parser.cocci |  7 +++++++
 fetch-pack.c                           |  3 ++-
 log-tree.c                             |  2 +-
 notes-utils.c                          |  4 +++-
 object.c                               |  2 +-
 sequencer.c                            |  2 +-
 sha1_name.c                            |  2 +-
 shallow.c                              | 17 ++++++++++-------
 tag.c                                  |  2 +-
 tree.c                                 |  2 +-
 20 files changed, 47 insertions(+), 27 deletions(-)
builtin/am.c +2 -1
index 32002a8661..83bc22649e 100644
@@ -1629,7 +1629,8 @@ static void do_commit(const struct am_state *state)
 
 	if (!get_oid_commit("HEAD", &parent)) {
 		old_oid = &parent;
-		commit_list_insert(lookup_commit(&parent), &parents);
+		commit_list_insert(lookup_commit(the_repository, &parent),
+				   &parents);
 	} else {
 		old_oid = NULL;
 		say(state, stderr, _("applying to an empty history"));
builtin/commit-tree.c +3 -1
index a54fb362ce..4f4fcace3b 100644
@@ -6,6 +6,7 @@
 #include "cache.h"
 #include "config.h"
 #include "object-store.h"
+#include "repository.h"
 #include "commit.h"
 #include "tree.h"
 #include "builtin.h"
@@ -60,7 +61,8 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
 			if (get_oid_commit(argv[i], &oid))
 				die("Not a valid object name %s", argv[i]);
 			assert_sha1_type(oid.hash, OBJ_COMMIT);
-			new_parent(lookup_commit(&oid), &parents);
+			new_parent(lookup_commit(the_repository, &oid),
+				   &parents);
 			continue;
 		}
 
builtin/commit.c +1 -1
index 8a87701414..cd3144f9f4 100644
@@ -1464,7 +1464,7 @@ static void print_summary(const char *prefix, const struct object_id *oid,
 	struct strbuf author_ident = STRBUF_INIT;
 	struct strbuf committer_ident = STRBUF_INIT;
 
-	commit = lookup_commit(oid);
+	commit = lookup_commit(the_repository, oid);
 	if (!commit)
 		die(_("couldn't look up newly created commit"));
 	if (parse_commit(commit))
builtin/diff-tree.c +1 -1
index 603f619532..62c435a65f 100644
@@ -25,7 +25,7 @@ static int stdin_diff_commit(struct commit *commit, const char *p)
 
 	/* Graft the fake parents locally to the commit */
 	while (isspace(*p++) && !parse_oid_hex(p, &oid, &p)) {
-		struct commit *parent = lookup_commit(&oid);
+		struct commit *parent = lookup_commit(the_repository, &oid);
 		if (!pptr) {
 			/* Free the real parent list */
 			free_commit_list(commit->parents);
builtin/fast-export.c +1 -1
index 14a27d539f..322adfd408 100644
@@ -958,7 +958,7 @@ static void import_marks(char *input_file)
 			/* only commits */
 			continue;
 
-		commit = lookup_commit(&oid);
+		commit = lookup_commit(the_repository, &oid);
 		if (!commit)
 			die("not a commit? can't happen: %s", oid_to_hex(&oid));
 
builtin/fmt-merge-msg.c +1 -1
index 49fd7ea1d2..3e99d10218 100644
@@ -573,7 +573,7 @@ static void find_merge_parents(struct merge_parents *result,
 		commit_list_insert(parent, &parents);
 		add_merge_parent(result, &obj->oid, &parent->object.oid);
 	}
-	head_commit = lookup_commit(head);
+	head_commit = lookup_commit(the_repository, head);
 	if (head_commit)
 		commit_list_insert(head_commit, &parents);
 	reduce_heads_replace(&parents);
builtin/merge-base.c +1 -1
index bbead6f33e..08d91b1f0c 100644
@@ -124,7 +124,7 @@ static void add_one_commit(struct object_id *oid, struct rev_collect *revs)
 	if (is_null_oid(oid))
 		return;
 
-	commit = lookup_commit(oid);
+	commit = lookup_commit(the_repository, oid);
 	if (!commit ||
 	    (commit->object.flags & TMP_MARK) ||
 	    parse_commit(commit))
builtin/verify-commit.c +3 -1
index 29f5e5507c..b0ae18ec33 100644
@@ -9,6 +9,7 @@
 #include "config.h"
 #include "builtin.h"
 #include "object-store.h"
+#include "repository.h"
 #include "commit.h"
 #include "run-command.h"
 #include <signal.h>
@@ -27,7 +28,8 @@ static int run_gpg_verify(const struct object_id *oid, const char *buf, unsigned
 
 	memset(&signature_check, 0, sizeof(signature_check));
 
-	ret = check_commit_signature(lookup_commit(oid), &signature_check);
+	ret = check_commit_signature(lookup_commit(the_repository, oid),
+				     &signature_check);
 	print_signature_buffer(&signature_check, flags);
 
 	signature_check_clear(&signature_check);
commit.c +4 -3
index b943b97aee..2137a0b9c6 100644
@@ -49,7 +49,7 @@ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref
 	return c;
 }
 
-struct commit *lookup_commit(const struct object_id *oid)
+struct commit *lookup_commit_the_repository(const struct object_id *oid)
 {
 	struct object *obj = lookup_object(the_repository, oid->hash);
 	if (!obj)
@@ -359,7 +359,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
 		 */
 		if (graft && (graft->nr_parent < 0 || grafts_replace_parents))
 			continue;
-		new_parent = lookup_commit(&parent);
+		new_parent = lookup_commit(the_repository, &parent);
 		if (new_parent)
 			pptr = &commit_list_insert(new_parent, pptr)->next;
 	}
@@ -367,7 +367,8 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
 		int i;
 		struct commit *new_parent;
 		for (i = 0; i < graft->nr_parent; i++) {
-			new_parent = lookup_commit(&graft->parent[i]);
+			new_parent = lookup_commit(the_repository,
+						   &graft->parent[i]);
 			if (!new_parent)
 				continue;
 			pptr = &commit_list_insert(new_parent, pptr)->next;
commit.h +2 -1
index 9159165fde..61e01112eb 100644
@@ -46,7 +46,8 @@ enum decoration_type {
 void add_name_decoration(enum decoration_type type, const char *name, struct object *obj);
 const struct name_decoration *get_name_decoration(const struct object *obj);
 
-struct commit *lookup_commit(const struct object_id *oid);
+#define lookup_commit(r, o) lookup_commit_##r(o)
+struct commit *lookup_commit_the_repository(const struct object_id *oid);
 #define lookup_commit_reference(r, o) \
 		lookup_commit_reference_##r(o)
 struct commit *lookup_commit_reference_the_repository(const struct object_id *oid);
contrib/coccinelle/object_parser.cocci +7 -0
index bc00029f8c..c3cc4dfc9e 100644
@@ -74,3 +74,10 @@ expression E;
  lookup_commit_reference(
 +the_repository,
  E)
+
+@@
+expression E;
+@@
+ lookup_commit(
++the_repository,
+ E)
fetch-pack.c +2 -1
index ee1e65688a..f38beea6a3 100644
@@ -491,7 +491,8 @@ static int find_common(struct fetch_pack_args *args,
 				case ACK_ready:
 				case ACK_continue: {
 					struct commit *commit =
-						lookup_commit(result_oid);
+						lookup_commit(the_repository,
+							      result_oid);
 					if (!commit)
 						die(_("invalid commit %s"), oid_to_hex(result_oid));
 					if (args->stateless_rpc
log-tree.c +1 -1
index 1137506884..9fb333605b 100644
@@ -147,7 +147,7 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid,
 
 static int add_graft_decoration(const struct commit_graft *graft, void *cb_data)
 {
-	struct commit *commit = lookup_commit(&graft->oid);
+	struct commit *commit = lookup_commit(the_repository, &graft->oid);
 	if (!commit)
 		return 0;
 	add_name_decoration(DECORATION_GRAFTED, "grafted", &commit->object);
notes-utils.c +3 -1
index 5c8e70c98f..3ef5340c6e 100644
@@ -3,6 +3,7 @@
 #include "commit.h"
 #include "refs.h"
 #include "notes-utils.h"
+#include "repository.h"
 
 void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
 			 const char *msg, size_t msg_len,
@@ -19,7 +20,8 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
 		/* Deduce parent commit from t->ref */
 		struct object_id parent_oid;
 		if (!read_ref(t->ref, &parent_oid)) {
-			struct commit *parent = lookup_commit(&parent_oid);
+			struct commit *parent = lookup_commit(the_repository,
+							      &parent_oid);
 			if (parse_commit(parent))
 				die("Failed to find/parse commit %s", t->ref);
 			commit_list_insert(parent, &parents);
object.c +1 -1
index c9ce89cf37..6676887315 100644
@@ -209,7 +209,7 @@ struct object *parse_object_buffer(const struct object_id *oid, enum object_type
 			}
 		}
 	} else if (type == OBJ_COMMIT) {
-		struct commit *commit = lookup_commit(oid);
+		struct commit *commit = lookup_commit(the_repository, oid);
 		if (commit) {
 			if (parse_commit_buffer(commit, buffer, size))
 				return NULL;
sequencer.c +1 -1
index d24586bc6f..4d259d9ae4 100644
@@ -497,7 +497,7 @@ static int is_index_unchanged(void)
 	if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL))
 		return error(_("could not resolve HEAD commit"));
 
-	head_commit = lookup_commit(&head_oid);
+	head_commit = lookup_commit(the_repository, &head_oid);
 
 	/*
 	 * If head_commit is NULL, check_commit, called from
sha1_name.c +1 -1
index ea169a28c1..45b7d6be91 100644
@@ -374,7 +374,7 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)
 
 	type = sha1_object_info(the_repository, oid->hash, NULL);
 	if (type == OBJ_COMMIT) {
-		struct commit *commit = lookup_commit(oid);
+		struct commit *commit = lookup_commit(the_repository, oid);
 		if (commit) {
 			struct pretty_print_context pp = {0};
 			pp.date_mode.type = DATE_SHORT;
shallow.c +10 -7
index b62dd2c5fb..97c483239a 100644
@@ -32,7 +32,7 @@ int register_shallow(const struct object_id *oid)
 {
 	struct commit_graft *graft =
 		xmalloc(sizeof(struct commit_graft));
-	struct commit *commit = lookup_commit(oid);
+	struct commit *commit = lookup_commit(the_repository, oid);
 
 	oidcpy(&graft->oid, oid);
 	graft->nr_parent = -1;
@@ -244,7 +244,7 @@ static int write_one_shallow(const struct commit_graft *graft, void *cb_data)
 	if (graft->nr_parent != -1)
 		return 0;
 	if (data->flags & SEEN_ONLY) {
-		struct commit *c = lookup_commit(&graft->oid);
+		struct commit *c = lookup_commit(the_repository, &graft->oid);
 		if (!c || !(c->object.flags & SEEN)) {
 			if (data->flags & VERBOSE)
 				printf("Removing %s from .git/shallow\n",
@@ -606,7 +606,8 @@ void assign_shallow_commits_to_refs(struct shallow_info *info,
 
 	/* Mark potential bottoms so we won't go out of bound */
 	for (i = 0; i < nr_shallow; i++) {
-		struct commit *c = lookup_commit(&oid[shallow[i]]);
+		struct commit *c = lookup_commit(the_repository,
+						 &oid[shallow[i]]);
 		c->object.flags |= BOTTOM;
 	}
 
@@ -617,7 +618,8 @@ void assign_shallow_commits_to_refs(struct shallow_info *info,
 		int bitmap_size = DIV_ROUND_UP(pi.nr_bits, 32) * sizeof(uint32_t);
 		memset(used, 0, sizeof(*used) * info->shallow->nr);
 		for (i = 0; i < nr_shallow; i++) {
-			const struct commit *c = lookup_commit(&oid[shallow[i]]);
+			const struct commit *c = lookup_commit(the_repository,
+							       &oid[shallow[i]]);
 			uint32_t **map = ref_bitmap_at(&pi.ref_bitmap, c);
 			if (*map)
 				used[shallow[i]] = xmemdupz(*map, bitmap_size);
@@ -687,7 +689,7 @@ static void post_assign_shallow(struct shallow_info *info,
 	for (i = dst = 0; i < info->nr_theirs; i++) {
 		if (i != dst)
 			info->theirs[dst] = info->theirs[i];
-		c = lookup_commit(&oid[info->theirs[i]]);
+		c = lookup_commit(the_repository, &oid[info->theirs[i]]);
 		bitmap = ref_bitmap_at(ref_bitmap, c);
 		if (!*bitmap)
 			continue;
@@ -708,7 +710,7 @@ static void post_assign_shallow(struct shallow_info *info,
 	for (i = dst = 0; i < info->nr_ours; i++) {
 		if (i != dst)
 			info->ours[dst] = info->ours[i];
-		c = lookup_commit(&oid[info->ours[i]]);
+		c = lookup_commit(the_repository, &oid[info->ours[i]]);
 		bitmap = ref_bitmap_at(ref_bitmap, c);
 		if (!*bitmap)
 			continue;
@@ -730,7 +732,8 @@ static void post_assign_shallow(struct shallow_info *info,
 int delayed_reachability_test(struct shallow_info *si, int c)
 {
 	if (si->need_reachability_test[c]) {
-		struct commit *commit = lookup_commit(&si->shallow->oid[c]);
+		struct commit *commit = lookup_commit(the_repository,
+						      &si->shallow->oid[c]);
 
 		if (!si->commits) {
 			struct commit_array ca;
tag.c +1 -1
index d8174e0405..da2fe4f2ee 100644
@@ -150,7 +150,7 @@ int parse_tag_buffer_the_repository(struct tag *item, const void *data, unsigned
 	} else if (!strcmp(type, tree_type)) {
 		item->tagged = (struct object *)lookup_tree(the_repository, &oid);
 	} else if (!strcmp(type, commit_type)) {
-		item->tagged = (struct object *)lookup_commit(&oid);
+		item->tagged = (struct object *)lookup_commit(the_repository, &oid);
 	} else if (!strcmp(type, tag_type)) {
 		item->tagged = (struct object *)lookup_tag(the_repository, &oid);
 	} else {
tree.c +1 -1
index b0d8610c41..6e0aafa805 100644
@@ -100,7 +100,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
 		else if (S_ISGITLINK(entry.mode)) {
 			struct commit *commit;
 
-			commit = lookup_commit(entry.oid);
+			commit = lookup_commit(the_repository, entry.oid);
 			if (!commit)
 				die("Commit %s in submodule path %s%s not found",
 				    oid_to_hex(entry.oid),
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#124 lore raw

PATCH 92/194 object: move grafts to object parser

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

Grafts are only meaningful in the context of a single repository. Therefore they cannot be global.

---
 commit.c | 44 +++++++++++++++++++++++---------------------
 object.h |  6 +++++-
 2 files changed, 28 insertions(+), 22 deletions(-)
commit.c +23 -21
index 2137a0b9c6..2ad5537ed7 100644
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "tag.h"
 #include "commit.h"
+#include "repository.h"
 #include "object-store.h"
 #include "pkt-line.h"
 #include "utf8.h"
@@ -98,9 +99,6 @@ static timestamp_t parse_commit_date(const char *buf, const char *tail)
 	return parse_timestamp(dateptr, NULL, 10);
 }
 
-static struct commit_graft **commit_graft;
-static int commit_graft_alloc, commit_graft_nr;
-
 static const unsigned char *commit_graft_sha1_access(size_t index, void *table)
 {
 	struct commit_graft **commit_graft_table = table;
@@ -109,7 +107,8 @@ static const unsigned char *commit_graft_sha1_access(size_t index, void *table)
 
 static int commit_graft_pos(const unsigned char *sha1)
 {
-	return sha1_pos(sha1, commit_graft, commit_graft_nr,
+	return sha1_pos(sha1, the_repository->parsed_objects.grafts,
+			the_repository->parsed_objects.grafts_nr,
 			commit_graft_sha1_access);
 }
 
@@ -121,20 +120,22 @@ int register_commit_graft(struct commit_graft *graft, int ignore_dups)
 		if (ignore_dups)
 			free(graft);
 		else {
-			free(commit_graft[pos]);
-			commit_graft[pos] = graft;
+			free(the_repository->parsed_objects.grafts[pos]);
+			the_repository->parsed_objects.grafts[pos] = graft;
 		}
 		return 1;
 	}
 	pos = -pos - 1;
-	ALLOC_GROW(commit_graft, commit_graft_nr + 1, commit_graft_alloc);
-	commit_graft_nr++;
-	if (pos < commit_graft_nr)
-		memmove(commit_graft + pos + 1,
-			commit_graft + pos,
-			(commit_graft_nr - pos - 1) *
-			sizeof(*commit_graft));
-	commit_graft[pos] = graft;
+	ALLOC_GROW(the_repository->parsed_objects.grafts,
+		   the_repository->parsed_objects.grafts_nr + 1,
+		   the_repository->parsed_objects.grafts_alloc);
+	the_repository->parsed_objects.grafts_nr++;
+	if (pos < the_repository->parsed_objects.grafts_nr)
+		memmove(the_repository->parsed_objects.grafts + pos + 1,
+			the_repository->parsed_objects.grafts + pos,
+			(the_repository->parsed_objects.grafts_nr - pos - 1) *
+			sizeof(*the_repository->parsed_objects.grafts));
+	the_repository->parsed_objects.grafts[pos] = graft;
 	return 0;
 }
 
@@ -216,14 +217,14 @@ struct commit_graft *lookup_commit_graft(const struct object_id *oid)
 	pos = commit_graft_pos(oid->hash);
 	if (pos < 0)
 		return NULL;
-	return commit_graft[pos];
+	return the_repository->parsed_objects.grafts[pos];
 }
 
 int for_each_commit_graft(each_commit_graft_fn fn, void *cb_data)
 {
 	int i, ret;
-	for (i = ret = 0; i < commit_graft_nr && !ret; i++)
-		ret = fn(commit_graft[i], cb_data);
+	for (i = ret = 0; i < the_repository->parsed_objects.grafts_nr && !ret; i++)
+		ret = fn(the_repository->parsed_objects.grafts[i], cb_data);
 	return ret;
 }
 
@@ -232,10 +233,11 @@ int unregister_shallow(const struct object_id *oid)
 	int pos = commit_graft_pos(oid->hash);
 	if (pos < 0)
 		return -1;
-	if (pos + 1 < commit_graft_nr)
-		MOVE_ARRAY(commit_graft + pos, commit_graft + pos + 1,
-			   commit_graft_nr - pos - 1);
-	commit_graft_nr--;
+	if (pos + 1 < the_repository->parsed_objects.grafts_nr)
+		MOVE_ARRAY(the_repository->parsed_objects.grafts + pos,
+			   the_repository->parsed_objects.grafts + pos + 1,
+			   the_repository->parsed_objects.grafts_nr - pos - 1);
+	the_repository->parsed_objects.grafts_nr--;
 	return 0;
 }
 
object.h +5 -1
index 727a03ebd6..b667404f88 100644
@@ -4,9 +4,13 @@
 struct object_parser {
 	struct object **obj_hash;
 	int nr_objs, obj_hash_size;
+
+	/* parent substitutions from .git/info/grafts and .git/shallow */
+	struct commit_graft **grafts;
+	int grafts_alloc, grafts_nr;
 };
 
-#define OBJECT_PARSER_INIT { NULL, 0, 0 }
+#define OBJECT_PARSER_INIT { NULL, 0, 0, NULL, 0, 0 }
 
 struct object_list {
 	struct object *item;
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#125 lore raw

Re: [PATCH 092/194] object: move grafts to object parser

Quoted 17 lines · Stefan Beller

Grafts are only meaningful in the context of a single repository. Therefore they cannot be global.

---

commit.c +2 -2
@@ -121,20 +120,22 @@ int register_commit_graft(struct commit_graft *graft, int ignore_dups)
                if (ignore_dups)
                        free(graft);
                else {
-                       free(commit_graft[pos]);
-                       commit_graft[pos] = graft;
+                       free(the_repository->parsed_objects.grafts[pos]);
+                       the_repository->parsed_objects.grafts[pos] = graft;

object.h line 11

Quoted 8 lines
object.h +4 -0
@@ -4,9 +4,13 @@
 struct object_parser {
        struct object **obj_hash;
        int nr_objs, obj_hash_size;
+
+       /* parent substitutions from .git/info/grafts and .git/shallow */
+       struct commit_graft **grafts;
+       int grafts_alloc, grafts_nr;
 };

Do items moved to object_parser need to get freed when object_parser itself is freed? Is that happening in some other patch?

#126 lore raw

Re: [PATCH 092/194] object: move grafts to object parser

Quoted 21 lines · Eric Sunshine
Quoted 20 lines · Stefan Beller

Grafts are only meaningful in the context of a single repository. Therefore they cannot be global.

---

commit.c +2 -2
@@ -121,20 +120,22 @@ int register_commit_graft(struct commit_graft *graft, int ignore_dups)
                if (ignore_dups)
                        free(graft);
                else {
-                       free(commit_graft[pos]);
-                       commit_graft[pos] = graft;
+                       free(the_repository->parsed_objects.grafts[pos]);
+                       the_repository->parsed_objects.grafts[pos] = graft;
object.h +0 -0
@@ -4,9 +4,13 @@
 struct object_parser {
        struct object **obj_hash;
        int nr_objs, obj_hash_size;
Quoted 8 lines

object.h line 11

Quoted 5 lines
object.h +4 -0
+
+       /* parent substitutions from .git/info/grafts and .git/shallow */
+       struct commit_graft **grafts;
+       int grafts_alloc, grafts_nr;
 };

Do items moved to object_parser need to get freed when object_parser itself is freed? Is that happening in some other patch?

No, this patch supposedly should free the memory via repo_free (which either does it itself or calls some specific free for the grafts)

Thanks for finding the mem leak!
Stefan

#127 lore raw

PATCH 93/194 object: add repository argument to commit_graft_pos

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

Add a repository argument to allow callers of commit_graft_pos to be more specific about which repository to handle. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet.

As with the previous commits, use a macro to catch callers passing a repository other than the_repository at compile time.

---
 commit.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
commit.c +5 -4
index 2ad5537ed7..a77c05f51c 100644
@@ -105,7 +105,8 @@ static const unsigned char *commit_graft_sha1_access(size_t index, void *table)
 	return commit_graft_table[index]->oid.hash;
 }
 
-static int commit_graft_pos(const unsigned char *sha1)
+#define commit_graft_pos(r, s) commit_graft_pos_##r(s)
+static int commit_graft_pos_the_repository(const unsigned char *sha1)
 {
 	return sha1_pos(sha1, the_repository->parsed_objects.grafts,
 			the_repository->parsed_objects.grafts_nr,
@@ -114,7 +115,7 @@ static int commit_graft_pos(const unsigned char *sha1)
 
 int register_commit_graft(struct commit_graft *graft, int ignore_dups)
 {
-	int pos = commit_graft_pos(graft->oid.hash);
+	int pos = commit_graft_pos(the_repository, graft->oid.hash);
 
 	if (0 <= pos) {
 		if (ignore_dups)
@@ -214,7 +215,7 @@ struct commit_graft *lookup_commit_graft(const struct object_id *oid)
 {
 	int pos;
 	prepare_commit_graft();
-	pos = commit_graft_pos(oid->hash);
+	pos = commit_graft_pos(the_repository, oid->hash);
 	if (pos < 0)
 		return NULL;
 	return the_repository->parsed_objects.grafts[pos];
@@ -230,7 +231,7 @@ int for_each_commit_graft(each_commit_graft_fn fn, void *cb_data)
 
 int unregister_shallow(const struct object_id *oid)
 {
-	int pos = commit_graft_pos(oid->hash);
+	int pos = commit_graft_pos(the_repository, oid->hash);
 	if (pos < 0)
 		return -1;
 	if (pos + 1 < the_repository->parsed_objects.grafts_nr)
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#128 lore raw

PATCH 94/194 commit: add repository argument to parse_commit_buffer

In reply to Stefan Beller

Add a repository argument to allow the callers of parse_commit_buffer to be more specific about which repository to act on. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet.

As with the previous commits, use a macro to catch callers passing a repository other than the_repository at compile time.

Add the cocci patch that converted the callers.

---
 commit.c                               | 4 ++--
 commit.h                               | 3 ++-
 contrib/coccinelle/object_parser.cocci | 9 +++++++++
 object.c                               | 2 +-
 sha1_file.c                            | 2 +-
 5 files changed, 15 insertions(+), 5 deletions(-)
commit.c +2 -2
index a77c05f51c..f10a882d87 100644
@@ -323,7 +323,7 @@ const void *detach_commit_buffer(struct commit *commit, unsigned long *sizep)
 	return ret;
 }
 
-int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long size)
+int parse_commit_buffer_the_repository(struct commit *item, const void *buffer, unsigned long size)
 {
 	const char *tail = buffer;
 	const char *bufptr = buffer;
@@ -403,7 +403,7 @@ int parse_commit_gently(struct commit *item, int quiet_on_missing)
 		return error("Object %s not a commit",
 			     oid_to_hex(&item->object.oid));
 	}
-	ret = parse_commit_buffer(item, buffer, size);
+	ret = parse_commit_buffer(the_repository, item, buffer, size);
 	if (save_commit_buffer && !ret) {
 		set_commit_buffer(item, buffer, size);
 		return 0;
commit.h +2 -1
index 61e01112eb..20ad5acabc 100644
@@ -65,7 +65,8 @@ struct commit *lookup_commit_reference_by_name(const char *name);
  */
 struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref_name);
 
-int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long size);
+#define parse_commit_buffer(r, i, b, s) parse_commit_buffer_##r(i, b, s)
+int parse_commit_buffer_the_repository(struct commit *item, const void *buffer, unsigned long size);
 int parse_commit_gently(struct commit *item, int quiet_on_missing);
 static inline int parse_commit(struct commit *item)
 {
contrib/coccinelle/object_parser.cocci +9 -0
index c3cc4dfc9e..60f93c30c4 100644
@@ -45,6 +45,15 @@ expression E;
 + the_repository,
  E)
 
+@@
+expression E;
+expression F;
+expression G;
+@@
+ parse_commit_buffer(
++the_repository,
+ E, F, G)
+
 @@
 expression E;
 expression F;
object.c +1 -1
index 6676887315..f518e5703b 100644
@@ -211,7 +211,7 @@ struct object *parse_object_buffer(const struct object_id *oid, enum object_type
 	} else if (type == OBJ_COMMIT) {
 		struct commit *commit = lookup_commit(the_repository, oid);
 		if (commit) {
-			if (parse_commit_buffer(commit, buffer, size))
+			if (parse_commit_buffer(the_repository, commit, buffer, size))
 				return NULL;
 			if (!get_cached_commit_buffer(commit, NULL)) {
 				set_commit_buffer(commit, buffer, size);
sha1_file.c +1 -1
index df8bd4c260..0c2e215ae5 100644
@@ -1751,7 +1751,7 @@ static void check_commit(const void *buf, size_t size)
 {
 	struct commit c;
 	memset(&c, 0, sizeof(c));
-	if (parse_commit_buffer(&c, buf, size))
+	if (parse_commit_buffer(the_repository, &c, buf, size))
 		die("corrupt commit");
 }
 
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#129 lore raw

PATCH 95/194 object: add repository argument to register_commit_graft

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

Add a repository argument to allow callers of register_commit_graft to be more specific about which repository to handle. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet.

As with the previous commits, use a macro to catch callers passing a repository other than the_repository at compile time.

---
 builtin/blame.c                        | 3 ++-
 commit.c                               | 4 ++--
 commit.h                               | 3 ++-
 contrib/coccinelle/object_parser.cocci | 8 ++++++++
 shallow.c                              | 3 ++-
 5 files changed, 16 insertions(+), 5 deletions(-)
builtin/blame.c +2 -1
index 005f55aaa2..815b0c75ed 100644
@@ -8,6 +8,7 @@
 #include "cache.h"
 #include "config.h"
 #include "builtin.h"
+#include "repository.h"
 #include "commit.h"
 #include "diff.h"
 #include "revision.h"
@@ -490,7 +491,7 @@ static int read_ancestry(const char *graft_file)
 		/* The format is just "Commit Parent1 Parent2 ...\n" */
 		struct commit_graft *graft = read_graft_line(&buf);
 		if (graft)
-			register_commit_graft(graft, 0);
+			register_commit_graft(the_repository, graft, 0);
 	}
 	fclose(fp);
 	strbuf_release(&buf);
commit.c +2 -2
index f10a882d87..ce18e41e33 100644
@@ -113,7 +113,7 @@ static int commit_graft_pos_the_repository(const unsigned char *sha1)
 			commit_graft_sha1_access);
 }
 
-int register_commit_graft(struct commit_graft *graft, int ignore_dups)
+int register_commit_graft_the_repository(struct commit_graft *graft, int ignore_dups)
 {
 	int pos = commit_graft_pos(the_repository, graft->oid.hash);
 
@@ -189,7 +189,7 @@ static int read_graft_file(const char *graft_file)
 		struct commit_graft *graft = read_graft_line(&buf);
 		if (!graft)
 			continue;
-		if (register_commit_graft(graft, 1))
+		if (register_commit_graft(the_repository, graft, 1))
 			error("duplicate graft data: %s", buf.buf);
 	}
 	fclose(fp);
commit.h +2 -1
index 20ad5acabc..c8c5aafcb1 100644
@@ -176,7 +176,8 @@ struct commit_graft {
 typedef int (*each_commit_graft_fn)(const struct commit_graft *, void *);
 
 struct commit_graft *read_graft_line(struct strbuf *line);
-int register_commit_graft(struct commit_graft *, int);
+#define register_commit_graft(r, g, i) register_commit_graft_##r(g, i)
+int register_commit_graft_the_repository(struct commit_graft *, int);
 struct commit_graft *lookup_commit_graft(const struct object_id *oid);
 
 extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2);
contrib/coccinelle/object_parser.cocci +8 -0
index 60f93c30c4..fc56a90934 100644
@@ -90,3 +90,11 @@ expression E;
  lookup_commit(
 +the_repository,
  E)
+
+@@
+expression E;
+expression F;
+@@
+ register_commit_graft(
++the_repository,
+ E, F)
shallow.c +2 -1
index 97c483239a..925db794fd 100644
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "repository.h"
 #include "tempfile.h"
 #include "lockfile.h"
 #include "object-store.h"
@@ -38,7 +39,7 @@ int register_shallow(const struct object_id *oid)
 	graft->nr_parent = -1;
 	if (commit && commit->object.parsed)
 		commit->parents = NULL;
-	return register_commit_graft(graft, 0);
+	return register_commit_graft(the_repository, graft, 0);
 }
 
 int is_repository_shallow(void)
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#130 lore raw

PATCH 96/194 object: add repository argument to read_graft_file

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

Add a repository argument to allow the caller of read_graft_file to be more specific about which repository to handle. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet.

As with the previous commits, use a macro to catch callers passing a repository other than the_repository at compile time.

---
 commit.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
commit.c +3 -2
index ce18e41e33..d2c6367f85 100644
@@ -178,7 +178,8 @@ struct commit_graft *read_graft_line(struct strbuf *line)
 	return NULL;
 }
 
-static int read_graft_file(const char *graft_file)
+#define read_graft_file(r, f) read_graft_file_##r(f)
+static int read_graft_file_the_repository(const char *graft_file)
 {
 	FILE *fp = fopen_or_warn(graft_file, "r");
 	struct strbuf buf = STRBUF_INIT;
@@ -205,7 +206,7 @@ static void prepare_commit_graft(void)
 	if (commit_graft_prepared)
 		return;
 	graft_file = get_graft_file();
-	read_graft_file(graft_file);
+	read_graft_file(the_repository, graft_file);
 	/* make sure shallows are read */
 	is_repository_shallow();
 	commit_graft_prepared = 1;
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#131 lore raw

PATCH 97/194 object: add repository argument to prepare_commit_graft

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

Add a repository argument to allow the caller of prepare_commit_graft to be more specific about which repository to handle. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet.

As with the previous commits, use a macro to catch callers passing a repository other than the_repository at compile time.

---
 commit.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
commit.c +3 -2
index d2c6367f85..fbe27cf436 100644
@@ -198,7 +198,8 @@ static int read_graft_file_the_repository(const char *graft_file)
 	return 0;
 }
 
-static void prepare_commit_graft(void)
+#define prepare_commit_graft(r) prepare_commit_graft_##r()
+static void prepare_commit_graft_the_repository(void)
 {
 	static int commit_graft_prepared;
 	char *graft_file;
@@ -215,7 +216,7 @@ static void prepare_commit_graft(void)
 struct commit_graft *lookup_commit_graft(const struct object_id *oid)
 {
 	int pos;
-	prepare_commit_graft();
+	prepare_commit_graft(the_repository);
 	pos = commit_graft_pos(the_repository, oid->hash);
 	if (pos < 0)
 		return NULL;
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#132 lore raw

PATCH 98/194 object: add repository argument to lookup_commit_graft

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

Add a repository argument to allow callers of lookup_commit_graft to be more specific about which repository to handle. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet.

As with the previous commits, use a macro to catch callers passing a repository other than the_repository at compile time.

The included coccinelle semantic patch will adapt any new callers in the diff produced by make coccicheck.

---
 commit.c                               | 4 ++--
 commit.h                               | 3 ++-
 contrib/coccinelle/object_parser.cocci | 7 +++++++
 fsck.c                                 | 2 +-
 shallow.c                              | 5 +++--
 5 files changed, 15 insertions(+), 6 deletions(-)
commit.c +2 -2
index fbe27cf436..8e42af7565 100644
@@ -213,7 +213,7 @@ static void prepare_commit_graft_the_repository(void)
 	commit_graft_prepared = 1;
 }
 
-struct commit_graft *lookup_commit_graft(const struct object_id *oid)
+struct commit_graft *lookup_commit_graft_the_repository(const struct object_id *oid)
 {
 	int pos;
 	prepare_commit_graft(the_repository);
@@ -349,7 +349,7 @@ int parse_commit_buffer_the_repository(struct commit *item, const void *buffer,
 	bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */
 	pptr = &item->parents;
 
-	graft = lookup_commit_graft(&item->object.oid);
+	graft = lookup_commit_graft(the_repository, &item->object.oid);
 	while (bufptr + parent_entry_len < tail && !memcmp(bufptr, "parent ", 7)) {
 		struct commit *new_parent;
 
commit.h +2 -1
index c8c5aafcb1..f791a55379 100644
@@ -178,7 +178,8 @@ typedef int (*each_commit_graft_fn)(const struct commit_graft *, void *);
 struct commit_graft *read_graft_line(struct strbuf *line);
 #define register_commit_graft(r, g, i) register_commit_graft_##r(g, i)
 int register_commit_graft_the_repository(struct commit_graft *, int);
-struct commit_graft *lookup_commit_graft(const struct object_id *oid);
+#define lookup_commit_graft(r, o) lookup_commit_graft_##r(o)
+struct commit_graft *lookup_commit_graft_the_repository(const struct object_id *oid);
 
 extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2);
 extern struct commit_list *get_merge_bases_many(struct commit *one, int n, struct commit **twos);
contrib/coccinelle/object_parser.cocci +7 -0
index fc56a90934..987630f70f 100644
@@ -98,3 +98,10 @@ expression F;
  register_commit_graft(
 +the_repository,
  E, F)
+
+@@
+expression E;
+@@
+ lookup_commit_graft(
++the_repository,
+ E)
fsck.c +1 -1
index 54943b7dee..af0291121d 100644
@@ -739,7 +739,7 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
 		buffer += 41;
 		parent_line_count++;
 	}
-	graft = lookup_commit_graft(&commit->object.oid);
+	graft = lookup_commit_graft(the_repository, &commit->object.oid);
 	parent_count = commit_list_count(commit->parents);
 	if (graft) {
 		if (graft->nr_parent == -1 && !parent_count)
shallow.c +3 -2
index 925db794fd..004f99d4e2 100644
@@ -111,7 +111,7 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
 		cur_depth++;
 		if ((depth != INFINITE_DEPTH && cur_depth >= depth) ||
 		    (is_repository_shallow() && !commit->parents &&
-		     (graft = lookup_commit_graft(&commit->object.oid)) != NULL &&
+		     (graft = lookup_commit_graft(the_repository, &commit->object.oid)) != NULL &&
 		     graft->nr_parent < 0)) {
 			commit_list_insert(commit, &result);
 			commit->object.flags |= shallow_flag;
@@ -400,7 +400,8 @@ void prepare_shallow_info(struct shallow_info *info, struct oid_array *sa)
 	for (i = 0; i < sa->nr; i++) {
 		if (has_object_file(sa->oid + i)) {
 			struct commit_graft *graft;
-			graft = lookup_commit_graft(&sa->oid[i]);
+			graft = lookup_commit_graft(the_repository,
+						    &sa->oid[i]);
 			if (graft && graft->nr_parent < 0)
 				continue;
 			info->ours[info->nr_ours++] = i;
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#133 lore raw

PATCH 99/194 object: allow grow_object_hash to handle arbitrary repositories

In reply to Stefan Beller
---
 object.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
object.c +9 -8
index f518e5703b..be5d6c0931 100644
@@ -115,27 +115,28 @@ struct object *lookup_object_the_repository(const unsigned char *sha1)
  * power of 2 (but at least 32).  Copy the existing values to the new
  * hash map.
  */
-#define grow_object_hash(r) grow_object_hash_##r()
-static void grow_object_hash_the_repository(void)
+static void grow_object_hash(struct repository *r)
 {
 	int i;
 	/*
 	 * Note that this size must always be power-of-2 to match hash_obj
 	 * above.
 	 */
-	int new_hash_size = the_repository->parsed_objects.obj_hash_size < 32 ? 32 : 2 * the_repository->parsed_objects.obj_hash_size;
+	int new_hash_size = r->parsed_objects.obj_hash_size < 32
+				? 32
+				: 2 * r->parsed_objects.obj_hash_size;
 	struct object **new_hash;
 
 	new_hash = xcalloc(new_hash_size, sizeof(struct object *));
-	for (i = 0; i < the_repository->parsed_objects.obj_hash_size; i++) {
-		struct object *obj = the_repository->parsed_objects.obj_hash[i];
+	for (i = 0; i < r->parsed_objects.obj_hash_size; i++) {
+		struct object *obj = r->parsed_objects.obj_hash[i];
 		if (!obj)
 			continue;
 		insert_obj_hash(obj, new_hash, new_hash_size);
 	}
-	free(the_repository->parsed_objects.obj_hash);
-	the_repository->parsed_objects.obj_hash = new_hash;
-	the_repository->parsed_objects.obj_hash_size = new_hash_size;
+	free(r->parsed_objects.obj_hash);
+	r->parsed_objects.obj_hash = new_hash;
+	r->parsed_objects.obj_hash_size = new_hash_size;
 }
 
 void *create_object_the_repository(const unsigned char *sha1, void *o)
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#134 lore raw

PATCH 100/194 object: allow create_object to handle arbitrary repositories

---
 object.c | 12 ++++++------
 object.h |  3 +--
 2 files changed, 7 insertions(+), 8 deletions(-)
object.c +6 -6
index be5d6c0931..de19d814c1 100644
@@ -139,7 +139,7 @@ static void grow_object_hash(struct repository *r)
 	r->parsed_objects.obj_hash_size = new_hash_size;
 }
 
-void *create_object_the_repository(const unsigned char *sha1, void *o)
+void *create_object(struct repository *r, const unsigned char *sha1, void *o)
 {
 	struct object *obj = o;
 
@@ -147,12 +147,12 @@ void *create_object_the_repository(const unsigned char *sha1, void *o)
 	obj->flags = 0;
 	hashcpy(obj->oid.hash, sha1);
 
-	if (the_repository->parsed_objects.obj_hash_size - 1 <= the_repository->parsed_objects.nr_objs * 2)
-		grow_object_hash(the_repository);
+	if (r->parsed_objects.obj_hash_size - 1 <= r->parsed_objects.nr_objs * 2)
+		grow_object_hash(r);
 
-	insert_obj_hash(obj, the_repository->parsed_objects.obj_hash,
-			the_repository->parsed_objects.obj_hash_size);
-	the_repository->parsed_objects.nr_objs++;
+	insert_obj_hash(obj, r->parsed_objects.obj_hash,
+			r->parsed_objects.obj_hash_size);
+	r->parsed_objects.nr_objs++;
 	return obj;
 }
 
object.h +1 -2
index b667404f88..699adcf161 100644
@@ -105,8 +105,7 @@ extern struct object *get_indexed_object(unsigned int);
 #define lookup_object(r, s) lookup_object_##r(s)
 struct object *lookup_object_the_repository(const unsigned char *sha1);
 
-#define create_object(r, s, o) create_object_##r(s, o)
-extern void *create_object_the_repository(const unsigned char *sha1, void *obj);
+extern void *create_object(struct repository *r, const unsigned char *sha1, void *obj);
 
 void *object_as_type(struct object *obj, enum object_type type, int quiet);
 
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#135 lore raw

PATCH 101/194 object: allow lookup_object to handle arbitrary repositories

In reply to Stefan Beller
---
 object.c | 15 +++++++--------
 object.h |  3 +--
 2 files changed, 8 insertions(+), 10 deletions(-)
object.c +7 -8
index de19d814c1..7cac87aa22 100644
@@ -81,21 +81,20 @@ static void insert_obj_hash(struct object *obj, struct object **hash, unsigned i
  * Look up the record for the given sha1 in the hash map stored in
  * obj_hash.  Return NULL if it was not found.
  */
-struct object *lookup_object_the_repository(const unsigned char *sha1)
+struct object *lookup_object(struct repository *r, const unsigned char *sha1)
 {
 	unsigned int i, first;
 	struct object *obj;
 
-	if (!the_repository->parsed_objects.obj_hash)
+	if (!r->parsed_objects.obj_hash)
 		return NULL;
 
-	first = i = hash_obj(sha1,
-			     the_repository->parsed_objects.obj_hash_size);
-	while ((obj = the_repository->parsed_objects.obj_hash[i]) != NULL) {
+	first = i = hash_obj(sha1, r->parsed_objects.obj_hash_size);
+	while ((obj = r->parsed_objects.obj_hash[i]) != NULL) {
 		if (!hashcmp(sha1, obj->oid.hash))
 			break;
 		i++;
-		if (i == the_repository->parsed_objects.obj_hash_size)
+		if (i == r->parsed_objects.obj_hash_size)
 			i = 0;
 	}
 	if (obj && i != first) {
@@ -104,8 +103,8 @@ struct object *lookup_object_the_repository(const unsigned char *sha1)
 		 * that we do not need to walk the hash table the next
 		 * time we look for it.
 		 */
-		SWAP(the_repository->parsed_objects.obj_hash[i],
-		     the_repository->parsed_objects.obj_hash[first]);
+		SWAP(r->parsed_objects.obj_hash[i],
+		     r->parsed_objects.obj_hash[first]);
 	}
 	return obj;
 }
object.h +1 -2
index 699adcf161..d59edc88af 100644
@@ -102,8 +102,7 @@ extern struct object *get_indexed_object(unsigned int);
  * half-initialised objects, the caller is expected to initialize them
  * by calling parse_object() on them.
  */
-#define lookup_object(r, s) lookup_object_##r(s)
-struct object *lookup_object_the_repository(const unsigned char *sha1);
+struct object *lookup_object(struct repository *r, const unsigned char *sha1);
 
 extern void *create_object(struct repository *r, const unsigned char *sha1, void *obj);
 
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#136 lore raw

PATCH 102/194 object: add repository argument to lookup_unknown_object

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

Add a repository argument to allow callers of lookup_unknown_object to be more specific about which repository to handle. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet.

As with the previous commits, use a macro to catch callers passing a repository other than the_repository at compile time.

The included coccinelle semantic patch will adapt any new callers in the diff produced by make coccicheck.

---
 builtin/fsck.c                         | 2 +-
 builtin/pack-objects.c                 | 2 +-
 contrib/coccinelle/object_parser.cocci | 7 +++++++
 http-push.c                            | 2 +-
 object.c                               | 2 +-
 object.h                               | 3 ++-
 refs.c                                 | 2 +-
 t/helper/test-example-decorate.c       | 6 +++---
 upload-pack.c                          | 2 +-
 walker.c                               | 2 +-
 10 files changed, 19 insertions(+), 11 deletions(-)
builtin/fsck.c +1 -1
index 79da01d338..78cd8cdc69 100644
@@ -615,7 +615,7 @@ static int fsck_cache_tree(struct cache_tree *it)
 
 static void mark_object_for_connectivity(const struct object_id *oid)
 {
-	struct object *obj = lookup_unknown_object(oid->hash);
+	struct object *obj = lookup_unknown_object(the_repository, oid->hash);
 	obj->flags |= HAS_OBJ;
 }
 
builtin/pack-objects.c +1 -1
index 6348a5e721..fae579f12a 100644
@@ -2672,7 +2672,7 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs)
 
 		for (i = 0; i < p->num_objects; i++) {
 			nth_packed_object_oid(&oid, p, i);
-			o = lookup_unknown_object(oid.hash);
+			o = lookup_unknown_object(the_repository, oid.hash);
 			if (!(o->flags & OBJECT_ADDED))
 				mark_in_pack_object(o, p, &in_pack);
 			o->flags |= OBJECT_ADDED;
contrib/coccinelle/object_parser.cocci +7 -0
index 987630f70f..43a312480f 100644
@@ -105,3 +105,10 @@ expression E;
  lookup_commit_graft(
 +the_repository,
  E)
+
+@@
+expression E;
+@@
+ lookup_unknown_object(
++the_repository,
+ E)
http-push.c +1 -1
index de5e70ea7b..7cefc2df76 100644
@@ -1427,7 +1427,7 @@ static void one_remote_ref(const char *refname)
 	 * may be required for updating server info later.
 	 */
 	if (repo->can_update_info_refs && !has_object_file(&ref->old_oid)) {
-		obj = lookup_unknown_object(ref->old_oid.hash);
+		obj = lookup_unknown_object(the_repository, ref->old_oid.hash);
 		fprintf(stderr,	"  fetch %s for %s\n",
 			oid_to_hex(&ref->old_oid), refname);
 		add_fetch_request(obj);
object.c +1 -1
index 7cac87aa22..3eb12bec49 100644
@@ -174,7 +174,7 @@ void *object_as_type(struct object *obj, enum object_type type, int quiet)
 	}
 }
 
-struct object *lookup_unknown_object(const unsigned char *sha1)
+struct object *lookup_unknown_object_the_repository(const unsigned char *sha1)
 {
 	struct object *obj = lookup_object(the_repository, sha1);
 	if (!obj)
object.h +2 -1
index d59edc88af..083111d7b7 100644
@@ -130,7 +130,8 @@ struct object *parse_object_or_die(const struct object_id *oid, const char *name
 struct object *parse_object_buffer(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p);
 
 /** Returns the object, with potentially excess memory allocated. **/
-struct object *lookup_unknown_object(const unsigned  char *sha1);
+#define lookup_unknown_object(r, s) lookup_unknown_object_##r(s)
+struct object *lookup_unknown_object_the_repository(const unsigned char *sha1);
 
 struct object_list *object_list_insert(struct object *item,
 				       struct object_list **list_p);
refs.c +1 -1
index ddcb4a908f..0ea9b05d03 100644
@@ -300,7 +300,7 @@ static int filter_refs(const char *refname, const struct object_id *oid,
 
 enum peel_status peel_object(const struct object_id *name, struct object_id *oid)
 {
-	struct object *o = lookup_unknown_object(name->hash);
+	struct object *o = lookup_unknown_object(the_repository, name->hash);
 
 	if (o->type == OBJ_NONE) {
 		int type = sha1_object_info(the_repository, name->hash, NULL);
t/helper/test-example-decorate.c +3 -3
index 90dc97a9d0..156b72733e 100644
@@ -25,8 +25,8 @@ int cmd_main(int argc, const char **argv)
 	 * Add 2 objects, one with a non-NULL decoration and one with a NULL
 	 * decoration.
 	 */
-	one = lookup_unknown_object(one_oid.hash);
-	two = lookup_unknown_object(two_oid.hash);
+	one = lookup_unknown_object(the_repository, one_oid.hash);
+	two = lookup_unknown_object(the_repository, two_oid.hash);
 	ret = add_decoration(&n, one, &decoration_a);
 	if (ret)
 		die("BUG: when adding a brand-new object, NULL should be returned");
@@ -55,7 +55,7 @@ int cmd_main(int argc, const char **argv)
 	ret = lookup_decoration(&n, two);
 	if (ret != &decoration_b)
 		die("BUG: lookup should return added declaration");
-	three = lookup_unknown_object(three_oid.hash);
+	three = lookup_unknown_object(the_repository, three_oid.hash);
 	ret = lookup_decoration(&n, three);
 	if (ret)
 		die("BUG: lookup for unknown object should return NULL");
upload-pack.c +1 -1
index 469a843669..9c003553f8 100644
@@ -898,7 +898,7 @@ static void receive_needs(void)
 static int mark_our_ref(const char *refname, const char *refname_full,
 			const struct object_id *oid)
 {
-	struct object *o = lookup_unknown_object(oid->hash);
+	struct object *o = lookup_unknown_object(the_repository, oid->hash);
 
 	if (ref_is_hidden(refname, refname_full)) {
 		o->flags |= HIDDEN_REF;
walker.c +1 -1
index 2b6bd9da81..b96e00a8f1 100644
@@ -288,7 +288,7 @@ int walker_fetch(struct walker *walker, int targets, char **target,
 			error("Could not interpret response from server '%s' as something to pull", target[i]);
 			goto done;
 		}
-		if (process(walker, lookup_unknown_object(oids[i].hash)))
+		if (process(walker, lookup_unknown_object(the_repository, oids[i].hash)))
 			goto done;
 	}
 
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#137 lore raw

PATCH 103/194 object: allow lookup_unknown_object to handle arbitrary repositories

In reply to Stefan Beller
---
 object.c | 7 ++++---
 object.h | 3 +--
 2 files changed, 5 insertions(+), 5 deletions(-)
object.c +4 -3
index 3eb12bec49..9edddbe1d4 100644
@@ -174,11 +174,12 @@ void *object_as_type(struct object *obj, enum object_type type, int quiet)
 	}
 }
 
-struct object *lookup_unknown_object_the_repository(const unsigned char *sha1)
+struct object *lookup_unknown_object(struct repository *r,
+				     const unsigned char *sha1)
 {
-	struct object *obj = lookup_object(the_repository, sha1);
+	struct object *obj = lookup_object(r, sha1);
 	if (!obj)
-		obj = create_object(the_repository, sha1,
+		obj = create_object(r, sha1,
 				    alloc_object_node());
 	return obj;
 }
object.h +1 -2
index 083111d7b7..dd009a03ec 100644
@@ -130,8 +130,7 @@ struct object *parse_object_or_die(const struct object_id *oid, const char *name
 struct object *parse_object_buffer(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p);
 
 /** Returns the object, with potentially excess memory allocated. **/
-#define lookup_unknown_object(r, s) lookup_unknown_object_##r(s)
-struct object *lookup_unknown_object_the_repository(const unsigned char *sha1);
+struct object *lookup_unknown_object(struct repository *r, const unsigned char *sha1);
 
 struct object_list *object_list_insert(struct object *item,
 				       struct object_list **list_p);
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#138 lore raw

PATCH 104/194 object: add repository argument to parse_object_buffer

In reply to Stefan Beller

Add a repository argument to allow the callers of parse_object_buffer to be more specific about which repository to act on. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet.

As with the previous commits, use a macro to catch callers passing a repository other than the_repository at compile time.

Add the cocci patch that converted the callers.

---
 builtin/fast-export.c                  |  3 ++-
 builtin/fsck.c                         |  6 ++++--
 builtin/index-pack.c                   |  3 ++-
 builtin/unpack-objects.c               |  3 ++-
 contrib/coccinelle/object_parser.cocci | 11 +++++++++++
 object.c                               |  5 +++--
 object.h                               |  3 ++-
 ref-filter.c                           |  3 ++-
 8 files changed, 28 insertions(+), 9 deletions(-)
builtin/fast-export.c +2 -1
index 322adfd408..b0f229351d 100644
@@ -244,7 +244,8 @@ static void export_blob(const struct object_id *oid)
 			die ("Could not read blob %s", oid_to_hex(oid));
 		if (check_sha1_signature(oid->hash, buf, size, typename(type)) < 0)
 			die("sha1 mismatch in blob %s", oid_to_hex(oid));
-		object = parse_object_buffer(oid, type, size, buf, &eaten);
+		object = parse_object_buffer(the_repository, oid, type,
+					     size, buf, &eaten);
 	}
 
 	if (!object)
builtin/fsck.c +4 -2
index 78cd8cdc69..527c03eb39 100644
@@ -377,7 +377,8 @@ static int fsck_obj_buffer(const struct object_id *oid, enum object_type type,
 	 * verify_packfile(), data_valid variable for details.
 	 */
 	struct object *obj;
-	obj = parse_object_buffer(oid, type, size, buffer, eaten);
+	obj = parse_object_buffer(the_repository, oid, type, size, buffer,
+				  eaten);
 	if (!obj) {
 		errors_found |= ERROR_OBJECT;
 		return error("%s: object corrupt or missing", oid_to_hex(oid));
@@ -499,7 +500,8 @@ static struct object *parse_loose_object(const struct object_id *oid,
 	if (!contents && type != OBJ_BLOB)
 		die("BUG: read_loose_object streamed a non-blob");
 
-	obj = parse_object_buffer(oid, type, size, contents, &eaten);
+	obj = parse_object_buffer(the_repository, oid, type, size,
+				  contents, &eaten);
 
 	if (!eaten)
 		free(contents);
builtin/index-pack.c +2 -1
index 67db12fc43..f570e16bb6 100644
@@ -850,7 +850,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
 			 * we do not need to free the memory here, as the
 			 * buf is deleted by the caller.
 			 */
-			obj = parse_object_buffer(oid, type, size, buf,
+			obj = parse_object_buffer(the_repository, oid, type,
+						  size, buf,
 						  &eaten);
 			if (!obj)
 				die(_("invalid %s"), typename(type));
builtin/unpack-objects.c +2 -1
index 8d13c5145c..6b8fb918b6 100644
@@ -263,7 +263,8 @@ static void write_object(unsigned nr, enum object_type type,
 		int eaten;
 		hash_sha1_file(buf, size, typename(type), obj_list[nr].oid.hash);
 		added_object(nr, type, buf, size);
-		obj = parse_object_buffer(&obj_list[nr].oid, type, size, buf,
+		obj = parse_object_buffer(the_repository, &obj_list[nr].oid,
+					  type, size, buf,
 					  &eaten);
 		if (!obj)
 			die("invalid %s", typename(type));
contrib/coccinelle/object_parser.cocci +11 -0
index 43a312480f..c2886c5e50 100644
@@ -45,6 +45,17 @@ expression E;
 + the_repository,
  E)
 
+@@
+expression E;
+expression F;
+expression G;
+expression H;
+expression I;
+@@
+parse_object_buffer(
++ the_repository,
+ E, F, G, H, I)
+
 @@
 expression E;
 expression F;
object.c +3 -2
index 9edddbe1d4..a10983755c 100644
@@ -184,7 +184,7 @@ struct object *lookup_unknown_object(struct repository *r,
 	return obj;
 }
 
-struct object *parse_object_buffer(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p)
+struct object *parse_object_buffer_the_repository(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p)
 {
 	struct object *obj;
 	*eaten_p = 0;
@@ -276,7 +276,8 @@ struct object *parse_object_the_repository(const struct object_id *oid)
 			return NULL;
 		}
 
-		obj = parse_object_buffer(oid, type, size, buffer, &eaten);
+		obj = parse_object_buffer(the_repository, oid, type, size,
+					  buffer, &eaten);
 		if (!eaten)
 			free(buffer);
 		return obj;
object.h +2 -1
index dd009a03ec..c9ea2285e8 100644
@@ -127,7 +127,8 @@ struct object *parse_object_or_die(const struct object_id *oid, const char *name
  * parsing it.  eaten_p indicates if the object has a borrowed copy
  * of buffer and the caller should not free() it.
  */
-struct object *parse_object_buffer(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p);
+#define parse_object_buffer(r, o, t, s, b, e) parse_object_buffer_##r(o, t, s, b, e)
+struct object *parse_object_buffer_the_repository(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p);
 
 /** Returns the object, with potentially excess memory allocated. **/
 struct object *lookup_unknown_object(struct repository *r, const unsigned char *sha1);
ref-filter.c +2 -1
index b4b6f8801c..256887b585 100644
@@ -733,7 +733,8 @@ static void *get_obj(const struct object_id *oid, struct object **obj, unsigned
 	void *buf = read_sha1_file(oid->hash, &type, sz);
 
 	if (buf)
-		*obj = parse_object_buffer(oid, type, *sz, buf, eaten);
+		*obj = parse_object_buffer(the_repository, oid, type, *sz,
+					   buf, eaten);
 	else
 		*obj = NULL;
 	return buf;
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#139 lore raw

PATCH 105/194 repository: keep track of all open repositories

In reply to Stefan Beller

When Git mmap's packfiles into memory it has to keep track of the memory management itself to not use too much memory. Each repository has its own set of packfiles that it keeps track of. To scan all the packfiles that are currently mmap'ed, we need to keep track of all repositories that are currently opened.

---
 builtin/grep.c     |  2 +-
 builtin/ls-files.c |  2 +-
 packfile.c         |  9 ++++++--
 repository.c       | 66 +++++++++++++++++++++++++++++++++++++-----------------
 repository.h       |  6 ++++-
 submodule.c        |  2 +-
 6 files changed, 61 insertions(+), 26 deletions(-)
builtin/grep.c +1 -1
index 2c43307f02..a9a908d92a 100644
@@ -465,7 +465,7 @@ static int grep_submodule(struct grep_opt *opt, struct repository *superproject,
 		hit = grep_cache(opt, &submodule, pathspec, 1);
 	}
 
-	repo_clear(&submodule);
+	repo_free(&submodule);
 	return hit;
 }
 
builtin/ls-files.c +1 -1
index 2fc836e330..a6d824a2ba 100644
@@ -215,7 +215,7 @@ static void show_submodule(struct repository *superproject,
 
 	show_files(&submodule, dir);
 
-	repo_clear(&submodule);
+	repo_free(&submodule);
 }
 
 static void show_ce(struct repository *repo, struct dir_struct *dir,
packfile.c +7 -2
index 6a8d5edf6d..f7e8a81ded 100644
@@ -237,13 +237,18 @@ static void scan_windows(struct packed_git *p,
 
 static int unuse_one_window(struct packed_git *current)
 {
+	int i = 0;
 	struct packed_git *p, *lru_p = NULL;
 	struct pack_window *lru_w = NULL, *lru_l = NULL;
 
 	if (current)
 		scan_windows(current, &lru_p, &lru_w, &lru_l);
-	for (p = the_repository->objects.packed_git; p; p = p->next)
-		scan_windows(p, &lru_p, &lru_w, &lru_l);
+	for (i = -1; i < open_repos_nr; i++) {
+		struct repository *r = i == -1 ? the_repository : open_repos[i];
+		for (p = r->objects.packed_git; p; p = p->next)
+			scan_windows(p, &lru_p, &lru_w, &lru_l);
+	}
+
 	if (lru_p) {
 		munmap(lru_w->base, lru_w->len);
 		pack_mapped -= lru_w->len;
repository.c +46 -20

88 lines not on this page · raw message

repository.h +5 -1
index c8a34d1ac9..74b2b27986 100644
@@ -110,6 +110,10 @@ struct repository {
 
 extern struct repository *the_repository;
 
+/* Any open repo except the_repository */
+extern struct repository **open_repos;
+extern int open_repos_nr;
+
 extern void repo_set_gitdir(struct repository *repo, const char *path);
 extern void repo_set_worktree(struct repository *repo, const char *path);
 extern void repo_set_hash_algo(struct repository *repo, int algo);
@@ -117,7 +121,7 @@ extern int repo_init(struct repository *repo, const char *gitdir, const char *wo
 extern int repo_submodule_init(struct repository *submodule,
 			       struct repository *superproject,
 			       const char *path);
-extern void repo_clear(struct repository *repo);
+extern void repo_free(struct repository *repo);
 
 /*
  * Populates the repository's index from its index_file, an index struct will
submodule.c +1 -1
index aec62e6c7d..9c4c01ba73 100644
@@ -898,7 +898,7 @@ static int submodule_has_commits(const char *path, struct oid_array *commits)
 		strbuf_release(&out);
 	}
 
-	repo_clear(&sub);
+	repo_free(&sub);
 	return has_commit.result;
 }
 
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#140 lore raw

PATCH 106/194 Rename sha1_object_info.cocci to object_store.cocci

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

---
 contrib/coccinelle/{sha1_object_info.cocci => object_store.cocci} | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename contrib/coccinelle/{sha1_object_info.cocci => object_store.cocci} (100%)
contrib/coccinelle/object_store.cocci renamed from contrib/coccinelle/sha1_object_info.cocci +0 -0
similarity index 100%
rename from contrib/coccinelle/sha1_object_info.cocci
rename to contrib/coccinelle/object_store.cocci
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#141 lore raw

PATCH 107/194 alternates: add repository argument to add_to_alternates_file

In reply to Stefan Beller

Add a repository argument to allow callers of add_to_alternates_file to be more specific about which repository to handle. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet.

As with the previous commits, use a macro to catch callers passing a repository other than the_repository at compile time.

---
 alternates.h    | 3 ++-
 builtin/clone.c | 9 +++++----
 sha1_file.c     | 2 +-
 3 files changed, 8 insertions(+), 6 deletions(-)
alternates.h +2 -1
index df5dc67e2e..2d06b71e50 100644
@@ -48,7 +48,8 @@ struct alternate_object_database *alloc_alt_odb(const char *dir);
  * Add the directory to the on-disk alternates file; the new entry will also
  * take effect in the current process.
  */
-extern void add_to_alternates_file(const char *dir);
+#define add_to_alternates_file(r, d) add_to_alternates_file_##r(d)
+extern void add_to_alternates_file_the_repository(const char *dir);
 
 /*
  * Add the directory to the in-memory list of alternates (along with any
builtin/clone.c +5 -4
index 6efe189846..548255f955 100644
@@ -11,6 +11,7 @@
 #include "builtin.h"
 #include "config.h"
 #include "lockfile.h"
+#include "repository.h"
 #include "alternates.h"
 #include "parse-options.h"
 #include "fetch-pack.h"
@@ -330,7 +331,7 @@ static int add_one_reference(struct string_list_item *item, void *cb_data)
 	} else {
 		struct strbuf sb = STRBUF_INIT;
 		strbuf_addf(&sb, "%s/objects", ref_git);
-		add_to_alternates_file(sb.buf);
+		add_to_alternates_file(the_repository, sb.buf);
 		strbuf_release(&sb);
 	}
 
@@ -372,12 +373,12 @@ static void copy_alternates(struct strbuf *src, struct strbuf *dst,
 		if (!line.len || line.buf[0] == '#')
 			continue;
 		if (is_absolute_path(line.buf)) {
-			add_to_alternates_file(line.buf);
+			add_to_alternates_file(the_repository, line.buf);
 			continue;
 		}
 		abs_path = mkpathdup("%s/objects/%s", src_repo, line.buf);
 		if (!normalize_path_copy(abs_path, abs_path))
-			add_to_alternates_file(abs_path);
+			add_to_alternates_file(the_repository, abs_path);
 		else
 			warning("skipping invalid relative alternate: %s/%s",
 				src_repo, line.buf);
@@ -456,7 +457,7 @@ static void clone_local(const char *src_repo, const char *dest_repo)
 		struct strbuf alt = STRBUF_INIT;
 		get_common_dir(&alt, src_repo);
 		strbuf_addstr(&alt, "/objects");
-		add_to_alternates_file(alt.buf);
+		add_to_alternates_file(the_repository, alt.buf);
 		strbuf_release(&alt);
 	} else {
 		struct strbuf src = STRBUF_INIT;
sha1_file.c +1 -1
index 0c2e215ae5..066aa187a1 100644
@@ -538,7 +538,7 @@ struct alternate_object_database *alloc_alt_odb(const char *dir)
 	return ent;
 }
 
-void add_to_alternates_file(const char *reference)
+void add_to_alternates_file_the_repository(const char *reference)
 {
 	struct lock_file lock = LOCK_INIT;
 	char *alts = git_pathdup("objects/info/alternates");
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#142 lore raw

PATCH 108/194 alternates: add repository argument to add_to_alternates_memory

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

Add a repository argument to allow callers of add_to_alternates_memory to be more specific about which repository to handle. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet.

As with the previous commits, use a macro to catch callers passing a repository other than the_repository at compile time.

---
 alternates.h              | 3 ++-
 builtin/grep.c            | 2 +-
 sha1_file.c               | 2 +-
 submodule.c               | 2 +-
 t/helper/test-ref-store.c | 2 +-
 tmp-objdir.c              | 2 +-
 6 files changed, 7 insertions(+), 6 deletions(-)
alternates.h +2 -1
index 2d06b71e50..e4520ae5c7 100644
@@ -56,7 +56,8 @@ extern void add_to_alternates_file_the_repository(const char *dir);
  * recursive alternates it points to), but do not modify the on-disk alternates
  * file.
  */
-extern void add_to_alternates_memory(const char *dir);
+#define add_to_alternates_memory(r, d) add_to_alternates_memory_##r(d)
+extern void add_to_alternates_memory_the_repository(const char *dir);
 
 /*
  * Returns a scratch strbuf pre-filled with the alternate object directory,
builtin/grep.c +1 -1
index a9a908d92a..a83e87a676 100644
@@ -433,7 +433,7 @@ static int grep_submodule(struct grep_opt *opt, struct repository *superproject,
 	 * object.
 	 */
 	grep_read_lock();
-	add_to_alternates_memory(submodule.objectdir);
+	add_to_alternates_memory(the_repository, submodule.objectdir);
 	grep_read_unlock();
 
 	if (oid) {
sha1_file.c +1 -1
index 066aa187a1..aa564e3ad4 100644
@@ -581,7 +581,7 @@ void add_to_alternates_file_the_repository(const char *reference)
 	free(alts);
 }
 
-void add_to_alternates_memory(const char *reference)
+void add_to_alternates_memory_the_repository(const char *reference)
 {
 	/*
 	 * Make sure alternates are initialized, or else our entry may be
submodule.c +1 -1
index 9c4c01ba73..f9426beff1 100644
@@ -165,7 +165,7 @@ static int add_submodule_odb(const char *path)
 		ret = -1;
 		goto done;
 	}
-	add_to_alternates_memory(objects_directory.buf);
+	add_to_alternates_memory(the_repository, objects_directory.buf);
 done:
 	strbuf_release(&objects_directory);
 	return ret;
t/helper/test-ref-store.c +1 -1
index 93ea6f781e..8442ee8146 100644
@@ -31,7 +31,7 @@ static const char **get_store(const char **argv, struct ref_store **refs)
 		ret = strbuf_git_path_submodule(&sb, gitdir, "objects/");
 		if (ret)
 			die("strbuf_git_path_submodule failed: %d", ret);
-		add_to_alternates_memory(sb.buf);
+		add_to_alternates_memory(the_repository, sb.buf);
 		strbuf_release(&sb);
 
 		*refs = get_submodule_ref_store(gitdir);
tmp-objdir.c +1 -1
index bf34315adf..a9334d3fc5 100644
@@ -288,5 +288,5 @@ const char **tmp_objdir_env(const struct tmp_objdir *t)
 
 void tmp_objdir_add_as_alternate(const struct tmp_objdir *t)
 {
-	add_to_alternates_memory(t->path.buf);
+	add_to_alternates_memory(the_repository, t->path.buf);
 }
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#143 lore raw

PATCH 109/194 object-store: move check_sha1_signature to object-store.h

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

When map == NULL, check_sha1_signature reads the object from the object store to hash it. Move the declaration of this function to object-store.h to make it easier to find.

While at it, clarify the comment describing its API.

---
 cache.h        | 2 --
 object-store.h | 9 +++++++++
 sha1_file.c    | 6 ------
 3 files changed, 9 insertions(+), 8 deletions(-)
cache.h +0 -2
index 634172cec4..15ba480ac3 100644
@@ -1195,8 +1195,6 @@ extern int git_open_cloexec(const char *name, int flags);
 extern int unpack_sha1_header(git_zstream *stream, unsigned char *map, unsigned long mapsize, void *buffer, unsigned long bufsiz);
 extern int parse_sha1_header(const char *hdr, unsigned long *sizep);
 
-extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned long size, const char *type);
-
 extern int finalize_object_file(const char *tmpfile, const char *filename);
 
 /* Helper to check and "touch" a file */
object-store.h +9 -0
index d009f952f8..a0e9824406 100644
@@ -99,6 +99,15 @@ extern int pretend_sha1_file(void *, unsigned long, enum object_type, unsigned c
 extern int force_object_loose(const unsigned char *sha1, time_t mtime);
 extern void *map_sha1_file(struct repository *r, const unsigned char *sha1, unsigned long *size);
 
+/*
+ * Rehash an object's data to make sure the object name actually matches
+ * "sha1" to detect object corruption.
+ *
+ * The in-core object data should be in "map". If "map" == NULL, reads the
+ * named object using the streaming interface and rehashes it on the fly.
+ */
+extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned long size, const char *type);
+
 /*
  * Convenience for sha1_object_info_extended() with a NULL struct
  * object_info. OBJECT_INFO_SKIP_CACHED is automatically set; pass
sha1_file.c +0 -6
index aa564e3ad4..3262075497 100644
@@ -802,12 +802,6 @@ void *xmmap(void *start, size_t length,
 	return ret;
 }
 
-/*
- * With an in-core object data in "map", rehash it to make sure the
- * object name actually matches "sha1" to detect object corruption.
- * With "map" == NULL, try reading the object named with "sha1" using
- * the streaming interface and rehash it to do the same.
- */
 int check_sha1_signature(const unsigned char *sha1, void *map,
 			 unsigned long size, const char *type)
 {
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#144 lore raw

PATCH 110/194 object-store: add repository argument to check_sha1_signature

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

Add a repository argument to allow callers of check_sha1_signature to be more specific about which repository to handle. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet.

As with the previous commits, use a macro to catch callers passing a repository other than the_repository at compile time.

The included coccinelle semantic patch will adapt any new callers in the diff produced by make coccicheck.

---
 builtin/fast-export.c                 |  2 +-
 builtin/index-pack.c                  |  2 +-
 builtin/mktag.c                       |  4 +++-
 contrib/coccinelle/object_store.cocci | 10 ++++++++++
 object-store.h                        |  3 ++-
 object.c                              |  4 ++--
 pack-check.c                          |  2 +-
 sha1_file.c                           |  4 ++--
 8 files changed, 22 insertions(+), 9 deletions(-)
builtin/fast-export.c +1 -1
index b0f229351d..5d524e7dd2 100644
@@ -242,7 +242,7 @@ static void export_blob(const struct object_id *oid)
 		buf = read_sha1_file(oid->hash, &type, &size);
 		if (!buf)
 			die ("Could not read blob %s", oid_to_hex(oid));
-		if (check_sha1_signature(oid->hash, buf, size, typename(type)) < 0)
+		if (check_sha1_signature(the_repository, oid->hash, buf, size, typename(type)) < 0)
 			die("sha1 mismatch in blob %s", oid_to_hex(oid));
 		object = parse_object_buffer(the_repository, oid, type,
 					     size, buf, &eaten);
builtin/index-pack.c +1 -1
index f570e16bb6..0928ed8dd5 100644
@@ -1383,7 +1383,7 @@ static void fix_unresolved_deltas(struct sha1file *f)
 		if (!base_obj->data)
 			continue;
 
-		if (check_sha1_signature(d->sha1, base_obj->data,
+		if (check_sha1_signature(the_repository, d->sha1, base_obj->data,
 				base_obj->size, typename(type)))
 			die(_("local object %s is corrupt"), sha1_to_hex(d->sha1));
 		base_obj->obj = append_obj_to_pack(f, d->sha1,
builtin/mktag.c +3 -1
index ab41735f2a..d05fdb824a 100644
@@ -30,7 +30,9 @@ static int verify_object(const unsigned char *sha1, const char *expected_type)
 
 	if (buffer) {
 		if (type == type_from_string(expected_type))
-			ret = check_sha1_signature(repl, buffer, size, expected_type);
+			ret = check_sha1_signature(the_repository, repl,
+						   buffer, size,
+						   expected_type);
 		free(buffer);
 	}
 	return ret;
contrib/coccinelle/object_store.cocci +10 -0
index 800e0581e5..6e6e5454da 100644
@@ -5,3 +5,13 @@ expression F;
  sha1_object_info(
 +the_repository,
  E, F)
+
+@@
+expression E;
+expression F;
+expression G;
+expression H;
+@@
+ check_sha1_signature(
++the_repository,
+ E, F, G, H)
object-store.h +2 -1
index a0e9824406..178268a048 100644
@@ -106,7 +106,8 @@ extern void *map_sha1_file(struct repository *r, const unsigned char *sha1, unsi
  * The in-core object data should be in "map". If "map" == NULL, reads the
  * named object using the streaming interface and rehashes it on the fly.
  */
-extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned long size, const char *type);
+#define check_sha1_signature(r, s, m, sz, t) check_sha1_signature_##r(s, m, sz, t)
+extern int check_sha1_signature_the_repository(const unsigned char *sha1, void *buf, unsigned long size, const char *type);
 
 /*
  * Convenience for sha1_object_info_extended() with a NULL struct
object.c +2 -2
index a10983755c..85b0360e0a 100644
@@ -260,7 +260,7 @@ struct object *parse_object_the_repository(const struct object_id *oid)
 	if ((obj && obj->type == OBJ_BLOB) ||
 	    (!obj && has_object_file(oid) &&
 	     sha1_object_info(the_repository, oid->hash, NULL) == OBJ_BLOB)) {
-		if (check_sha1_signature(repl, NULL, 0, NULL) < 0) {
+		if (check_sha1_signature(the_repository, repl, NULL, 0, NULL) < 0) {
 			error("sha1 mismatch %s", oid_to_hex(oid));
 			return NULL;
 		}
@@ -270,7 +270,7 @@ struct object *parse_object_the_repository(const struct object_id *oid)
 
 	buffer = read_sha1_file(oid->hash, &type, &size);
 	if (buffer) {
-		if (check_sha1_signature(repl, buffer, size, typename(type)) < 0) {
+		if (check_sha1_signature(the_repository, repl, buffer, size, typename(type)) < 0) {
 			free(buffer);
 			error("sha1 mismatch %s", sha1_to_hex(repl));
 			return NULL;
pack-check.c +1 -1
index 25afd59c7d..2eb07cf596 100644
@@ -143,7 +143,7 @@ static int verify_packfile(struct packed_git *p,
 			err = error("cannot unpack %s from %s at offset %"PRIuMAX"",
 				    oid_to_hex(entries[i].oid.oid), p->pack_name,
 				    (uintmax_t)entries[i].offset);
-		else if (check_sha1_signature(entries[i].oid.hash, data, size, typename(type)))
+		else if (check_sha1_signature(the_repository, entries[i].oid.hash, data, size, typename(type)))
 			err = error("packed %s from %s is corrupt",
 				    oid_to_hex(entries[i].oid.oid), p->pack_name);
 		else if (fn) {
sha1_file.c +2 -2
index 3262075497..9ef25e6154 100644
@@ -802,7 +802,7 @@ void *xmmap(void *start, size_t length,
 	return ret;
 }
 
-int check_sha1_signature(const unsigned char *sha1, void *map,
+int check_sha1_signature_the_repository(const unsigned char *sha1, void *map,
 			 unsigned long size, const char *type)
 {
 	unsigned char real_sha1[20];
@@ -2207,7 +2207,7 @@ int read_loose_object(const char *path,
 			git_inflate_end(&stream);
 			goto out;
 		}
-		if (check_sha1_signature(expected_sha1, *contents,
+		if (check_sha1_signature(the_repository, expected_sha1, *contents,
 					 *size, typename(*type))) {
 			error("sha1 mismatch for %s (expected %s)", path,
 			      sha1_to_hex(expected_sha1));
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#145 lore raw

PATCH 111/194 object-store: add repository argument to read_object

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

Add a repository argument to allow callers of read_object to be more specific about which repository to handle. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet.

As with the previous commits, use a macro to catch callers passing a repository other than the_repository at compile time.

---
 sha1_file.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
sha1_file.c +4 -3
index 9ef25e6154..e62595e3e2 100644
@@ -1319,7 +1319,8 @@ int sha1_object_info(struct repository *r,
 	return type;
 }
 
-static void *read_object(const unsigned char *sha1, enum object_type *type,
+#define read_object(r, s, t, sz) read_object_##r(s, t, sz)
+static void *read_object_the_repository(const unsigned char *sha1, enum object_type *type,
 			 unsigned long *size)
 {
 	struct object_info oi = OBJECT_INFO_INIT;
@@ -1369,7 +1370,7 @@ void *read_sha1_file_extended(const unsigned char *sha1,
 		lookup_replace_object(the_repository, sha1) : sha1;
 
 	errno = 0;
-	data = read_object(repl, type, size);
+	data = read_object(the_repository, repl, type, size);
 	if (data)
 		return data;
 
@@ -1701,7 +1702,7 @@ int force_object_loose(const unsigned char *sha1, time_t mtime)
 
 	if (has_loose_object(sha1))
 		return 0;
-	buf = read_object(sha1, &type, &len);
+	buf = read_object(the_repository, sha1, &type, &len);
 	if (!buf)
 		return error("cannot read sha1_file for %s", sha1_to_hex(sha1));
 	hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", typename(type), len) + 1;
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#146 lore raw

PATCH 112/194 object-store: add repository argument to read_sha1_file_extended

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

Add a repository argument to allow callers of read_sha1_file_extended to be more specific about which repository to handle. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet.

As with the previous commits, use a macro to catch callers passing a repository other than the_repository at compile time.

The included coccinelle semantic patch will adapt any new callers in the diff produced by make coccicheck.

---
 contrib/coccinelle/object_store.cocci | 10 ++++++++++
 object-store.h                        |  5 +++--
 sha1_file.c                           |  2 +-
 streaming.c                           |  3 ++-
 4 files changed, 16 insertions(+), 4 deletions(-)
contrib/coccinelle/object_store.cocci +10 -0
index 6e6e5454da..915dd176dd 100644
@@ -15,3 +15,13 @@ expression H;
  check_sha1_signature(
 +the_repository,
  E, F, G, H)
+
+@@
+expression E;
+expression F;
+expression G;
+expression H;
+@@
+ read_sha1_file_extended(
++the_repository,
+ E, F, G, H)
object-store.h +3 -2
index 178268a048..d6462cd9f1 100644
@@ -82,12 +82,13 @@ struct packed_git {
 	char pack_name[FLEX_ARRAY]; /* more */
 };
 
-extern void *read_sha1_file_extended(const unsigned char *sha1,
+#define read_sha1_file_extended(r, s, t, sz, l) read_sha1_file_extended_##r(s, t, sz, l)
+extern void *read_sha1_file_extended_the_repository(const unsigned char *sha1,
 				     enum object_type *type,
 				     unsigned long *size, int lookup_replace);
 static inline void *read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size)
 {
-	return read_sha1_file_extended(sha1, type, size, 1);
+	return read_sha1_file_extended(the_repository, sha1, type, size, 1);
 }
 
 /* Read and unpack a sha1 file into memory, write memory to a sha1 file */
sha1_file.c +1 -1
index e62595e3e2..2d9a794654 100644
@@ -1357,7 +1357,7 @@ int pretend_sha1_file(void *buf, unsigned long len, enum object_type type,
  * deal with them should arrange to call read_object() and give error
  * messages themselves.
  */
-void *read_sha1_file_extended(const unsigned char *sha1,
+void *read_sha1_file_extended_the_repository(const unsigned char *sha1,
 			      enum object_type *type,
 			      unsigned long *size,
 			      int lookup_replace)
streaming.c +2 -1
index bc3c4811ca..f0ff5e7245 100644
@@ -490,7 +490,8 @@ static struct stream_vtbl incore_vtbl = {
 
 static open_method_decl(incore)
 {
-	st->u.incore.buf = read_sha1_file_extended(sha1, type, &st->size, 0);
+	st->u.incore.buf = read_sha1_file_extended(the_repository, sha1,
+						   type, &st->size, 0);
 	st->u.incore.read_ptr = 0;
 	st->vtbl = &incore_vtbl;
 
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#147 lore raw

PATCH 113/194 object-store: add repository argument to read_sha1_file

In reply to Stefan Beller

Add a repository argument to allow callers of read_sha1_file to be more specific about which repository to handle. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet.

As with the previous commits, use a macro to catch callers passing a repository other than the_repository at compile time.

The included coccinelle semantic patch will adapt any new callers in the diff produced by make coccicheck.

---
 apply.c                               |  7 +++++--
 archive.c                             |  3 ++-
 bisect.c                              |  4 +++-
 blame.c                               |  7 +++++--
 builtin/cat-file.c                    | 15 ++++++++++-----
 builtin/difftool.c                    |  4 +++-
 builtin/fast-export.c                 |  6 ++++--
 builtin/fmt-merge-msg.c               |  3 ++-
 builtin/grep.c                        |  2 +-
 builtin/index-pack.c                  |  6 ++++--
 builtin/log.c                         |  2 +-
 builtin/merge-tree.c                  |  8 ++++++--
 builtin/mktag.c                       |  2 +-
 builtin/notes.c                       |  7 ++++---
 builtin/pack-objects.c                | 17 +++++++++++------
 builtin/reflog.c                      |  3 ++-
 builtin/tag.c                         |  4 ++--
 builtin/unpack-file.c                 |  3 ++-
 builtin/unpack-objects.c              |  3 ++-
 builtin/verify-commit.c               |  2 +-
 bundle.c                              |  2 +-
 combine-diff.c                        |  4 +++-
 commit.c                              |  9 ++++++---
 config.c                              |  2 +-
 contrib/coccinelle/object_store.cocci |  9 +++++++++
 diff.c                                |  3 ++-
 dir.c                                 |  3 ++-
 entry.c                               |  4 +++-
 fast-import.c                         |  9 ++++++---
 fsck.c                                |  3 ++-
 grep.c                                |  4 +++-
 http-push.c                           |  3 ++-
 mailmap.c                             |  3 ++-
 match-trees.c                         |  5 +++--
 merge-blobs.c                         |  7 +++++--
 merge-recursive.c                     |  5 +++--
 notes-cache.c                         |  3 ++-
 notes-merge.c                         |  2 +-
 notes.c                               | 11 +++++++----
 object-store.h                        |  3 ++-
 object.c                              |  2 +-
 read-cache.c                          |  6 ++++--
 ref-filter.c                          |  2 +-
 remote-testsvn.c                      |  5 +++--
 rerere.c                              |  4 +++-
 sha1_file.c                           |  3 ++-
 submodule-config.c                    |  3 ++-
 tag.c                                 |  5 +++--
 tree-walk.c                           |  4 +++-
 tree.c                                |  3 ++-
 xdiff-interface.c                     |  3 ++-
 51 files changed, 162 insertions(+), 80 deletions(-)
apply.c +5 -2
index de4440cd2a..fa266f6c27 100644
@@ -10,6 +10,7 @@
 #include "cache.h"
 #include "config.h"
 #include "object-store.h"
+#include "repository.h"
 #include "blob.h"
 #include "delta.h"
 #include "diff.h"
@@ -3181,7 +3182,8 @@ static int apply_binary(struct apply_state *state,
 		unsigned long size;
 		char *result;
 
-		result = read_sha1_file(oid.hash, &type, &size);
+		result = read_sha1_file(the_repository, oid.hash, &type,
+					&size);
 		if (!result)
 			return error(_("the necessary postimage %s for "
 				       "'%s' cannot be read"),
@@ -3243,7 +3245,8 @@ static int read_blob_object(struct strbuf *buf, const struct object_id *oid, uns
 		unsigned long sz;
 		char *result;
 
-		result = read_sha1_file(oid->hash, &type, &sz);
+		result = read_sha1_file(the_repository, oid->hash, &type,
+					&sz);
 		if (!result)
 			return -1;
 		/* XXX read_sha1_file NUL-terminates */
archive.c +2 -1
index 2aeafe647d..6f38a5cf55 100644
@@ -2,6 +2,7 @@
 #include "config.h"
 #include "refs.h"
 #include "object-store.h"
+#include "repository.h"
 #include "commit.h"
 #include "tree-walk.h"
 #include "attr.h"
@@ -73,7 +74,7 @@ void *sha1_file_to_archive(const struct archiver_args *args,
 	const struct commit *commit = args->convert ? args->commit : NULL;
 
 	path += args->baselen;
-	buffer = read_sha1_file(sha1, type, sizep);
+	buffer = read_sha1_file(the_repository, sha1, type, sizep);
 	if (buffer && S_ISREG(mode)) {
 		struct strbuf buf = STRBUF_INIT;
 		size_t size = 0;
bisect.c +3 -1
index c3066bd972..2db384ce2d 100644
@@ -132,7 +132,9 @@ static void show_list(const char *debug, int counted, int nr,
 		unsigned flags = commit->object.flags;
 		enum object_type type;
 		unsigned long size;
-		char *buf = read_sha1_file(commit->object.sha1, &type, &size);
+		char *buf = read_sha1_file(the_repository,
+					   commit->object.sha1, &type,
+					   &size);
 		const char *subject_start;
 		int subject_len;
 
blame.c +5 -2
index 1aab6228cc..8648a1ddff 100644
@@ -299,7 +299,8 @@ static void fill_origin_blob(struct diff_options *opt,
 		    textconv_object(o->path, o->mode, &o->blob_oid, 1, &file->ptr, &file_size))
 			;
 		else
-			file->ptr = read_sha1_file(o->blob_oid.hash, &type,
+			file->ptr = read_sha1_file(the_repository,
+						   o->blob_oid.hash, &type,
 						   &file_size);
 		file->size = file_size;
 
@@ -1833,7 +1834,9 @@ void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blam
 				    &sb->final_buf_size))
 			;
 		else
-			sb->final_buf = read_sha1_file(o->blob_oid.hash, &type,
+			sb->final_buf = read_sha1_file(the_repository,
+						       o->blob_oid.hash,
+						       &type,
 						       &sb->final_buf_size);
 
 		if (!sb->final_buf)
builtin/cat-file.c +10 -5
index 96c834b8f4..2ebed86524 100644
@@ -33,7 +33,7 @@ static int filter_object(const char *path, unsigned mode,
 {
 	enum object_type type;
 
-	*buf = read_sha1_file(oid->hash, &type, size);
+	*buf = read_sha1_file(the_repository, oid->hash, &type, size);
 	if (!*buf)
 		return error(_("cannot read object %s '%s'"),
 			     oid_to_hex(oid), path);
@@ -131,7 +131,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
 
 		if (type == OBJ_BLOB)
 			return stream_blob_to_fd(1, &oid, NULL, 0);
-		buf = read_sha1_file(oid.hash, &type, &size);
+		buf = read_sha1_file(the_repository, oid.hash, &type, &size);
 		if (!buf)
 			die("Cannot read object %s", obj_name);
 
@@ -142,7 +142,9 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
 		if (type_from_string(exp_type) == OBJ_BLOB) {
 			struct object_id blob_oid;
 			if (sha1_object_info(the_repository, oid.hash, NULL) == OBJ_TAG) {
-				char *buffer = read_sha1_file(oid.hash, &type, &size);
+				char *buffer = read_sha1_file(the_repository,
+							      oid.hash,
+							      &type, &size);
 				const char *target;
 				if (!skip_prefix(buffer, "object ", &target) ||
 				    get_oid_hex(target, &blob_oid))
@@ -305,7 +307,9 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
 				enum object_type type;
 				if (!textconv_object(data->rest, 0100644, oid,
 						     1, &contents, &size))
-					contents = read_sha1_file(oid->hash, &type,
+					contents = read_sha1_file(the_repository,
+								  oid->hash,
+								  &type,
 								  &size);
 				if (!contents)
 					die("could not convert '%s' %s",
@@ -322,7 +326,8 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
 		unsigned long size;
 		void *contents;
 
-		contents = read_sha1_file(oid->hash, &type, &size);
+		contents = read_sha1_file(the_repository, oid->hash, &type,
+					  &size);
 		if (!contents)
 			die("object %s disappeared", oid_to_hex(oid));
 		if (type != data->type)
builtin/difftool.c +3 -1
index d62094060d..32bebbf358 100644
@@ -21,6 +21,7 @@
 #include "strbuf.h"
 #include "lockfile.h"
 #include "object-store.h"
+#include "repository.h"
 #include "dir.h"
 
 static char *diff_gui_tool;
@@ -307,7 +308,8 @@ static char *get_symlink(const struct object_id *oid, const char *path)
 	} else {
 		enum object_type type;
 		unsigned long size;
-		data = read_sha1_file(oid->hash, &type, &size);
+		data = read_sha1_file(the_repository, oid->hash, &type,
+				      &size);
 		if (!data)
 			die(_("could not read object %s for symlink %s"),
 				oid_to_hex(oid), path);
builtin/fast-export.c +4 -2
index 5d524e7dd2..1562ac4927 100644
@@ -239,7 +239,8 @@ static void export_blob(const struct object_id *oid)
 		object = (struct object *)lookup_blob(the_repository, oid);
 		eaten = 0;
 	} else {
-		buf = read_sha1_file(oid->hash, &type, &size);
+		buf = read_sha1_file(the_repository, oid->hash, &type,
+				     &size);
 		if (!buf)
 			die ("Could not read blob %s", oid_to_hex(oid));
 		if (check_sha1_signature(the_repository, oid->hash, buf, size, typename(type)) < 0)
@@ -686,7 +687,8 @@ static void handle_tag(const char *name, struct tag *tag)
 		return;
 	}
 
-	buf = read_sha1_file(tag->object.oid.hash, &type, &size);
+	buf = read_sha1_file(the_repository, tag->object.oid.hash, &type,
+			     &size);
 	if (!buf)
 		die ("Could not read tag %s", oid_to_hex(&tag->object.oid));
 	message = memmem(buf, size, "\n\n", 2);
builtin/fmt-merge-msg.c +2 -1
index 3e99d10218..ac98556a1d 100644
@@ -492,7 +492,8 @@ static void fmt_merge_msg_sigs(struct strbuf *out)
 		unsigned char *sha1 = origins.items[i].util;
 		enum object_type type;
 		unsigned long size, len;
-		char *buf = read_sha1_file(sha1, &type, &size);
+		char *buf = read_sha1_file(the_repository, sha1, &type,
+					   &size);
 		struct strbuf sig = STRBUF_INIT;
 
 		if (!buf || type != OBJ_TAG)
builtin/grep.c +1 -1
index a83e87a676..de1339bfc6 100644
@@ -308,7 +308,7 @@ static void *lock_and_read_oid_file(const struct object_id *oid, enum object_typ
 	void *data;
 
 	grep_read_lock();
-	data = read_sha1_file(oid->hash, type, size);
+	data = read_sha1_file(the_repository, oid->hash, type, size);
 	grep_read_unlock();
 	return data;
 }
builtin/index-pack.c +4 -2
index 0928ed8dd5..b42bf12f65 100644
@@ -819,7 +819,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
 			die(_("cannot read existing object info %s"), oid_to_hex(oid));
 		if (has_type != type || has_size != size)
 			die(_("SHA1 COLLISION FOUND WITH %s !"), oid_to_hex(oid));
-		has_data = read_sha1_file(oid->hash, &has_type, &has_size);
+		has_data = read_sha1_file(the_repository, oid->hash,
+					  &has_type, &has_size);
 		read_unlock();
 		if (!data)
 			data = new_data = get_data_from_pack(obj_entry);
@@ -1379,7 +1380,8 @@ static void fix_unresolved_deltas(struct sha1file *f)
 
 		if (objects[d->obj_no].real_type != OBJ_REF_DELTA)
 			continue;
-		base_obj->data = read_sha1_file(d->sha1, &type, &base_obj->size);
+		base_obj->data = read_sha1_file(the_repository, d->sha1,
+						&type, &base_obj->size);
 		if (!base_obj->data)
 			continue;
 
builtin/log.c +1 -1
index 529e19ce6f..fce7b07df4 100644
@@ -518,7 +518,7 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev)
 {
 	unsigned long size;
 	enum object_type type;
-	char *buf = read_sha1_file(oid->hash, &type, &size);
+	char *buf = read_sha1_file(the_repository, oid->hash, &type, &size);
 	int offset = 0;
 
 	if (!buf)
builtin/merge-tree.c +6 -2
index 41f1ae30cc..86a8ea3965 100644
@@ -62,7 +62,9 @@ static void *result(struct merge_list *entry, unsigned long *size)
 	const char *path = entry->path;
 
 	if (!entry->stage)
-		return read_sha1_file(entry->blob->object.oid.hash, &type, size);
+		return read_sha1_file(the_repository,
+				      entry->blob->object.oid.hash, &type,
+				      size);
 	base = NULL;
 	if (entry->stage == 1) {
 		base = entry->blob;
@@ -84,7 +86,9 @@ static void *origin(struct merge_list *entry, unsigned long *size)
 	enum object_type type;
 	while (entry) {
 		if (entry->stage == 2)
-			return read_sha1_file(entry->blob->object.oid.hash, &type, size);
+			return read_sha1_file(the_repository,
+					      entry->blob->object.oid.hash,
+					      &type, size);
 		entry = entry->link;
 	}
 	return NULL;
builtin/mktag.c +1 -1
index d05fdb824a..b6498dbb0e 100644
@@ -25,7 +25,7 @@ static int verify_object(const unsigned char *sha1, const char *expected_type)
 	int ret = -1;
 	enum object_type type;
 	unsigned long size;
-	void *buffer = read_sha1_file(sha1, &type, &size);
+	void *buffer = read_sha1_file(the_repository, sha1, &type, &size);
 	const unsigned char *repl = lookup_replace_object(the_repository, sha1);
 
 	if (buffer) {
builtin/notes.c +4 -3
index 18128eb439..56d99c2789 100644
@@ -124,7 +124,7 @@ static void copy_obj_to_fd(int fd, const unsigned char *sha1)
 {
 	unsigned long size;
 	enum object_type type;
-	char *buf = read_sha1_file(sha1, &type, &size);
+	char *buf = read_sha1_file(the_repository, sha1, &type, &size);
 	if (buf) {
 		if (size)
 			write_or_die(fd, buf, size);
@@ -255,7 +255,7 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
 
 	if (get_oid(arg, &object))
 		die(_("failed to resolve '%s' as a valid ref."), arg);
-	if (!(buf = read_sha1_file(object.hash, &type, &len))) {
+	if (!(buf = read_sha1_file(the_repository, object.hash, &type, &len))) {
 		free(buf);
 		die(_("failed to read object '%s'."), arg);
 	}
@@ -610,7 +610,8 @@ static int append_edit(int argc, const char **argv, const char *prefix)
 		/* Append buf to previous note contents */
 		unsigned long size;
 		enum object_type type;
-		char *prev_buf = read_sha1_file(note->hash, &type, &size);
+		char *prev_buf = read_sha1_file(the_repository, note->hash,
+						&type, &size);
 
 		strbuf_grow(&d.buf, size + 1);
 		if (d.buf.len && prev_buf && size)
builtin/pack-objects.c +11 -6
index fae579f12a..128e5e3676 100644
@@ -123,10 +123,12 @@ static void *get_delta(struct object_entry *entry)
 	void *buf, *base_buf, *delta_buf;
 	enum object_type type;
 
-	buf = read_sha1_file(entry->idx.oid.hash, &type, &size);
+	buf = read_sha1_file(the_repository, entry->idx.oid.hash, &type,
+			     &size);
 	if (!buf)
 		die("unable to read %s", oid_to_hex(&entry->idx.oid));
-	base_buf = read_sha1_file(entry->delta->idx.oid.hash, &type,
+	base_buf = read_sha1_file(the_repository, entry->delta->idx.oid.hash,
+				  &type,
 				  &base_size);
 	if (!base_buf)
 		die("unable to read %s",
@@ -271,7 +273,8 @@ static unsigned long write_no_reuse_object(struct sha1file *f, struct object_ent
 		    (st = open_istream(entry->idx.oid.hash, &type, &size, NULL)) != NULL)
 			buf = NULL;
 		else {
-			buf = read_sha1_file(entry->idx.oid.hash, &type,
+			buf = read_sha1_file(the_repository,
+					     entry->idx.oid.hash, &type,
 					     &size);
 			if (!buf)
 				die(_("unable to read %s"),
@@ -1193,7 +1196,7 @@ static struct pbase_tree_cache *pbase_tree_get(const struct object_id *oid)
 	/* Did not find one.  Either we got a bogus request or
 	 * we need to read and perhaps cache.
 	 */
-	data = read_sha1_file(oid->hash, &type, &size);
+	data = read_sha1_file(the_repository, oid->hash, &type, &size);
 	if (!data)
 		return NULL;
 	if (type != OBJ_TREE) {
@@ -1877,7 +1880,8 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
 	/* Load data if not already done */
 	if (!trg->data) {
 		read_lock();
-		trg->data = read_sha1_file(trg_entry->idx.oid.hash, &type,
+		trg->data = read_sha1_file(the_repository,
+					   trg_entry->idx.oid.hash, &type,
 					   &sz);
 		read_unlock();
 		if (!trg->data)
@@ -1891,7 +1895,8 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
 	}
 	if (!src->data) {
 		read_lock();
-		src->data = read_sha1_file(src_entry->idx.oid.hash, &type,
+		src->data = read_sha1_file(the_repository,
+					   src_entry->idx.oid.hash, &type,
 					   &sz);
 		read_unlock();
 		if (!src->data) {
builtin/reflog.c +2 -1
index e12b99e9cb..3b600966e3 100644
@@ -76,7 +76,8 @@ static int tree_is_complete(const struct object_id *oid)
 	if (!tree->buffer) {
 		enum object_type type;
 		unsigned long size;
-		void *data = read_sha1_file(oid->hash, &type, &size);
+		void *data = read_sha1_file(the_repository, oid->hash, &type,
+					    &size);
 		if (!data) {
 			tree->object.flags |= INCOMPLETE;
 			return 0;
builtin/tag.c +2 -2
index 1fad1e6733..59db44447f 100644
@@ -169,7 +169,7 @@ static void write_tag_body(int fd, const struct object_id *oid)
 	enum object_type type;
 	char *buf, *sp;
 
-	buf = read_sha1_file(oid->hash, &type, &size);
+	buf = read_sha1_file(the_repository, oid->hash, &type, &size);
 	if (!buf)
 		return;
 	/* skip header */
@@ -301,7 +301,7 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb)
 		strbuf_addstr(sb, "object of unknown type");
 		break;
 	case OBJ_COMMIT:
-		if ((buf = read_sha1_file(oid->hash, &type, &size)) != NULL) {
+		if ((buf = read_sha1_file(the_repository, oid->hash, &type, &size)) != NULL) {
 			subject_len = find_commit_subject(buf, &subject_start);
 			strbuf_insert(sb, sb->len, subject_start, subject_len);
 		} else {
builtin/unpack-file.c +2 -1
index b28e056c74..2e9aeaf0da 100644
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "config.h"
 #include "object-store.h"
+#include "repository.h"
 
 static char *create_temp_file(struct object_id *oid)
 {
@@ -10,7 +11,7 @@ static char *create_temp_file(struct object_id *oid)
 	unsigned long size;
 	int fd;
 
-	buf = read_sha1_file(oid->hash, &type, &size);
+	buf = read_sha1_file(the_repository, oid->hash, &type, &size);
 	if (!buf || type != OBJ_BLOB)
 		die("unable to read blob object %s", oid_to_hex(oid));
 
builtin/unpack-objects.c +2 -1
index 6b8fb918b6..d8175cecd6 100644
@@ -423,7 +423,8 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
 	if (resolve_against_held(nr, &base_oid, delta_data, delta_size))
 		return;
 
-	base = read_sha1_file(base_oid.hash, &type, &base_size);
+	base = read_sha1_file(the_repository, base_oid.hash, &type,
+			      &base_size);
 	if (!base) {
 		error("failed to read delta-pack base object %s",
 		      oid_to_hex(&base_oid));
builtin/verify-commit.c +1 -1
index b0ae18ec33..17641b6097 100644
@@ -47,7 +47,7 @@ static int verify_commit(const char *name, unsigned flags)
 	if (get_oid(name, &oid))
 		return error("commit '%s' not found.", name);
 
-	buf = read_sha1_file(oid.hash, &type, &size);
+	buf = read_sha1_file(the_repository, oid.hash, &type, &size);
 	if (!buf)
 		return error("%s: unable to read file.", name);
 	if (type != OBJ_COMMIT)
bundle.c +1 -1
index d9579f851e..abe158b59c 100644
@@ -227,7 +227,7 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs)
 	if (revs->max_age == -1 && revs->min_age == -1)
 		goto out;
 
-	buf = read_sha1_file(tag->oid.hash, &type, &size);
+	buf = read_sha1_file(the_repository, tag->oid.hash, &type, &size);
 	if (!buf)
 		goto out;
 	line = memmem(buf, size, "\ntagger ", 8);
combine-diff.c +3 -1
index f45ab6f57c..8f6ac31252 100644
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "object-store.h"
+#include "repository.h"
 #include "commit.h"
 #include "blob.h"
 #include "diff.h"
@@ -307,7 +308,8 @@ static char *grab_blob(const struct object_id *oid, unsigned int mode,
 		*size = fill_textconv(textconv, df, &blob);
 		free_filespec(df);
 	} else {
-		blob = read_sha1_file(oid->hash, &type, size);
+		blob = read_sha1_file(the_repository, oid->hash, &type,
+				      size);
 		if (type != OBJ_BLOB)
 			die("object '%s' is not a blob!", oid_to_hex(oid));
 	}
commit.c +6 -3
index 8e42af7565..2fb702795c 100644
@@ -277,7 +277,8 @@ const void *get_commit_buffer(const struct commit *commit, unsigned long *sizep)
 	if (!ret) {
 		enum object_type type;
 		unsigned long size;
-		ret = read_sha1_file(commit->object.oid.hash, &type, &size);
+		ret = read_sha1_file(the_repository, commit->object.oid.hash,
+				     &type, &size);
 		if (!ret)
 			die("cannot read commit object %s",
 			    oid_to_hex(&commit->object.oid));
@@ -395,7 +396,8 @@ int parse_commit_gently(struct commit *item, int quiet_on_missing)
 		return -1;
 	if (item->object.parsed)
 		return 0;
-	buffer = read_sha1_file(item->object.oid.hash, &type, &size);
+	buffer = read_sha1_file(the_repository, item->object.oid.hash, &type,
+				&size);
 	if (!buffer)
 		return quiet_on_missing ? -1 :
 			error("Could not read %s",
@@ -1234,7 +1236,8 @@ static void handle_signed_tag(struct commit *parent, struct commit_extra_header
 	desc = merge_remote_util(parent);
 	if (!desc || !desc->obj)
 		return;
-	buf = read_sha1_file(desc->obj->oid.hash, &type, &size);
+	buf = read_sha1_file(the_repository, desc->obj->oid.hash, &type,
+			     &size);
 	if (!buf || type != OBJ_TAG)
 		goto free_return;
 	len = parse_signature(buf, size);
config.c +1 -1
index e617c2018d..c023740c97 100644
@@ -1480,7 +1480,7 @@ int git_config_from_blob_oid(config_fn_t fn,
 	unsigned long size;
 	int ret;
 
-	buf = read_sha1_file(oid->hash, &type, &size);
+	buf = read_sha1_file(the_repository, oid->hash, &type, &size);
 	if (!buf)
 		return error("unable to load config blob object '%s'", name);
 	if (type != OBJ_BLOB) {
contrib/coccinelle/object_store.cocci +9 -0
index 915dd176dd..72066e3768 100644
@@ -25,3 +25,12 @@ expression H;
  read_sha1_file_extended(
 +the_repository,
  E, F, G, H)
+
+@@
+expression E;
+expression F;
+expression G;
+@@
+ read_sha1_file(
++the_repository,
+ E, F, G)
diff.c +2 -1
index 08bff6e720..9ad272b5cb 100644
@@ -3629,7 +3629,8 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)
 				return 0;
 			}
 		}
-		s->data = read_sha1_file(s->oid.hash, &type, &s->size);
+		s->data = read_sha1_file(the_repository, s->oid.hash, &type,
+					 &s->size);
 		if (!s->data)
 			die("unable to read %s", oid_to_hex(&s->oid));
 		s->should_free = 1;
dir.c +2 -1
index 4a7981abc4..e4f49636ca 100644
@@ -12,6 +12,7 @@
 #include "config.h"
 #include "dir.h"
 #include "object-store.h"
+#include "repository.h"
 #include "attr.h"
 #include "refs.h"
 #include "wildmatch.h"
@@ -246,7 +247,7 @@ static int do_read_blob(const struct object_id *oid,
 	*size_out = 0;
 	*data_out = NULL;
 
-	data = read_sha1_file(oid->hash, &type, &sz);
+	data = read_sha1_file(the_repository, oid->hash, &type, &sz);
 	if (!data || type != OBJ_BLOB) {
 		free(data);
 		return -1;
entry.c +3 -1
index 02aa09bc83..4fa34741af 100644
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "blob.h"
 #include "object-store.h"
+#include "repository.h"
 #include "dir.h"
 #include "streaming.h"
 #include "submodule.h"
@@ -86,7 +87,8 @@ static int create_file(const char *path, unsigned int mode)
 static void *read_blob_entry(const struct cache_entry *ce, unsigned long *size)
 {
 	enum object_type type;
-	void *new = read_sha1_file(ce->oid.hash, &type, size);
+	void *new = read_sha1_file(the_repository, ce->oid.hash, &type,
+				   size);
 
 	if (new) {
 		if (type == OBJ_BLOB)
fast-import.c +6 -3
index 54c2e10656..b1ff3d47df 100644
@@ -1412,7 +1412,8 @@ static void load_tree(struct tree_entry *root)
 			die("Can't load tree %s", oid_to_hex(oid));
 	} else {
 		enum object_type type;
-		buf = read_sha1_file(oid->hash, &type, &size);
+		buf = read_sha1_file(the_repository, oid->hash, &type,
+				     &size);
 		if (!buf || type != OBJ_TREE)
 			die("Can't load tree %s", oid_to_hex(oid));
 	}
@@ -2973,7 +2974,8 @@ static void cat_blob(struct object_entry *oe, struct object_id *oid)
 	char *buf;
 
 	if (!oe || oe->pack_id == MAX_PACK_ID) {
-		buf = read_sha1_file(oid->hash, &type, &size);
+		buf = read_sha1_file(the_repository, oid->hash, &type,
+				     &size);
 	} else {
 		type = oe->type;
 		buf = gfi_unpack_entry(oe, &size);
@@ -3079,7 +3081,8 @@ static struct object_entry *dereference(struct object_entry *oe,
 		buf = gfi_unpack_entry(oe, &size);
 	} else {
 		enum object_type unused;
-		buf = read_sha1_file(oid->hash, &unused, &size);
+		buf = read_sha1_file(the_repository, oid->hash, &unused,
+				     &size);
 	}
 	if (!buf)
 		die("Can't load object %s", oid_to_hex(oid));
fsck.c +2 -1
index af0291121d..5144ceb8e2 100644
@@ -813,7 +813,8 @@ static int fsck_tag_buffer(struct tag *tag, const char *data,
 		enum object_type type;
 
 		buffer = to_free =
-			read_sha1_file(tag->object.oid.hash, &type, &size);
+			read_sha1_file(the_repository, tag->object.oid.hash,
+				       &type, &size);
 		if (!buffer)
 			return report(options, &tag->object,
 				FSCK_MSG_MISSING_TAG_OBJECT,
grep.c +3 -1
index 6bccd7c7ea..c8e27ec6e2 100644
@@ -2,6 +2,7 @@
 #include "config.h"
 #include "grep.h"
 #include "object-store.h"
+#include "repository.h"
 #include "userdiff.h"
 #include "xdiff-interface.h"
 #include "diff.h"
@@ -2011,7 +2012,8 @@ static int grep_source_load_oid(struct grep_source *gs)
 	enum object_type type;
 
 	grep_read_lock();
-	gs->buf = read_sha1_file(gs->identifier, &type, &gs->size);
+	gs->buf = read_sha1_file(the_repository, gs->identifier, &type,
+				 &gs->size);
 	grep_read_unlock();
 
 	if (!gs->buf)
http-push.c +2 -1
index 7cefc2df76..c7fa9ee15a 100644
@@ -364,7 +364,8 @@ static void start_put(struct transfer_request *request)
 	ssize_t size;
 	git_zstream stream;
 
-	unpacked = read_sha1_file(request->obj->oid.hash, &type, &len);
+	unpacked = read_sha1_file(the_repository, request->obj->oid.hash,
+				  &type, &len);
 	hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", typename(type), len) + 1;
 
 	/* Set it up */
mailmap.c +2 -1
index 6afa9cc56d..1830e9d2a3 100644
@@ -2,6 +2,7 @@
 #include "string-list.h"
 #include "mailmap.h"
 #include "object-store.h"
+#include "repository.h"
 
 #define DEBUG_MAILMAP 0
 #if DEBUG_MAILMAP
@@ -225,7 +226,7 @@ static int read_mailmap_blob(struct string_list *map,
 	if (get_oid(name, &oid) < 0)
 		return 0;
 
-	buf = read_sha1_file(oid.hash, &type, &size);
+	buf = read_sha1_file(the_repository, oid.hash, &type, &size);
 	if (!buf)
 		return error("unable to read mailmap object at %s", name);
 	if (type != OBJ_BLOB)
match-trees.c +3 -2
index bdfdfcaaab..af77d78e63 100644
@@ -2,6 +2,7 @@
 #include "tree.h"
 #include "tree-walk.h"
 #include "object-store.h"
+#include "repository.h"
 
 static int score_missing(unsigned mode, const char *path)
 {
@@ -55,7 +56,7 @@ static void *fill_tree_desc_strict(struct tree_desc *desc,
 	enum object_type type;
 	unsigned long size;
 
-	buffer = read_sha1_file(hash->hash, &type, &size);
+	buffer = read_sha1_file(the_repository, hash->hash, &type, &size);
 	if (!buffer)
 		die("unable to read tree (%s)", oid_to_hex(hash));
 	if (type != OBJ_TREE)
@@ -183,7 +184,7 @@ static int splice_tree(const unsigned char *hash1,
 	if (*subpath)
 		subpath++;
 
-	buf = read_sha1_file(hash1, &type, &sz);
+	buf = read_sha1_file(the_repository, hash1, &type, &sz);
 	if (!buf)
 		die("cannot read tree %s", sha1_to_hex(hash1));
 	init_tree_desc(&desc, buf, sz);
merge-blobs.c +5 -2
index f5e71bcd9b..4c69509bf8 100644
@@ -5,6 +5,7 @@
 #include "blob.h"
 #include "merge-blobs.h"
 #include "object-store.h"
+#include "repository.h"
 
 static int fill_mmfile_blob(mmfile_t *f, struct blob *obj)
 {
@@ -12,7 +13,8 @@ static int fill_mmfile_blob(mmfile_t *f, struct blob *obj)
 	unsigned long size;
 	enum object_type type;
 
-	buf = read_sha1_file(obj->object.oid.hash, &type, &size);
+	buf = read_sha1_file(the_repository, obj->object.oid.hash, &type,
+			     &size);
 	if (!buf)
 		return -1;
 	if (type != OBJ_BLOB) {
@@ -67,7 +69,8 @@ void *merge_blobs(const char *path, struct blob *base, struct blob *our, struct
 			return NULL;
 		if (!our)
 			our = their;
-		return read_sha1_file(our->object.oid.hash, &type, size);
+		return read_sha1_file(the_repository, our->object.oid.hash,
+				      &type, size);
 	}
 
 	if (fill_mmfile_blob(&f1, our) < 0)
merge-recursive.c +3 -2
index 8b6984cdd7..0b4cb14773 100644
@@ -825,7 +825,8 @@ static int update_file_flags(struct merge_options *o,
 			goto update_index;
 		}
 
-		buf = read_sha1_file(oid->hash, &type, &size);
+		buf = read_sha1_file(the_repository, oid->hash, &type,
+				     &size);
 		if (!buf)
 			return err(o, _("cannot read object %s '%s'"), oid_to_hex(oid), path);
 		if (type != OBJ_BLOB) {
@@ -1629,7 +1630,7 @@ static int read_oid_strbuf(struct merge_options *o,
 	void *buf;
 	enum object_type type;
 	unsigned long size;
-	buf = read_sha1_file(oid->hash, &type, &size);
+	buf = read_sha1_file(the_repository, oid->hash, &type, &size);
 	if (!buf)
 		return err(o, _("cannot read object %s"), oid_to_hex(oid));
 	if (type != OBJ_BLOB) {
notes-cache.c +2 -1
index 6348baeb07..a4a6ccab97 100644
@@ -79,7 +79,8 @@ char *notes_cache_get(struct notes_cache *c, struct object_id *key_oid,
 	value_oid = get_note(&c->tree, key_oid);
 	if (!value_oid)
 		return NULL;
-	value = read_sha1_file(value_oid->hash, &type, &size);
+	value = read_sha1_file(the_repository, value_oid->hash, &type,
+			       &size);
 
 	*outsize = size;
 	return value;
notes-merge.c +1 -1
index ea701827ba..02729fc474 100644
@@ -324,7 +324,7 @@ static void write_note_to_worktree(const struct object_id *obj,
 {
 	enum object_type type;
 	unsigned long size;
-	void *buf = read_sha1_file(note->hash, &type, &size);
+	void *buf = read_sha1_file(the_repository, note->hash, &type, &size);
 
 	if (!buf)
 		die("cannot read note %s for object %s",
notes.c +7 -4
index b1478a8dca..369af2ee15 100644
@@ -2,6 +2,7 @@
 #include "config.h"
 #include "notes.h"
 #include "object-store.h"
+#include "repository.h"
 #include "blob.h"
 #include "tree.h"
 #include "utf8.h"
@@ -797,13 +798,15 @@ int combine_notes_concatenate(unsigned char *cur_sha1,
 
 	/* read in both note blob objects */
 	if (!is_null_sha1(new_sha1))
-		new_msg = read_sha1_file(new_sha1, &new_type, &new_len);
+		new_msg = read_sha1_file(the_repository, new_sha1, &new_type,
+					 &new_len);
 	if (!new_msg || !new_len || new_type != OBJ_BLOB) {
 		free(new_msg);
 		return 0;
 	}
 	if (!is_null_sha1(cur_sha1))
-		cur_msg = read_sha1_file(cur_sha1, &cur_type, &cur_len);
+		cur_msg = read_sha1_file(the_repository, cur_sha1, &cur_type,
+					 &cur_len);
 	if (!cur_msg || !cur_len || cur_type != OBJ_BLOB) {
 		free(cur_msg);
 		free(new_msg);
@@ -859,7 +862,7 @@ static int string_list_add_note_lines(struct string_list *list,
 		return 0;
 
 	/* read_sha1_file NUL-terminates */
-	data = read_sha1_file(sha1, &t, &len);
+	data = read_sha1_file(the_repository, sha1, &t, &len);
 	if (t != OBJ_BLOB || !data || !len) {
 		free(data);
 		return t != OBJ_BLOB || !data;
@@ -1217,7 +1220,7 @@ static void format_note(struct notes_tree *t, const struct object_id *object_oid
 	if (!oid)
 		return;
 
-	if (!(msg = read_sha1_file(oid->hash, &type, &msglen)) || type != OBJ_BLOB) {
+	if (!(msg = read_sha1_file(the_repository, oid->hash, &type, &msglen)) || type != OBJ_BLOB) {
 		free(msg);
 		return;
 	}
object-store.h +2 -1
index d6462cd9f1..974f2de78d 100644
@@ -86,7 +86,8 @@ struct packed_git {
 extern void *read_sha1_file_extended_the_repository(const unsigned char *sha1,
 				     enum object_type *type,
 				     unsigned long *size, int lookup_replace);
-static inline void *read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size)
+#define read_sha1_file(r, s, t, sz) read_sha1_file_##r(s, t, sz)
+static inline void *read_sha1_file_the_repository(const unsigned char *sha1, enum object_type *type, unsigned long *size)
 {
 	return read_sha1_file_extended(the_repository, sha1, type, size, 1);
 }
object.c +1 -1
index 85b0360e0a..28f536dcae 100644
@@ -268,7 +268,7 @@ struct object *parse_object_the_repository(const struct object_id *oid)
 		return lookup_object(the_repository, oid->hash);
 	}
 
-	buffer = read_sha1_file(oid->hash, &type, &size);
+	buffer = read_sha1_file(the_repository, oid->hash, &type, &size);
 	if (buffer) {
 		if (check_sha1_signature(the_repository, repl, buffer, size, typename(type)) < 0) {
 			free(buffer);
read-cache.c +4 -2
index 45cad9272a..0df9c2d7b7 100644
@@ -12,6 +12,7 @@
 #include "refs.h"
 #include "dir.h"
 #include "object-store.h"
+#include "repository.h"
 #include "tree.h"
 #include "commit.h"
 #include "blob.h"
@@ -185,7 +186,7 @@ static int ce_compare_link(const struct cache_entry *ce, size_t expected_size)
 	if (strbuf_readlink(&sb, ce->name, expected_size))
 		return -1;
 
-	buffer = read_sha1_file(ce->oid.hash, &type, &size);
+	buffer = read_sha1_file(the_repository, ce->oid.hash, &type, &size);
 	if (buffer) {
 		if (size == sb.len)
 			match = memcmp(buffer, sb.buf, size);
@@ -2671,7 +2672,8 @@ void *read_blob_data_from_index(const struct index_state *istate,
 	}
 	if (pos < 0)
 		return NULL;
-	data = read_sha1_file(istate->cache[pos]->oid.hash, &type, &sz);
+	data = read_sha1_file(the_repository, istate->cache[pos]->oid.hash,
+			      &type, &sz);
 	if (!data || type != OBJ_BLOB) {
 		free(data);
 		return NULL;
ref-filter.c +1 -1
index 256887b585..32e2c1cbfc 100644
@@ -730,7 +730,7 @@ int verify_ref_format(struct ref_format *format)
 static void *get_obj(const struct object_id *oid, struct object **obj, unsigned long *sz, int *eaten)
 {
 	enum object_type type;
-	void *buf = read_sha1_file(oid->hash, &type, sz);
+	void *buf = read_sha1_file(the_repository, oid->hash, &type, sz);
 
 	if (buf)
 		*obj = parse_object_buffer(the_repository, oid, type, *sz,
remote-testsvn.c +3 -2
index 387d4ae935..d27cdce87f 100644
@@ -2,6 +2,7 @@
 #include "refs.h"
 #include "remote.h"
 #include "object-store.h"
+#include "repository.h"
 #include "strbuf.h"
 #include "url.h"
 #include "exec_cmd.h"
@@ -62,7 +63,7 @@ static char *read_ref_note(const struct object_id *oid)
 	init_notes(NULL, notes_ref, NULL, 0);
 	if (!(note_oid = get_note(NULL, oid)))
 		return NULL;	/* note tree not found */
-	if (!(msg = read_sha1_file(note_oid->hash, &type, &msglen)))
+	if (!(msg = read_sha1_file(the_repository, note_oid->hash, &type, &msglen)))
 		error("Empty notes tree. %s", notes_ref);
 	else if (!msglen || type != OBJ_BLOB) {
 		error("Note contains unusable content. "
@@ -109,7 +110,7 @@ static int note2mark_cb(const struct object_id *object_oid,
 	enum object_type type;
 	struct rev_note note;
 
-	if (!(msg = read_sha1_file(note_oid->hash, &type, &msglen)) ||
+	if (!(msg = read_sha1_file(the_repository, note_oid->hash, &type, &msglen)) ||
 			!msglen || type != OBJ_BLOB) {
 		free(msg);
 		return 1;
rerere.c +3 -1
index ab64d3f48e..30ca5fa56d 100644
@@ -10,6 +10,7 @@
 #include "attr.h"
 #include "pathspec.h"
 #include "object-store.h"
+#include "repository.h"
 #include "sha1-lookup.h"
 
 #define RESOLVED 0
@@ -982,7 +983,8 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu
 			break;
 		i = ce_stage(ce) - 1;
 		if (!mmfile[i].ptr) {
-			mmfile[i].ptr = read_sha1_file(ce->oid.hash, &type,
+			mmfile[i].ptr = read_sha1_file(the_repository,
+						       ce->oid.hash, &type,
 						       &size);
 			mmfile[i].size = size;
 		}
sha1_file.c +2 -1
index 2d9a794654..ca567b64d6 100644
@@ -1409,7 +1409,8 @@ void *read_object_with_reference(const unsigned char *sha1,
 		int ref_length = -1;
 		const char *ref_type = NULL;
 
-		buffer = read_sha1_file(actual_sha1, &type, &isize);
+		buffer = read_sha1_file(the_repository, actual_sha1, &type,
+					&isize);
 		if (!buffer)
 			return NULL;
 		if (type == required_type) {
submodule-config.c +2 -1
index 2aa8a1747f..cac5f0ac52 100644
@@ -520,7 +520,8 @@ static const struct submodule *config_from(struct submodule_cache *cache,
 	if (submodule)
 		goto out;
 
-	config = read_sha1_file(oid.hash, &type, &config_size);
+	config = read_sha1_file(the_repository, oid.hash, &type,
+				&config_size);
 	if (!config || type != OBJ_BLOB)
 		goto out;
 
tag.c +3 -2
index da2fe4f2ee..e2fd31ffc7 100644
@@ -51,7 +51,7 @@ int gpg_verify_tag(const struct object_id *oid, const char *name_to_report,
 				find_unique_abbrev(oid->hash, DEFAULT_ABBREV),
 				typename(type));
 
-	buf = read_sha1_file(oid->hash, &type, &size);
+	buf = read_sha1_file(the_repository, oid->hash, &type, &size);
 	if (!buf)
 		return error("%s: unable to read file.",
 				name_to_report ?
@@ -186,7 +186,8 @@ int parse_tag(struct tag *item)
 
 	if (item->object.parsed)
 		return 0;
-	data = read_sha1_file(item->object.oid.hash, &type, &size);
+	data = read_sha1_file(the_repository, item->object.oid.hash, &type,
+			      &size);
 	if (!data)
 		return error("Could not read %s",
 			     oid_to_hex(&item->object.oid));
tree-walk.c +3 -1
index 8bd56eddd5..1fa979d146 100644
@@ -3,6 +3,7 @@
 #include "unpack-trees.h"
 #include "dir.h"
 #include "object-store.h"
+#include "repository.h"
 #include "tree.h"
 #include "pathspec.h"
 
@@ -715,7 +716,8 @@ enum follow_symlinks_result get_tree_entry_follow_symlinks(unsigned char *tree_s
 			 */
 			retval = DANGLING_SYMLINK;
 
-			contents = read_sha1_file(current_tree_sha1, &type,
+			contents = read_sha1_file(the_repository,
+						  current_tree_sha1, &type,
 						  &link_len);
 
 			if (!contents)
tree.c +2 -1
index 6e0aafa805..f1c4e937c8 100644
@@ -222,7 +222,8 @@ int parse_tree_gently(struct tree *item, int quiet_on_missing)
 
 	if (item->object.parsed)
 		return 0;
-	buffer = read_sha1_file(item->object.oid.hash, &type, &size);
+	buffer = read_sha1_file(the_repository, item->object.oid.hash, &type,
+				&size);
 	if (!buffer)
 		return quiet_on_missing ? -1 :
 			error("Could not read %s",
xdiff-interface.c +2 -1
index a2d0e05edd..22bbe92584 100644
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "config.h"
 #include "object-store.h"
+#include "repository.h"
 #include "xdiff-interface.h"
 #include "xdiff/xtypes.h"
 #include "xdiff/xdiffi.h"
@@ -192,7 +193,7 @@ void read_mmblob(mmfile_t *ptr, const struct object_id *oid)
 		return;
 	}
 
-	ptr->ptr = read_sha1_file(oid->hash, &type, &size);
+	ptr->ptr = read_sha1_file(the_repository, oid->hash, &type, &size);
 	if (!ptr->ptr || type != OBJ_BLOB)
 		die("unable to read blob object %s", oid_to_hex(oid));
 	ptr->size = size;
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#148 lore raw

PATCH 114/194 object: move read_object_with_reference to object.h

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

This should make the function easier to find, alongside other functions that parse and act on the content of objects.

While at it, add a comment describing the function's API.

---
 cache.h  |  5 -----
 object.h | 16 ++++++++++++++++
 2 files changed, 16 insertions(+), 5 deletions(-)
cache.h +0 -5
index 15ba480ac3..89422e7976 100644
@@ -1351,11 +1351,6 @@ extern int df_name_compare(const char *name1, int len1, int mode1, const char *n
 extern int name_compare(const char *name1, size_t len1, const char *name2, size_t len2);
 extern int cache_name_stage_compare(const char *name1, int len1, int stage1, const char *name2, int len2, int stage2);
 
-extern void *read_object_with_reference(const unsigned char *sha1,
-					const char *required_type,
-					unsigned long *size,
-					unsigned char *sha1_ret);
-
 extern struct object *peel_to_type(const char *name, int namelen,
 				   struct object *o, enum object_type);
 
object.h +16 -0
index c9ea2285e8..d676404f00 100644
@@ -108,6 +108,22 @@ extern void *create_object(struct repository *r, const unsigned char *sha1, void
 
 void *object_as_type(struct object *obj, enum object_type type, int quiet);
 
+/*
+ * Resolves 'sha1' to an object of the specified type and returns the
+ * raw content of the resulting object.
+ *
+ * For example, with required_type == OBJ_TREE, this can be passed a
+ * tree, commit, or tag object id to get the raw tree object pointed
+ * to by the named object.
+ *
+ * Returns NULL if 'sha1' can not be peeled to an object of the
+ * specified type.
+ */
+extern void *read_object_with_reference(const unsigned char *sha1,
+					const char *required_type,
+					unsigned long *size,
+					unsigned char *sha1_ret);
+
 /*
  * Returns the object, having parsed it to find out what it is.
  *
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#149 lore raw

PATCH 115/194 packfile: add repository argument to has_packed_and_bad

In reply to Stefan Beller

Add a repository argument to allow the callers of has_packed_and_bad to be more specific about which repository to act on. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet.

As with the previous commits, use a macro to catch callers passing a repository other than the_repository at compile time.

Add the cocci patch that converted the callers.

---
 packfile.c  | 2 +-
 packfile.h  | 4 +++-
 sha1_file.c | 2 +-
 3 files changed, 5 insertions(+), 3 deletions(-)
packfile.c +1 -1
index f7e8a81ded..28453739b2 100644
@@ -1004,7 +1004,7 @@ void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1)
 	p->num_bad_objects++;
 }
 
-const struct packed_git *has_packed_and_bad(const unsigned char *sha1)
+const struct packed_git *has_packed_and_bad_the_repository(const unsigned char *sha1)
 {
 	struct packed_git *p;
 	unsigned i;
packfile.h +3 -1
index f8d2825cce..b5122d455e 100644
@@ -140,7 +140,9 @@ extern int packed_object_info(struct repository *r,
 			      off_t offset, struct object_info *);
 
 extern void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1);
-extern const struct packed_git *has_packed_and_bad(const unsigned char *sha1);
+
+#define has_packed_and_bad(r, s) has_packed_and_bad_##r(s)
+extern const struct packed_git *has_packed_and_bad_the_repository(const unsigned char *sha1);
 
 extern int find_pack_entry(struct repository *r,
 			   const unsigned char *sha1,
sha1_file.c +1 -1
index ca567b64d6..e1427c0982 100644
@@ -1386,7 +1386,7 @@ void *read_sha1_file_extended_the_repository(const unsigned char *sha1,
 		die("loose object %s (stored in %s) is corrupt",
 		    sha1_to_hex(repl), path);
 
-	if ((p = has_packed_and_bad(repl)) != NULL)
+	if ((p = has_packed_and_bad(the_repository, repl)) != NULL)
 		die("packed object %s (stored in %s) is corrupt",
 		    sha1_to_hex(repl), p->pack_name);
 
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#150 lore raw

PATCH 116/194 packfile: allow has_packed_and_bad to handle arbitrary repositories

In reply to Stefan Beller
---
 packfile.c | 4 ++--
 packfile.h | 3 +--
 2 files changed, 3 insertions(+), 4 deletions(-)
packfile.c +2 -2
index 28453739b2..21ca15b1ce 100644
@@ -1004,12 +1004,12 @@ void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1)
 	p->num_bad_objects++;
 }
 
-const struct packed_git *has_packed_and_bad_the_repository(const unsigned char *sha1)
+const struct packed_git *has_packed_and_bad(struct repository *r, const unsigned char *sha1)
 {
 	struct packed_git *p;
 	unsigned i;
 
-	for (p = the_repository->objects.packed_git; p; p = p->next)
+	for (p = r->objects.packed_git; p; p = p->next)
 		for (i = 0; i < p->num_bad_objects; i++)
 			if (!hashcmp(sha1, p->bad_object_sha1 + 20 * i))
 				return p;
packfile.h +1 -2
index b5122d455e..42593940b0 100644
@@ -141,8 +141,7 @@ extern int packed_object_info(struct repository *r,
 
 extern void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1);
 
-#define has_packed_and_bad(r, s) has_packed_and_bad_##r(s)
-extern const struct packed_git *has_packed_and_bad_the_repository(const unsigned char *sha1);
+extern const struct packed_git *has_packed_and_bad(struct repository *r, const unsigned char *sha1);
 
 extern int find_pack_entry(struct repository *r,
 			   const unsigned char *sha1,
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#151 lore raw

PATCH 117/194 streaming: add repository argument to open_istream_fn

In reply to Stefan Beller

Add a repository argument to allow the callers of open_istream_fn to be more specific about which repository to act on. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet.

Unlike the previous commits, this uses a run time check to make sure the passed repository is the_repository instead of a compile time check.

---
 streaming.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
streaming.c +16 -4
index f0ff5e7245..8c1e1a1601 100644
@@ -15,7 +15,8 @@ enum input_source {
 	pack_non_delta = 2
 };
 
-typedef int (*open_istream_fn)(struct git_istream *,
+typedef int (*open_istream_fn)(struct repository *,
+			       struct git_istream *,
 			       struct object_info *,
 			       const unsigned char *,
 			       enum object_type *);
@@ -29,7 +30,9 @@ struct stream_vtbl {
 
 #define open_method_decl(name) \
 	int open_istream_ ##name \
-	(struct git_istream *st, struct object_info *oi, \
+	(struct repository *r, \
+	 struct git_istream *st, \
+	 struct object_info *oi, \
 	 const unsigned char *sha1, \
 	 enum object_type *type)
 
@@ -147,8 +150,8 @@ struct git_istream *open_istream(const unsigned char *sha1,
 		return NULL;
 
 	st = xmalloc(sizeof(*st));
-	if (open_istream_tbl[src](st, &oi, real, type)) {
-		if (open_istream_incore(st, &oi, real, type)) {
+	if (open_istream_tbl[src](the_repository, st, &oi, real, type)) {
+		if (open_istream_incore(the_repository, st, &oi, real, type)) {
 			free(st);
 			return NULL;
 		}
@@ -338,6 +341,9 @@ static struct stream_vtbl loose_vtbl = {
 
 static open_method_decl(loose)
 {
+	if (r != the_repository)
+		BUG("r != the_repository");
+
 	st->u.loose.mapped = map_sha1_file(the_repository,
 					   sha1, &st->u.loose.mapsize);
 	if (!st->u.loose.mapped)
@@ -433,6 +439,9 @@ static open_method_decl(pack_non_delta)
 	struct pack_window *window;
 	enum object_type in_pack_type;
 
+	if (r != the_repository)
+		BUG("r != the_repository");
+
 	st->u.in_pack.pack = oi->u.packed.pack;
 	st->u.in_pack.pos = oi->u.packed.offset;
 	window = NULL;
@@ -490,6 +499,9 @@ static struct stream_vtbl incore_vtbl = {
 
 static open_method_decl(incore)
 {
+	if (r != the_repository)
+		BUG("r != the_repository");
+
 	st->u.incore.buf = read_sha1_file_extended(the_repository, sha1,
 						   type, &st->size, 0);
 	st->u.incore.read_ptr = 0;
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#152 lore raw

PATCH 119/194 streaming: add repository argument to istream_source

In reply to Stefan Beller

Add a repository argument to allow the callers of istream_source to be more specific about which repository to act on. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet.

As with the previous commits, use a macro to catch callers passing a repository other than the_repository at compile time.

---
 streaming.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
streaming.c +3 -2
index 90acf7448f..5d2c24798e 100644
@@ -111,7 +111,8 @@ ssize_t read_istream(struct git_istream *st, void *buf, size_t sz)
 	return st->vtbl->read(st, buf, sz);
 }
 
-static enum input_source istream_source(const unsigned char *sha1,
+#define istream_source(r, s, t, o) istream_source_##r(s, t, o)
+static enum input_source istream_source_the_repository(const unsigned char *sha1,
 					enum object_type *type,
 					struct object_info *oi)
 {
@@ -144,7 +145,7 @@ struct git_istream *open_istream_the_repository(const unsigned char *sha1,
 	struct git_istream *st;
 	struct object_info oi = OBJECT_INFO_INIT;
 	const unsigned char *real = lookup_replace_object(the_repository, sha1);
-	enum input_source src = istream_source(real, type, &oi);
+	enum input_source src = istream_source(the_repository, real, type, &oi);
 
 	if (src < 0)
 		return NULL;
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#153 lore raw

PATCH 120/194 streaming: allow istream_source to handle arbitrary repositories

In reply to Stefan Beller
---
 streaming.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
streaming.c +3 -3
index 5d2c24798e..cb7f8b2042 100644
@@ -111,8 +111,8 @@ ssize_t read_istream(struct git_istream *st, void *buf, size_t sz)
 	return st->vtbl->read(st, buf, sz);
 }
 
-#define istream_source(r, s, t, o) istream_source_##r(s, t, o)
-static enum input_source istream_source_the_repository(const unsigned char *sha1,
+static enum input_source istream_source(struct repository *r,
+					const unsigned char *sha1,
 					enum object_type *type,
 					struct object_info *oi)
 {
@@ -121,7 +121,7 @@ static enum input_source istream_source_the_repository(const unsigned char *sha1
 
 	oi->typep = type;
 	oi->sizep = &size;
-	status = sha1_object_info_extended(the_repository, sha1, oi, 0);
+	status = sha1_object_info_extended(r, sha1, oi, 0);
 	if (status < 0)
 		return stream_error;
 
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#154 lore raw

PATCH 121/194 sha1_file: allow read_object to handle arbitrary repositories

In reply to Stefan Beller
---
 sha1_file.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
sha1_file.c +3 -4
index a5ad67143d..6164ba29c5 100644
@@ -1319,9 +1319,8 @@ int sha1_object_info(struct repository *r,
 	return type;
 }
 
-#define read_object(r, s, t, sz) read_object_##r(s, t, sz)
-static void *read_object_the_repository(const unsigned char *sha1, enum object_type *type,
-			 unsigned long *size)
+static void *read_object(struct repository *r, const unsigned char *sha1,
+			 enum object_type *type, unsigned long *size)
 {
 	struct object_info oi = OBJECT_INFO_INIT;
 	void *content;
@@ -1329,7 +1328,7 @@ static void *read_object_the_repository(const unsigned char *sha1, enum object_t
 	oi.sizep = size;
 	oi.contentp = &content;
 
-	if (sha1_object_info_extended(the_repository, sha1, &oi, 0) < 0)
+	if (sha1_object_info_extended(r, sha1, &oi, 0) < 0)
 		return NULL;
 	return content;
 }
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#155 lore raw

PATCH 122/194 object-store.h: allow read_sha1_file{_extended} to handle arbitrary repositories

In reply to Stefan Beller
---
 object-store.h | 10 +++++-----
 sha1_file.c    | 11 ++++++-----
 2 files changed, 11 insertions(+), 10 deletions(-)
object-store.h +5 -5
index 974f2de78d..47c38170e3 100644
@@ -82,14 +82,14 @@ struct packed_git {
 	char pack_name[FLEX_ARRAY]; /* more */
 };
 
-#define read_sha1_file_extended(r, s, t, sz, l) read_sha1_file_extended_##r(s, t, sz, l)
-extern void *read_sha1_file_extended_the_repository(const unsigned char *sha1,
+extern void *read_sha1_file_extended(struct repository *r,
+				     const unsigned char *sha1,
 				     enum object_type *type,
 				     unsigned long *size, int lookup_replace);
-#define read_sha1_file(r, s, t, sz) read_sha1_file_##r(s, t, sz)
-static inline void *read_sha1_file_the_repository(const unsigned char *sha1, enum object_type *type, unsigned long *size)
+
+static inline void *read_sha1_file(struct repository *r, const unsigned char *sha1, enum object_type *type, unsigned long *size)
 {
-	return read_sha1_file_extended(the_repository, sha1, type, size, 1);
+	return read_sha1_file_extended(r, sha1, type, size, 1);
 }
 
 /* Read and unpack a sha1 file into memory, write memory to a sha1 file */
sha1_file.c +6 -5
index 6164ba29c5..743ada360d 100644
@@ -1356,7 +1356,8 @@ int pretend_sha1_file(void *buf, unsigned long len, enum object_type type,
  * deal with them should arrange to call read_object() and give error
  * messages themselves.
  */
-void *read_sha1_file_extended_the_repository(const unsigned char *sha1,
+void *read_sha1_file_extended(struct repository *r,
+			      const unsigned char *sha1,
 			      enum object_type *type,
 			      unsigned long *size,
 			      int lookup_replace)
@@ -1366,10 +1367,10 @@ void *read_sha1_file_extended_the_repository(const unsigned char *sha1,
 	const char *path;
 	struct stat st;
 	const unsigned char *repl = lookup_replace ?
-		lookup_replace_object(the_repository, sha1) : sha1;
+		lookup_replace_object(r, sha1) : sha1;
 
 	errno = 0;
-	data = read_object(the_repository, repl, type, size);
+	data = read_object(r, repl, type, size);
 	if (data)
 		return data;
 
@@ -1381,11 +1382,11 @@ void *read_sha1_file_extended_the_repository(const unsigned char *sha1,
 		die("replacement %s not found for %s",
 		    sha1_to_hex(repl), sha1_to_hex(sha1));
 
-	if (!stat_sha1_file(the_repository, repl, &st, &path))
+	if (!stat_sha1_file(r, repl, &st, &path))
 		die("loose object %s (stored in %s) is corrupt",
 		    sha1_to_hex(repl), path);
 
-	if ((p = has_packed_and_bad(the_repository, repl)) != NULL)
+	if ((p = has_packed_and_bad(r, repl)) != NULL)
 		die("packed object %s (stored in %s) is corrupt",
 		    sha1_to_hex(repl), p->pack_name);
 
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#156 lore raw

PATCH 123/194 streaming: allow open_istream_incore to handle arbitrary repositories

In reply to Stefan Beller
---
 streaming.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
streaming.c +1 -4
index cb7f8b2042..94651ffbf0 100644
@@ -500,10 +500,7 @@ static struct stream_vtbl incore_vtbl = {
 
 static open_method_decl(incore)
 {
-	if (r != the_repository)
-		BUG("r != the_repository");
-
-	st->u.incore.buf = read_sha1_file_extended(the_repository, sha1,
+	st->u.incore.buf = read_sha1_file_extended(r, sha1,
 						   type, &st->size, 0);
 	st->u.incore.read_ptr = 0;
 	st->vtbl = &incore_vtbl;
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#157 lore raw

PATCH 124/194 streaming: allow open_istream_pack_non_delta to handle arbitrary repositories

In reply to Stefan Beller
---
 streaming.c | 3 ---
 1 file changed, 3 deletions(-)
streaming.c +0 -3
index 94651ffbf0..21bd069315 100644
@@ -440,9 +440,6 @@ static open_method_decl(pack_non_delta)
 	struct pack_window *window;
 	enum object_type in_pack_type;
 
-	if (r != the_repository)
-		BUG("r != the_repository");
-
 	st->u.in_pack.pack = oi->u.packed.pack;
 	st->u.in_pack.pos = oi->u.packed.offset;
 	window = NULL;
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#158 lore raw

PATCH 125/194 streaming: allow open_istream_loose to handle arbitrary repositories

In reply to Stefan Beller
---
 streaming.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
streaming.c +1 -5
index 21bd069315..cd52f517eb 100644
@@ -342,11 +342,7 @@ static struct stream_vtbl loose_vtbl = {
 
 static open_method_decl(loose)
 {
-	if (r != the_repository)
-		BUG("r != the_repository");
-
-	st->u.loose.mapped = map_sha1_file(the_repository,
-					   sha1, &st->u.loose.mapsize);
+	st->u.loose.mapped = map_sha1_file(r, sha1, &st->u.loose.mapsize);
 	if (!st->u.loose.mapped)
 		return -1;
 	if ((unpack_sha1_header(&st->z,
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#159 lore raw

PATCH 126/194 streaming: allow open_istream to handle arbitrary repositories

In reply to Stefan Beller
---
 streaming.c | 11 ++++++-----
 streaming.h |  3 +--
 2 files changed, 7 insertions(+), 7 deletions(-)
streaming.c +6 -5
index cd52f517eb..2373395afe 100644
@@ -137,22 +137,23 @@ static enum input_source istream_source(struct repository *r,
 	}
 }
 
-struct git_istream *open_istream_the_repository(const unsigned char *sha1,
+struct git_istream *open_istream(struct repository *r,
+				 const unsigned char *sha1,
 				 enum object_type *type,
 				 unsigned long *size,
 				 struct stream_filter *filter)
 {
 	struct git_istream *st;
 	struct object_info oi = OBJECT_INFO_INIT;
-	const unsigned char *real = lookup_replace_object(the_repository, sha1);
-	enum input_source src = istream_source(the_repository, real, type, &oi);
+	const unsigned char *real = lookup_replace_object(r, sha1);
+	enum input_source src = istream_source(r, real, type, &oi);
 
 	if (src < 0)
 		return NULL;
 
 	st = xmalloc(sizeof(*st));
-	if (open_istream_tbl[src](the_repository, st, &oi, real, type)) {
-		if (open_istream_incore(the_repository, st, &oi, real, type)) {
+	if (open_istream_tbl[src](r, st, &oi, real, type)) {
+		if (open_istream_incore(r, st, &oi, real, type)) {
 			free(st);
 			return NULL;
 		}
streaming.h +1 -2
index 9f4d5aeee2..cb36ce4c02 100644
@@ -8,8 +8,7 @@
 /* opaque */
 struct git_istream;
 
-#define open_istream(r, s, t, sz, f) open_istream_##r(s, t, sz, f)
-extern struct git_istream *open_istream_the_repository(const unsigned char *, enum object_type *, unsigned long *, struct stream_filter *);
+extern struct git_istream *open_istream(struct repository *, const unsigned char *, enum object_type *, unsigned long *, struct stream_filter *);
 extern int close_istream(struct git_istream *);
 extern ssize_t read_istream(struct git_istream *, void *, size_t);
 
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#160 lore raw

PATCH 127/194 alternates: convert add_to_alternates_memory to handle arbitrary repos

In reply to Stefan Beller
---
 alternates.h | 3 +--
 sha1_file.c  | 7 +++----
 tmp-objdir.c | 1 +
 3 files changed, 5 insertions(+), 6 deletions(-)
alternates.h +1 -2
index e4520ae5c7..b3d8d57ba4 100644
@@ -56,8 +56,7 @@ extern void add_to_alternates_file_the_repository(const char *dir);
  * recursive alternates it points to), but do not modify the on-disk alternates
  * file.
  */
-#define add_to_alternates_memory(r, d) add_to_alternates_memory_##r(d)
-extern void add_to_alternates_memory_the_repository(const char *dir);
+extern void add_to_alternates_memory(struct repository *r, const char *dir);
 
 /*
  * Returns a scratch strbuf pre-filled with the alternate object directory,
sha1_file.c +3 -4
index 743ada360d..3c39e34c72 100644
@@ -581,16 +581,15 @@ void add_to_alternates_file_the_repository(const char *reference)
 	free(alts);
 }
 
-void add_to_alternates_memory_the_repository(const char *reference)
+void add_to_alternates_memory(struct repository *r, const char *reference)
 {
 	/*
 	 * Make sure alternates are initialized, or else our entry may be
 	 * overwritten when they are.
 	 */
-	prepare_alt_odb(the_repository);
+	prepare_alt_odb(r);
 
-	link_alt_odb_entries(the_repository, reference,
-			     '\n', NULL, 0);
+	link_alt_odb_entries(r, reference, '\n', NULL, 0);
 }
 
 /*
tmp-objdir.c +1 -0
index a9334d3fc5..acd55680c8 100644
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "tmp-objdir.h"
 #include "alternates.h"
+#include "repository.h"
 #include "dir.h"
 #include "sigchain.h"
 #include "string-list.h"
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#161 lore raw

PATCH 128/194 object: add repository argument to object_as_type

In reply to Stefan Beller
---
 blob.c         | 2 +-
 builtin/fsck.c | 2 +-
 commit.c       | 4 ++--
 object.c       | 2 +-
 object.h       | 3 ++-
 refs.c         | 2 +-
 tag.c          | 2 +-
 tree.c         | 2 +-
 8 files changed, 10 insertions(+), 9 deletions(-)
blob.c +1 -1
index 25faf3e692..0c53cfce45 100644
@@ -10,7 +10,7 @@ struct blob *lookup_blob_the_repository(const struct object_id *oid)
 	if (!obj)
 		return create_object(the_repository, oid->hash,
 				     alloc_blob_node());
-	return object_as_type(obj, OBJ_BLOB, 0);
+	return object_as_type(the_repository, obj, OBJ_BLOB, 0);
 }
 
 int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size)
builtin/fsck.c +1 -1
index 527c03eb39..2e8b298384 100644
@@ -72,7 +72,7 @@ static const char *printable_type(struct object *obj)
 		enum object_type type = sha1_object_info(the_repository,
 							 obj->oid.hash, NULL);
 		if (type > 0)
-			object_as_type(obj, type, 0);
+			object_as_type(the_repository, obj, type, 0);
 	}
 
 	ret = typename(obj->type);
commit.c +2 -2
index 2fb702795c..953c537059 100644
@@ -30,7 +30,7 @@ struct commit *lookup_commit_reference_gently_the_repository(
 
 	if (!obj)
 		return NULL;
-	return object_as_type(obj, OBJ_COMMIT, quiet);
+	return object_as_type(the_repository, obj, OBJ_COMMIT, quiet);
 }
 
 struct commit *lookup_commit_reference_the_repository(const struct object_id *oid)
@@ -56,7 +56,7 @@ struct commit *lookup_commit_the_repository(const struct object_id *oid)
 	if (!obj)
 		return create_object(the_repository, oid->hash,
 				     alloc_commit_node());
-	return object_as_type(obj, OBJ_COMMIT, 0);
+	return object_as_type(the_repository, obj, OBJ_COMMIT, 0);
 }
 
 struct commit *lookup_commit_reference_by_name(const char *name)
object.c +1 -1
index 28f536dcae..156fbae15e 100644
@@ -155,7 +155,7 @@ void *create_object(struct repository *r, const unsigned char *sha1, void *o)
 	return obj;
 }
 
-void *object_as_type(struct object *obj, enum object_type type, int quiet)
+void *object_as_type_the_repository(struct object *obj, enum object_type type, int quiet)
 {
 	if (obj->type == type)
 		return obj;
object.h +2 -1
index d676404f00..a61d965700 100644
@@ -106,7 +106,8 @@ struct object *lookup_object(struct repository *r, const unsigned char *sha1);
 
 extern void *create_object(struct repository *r, const unsigned char *sha1, void *obj);
 
-void *object_as_type(struct object *obj, enum object_type type, int quiet);
+#define object_as_type(r, o, t, q) object_as_type_##r(o, t, q)
+void *object_as_type_the_repository(struct object *obj, enum object_type type, int quiet);
 
 /*
  * Resolves 'sha1' to an object of the specified type and returns the
refs.c +1 -1
index 0ea9b05d03..24fa57b0f1 100644
@@ -304,7 +304,7 @@ enum peel_status peel_object(const struct object_id *name, struct object_id *oid
 
 	if (o->type == OBJ_NONE) {
 		int type = sha1_object_info(the_repository, name->hash, NULL);
-		if (type < 0 || !object_as_type(o, type, 0))
+		if (type < 0 || !object_as_type(the_repository, o, type, 0))
 			return PEEL_INVALID;
 	}
 
tag.c +1 -1
index e2fd31ffc7..abba1b8d88 100644
@@ -98,7 +98,7 @@ struct tag *lookup_tag_the_repository(const struct object_id *oid)
 	if (!obj)
 		return create_object(the_repository, oid->hash,
 				     alloc_tag_node());
-	return object_as_type(obj, OBJ_TAG, 0);
+	return object_as_type(the_repository, obj, OBJ_TAG, 0);
 }
 
 static timestamp_t parse_tag_date(const char *buf, const char *tail)
tree.c +1 -1
index f1c4e937c8..37fec8623b 100644
@@ -200,7 +200,7 @@ struct tree *lookup_tree_the_repository(const struct object_id *oid)
 	if (!obj)
 		return create_object(the_repository, oid->hash,
 				     alloc_tree_node());
-	return object_as_type(obj, OBJ_TREE, 0);
+	return object_as_type(the_repository, obj, OBJ_TREE, 0);
 }
 
 int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size)
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#162 lore raw

PATCH 129/194 alloc: add repository argument to alloc_blob_node

In reply to Stefan Beller
---
 alloc.c | 2 +-
 blob.c  | 2 +-
 cache.h | 3 ++-
 3 files changed, 4 insertions(+), 3 deletions(-)
alloc.c +1 -1
index 12afadfacd..6c5c376a25 100644
@@ -49,7 +49,7 @@ static inline void *alloc_node(struct alloc_state *s, size_t node_size)
 }
 
 static struct alloc_state blob_state;
-void *alloc_blob_node(void)
+void *alloc_blob_node_the_repository(void)
 {
 	struct blob *b = alloc_node(&blob_state, sizeof(struct blob));
 	b->object.type = OBJ_BLOB;
blob.c +1 -1
index 0c53cfce45..7c661f178a 100644
@@ -9,7 +9,7 @@ struct blob *lookup_blob_the_repository(const struct object_id *oid)
 	struct object *obj = lookup_object(the_repository, oid->hash);
 	if (!obj)
 		return create_object(the_repository, oid->hash,
-				     alloc_blob_node());
+				     alloc_blob_node(the_repository));
 	return object_as_type(the_repository, obj, OBJ_BLOB, 0);
 }
 
cache.h +2 -1
index 89422e7976..6ee415d9f7 100644
@@ -1575,7 +1575,8 @@ int decode_85(char *dst, const char *line, int linelen);
 void encode_85(char *buf, const unsigned char *data, int bytes);
 
 /* alloc.c */
-extern void *alloc_blob_node(void);
+#define alloc_blob_node(r) alloc_blob_node_##r()
+extern void *alloc_blob_node_the_repository(void);
 extern void *alloc_tree_node(void);
 extern void *alloc_commit_node(void);
 extern void *alloc_tag_node(void);
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#163 lore raw

PATCH 130/194 alloc: add repository argument to alloc_tree_node

In reply to Stefan Beller
---
 alloc.c | 2 +-
 cache.h | 3 ++-
 tree.c  | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)
alloc.c +1 -1
index 6c5c376a25..2c8d143075 100644
@@ -57,7 +57,7 @@ void *alloc_blob_node_the_repository(void)
 }
 
 static struct alloc_state tree_state;
-void *alloc_tree_node(void)
+void *alloc_tree_node_the_repository(void)
 {
 	struct tree *t = alloc_node(&tree_state, sizeof(struct tree));
 	t->object.type = OBJ_TREE;
cache.h +2 -1
index 6ee415d9f7..6a794aa903 100644
@@ -1577,7 +1577,8 @@ void encode_85(char *buf, const unsigned char *data, int bytes);
 /* alloc.c */
 #define alloc_blob_node(r) alloc_blob_node_##r()
 extern void *alloc_blob_node_the_repository(void);
-extern void *alloc_tree_node(void);
+#define alloc_tree_node(r) alloc_tree_node_##r()
+extern void *alloc_tree_node_the_repository(void);
 extern void *alloc_commit_node(void);
 extern void *alloc_tag_node(void);
 extern void *alloc_object_node(void);
tree.c +1 -1
index 37fec8623b..07cea88450 100644
@@ -199,7 +199,7 @@ struct tree *lookup_tree_the_repository(const struct object_id *oid)
 	struct object *obj = lookup_object(the_repository, oid->hash);
 	if (!obj)
 		return create_object(the_repository, oid->hash,
-				     alloc_tree_node());
+				     alloc_tree_node(the_repository));
 	return object_as_type(the_repository, obj, OBJ_TREE, 0);
 }
 
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#164 lore raw

PATCH 131/194 alloc: add repository argument to alloc_commit_node

In reply to Stefan Beller
---
 alloc.c           | 2 +-
 blame.c           | 2 +-
 cache.h           | 3 ++-
 commit.c          | 2 +-
 merge-recursive.c | 2 +-
 5 files changed, 6 insertions(+), 5 deletions(-)
alloc.c +1 -1
index 2c8d143075..9e2b897ec1 100644
@@ -88,7 +88,7 @@ unsigned int alloc_commit_index(void)
 	return count++;
 }
 
-void *alloc_commit_node(void)
+void *alloc_commit_node_the_repository(void)
 {
 	struct commit *c = alloc_node(&commit_state, sizeof(struct commit));
 	c->object.type = OBJ_COMMIT;
blame.c +1 -1
index 8648a1ddff..592bedd0e0 100644
@@ -163,7 +163,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
 
 	read_cache();
 	time(&now);
-	commit = alloc_commit_node();
+	commit = alloc_commit_node(the_repository);
 	commit->object.parsed = 1;
 	commit->date = now;
 	parent_tail = &commit->parents;
cache.h +2 -1
index 6a794aa903..cb41e22123 100644
@@ -1579,7 +1579,8 @@ void encode_85(char *buf, const unsigned char *data, int bytes);
 extern void *alloc_blob_node_the_repository(void);
 #define alloc_tree_node(r) alloc_tree_node_##r()
 extern void *alloc_tree_node_the_repository(void);
-extern void *alloc_commit_node(void);
+#define alloc_commit_node(r) alloc_commit_node_##r()
+extern void *alloc_commit_node_the_repository(void);
 extern void *alloc_tag_node(void);
 extern void *alloc_object_node(void);
 extern void alloc_report(void);
commit.c +1 -1
index 953c537059..17bdd13e0d 100644
@@ -55,7 +55,7 @@ struct commit *lookup_commit_the_repository(const struct object_id *oid)
 	struct object *obj = lookup_object(the_repository, oid->hash);
 	if (!obj)
 		return create_object(the_repository, oid->hash,
-				     alloc_commit_node());
+				     alloc_commit_node(the_repository));
 	return object_as_type(the_repository, obj, OBJ_COMMIT, 0);
 }
 
merge-recursive.c +1 -1
index 0b4cb14773..f6d28f0d8f 100644
@@ -100,7 +100,7 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two,
 
 static struct commit *make_virtual_commit(struct tree *tree, const char *comment)
 {
-	struct commit *commit = alloc_commit_node();
+	struct commit *commit = alloc_commit_node(the_repository);
 
 	set_merge_remote_desc(commit, comment, (struct object *)commit);
 	commit->tree = tree;
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#165 lore raw

PATCH 132/194 alloc: add repository argument to alloc_tag_node

In reply to Stefan Beller
---
 alloc.c | 2 +-
 cache.h | 3 ++-
 tag.c   | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)
alloc.c +1 -1
index 9e2b897ec1..290250e359 100644
@@ -65,7 +65,7 @@ void *alloc_tree_node_the_repository(void)
 }
 
 static struct alloc_state tag_state;
-void *alloc_tag_node(void)
+void *alloc_tag_node_the_repository(void)
 {
 	struct tag *t = alloc_node(&tag_state, sizeof(struct tag));
 	t->object.type = OBJ_TAG;
cache.h +2 -1
index cb41e22123..36c01bdcf5 100644
@@ -1581,7 +1581,8 @@ extern void *alloc_blob_node_the_repository(void);
 extern void *alloc_tree_node_the_repository(void);
 #define alloc_commit_node(r) alloc_commit_node_##r()
 extern void *alloc_commit_node_the_repository(void);
-extern void *alloc_tag_node(void);
+#define alloc_tag_node(r) alloc_tag_node_##r()
+extern void *alloc_tag_node_the_repository(void);
 extern void *alloc_object_node(void);
 extern void alloc_report(void);
 extern unsigned int alloc_commit_index(void);
tag.c +1 -1
index abba1b8d88..e0b695cb60 100644
@@ -97,7 +97,7 @@ struct tag *lookup_tag_the_repository(const struct object_id *oid)
 	struct object *obj = lookup_object(the_repository, oid->hash);
 	if (!obj)
 		return create_object(the_repository, oid->hash,
-				     alloc_tag_node());
+				     alloc_tag_node(the_repository));
 	return object_as_type(the_repository, obj, OBJ_TAG, 0);
 }
 
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#166 lore raw

PATCH 133/194 alloc: add repository argument to alloc_object_node

In reply to Stefan Beller
---
 alloc.c  | 2 +-
 cache.h  | 3 ++-
 object.c | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)
alloc.c +1 -1
index 290250e359..f031ce422d 100644
@@ -73,7 +73,7 @@ void *alloc_tag_node_the_repository(void)
 }
 
 static struct alloc_state object_state;
-void *alloc_object_node(void)
+void *alloc_object_node_the_repository(void)
 {
 	struct object *obj = alloc_node(&object_state, sizeof(union any_object));
 	obj->type = OBJ_NONE;
cache.h +2 -1
index 36c01bdcf5..e0916d1a73 100644
@@ -1583,7 +1583,8 @@ extern void *alloc_tree_node_the_repository(void);
 extern void *alloc_commit_node_the_repository(void);
 #define alloc_tag_node(r) alloc_tag_node_##r()
 extern void *alloc_tag_node_the_repository(void);
-extern void *alloc_object_node(void);
+#define alloc_object_node(r) alloc_object_node_##r()
+extern void *alloc_object_node_the_repository(void);
 extern void alloc_report(void);
 extern unsigned int alloc_commit_index(void);
 
object.c +1 -1
index 156fbae15e..cd73d41d87 100644
@@ -180,7 +180,7 @@ struct object *lookup_unknown_object(struct repository *r,
 	struct object *obj = lookup_object(r, sha1);
 	if (!obj)
 		obj = create_object(r, sha1,
-				    alloc_object_node());
+				    alloc_object_node(the_repository));
 	return obj;
 }
 
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#167 lore raw

PATCH 134/194 alloc: add repository argument to alloc_report

In reply to Stefan Beller
---
 alloc.c | 2 +-
 cache.h | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)
alloc.c +1 -1
index f031ce422d..28b85b2214 100644
@@ -105,7 +105,7 @@ static void report(const char *name, unsigned int count, size_t size)
 #define REPORT(name, type)	\
     report(#name, name##_state.count, name##_state.count * sizeof(type) >> 10)
 
-void alloc_report(void)
+void alloc_report_the_repository(void)
 {
 	REPORT(blob, struct blob);
 	REPORT(tree, struct tree);
cache.h +2 -1
index e0916d1a73..5c9807fa8f 100644
@@ -1585,7 +1585,8 @@ extern void *alloc_commit_node_the_repository(void);
 extern void *alloc_tag_node_the_repository(void);
 #define alloc_object_node(r) alloc_object_node_##r()
 extern void *alloc_object_node_the_repository(void);
-extern void alloc_report(void);
+#define alloc_report(r) alloc_report_##r()
+extern void alloc_report_the_repository(void);
 extern unsigned int alloc_commit_index(void);
 
 /* pkt-line.c */
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#168 lore raw

PATCH 135/194 alloc: add repository argument to alloc_commit_index

In reply to Stefan Beller
---
 alloc.c  | 4 ++--
 cache.h  | 3 ++-
 object.c | 2 +-
 3 files changed, 5 insertions(+), 4 deletions(-)
alloc.c +2 -2
index 28b85b2214..277dadd221 100644
@@ -82,7 +82,7 @@ void *alloc_object_node_the_repository(void)
 
 static struct alloc_state commit_state;
 
-unsigned int alloc_commit_index(void)
+unsigned int alloc_commit_index_the_repository(void)
 {
 	static unsigned int count;
 	return count++;
@@ -92,7 +92,7 @@ void *alloc_commit_node_the_repository(void)
 {
 	struct commit *c = alloc_node(&commit_state, sizeof(struct commit));
 	c->object.type = OBJ_COMMIT;
-	c->index = alloc_commit_index();
+	c->index = alloc_commit_index(the_repository);
 	return c;
 }
 
cache.h +2 -1
index 5c9807fa8f..40aa3f25aa 100644
@@ -1587,7 +1587,8 @@ extern void *alloc_tag_node_the_repository(void);
 extern void *alloc_object_node_the_repository(void);
 #define alloc_report(r) alloc_report_##r()
 extern void alloc_report_the_repository(void);
-extern unsigned int alloc_commit_index(void);
+#define alloc_commit_index(r) alloc_commit_index_##r()
+extern unsigned int alloc_commit_index_the_repository(void);
 
 /* pkt-line.c */
 void packet_trace_identity(const char *prog);
object.c +1 -1
index cd73d41d87..e84447f229 100644
@@ -161,7 +161,7 @@ void *object_as_type_the_repository(struct object *obj, enum object_type type, i
 		return obj;
 	else if (obj->type == OBJ_NONE) {
 		if (type == OBJ_COMMIT)
-			((struct commit *)obj)->index = alloc_commit_index();
+			((struct commit *)obj)->index = alloc_commit_index(the_repository);
 		obj->type = type;
 		return obj;
 	}
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#169 lore raw

PATCH 136/194 alloc: allow arbitrary repositories for alloc functions

In reply to Stefan Beller

We have to convert them all at once, because alloc_report uses funky a macro for reporting. It is better for the sake of mechanical conversion to convert multiple functions at once rather than changing the structure of the reporting function.

---
 alloc.c      | 48 ++++++++++++++++++++++++++----------------------
 cache.h      | 22 ++++++++--------------
 object.h     | 20 +++++++++++++++++++-
 repository.c |  6 ++++++
 4 files changed, 59 insertions(+), 37 deletions(-)
alloc.c +26 -22
index 277dadd221..0e11c7766a 100644
@@ -32,6 +32,11 @@ struct alloc_state {
 	void *p;   /* first free node in current allocation */
 };
 
+void *allocate_alloc_state(void)
+{
+	return xcalloc(1, sizeof(struct alloc_state));
+}
+
 static inline void *alloc_node(struct alloc_state *s, size_t node_size)
 {
 	void *ret;
@@ -48,51 +53,49 @@ static inline void *alloc_node(struct alloc_state *s, size_t node_size)
 	return ret;
 }
 
-static struct alloc_state blob_state;
-void *alloc_blob_node_the_repository(void)
+struct alloc_state the_repository_blob_state;
+void *alloc_blob_node(struct repository *r)
 {
-	struct blob *b = alloc_node(&blob_state, sizeof(struct blob));
+	struct blob *b = alloc_node(r->parsed_objects.blob_state, sizeof(struct blob));
 	b->object.type = OBJ_BLOB;
 	return b;
 }
 
-static struct alloc_state tree_state;
-void *alloc_tree_node_the_repository(void)
+struct alloc_state the_repository_tree_state;
+void *alloc_tree_node(struct repository *r)
 {
-	struct tree *t = alloc_node(&tree_state, sizeof(struct tree));
+	struct tree *t = alloc_node(r->parsed_objects.tree_state, sizeof(struct tree));
 	t->object.type = OBJ_TREE;
 	return t;
 }
 
-static struct alloc_state tag_state;
-void *alloc_tag_node_the_repository(void)
+struct alloc_state the_repository_tag_state;
+void *alloc_tag_node(struct repository *r)
 {
-	struct tag *t = alloc_node(&tag_state, sizeof(struct tag));
+	struct tag *t = alloc_node(r->parsed_objects.tag_state, sizeof(struct tag));
 	t->object.type = OBJ_TAG;
 	return t;
 }
 
-static struct alloc_state object_state;
-void *alloc_object_node_the_repository(void)
+struct alloc_state the_repository_object_state;
+void *alloc_object_node(struct repository *r)
 {
-	struct object *obj = alloc_node(&object_state, sizeof(union any_object));
+	struct object *obj = alloc_node(r->parsed_objects.object_state, sizeof(union any_object));
 	obj->type = OBJ_NONE;
 	return obj;
 }
 
-static struct alloc_state commit_state;
-
-unsigned int alloc_commit_index_the_repository(void)
+unsigned int alloc_commit_index(struct repository *r)
 {
-	static unsigned int count;
-	return count++;
+	return r->parsed_objects.commit_count++;
 }
 
-void *alloc_commit_node_the_repository(void)
+struct alloc_state the_repository_commit_state;
+void *alloc_commit_node(struct repository *r)
 {
-	struct commit *c = alloc_node(&commit_state, sizeof(struct commit));
+	struct commit *c = alloc_node(r->parsed_objects.commit_state, sizeof(struct commit));
 	c->object.type = OBJ_COMMIT;
-	c->index = alloc_commit_index(the_repository);
+	c->index = alloc_commit_index(r);
 	return c;
 }
 
@@ -103,9 +106,10 @@ static void report(const char *name, unsigned int count, size_t size)
 }
 
 #define REPORT(name, type)	\
-    report(#name, name##_state.count, name##_state.count * sizeof(type) >> 10)
+    report(#name, r->parsed_objects.name##_state->count, \
+		  r->parsed_objects.name##_state->count * sizeof(type) >> 10)
 
-void alloc_report_the_repository(void)
+void alloc_report(struct repository *r)
 {
 	REPORT(blob, struct blob);
 	REPORT(tree, struct tree);
cache.h +8 -14
index 40aa3f25aa..ee01daf130 100644
@@ -1575,20 +1575,14 @@ int decode_85(char *dst, const char *line, int linelen);
 void encode_85(char *buf, const unsigned char *data, int bytes);
 
 /* alloc.c */
-#define alloc_blob_node(r) alloc_blob_node_##r()
-extern void *alloc_blob_node_the_repository(void);
-#define alloc_tree_node(r) alloc_tree_node_##r()
-extern void *alloc_tree_node_the_repository(void);
-#define alloc_commit_node(r) alloc_commit_node_##r()
-extern void *alloc_commit_node_the_repository(void);
-#define alloc_tag_node(r) alloc_tag_node_##r()
-extern void *alloc_tag_node_the_repository(void);
-#define alloc_object_node(r) alloc_object_node_##r()
-extern void *alloc_object_node_the_repository(void);
-#define alloc_report(r) alloc_report_##r()
-extern void alloc_report_the_repository(void);
-#define alloc_commit_index(r) alloc_commit_index_##r()
-extern unsigned int alloc_commit_index_the_repository(void);
+extern void *alloc_blob_node(struct repository *r);
+extern void *alloc_tree_node(struct repository *r);
+extern void *alloc_commit_node(struct repository *r);
+extern void *alloc_tag_node(struct repository *r);
+extern void *alloc_object_node(struct repository *r);
+extern void alloc_report(struct repository *r);
+extern unsigned int alloc_commit_index(struct repository *r);
+void *allocate_alloc_state(void);
 
 /* pkt-line.c */
 void packet_trace_identity(const char *prog);
object.h +19 -1
index a61d965700..587db55dfe 100644
@@ -8,9 +8,27 @@ struct object_parser {
 	/* parent substitutions from .git/info/grafts and .git/shallow */
 	struct commit_graft **grafts;
 	int grafts_alloc, grafts_nr;
+
+	struct alloc_state *blob_state;
+	struct alloc_state *tree_state;
+	struct alloc_state *commit_state;
+	struct alloc_state *tag_state;
+	struct alloc_state *object_state;
+	unsigned commit_count;
 };
 
-#define OBJECT_PARSER_INIT { NULL, 0, 0, NULL, 0, 0 }
+extern struct alloc_state the_repository_blob_state;
+extern struct alloc_state the_repository_tree_state;
+extern struct alloc_state the_repository_commit_state;
+extern struct alloc_state the_repository_tag_state;
+extern struct alloc_state the_repository_object_state;
+#define OBJECT_PARSER_INIT { NULL, 0, 0, NULL, 0, 0, \
+	&the_repository_blob_state, \
+	&the_repository_tree_state, \
+	&the_repository_commit_state, \
+	&the_repository_tag_state, \
+	&the_repository_object_state, \
+	0 }
 
 struct object_list {
 	struct object *item;
repository.c +6 -0
index 361e503824..f76f0ddd37 100644
@@ -175,6 +175,12 @@ int repo_init(struct repository *repo, const char *gitdir, const char *worktree)
 
 	repo_set_hash_algo(repo, format.hash_algo);
 
+	repo->parsed_objects.blob_state = allocate_alloc_state();
+	repo->parsed_objects.tree_state = allocate_alloc_state();
+	repo->parsed_objects.commit_state = allocate_alloc_state();
+	repo->parsed_objects.tag_state = allocate_alloc_state();
+	repo->parsed_objects.object_state = allocate_alloc_state();
+
 	if (worktree)
 		repo_set_worktree(repo, worktree);
 
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#170 lore raw

Re: [PATCH 136/194] alloc: allow arbitrary repositories for alloc functions

Quoted 1 line · Stefan Beller

We have to convert them all at once, because alloc_report uses funky a

s/funky a/a funky/

Quoted 5 lines

macro for reporting. It is better for the sake of mechanical conversion to convert multiple functions at once rather than changing the structure of the reporting function.

#171 lore raw

PATCH 137/194 object: allow object_as_type to handle arbitrary repositories

In reply to Stefan Beller
---
 object.c | 4 ++--
 object.h | 3 +--
 2 files changed, 3 insertions(+), 4 deletions(-)
object.c +2 -2
index e84447f229..db15de6623 100644
@@ -155,13 +155,13 @@ void *create_object(struct repository *r, const unsigned char *sha1, void *o)
 	return obj;
 }
 
-void *object_as_type_the_repository(struct object *obj, enum object_type type, int quiet)
+void *object_as_type(struct repository *r, struct object *obj, enum object_type type, int quiet)
 {
 	if (obj->type == type)
 		return obj;
 	else if (obj->type == OBJ_NONE) {
 		if (type == OBJ_COMMIT)
-			((struct commit *)obj)->index = alloc_commit_index(the_repository);
+			((struct commit *)obj)->index = alloc_commit_index(r);
 		obj->type = type;
 		return obj;
 	}
object.h +1 -2
index 587db55dfe..513f5eaef4 100644
@@ -124,8 +124,7 @@ struct object *lookup_object(struct repository *r, const unsigned char *sha1);
 
 extern void *create_object(struct repository *r, const unsigned char *sha1, void *obj);
 
-#define object_as_type(r, o, t, q) object_as_type_##r(o, t, q)
-void *object_as_type_the_repository(struct object *obj, enum object_type type, int quiet);
+void *object_as_type(struct repository *r, struct object *obj, enum object_type type, int quiet);
 
 /*
  * Resolves 'sha1' to an object of the specified type and returns the
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#172 lore raw

PATCH 138/194 commit: allow lookup_commit to handle arbitrary repositories

In reply to Stefan Beller
---
 commit.c | 10 +++++-----
 commit.h |  3 +--
 2 files changed, 6 insertions(+), 7 deletions(-)
commit.c +5 -5
index 17bdd13e0d..435735ed2c 100644
@@ -50,13 +50,13 @@ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref
 	return c;
 }
 
-struct commit *lookup_commit_the_repository(const struct object_id *oid)
+struct commit *lookup_commit(struct repository *r, const struct object_id *oid)
 {
-	struct object *obj = lookup_object(the_repository, oid->hash);
+	struct object *obj = lookup_object(r, oid->hash);
 	if (!obj)
-		return create_object(the_repository, oid->hash,
-				     alloc_commit_node(the_repository));
-	return object_as_type(the_repository, obj, OBJ_COMMIT, 0);
+		return create_object(r, oid->hash,
+				     alloc_commit_node(r));
+	return object_as_type(r, obj, OBJ_COMMIT, 0);
 }
 
 struct commit *lookup_commit_reference_by_name(const char *name)
commit.h +1 -2
index f791a55379..41a8947b33 100644
@@ -46,8 +46,7 @@ enum decoration_type {
 void add_name_decoration(enum decoration_type type, const char *name, struct object *obj);
 const struct name_decoration *get_name_decoration(const struct object *obj);
 
-#define lookup_commit(r, o) lookup_commit_##r(o)
-struct commit *lookup_commit_the_repository(const struct object_id *oid);
+struct commit *lookup_commit(struct repository *r, const struct object_id *oid);
 #define lookup_commit_reference(r, o) \
 		lookup_commit_reference_##r(o)
 struct commit *lookup_commit_reference_the_repository(const struct object_id *oid);
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#173 lore raw

PATCH 139/194 sha1_file: allow add_to_alternates_file to handle arbitrary repositories

In reply to Stefan Beller

From: Brandon Williams <[email protected]>

---
 alternates.h | 3 +--
 sha1_file.c  | 8 ++++----
 2 files changed, 5 insertions(+), 6 deletions(-)
alternates.h +1 -2
index b3d8d57ba4..4d5296c83f 100644
@@ -48,8 +48,7 @@ struct alternate_object_database *alloc_alt_odb(const char *dir);
  * Add the directory to the on-disk alternates file; the new entry will also
  * take effect in the current process.
  */
-#define add_to_alternates_file(r, d) add_to_alternates_file_##r(d)
-extern void add_to_alternates_file_the_repository(const char *dir);
+extern void add_to_alternates_file(struct repository *r, const char *dir);
 
 /*
  * Add the directory to the in-memory list of alternates (along with any
sha1_file.c +4 -4
index 3c39e34c72..8638fae9c4 100644
@@ -538,10 +538,10 @@ struct alternate_object_database *alloc_alt_odb(const char *dir)
 	return ent;
 }
 
-void add_to_alternates_file_the_repository(const char *reference)
+void add_to_alternates_file(struct repository *r, const char *reference)
 {
 	struct lock_file lock = LOCK_INIT;
-	char *alts = git_pathdup("objects/info/alternates");
+	char *alts = repo_git_path(r, "objects/info/alternates");
 	FILE *in, *out;
 	int found = 0;
 
@@ -574,8 +574,8 @@ void add_to_alternates_file_the_repository(const char *reference)
 		fprintf_or_die(out, "%s\n", reference);
 		if (commit_lock_file(&lock))
 			die_errno("unable to move new alternates file into place");
-		if (the_repository->objects.alt_odb.tail)
-			link_alt_odb_entries(the_repository, reference,
+		if (r->objects.alt_odb.tail)
+			link_alt_odb_entries(r, reference,
 					     '\n', NULL, 0);
 	}
 	free(alts);
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#174 lore raw

PATCH 140/194 commit: convert commit_graft_pos() to handle arbitrary repositories

In reply to Stefan Beller

From: Brandon Williams <[email protected]>

---
 commit.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
commit.c +3 -4
index 435735ed2c..0d006ab1bb 100644
@@ -105,11 +105,10 @@ static const unsigned char *commit_graft_sha1_access(size_t index, void *table)
 	return commit_graft_table[index]->oid.hash;
 }
 
-#define commit_graft_pos(r, s) commit_graft_pos_##r(s)
-static int commit_graft_pos_the_repository(const unsigned char *sha1)
+static int commit_graft_pos(struct repository *r, const unsigned char *sha1)
 {
-	return sha1_pos(sha1, the_repository->parsed_objects.grafts,
-			the_repository->parsed_objects.grafts_nr,
+	return sha1_pos(sha1, r->parsed_objects.grafts,
+			r->parsed_objects.grafts_nr,
 			commit_graft_sha1_access);
 }
 
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#175 lore raw

PATCH 141/194 commit: convert register_commit_graft to handle arbitrary repositories

In reply to Stefan Beller

From: Brandon Williams <[email protected]>

---
 commit.c | 29 +++++++++++++++--------------
 commit.h |  3 +--
 2 files changed, 16 insertions(+), 16 deletions(-)
commit.c +15 -14
index 0d006ab1bb..43ed3298cc 100644
@@ -112,30 +112,31 @@ static int commit_graft_pos(struct repository *r, const unsigned char *sha1)
 			commit_graft_sha1_access);
 }
 
-int register_commit_graft_the_repository(struct commit_graft *graft, int ignore_dups)
+int register_commit_graft(struct repository *r, struct commit_graft *graft,
+			  int ignore_dups)
 {
-	int pos = commit_graft_pos(the_repository, graft->oid.hash);
+	int pos = commit_graft_pos(r, graft->oid.hash);
 
 	if (0 <= pos) {
 		if (ignore_dups)
 			free(graft);
 		else {
-			free(the_repository->parsed_objects.grafts[pos]);
-			the_repository->parsed_objects.grafts[pos] = graft;
+			free(r->parsed_objects.grafts[pos]);
+			r->parsed_objects.grafts[pos] = graft;
 		}
 		return 1;
 	}
 	pos = -pos - 1;
-	ALLOC_GROW(the_repository->parsed_objects.grafts,
-		   the_repository->parsed_objects.grafts_nr + 1,
-		   the_repository->parsed_objects.grafts_alloc);
-	the_repository->parsed_objects.grafts_nr++;
-	if (pos < the_repository->parsed_objects.grafts_nr)
-		memmove(the_repository->parsed_objects.grafts + pos + 1,
-			the_repository->parsed_objects.grafts + pos,
-			(the_repository->parsed_objects.grafts_nr - pos - 1) *
-			sizeof(*the_repository->parsed_objects.grafts));
-	the_repository->parsed_objects.grafts[pos] = graft;
+	ALLOC_GROW(r->parsed_objects.grafts,
+		   r->parsed_objects.grafts_nr + 1,
+		   r->parsed_objects.grafts_alloc);
+	r->parsed_objects.grafts_nr++;
+	if (pos < r->parsed_objects.grafts_nr)
+		memmove(r->parsed_objects.grafts + pos + 1,
+			r->parsed_objects.grafts + pos,
+			(r->parsed_objects.grafts_nr - pos - 1) *
+			sizeof(*r->parsed_objects.grafts));
+	r->parsed_objects.grafts[pos] = graft;
 	return 0;
 }
 
commit.h +1 -2
index 41a8947b33..870ad525fd 100644
@@ -175,8 +175,7 @@ struct commit_graft {
 typedef int (*each_commit_graft_fn)(const struct commit_graft *, void *);
 
 struct commit_graft *read_graft_line(struct strbuf *line);
-#define register_commit_graft(r, g, i) register_commit_graft_##r(g, i)
-int register_commit_graft_the_repository(struct commit_graft *, int);
+int register_commit_graft(struct repository *r, struct commit_graft *, int);
 #define lookup_commit_graft(r, o) lookup_commit_graft_##r(o)
 struct commit_graft *lookup_commit_graft_the_repository(const struct object_id *oid);
 
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#176 lore raw

PATCH 142/194 commit: convert read_graft_file to handle arbitrary repositories

In reply to Stefan Beller

From: Brandon Williams <[email protected]>

---
 commit.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
commit.c +2 -3
index 43ed3298cc..3a990b7078 100644
@@ -178,8 +178,7 @@ struct commit_graft *read_graft_line(struct strbuf *line)
 	return NULL;
 }
 
-#define read_graft_file(r, f) read_graft_file_##r(f)
-static int read_graft_file_the_repository(const char *graft_file)
+static int read_graft_file(struct repository *r, const char *graft_file)
 {
 	FILE *fp = fopen_or_warn(graft_file, "r");
 	struct strbuf buf = STRBUF_INIT;
@@ -190,7 +189,7 @@ static int read_graft_file_the_repository(const char *graft_file)
 		struct commit_graft *graft = read_graft_line(&buf);
 		if (!graft)
 			continue;
-		if (register_commit_graft(the_repository, graft, 1))
+		if (register_commit_graft(r, graft, 1))
 			error("duplicate graft data: %s", buf.buf);
 	}
 	fclose(fp);
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#177 lore raw

PATCH 143/194 object: add repository argument to parse_commit_gently

In reply to Stefan Beller

Add a repository argument to allow callers of parse_commit_gently to be more specific about which repository to handle. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet.

As with the previous commits, use a macro to catch callers passing a repository other than the_repository at compile time.

The included coccinelle semantic patch will adapt any new callers in the diff produced by make coccicheck.

---
 commit.c                              | 2 +-
 commit.h                              | 5 +++--
 contrib/coccinelle/object_store.cocci | 9 +++++++++
 revision.c                            | 4 ++--
 4 files changed, 15 insertions(+), 5 deletions(-)
commit.c +1 -1
index 3a990b7078..93a4f70fa4 100644
@@ -384,7 +384,7 @@ int parse_commit_buffer_the_repository(struct commit *item, const void *buffer,
 	return 0;
 }
 
-int parse_commit_gently(struct commit *item, int quiet_on_missing)
+int parse_commit_gently_the_repository(struct commit *item, int quiet_on_missing)
 {
 	enum object_type type;
 	void *buffer;
commit.h +3 -2
index 870ad525fd..bb2b1e1e28 100644
@@ -66,10 +66,11 @@ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref
 
 #define parse_commit_buffer(r, i, b, s) parse_commit_buffer_##r(i, b, s)
 int parse_commit_buffer_the_repository(struct commit *item, const void *buffer, unsigned long size);
-int parse_commit_gently(struct commit *item, int quiet_on_missing);
+#define parse_commit_gently(r, i, q) parse_commit_gently_##r(i, q)
+int parse_commit_gently_the_repository(struct commit *item, int quiet_on_missing);
 static inline int parse_commit(struct commit *item)
 {
-	return parse_commit_gently(item, 0);
+	return parse_commit_gently(the_repository, item, 0);
 }
 void parse_commit_or_die(struct commit *item);
 
contrib/coccinelle/object_store.cocci +9 -0
index 3d29868dbf..93b1d03971 100644
@@ -44,3 +44,12 @@ expression H;
 open_istream(
 + the_repository,
  E, F, G, H)
+
+@@
+expression E;
+expression F;
+@@
+ parse_commit_gently(
++ the_repository,
+  E, F)
+
revision.c +2 -2
index 5c5375ac54..7501ef3160 100644
@@ -775,7 +775,7 @@ static int add_parents_to_list(struct rev_info *revs, struct commit *commit,
 			parent = parent->next;
 			if (p)
 				p->object.flags |= UNINTERESTING;
-			if (parse_commit_gently(p, 1) < 0)
+			if (parse_commit_gently(the_repository, p, 1) < 0)
 				continue;
 			if (p->parents)
 				mark_parents_uninteresting(p);
@@ -802,7 +802,7 @@ static int add_parents_to_list(struct rev_info *revs, struct commit *commit,
 	for (parent = commit->parents; parent; parent = parent->next) {
 		struct commit *p = parent->item;
 
-		if (parse_commit_gently(p, revs->ignore_missing_links) < 0)
+		if (parse_commit_gently(the_repository, p, revs->ignore_missing_links) < 0)
 			return -1;
 		if (revs->show_source && !p->util)
 			p->util = commit->util;
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#178 lore raw

PATCH 144/194 commit: add repository argument to parse_commit

In reply to Stefan Beller

Add a repository argument to allow callers of parse_commit to be more specific about which repository to handle. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet.

As with the previous commits, use a macro to catch callers passing a repository other than the_repository at compile time.

The included coccinelle semantic patch will adapt any new callers in the diff produced by make coccicheck.

---
 blame.c                               |  4 ++--
 builtin/checkout.c                    |  4 ++--
 builtin/commit.c                      |  4 ++--
 builtin/describe.c                    |  4 ++--
 builtin/merge-base.c                  |  2 +-
 builtin/name-rev.c                    |  2 +-
 builtin/notes.c                       |  2 +-
 builtin/reflog.c                      |  2 +-
 builtin/show-branch.c                 |  4 ++--
 commit.c                              | 18 +++++++++---------
 commit.h                              |  3 ++-
 contrib/coccinelle/object_store.cocci |  7 +++++++
 fetch-pack.c                          |  6 +++---
 fsck.c                                |  2 +-
 merge-recursive.c                     |  4 ++--
 notes-utils.c                         |  2 +-
 remote.c                              |  2 +-
 revision.c                            |  6 +++---
 sequencer.c                           | 12 ++++++------
 sha1_name.c                           |  4 ++--
 shallow.c                             |  4 ++--
 tree.c                                |  2 +-
 walker.c                              |  2 +-
 23 files changed, 55 insertions(+), 47 deletions(-)
blame.c +2 -2
index 592bedd0e0..ccd6a5097b 100644
@@ -1433,7 +1433,7 @@ static void pass_blame(struct blame_scoreboard *sb, struct blame_origin *origin,
 
 			if (sg_origin[i])
 				continue;
-			if (parse_commit(p))
+			if (parse_commit(the_repository, p))
 				continue;
 			porigin = find(p, origin);
 			if (!porigin)
@@ -1572,7 +1572,7 @@ void assign_blame(struct blame_scoreboard *sb, int opt)
 		 * so hold onto it in the meantime.
 		 */
 		blame_origin_incref(suspect);
-		parse_commit(commit);
+		parse_commit(the_repository, commit);
 		if (sb->reverse ||
 		    (!(commit->object.flags & UNINTERESTING) &&
 		     !(revs->max_age != -1 && commit->date < revs->max_age)))
builtin/checkout.c +2 -2
index cef2b4f2ad..4428fd5da5 100644
@@ -403,7 +403,7 @@ static void describe_detached_head(const char *msg, struct commit *commit)
 {
 	struct strbuf sb = STRBUF_INIT;
 
-	if (!parse_commit(commit))
+	if (!parse_commit(the_repository, commit))
 		pp_commit_easy(CMIT_FMT_ONELINE, commit, &sb);
 	if (print_sha1_ellipsis()) {
 		fprintf(stderr, "%s %s... %s\n", msg,
@@ -724,7 +724,7 @@ static void describe_one_orphan(struct strbuf *sb, struct commit *commit)
 	strbuf_addstr(sb, "  ");
 	strbuf_add_unique_abbrev(sb, commit->object.oid.hash, DEFAULT_ABBREV);
 	strbuf_addch(sb, ' ');
-	if (!parse_commit(commit))
+	if (!parse_commit(the_repository, commit))
 		pp_commit_easy(CMIT_FMT_ONELINE, commit, sb);
 	strbuf_addch(sb, '\n');
 }
builtin/commit.c +2 -2
index cd3144f9f4..d15592ad45 100644
@@ -1467,7 +1467,7 @@ static void print_summary(const char *prefix, const struct object_id *oid,
 	commit = lookup_commit(the_repository, oid);
 	if (!commit)
 		die(_("couldn't look up newly created commit"));
-	if (parse_commit(commit))
+	if (parse_commit(the_repository, commit))
 		die(_("could not parse newly created commit"));
 
 	strbuf_addstr(&format, "format:%h] %s");
@@ -1692,7 +1692,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 		current_head = NULL;
 	else {
 		current_head = lookup_commit_or_die(&oid, "HEAD");
-		if (parse_commit(current_head))
+		if (parse_commit(the_repository, current_head))
 			die(_("could not parse HEAD commit"));
 	}
 	verbose = -1; /* unspecified */
builtin/describe.c +2 -2
index 5bd0920ebd..870a3a780b 100644
@@ -249,7 +249,7 @@ static unsigned long finish_depth_computation(
 			best->depth++;
 		while (parents) {
 			struct commit *p = parents->item;
-			parse_commit(p);
+			parse_commit(the_repository, p);
 			if (!(p->object.flags & SEEN))
 				commit_list_insert_by_date(p, list);
 			p->object.flags |= c->object.flags;
@@ -367,7 +367,7 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst)
 		}
 		while (parents) {
 			struct commit *p = parents->item;
-			parse_commit(p);
+			parse_commit(the_repository, p);
 			if (!(p->object.flags & SEEN))
 				commit_list_insert_by_date(p, &list);
 			p->object.flags |= c->object.flags;
builtin/merge-base.c +1 -1
index 08d91b1f0c..426882818c 100644
@@ -127,7 +127,7 @@ static void add_one_commit(struct object_id *oid, struct rev_collect *revs)
 	commit = lookup_commit(the_repository, oid);
 	if (!commit ||
 	    (commit->object.flags & TMP_MARK) ||
-	    parse_commit(commit))
+	    parse_commit(the_repository, commit))
 		return;
 
 	ALLOC_GROW(revs->commit, revs->nr + 1, revs->alloc);
builtin/name-rev.c +1 -1
index 2cbb702c2c..57db381381 100644
@@ -71,7 +71,7 @@ static void name_rev(struct commit *commit,
 	int parent_number = 1;
 	char *to_free = NULL;
 
-	parse_commit(commit);
+	parse_commit(the_repository, commit);
 
 	if (commit->date < cutoff)
 		return;
builtin/notes.c +1 -1
index 56d99c2789..9100ac5ce0 100644
@@ -715,7 +715,7 @@ static int merge_commit(struct notes_merge_options *o)
 		die(_("failed to read ref NOTES_MERGE_PARTIAL"));
 	else if (!(partial = lookup_commit_reference(the_repository, &oid)))
 		die(_("could not find commit from NOTES_MERGE_PARTIAL."));
-	else if (parse_commit(partial))
+	else if (parse_commit(the_repository, partial))
 		die(_("could not parse commit from NOTES_MERGE_PARTIAL."));
 
 	if (partial->parents)
builtin/reflog.c +1 -1
index 3b600966e3..05eb1baa31 100644
@@ -235,7 +235,7 @@ static void mark_reachable(struct expire_reflog_policy_cb *cb)
 		struct commit *commit = pop_commit(&pending);
 		if (commit->object.flags & REACHABLE)
 			continue;
-		if (parse_commit(commit))
+		if (parse_commit(the_repository, commit))
 			continue;
 		commit->object.flags |= REACHABLE;
 		if (commit->date < expire_limit) {
builtin/show-branch.c +2 -2
index 03c98efbe5..a3195937d3 100644
@@ -220,7 +220,7 @@ static void join_revs(struct commit_list **list_p,
 			parents = parents->next;
 			if ((this_flag & flags) == flags)
 				continue;
-			parse_commit(p);
+			parse_commit(the_repository, p);
 			if (mark_seen(p, seen_p) && !still_interesting)
 				extra--;
 			p->object.flags |= flags;
@@ -815,7 +815,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
 		if (!commit)
 			die(_("cannot find commit %s (%s)"),
 			    ref_name[num_rev], oid_to_hex(&revkey));
-		parse_commit(commit);
+		parse_commit(the_repository, commit);
 		mark_seen(commit, &seen);
 
 		/* rev#0 uses bit REV_SHIFT, rev#1 uses bit REV_SHIFT+1,
commit.c +9 -9
index 93a4f70fa4..49c8f76e41 100644
@@ -67,7 +67,7 @@ struct commit *lookup_commit_reference_by_name(const char *name)
 	if (get_oid_committish(name, &oid))
 		return NULL;
 	commit = lookup_commit_reference(the_repository, &oid);
-	if (parse_commit(commit))
+	if (parse_commit(the_repository, commit))
 		return NULL;
 	return commit;
 }
@@ -417,7 +417,7 @@ int parse_commit_gently_the_repository(struct commit *item, int quiet_on_missing
 
 void parse_commit_or_die(struct commit *item)
 {
-	if (parse_commit(item))
+	if (parse_commit(the_repository, item))
 		die("unable to parse commit %s",
 		    item ? oid_to_hex(&item->object.oid) : "(null)");
 }
@@ -522,7 +522,7 @@ struct commit *pop_most_recent_commit(struct commit_list **list,
 
 	while (parents) {
 		struct commit *commit = parents->item;
-		if (!parse_commit(commit) && !(commit->object.flags & mark)) {
+		if (!parse_commit(the_repository, commit) && !(commit->object.flags & mark)) {
 			commit->object.flags |= mark;
 			commit_list_insert_by_date(commit, list);
 		}
@@ -834,7 +834,7 @@ static struct commit_list *paint_down_to_common(struct commit *one, int n, struc
 			parents = parents->next;
 			if ((p->object.flags & flags) == flags)
 				continue;
-			if (parse_commit(p))
+			if (parse_commit(the_repository, p))
 				return NULL;
 			p->object.flags |= flags;
 			prio_queue_put(&queue, p);
@@ -860,10 +860,10 @@ static struct commit_list *merge_bases_many(struct commit *one, int n, struct co
 			return commit_list_insert(one, &result);
 	}
 
-	if (parse_commit(one))
+	if (parse_commit(the_repository, one))
 		return NULL;
 	for (i = 0; i < n; i++) {
-		if (parse_commit(twos[i]))
+		if (parse_commit(the_repository, twos[i]))
 			return NULL;
 	}
 
@@ -922,7 +922,7 @@ static int remove_redundant(struct commit **array, int cnt)
 	ALLOC_ARRAY(filled_index, cnt - 1);
 
 	for (i = 0; i < cnt; i++)
-		parse_commit(array[i]);
+		parse_commit(the_repository, array[i]);
 	for (i = 0; i < cnt; i++) {
 		struct commit_list *common;
 
@@ -1046,10 +1046,10 @@ int in_merge_bases_many(struct commit *commit, int nr_reference, struct commit *
 	struct commit_list *bases;
 	int ret = 0, i;
 
-	if (parse_commit(commit))
+	if (parse_commit(the_repository, commit))
 		return ret;
 	for (i = 0; i < nr_reference; i++)
-		if (parse_commit(reference[i]))
+		if (parse_commit(the_repository, reference[i]))
 			return ret;
 
 	bases = paint_down_to_common(commit, nr_reference, reference);
commit.h +2 -1
index bb2b1e1e28..16203fb18c 100644
@@ -68,7 +68,8 @@ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref
 int parse_commit_buffer_the_repository(struct commit *item, const void *buffer, unsigned long size);
 #define parse_commit_gently(r, i, q) parse_commit_gently_##r(i, q)
 int parse_commit_gently_the_repository(struct commit *item, int quiet_on_missing);
-static inline int parse_commit(struct commit *item)
+#define parse_commit(r, i) parse_commit_##r(i)
+static inline int parse_commit_the_repository(struct commit *item)
 {
 	return parse_commit_gently(the_repository, item, 0);
 }
contrib/coccinelle/object_store.cocci +7 -0
index 93b1d03971..3ffb34d5b5 100644
@@ -53,3 +53,10 @@ expression F;
 + the_repository,
   E, F)
 
+@@
+expression E;
+@@
+ parse_commit(
++ the_repository,
+ E)
+
fetch-pack.c +3 -3
index f38beea6a3..e8b1fc0d1b 100644
@@ -112,7 +112,7 @@ static void rev_list_push(struct commit *commit, int mark)
 	if (!(commit->object.flags & mark)) {
 		commit->object.flags |= mark;
 
-		if (parse_commit(commit))
+		if (parse_commit(the_repository, commit))
 			return;
 
 		prio_queue_put(&rev_list, commit);
@@ -176,7 +176,7 @@ static void mark_common(struct commit *commit,
 			if (!ancestors_only && !(o->flags & POPPED))
 				non_common_revs--;
 			if (!o->parsed && !dont_parse)
-				if (parse_commit(commit))
+				if (parse_commit(the_repository, commit))
 					return;
 
 			for (parents = commit->parents;
@@ -203,7 +203,7 @@ static const struct object_id *get_rev(void)
 			return NULL;
 
 		commit = prio_queue_get(&rev_list);
-		parse_commit(commit);
+		parse_commit(the_repository, commit);
 		parents = commit->parents;
 
 		commit->object.flags |= POPPED;
fsck.c +1 -1
index 5144ceb8e2..494b4e3b30 100644
@@ -393,7 +393,7 @@ static int fsck_walk_commit(struct commit *commit, void *data, struct fsck_optio
 	int result;
 	const char *name;
 
-	if (parse_commit(commit))
+	if (parse_commit(the_repository, commit))
 		return -1;
 
 	name = get_object_name(options, &commit->object);
merge-recursive.c +2 -2
index f6d28f0d8f..719fa58ab1 100644
@@ -233,7 +233,7 @@ static void output_commit_title(struct merge_options *o, struct commit *commit)
 		strbuf_add_unique_abbrev(&o->obuf, commit->object.oid.hash,
 					 DEFAULT_ABBREV);
 		strbuf_addch(&o->obuf, ' ');
-		if (parse_commit(commit) != 0)
+		if (parse_commit(the_repository, commit) != 0)
 			strbuf_addstr(&o->obuf, _("(bad commit)\n"));
 		else {
 			const char *title;
@@ -2162,7 +2162,7 @@ static struct commit *get_ref(const struct object_id *oid, const char *name)
 		return make_virtual_commit((struct tree*)object, name);
 	if (object->type != OBJ_COMMIT)
 		return NULL;
-	if (parse_commit((struct commit *)object))
+	if (parse_commit(the_repository, (struct commit *)object))
 		return NULL;
 	return (struct commit *)object;
 }
notes-utils.c +1 -1
index 3ef5340c6e..7b0b2a8f8a 100644
@@ -22,7 +22,7 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
 		if (!read_ref(t->ref, &parent_oid)) {
 			struct commit *parent = lookup_commit(the_repository,
 							      &parent_oid);
-			if (parse_commit(parent))
+			if (parse_commit(the_repository, parent))
 				die("Failed to find/parse commit %s", t->ref);
 			commit_list_insert(parent, &parents);
 		}
remote.c +1 -1
index ecfa60a975..a4cf885012 100644
@@ -1993,7 +1993,7 @@ int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid)
 		return 0;
 	new = (struct commit *) o;
 
-	if (parse_commit(new) < 0)
+	if (parse_commit(the_repository, new) < 0)
 		return 0;
 
 	used = list = NULL;
revision.c +3 -3
index 7501ef3160..56c1a9a78f 100644
@@ -253,7 +253,7 @@ static struct commit *handle_commit(struct rev_info *revs,
 	 */
 	if (object->type == OBJ_COMMIT) {
 		struct commit *commit = (struct commit *)object;
-		if (parse_commit(commit) < 0)
+		if (parse_commit(the_repository, commit) < 0)
 			die("unable to parse commit %s", name);
 		if (flags & UNINTERESTING) {
 			mark_parents_uninteresting(commit);
@@ -663,7 +663,7 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
 					ts->treesame[0] = 1;
 			}
 		}
-		if (parse_commit(p) < 0)
+		if (parse_commit(the_repository, p) < 0)
 			die("cannot simplify commit %s (because of %s)",
 			    oid_to_hex(&commit->object.oid),
 			    oid_to_hex(&p->object.oid));
@@ -696,7 +696,7 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
 				 * IOW, we pretend this parent is a
 				 * "root" commit.
 				 */
-				if (parse_commit(p) < 0)
+				if (parse_commit(the_repository, p) < 0)
 					die("cannot simplify commit %s (invalid %s)",
 					    oid_to_hex(&commit->object.oid),
 					    oid_to_hex(&p->object.oid));
sequencer.c +6 -6
index 4d259d9ae4..e94ed30965 100644
@@ -507,7 +507,7 @@ static int is_index_unchanged(void)
 	 * the commit is invalid, parse_commit() will complain.  So
 	 * there is nothing for us to say here.  Just return failure.
 	 */
-	if (parse_commit(head_commit))
+	if (parse_commit(the_repository, head_commit))
 		return -1;
 
 	if (!active_cache_tree)
@@ -700,12 +700,12 @@ static int is_original_commit_empty(struct commit *commit)
 {
 	const struct object_id *ptree_oid;
 
-	if (parse_commit(commit))
+	if (parse_commit(the_repository, commit))
 		return error(_("could not parse commit %s"),
 			     oid_to_hex(&commit->object.oid));
 	if (commit->parents) {
 		struct commit *parent = commit->parents->item;
-		if (parse_commit(parent))
+		if (parse_commit(the_repository, parent))
 			return error(_("could not parse parent commit %s"),
 				oid_to_hex(&parent->object.oid));
 		ptree_oid = &parent->tree->object.oid;
@@ -1019,7 +1019,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
 		msg_file = NULL;
 		goto fast_forward_edit;
 	}
-	if (parent && parse_commit(parent) < 0)
+	if (parent && parse_commit(the_repository, parent) < 0)
 		/* TRANSLATORS: The first %s will be a "todo" command like
 		   "revert" or "pick", the second %s a SHA1. */
 		return error(_("%s: cannot parse parent commit %s"),
@@ -2774,7 +2774,7 @@ int skip_unnecessary_picks(void)
 			continue;
 		if (item->command != TODO_PICK)
 			break;
-		if (parse_commit(item->commit)) {
+		if (parse_commit(the_repository, item->commit)) {
 			todo_list_release(&todo_list);
 			return error(_("could not parse commit '%s'"),
 				oid_to_hex(&item->commit->object.oid));
@@ -2903,7 +2903,7 @@ int rearrange_squash(void)
 
 		item->commit->util = item;
 
-		parse_commit(item->commit);
+		parse_commit(the_repository, item->commit);
 		commit_buffer = get_commit_buffer(item->commit, NULL);
 		find_commit_subject(commit_buffer, &subject);
 		format_subject(&buf, subject, " ");
sha1_name.c +2 -2
index 45b7d6be91..43fe20b927 100644
@@ -850,7 +850,7 @@ static int get_parent(const char *name, int len,
 	if (ret)
 		return ret;
 	commit = lookup_commit_reference(the_repository, &oid);
-	if (parse_commit(commit))
+	if (parse_commit(the_repository, commit))
 		return -1;
 	if (!idx) {
 		oidcpy(result, &commit->object.oid);
@@ -882,7 +882,7 @@ static int get_nth_ancestor(const char *name, int len,
 		return -1;
 
 	while (generation--) {
-		if (parse_commit(commit) || !commit->parents)
+		if (parse_commit(the_repository, commit) || !commit->parents)
 			return -1;
 		commit = commit->parents->item;
 	}
shallow.c +2 -2
index 004f99d4e2..254c1a397a 100644
@@ -194,7 +194,7 @@ struct commit_list *get_shallow_commits_by_rev_list(int ac, const char **av,
 		struct commit *c = p->item;
 		struct commit_list *parent;
 
-		if (parse_commit(c))
+		if (parse_commit(the_repository, c))
 			die("unable to parse commit %s",
 			    oid_to_hex(&c->object.oid));
 
@@ -515,7 +515,7 @@ static void paint_down(struct paint_info *info, const struct object_id *oid,
 		if (c->object.flags & BOTTOM)
 			continue;
 
-		if (parse_commit(c))
+		if (parse_commit(the_repository, c))
 			die("unable to parse commit %s",
 			    oid_to_hex(&c->object.oid));
 
tree.c +1 -1
index 07cea88450..1635a01794 100644
@@ -106,7 +106,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
 				    oid_to_hex(entry.oid),
 				    base->buf, entry.path);
 
-			if (parse_commit(commit))
+			if (parse_commit(the_repository, commit))
 				die("Invalid commit %s in submodule path %s%s",
 				    oid_to_hex(entry.oid),
 				    base->buf, entry.path);
walker.c +1 -1
index b96e00a8f1..6efaf087df 100644
@@ -76,7 +76,7 @@ static struct commit_list *complete = NULL;
 
 static int process_commit(struct walker *walker, struct commit *commit)
 {
-	if (parse_commit(commit))
+	if (parse_commit(the_repository, commit))
 		return -1;
 
 	while (complete && complete->item->date >= commit->date) {
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#179 lore raw

PATCH 145/194 commit: add repository argument to set_commit_buffer

In reply to Stefan Beller

Add a repository argument to allow callers of set_commit_buffer to be more specific about which repository to handle. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet.

As with the previous commits, use a macro to catch callers passing a repository other than the_repository at compile time.

The included coccinelle semantic patch will adapt any new callers in the diff produced by make coccicheck.

---
 blame.c  | 2 +-
 commit.c | 4 ++--
 commit.h | 3 ++-
 object.c | 2 +-
 4 files changed, 6 insertions(+), 5 deletions(-)
blame.c +1 -1
index ccd6a5097b..1cd39e7a17 100644
@@ -138,7 +138,7 @@ static void set_commit_buffer_from_strbuf(struct commit *c, struct strbuf *sb)
 {
 	size_t len;
 	void *buf = strbuf_detach(sb, &len);
-	set_commit_buffer(c, buf, len);
+	set_commit_buffer(the_repository, c, buf, len);
 }
 
 /*
commit.c +2 -2
index 49c8f76e41..5de78c73fd 100644
@@ -250,7 +250,7 @@ struct commit_buffer {
 define_commit_slab(buffer_slab, struct commit_buffer);
 static struct buffer_slab buffer_slab = COMMIT_SLAB_INIT(1, buffer_slab);
 
-void set_commit_buffer(struct commit *commit, void *buffer, unsigned long size)
+void set_commit_buffer_the_repository(struct commit *commit, void *buffer, unsigned long size)
 {
 	struct commit_buffer *v = buffer_slab_at(&buffer_slab, commit);
 	v->buffer = buffer;
@@ -408,7 +408,7 @@ int parse_commit_gently_the_repository(struct commit *item, int quiet_on_missing
 	}
 	ret = parse_commit_buffer(the_repository, item, buffer, size);
 	if (save_commit_buffer && !ret) {
-		set_commit_buffer(item, buffer, size);
+		set_commit_buffer(the_repository, item, buffer, size);
 		return 0;
 	}
 	free(buffer);
commit.h +2 -1
index 16203fb18c..d3ec52d1c1 100644
@@ -79,7 +79,8 @@ void parse_commit_or_die(struct commit *item);
  * Associate an object buffer with the commit. The ownership of the
  * memory is handed over to the commit, and must be free()-able.
  */
-void set_commit_buffer(struct commit *, void *buffer, unsigned long size);
+#define set_commit_buffer(r, c, b, s) set_commit_buffer_##r(c, b, s)
+void set_commit_buffer_the_repository(struct commit *, void *buffer, unsigned long size);
 
 /*
  * Get any cached object buffer associated with the commit. Returns NULL
object.c +1 -1
index db15de6623..7d848b5b7a 100644
@@ -215,7 +215,7 @@ struct object *parse_object_buffer_the_repository(const struct object_id *oid, e
 			if (parse_commit_buffer(the_repository, commit, buffer, size))
 				return NULL;
 			if (!get_cached_commit_buffer(commit, NULL)) {
-				set_commit_buffer(commit, buffer, size);
+				set_commit_buffer(the_repository, commit, buffer, size);
 				*eaten_p = 1;
 			}
 			obj = &commit->object;
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#180 lore raw

PATCH 146/194 commit: add repository argument to get_cached_commit_buffer

In reply to Stefan Beller

Add a repository argument to allow callers of get_cached_commit_buffer to be more specific about which repository to handle. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet.

As with the previous commits, use a macro to catch callers passing a repository other than the_repository at compile time.

---
 builtin/rev-list.c | 2 +-
 commit.c           | 4 ++--
 commit.h           | 3 ++-
 log-tree.c         | 2 +-
 object.c           | 2 +-
 pretty.c           | 2 +-
 6 files changed, 8 insertions(+), 7 deletions(-)
builtin/rev-list.c +1 -1
index 3c2ae454ea..e28e7426a5 100644
@@ -133,7 +133,7 @@ static void show_commit(struct commit *commit, void *data)
 	else
 		putchar('\n');
 
-	if (revs->verbose_header && get_cached_commit_buffer(commit, NULL)) {
+	if (revs->verbose_header && get_cached_commit_buffer(the_repository, commit, NULL)) {
 		struct strbuf buf = STRBUF_INIT;
 		struct pretty_print_context ctx = {0};
 		ctx.abbrev = revs->abbrev;
commit.c +2 -2
index 5de78c73fd..1863900824 100644
@@ -257,7 +257,7 @@ void set_commit_buffer_the_repository(struct commit *commit, void *buffer, unsig
 	v->size = size;
 }
 
-const void *get_cached_commit_buffer(const struct commit *commit, unsigned long *sizep)
+const void *get_cached_commit_buffer_the_repository(const struct commit *commit, unsigned long *sizep)
 {
 	struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
 	if (!v) {
@@ -272,7 +272,7 @@ const void *get_cached_commit_buffer(const struct commit *commit, unsigned long
 
 const void *get_commit_buffer(const struct commit *commit, unsigned long *sizep)
 {
-	const void *ret = get_cached_commit_buffer(commit, sizep);
+	const void *ret = get_cached_commit_buffer(the_repository, commit, sizep);
 	if (!ret) {
 		enum object_type type;
 		unsigned long size;
commit.h +2 -1
index d3ec52d1c1..bcecb23722 100644
@@ -86,7 +86,8 @@ void set_commit_buffer_the_repository(struct commit *, void *buffer, unsigned lo
  * Get any cached object buffer associated with the commit. Returns NULL
  * if none. The resulting memory should not be freed.
  */
-const void *get_cached_commit_buffer(const struct commit *, unsigned long *size);
+#define get_cached_commit_buffer(r, c, s) get_cached_commit_buffer_##r(c, s)
+const void *get_cached_commit_buffer_the_repository(const struct commit *, unsigned long *size);
 
 /*
  * Get the commit's object contents, either from cache or by reading the object
log-tree.c +1 -1
index 9fb333605b..c6d2883190 100644
@@ -661,7 +661,7 @@ void show_log(struct rev_info *opt)
 		show_mergetag(opt, commit);
 	}
 
-	if (!get_cached_commit_buffer(commit, NULL))
+	if (!get_cached_commit_buffer(the_repository, commit, NULL))
 		return;
 
 	if (opt->show_notes) {
object.c +1 -1
index 7d848b5b7a..c2268990dd 100644
@@ -214,7 +214,7 @@ struct object *parse_object_buffer_the_repository(const struct object_id *oid, e
 		if (commit) {
 			if (parse_commit_buffer(the_repository, commit, buffer, size))
 				return NULL;
-			if (!get_cached_commit_buffer(commit, NULL)) {
+			if (!get_cached_commit_buffer(the_repository, commit, NULL)) {
 				set_commit_buffer(the_repository, commit, buffer, size);
 				*eaten_p = 1;
 			}
pretty.c +1 -1
index 478af1a860..f82d30cd97 100644
@@ -630,7 +630,7 @@ const char *logmsg_reencode(const struct commit *commit,
 		 * the cached copy from get_commit_buffer, we need to duplicate it
 		 * to avoid munging the cached copy.
 		 */
-		if (msg == get_cached_commit_buffer(commit, NULL))
+		if (msg == get_cached_commit_buffer(the_repository, commit, NULL))
 			out = xstrdup(msg);
 		else
 			out = (char *)msg;
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#181 lore raw

PATCH 147/194 commit: add repository argument to unuse_commit_buffer

In reply to Stefan Beller

Add a repository argument to allow callers of unuse_commit_buffer to be more specific about which repository to handle. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet.

As with the previous commits, use a macro to catch callers passing a repository other than the_repository at compile time.

The included coccinelle semantic patch will adapt any new callers in the diff produced by make coccicheck.

---
 builtin/am.c                          |  2 +-
 builtin/blame.c                       |  4 ++--
 builtin/fast-export.c                 |  2 +-
 builtin/fmt-merge-msg.c               |  2 +-
 builtin/log.c                         |  2 +-
 builtin/replace.c                     |  2 +-
 builtin/reset.c                       |  2 +-
 commit.c                              |  8 ++++----
 commit.h                              |  3 ++-
 contrib/coccinelle/object_store.cocci |  7 +++++++
 fsck.c                                |  2 +-
 merge-recursive.c                     |  2 +-
 notes-merge.c                         |  2 +-
 pretty.c                              |  6 +++---
 revision.c                            |  2 +-
 sequencer.c                           | 16 +++++++++-------
 sha1_name.c                           |  2 +-
 17 files changed, 38 insertions(+), 28 deletions(-)
builtin/am.c +1 -1
index 83bc22649e..7072ec78cb 100644
@@ -1358,7 +1358,7 @@ static void get_commit_info(struct am_state *state, struct commit *commit)
 		die(_("unable to parse commit %s"), oid_to_hex(&commit->object.oid));
 	state->msg = xstrdup(msg + 2);
 	state->msg_len = strlen(state->msg);
-	unuse_commit_buffer(commit, buffer);
+	unuse_commit_buffer(the_repository, commit, buffer);
 }
 
 /**
builtin/blame.c +2 -2
index 815b0c75ed..956df42c67 100644
@@ -192,7 +192,7 @@ static void get_commit_info(struct commit *commit,
 		    &ret->author_time, &ret->author_tz);
 
 	if (!detailed) {
-		unuse_commit_buffer(commit, message);
+		unuse_commit_buffer(the_repository, commit, message);
 		return;
 	}
 
@@ -206,7 +206,7 @@ static void get_commit_info(struct commit *commit,
 	else
 		strbuf_addf(&ret->summary, "(%s)", oid_to_hex(&commit->object.oid));
 
-	unuse_commit_buffer(commit, message);
+	unuse_commit_buffer(the_repository, commit, message);
 }
 
 /*
builtin/fast-export.c +1 -1
index 1562ac4927..80853bb91a 100644
@@ -618,7 +618,7 @@ static void handle_commit(struct commit *commit, struct rev_info *rev,
 			  ? strlen(message) : 0),
 	       reencoded ? reencoded : message ? message : "");
 	free(reencoded);
-	unuse_commit_buffer(commit, commit_buffer);
+	unuse_commit_buffer(the_repository, commit, commit_buffer);
 
 	for (i = 0, p = commit->parents; p; p = p->next) {
 		int mark = get_object_mark(&p->item->object);
builtin/fmt-merge-msg.c +1 -1
index ac98556a1d..c54f045ccd 100644
@@ -263,7 +263,7 @@ static void record_person(int which, struct string_list *people,
 {
 	const char *buffer = get_commit_buffer(commit, NULL);
 	record_person_from_buf(which, people, buffer);
-	unuse_commit_buffer(commit, buffer);
+	unuse_commit_buffer(the_repository, commit, buffer);
 }
 
 static int cmp_string_list_util_as_integral(const void *a_, const void *b_)
builtin/log.c +1 -1
index fce7b07df4..7080c5f776 100644
@@ -1025,7 +1025,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
 		const char *buf = get_commit_buffer(list[i], NULL);
 		if (has_non_ascii(buf))
 			need_8bit_cte = 1;
-		unuse_commit_buffer(list[i], buf);
+		unuse_commit_buffer(the_repository, list[i], buf);
 	}
 
 	if (!branch_name)
builtin/replace.c +1 -1
index d1a939c17b..1a92c0082a 100644
@@ -403,7 +403,7 @@ static int create_graft(int argc, const char **argv, int force)
 
 	buffer = get_commit_buffer(commit, &size);
 	strbuf_add(&buf, buffer, size);
-	unuse_commit_buffer(commit, buffer);
+	unuse_commit_buffer(the_repository, commit, buffer);
 
 	replace_parents(&buf, argc - 1, &argv[1]);
 
builtin/reset.c +1 -1
index ea600bc62a..891dd77a5f 100644
@@ -123,7 +123,7 @@ static void print_new_head_line(struct commit *commit)
 	}
 	else
 		printf("\n");
-	unuse_commit_buffer(commit, msg);
+	unuse_commit_buffer(the_repository, commit, msg);
 }
 
 static void update_index_from_diff(struct diff_queue_struct *q,
commit.c +4 -4
index 1863900824..fa578a2d22 100644
@@ -290,7 +290,7 @@ const void *get_commit_buffer(const struct commit *commit, unsigned long *sizep)
 	return ret;
 }
 
-void unuse_commit_buffer(const struct commit *commit, const void *buffer)
+void unuse_commit_buffer_the_repository(const struct commit *commit, const void *buffer)
 {
 	struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
 	if (!(v && v->buffer == buffer))
@@ -630,7 +630,7 @@ static void record_author_date(struct author_date_slab *author_date,
 	*(author_date_slab_at(author_date, commit)) = date;
 
 fail_exit:
-	unuse_commit_buffer(commit, buffer);
+	unuse_commit_buffer(the_repository, commit, buffer);
 }
 
 static int compare_commits_by_author_date(const void *a_, const void *b_,
@@ -1186,7 +1186,7 @@ int parse_signed_commit(const struct commit *commit,
 		}
 		line = next;
 	}
-	unuse_commit_buffer(commit, buffer);
+	unuse_commit_buffer(the_repository, commit, buffer);
 	return saw_signature;
 }
 
@@ -1314,7 +1314,7 @@ struct commit_extra_header *read_commit_extra_headers(struct commit *commit,
 	unsigned long size;
 	const char *buffer = get_commit_buffer(commit, &size);
 	extra = read_commit_extra_header_lines(buffer, size, exclude);
-	unuse_commit_buffer(commit, buffer);
+	unuse_commit_buffer(the_repository, commit, buffer);
 	return extra;
 }
 
commit.h +2 -1
index bcecb23722..85dd52d1bf 100644
@@ -102,7 +102,8 @@ const void *get_commit_buffer(const struct commit *, unsigned long *size);
  * from an earlier call to get_commit_buffer.  The buffer may or may not be
  * freed by this call; callers should not access the memory afterwards.
  */
-void unuse_commit_buffer(const struct commit *, const void *buffer);
+#define unuse_commit_buffer(r, c, b) unuse_commit_buffer_##r(c, b)
+void unuse_commit_buffer_the_repository(const struct commit *, const void *buffer);
 
 /*
  * Free any cached object buffer associated with the commit.
contrib/coccinelle/object_store.cocci +7 -0
index 3ffb34d5b5..b56ebef884 100644
@@ -60,3 +60,10 @@ expression E;
 + the_repository,
  E)
 
+@@
+expression E;
+expression F;
+@@
+ unuse_commit_buffer(
++the_repository,
+ E, F)
fsck.c +1 -1
index 494b4e3b30..3155b77348 100644
@@ -794,7 +794,7 @@ static int fsck_commit(struct commit *commit, const char *data,
 	const char *buffer = data ?  data : get_commit_buffer(commit, &size);
 	int ret = fsck_commit_buffer(commit, buffer, size, options);
 	if (!data)
-		unuse_commit_buffer(commit, buffer);
+		unuse_commit_buffer(the_repository, commit, buffer);
 	return ret;
 }
 
merge-recursive.c +1 -1
index 719fa58ab1..c749785b0b 100644
@@ -241,7 +241,7 @@ static void output_commit_title(struct merge_options *o, struct commit *commit)
 			int len = find_commit_subject(msg, &title);
 			if (len)
 				strbuf_addf(&o->obuf, "%.*s\n", len, title);
-			unuse_commit_buffer(commit, msg);
+			unuse_commit_buffer(the_repository, commit, msg);
 		}
 	}
 	flush_output(o);
notes-merge.c +1 -1
index 02729fc474..df66d96811 100644
@@ -722,7 +722,7 @@ int notes_merge_commit(struct notes_merge_options *o,
 
 	create_notes_commit(partial_tree, partial_commit->parents,
 			    msg, strlen(msg), result_oid->hash);
-	unuse_commit_buffer(partial_commit, buffer);
+	unuse_commit_buffer(the_repository, partial_commit, buffer);
 	if (o->verbosity >= 4)
 		printf("Finalized notes merge commit: %s\n",
 			oid_to_hex(result_oid));
pretty.c +3 -3
index f82d30cd97..9a7f19f8c7 100644
@@ -644,7 +644,7 @@ const char *logmsg_reencode(const struct commit *commit,
 		 */
 		out = reencode_string(msg, output_encoding, use_encoding);
 		if (out)
-			unuse_commit_buffer(commit, msg);
+			unuse_commit_buffer(the_repository, commit, msg);
 	}
 
 	/*
@@ -1545,7 +1545,7 @@ void format_commit_message(const struct commit *commit,
 	}
 
 	free(context.commit_encoding);
-	unuse_commit_buffer(commit, context.message);
+	unuse_commit_buffer(the_repository, commit, context.message);
 }
 
 static void pp_header(struct pretty_print_context *pp,
@@ -1858,7 +1858,7 @@ void pretty_print_commit(struct pretty_print_context *pp,
 	if (cmit_fmt_is_mail(pp->fmt) && sb->len <= beginning_of_body)
 		strbuf_addch(sb, '\n');
 
-	unuse_commit_buffer(commit, reencoded);
+	unuse_commit_buffer(the_repository, commit, reencoded);
 }
 
 void pp_commit_easy(enum cmit_fmt fmt, const struct commit *commit,
revision.c +1 -1
index 56c1a9a78f..754d7b438e 100644
@@ -3037,7 +3037,7 @@ static int commit_match(struct commit *commit, struct rev_info *opt)
 		retval = grep_buffer(&opt->grep_filter,
 				     (char *)message, strlen(message));
 	strbuf_release(&buf);
-	unuse_commit_buffer(commit, message);
+	unuse_commit_buffer(the_repository, commit, message);
 	return opt->invert_grep ? !retval : retval;
 }
 
sequencer.c +9 -7
index e94ed30965..fbbe5267f7 100644
@@ -260,7 +260,7 @@ static void free_message(struct commit *commit, struct commit_message *msg)
 	free(msg->parent_label);
 	free(msg->label);
 	free(msg->subject);
-	unuse_commit_buffer(commit, msg->message);
+	unuse_commit_buffer(the_repository, commit, msg->message);
 }
 
 static void print_advice(int show_hint, struct replay_opts *opts)
@@ -865,7 +865,8 @@ static int update_squash_messages(enum todo_command command,
 		find_commit_subject(head_message, &body);
 		if (write_message(body, strlen(body),
 				  rebase_path_fixup_msg(), 0)) {
-			unuse_commit_buffer(head_commit, head_message);
+			unuse_commit_buffer(the_repository, head_commit,
+					    head_message);
 			return error(_("cannot write '%s'"),
 				     rebase_path_fixup_msg());
 		}
@@ -879,7 +880,7 @@ static int update_squash_messages(enum todo_command command,
 		strbuf_addstr(&buf, "\n\n");
 		strbuf_addstr(&buf, body);
 
-		unuse_commit_buffer(head_commit, head_message);
+		unuse_commit_buffer(the_repository, head_commit, head_message);
 	}
 
 	if (!(message = get_commit_buffer(commit, NULL)))
@@ -901,7 +902,7 @@ static int update_squash_messages(enum todo_command command,
 		strbuf_add_commented_lines(&buf, body, strlen(body));
 	} else
 		return error(_("unknown command: %d"), command);
-	unuse_commit_buffer(commit, message);
+	unuse_commit_buffer(the_repository, commit, message);
 
 	res = write_message(buf.buf, buf.len, rebase_path_squash_msg(), 0);
 	strbuf_release(&buf);
@@ -1560,7 +1561,7 @@ static int walk_revs_populate_todo(struct todo_list *todo_list,
 		subject_len = find_commit_subject(commit_buffer, &subject);
 		strbuf_addf(&todo_list->buf, "%s %s %.*s\n", command_string,
 			short_commit_name(commit), subject_len, subject);
-		unuse_commit_buffer(commit, commit_buffer);
+		unuse_commit_buffer(the_repository, commit, commit_buffer);
 	}
 	return 0;
 }
@@ -1818,7 +1819,7 @@ static int make_patch(struct commit *commit, struct replay_opts *opts)
 		const char *commit_buffer = get_commit_buffer(commit, NULL);
 		find_commit_subject(commit_buffer, &subject);
 		res |= write_message(subject, strlen(subject), buf.buf, 1);
-		unuse_commit_buffer(commit, commit_buffer);
+		unuse_commit_buffer(the_repository, commit, commit_buffer);
 	}
 	strbuf_release(&buf);
 
@@ -2908,7 +2909,8 @@ int rearrange_squash(void)
 		find_commit_subject(commit_buffer, &subject);
 		format_subject(&buf, subject, " ");
 		subject = subjects[i] = strbuf_detach(&buf, &subject_len);
-		unuse_commit_buffer(item->commit, commit_buffer);
+		unuse_commit_buffer(the_repository, item->commit,
+				    commit_buffer);
 		if ((skip_prefix(subject, "fixup! ", &p) ||
 		     skip_prefix(subject, "squash! ", &p))) {
 			struct commit *commit2;
sha1_name.c +1 -1
index 43fe20b927..a60eaf14d2 100644
@@ -1153,7 +1153,7 @@ static int get_oid_oneline(const char *prefix, struct object_id *oid,
 		buf = get_commit_buffer(commit, NULL);
 		p = strstr(buf, "\n\n");
 		matches = negative ^ (p && !regexec(&regex, p + 2, 0, NULL, 0));
-		unuse_commit_buffer(commit, buf);
+		unuse_commit_buffer(the_repository, commit, buf);
 
 		if (matches) {
 			oidcpy(oid, &commit->object.oid);
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#182 lore raw

PATCH 148/194 commit: add repository argument to free_commit_buffer

In reply to Stefan Beller

Add a repository argument to allow callers of free_commit_buffer to be more specific about which repository to handle. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet.

As with the previous commits, use a macro to catch callers passing a repository other than the_repository at compile time.

---
 builtin/fsck.c     | 2 +-
 builtin/log.c      | 4 ++--
 builtin/rev-list.c | 2 +-
 commit.c           | 2 +-
 commit.h           | 3 ++-
 5 files changed, 7 insertions(+), 6 deletions(-)
builtin/fsck.c +1 -1
index 2e8b298384..01c612f75f 100644
@@ -365,7 +365,7 @@ static int fsck_obj(struct object *obj)
 	if (obj->type == OBJ_TREE)
 		free_tree_buffer((struct tree *)obj);
 	if (obj->type == OBJ_COMMIT)
-		free_commit_buffer((struct commit *)obj);
+		free_commit_buffer(the_repository, (struct commit *)obj);
 	return err;
 }
 
builtin/log.c +2 -2
index 7080c5f776..12426e685f 100644
@@ -386,7 +386,7 @@ static int cmd_log_walk(struct rev_info *rev)
 			 * We may show a given commit multiple times when
 			 * walking the reflogs.
 			 */
-			free_commit_buffer(commit);
+			free_commit_buffer(the_repository, commit);
 			free_commit_list(commit->parents);
 			commit->parents = NULL;
 		}
@@ -1813,7 +1813,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 		    open_next_file(rev.numbered_files ? NULL : commit, NULL, &rev, quiet))
 			die(_("Failed to create output files"));
 		shown = log_tree_commit(&rev, commit);
-		free_commit_buffer(commit);
+		free_commit_buffer(the_repository, commit);
 
 		/* We put one extra blank line between formatted
 		 * patches and this flag is used by log-tree code
builtin/rev-list.c +1 -1
index e28e7426a5..142ba35fdb 100644
@@ -193,7 +193,7 @@ static void finish_commit(struct commit *commit, void *data)
 		free_commit_list(commit->parents);
 		commit->parents = NULL;
 	}
-	free_commit_buffer(commit);
+	free_commit_buffer(the_repository, commit);
 }
 
 static inline void finish_object__ma(struct object *obj)
commit.c +1 -1
index fa578a2d22..8ef8619dec 100644
@@ -297,7 +297,7 @@ void unuse_commit_buffer_the_repository(const struct commit *commit, const void
 		free((void *)buffer);
 }
 
-void free_commit_buffer(struct commit *commit)
+void free_commit_buffer_the_repository(struct commit *commit)
 {
 	struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
 	if (v) {
commit.h +2 -1
index 85dd52d1bf..8892989b1d 100644
@@ -108,7 +108,8 @@ void unuse_commit_buffer_the_repository(const struct commit *, const void *buffe
 /*
  * Free any cached object buffer associated with the commit.
  */
-void free_commit_buffer(struct commit *);
+#define free_commit_buffer(r, c) free_commit_buffer_##r(c)
+void free_commit_buffer_the_repository(struct commit *);
 
 /*
  * Disassociate any cached object buffer from the commit, but do not free it.
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#183 lore raw

PATCH 149/194 commit: allow commit buffer functions to handle arbitrary repositories

In reply to Stefan Beller
---
 builtin/index-pack.c |  2 +-
 commit.c             | 33 ++++++++++++++++++++++-----------
 commit.h             | 17 ++++++++---------
 object.h             |  6 +++++-
 repository.c         |  6 ++++++
 5 files changed, 42 insertions(+), 22 deletions(-)
builtin/index-pack.c +1 -1
index f78e9d2e65..b2b6021ad3 100644
@@ -870,7 +870,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
 			}
 			if (obj->type == OBJ_COMMIT) {
 				struct commit *commit = (struct commit *) obj;
-				if (detach_commit_buffer(commit, NULL) != data)
+				if (detach_commit_buffer(the_repository, commit, NULL) != data)
 					die("BUG: parse_object_buffer transmogrified our buffer");
 			}
 			obj->flags |= FLAG_CHECKED;
commit.c +22 -11
index 8ef8619dec..a5e570f057 100644
@@ -248,18 +248,29 @@ struct commit_buffer {
 	unsigned long size;
 };
 define_commit_slab(buffer_slab, struct commit_buffer);
-static struct buffer_slab buffer_slab = COMMIT_SLAB_INIT(1, buffer_slab);
+struct buffer_slab the_repository_buffer_slab = COMMIT_SLAB_INIT(1, the_repository_buffer_slab);
 
-void set_commit_buffer_the_repository(struct commit *commit, void *buffer, unsigned long size)
+void alloc_buffer_slab(struct repository *r)
 {
-	struct commit_buffer *v = buffer_slab_at(&buffer_slab, commit);
+	r->parsed_objects.buffer_slab = xcalloc(1, sizeof(struct buffer_slab));
+	init_buffer_slab(r->parsed_objects.buffer_slab);
+}
+
+void free_commit_slab(struct repository *r)
+{
+	free(r->parsed_objects.buffer_slab);
+}
+
+void set_commit_buffer(struct repository *r, struct commit *commit, void *buffer, unsigned long size)
+{
+	struct commit_buffer *v = buffer_slab_at(r->parsed_objects.buffer_slab, commit);
 	v->buffer = buffer;
 	v->size = size;
 }
 
-const void *get_cached_commit_buffer_the_repository(const struct commit *commit, unsigned long *sizep)
+const void *get_cached_commit_buffer(struct repository *r, const struct commit *commit, unsigned long *sizep)
 {
-	struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
+	struct commit_buffer *v = buffer_slab_peek(r->parsed_objects.buffer_slab, commit);
 	if (!v) {
 		if (sizep)
 			*sizep = 0;
@@ -290,25 +301,25 @@ const void *get_commit_buffer(const struct commit *commit, unsigned long *sizep)
 	return ret;
 }
 
-void unuse_commit_buffer_the_repository(const struct commit *commit, const void *buffer)
+void unuse_commit_buffer(struct repository *r, const struct commit *commit, const void *buffer)
 {
-	struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
+	struct commit_buffer *v = buffer_slab_peek(r->parsed_objects.buffer_slab, commit);
 	if (!(v && v->buffer == buffer))
 		free((void *)buffer);
 }
 
-void free_commit_buffer_the_repository(struct commit *commit)
+void free_commit_buffer(struct repository *r, struct commit *commit)
 {
-	struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
+	struct commit_buffer *v = buffer_slab_peek(r->parsed_objects.buffer_slab, commit);
 	if (v) {
 		FREE_AND_NULL(v->buffer);
 		v->size = 0;
 	}
 }
 
-const void *detach_commit_buffer(struct commit *commit, unsigned long *sizep)
+const void *detach_commit_buffer(struct repository *r, struct commit *commit, unsigned long *sizep)
 {
-	struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
+	struct commit_buffer *v = buffer_slab_peek(r->parsed_objects.buffer_slab, commit);
 	void *ret;
 
 	if (!v) {
commit.h +8 -9
index 8892989b1d..0d3ccd7279 100644
@@ -75,19 +75,20 @@ static inline int parse_commit_the_repository(struct commit *item)
 }
 void parse_commit_or_die(struct commit *item);
 
+extern void alloc_buffer_slab(struct repository *r);
+extern void free_commit_slab(struct repository *r);
+
 /*
  * Associate an object buffer with the commit. The ownership of the
  * memory is handed over to the commit, and must be free()-able.
  */
-#define set_commit_buffer(r, c, b, s) set_commit_buffer_##r(c, b, s)
-void set_commit_buffer_the_repository(struct commit *, void *buffer, unsigned long size);
+void set_commit_buffer(struct repository *r, struct commit *, void *buffer, unsigned long size);
 
 /*
  * Get any cached object buffer associated with the commit. Returns NULL
  * if none. The resulting memory should not be freed.
  */
-#define get_cached_commit_buffer(r, c, s) get_cached_commit_buffer_##r(c, s)
-const void *get_cached_commit_buffer_the_repository(const struct commit *, unsigned long *size);
+const void *get_cached_commit_buffer(struct repository *r, const struct commit *, unsigned long *size);
 
 /*
  * Get the commit's object contents, either from cache or by reading the object
@@ -102,20 +103,18 @@ const void *get_commit_buffer(const struct commit *, unsigned long *size);
  * from an earlier call to get_commit_buffer.  The buffer may or may not be
  * freed by this call; callers should not access the memory afterwards.
  */
-#define unuse_commit_buffer(r, c, b) unuse_commit_buffer_##r(c, b)
-void unuse_commit_buffer_the_repository(const struct commit *, const void *buffer);
+void unuse_commit_buffer(struct repository *r, const struct commit *, const void *buffer);
 
 /*
  * Free any cached object buffer associated with the commit.
  */
-#define free_commit_buffer(r, c) free_commit_buffer_##r(c)
-void free_commit_buffer_the_repository(struct commit *);
+void free_commit_buffer(struct repository *r, struct commit *);
 
 /*
  * Disassociate any cached object buffer from the commit, but do not free it.
  * The buffer (or NULL, if none) is returned.
  */
-const void *detach_commit_buffer(struct commit *, unsigned long *sizep);
+const void *detach_commit_buffer(struct repository *r, struct commit *, unsigned long *sizep);
 
 /* Find beginning and length of commit subject. */
 int find_commit_subject(const char *commit_buffer, const char **subject);
object.h +5 -1
index 513f5eaef4..65b5326e0f 100644
@@ -5,6 +5,8 @@ struct object_parser {
 	struct object **obj_hash;
 	int nr_objs, obj_hash_size;
 
+	struct buffer_slab *buffer_slab;
+
 	/* parent substitutions from .git/info/grafts and .git/shallow */
 	struct commit_graft **grafts;
 	int grafts_alloc, grafts_nr;
@@ -17,12 +19,14 @@ struct object_parser {
 	unsigned commit_count;
 };
 
+extern struct buffer_slab the_repository_buffer_slab;
 extern struct alloc_state the_repository_blob_state;
 extern struct alloc_state the_repository_tree_state;
 extern struct alloc_state the_repository_commit_state;
 extern struct alloc_state the_repository_tag_state;
 extern struct alloc_state the_repository_object_state;
-#define OBJECT_PARSER_INIT { NULL, 0, 0, NULL, 0, 0, \
+#define OBJECT_PARSER_INIT { NULL, 0, 0, &the_repository_buffer_slab, \
+	NULL, 0, 0, \
 	&the_repository_blob_state, \
 	&the_repository_tree_state, \
 	&the_repository_commit_state, \
repository.c +6 -0
index f76f0ddd37..0cf019bb9b 100644
@@ -2,6 +2,7 @@
 #include "repository.h"
 #include "object-store.h"
 #include "config.h"
+#include "commit.h"
 #include "submodule-config.h"
 
 /* The main repository */
@@ -187,6 +188,8 @@ int repo_init(struct repository *repo, const char *gitdir, const char *worktree)
 	ALLOC_GROW(open_repos, open_repos_nr + 1, open_repos_alloc);
 	open_repos[open_repos_nr++] = repo;
 
+	alloc_buffer_slab(repo);
+
 	return 0;
 
 error:
@@ -249,6 +252,9 @@ int repo_submodule_init(struct repository *submodule,
 void repo_free(struct repository *repo)
 {
 	int i;
+
+	free_commit_slab(repo);
+
 	for (i = 0; i < open_repos_nr; i++) {
 		if (open_repos[i] != repo)
 			continue;
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#184 lore raw

PATCH 150/194 tree: allow lookup_tree to handle arbitrary repositories

In reply to Stefan Beller
---
 tree.c | 10 +++++-----
 tree.h |  3 +--
 2 files changed, 6 insertions(+), 7 deletions(-)
tree.c +5 -5
index 1635a01794..e8150ba54b 100644
@@ -194,13 +194,13 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match,
 	return 0;
 }
 
-struct tree *lookup_tree_the_repository(const struct object_id *oid)
+struct tree *lookup_tree(struct repository *r, const struct object_id *oid)
 {
-	struct object *obj = lookup_object(the_repository, oid->hash);
+	struct object *obj = lookup_object(r, oid->hash);
 	if (!obj)
-		return create_object(the_repository, oid->hash,
-				     alloc_tree_node(the_repository));
-	return object_as_type(the_repository, obj, OBJ_TREE, 0);
+		return create_object(r, oid->hash,
+				     alloc_tree_node(r));
+	return object_as_type(r, obj, OBJ_TREE, 0);
 }
 
 int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size)
tree.h +1 -2
index 8195db473f..5e7988d390 100644
@@ -12,8 +12,7 @@ struct tree {
 	unsigned long size;
 };
 
-#define lookup_tree(r, oid) lookup_tree_##r(oid)
-struct tree *lookup_tree_the_repository(const struct object_id *oid);
+struct tree *lookup_tree(struct repository *r, const struct object_id *oid);
 
 int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size);
 
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#185 lore raw

PATCH 151/194 cache: convert get_graft_file to handle arbitrary repositories

In reply to Stefan Beller
---
 cache.h       | 2 +-
 commit.c      | 2 +-
 environment.c | 6 +++---
 3 files changed, 5 insertions(+), 5 deletions(-)
cache.h +1 -1
index ee01daf130..a74a10fe1f 100644
@@ -489,7 +489,7 @@ extern const char *get_git_dir(void);
 extern const char *get_git_common_dir(void);
 extern char *get_object_directory(void);
 extern char *get_index_file(void);
-extern char *get_graft_file(void);
+extern char *get_graft_file(struct repository *r);
 extern int set_git_dir(const char *path);
 extern int get_common_dir_noenv(struct strbuf *sb, const char *gitdir);
 extern int get_common_dir(struct strbuf *sb, const char *gitdir);
commit.c +1 -1
index a5e570f057..32eda5f7c9 100644
@@ -205,7 +205,7 @@ static void prepare_commit_graft_the_repository(void)
 
 	if (commit_graft_prepared)
 		return;
-	graft_file = get_graft_file();
+	graft_file = get_graft_file(the_repository);
 	read_graft_file(the_repository, graft_file);
 	/* make sure shallows are read */
 	is_repository_shallow();
environment.c +3 -3
index 249516cf6b..972ade61d8 100644
@@ -287,11 +287,11 @@ char *get_index_file(void)
 	return the_repository->index_file;
 }
 
-char *get_graft_file(void)
+char *get_graft_file(struct repository *r)
 {
-	if (!the_repository->graft_file)
+	if (!r->graft_file)
 		BUG("git environment hasn't been setup");
-	return the_repository->graft_file;
+	return r->graft_file;
 }
 
 int set_git_dir(const char *path)
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#186 lore raw

PATCH 152/194 shallow: add repository argument to set_alternate_shallow_file

In reply to Stefan Beller
---
 commit.h      | 3 ++-
 environment.c | 2 +-
 git.c         | 2 +-
 shallow.c     | 2 +-
 4 files changed, 5 insertions(+), 4 deletions(-)
commit.h +2 -1
index 0d3ccd7279..7ef21a0fbf 100644
@@ -204,7 +204,8 @@ extern struct commit_list *get_shallow_commits(struct object_array *heads,
 		int depth, int shallow_flag, int not_shallow_flag);
 extern struct commit_list *get_shallow_commits_by_rev_list(
 		int ac, const char **av, int shallow_flag, int not_shallow_flag);
-extern void set_alternate_shallow_file(const char *path, int override);
+#define set_alternate_shallow_file(r, p, o) set_alternate_shallow_file_##r(p, o)
+extern void set_alternate_shallow_file_the_repository(const char *path, int override);
 extern int write_shallow_commits(struct strbuf *out, int use_pack_protocol,
 				 const struct oid_array *extra);
 extern void setup_alternate_shallow(struct lock_file *shallow_lock,
environment.c +1 -1
index 972ade61d8..d3915a5a0a 100644
@@ -160,7 +160,7 @@ void setup_git_env(void)
 	namespace = expand_namespace(getenv(GIT_NAMESPACE_ENVIRONMENT));
 	shallow_file = getenv(GIT_SHALLOW_FILE_ENVIRONMENT);
 	if (shallow_file)
-		set_alternate_shallow_file(shallow_file, 0);
+		set_alternate_shallow_file(the_repository, shallow_file, 0);
 }
 
 int is_bare_repository(void)
git.c +1 -1
index c870b9719c..6c5ef91a0d 100644
@@ -189,7 +189,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
 		} else if (!strcmp(cmd, "--shallow-file")) {
 			(*argv)++;
 			(*argc)--;
-			set_alternate_shallow_file((*argv)[0], 1);
+			set_alternate_shallow_file(the_repository, (*argv)[0], 1);
 			if (envchanged)
 				*envchanged = 1;
 		} else if (!strcmp(cmd, "-C")) {
shallow.c +1 -1
index 254c1a397a..c26e99fedd 100644
@@ -19,7 +19,7 @@ static int is_shallow = -1;
 static struct stat_validity shallow_stat;
 static char *alternate_shallow_file;
 
-void set_alternate_shallow_file(const char *path, int override)
+void set_alternate_shallow_file_the_repository(const char *path, int override)
 {
 	if (is_shallow != -1)
 		die("BUG: is_repository_shallow must not be called before set_alternate_shallow_file");
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#187 lore raw

PATCH 153/194 shallow: add repository argument to register_shallow

In reply to Stefan Beller
---
 builtin/pack-objects.c | 2 +-
 builtin/receive-pack.c | 2 +-
 commit.h               | 3 ++-
 fetch-pack.c           | 2 +-
 shallow.c              | 4 ++--
 upload-pack.c          | 7 ++++---
 6 files changed, 11 insertions(+), 9 deletions(-)
builtin/pack-objects.c +1 -1
index 77275058e4..a16ecc3fe0 100644
@@ -2864,7 +2864,7 @@ static void get_object_list(int ac, const char **av)
 				struct object_id oid;
 				if (get_oid_hex(line + 10, &oid))
 					die("not an SHA-1 '%s'", line + 10);
-				register_shallow(&oid);
+				register_shallow(the_repository, &oid);
 				use_bitmap_index = 0;
 				continue;
 			}
builtin/receive-pack.c +1 -1
index 22d805a8ff..7d00f0bad6 100644
@@ -905,7 +905,7 @@ static int update_shallow_ref(struct command *cmd, struct shallow_info *si)
 	 * not lose these new roots..
 	 */
 	for (i = 0; i < extra.nr; i++)
-		register_shallow(&extra.oid[i]);
+		register_shallow(the_repository, &extra.oid[i]);
 
 	si->shallow_ref[cmd->index] = 0;
 	oid_array_clear(&extra);
commit.h +2 -1
index 7ef21a0fbf..0c854d3679 100644
@@ -196,7 +196,8 @@ extern struct commit_list *get_merge_bases_many_dirty(struct commit *one, int n,
 
 struct oid_array;
 struct ref;
-extern int register_shallow(const struct object_id *oid);
+#define register_shallow(r, o) register_shallow_##r(o);
+extern int register_shallow_the_repository(const struct object_id *oid);
 extern int unregister_shallow(const struct object_id *oid);
 extern int for_each_commit_graft(each_commit_graft_fn, void *);
 extern int is_repository_shallow(void);
fetch-pack.c +1 -1
index e8b1fc0d1b..1cd738fd62 100644
@@ -425,7 +425,7 @@ static int find_common(struct fetch_pack_args *args,
 			if (skip_prefix(line, "shallow ", &arg)) {
 				if (get_oid_hex(arg, &oid))
 					die(_("invalid shallow line: %s"), line);
-				register_shallow(&oid);
+				register_shallow(the_repository, &oid);
 				continue;
 			}
 			if (skip_prefix(line, "unshallow ", &arg)) {
shallow.c +2 -2
index c26e99fedd..67feeb3a4f 100644
@@ -29,7 +29,7 @@ void set_alternate_shallow_file_the_repository(const char *path, int override)
 	alternate_shallow_file = xstrdup_or_null(path);
 }
 
-int register_shallow(const struct object_id *oid)
+int register_shallow_the_repository(const struct object_id *oid)
 {
 	struct commit_graft *graft =
 		xmalloc(sizeof(struct commit_graft));
@@ -70,7 +70,7 @@ int is_repository_shallow(void)
 		struct object_id oid;
 		if (get_oid_hex(buf, &oid))
 			die("bad shallow line: %s", buf);
-		register_shallow(&oid);
+		register_shallow(the_repository, &oid);
 	}
 	fclose(fp);
 	return is_shallow;
upload-pack.c +4 -3
index 9c003553f8..ed2d394ace 100644
@@ -646,7 +646,7 @@ static void send_shallow(struct commit_list *result)
 		if (!(object->flags & (CLIENT_SHALLOW|NOT_SHALLOW))) {
 			packet_write_fmt(1, "shallow %s",
 					 oid_to_hex(&object->oid));
-			register_shallow(&object->oid);
+			register_shallow(the_repository, &object->oid);
 			shallow_nr++;
 		}
 		result = result->next;
@@ -683,7 +683,7 @@ static void send_unshallow(const struct object_array *shallows)
 			add_object_array(object, NULL, &extra_edge_obj);
 		}
 		/* make sure commit traversal conforms to client */
-		register_shallow(&object->oid);
+		register_shallow(the_repository, &object->oid);
 	}
 }
 
@@ -887,7 +887,8 @@ static void receive_needs(void)
 		if (shallows.nr > 0) {
 			int i;
 			for (i = 0; i < shallows.nr; i++)
-				register_shallow(&shallows.objects[i].item->oid);
+				register_shallow(the_repository,
+						 &shallows.objects[i].item->oid);
 		}
 
 	shallow_nr += shallows.nr;
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#188 lore raw

PATCH 154/194 shallow: add repository argument to check_shallow_file_for_update

In reply to Stefan Beller
---
 shallow.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
shallow.c +4 -3
index 67feeb3a4f..2a7685fa7c 100644
@@ -219,7 +219,8 @@ struct commit_list *get_shallow_commits_by_rev_list(int ac, const char **av,
 	return result;
 }
 
-static void check_shallow_file_for_update(void)
+#define check_shallow_file_for_update(r) check_shallow_file_for_update_##r()
+static void check_shallow_file_for_update_the_repository(void)
 {
 	if (is_shallow == -1)
 		die("BUG: shallow must be initialized by now");
@@ -321,7 +322,7 @@ void setup_alternate_shallow(struct lock_file *shallow_lock,
 
 	fd = hold_lock_file_for_update(shallow_lock, git_path_shallow(),
 				       LOCK_DIE_ON_ERROR);
-	check_shallow_file_for_update();
+	check_shallow_file_for_update(the_repository);
 	if (write_shallow_commits(&sb, 0, extra)) {
 		if (write_in_full(fd, sb.buf, sb.len) < 0)
 			die_errno("failed to write to %s",
@@ -368,7 +369,7 @@ void prune_shallow(int show_only)
 	}
 	fd = hold_lock_file_for_update(&shallow_lock, git_path_shallow(),
 				       LOCK_DIE_ON_ERROR);
-	check_shallow_file_for_update();
+	check_shallow_file_for_update(the_repository);
 	if (write_shallow_commits_1(&sb, 0, NULL, SEEN_ONLY)) {
 		if (write_in_full(fd, sb.buf, sb.len) < 0)
 			die_errno("failed to write to %s",
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#189 lore raw

PATCH 155/194 shallow: add repository argument to is_repository_shallow

In reply to Stefan Beller
---
 builtin/fetch.c                       | 2 +-
 builtin/pack-objects.c                | 4 ++--
 builtin/prune.c                       | 2 +-
 builtin/rev-parse.c                   | 3 ++-
 commit.c                              | 2 +-
 commit.h                              | 2 ++
 contrib/coccinelle/object_store.cocci | 5 +++++
 fetch-pack.c                          | 4 ++--
 send-pack.c                           | 6 +++---
 shallow.c                             | 8 ++++----
 upload-pack.c                         | 2 +-
 11 files changed, 24 insertions(+), 16 deletions(-)
builtin/fetch.c +1 -1
index 904496fa33..da99363067 100644
@@ -1352,7 +1352,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
 	if (unshallow) {
 		if (depth)
 			die(_("--depth and --unshallow cannot be used together"));
-		else if (!is_repository_shallow())
+		else if (!is_repository_shallow(the_repository))
 			die(_("--unshallow on a complete repository does not make sense"));
 		else
 			depth = xstrfmt("%d", INFINITE_DEPTH);
builtin/pack-objects.c +2 -2
index a16ecc3fe0..9a98154ec4 100644
@@ -2846,7 +2846,7 @@ static void get_object_list(int ac, const char **av)
 	setup_revisions(ac, av, &revs, NULL);
 
 	/* make sure shallows are read */
-	is_repository_shallow();
+	is_repository_shallow(the_repository);
 
 	while (fgets(line, sizeof(line), stdin) != NULL) {
 		int len = strlen(line);
@@ -3123,7 +3123,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
 		use_bitmap_index = use_bitmap_index_default;
 
 	/* "hard" reasons not to use bitmaps; these just won't work at all */
-	if (!use_internal_rev_list || (!pack_to_stdout && write_bitmap_index) || is_repository_shallow())
+	if (!use_internal_rev_list || (!pack_to_stdout && write_bitmap_index) || is_repository_shallow(the_repository))
 		use_bitmap_index = 0;
 
 	if (pack_to_stdout || !rev_list_all)
builtin/prune.c +1 -1
index 06e6de45b5..9a5f231b3a 100644
@@ -153,7 +153,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
 	remove_temporary_files(s);
 	free(s);
 
-	if (is_repository_shallow())
+	if (is_repository_shallow(the_repository))
 		prune_shallow(show_only);
 
 	return 0;
builtin/rev-parse.c +2 -1
index b5515df1ae..5911714441 100644
@@ -879,7 +879,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
 				continue;
 			}
 			if (!strcmp(arg, "--is-shallow-repository")) {
-				printf("%s\n", is_repository_shallow() ? "true"
+				printf("%s\n",
+						is_repository_shallow(the_repository) ? "true"
 						: "false");
 				continue;
 			}
commit.c +1 -1
index 32eda5f7c9..63dac3e601 100644
@@ -208,7 +208,7 @@ static void prepare_commit_graft_the_repository(void)
 	graft_file = get_graft_file(the_repository);
 	read_graft_file(the_repository, graft_file);
 	/* make sure shallows are read */
-	is_repository_shallow();
+	is_repository_shallow(the_repository);
 	commit_graft_prepared = 1;
 }
 
commit.h +2 -0
index 0c854d3679..06795f0684 100644
@@ -201,6 +201,8 @@ extern int register_shallow_the_repository(const struct object_id *oid);
 extern int unregister_shallow(const struct object_id *oid);
 extern int for_each_commit_graft(each_commit_graft_fn, void *);
 extern int is_repository_shallow(void);
+#define is_repository_shallow(r) is_repository_shallow_##r()
+extern int is_repository_shallow_the_repository(void);
 extern struct commit_list *get_shallow_commits(struct object_array *heads,
 		int depth, int shallow_flag, int not_shallow_flag);
 extern struct commit_list *get_shallow_commits_by_rev_list(
contrib/coccinelle/object_store.cocci +5 -0
index b56ebef884..b22c57ed43 100644
@@ -67,3 +67,8 @@ expression F;
  unuse_commit_buffer(
 +the_repository,
  E, F)
+
+@@ @@
+ is_repository_shallow(
++the_repository
+ )
fetch-pack.c +2 -2
index 1cd738fd62..01e5b36661 100644
@@ -397,7 +397,7 @@ static int find_common(struct fetch_pack_args *args,
 		return 1;
 	}
 
-	if (is_repository_shallow())
+	if (is_repository_shallow(the_repository))
 		write_shallow_commits(&req_buf, 1, NULL);
 	if (args->depth > 0)
 		packet_buf_write(&req_buf, "deepen %d", args->depth);
@@ -927,7 +927,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
 	sort_ref_list(&ref, ref_compare_name);
 	QSORT(sought, nr_sought, cmp_ref_by_name);
 
-	if ((args->depth > 0 || is_repository_shallow()) && !server_supports("shallow"))
+	if ((args->depth > 0 || is_repository_shallow(the_repository)) && !server_supports("shallow"))
 		die(_("Server does not support shallow clients"));
 	if (args->depth > 0 || args->deepen_since || args->deepen_not)
 		args->deepen = 1;
send-pack.c +3 -3
index c2856dcfd5..b6080b9c35 100644
@@ -76,7 +76,7 @@ static int pack_objects(int fd, struct ref *refs, struct oid_array *extra, struc
 		argv_array_push(&po.args, "-q");
 	if (args->progress)
 		argv_array_push(&po.args, "--progress");
-	if (is_repository_shallow())
+	if (is_repository_shallow(the_repository))
 		argv_array_push(&po.args, "--shallow");
 	po.in = -1;
 	po.out = args->stateless_rpc ? -1 : fd;
@@ -219,7 +219,7 @@ static int advertise_shallow_grafts_cb(const struct commit_graft *graft, void *c
 
 static void advertise_shallow_grafts_buf(struct strbuf *sb)
 {
-	if (!is_repository_shallow())
+	if (!is_repository_shallow(the_repository))
 		return;
 	for_each_commit_graft(advertise_shallow_grafts_cb, sb);
 }
@@ -536,7 +536,7 @@ int send_pack(struct send_pack_args *args,
 	}
 
 	if (args->stateless_rpc) {
-		if (!args->dry_run && (cmds_sent || is_repository_shallow())) {
+		if (!args->dry_run && (cmds_sent || is_repository_shallow(the_repository))) {
 			packet_buf_flush(&req_buf);
 			send_sideband(out, -1, req_buf.buf, req_buf.len, LARGE_PACKET_MAX);
 		}
shallow.c +4 -4
index 2a7685fa7c..18c6f063c1 100644
@@ -42,7 +42,7 @@ int register_shallow_the_repository(const struct object_id *oid)
 	return register_commit_graft(the_repository, graft, 0);
 }
 
-int is_repository_shallow(void)
+int is_repository_shallow_the_repository(void)
 {
 	FILE *fp;
 	char buf[1024];
@@ -110,7 +110,7 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
 		parse_commit_or_die(commit);
 		cur_depth++;
 		if ((depth != INFINITE_DEPTH && cur_depth >= depth) ||
-		    (is_repository_shallow() && !commit->parents &&
+		    (is_repository_shallow(the_repository) && !commit->parents &&
 		     (graft = lookup_commit_graft(the_repository, &commit->object.oid)) != NULL &&
 		     graft->nr_parent < 0)) {
 			commit_list_insert(commit, &result);
@@ -169,7 +169,7 @@ struct commit_list *get_shallow_commits_by_rev_list(int ac, const char **av,
 	 */
 	clear_object_flags(both_flags);
 
-	is_repository_shallow(); /* make sure shallows are read */
+	is_repository_shallow(the_repository); /* make sure shallows are read */
 
 	init_revisions(&revs, NULL);
 	save_commit_buffer = 0;
@@ -347,7 +347,7 @@ static int advertise_shallow_grafts_cb(const struct commit_graft *graft, void *c
 
 void advertise_shallow_grafts(int fd)
 {
-	if (!is_repository_shallow())
+	if (!is_repository_shallow(the_repository))
 		return;
 	for_each_commit_graft(advertise_shallow_grafts_cb, &fd);
 }
upload-pack.c +1 -1
index ed2d394ace..5bf761518f 100644
@@ -690,7 +690,7 @@ static void send_unshallow(const struct object_array *shallows)
 static void deepen(int depth, int deepen_relative,
 		   struct object_array *shallows)
 {
-	if (depth == INFINITE_DEPTH && !is_repository_shallow()) {
+	if (depth == INFINITE_DEPTH && !is_repository_shallow(the_repository)) {
 		int i;
 
 		for (i = 0; i < shallows->nr; i++) {
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#190 lore raw

PATCH 156/194 migrate cached path to use the_repository

In reply to Stefan Beller
---
 blame.c                              |  8 ++++---
 branch.c                             | 14 ++++++------
 builtin/commit.c                     | 38 +++++++++++++++----------------
 builtin/fetch.c                      |  4 ++--
 builtin/merge.c                      | 37 +++++++++++++++---------------
 builtin/pull.c                       |  4 ++--
 builtin/reset.c                      |  2 +-
 contrib/coccinelle/cached_path.cocci | 44 ++++++++++++++++++++++++++++++++++++
 fetch-pack.c                         |  2 +-
 path.c                               | 18 +++++++--------
 path.h                               | 40 ++++++++++++++++++++++++--------
 repository.c                         |  2 +-
 repository.h                         |  5 ++++
 rerere.c                             |  7 +++---
 sequencer.c                          | 33 ++++++++++++++-------------
 shallow.c                            | 12 ++++++----
 wt-status.c                          |  8 +++----
 17 files changed, 178 insertions(+), 100 deletions(-)
 create mode 100644 contrib/coccinelle/cached_path.cocci
blame.c +5 -3
index 1cd39e7a17..6832271319 100644
@@ -112,17 +112,19 @@ static void append_merge_parents(struct commit_list **tail)
 	int merge_head;
 	struct strbuf line = STRBUF_INIT;
 
-	merge_head = open(git_path_merge_head(), O_RDONLY);
+	merge_head = open(git_path_merge_head(the_repository), O_RDONLY);
 	if (merge_head < 0) {
 		if (errno == ENOENT)
 			return;
-		die("cannot open '%s' for reading", git_path_merge_head());
+		die("cannot open '%s' for reading",
+		    git_path_merge_head(the_repository));
 	}
 
 	while (!strbuf_getwholeline_fd(&line, merge_head, '\n')) {
 		struct object_id oid;
 		if (line.len < GIT_SHA1_HEXSZ || get_oid_hex(line.buf, &oid))
-			die("unknown line in '%s': %s", git_path_merge_head(), line.buf);
+			die("unknown line in '%s': %s",
+			    git_path_merge_head(the_repository), line.buf);
 		tail = append_parent(tail, &oid);
 	}
 	close(merge_head);
branch.c +7 -7
index 0b7aaa1aca..08d4efc1be 100644
@@ -339,13 +339,13 @@ void create_branch(const char *name, const char *start_name,
 
 void remove_branch_state(void)
 {
-	unlink(git_path_cherry_pick_head());
-	unlink(git_path_revert_head());
-	unlink(git_path_merge_head());
-	unlink(git_path_merge_rr());
-	unlink(git_path_merge_msg());
-	unlink(git_path_merge_mode());
-	unlink(git_path_squash_msg());
+	unlink(git_path_cherry_pick_head(the_repository));
+	unlink(git_path_revert_head(the_repository));
+	unlink(git_path_merge_head(the_repository));
+	unlink(git_path_merge_rr(the_repository));
+	unlink(git_path_merge_msg(the_repository));
+	unlink(git_path_merge_mode(the_repository));
+	unlink(git_path_squash_msg(the_repository));
 }
 
 void die_if_checked_out(const char *branch, int ignore_current_worktree)
builtin/commit.c +19 -19
index d15592ad45..cceb965569 100644
@@ -179,9 +179,9 @@ static int opt_parse_m(const struct option *opt, const char *arg, int unset)
 
 static void determine_whence(struct wt_status *s)
 {
-	if (file_exists(git_path_merge_head()))
+	if (file_exists(git_path_merge_head(the_repository)))
 		whence = FROM_MERGE;
-	else if (file_exists(git_path_cherry_pick_head())) {
+	else if (file_exists(git_path_cherry_pick_head(the_repository))) {
 		whence = FROM_CHERRY_PICK;
 		if (file_exists(git_path_seq_dir()))
 			sequencer_in_use = 1;
@@ -732,21 +732,21 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 		format_commit_message(commit, "fixup! %s\n\n",
 				      &sb, &ctx);
 		hook_arg1 = "message";
-	} else if (!stat(git_path_merge_msg(), &statbuf)) {
+	} else if (!stat(git_path_merge_msg(the_repository), &statbuf)) {
 		/*
 		 * prepend SQUASH_MSG here if it exists and a
 		 * "merge --squash" was originally performed
 		 */
-		if (!stat(git_path_squash_msg(), &statbuf)) {
-			if (strbuf_read_file(&sb, git_path_squash_msg(), 0) < 0)
+		if (!stat(git_path_squash_msg(the_repository), &statbuf)) {
+			if (strbuf_read_file(&sb, git_path_squash_msg(the_repository), 0) < 0)
 				die_errno(_("could not read SQUASH_MSG"));
 			hook_arg1 = "squash";
 		} else
 			hook_arg1 = "merge";
-		if (strbuf_read_file(&sb, git_path_merge_msg(), 0) < 0)
+		if (strbuf_read_file(&sb, git_path_merge_msg(the_repository), 0) < 0)
 			die_errno(_("could not read MERGE_MSG"));
-	} else if (!stat(git_path_squash_msg(), &statbuf)) {
-		if (strbuf_read_file(&sb, git_path_squash_msg(), 0) < 0)
+	} else if (!stat(git_path_squash_msg(the_repository), &statbuf)) {
+		if (strbuf_read_file(&sb, git_path_squash_msg(the_repository), 0) < 0)
 			die_errno(_("could not read SQUASH_MSG"));
 		hook_arg1 = "squash";
 	} else if (template_file) {
@@ -827,8 +827,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 					"	%s\n"
 					"and try again.\n"),
 				whence == FROM_MERGE ?
-					git_path_merge_head() :
-					git_path_cherry_pick_head());
+					git_path_merge_head(the_repository) :
+					git_path_cherry_pick_head(the_repository));
 		}
 
 		fprintf(s->fp, "\n");
@@ -1732,7 +1732,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 		if (!reflog_msg)
 			reflog_msg = "commit (merge)";
 		pptr = commit_list_append(current_head, pptr);
-		fp = xfopen(git_path_merge_head(), "r");
+		fp = xfopen(git_path_merge_head(the_repository), "r");
 		while (strbuf_getline_lf(&m, fp) != EOF) {
 			struct commit *parent;
 
@@ -1743,8 +1743,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 		}
 		fclose(fp);
 		strbuf_release(&m);
-		if (!stat(git_path_merge_mode(), &statbuf)) {
-			if (strbuf_read_file(&sb, git_path_merge_mode(), 0) < 0)
+		if (!stat(git_path_merge_mode(the_repository), &statbuf)) {
+			if (strbuf_read_file(&sb, git_path_merge_mode(the_repository), 0) < 0)
 				die_errno(_("could not read MERGE_MODE"));
 			if (!strcmp(sb.buf, "no-ff"))
 				allow_fast_forward = 0;
@@ -1820,12 +1820,12 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 	}
 	ref_transaction_free(transaction);
 
-	unlink(git_path_cherry_pick_head());
-	unlink(git_path_revert_head());
-	unlink(git_path_merge_head());
-	unlink(git_path_merge_msg());
-	unlink(git_path_merge_mode());
-	unlink(git_path_squash_msg());
+	unlink(git_path_cherry_pick_head(the_repository));
+	unlink(git_path_revert_head(the_repository));
+	unlink(git_path_merge_head(the_repository));
+	unlink(git_path_merge_msg(the_repository));
+	unlink(git_path_merge_mode(the_repository));
+	unlink(git_path_squash_msg(the_repository));
 
 	if (commit_index_files())
 		die (_("Repository has been updated, but unable to write\n"
builtin/fetch.c +2 -2
index da99363067..b516b176f0 100644
@@ -756,7 +756,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
 	const char *what, *kind;
 	struct ref *rm;
 	char *url;
-	const char *filename = dry_run ? "/dev/null" : git_path_fetch_head();
+	const char *filename = dry_run ? "/dev/null" : git_path_fetch_head(the_repository);
 	int want_status;
 	int summary_width = transport_summary_width(ref_map);
 
@@ -1009,7 +1009,7 @@ static void check_not_current_branch(struct ref *ref_map)
 
 static int truncate_fetch_head(void)
 {
-	const char *filename = git_path_fetch_head();
+	const char *filename = git_path_fetch_head(the_repository);
 	FILE *fp = fopen_for_writing(filename);
 
 	if (!fp)
builtin/merge.c +19 -18
index 30264cfd7c..4f5c01c41c 100644
@@ -244,9 +244,9 @@ static struct option builtin_merge_options[] = {
 /* Cleans up metadata that is uninteresting after a succeeded merge. */
 static void drop_save(void)
 {
-	unlink(git_path_merge_head());
-	unlink(git_path_merge_msg());
-	unlink(git_path_merge_mode());
+	unlink(git_path_merge_head(the_repository));
+	unlink(git_path_merge_msg(the_repository));
+	unlink(git_path_merge_mode(the_repository));
 }
 
 static int save_state(struct object_id *stash)
@@ -379,7 +379,7 @@ static void squash_message(struct commit *commit, struct commit_list *remotehead
 			oid_to_hex(&commit->object.oid));
 		pretty_print_commit(&ctx, commit, &out);
 	}
-	write_file_buf(git_path_squash_msg(), out.buf, out.len);
+	write_file_buf(git_path_squash_msg(the_repository), out.buf, out.len);
 	strbuf_release(&out);
 }
 
@@ -742,7 +742,7 @@ static void add_strategies(const char *string, unsigned attr)
 
 static void read_merge_msg(struct strbuf *msg)
 {
-	const char *filename = git_path_merge_msg();
+	const char *filename = git_path_merge_msg(the_repository);
 	strbuf_reset(msg);
 	if (strbuf_read_file(msg, filename, 0) < 0)
 		die_errno(_("Could not read from '%s'"), filename);
@@ -779,18 +779,18 @@ static void prepare_to_commit(struct commit_list *remoteheads)
 	if (signoff)
 		append_signoff(&msg, ignore_non_trailer(msg.buf, msg.len), 0);
 	write_merge_heads(remoteheads);
-	write_file_buf(git_path_merge_msg(), msg.buf, msg.len);
+	write_file_buf(git_path_merge_msg(the_repository), msg.buf, msg.len);
 	if (run_commit_hook(0 < option_edit, get_index_file(), "prepare-commit-msg",
-			    git_path_merge_msg(), "merge", NULL))
+			    git_path_merge_msg(the_repository), "merge", NULL))
 		abort_commit(remoteheads, NULL);
 	if (0 < option_edit) {
-		if (launch_editor(git_path_merge_msg(), NULL, NULL))
+		if (launch_editor(git_path_merge_msg(the_repository), NULL, NULL))
 			abort_commit(remoteheads, NULL);
 	}
 
 	if (verify_msg && run_commit_hook(0 < option_edit, get_index_file(),
 					  "commit-msg",
-					  git_path_merge_msg(), NULL))
+					  git_path_merge_msg(the_repository), NULL))
 		abort_commit(remoteheads, NULL);
 
 	read_merge_msg(&msg);
@@ -861,7 +861,7 @@ static int suggest_conflicts(void)
 	FILE *fp;
 	struct strbuf msgbuf = STRBUF_INIT;
 
-	filename = git_path_merge_msg();
+	filename = git_path_merge_msg(the_repository);
 	fp = xfopen(filename, "a");
 
 	append_conflicts_hint(&msgbuf);
@@ -941,12 +941,12 @@ static void write_merge_heads(struct commit_list *remoteheads)
 		}
 		strbuf_addf(&buf, "%s\n", oid_to_hex(oid));
 	}
-	write_file_buf(git_path_merge_head(), buf.buf, buf.len);
+	write_file_buf(git_path_merge_head(the_repository), buf.buf, buf.len);
 
 	strbuf_reset(&buf);
 	if (fast_forward == FF_NO)
 		strbuf_addstr(&buf, "no-ff");
-	write_file_buf(git_path_merge_mode(), buf.buf, buf.len);
+	write_file_buf(git_path_merge_mode(the_repository), buf.buf, buf.len);
 	strbuf_release(&buf);
 }
 
@@ -954,7 +954,8 @@ static void write_merge_state(struct commit_list *remoteheads)
 {
 	write_merge_heads(remoteheads);
 	strbuf_addch(&merge_msg, '\n');
-	write_file_buf(git_path_merge_msg(), merge_msg.buf, merge_msg.len);
+	write_file_buf(git_path_merge_msg(the_repository), merge_msg.buf,
+		       merge_msg.len);
 }
 
 static int default_edit_option(void)
@@ -1037,7 +1038,7 @@ static void handle_fetch_head(struct commit_list **remotes, struct strbuf *merge
 	if (!merge_names)
 		merge_names = &fetch_head_file;
 
-	filename = git_path_fetch_head();
+	filename = git_path_fetch_head(the_repository);
 	fd = open(filename, O_RDONLY);
 	if (fd < 0)
 		die_errno(_("could not open '%s' for reading"), filename);
@@ -1174,7 +1175,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 			usage_msg_opt(_("--abort expects no arguments"),
 			      builtin_merge_usage, builtin_merge_options);
 
-		if (!file_exists(git_path_merge_head()))
+		if (!file_exists(git_path_merge_head(the_repository)))
 			die(_("There is no merge to abort (MERGE_HEAD missing)."));
 
 		/* Invoke 'git reset --merge' */
@@ -1190,7 +1191,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 			usage_msg_opt(_("--continue expects no arguments"),
 			      builtin_merge_usage, builtin_merge_options);
 
-		if (!file_exists(git_path_merge_head()))
+		if (!file_exists(git_path_merge_head(the_repository)))
 			die(_("There is no merge in progress (MERGE_HEAD missing)."));
 
 		/* Invoke 'git commit' */
@@ -1201,7 +1202,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 	if (read_cache_unmerged())
 		die_resolve_conflict("merge");
 
-	if (file_exists(git_path_merge_head())) {
+	if (file_exists(git_path_merge_head(the_repository))) {
 		/*
 		 * There is no unmerged entry, don't advise 'git
 		 * add/rm <file>', just 'git commit'.
@@ -1212,7 +1213,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 		else
 			die(_("You have not concluded your merge (MERGE_HEAD exists)."));
 	}
-	if (file_exists(git_path_cherry_pick_head())) {
+	if (file_exists(git_path_cherry_pick_head(the_repository))) {
 		if (advice_resolve_conflict)
 			die(_("You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists).\n"
 			    "Please, commit your changes before you merge."));
builtin/pull.c +2 -2
index 90aa922260..0fb48a33be 100644
@@ -351,7 +351,7 @@ static int git_pull_config(const char *var, const char *value, void *cb)
  */
 static void get_merge_heads(struct oid_array *merge_heads)
 {
-	const char *filename = git_path_fetch_head();
+	const char *filename = git_path_fetch_head(the_repository);
 	FILE *fp;
 	struct strbuf sb = STRBUF_INIT;
 	struct object_id oid;
@@ -858,7 +858,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
 	if (read_cache_unmerged())
 		die_resolve_conflict("pull");
 
-	if (file_exists(git_path_merge_head()))
+	if (file_exists(git_path_merge_head(the_repository)))
 		die_conclude_merge();
 
 	if (get_oid("HEAD", &orig_head))
builtin/reset.c +1 -1
index 891dd77a5f..7c57309adc 100644
@@ -39,7 +39,7 @@ static const char *reset_type_names[] = {
 
 static inline int is_merge(void)
 {
-	return !access(git_path_merge_head(), F_OK);
+	return !access(git_path_merge_head(the_repository), F_OK);
 }
 
 static int reset_index(const struct object_id *oid, int reset_type, int quiet)
contrib/coccinelle/cached_path.cocci new file +44 -0

44 lines not on this page · raw message

fetch-pack.c +1 -1
index 01e5b36661..74265554c3 100644
@@ -1070,7 +1070,7 @@ static void update_shallow(struct fetch_pack_args *args,
 
 	if (args->deepen && alternate_shallow_file) {
 		if (*alternate_shallow_file == '\0') { /* --unshallow */
-			unlink_or_warn(git_path_shallow());
+			unlink_or_warn(git_path_shallow(the_repository));
 			rollback_lock_file(&shallow_lock);
 		} else
 			commit_lock_file(&shallow_lock);
path.c +9 -9
index da8b655730..8a88f145cd 100644
@@ -1357,12 +1357,12 @@ char *xdg_cache_home(const char *filename)
 	return NULL;
 }
 
-GIT_PATH_FUNC(git_path_cherry_pick_head, "CHERRY_PICK_HEAD")
-GIT_PATH_FUNC(git_path_revert_head, "REVERT_HEAD")
-GIT_PATH_FUNC(git_path_squash_msg, "SQUASH_MSG")
-GIT_PATH_FUNC(git_path_merge_msg, "MERGE_MSG")
-GIT_PATH_FUNC(git_path_merge_rr, "MERGE_RR")
-GIT_PATH_FUNC(git_path_merge_mode, "MERGE_MODE")
-GIT_PATH_FUNC(git_path_merge_head, "MERGE_HEAD")
-GIT_PATH_FUNC(git_path_fetch_head, "FETCH_HEAD")
-GIT_PATH_FUNC(git_path_shallow, "shallow")
+REPO_GIT_PATH_FUNC(path_cherry_pick_head, "CHERRY_PICK_HEAD")
+REPO_GIT_PATH_FUNC(path_revert_head, "REVERT_HEAD")
+REPO_GIT_PATH_FUNC(path_squash_msg, "SQUASH_MSG")
+REPO_GIT_PATH_FUNC(path_merge_msg, "MERGE_MSG")
+REPO_GIT_PATH_FUNC(path_merge_rr, "MERGE_RR")
+REPO_GIT_PATH_FUNC(path_merge_mode, "MERGE_MODE")
+REPO_GIT_PATH_FUNC(path_merge_head, "MERGE_HEAD")
+REPO_GIT_PATH_FUNC(path_fetch_head, "FETCH_HEAD")
+REPO_GIT_PATH_FUNC(path_shallow, "shallow")
path.h +31 -9
index 1ccd0373c9..0fa6172f96 100644
@@ -160,14 +160,36 @@ extern void report_linked_checkout_garbage(void);
 		return ret; \
 	}
 
-const char *git_path_cherry_pick_head(void);
-const char *git_path_revert_head(void);
-const char *git_path_squash_msg(void);
-const char *git_path_merge_msg(void);
-const char *git_path_merge_rr(void);
-const char *git_path_merge_mode(void);
-const char *git_path_merge_head(void);
-const char *git_path_fetch_head(void);
-const char *git_path_shallow(void);
+#define REPO_GIT_PATH_FUNC(var, filename) \
+	const char *git_##var(struct repository *r) \
+	{ \
+		if (!r->cached_paths.var) \
+			r->cached_paths.var = git_pathdup(filename); \
+		return r->cached_paths.var; \
+	}
+
+struct path_cache {
+	const char *path_cherry_pick_head;
+	const char *path_revert_head;
+	const char *path_squash_msg;
+	const char *path_merge_msg;
+	const char *path_merge_rr;
+	const char *path_merge_mode;
+	const char *path_merge_head;
+	const char *path_fetch_head;
+	const char *path_shallow;
+};
+
+#define PATH_CACHE_INIT { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
+
+const char *git_path_cherry_pick_head(struct repository *r);
+const char *git_path_revert_head(struct repository *r);
+const char *git_path_squash_msg(struct repository *r);
+const char *git_path_merge_msg(struct repository *r);
+const char *git_path_merge_rr(struct repository *r);
+const char *git_path_merge_mode(struct repository *r);
+const char *git_path_merge_head(struct repository *r);
+const char *git_path_fetch_head(struct repository *r);
+const char *git_path_shallow(struct repository *r);
 
 #endif /* PATH_H */
repository.c +1 -1
index 0cf019bb9b..3ee47b4c5d 100644
@@ -7,7 +7,7 @@
 
 /* The main repository */
 static struct repository the_repo = {
-	NULL, NULL, NULL, RAW_OBJECT_STORE_INIT, OBJECT_PARSER_INIT, NULL,
+	NULL, NULL, NULL, RAW_OBJECT_STORE_INIT, OBJECT_PARSER_INIT, PATH_CACHE_INIT, NULL,
 	NULL, NULL, NULL, NULL, NULL, NULL, &the_index, NULL, 0, 0
 };
 struct repository *the_repository = &the_repo;
repository.h +5 -0
index 74b2b27986..8de14137b4 100644
@@ -43,6 +43,11 @@ struct repository {
 	 */
 	struct object_parser parsed_objects;
 
+	/*
+	 * Contains path to often used file names.
+	 */
+	struct path_cache cached_paths;
+
 	/*
 	 * The store in which the refs are hold.
 	 */
rerere.c +4 -3
index 30ca5fa56d..dc79b940c5 100644
@@ -202,7 +202,7 @@ static struct rerere_id *new_rerere_id(unsigned char *sha1)
 static void read_rr(struct string_list *rr)
 {
 	struct strbuf buf = STRBUF_INIT;
-	FILE *in = fopen_or_warn(git_path_merge_rr(), "r");
+	FILE *in = fopen_or_warn(git_path_merge_rr(the_repository), "r");
 
 	if (!in)
 		return;
@@ -900,7 +900,8 @@ int setup_rerere(struct string_list *merge_rr, int flags)
 	if (flags & RERERE_READONLY)
 		fd = 0;
 	else
-		fd = hold_lock_file_for_update(&write_lock, git_path_merge_rr(),
+		fd = hold_lock_file_for_update(&write_lock,
+					       git_path_merge_rr(the_repository),
 					       LOCK_DIE_ON_ERROR);
 	read_rr(merge_rr);
 	return fd;
@@ -1251,6 +1252,6 @@ void rerere_clear(struct string_list *merge_rr)
 			rmdir(rerere_path(id, NULL));
 		}
 	}
-	unlink_or_warn(git_path_merge_rr());
+	unlink_or_warn(git_path_merge_rr(the_repository));
 	rollback_lock_file(&write_lock);
 }
sequencer.c +17 -16
index fbbe5267f7..521da238b5 100644
@@ -274,7 +274,7 @@ static void print_advice(int show_hint, struct replay_opts *opts)
 		 * (typically rebase --interactive) wants to take care
 		 * of the commit itself so remove CHERRY_PICK_HEAD
 		 */
-		unlink(git_path_cherry_pick_head());
+		unlink(git_path_cherry_pick_head(the_repository));
 		return;
 	}
 
@@ -951,7 +951,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
 		struct replay_opts *opts, int final_fixup)
 {
 	unsigned int flags = opts->edit ? EDIT_MSG : 0;
-	const char *msg_file = opts->edit ? NULL : git_path_merge_msg();
+	const char *msg_file = opts->edit ? NULL : git_path_merge_msg(the_repository);
 	struct object_id head;
 	struct commit *base, *next, *parent;
 	const char *base_label, *next_label;
@@ -1083,12 +1083,12 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
 			flags |= CLEANUP_MSG;
 			msg_file = rebase_path_fixup_msg();
 		} else {
-			const char *dest = git_path_squash_msg();
+			const char *dest = git_path_squash_msg(the_repository);
 			unlink(dest);
 			if (copy_file(dest, rebase_path_squash_msg(), 0666))
 				return error(_("could not rename '%s' to '%s'"),
 					     rebase_path_squash_msg(), dest);
-			unlink(git_path_merge_msg());
+			unlink(git_path_merge_msg(the_repository));
 			msg_file = dest;
 			flags |= EDIT_MSG;
 		}
@@ -1102,13 +1102,13 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
 		if (res < 0)
 			return res;
 		res |= write_message(msgbuf.buf, msgbuf.len,
-				     git_path_merge_msg(), 0);
+				     git_path_merge_msg(the_repository), 0);
 	} else {
 		struct commit_list *common = NULL;
 		struct commit_list *remotes = NULL;
 
 		res = write_message(msgbuf.buf, msgbuf.len,
-				    git_path_merge_msg(), 0);
+				    git_path_merge_msg(the_repository), 0);
 
 		commit_list_insert(base, &common);
 		commit_list_insert(next, &remotes);
@@ -1644,8 +1644,8 @@ static int rollback_single_pick(void)
 {
 	struct object_id head_oid;
 
-	if (!file_exists(git_path_cherry_pick_head()) &&
-	    !file_exists(git_path_revert_head()))
+	if (!file_exists(git_path_cherry_pick_head(the_repository)) &&
+	    !file_exists(git_path_revert_head(the_repository)))
 		return error(_("no cherry-pick or revert in progress"));
 	if (read_ref_full("HEAD", 0, &head_oid, NULL))
 		return error(_("cannot resolve HEAD"));
@@ -1870,10 +1870,11 @@ static int error_failed_squash(struct commit *commit,
 		return error(_("could not rename '%s' to '%s'"),
 			rebase_path_squash_msg(), rebase_path_message());
 	unlink(rebase_path_fixup_msg());
-	unlink(git_path_merge_msg());
-	if (copy_file(git_path_merge_msg(), rebase_path_message(), 0666))
+	unlink(git_path_merge_msg(the_repository));
+	if (copy_file(git_path_merge_msg(the_repository), rebase_path_message(), 0666))
 		return error(_("could not copy '%s' to '%s'"),
-			     rebase_path_message(), git_path_merge_msg());
+			     rebase_path_message(),
+			     git_path_merge_msg(the_repository));
 	return error_with_patch(commit, subject, subject_len, opts, 1, 0);
 }
 
@@ -2228,8 +2229,8 @@ static int continue_single_pick(void)
 {
 	const char *argv[] = { "commit", NULL };
 
-	if (!file_exists(git_path_cherry_pick_head()) &&
-	    !file_exists(git_path_revert_head()))
+	if (!file_exists(git_path_cherry_pick_head(the_repository)) &&
+	    !file_exists(git_path_revert_head(the_repository)))
 		return error(_("no cherry-pick or revert in progress"));
 	return run_command_v_opt(argv, RUN_GIT_CMD);
 }
@@ -2241,7 +2242,7 @@ static int commit_staged_changes(struct replay_opts *opts)
 	if (has_unstaged_changes(1))
 		return error(_("cannot rebase: You have unstaged changes."));
 	if (!has_uncommitted_changes(0)) {
-		const char *cherry_pick_head = git_path_cherry_pick_head();
+		const char *cherry_pick_head = git_path_cherry_pick_head(the_repository);
 
 		if (file_exists(cherry_pick_head) && unlink(cherry_pick_head))
 			return error(_("could not remove CHERRY_PICK_HEAD"));
@@ -2295,8 +2296,8 @@ int sequencer_continue(struct replay_opts *opts)
 
 	if (!is_rebase_i(opts)) {
 		/* Verify that the conflict has been resolved */
-		if (file_exists(git_path_cherry_pick_head()) ||
-		    file_exists(git_path_revert_head())) {
+		if (file_exists(git_path_cherry_pick_head(the_repository)) ||
+		    file_exists(git_path_revert_head(the_repository))) {
 			res = continue_single_pick();
 			if (res)
 				goto release_todo_list;
shallow.c +7 -5
index 18c6f063c1..2849046477 100644
@@ -52,7 +52,7 @@ int is_repository_shallow_the_repository(void)
 		return is_shallow;
 
 	if (!path)
-		path = git_path_shallow();
+		path = git_path_shallow(the_repository);
 	/*
 	 * fetch-pack sets '--shallow-file ""' as an indicator that no
 	 * shallow file should be used. We could just open it and it
@@ -225,7 +225,7 @@ static void check_shallow_file_for_update_the_repository(void)
 	if (is_shallow == -1)
 		die("BUG: shallow must be initialized by now");
 
-	if (!stat_validity_check(&shallow_stat, git_path_shallow()))
+	if (!stat_validity_check(&shallow_stat, git_path_shallow(the_repository)))
 		die("shallow file has changed since we read it");
 }
 
@@ -320,7 +320,8 @@ void setup_alternate_shallow(struct lock_file *shallow_lock,
 	struct strbuf sb = STRBUF_INIT;
 	int fd;
 
-	fd = hold_lock_file_for_update(shallow_lock, git_path_shallow(),
+	fd = hold_lock_file_for_update(shallow_lock,
+				       git_path_shallow(the_repository),
 				       LOCK_DIE_ON_ERROR);
 	check_shallow_file_for_update(the_repository);
 	if (write_shallow_commits(&sb, 0, extra)) {
@@ -367,7 +368,8 @@ void prune_shallow(int show_only)
 		strbuf_release(&sb);
 		return;
 	}
-	fd = hold_lock_file_for_update(&shallow_lock, git_path_shallow(),
+	fd = hold_lock_file_for_update(&shallow_lock,
+				       git_path_shallow(the_repository),
 				       LOCK_DIE_ON_ERROR);
 	check_shallow_file_for_update(the_repository);
 	if (write_shallow_commits_1(&sb, 0, NULL, SEEN_ONLY)) {
@@ -376,7 +378,7 @@ void prune_shallow(int show_only)
 				  get_lock_file_path(&shallow_lock));
 		commit_lock_file(&shallow_lock);
 	} else {
-		unlink(git_path_shallow());
+		unlink(git_path_shallow(the_repository));
 		rollback_lock_file(&shallow_lock);
 	}
 	strbuf_release(&sb);
wt-status.c +4 -4
index 6655bc6f67..6b2885a2f1 100644
@@ -1286,7 +1286,7 @@ static void show_rebase_in_progress(struct wt_status *s,
 			status_printf_ln(s, color,
 				_("  (use \"git rebase --abort\" to check out the original branch)"));
 		}
-	} else if (state->rebase_in_progress || !stat(git_path_merge_msg(), &st)) {
+	} else if (state->rebase_in_progress || !stat(git_path_merge_msg(the_repository), &st)) {
 		print_rebase_state(s, state, color);
 		if (s->hints)
 			status_printf_ln(s, color,
@@ -1521,17 +1521,17 @@ void wt_status_get_state(struct wt_status_state *state,
 	struct stat st;
 	struct object_id oid;
 
-	if (!stat(git_path_merge_head(), &st)) {
+	if (!stat(git_path_merge_head(the_repository), &st)) {
 		state->merge_in_progress = 1;
 	} else if (wt_status_check_rebase(NULL, state)) {
 		;		/* all set */
-	} else if (!stat(git_path_cherry_pick_head(), &st) &&
+	} else if (!stat(git_path_cherry_pick_head(the_repository), &st) &&
 			!get_oid("CHERRY_PICK_HEAD", &oid)) {
 		state->cherry_pick_in_progress = 1;
 		hashcpy(state->cherry_pick_head_sha1, oid.hash);
 	}
 	wt_status_check_bisect(NULL, state);
-	if (!stat(git_path_revert_head(), &st) &&
+	if (!stat(git_path_revert_head(the_repository), &st) &&
 	    !get_oid("REVERT_HEAD", &oid)) {
 		state->revert_in_progress = 1;
 		hashcpy(state->revert_head_sha1, oid.hash);
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#191 lore raw

PATCH 157/194 shallow: migrate shallow information into the object parser

In reply to Stefan Beller
---
 commit.h     | 11 ++++-------
 object.h     |  6 ++++++
 repository.c |  4 ++++
 shallow.c    | 52 +++++++++++++++++++++++++---------------------------
 4 files changed, 39 insertions(+), 34 deletions(-)
commit.h +4 -7
index 06795f0684..cdd12ad75d 100644
@@ -196,19 +196,16 @@ extern struct commit_list *get_merge_bases_many_dirty(struct commit *one, int n,
 
 struct oid_array;
 struct ref;
-#define register_shallow(r, o) register_shallow_##r(o);
-extern int register_shallow_the_repository(const struct object_id *oid);
+extern int register_shallow(struct repository *r, const struct object_id *oid);
 extern int unregister_shallow(const struct object_id *oid);
 extern int for_each_commit_graft(each_commit_graft_fn, void *);
-extern int is_repository_shallow(void);
-#define is_repository_shallow(r) is_repository_shallow_##r()
-extern int is_repository_shallow_the_repository(void);
+extern int is_repository_shallow(struct repository *r);
+extern int for_each_commit_graft_the_repository(each_commit_graft_fn, void *);
 extern struct commit_list *get_shallow_commits(struct object_array *heads,
 		int depth, int shallow_flag, int not_shallow_flag);
 extern struct commit_list *get_shallow_commits_by_rev_list(
 		int ac, const char **av, int shallow_flag, int not_shallow_flag);
-#define set_alternate_shallow_file(r, p, o) set_alternate_shallow_file_##r(p, o)
-extern void set_alternate_shallow_file_the_repository(const char *path, int override);
+extern void set_alternate_shallow_file(struct repository *r, const char *path, int override);
 extern int write_shallow_commits(struct strbuf *out, int use_pack_protocol,
 				 const struct oid_array *extra);
 extern void setup_alternate_shallow(struct lock_file *shallow_lock,
object.h +6 -0
index 65b5326e0f..369295c7c1 100644
@@ -11,6 +11,10 @@ struct object_parser {
 	struct commit_graft **grafts;
 	int grafts_alloc, grafts_nr;
 
+	int is_shallow;
+	struct stat_validity *shallow_stat;
+	char *alternate_shallow_file;
+
 	struct alloc_state *blob_state;
 	struct alloc_state *tree_state;
 	struct alloc_state *commit_state;
@@ -20,6 +24,7 @@ struct object_parser {
 };
 
 extern struct buffer_slab the_repository_buffer_slab;
+extern struct stat_validity the_repository_shallow_stat;
 extern struct alloc_state the_repository_blob_state;
 extern struct alloc_state the_repository_tree_state;
 extern struct alloc_state the_repository_commit_state;
@@ -27,6 +32,7 @@ extern struct alloc_state the_repository_tag_state;
 extern struct alloc_state the_repository_object_state;
 #define OBJECT_PARSER_INIT { NULL, 0, 0, &the_repository_buffer_slab, \
 	NULL, 0, 0, \
+	-1, &the_repository_shallow_stat, NULL, \
 	&the_repository_blob_state, \
 	&the_repository_tree_state, \
 	&the_repository_commit_state, \
repository.c +4 -0
index 3ee47b4c5d..64fb6d8b34 100644
@@ -185,6 +185,10 @@ int repo_init(struct repository *repo, const char *gitdir, const char *worktree)
 	if (worktree)
 		repo_set_worktree(repo, worktree);
 
+	repo->parsed_objects.is_shallow = -1;
+	repo->parsed_objects.shallow_stat = xcalloc(1, sizeof(
+		*repo->parsed_objects.shallow_stat));
+
 	ALLOC_GROW(open_repos, open_repos_nr + 1, open_repos_alloc);
 	open_repos[open_repos_nr++] = repo;
 
shallow.c +25 -27

104 lines not on this page · raw message

Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#192 lore raw

PATCH 158/194 commit: allow prepare_commit_graft to handle arbitrary repositories

In reply to Stefan Beller
---
 commit.c | 14 ++++++--------
 object.h |  3 +++
 2 files changed, 9 insertions(+), 8 deletions(-)
commit.c +6 -8
index 63dac3e601..fcda65bee2 100644
@@ -197,19 +197,17 @@ static int read_graft_file(struct repository *r, const char *graft_file)
 	return 0;
 }
 
-#define prepare_commit_graft(r) prepare_commit_graft_##r()
-static void prepare_commit_graft_the_repository(void)
+static void prepare_commit_graft(struct repository *r)
 {
-	static int commit_graft_prepared;
 	char *graft_file;
 
-	if (commit_graft_prepared)
+	if (r->parsed_objects.commit_graft_prepared)
 		return;
-	graft_file = get_graft_file(the_repository);
-	read_graft_file(the_repository, graft_file);
+	graft_file = get_graft_file(r);
+	read_graft_file(r, graft_file);
 	/* make sure shallows are read */
-	is_repository_shallow(the_repository);
-	commit_graft_prepared = 1;
+	is_repository_shallow(r);
+	r->parsed_objects.commit_graft_prepared = 1;
 }
 
 struct commit_graft *lookup_commit_graft_the_repository(const struct object_id *oid)
object.h +3 -0
index 369295c7c1..14e0d412bb 100644
@@ -11,6 +11,8 @@ struct object_parser {
 	struct commit_graft **grafts;
 	int grafts_alloc, grafts_nr;
 
+	int commit_graft_prepared;
+
 	int is_shallow;
 	struct stat_validity *shallow_stat;
 	char *alternate_shallow_file;
@@ -32,6 +34,7 @@ extern struct alloc_state the_repository_tag_state;
 extern struct alloc_state the_repository_object_state;
 #define OBJECT_PARSER_INIT { NULL, 0, 0, &the_repository_buffer_slab, \
 	NULL, 0, 0, \
+	0, \
 	-1, &the_repository_shallow_stat, NULL, \
 	&the_repository_blob_state, \
 	&the_repository_tree_state, \
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#193 lore raw

PATCH 159/194 commit: allow lookup_commit_graft to handle arbitrary repositories

In reply to Stefan Beller
---
 commit.c | 8 ++++----
 commit.h | 3 +--
 2 files changed, 5 insertions(+), 6 deletions(-)
commit.c +4 -4
index fcda65bee2..a9660f7401 100644
@@ -210,14 +210,14 @@ static void prepare_commit_graft(struct repository *r)
 	r->parsed_objects.commit_graft_prepared = 1;
 }
 
-struct commit_graft *lookup_commit_graft_the_repository(const struct object_id *oid)
+struct commit_graft *lookup_commit_graft(struct repository *r, const struct object_id *oid)
 {
 	int pos;
-	prepare_commit_graft(the_repository);
-	pos = commit_graft_pos(the_repository, oid->hash);
+	prepare_commit_graft(r);
+	pos = commit_graft_pos(r, oid->hash);
 	if (pos < 0)
 		return NULL;
-	return the_repository->parsed_objects.grafts[pos];
+	return r->parsed_objects.grafts[pos];
 }
 
 int for_each_commit_graft(each_commit_graft_fn fn, void *cb_data)
commit.h +1 -2
index cdd12ad75d..b53053400d 100644
@@ -181,8 +181,7 @@ typedef int (*each_commit_graft_fn)(const struct commit_graft *, void *);
 
 struct commit_graft *read_graft_line(struct strbuf *line);
 int register_commit_graft(struct repository *r, struct commit_graft *, int);
-#define lookup_commit_graft(r, o) lookup_commit_graft_##r(o)
-struct commit_graft *lookup_commit_graft_the_repository(const struct object_id *oid);
+struct commit_graft *lookup_commit_graft(struct repository *r, const struct object_id *oid);
 
 extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2);
 extern struct commit_list *get_merge_bases_many(struct commit *one, int n, struct commit **twos);
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#194 lore raw

PATCH 160/194 commit: allow arbitrary repository argument for parse_commit_buffer

In reply to Stefan Beller
---
 commit.c | 10 +++++-----
 commit.h |  3 +--
 2 files changed, 6 insertions(+), 7 deletions(-)
commit.c +5 -5
index a9660f7401..67d329e13c 100644
@@ -334,7 +334,7 @@ const void *detach_commit_buffer(struct repository *r, struct commit *commit, un
 	return ret;
 }
 
-int parse_commit_buffer_the_repository(struct commit *item, const void *buffer, unsigned long size)
+int parse_commit_buffer(struct repository *r, struct commit *item, const void *buffer, unsigned long size)
 {
 	const char *tail = buffer;
 	const char *bufptr = buffer;
@@ -354,11 +354,11 @@ int parse_commit_buffer_the_repository(struct commit *item, const void *buffer,
 	if (get_sha1_hex(bufptr + 5, parent.hash) < 0)
 		return error("bad tree pointer in commit %s",
 			     oid_to_hex(&item->object.oid));
-	item->tree = lookup_tree(the_repository, &parent);
+	item->tree = lookup_tree(r, &parent);
 	bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */
 	pptr = &item->parents;
 
-	graft = lookup_commit_graft(the_repository, &item->object.oid);
+	graft = lookup_commit_graft(r, &item->object.oid);
 	while (bufptr + parent_entry_len < tail && !memcmp(bufptr, "parent ", 7)) {
 		struct commit *new_parent;
 
@@ -373,7 +373,7 @@ int parse_commit_buffer_the_repository(struct commit *item, const void *buffer,
 		 */
 		if (graft && (graft->nr_parent < 0 || grafts_replace_parents))
 			continue;
-		new_parent = lookup_commit(the_repository, &parent);
+		new_parent = lookup_commit(r, &parent);
 		if (new_parent)
 			pptr = &commit_list_insert(new_parent, pptr)->next;
 	}
@@ -381,7 +381,7 @@ int parse_commit_buffer_the_repository(struct commit *item, const void *buffer,
 		int i;
 		struct commit *new_parent;
 		for (i = 0; i < graft->nr_parent; i++) {
-			new_parent = lookup_commit(the_repository,
+			new_parent = lookup_commit(r,
 						   &graft->parent[i]);
 			if (!new_parent)
 				continue;
commit.h +1 -2
index b53053400d..8532ddd69c 100644
@@ -64,8 +64,7 @@ struct commit *lookup_commit_reference_by_name(const char *name);
  */
 struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref_name);
 
-#define parse_commit_buffer(r, i, b, s) parse_commit_buffer_##r(i, b, s)
-int parse_commit_buffer_the_repository(struct commit *item, const void *buffer, unsigned long size);
+int parse_commit_buffer(struct repository *r, struct commit *item, const void *buffer, unsigned long size);
 #define parse_commit_gently(r, i, q) parse_commit_gently_##r(i, q)
 int parse_commit_gently_the_repository(struct commit *item, int quiet_on_missing);
 #define parse_commit(r, i) parse_commit_##r(i)
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#195 lore raw

PATCH 161/194 commit: allow parse_commit_gently to handle arbitrary repository

In reply to Stefan Beller
---
 commit.c | 8 ++++----
 commit.h | 3 +--
 2 files changed, 5 insertions(+), 6 deletions(-)
commit.c +4 -4
index 67d329e13c..bd9049a9df 100644
@@ -393,7 +393,7 @@ int parse_commit_buffer(struct repository *r, struct commit *item, const void *b
 	return 0;
 }
 
-int parse_commit_gently_the_repository(struct commit *item, int quiet_on_missing)
+int parse_commit_gently(struct repository *r, struct commit *item, int quiet_on_missing)
 {
 	enum object_type type;
 	void *buffer;
@@ -404,7 +404,7 @@ int parse_commit_gently_the_repository(struct commit *item, int quiet_on_missing
 		return -1;
 	if (item->object.parsed)
 		return 0;
-	buffer = read_sha1_file(the_repository, item->object.oid.hash, &type,
+	buffer = read_sha1_file(r, item->object.oid.hash, &type,
 				&size);
 	if (!buffer)
 		return quiet_on_missing ? -1 :
@@ -415,9 +415,9 @@ int parse_commit_gently_the_repository(struct commit *item, int quiet_on_missing
 		return error("Object %s not a commit",
 			     oid_to_hex(&item->object.oid));
 	}
-	ret = parse_commit_buffer(the_repository, item, buffer, size);
+	ret = parse_commit_buffer(r, item, buffer, size);
 	if (save_commit_buffer && !ret) {
-		set_commit_buffer(the_repository, item, buffer, size);
+		set_commit_buffer(r, item, buffer, size);
 		return 0;
 	}
 	free(buffer);
commit.h +1 -2
index 8532ddd69c..153f13600b 100644
@@ -65,8 +65,7 @@ struct commit *lookup_commit_reference_by_name(const char *name);
 struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref_name);
 
 int parse_commit_buffer(struct repository *r, struct commit *item, const void *buffer, unsigned long size);
-#define parse_commit_gently(r, i, q) parse_commit_gently_##r(i, q)
-int parse_commit_gently_the_repository(struct commit *item, int quiet_on_missing);
+int parse_commit_gently(struct repository *r, struct commit *item, int quiet_on_missing);
 #define parse_commit(r, i) parse_commit_##r(i)
 static inline int parse_commit_the_repository(struct commit *item)
 {
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#196 lore raw

PATCH 162/194 commit: add repository argument to get_merge_bases_many_0

In reply to Stefan Beller
---
 commit.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
commit.c +5 -4
index bd9049a9df..a4f35cd9fc 100644
@@ -969,7 +969,8 @@ static int remove_redundant(struct commit **array, int cnt)
 	return filled;
 }
 
-static struct commit_list *get_merge_bases_many_0(struct commit *one,
+#define get_merge_bases_many_0(r, o, n, t, c) get_merge_bases_many_0_##r(o, n, t, c)
+static struct commit_list *get_merge_bases_many_0_the_repository(struct commit *one,
 						  int n,
 						  struct commit **twos,
 						  int cleanup)
@@ -1014,19 +1015,19 @@ struct commit_list *get_merge_bases_many(struct commit *one,
 					 int n,
 					 struct commit **twos)
 {
-	return get_merge_bases_many_0(one, n, twos, 1);
+	return get_merge_bases_many_0(the_repository, one, n, twos, 1);
 }
 
 struct commit_list *get_merge_bases_many_dirty(struct commit *one,
 					       int n,
 					       struct commit **twos)
 {
-	return get_merge_bases_many_0(one, n, twos, 0);
+	return get_merge_bases_many_0(the_repository, one, n, twos, 0);
 }
 
 struct commit_list *get_merge_bases(struct commit *one, struct commit *two)
 {
-	return get_merge_bases_many_0(one, 1, &two, 1);
+	return get_merge_bases_many_0(the_repository, one, 1, &two, 1);
 }
 
 /*
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#197 lore raw

PATCH 163/194 commit: add repository argument to merge_bases_many

In reply to Stefan Beller
---
 commit.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
commit.c +3 -2
index a4f35cd9fc..ed7349bbd7 100644
@@ -854,7 +854,8 @@ static struct commit_list *paint_down_to_common(struct commit *one, int n, struc
 	return result;
 }
 
-static struct commit_list *merge_bases_many(struct commit *one, int n, struct commit **twos)
+#define merge_bases_many(r, o, n, t) merge_bases_many_##r(o, n, t)
+static struct commit_list *merge_bases_many_the_repository(struct commit *one, int n, struct commit **twos)
 {
 	struct commit_list *list = NULL;
 	struct commit_list *result = NULL;
@@ -980,7 +981,7 @@ static struct commit_list *get_merge_bases_many_0_the_repository(struct commit *
 	struct commit_list *result;
 	int cnt, i;
 
-	result = merge_bases_many(one, n, twos);
+	result = merge_bases_many(the_repository, one, n, twos);
 	for (i = 0; i < n; i++) {
 		if (one == twos[i])
 			return result;
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#198 lore raw

PATCH 164/194 commit: add repository argument to paint_down_to_common

In reply to Stefan Beller
---
 commit.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
commit.c +5 -4
index ed7349bbd7..3886266785 100644
@@ -805,7 +805,8 @@ static int queue_has_nonstale(struct prio_queue *queue)
 }
 
 /* all input commits in one and twos[] must have been parsed! */
-static struct commit_list *paint_down_to_common(struct commit *one, int n, struct commit **twos)
+#define paint_down_to_common(r, o, n, t) paint_down_to_common_##r(o, n, t)
+static struct commit_list *paint_down_to_common_the_repository(struct commit *one, int n, struct commit **twos)
 {
 	struct prio_queue queue = { compare_commits_by_commit_date };
 	struct commit_list *result = NULL;
@@ -877,7 +878,7 @@ static struct commit_list *merge_bases_many_the_repository(struct commit *one, i
 			return NULL;
 	}
 
-	list = paint_down_to_common(one, n, twos);
+	list = paint_down_to_common(the_repository, one, n, twos);
 
 	while (list) {
 		struct commit *commit = pop_commit(&list);
@@ -944,7 +945,7 @@ static int remove_redundant(struct commit **array, int cnt)
 			filled_index[filled] = j;
 			work[filled++] = array[j];
 		}
-		common = paint_down_to_common(array[i], filled, work);
+		common = paint_down_to_common(the_repository, array[i], filled, work);
 		if (array[i]->object.flags & PARENT2)
 			redundant[i] = 1;
 		for (j = 0; j < filled; j++)
@@ -1063,7 +1064,7 @@ int in_merge_bases_many(struct commit *commit, int nr_reference, struct commit *
 		if (parse_commit(the_repository, reference[i]))
 			return ret;
 
-	bases = paint_down_to_common(commit, nr_reference, reference);
+	bases = paint_down_to_common(the_repository, commit, nr_reference, reference);
 	if (commit->object.flags & PARENT2)
 		ret = 1;
 	clear_commit_marks(commit, all_flags);
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#199 lore raw

PATCH 165/194 commit: allow parse_commit to handle arbitrary repositories

In reply to Stefan Beller
---
 commit.h | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
commit.h +2 -3
index 153f13600b..b60c287e7d 100644
@@ -66,10 +66,9 @@ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref
 
 int parse_commit_buffer(struct repository *r, struct commit *item, const void *buffer, unsigned long size);
 int parse_commit_gently(struct repository *r, struct commit *item, int quiet_on_missing);
-#define parse_commit(r, i) parse_commit_##r(i)
-static inline int parse_commit_the_repository(struct commit *item)
+static inline int parse_commit(struct repository *r, struct commit *item)
 {
-	return parse_commit_gently(the_repository, item, 0);
+	return parse_commit_gently(r, item, 0);
 }
 void parse_commit_or_die(struct commit *item);
 
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#200 lore raw

PATCH 166/194 commit: allow paint_down_to_common to handle arbitrary repositories

In reply to Stefan Beller
---
 commit.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
commit.c +2 -3
index 3886266785..5454bb5e11 100644
@@ -805,8 +805,7 @@ static int queue_has_nonstale(struct prio_queue *queue)
 }
 
 /* all input commits in one and twos[] must have been parsed! */
-#define paint_down_to_common(r, o, n, t) paint_down_to_common_##r(o, n, t)
-static struct commit_list *paint_down_to_common_the_repository(struct commit *one, int n, struct commit **twos)
+static struct commit_list *paint_down_to_common(struct repository *r, struct commit *one, int n, struct commit **twos)
 {
 	struct prio_queue queue = { compare_commits_by_commit_date };
 	struct commit_list *result = NULL;
@@ -844,7 +843,7 @@ static struct commit_list *paint_down_to_common_the_repository(struct commit *on
 			parents = parents->next;
 			if ((p->object.flags & flags) == flags)
 				continue;
-			if (parse_commit(the_repository, p))
+			if (parse_commit(r, p))
 				return NULL;
 			p->object.flags |= flags;
 			prio_queue_put(&queue, p);
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#201 lore raw

PATCH 167/194 commit: allow merge_bases_many to handle arbitrary repositories

In reply to Stefan Beller
---
 commit.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
commit.c +4 -5
index 5454bb5e11..b01352f54a 100644
@@ -854,8 +854,7 @@ static struct commit_list *paint_down_to_common(struct repository *r, struct com
 	return result;
 }
 
-#define merge_bases_many(r, o, n, t) merge_bases_many_##r(o, n, t)
-static struct commit_list *merge_bases_many_the_repository(struct commit *one, int n, struct commit **twos)
+static struct commit_list *merge_bases_many(struct repository *r, struct commit *one, int n, struct commit **twos)
 {
 	struct commit_list *list = NULL;
 	struct commit_list *result = NULL;
@@ -870,14 +869,14 @@ static struct commit_list *merge_bases_many_the_repository(struct commit *one, i
 			return commit_list_insert(one, &result);
 	}
 
-	if (parse_commit(the_repository, one))
+	if (parse_commit(r, one))
 		return NULL;
 	for (i = 0; i < n; i++) {
-		if (parse_commit(the_repository, twos[i]))
+		if (parse_commit(r, twos[i]))
 			return NULL;
 	}
 
-	list = paint_down_to_common(the_repository, one, n, twos);
+	list = paint_down_to_common(r, one, n, twos);
 
 	while (list) {
 		struct commit *commit = pop_commit(&list);
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#202 lore raw

PATCH 168/194 commit: add repository argument to remove_redundant

In reply to Stefan Beller
---
 commit.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
commit.c +4 -3
index b01352f54a..3ed46e7372 100644
@@ -913,7 +913,8 @@ struct commit_list *get_octopus_merge_bases(struct commit_list *in)
 	return ret;
 }
 
-static int remove_redundant(struct commit **array, int cnt)
+#define remove_redundant(r, a, c) remove_redundant_##r(a, c)
+static int remove_redundant_the_repository(struct commit **array, int cnt)
 {
 	/*
 	 * Some commit in the array may be an ancestor of
@@ -1003,7 +1004,7 @@ static struct commit_list *get_merge_bases_many_0_the_repository(struct commit *
 	clear_commit_marks(one, all_flags);
 	clear_commit_marks_many(n, twos, all_flags);
 
-	cnt = remove_redundant(rslt, cnt);
+	cnt = remove_redundant(the_repository, rslt, cnt);
 	result = NULL;
 	for (i = 0; i < cnt; i++)
 		commit_list_insert_by_date(rslt[i], &result);
@@ -1105,7 +1106,7 @@ struct commit_list *reduce_heads(struct commit_list *heads)
 			p->item->object.flags &= ~STALE;
 		}
 	}
-	num_head = remove_redundant(array, num_head);
+	num_head = remove_redundant(the_repository, array, num_head);
 	for (i = 0; i < num_head; i++)
 		tail = &commit_list_insert(array[i], tail)->next;
 	free(array);
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#203 lore raw

PATCH 169/194 commit: allow remove_redundant to handle arbitrary repositories

In reply to Stefan Beller
---
 commit.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
commit.c +3 -4
index 3ed46e7372..a8f964c6f9 100644
@@ -913,8 +913,7 @@ struct commit_list *get_octopus_merge_bases(struct commit_list *in)
 	return ret;
 }
 
-#define remove_redundant(r, a, c) remove_redundant_##r(a, c)
-static int remove_redundant_the_repository(struct commit **array, int cnt)
+static int remove_redundant(struct repository *r, struct commit **array, int cnt)
 {
 	/*
 	 * Some commit in the array may be an ancestor of
@@ -932,7 +931,7 @@ static int remove_redundant_the_repository(struct commit **array, int cnt)
 	ALLOC_ARRAY(filled_index, cnt - 1);
 
 	for (i = 0; i < cnt; i++)
-		parse_commit(the_repository, array[i]);
+		parse_commit(r, array[i]);
 	for (i = 0; i < cnt; i++) {
 		struct commit_list *common;
 
@@ -944,7 +943,7 @@ static int remove_redundant_the_repository(struct commit **array, int cnt)
 			filled_index[filled] = j;
 			work[filled++] = array[j];
 		}
-		common = paint_down_to_common(the_repository, array[i], filled, work);
+		common = paint_down_to_common(r, array[i], filled, work);
 		if (array[i]->object.flags & PARENT2)
 			redundant[i] = 1;
 		for (j = 0; j < filled; j++)
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#204 lore raw

PATCH 170/194 commit: allow get_merge_bases_many_0 to handle arbitrary repositories

In reply to Stefan Beller
---
 commit.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
commit.c +4 -4
index a8f964c6f9..db03550d70 100644
@@ -969,8 +969,8 @@ static int remove_redundant(struct repository *r, struct commit **array, int cnt
 	return filled;
 }
 
-#define get_merge_bases_many_0(r, o, n, t, c) get_merge_bases_many_0_##r(o, n, t, c)
-static struct commit_list *get_merge_bases_many_0_the_repository(struct commit *one,
+static struct commit_list *get_merge_bases_many_0(struct repository *r,
+						  struct commit *one,
 						  int n,
 						  struct commit **twos,
 						  int cleanup)
@@ -980,7 +980,7 @@ static struct commit_list *get_merge_bases_many_0_the_repository(struct commit *
 	struct commit_list *result;
 	int cnt, i;
 
-	result = merge_bases_many(the_repository, one, n, twos);
+	result = merge_bases_many(r, one, n, twos);
 	for (i = 0; i < n; i++) {
 		if (one == twos[i])
 			return result;
@@ -1003,7 +1003,7 @@ static struct commit_list *get_merge_bases_many_0_the_repository(struct commit *
 	clear_commit_marks(one, all_flags);
 	clear_commit_marks_many(n, twos, all_flags);
 
-	cnt = remove_redundant(the_repository, rslt, cnt);
+	cnt = remove_redundant(r, rslt, cnt);
 	result = NULL;
 	for (i = 0; i < cnt; i++)
 		commit_list_insert_by_date(rslt[i], &result);
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#205 lore raw

PATCH 171/194 commit: add repository argument to get_merge_bases

In reply to Stefan Beller
---
 builtin/log.c       | 2 +-
 builtin/merge.c     | 4 ++--
 builtin/rev-parse.c | 2 +-
 commit.c            | 4 ++--
 commit.h            | 3 ++-
 merge-recursive.c   | 2 +-
 notes-merge.c       | 2 +-
 revision.c          | 4 ++--
 sha1_name.c         | 2 +-
 submodule.c         | 2 +-
 10 files changed, 14 insertions(+), 13 deletions(-)
builtin/log.c +1 -1
index 12426e685f..3ccab366e7 100644
@@ -1312,7 +1312,7 @@ static struct commit *get_base_commit(const char *base_commit,
 	while (rev_nr > 1) {
 		for (i = 0; i < rev_nr / 2; i++) {
 			struct commit_list *merge_base;
-			merge_base = get_merge_bases(rev[2 * i], rev[2 * i + 1]);
+			merge_base = get_merge_bases(the_repository, rev[2 * i], rev[2 * i + 1]);
 			if (!merge_base || merge_base->next)
 				die(_("Failed to find exact merge base"));
 
builtin/merge.c +2 -2
index 4f5c01c41c..93a736ac36 100644
@@ -1352,7 +1352,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 	if (!remoteheads)
 		; /* already up-to-date */
 	else if (!remoteheads->next)
-		common = get_merge_bases(head_commit, remoteheads->item);
+		common = get_merge_bases(the_repository, head_commit, remoteheads->item);
 	else {
 		struct commit_list *list = remoteheads;
 		commit_list_insert(head_commit, &list);
@@ -1451,7 +1451,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 			 * merge_bases again, otherwise "git merge HEAD^
 			 * HEAD^^" would be missed.
 			 */
-			common_one = get_merge_bases(head_commit, j->item);
+			common_one = get_merge_bases(the_repository, head_commit, j->item);
 			if (oidcmp(&common_one->item->object.oid, &j->item->object.oid)) {
 				up_to_date = 0;
 				break;
builtin/rev-parse.c +1 -1
index 5911714441..3399176e49 100644
@@ -282,7 +282,7 @@ static int try_difference(const char *arg)
 			struct commit *a, *b;
 			a = lookup_commit_reference(the_repository, &oid);
 			b = lookup_commit_reference(the_repository, &end);
-			exclude = get_merge_bases(a, b);
+			exclude = get_merge_bases(the_repository, a, b);
 			while (exclude) {
 				struct commit *commit = pop_commit(&exclude);
 				show_rev(REVERSED, &commit->object.oid, NULL);
commit.c +2 -2
index db03550d70..8b1e35d2a1 100644
@@ -900,7 +900,7 @@ struct commit_list *get_octopus_merge_bases(struct commit_list *in)
 
 		for (j = ret; j; j = j->next) {
 			struct commit_list *bases;
-			bases = get_merge_bases(i->item, j->item);
+			bases = get_merge_bases(the_repository, i->item, j->item);
 			if (!new)
 				new = bases;
 			else
@@ -1025,7 +1025,7 @@ struct commit_list *get_merge_bases_many_dirty(struct commit *one,
 	return get_merge_bases_many_0(the_repository, one, n, twos, 0);
 }
 
-struct commit_list *get_merge_bases(struct commit *one, struct commit *two)
+struct commit_list *get_merge_bases_the_repository(struct commit *one, struct commit *two)
 {
 	return get_merge_bases_many_0(the_repository, one, 1, &two, 1);
 }
commit.h +2 -1
index b60c287e7d..e671ce68db 100644
@@ -180,7 +180,8 @@ struct commit_graft *read_graft_line(struct strbuf *line);
 int register_commit_graft(struct repository *r, struct commit_graft *, int);
 struct commit_graft *lookup_commit_graft(struct repository *r, const struct object_id *oid);
 
-extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2);
+#define get_merge_bases(r, r1, r2) get_merge_bases_##r(r1, r2)
+extern struct commit_list *get_merge_bases_the_repository(struct commit *rev1, struct commit *rev2);
 extern struct commit_list *get_merge_bases_many(struct commit *one, int n, struct commit **twos);
 extern struct commit_list *get_octopus_merge_bases(struct commit_list *in);
 
merge-recursive.c +1 -1
index c749785b0b..6e06634993 100644
@@ -2074,7 +2074,7 @@ int merge_recursive(struct merge_options *o,
 	}
 
 	if (!ca) {
-		ca = get_merge_bases(h1, h2);
+		ca = get_merge_bases(the_repository, h1, h2);
 		ca = reverse_commit_list(ca);
 	}
 
notes-merge.c +1 -1
index df66d96811..58b518ae0a 100644
@@ -594,7 +594,7 @@ int notes_merge(struct notes_merge_options *o,
 	assert(local && remote);
 
 	/* Find merge bases */
-	bases = get_merge_bases(local, remote);
+	bases = get_merge_bases(the_repository, local, remote);
 	if (!bases) {
 		base_oid = &null_oid;
 		base_tree_oid = the_hash_algo->empty_tree;
revision.c +2 -2
index 754d7b438e..c5d376ba0a 100644
@@ -1473,7 +1473,7 @@ static void prepare_show_merge(struct rev_info *revs)
 	other = lookup_commit_or_die(&oid, "MERGE_HEAD");
 	add_pending_object(revs, &head->object, "HEAD");
 	add_pending_object(revs, &other->object, "MERGE_HEAD");
-	bases = get_merge_bases(head, other);
+	bases = get_merge_bases(the_repository, head, other);
 	add_rev_cmdline_list(revs, bases, REV_CMD_MERGE_BASE, UNINTERESTING | BOTTOM);
 	add_pending_commit_list(revs, bases, UNINTERESTING | BOTTOM);
 	free_commit_list(bases);
@@ -1568,7 +1568,7 @@ static int handle_dotdot_1(const char *arg, char *dotdot,
 		if (!a || !b)
 			return dotdot_missing(arg, dotdot, revs, symmetric);
 
-		exclude = get_merge_bases(a, b);
+		exclude = get_merge_bases(the_repository, a, b);
 		add_rev_cmdline_list(revs, exclude, REV_CMD_MERGE_BASE,
 				     flags_exclude);
 		add_pending_commit_list(revs, exclude, flags_exclude);
sha1_name.c +1 -1
index a60eaf14d2..7675ec634f 100644
@@ -1266,7 +1266,7 @@ int get_oid_mb(const char *name, struct object_id *oid)
 	two = lookup_commit_reference_gently(the_repository, &oid_tmp, 0);
 	if (!two)
 		return -1;
-	mbs = get_merge_bases(one, two);
+	mbs = get_merge_bases(the_repository, one, two);
 	if (!mbs || mbs->next)
 		st = -1;
 	else {
submodule.c +1 -1
index f9426beff1..af4a1d2cea 100644
@@ -526,7 +526,7 @@ static void show_submodule_header(struct diff_options *o, const char *path,
 	     (!is_null_oid(two) && !*right))
 		message = "(commits not present)";
 
-	*merge_bases = get_merge_bases(*left, *right);
+	*merge_bases = get_merge_bases(the_repository, *left, *right);
 	if (*merge_bases) {
 		if ((*merge_bases)->item == *left)
 			fast_forward = 1;
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#206 lore raw

PATCH 172/194 commit: allow get_merge_bases to handle arbitrary repositories

In reply to Stefan Beller
---
 commit.c | 4 ++--
 commit.h | 3 +--
 2 files changed, 3 insertions(+), 4 deletions(-)
commit.c +2 -2
index 8b1e35d2a1..33f5442dc1 100644
@@ -1025,9 +1025,9 @@ struct commit_list *get_merge_bases_many_dirty(struct commit *one,
 	return get_merge_bases_many_0(the_repository, one, n, twos, 0);
 }
 
-struct commit_list *get_merge_bases_the_repository(struct commit *one, struct commit *two)
+struct commit_list *get_merge_bases(struct repository *r, struct commit *one, struct commit *two)
 {
-	return get_merge_bases_many_0(the_repository, one, 1, &two, 1);
+	return get_merge_bases_many_0(r, one, 1, &two, 1);
 }
 
 /*
commit.h +1 -2
index e671ce68db..7fe6bb0b22 100644
@@ -180,8 +180,7 @@ struct commit_graft *read_graft_line(struct strbuf *line);
 int register_commit_graft(struct repository *r, struct commit_graft *, int);
 struct commit_graft *lookup_commit_graft(struct repository *r, const struct object_id *oid);
 
-#define get_merge_bases(r, r1, r2) get_merge_bases_##r(r1, r2)
-extern struct commit_list *get_merge_bases_the_repository(struct commit *rev1, struct commit *rev2);
+extern struct commit_list *get_merge_bases(struct repository *r, struct commit *rev1, struct commit *rev2);
 extern struct commit_list *get_merge_bases_many(struct commit *one, int n, struct commit **twos);
 extern struct commit_list *get_octopus_merge_bases(struct commit_list *in);
 
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#207 lore raw

PATCH 173/194 blob: allow lookup_blob to handle arbitrary repositories

In reply to Stefan Beller
---
 blob.c | 10 +++++-----
 blob.h |  3 +--
 2 files changed, 6 insertions(+), 7 deletions(-)
blob.c +5 -5
index 7c661f178a..5dcaf63697 100644
@@ -4,13 +4,13 @@
 
 const char *blob_type = "blob";
 
-struct blob *lookup_blob_the_repository(const struct object_id *oid)
+struct blob *lookup_blob(struct repository *r, const struct object_id *oid)
 {
-	struct object *obj = lookup_object(the_repository, oid->hash);
+	struct object *obj = lookup_object(r, oid->hash);
 	if (!obj)
-		return create_object(the_repository, oid->hash,
-				     alloc_blob_node(the_repository));
-	return object_as_type(the_repository, obj, OBJ_BLOB, 0);
+		return create_object(r, oid->hash,
+				     alloc_blob_node(r));
+	return object_as_type(r, obj, OBJ_BLOB, 0);
 }
 
 int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size)
blob.h +1 -2
index 08bc34487a..1664872055 100644
@@ -9,8 +9,7 @@ struct blob {
 	struct object object;
 };
 
-#define lookup_blob(r, o) lookup_blob_##r(o)
-struct blob *lookup_blob_the_repository(const struct object_id *oid);
+struct blob *lookup_blob(struct repository *r, const struct object_id *oid);
 
 int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size);
 
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#208 lore raw

PATCH 174/194 tag: allow lookup_tag to handle arbitrary repositories

In reply to Stefan Beller
---
 tag.c | 10 +++++-----
 tag.h |  3 +--
 2 files changed, 6 insertions(+), 7 deletions(-)
tag.c +5 -5
index e0b695cb60..52009bf454 100644
@@ -92,13 +92,13 @@ struct object *deref_tag_noverify(struct object *o)
 	return o;
 }
 
-struct tag *lookup_tag_the_repository(const struct object_id *oid)
+struct tag *lookup_tag(struct repository *r, const struct object_id *oid)
 {
-	struct object *obj = lookup_object(the_repository, oid->hash);
+	struct object *obj = lookup_object(r, oid->hash);
 	if (!obj)
-		return create_object(the_repository, oid->hash,
-				     alloc_tag_node(the_repository));
-	return object_as_type(the_repository, obj, OBJ_TAG, 0);
+		return create_object(r, oid->hash,
+				     alloc_tag_node(r));
+	return object_as_type(r, obj, OBJ_TAG, 0);
 }
 
 static timestamp_t parse_tag_date(const char *buf, const char *tail)
tag.h +1 -2
index 4f45695e1e..d23af572d8 100644
@@ -11,8 +11,7 @@ struct tag {
 	char *tag;
 	timestamp_t date;
 };
-#define lookup_tag(r, o) lookup_tag_##r(o)
-extern struct tag *lookup_tag_the_repository(const struct object_id *oid);
+extern struct tag *lookup_tag(struct repository *r, const struct object_id *oid);
 #define parse_tag_buffer(r, i, d, s) parse_tag_buffer_##r(i, d, s)
 extern int parse_tag_buffer_the_repository(struct tag *item, const void *data, unsigned long size);
 extern int parse_tag(struct tag *item);
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#209 lore raw

PATCH 175/194 tag: allow parse_tag_buffer to handle arbitrary repositories

In reply to Stefan Beller
---
 tag.c | 10 +++++-----
 tag.h |  3 +--
 2 files changed, 6 insertions(+), 7 deletions(-)
tag.c +5 -5
index 52009bf454..96757f37dc 100644
@@ -118,7 +118,7 @@ static timestamp_t parse_tag_date(const char *buf, const char *tail)
 	return parse_timestamp(dateptr, NULL, 10);
 }
 
-int parse_tag_buffer_the_repository(struct tag *item, const void *data, unsigned long size)
+int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, unsigned long size)
 {
 	struct object_id oid;
 	char type[20];
@@ -146,13 +146,13 @@ int parse_tag_buffer_the_repository(struct tag *item, const void *data, unsigned
 	bufptr = nl + 1;
 
 	if (!strcmp(type, blob_type)) {
-		item->tagged = (struct object *)lookup_blob(the_repository, &oid);
+		item->tagged = (struct object *)lookup_blob(r, &oid);
 	} else if (!strcmp(type, tree_type)) {
-		item->tagged = (struct object *)lookup_tree(the_repository, &oid);
+		item->tagged = (struct object *)lookup_tree(r, &oid);
 	} else if (!strcmp(type, commit_type)) {
-		item->tagged = (struct object *)lookup_commit(the_repository, &oid);
+		item->tagged = (struct object *)lookup_commit(r, &oid);
 	} else if (!strcmp(type, tag_type)) {
-		item->tagged = (struct object *)lookup_tag(the_repository, &oid);
+		item->tagged = (struct object *)lookup_tag(r, &oid);
 	} else {
 		error("Unknown type %s", type);
 		item->tagged = NULL;
tag.h +1 -2
index d23af572d8..91208dd2d6 100644
@@ -12,8 +12,7 @@ struct tag {
 	timestamp_t date;
 };
 extern struct tag *lookup_tag(struct repository *r, const struct object_id *oid);
-#define parse_tag_buffer(r, i, d, s) parse_tag_buffer_##r(i, d, s)
-extern int parse_tag_buffer_the_repository(struct tag *item, const void *data, unsigned long size);
+extern int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, unsigned long size);
 extern int parse_tag(struct tag *item);
 #define deref_tag(r, o, w, l) deref_tag_##r(o, w, l)
 extern struct object *deref_tag_the_repository(struct object *, const char *, int);
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#210 lore raw

PATCH 176/194 object: allow parse_object_buffer to handle arbitrary repositories

In reply to Stefan Beller
---
 object.c | 18 +++++++++---------
 object.h |  3 +--
 2 files changed, 10 insertions(+), 11 deletions(-)
object.c +9 -9
index c2268990dd..2a05613c64 100644
@@ -184,21 +184,21 @@ struct object *lookup_unknown_object(struct repository *r,
 	return obj;
 }
 
-struct object *parse_object_buffer_the_repository(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p)
+struct object *parse_object_buffer(struct repository *r, const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p)
 {
 	struct object *obj;
 	*eaten_p = 0;
 
 	obj = NULL;
 	if (type == OBJ_BLOB) {
-		struct blob *blob = lookup_blob(the_repository, oid);
+		struct blob *blob = lookup_blob(r, oid);
 		if (blob) {
 			if (parse_blob_buffer(blob, buffer, size))
 				return NULL;
 			obj = &blob->object;
 		}
 	} else if (type == OBJ_TREE) {
-		struct tree *tree = lookup_tree(the_repository, oid);
+		struct tree *tree = lookup_tree(r, oid);
 		if (tree) {
 			obj = &tree->object;
 			if (!tree->buffer)
@@ -210,20 +210,20 @@ struct object *parse_object_buffer_the_repository(const struct object_id *oid, e
 			}
 		}
 	} else if (type == OBJ_COMMIT) {
-		struct commit *commit = lookup_commit(the_repository, oid);
+		struct commit *commit = lookup_commit(r, oid);
 		if (commit) {
-			if (parse_commit_buffer(the_repository, commit, buffer, size))
+			if (parse_commit_buffer(r, commit, buffer, size))
 				return NULL;
-			if (!get_cached_commit_buffer(the_repository, commit, NULL)) {
-				set_commit_buffer(the_repository, commit, buffer, size);
+			if (!get_cached_commit_buffer(r, commit, NULL)) {
+				set_commit_buffer(r, commit, buffer, size);
 				*eaten_p = 1;
 			}
 			obj = &commit->object;
 		}
 	} else if (type == OBJ_TAG) {
-		struct tag *tag = lookup_tag(the_repository, oid);
+		struct tag *tag = lookup_tag(r, oid);
 		if (tag) {
-			if (parse_tag_buffer(the_repository, tag, buffer, size))
+			if (parse_tag_buffer(r, tag, buffer, size))
 			       return NULL;
 			obj = &tag->object;
 		}
object.h +1 -2
index 14e0d412bb..a5456fc2d7 100644
@@ -174,8 +174,7 @@ struct object *parse_object_or_die(const struct object_id *oid, const char *name
  * parsing it.  eaten_p indicates if the object has a borrowed copy
  * of buffer and the caller should not free() it.
  */
-#define parse_object_buffer(r, o, t, s, b, e) parse_object_buffer_##r(o, t, s, b, e)
-struct object *parse_object_buffer_the_repository(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p);
+struct object *parse_object_buffer(struct repository *r, const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p);
 
 /** Returns the object, with potentially excess memory allocated. **/
 struct object *lookup_unknown_object(struct repository *r, const unsigned char *sha1);
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#211 lore raw

PATCH 177/194 objects: allow check_sha1_signature to handle arbitrary repositories

In reply to Stefan Beller
---
 object-store.h | 3 +--
 sha1_file.c    | 4 ++--
 2 files changed, 3 insertions(+), 4 deletions(-)
object-store.h +1 -2
index 47c38170e3..62763b8412 100644
@@ -108,8 +108,7 @@ extern void *map_sha1_file(struct repository *r, const unsigned char *sha1, unsi
  * The in-core object data should be in "map". If "map" == NULL, reads the
  * named object using the streaming interface and rehashes it on the fly.
  */
-#define check_sha1_signature(r, s, m, sz, t) check_sha1_signature_##r(s, m, sz, t)
-extern int check_sha1_signature_the_repository(const unsigned char *sha1, void *buf, unsigned long size, const char *type);
+extern int check_sha1_signature(struct repository *r, const unsigned char *sha1, void *buf, unsigned long size, const char *type);
 
 /*
  * Convenience for sha1_object_info_extended() with a NULL struct
sha1_file.c +2 -2
index 8638fae9c4..1cf173da16 100644
@@ -801,7 +801,7 @@ void *xmmap(void *start, size_t length,
 	return ret;
 }
 
-int check_sha1_signature_the_repository(const unsigned char *sha1, void *map,
+int check_sha1_signature(struct repository *r, const unsigned char *sha1, void *map,
 			 unsigned long size, const char *type)
 {
 	unsigned char real_sha1[20];
@@ -816,7 +816,7 @@ int check_sha1_signature_the_repository(const unsigned char *sha1, void *map,
 		return hashcmp(sha1, real_sha1) ? -1 : 0;
 	}
 
-	st = open_istream(the_repository, sha1, &obj_type, &size, NULL);
+	st = open_istream(r, sha1, &obj_type, &size, NULL);
 	if (!st)
 		return -1;
 
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#212 lore raw

PATCH 178/194 object: allow parse_object to handle arbitrary repositories

In reply to Stefan Beller
---
 object.c | 20 ++++++++++----------
 object.h |  3 +--
 2 files changed, 11 insertions(+), 12 deletions(-)
object.c +10 -10
index 2a05613c64..2fe5fac3ce 100644
@@ -244,39 +244,39 @@ struct object *parse_object_or_die(const struct object_id *oid,
 	die(_("unable to parse object: %s"), name ? name : oid_to_hex(oid));
 }
 
-struct object *parse_object_the_repository(const struct object_id *oid)
+struct object *parse_object(struct repository *r, const struct object_id *oid)
 {
 	unsigned long size;
 	enum object_type type;
 	int eaten;
-	const unsigned char *repl = lookup_replace_object(the_repository, oid->hash);
+	const unsigned char *repl = lookup_replace_object(r, oid->hash);
 	void *buffer;
 	struct object *obj;
 
-	obj = lookup_object(the_repository, oid->hash);
+	obj = lookup_object(r, oid->hash);
 	if (obj && obj->parsed)
 		return obj;
 
 	if ((obj && obj->type == OBJ_BLOB) ||
 	    (!obj && has_object_file(oid) &&
-	     sha1_object_info(the_repository, oid->hash, NULL) == OBJ_BLOB)) {
-		if (check_sha1_signature(the_repository, repl, NULL, 0, NULL) < 0) {
+	     sha1_object_info(r, oid->hash, NULL) == OBJ_BLOB)) {
+		if (check_sha1_signature(r, repl, NULL, 0, NULL) < 0) {
 			error("sha1 mismatch %s", oid_to_hex(oid));
 			return NULL;
 		}
-		parse_blob_buffer(lookup_blob(the_repository, oid), NULL, 0);
-		return lookup_object(the_repository, oid->hash);
+		parse_blob_buffer(lookup_blob(r, oid), NULL, 0);
+		return lookup_object(r, oid->hash);
 	}
 
-	buffer = read_sha1_file(the_repository, oid->hash, &type, &size);
+	buffer = read_sha1_file(r, oid->hash, &type, &size);
 	if (buffer) {
-		if (check_sha1_signature(the_repository, repl, buffer, size, typename(type)) < 0) {
+		if (check_sha1_signature(r, repl, buffer, size, typename(type)) < 0) {
 			free(buffer);
 			error("sha1 mismatch %s", sha1_to_hex(repl));
 			return NULL;
 		}
 
-		obj = parse_object_buffer(the_repository, oid, type, size,
+		obj = parse_object_buffer(r, oid, type, size,
 					  buffer, &eaten);
 		if (!eaten)
 			free(buffer);
object.h +1 -2
index a5456fc2d7..900f1b6611 100644
@@ -160,8 +160,7 @@ extern void *read_object_with_reference(const unsigned char *sha1,
  *
  * Returns NULL if the object is missing or corrupt.
  */
-#define parse_object(r, oid) parse_object_##r(oid)
-struct object *parse_object_the_repository(const struct object_id *oid);
+struct object *parse_object(struct repository *r, const struct object_id *oid);
 
 /*
  * Like parse_object, but will die() instead of returning NULL. If the
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#213 lore raw

PATCH 179/194 tag: allow deref_tag to handle arbitrary repositories

In reply to Stefan Beller
---
 tag.c | 5 ++---
 tag.h | 3 +--
 2 files changed, 3 insertions(+), 5 deletions(-)
tag.c +2 -3
index 96757f37dc..d2b2bbb79c 100644
@@ -64,12 +64,11 @@ int gpg_verify_tag(const struct object_id *oid, const char *name_to_report,
 	return ret;
 }
 
-struct object *deref_tag_the_repository(struct object *o, const char *warn, int warnlen)
+struct object *deref_tag(struct repository *r, struct object *o, const char *warn, int warnlen)
 {
 	while (o && o->type == OBJ_TAG)
 		if (((struct tag *)o)->tagged)
-			o = parse_object(the_repository,
-					 &((struct tag *)o)->tagged->oid);
+			o = parse_object(r, &((struct tag *)o)->tagged->oid);
 		else
 			o = NULL;
 	if (!o && warn) {
tag.h +1 -2
index 91208dd2d6..91bb163e26 100644
@@ -14,8 +14,7 @@ struct tag {
 extern struct tag *lookup_tag(struct repository *r, const struct object_id *oid);
 extern int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, unsigned long size);
 extern int parse_tag(struct tag *item);
-#define deref_tag(r, o, w, l) deref_tag_##r(o, w, l)
-extern struct object *deref_tag_the_repository(struct object *, const char *, int);
+extern struct object *deref_tag(struct repository *r, struct object *, const char *, int);
 extern struct object *deref_tag_noverify(struct object *);
 extern int gpg_verify_tag(const struct object_id *oid,
 		const char *name_to_report, unsigned flags);
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#214 lore raw

PATCH 180/194 commit: allow lookup_commit_reference_gently to handle arbitrary repositories

In reply to Stefan Beller
---
 commit.c | 8 +++-----
 commit.h | 4 +---
 2 files changed, 4 insertions(+), 8 deletions(-)
commit.c +3 -5
index 33f5442dc1..426cbc9b55 100644
@@ -21,16 +21,14 @@ int save_commit_buffer = 1;
 
 const char *commit_type = "commit";
 
-struct commit *lookup_commit_reference_gently_the_repository(
+struct commit *lookup_commit_reference_gently(struct repository *r,
 		const struct object_id *oid, int quiet)
 {
-	struct object *obj = deref_tag(the_repository,
-				       parse_object(the_repository, oid),
+	struct object *obj = deref_tag(r, parse_object(r, oid),
 				       NULL, 0);
-
 	if (!obj)
 		return NULL;
-	return object_as_type(the_repository, obj, OBJ_COMMIT, quiet);
+	return object_as_type(r, obj, OBJ_COMMIT, quiet);
 }
 
 struct commit *lookup_commit_reference_the_repository(const struct object_id *oid)
commit.h +1 -3
index 7fe6bb0b22..154c61f111 100644
@@ -50,9 +50,7 @@ struct commit *lookup_commit(struct repository *r, const struct object_id *oid);
 #define lookup_commit_reference(r, o) \
 		lookup_commit_reference_##r(o)
 struct commit *lookup_commit_reference_the_repository(const struct object_id *oid);
-#define lookup_commit_reference_gently(r, o, q) \
-		lookup_commit_reference_gently_##r(o, q)
-struct commit *lookup_commit_reference_gently_the_repository(
+struct commit *lookup_commit_reference_gently(struct repository *r,
 					      const struct object_id *oid,
 					      int quiet);
 struct commit *lookup_commit_reference_by_name(const char *name);
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#215 lore raw

PATCH 181/194 commit: allow lookup_commit_reference to handle arbitrary repositories

In reply to Stefan Beller
---
 commit.c | 4 ++--
 commit.h | 4 +---
 2 files changed, 3 insertions(+), 5 deletions(-)
commit.c +2 -2
index 426cbc9b55..ac65c1dbd7 100644
@@ -31,9 +31,9 @@ struct commit *lookup_commit_reference_gently(struct repository *r,
 	return object_as_type(r, obj, OBJ_COMMIT, quiet);
 }
 
-struct commit *lookup_commit_reference_the_repository(const struct object_id *oid)
+struct commit *lookup_commit_reference(struct repository *r, const struct object_id *oid)
 {
-	return lookup_commit_reference_gently(the_repository, oid, 0);
+	return lookup_commit_reference_gently(r, oid, 0);
 }
 
 struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref_name)
commit.h +1 -3
index 154c61f111..d2d5e66b53 100644
@@ -47,9 +47,7 @@ void add_name_decoration(enum decoration_type type, const char *name, struct obj
 const struct name_decoration *get_name_decoration(const struct object *obj);
 
 struct commit *lookup_commit(struct repository *r, const struct object_id *oid);
-#define lookup_commit_reference(r, o) \
-		lookup_commit_reference_##r(o)
-struct commit *lookup_commit_reference_the_repository(const struct object_id *oid);
+struct commit *lookup_commit_reference(struct repository *r,const struct object_id *oid);
 struct commit *lookup_commit_reference_gently(struct repository *r,
 					      const struct object_id *oid,
 					      int quiet);
Signature · 1 line
2.15.1.433.g936d1b9894.dirty