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 1 of 3

lore
Share & tools
lore
#0 lore raw

cover Moving global state into the repository object

This series moves a lot of global state into the repository struct. It applies on top of 2512f15446149235156528dafbe75930c712b29e (2.16.0) It can be found at https://github.com/stefanbeller/git/tree/object-store

Motivation for this series:
* Easier to reason about code when all state is stored in one place, for example for multithreading
* Easier to move to processing submodules in-process instead of calling a processes for the submodule handling.
The last patch demonstrates this.

Usually when approaching large refactoring series, a lot of tedious review work is involved and yet it is hard to be convinced the series did everything right.

When reviewing this series in particular it is hard to be convinced if any function that is converted to take the repository as an argument is fully converted or if there are any hidden dependencies that are not obvious from code review.

This is why this series tries to be reviewer friendly by utilizing machine assistance as much as possible. There are 3 types of patches in this series:

(A) <area>: add repository argument to <function_foo>
This sort of patch is just adding the repository as an argument to that function. It assumes the given repository is the_repository and has a compile time check for that assertion using a preprocessor trick. As did a compile check after each commit of the series, I don't expect the review burden on these patches to be high. Review on these patches is mostly checking for formatting errors or if I sneak in malicious code -- if you're inclined to believe that.

(B) <area>: allow <function_foo> to handle arbitrary repositories This sort of patch is touching code inside the given function only, usually replacing all occurrences of the_repository by the argument r. Here the review is critical: Did I miss any function that relies on state of the_repository ?
This series was developed by converting all functions of packfile/sha1-file/commit/etc using (A); after the demo patch was possible, all patches that did (A), but not (B) were deleted. Therefore I was confident at time of writing that patch that the conversion of a function which doesn't take a repository argument is okay.

(C) other patches, such as moving code around,
demoing this series in the last patch

This approach was chosen as I think it is review friendly, despite the huge number of patches.

A weakness of this approach is the buildup of a large series, which ignores the ongoing development. Rebasing that series turned out to be ok, but merging it with confidence is an issue.

This series was developed partially as a pair programming exercise with Jonathan Nieder and Brandon Williams.

The idea with the #define trick to separate the two very separate issues of touching a lot of code and reasoning about its correctness (hidden deps) is mostly from Jonathan Tan.

Any suggestions welcome!

Thanks,
Stefan

Brandon Williams (4):
sha1_file: allow add_to_alternates_file to handle arbitrary
repositories
commit: convert commit_graft_pos() to handle arbitrary repositories
commit: convert register_commit_graft to handle arbitrary repositories
commit: convert read_graft_file to handle arbitrary repositories

Jonathan Nieder (50):
object-store: move packed_git and packed_git_mru to object store
pack: move prepare_packed_git_run_once to object store
pack: move approximate object count to object store
pack: add repository argument to install_packed_git
pack: add repository argument to prepare_packed_git_one
pack: add repository argument to rearrange_packed_git
pack: add repository argument to prepare_packed_git_mru
pack: add repository argument to prepare_packed_git
pack: add repository argument to reprepare_packed_git
pack: add repository argument to sha1_file_name
pack: add repository argument to map_sha1_file
sha1_file: allow alt_odb_usable to handle arbitrary repositories
pack: allow install_packed_git to handle arbitrary repositories
pack: allow rearrange_packed_git to handle arbitrary repositories
pack: allow prepare_packed_git_mru to handle arbitrary repositories
pack: allow prepare_packed_git_one to handle arbitrary repositories
pack: allow prepare_packed_git to handle arbitrary repositories
pack: allow reprepare_packed_git to handle arbitrary repositories
pack: allow sha1_file_name to handle arbitrary repositories
pack: allow stat_sha1_file to handle arbitrary repositories
pack: allow open_sha1_file to handle arbitrary repositories
pack: allow map_sha1_file_1 to handle arbitrary repositories
pack: allow map_sha1_file to handle arbitrary repositories
pack: allow sha1_loose_object_info to handle arbitrary repositories
sha1_file: add repository argument to sha1_object_info_extended
object-store: move alternates API to new alternates.h
object-store: move loose object functions to new loose-object.h
pack: move struct pack_window and pack_entry to packfile.h
object-store: move replace_objects back to object-store
object-store: move lookup_replace_object to replace-object.h
pack: add repository argument to packed_object_info
pack: add repository argument to find_pack_entry
object: add repository argument to lookup_object
object: add repository argument to grow_object_hash
object: add repository argument to lookup_commit_reference_gently
object: add repository argument to lookup_commit
object: move grafts to object parser
object: add repository argument to commit_graft_pos
object: add repository argument to register_commit_graft
object: add repository argument to read_graft_file
object: add repository argument to prepare_commit_graft
object: add repository argument to lookup_commit_graft
object: add repository argument to lookup_unknown_object Rename sha1_object_info.cocci to object_store.cocci
alternates: add repository argument to add_to_alternates_memory
object-store: move check_sha1_signature to object-store.h
object-store: add repository argument to check_sha1_signature
object-store: add repository argument to read_object
object-store: add repository argument to read_sha1_file_extended
object: move read_object_with_reference to object.h

Stefan Beller (140):
repository: introduce object store field
object-store: move alt_odb_list and alt_odb_tail to object store
sha1_file: add repository argument to alt_odb_usable
sha1_file: add repository argument to link_alt_odb_entry
sha1_file: add repository argument to read_info_alternates
sha1_file: add repository argument to link_alt_odb_entries
sha1_file: add repository argument to stat_sha1_file
sha1_file: add repository argument to open_sha1_file
sha1_file: add repository argument to map_sha1_file_1
sha1_file: add repository argument to sha1_loose_object_info
object-store: add repository argument to prepare_alt_odb
object-store: add repository argument to foreach_alt_odb
object-store: allow prepare_alt_odb to handle arbitrary repositories
object-store: allow foreach_alt_odb to handle arbitrary repositories replace_object.c: rename to use dash in file name
replace-object: move replace_object to object store
object-store: move object access functions to object-store.h
replace-object: add repository argument to do_lookup_replace_object
replace-object: move replace objects prepared flag to object store
replace-object: check_replace_refs is safe in multi repo environment
refs: add repository argument to for_each_replace_ref
refs: add repository argument to get_main_ref_store
replace-object: add repository argument to register_replace_object
replace-object: add repository argument to register_replace_ref
replace-object: add repository argument to replace_object_pos
replace-object: allow replace_object_pos to handle arbitrary
repositories
replace-object: allow register_replace_object to handle arbitrary
repositories
replace-object: add repository argument to prepare_replace_object
refs: store the main ref store inside the repository struct
refs: allow for_each_replace_ref to handle arbitrary repositories
replace-object: allow prepare_replace_object to handle arbitrary
repositories
replace_object: allow do_lookup_replace_object to handle arbitrary
repositories
replace-object: add repository argument to lookup_replace_object
repository: allow lookup_replace_object to handle arbitrary
repositories
object-store: add repository argument to sha1_object_info
pack: add repository argument to retry_bad_packed_offset
pack: add repository argument to packed_to_object_type
packfile: add repository argument to read_object
packfile: add repository argument to unpack_entry
packfile: add repository argument to cache_or_unpack_entry
pack: allow find_pack_entry to handle arbitrary repositories
object-store: allow sha1_object_info to handle arbitrary repositories fetch, push: do not use submodule as alternate in has_commits check
push: add test showing bad interaction of replace refs and submodules
replace_object: allow register_replace_ref to handle arbitrary
repositories
cache.h: migrate the definition of object_id to object.h
repository: introduce object parser field
object: add repository argument to parse_object
object: add repository argument to create_object
blob: add repository argument to lookup_blob
tree: add repository argument to lookup_tree
tag: add repository argument to lookup_tag
tag: add repository argument to parse_tag_buffer
tag: add repository argument to deref_tag
object: add repository argument to lookup_commit_reference
commit: add repository argument to parse_commit_buffer
object: allow grow_object_hash to handle arbitrary repositories
object: allow create_object to handle arbitrary repositories
object: allow lookup_object to handle arbitrary repositories
object: allow lookup_unknown_object to handle arbitrary repositories
object: add repository argument to parse_object_buffer
repository: keep track of all open repositories
alternates: add repository argument to add_to_alternates_file
object-store: add repository argument to read_sha1_file
packfile: add repository argument to has_packed_and_bad
packfile: allow has_packed_and_bad to handle arbitrary repositories
streaming: add repository argument to open_istream_fn
streaming: add repository argument to open_istream
streaming: add repository argument to istream_source
streaming: allow istream_source to handle arbitrary repositories
sha1_file: allow read_object to handle arbitrary repositories object-store.h: allow read_sha1_file{_extended} to handle arbitrary
repositories
streaming: allow open_istream_incore to handle arbitrary repositories
streaming: allow open_istream_pack_non_delta to handle arbitrary
repositories
streaming: allow open_istream_loose to handle arbitrary repositories
streaming: allow open_istream to handle arbitrary repositories
alternates: convert add_to_alternates_memory to handle arbitrary repos
object: add repository argument to object_as_type
alloc: add repository argument to alloc_blob_node
alloc: add repository argument to alloc_tree_node
alloc: add repository argument to alloc_commit_node
alloc: add repository argument to alloc_tag_node
alloc: add repository argument to alloc_object_node
alloc: add repository argument to alloc_report
alloc: add repository argument to alloc_commit_index
alloc: allow arbitrary repositories for alloc functions
object: allow object_as_type to handle arbitrary repositories
commit: allow lookup_commit to handle arbitrary repositories
object: add repository argument to parse_commit_gently
commit: add repository argument to parse_commit
commit: add repository argument to set_commit_buffer
commit: add repository argument to get_cached_commit_buffer
commit: add repository argument to unuse_commit_buffer
commit: add repository argument to free_commit_buffer
commit: allow commit buffer functions to handle arbitrary repositories
tree: allow lookup_tree to handle arbitrary repositories
cache: convert get_graft_file to handle arbitrary repositories
shallow: add repository argument to set_alternate_shallow_file
shallow: add repository argument to register_shallow
shallow: add repository argument to check_shallow_file_for_update
shallow: add repository argument to is_repository_shallow migrate cached path to use the_repository
shallow: migrate shallow information into the object parser
commit: allow prepare_commit_graft to handle arbitrary repositories
commit: allow lookup_commit_graft to handle arbitrary repositories
commit: allow arbitrary repository argument for parse_commit_buffer
commit: allow parse_commit_gently to handle arbitrary repository
commit: add repository argument to get_merge_bases_many_0
commit: add repository argument to merge_bases_many
commit: add repository argument to paint_down_to_common
commit: allow parse_commit to handle arbitrary repositories
commit: allow paint_down_to_common to handle arbitrary repositories
commit: allow merge_bases_many to handle arbitrary repositories
commit: add repository argument to remove_redundant
commit: allow remove_redundant to handle arbitrary repositories
commit: allow get_merge_bases_many_0 to handle arbitrary repositories
commit: add repository argument to get_merge_bases
commit: allow get_merge_bases to handle arbitrary repositories
blob: allow lookup_blob to handle arbitrary repositories
tag: allow lookup_tag to handle arbitrary repositories
tag: allow parse_tag_buffer to handle arbitrary repositories
object: allow parse_object_buffer to handle arbitrary repositories
objects: allow check_sha1_signature to handle arbitrary repositories
object: allow parse_object to handle arbitrary repositories
tag: allow deref_tag to handle arbitrary repositories
commit: allow lookup_commit_reference_gently to handle arbitrary
repositories
commit: allow lookup_commit_reference to handle arbitrary repositories
commit: add repository argument to get_commit_buffer
commit: add repository argument to logmsg_reencode
pretty: add repository argument to format_commit_message
commit: allow get_commit_buffer to handle arbitrary repositories
pretty: allow logmsg_reencode to handle arbitrary repositories
commit: add repository argument to in_merge_bases_many
commit: add repository argument to in_merge_bases
commit: allow in_merge_bases_many to handle arbitrary repositories
commit: allow in_merge_bases to handle arbitrary repositories
pretty: allow format_commit_message to handle arbitrary repositories
submodule: add repository argument to print_submodule_summary
submodule: Reorder open_submodule function
submodule: use submodule repos for object lookup

 Makefile                                   |   2 +-
 alloc.c                                    |  48 +++--
 alternates.h                               |  68 +++++++
 apply.c                                    |   8 +-
 archive-tar.c                              |   6 +-
 archive-zip.c                              |   8 +-
 archive.c                                  |   9 +-
 bisect.c                                   |   6 +-
 blame.c                                    |  40 ++--
 blob.c                                     |  10 +-
 blob.h                                     |   2 +-
 branch.c                                   |  16 +-
 builtin/am.c                               |  14 +-
 builtin/blame.c                            |   9 +-
 builtin/branch.c                           |  11 +-
 builtin/cat-file.c                         |  28 ++-
 builtin/checkout.c                         |  12 +-
 builtin/clone.c                            |  14 +-
 builtin/commit-tree.c                      |   5 +-
 builtin/commit.c                           |  63 +++---
 builtin/count-objects.c                    |  12 +-
 builtin/describe.c                         |  19 +-
 builtin/diff-tree.c                        |   9 +-
 builtin/diff.c                             |   7 +-
 builtin/difftool.c                         |   5 +-
 builtin/fast-export.c                      |  30 +--
 builtin/fetch.c                            |  21 +-
 builtin/fmt-merge-msg.c                    |  19 +-
 builtin/fsck.c                             |  44 ++--
 builtin/gc.c                               |   8 +-
 builtin/grep.c                             |  10 +-
 builtin/hash-object.c                      |   1 +
 builtin/index-pack.c                       |  26 ++-
 builtin/log.c                              |  26 ++-
 builtin/ls-files.c                         |   2 +-
 builtin/ls-tree.c                          |   4 +-
 builtin/merge-base.c                       |  11 +-
 builtin/merge-tree.c                       |  12 +-
 builtin/merge.c                            |  41 ++--
 builtin/mktag.c                            |  10 +-
 builtin/mktree.c                           |   4 +-
 builtin/name-rev.c                         |  15 +-
 builtin/notes.c                            |  16 +-
 builtin/pack-objects.c                     |  66 +++---
 builtin/pack-redundant.c                   |   8 +-
 builtin/pack-refs.c                        |   3 +-
 builtin/prune-packed.c                     |   1 +
 builtin/prune.c                            |   8 +-
 builtin/pull.c                             |  19 +-
 builtin/receive-pack.c                     |  14 +-
 builtin/reflog.c                           |  21 +-
 builtin/remote.c                           |   1 +
 builtin/replace.c                          |  24 ++-
 builtin/reset.c                            |  11 +-
 builtin/rev-list.c                         |   7 +-
 builtin/rev-parse.c                        |  11 +-
 builtin/shortlog.c                         |   5 +-
 builtin/show-branch.c                      |   9 +-
 builtin/show-ref.c                         |   1 +
 builtin/submodule--helper.c                |   5 +-
 builtin/tag.c                              |  12 +-
 builtin/unpack-file.c                      |   4 +-
 builtin/unpack-objects.c                   |  15 +-
 builtin/verify-commit.c                    |   7 +-
 bulk-checkin.c                             |   3 +-
 bundle.c                                   |   9 +-
 cache-tree.c                               |   4 +-
 cache.h                                    | 315 ++---------------------------
 combine-diff.c                             |   5 +-
 commit.c                                   | 241 ++++++++++++----------
 commit.h                                   |  49 +++--
 config.c                                   |   2 +-
 contrib/coccinelle/cached_path.cocci       |  44 ++++
 contrib/coccinelle/object_parser.cocci     | 125 ++++++++++++
 contrib/coccinelle/object_store.cocci      |  74 +++++++
 contrib/coccinelle/packed_git.cocci        |  15 ++
 contrib/coccinelle/submodule_reading.cocci |  34 ++++
 convert.c                                  |   1 +
 diff.c                                     |   8 +-
 diffcore-rename.c                          |   1 +
 dir.c                                      |   4 +-
 entry.c                                    |   5 +-
 environment.c                              |  10 +-
 fast-import.c                              |  45 +++--
 fetch-pack.c                               |  47 +++--
 fsck.c                                     |  20 +-
 git.c                                      |   2 +-
 grep.c                                     |   5 +-
 http-backend.c                             |  12 +-
 http-push.c                                |  24 ++-
 http-walker.c                              |   5 +-
 http.c                                     |  10 +-
 line-log.c                                 |   2 +-
 list-objects-filter.c                      |   2 +-
 list-objects.c                             |   4 +-
 log-tree.c                                 |  18 +-
 loose-object.h                             |  91 +++++++++
 mailmap.c                                  |   4 +-
 match-trees.c                              |   6 +-
 merge-blobs.c                              |   8 +-
 merge-recursive.c                          |  30 +--
 mru.h                                      |   1 +
 notes-cache.c                              |   9 +-
 notes-merge.c                              |  15 +-
 notes-utils.c                              |   6 +-
 notes.c                                    |  12 +-
 object-store.h                             | 183 +++++++++++++++++
 object.c                                   | 106 +++++-----
 object.h                                   |  82 +++++++-
 pack-bitmap-write.c                        |   7 +-
 pack-bitmap.c                              |   6 +-
 pack-check.c                               |   6 +-
 pack-revindex.c                            |   1 +
 pack.h                                     |   1 +
 packfile.c                                 | 149 ++++++++------
 packfile.h                                 |  41 +++-
 parse-options-cb.c                         |   2 +-
 path.c                                     |  18 +-
 path.h                                     |  40 +++-
 pretty.c                                   |  24 ++-
 pretty.h                                   |   2 +-
 reachable.c                                |  12 +-
 read-cache.c                               |   7 +-
 ref-filter.c                               |  15 +-
 reflog-walk.c                              |   3 +-
 refs.c                                     |  87 ++++----
 refs.h                                     |   4 +-
 refs/files-backend.c                       |   2 +-
 remote-testsvn.c                           |   6 +-
 remote.c                                   |  27 ++-
 replace_object.c => replace-object.c       |  70 +++----
 replace-object.h                           |  34 ++++
 repository.c                               |  84 ++++++--
 repository.h                               |  33 ++-
 rerere.c                                   |  12 +-
 revision.c                                 |  48 ++---
 send-pack.c                                |   7 +-
 sequencer.c                                |  93 +++++----
 server-info.c                              |  12 +-
 sha1_file.c                                | 236 +++++++++++----------
 sha1_name.c                                |  75 ++++---
 shallow.c                                  | 113 ++++++-----
 streaming.c                                |  33 +--
 streaming.h                                |   2 +-
 submodule-config.c                         |   3 +-
 submodule.c                                | 100 +++++----
 t/helper/test-example-decorate.c           |   6 +-
 t/helper/test-ref-store.c                  |   6 +-
 t/helper/test-revision-walking.c           |   2 +-
 t/t5531-deep-submodule-push.sh             |  16 ++
 tag.c                                      |  36 ++--
 tag.h                                      |   7 +-
 tmp-objdir.c                               |   4 +-
 transport.c                                |   5 +-
 tree-walk.c                                |   5 +-
 tree.c                                     |  24 ++-
 tree.h                                     |   2 +-
 upload-pack.c                              |  25 ++-
 walker.c                                   |  17 +-
 wt-status.c                                |  10 +-
 xdiff-interface.c                          |   4 +-
 161 files changed, 2669 insertions(+), 1596 deletions(-)
 create mode 100644 alternates.h
 create mode 100644 contrib/coccinelle/cached_path.cocci
 create mode 100644 contrib/coccinelle/object_parser.cocci
 create mode 100644 contrib/coccinelle/object_store.cocci
 create mode 100644 contrib/coccinelle/packed_git.cocci
 create mode 100644 contrib/coccinelle/submodule_reading.cocci
 create mode 100644 loose-object.h
 create mode 100644 object-store.h
 rename replace_object.c => replace-object.c (55%)
 create mode 100644 replace-object.h
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#1 lore raw

PATCH 1/194 repository: introduce object store field

The object store field will contain any objects needed for access to objects in a given repository.

This patch introduces the object store but for now it is empty. C99 forbids empty structs, but common C compilers cope well with them and this struct will gain members very soon (starting with the next patch).

---
 object-store.h | 8 ++++++++
 repository.c   | 4 +++-
 repository.h   | 7 +++++++
 3 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100644 object-store.h
object-store.h new file +8 -0
new file mode 100644
index 0000000000..05722cdde0
@@ -0,0 +1,8 @@
+#ifndef OBJECT_STORE_H
+#define OBJECT_STORE_H
+
+struct object_store {
+};
+#define OBJECT_STORE_INIT {}
+
+#endif /* OBJECT_STORE_H */
repository.c +3 -1
index 998413b8bb..0ec9648f53 100644
@@ -1,11 +1,13 @@
 #include "cache.h"
 #include "repository.h"
+#include "object-store.h"
 #include "config.h"
 #include "submodule-config.h"
 
 /* The main repository */
 static struct repository the_repo = {
-	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &the_index, NULL, 0, 0
+	NULL, NULL, NULL, OBJECT_STORE_INIT,
+	NULL, NULL, NULL, NULL, NULL, NULL, &the_index, NULL, 0, 0
 };
 struct repository *the_repository = &the_repo;
 
repository.h +7 -0
index 0329e40c7f..ba7b3b7cb9 100644
@@ -1,6 +1,8 @@
 #ifndef REPOSITORY_H
 #define REPOSITORY_H
 
+#include "object-store.h"
+
 struct config_set;
 struct index_state;
 struct submodule_cache;
@@ -26,6 +28,11 @@ struct repository {
 	 */
 	char *objectdir;
 
+	/*
+	 * Holds any information related to the object store.
+	 */
+	struct object_store objects;
+
 	/*
 	 * Path to the repository's graft file.
 	 * Cannot be NULL after initialization.
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#2 lore raw

PATCH 2/194 object-store: move alt_odb_list and alt_odb_tail to object store

In reply to Stefan Beller

In a process with multiple repositories open, alternates should be associated to a single repository and not shared globally. Move alt_odb_list and alt_odb_tail into the_repository and adjust callers to reflect this.

No functional change intended.

---
 builtin/fsck.c |  4 +++-
 cache.h        |  4 ++--
 object-store.h |  6 +++++-
 packfile.c     |  3 ++-
 sha1_file.c    | 25 ++++++++++++-------------
 sha1_name.c    |  3 ++-
 6 files changed, 26 insertions(+), 19 deletions(-)
builtin/fsck.c +3 -1
index 04846d46f9..1048255da1 100644
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "repository.h"
 #include "config.h"
 #include "commit.h"
 #include "tree.h"
@@ -694,7 +695,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
 		fsck_object_dir(get_object_directory());
 
 		prepare_alt_odb();
-		for (alt = alt_odb_list; alt; alt = alt->next)
+		for (alt = the_repository->objects.alt_odb_list;
+				alt; alt = alt->next)
 			fsck_object_dir(alt->path);
 
 		if (check_full) {
cache.h +2 -2
index d8b975a571..918c2f15b4 100644
@@ -1573,7 +1573,7 @@ extern int has_dirs_only_path(const char *name, int len, int prefix_len);
 extern void schedule_dir_for_removal(const char *name, int len);
 extern void remove_scheduled_dirs(void);
 
-extern struct alternate_object_database {
+struct alternate_object_database {
 	struct alternate_object_database *next;
 
 	/* see alt_scratch_buf() */
@@ -1591,7 +1591,7 @@ extern struct alternate_object_database {
 	struct oid_array loose_objects_cache;
 
 	char path[FLEX_ARRAY];
-} *alt_odb_list;
+};
 extern void prepare_alt_odb(void);
 extern char *compute_alternate_path(const char *path, struct strbuf *err);
 typedef int alt_odb_fn(struct alternate_object_database *, void *);
object-store.h +5 -1
index 05722cdde0..ace3efbfab 100644
@@ -1,8 +1,12 @@
 #ifndef OBJECT_STORE_H
 #define OBJECT_STORE_H
 
+#include "cache.h"
+
 struct object_store {
+	struct alternate_object_database *alt_odb_list;
+	struct alternate_object_database **alt_odb_tail;
 };
-#define OBJECT_STORE_INIT {}
+#define OBJECT_STORE_INIT { NULL, NULL }
 
 #endif /* OBJECT_STORE_H */
packfile.c +2 -1
index 4a5fe7ab18..d61076faaf 100644
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "mru.h"
 #include "pack.h"
+#include "repository.h"
 #include "dir.h"
 #include "mergesort.h"
 #include "packfile.h"
@@ -880,7 +881,7 @@ void prepare_packed_git(void)
 		return;
 	prepare_packed_git_one(get_object_directory(), 1);
 	prepare_alt_odb();
-	for (alt = alt_odb_list; alt; alt = alt->next)
+	for (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next)
 		prepare_packed_git_one(alt->path, 0);
 	rearrange_packed_git();
 	prepare_packed_git_mru();
sha1_file.c +12 -13
index 3da70ac650..2826d5d6ed 100644
@@ -22,6 +22,7 @@
 #include "pack-revindex.h"
 #include "sha1-lookup.h"
 #include "bulk-checkin.h"
+#include "repository.h"
 #include "streaming.h"
 #include "dir.h"
 #include "mru.h"
@@ -346,9 +347,6 @@ static const char *alt_sha1_path(struct alternate_object_database *alt,
 	return buf->buf;
 }
 
-struct alternate_object_database *alt_odb_list;
-static struct alternate_object_database **alt_odb_tail;
-
 /*
  * Return non-zero iff the path is usable as an alternate object database.
  */
@@ -368,7 +366,7 @@ static int alt_odb_usable(struct strbuf *path, const char *normalized_objdir)
 	 * Prevent the common mistake of listing the same
 	 * thing twice, or object directory itself.
 	 */
-	for (alt = alt_odb_list; alt; alt = alt->next) {
+	for (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next) {
 		if (!fspathcmp(path->buf, alt->path))
 			return 0;
 	}
@@ -428,8 +426,8 @@ static int link_alt_odb_entry(const char *entry, const char *relative_base,
 	ent = alloc_alt_odb(pathbuf.buf);
 
 	/* add the alternate entry */
-	*alt_odb_tail = ent;
-	alt_odb_tail = &(ent->next);
+	*the_repository->objects.alt_odb_tail = ent;
+	the_repository->objects.alt_odb_tail = &(ent->next);
 	ent->next = NULL;
 
 	/* recursively add alternates */
@@ -563,7 +561,7 @@ void add_to_alternates_file(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 (alt_odb_tail)
+		if (the_repository->objects.alt_odb_tail)
 			link_alt_odb_entries(reference, '\n', NULL, 0);
 	}
 	free(alts);
@@ -661,7 +659,7 @@ int foreach_alt_odb(alt_odb_fn fn, void *cb)
 	int r = 0;
 
 	prepare_alt_odb();
-	for (ent = alt_odb_list; ent; ent = ent->next) {
+	for (ent = the_repository->objects.alt_odb_list; ent; ent = ent->next) {
 		r = fn(ent, cb);
 		if (r)
 			break;
@@ -673,12 +671,13 @@ void prepare_alt_odb(void)
 {
 	const char *alt;
 
-	if (alt_odb_tail)
+	if (the_repository->objects.alt_odb_tail)
 		return;
 
 	alt = getenv(ALTERNATE_DB_ENVIRONMENT);
 
-	alt_odb_tail = &alt_odb_list;
+	the_repository->objects.alt_odb_tail =
+			&the_repository->objects.alt_odb_list;
 	link_alt_odb_entries(alt, PATH_SEP, NULL, 0);
 
 	read_info_alternates(get_object_directory(), 0);
@@ -717,7 +716,7 @@ static int check_and_freshen_nonlocal(const unsigned char *sha1, int freshen)
 {
 	struct alternate_object_database *alt;
 	prepare_alt_odb();
-	for (alt = alt_odb_list; alt; alt = alt->next) {
+	for (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next) {
 		const char *path = alt_sha1_path(alt, sha1);
 		if (check_and_freshen_file(path, freshen))
 			return 1;
@@ -873,7 +872,7 @@ static int stat_sha1_file(const unsigned char *sha1, struct stat *st,
 
 	prepare_alt_odb();
 	errno = ENOENT;
-	for (alt = alt_odb_list; alt; alt = alt->next) {
+	for (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next) {
 		*path = alt_sha1_path(alt, sha1);
 		if (!lstat(*path, st))
 			return 0;
@@ -899,7 +898,7 @@ static int open_sha1_file(const unsigned char *sha1, const char **path)
 	most_interesting_errno = errno;
 
 	prepare_alt_odb();
-	for (alt = alt_odb_list; alt; alt = alt->next) {
+	for (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next) {
 		*path = alt_sha1_path(alt, sha1);
 		fd = git_open(*path);
 		if (fd >= 0)
sha1_name.c +2 -1
index 611c7d24dd..957ce25680 100644
@@ -10,6 +10,7 @@
 #include "dir.h"
 #include "sha1-array.h"
 #include "packfile.h"
+#include "repository.h"
 
 static int get_oid_oneline(const char *, struct object_id *, struct commit_list *);
 
@@ -104,7 +105,7 @@ static void find_short_object_filename(struct disambiguate_state *ds)
 		 */
 		fakeent = alloc_alt_odb(get_object_directory());
 	}
-	fakeent->next = alt_odb_list;
+	fakeent->next = the_repository->objects.alt_odb_list;
 
 	for (alt = fakeent; alt && !ds->ambiguous; alt = alt->next) {
 		int pos;
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#3 lore raw

PATCH 3/194 object-store: move packed_git and packed_git_mru to object store

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

In a process with multiple repositories open, packfile accessors should be associated to a single repository and not shared globally. Move packed_git and packed_git_mru into the_repository and adjust callers to reflect this.

Patch generated by

1. Moving the struct packed_git declaration to object-store.h and packed_git, packed_git_mru globals to struct object_store.

2. Applying the semantic patch contrib/coccinelle/packed_git.cocci to adjust callers.

3. Applying line wrapping fixes from "make style" to break the resulting long lines.

4. Adding missing #includes of repository.h and object-store.h where needed.

---
 builtin/count-objects.c             |  6 ++++--
 builtin/fsck.c                      |  7 +++++--
 builtin/gc.c                        |  4 +++-
 builtin/index-pack.c                |  1 +
 builtin/pack-objects.c              | 21 ++++++++++++--------
 builtin/pack-redundant.c            |  6 ++++--
 builtin/receive-pack.c              |  1 +
 cache.h                             | 28 --------------------------
 contrib/coccinelle/packed_git.cocci |  7 +++++++
 fast-import.c                       |  6 ++++--
 http-backend.c                      |  6 ++++--
 http-push.c                         |  1 +
 http-walker.c                       |  1 +
 http.c                              |  1 +
 mru.h                               |  1 +
 object-store.h                      | 33 ++++++++++++++++++++++++++++++-
 pack-bitmap.c                       |  4 +++-
 pack-check.c                        |  1 +
 pack-revindex.c                     |  1 +
 packfile.c                          | 39 +++++++++++++++++++------------------
 reachable.c                         |  1 +
 server-info.c                       |  6 ++++--
 sha1_name.c                         |  5 +++--
 23 files changed, 115 insertions(+), 72 deletions(-)
 create mode 100644 contrib/coccinelle/packed_git.cocci
builtin/count-objects.c +4 -2
index 33343818c8..9334648dcc 100644
@@ -7,6 +7,8 @@
 #include "cache.h"
 #include "config.h"
 #include "dir.h"
+#include "repository.h"
+#include "object-store.h"
 #include "builtin.h"
 #include "parse-options.h"
 #include "quote.h"
@@ -120,9 +122,9 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
 		struct strbuf loose_buf = STRBUF_INIT;
 		struct strbuf pack_buf = STRBUF_INIT;
 		struct strbuf garbage_buf = STRBUF_INIT;
-		if (!packed_git)
+		if (!the_repository->objects.packed_git)
 			prepare_packed_git();
-		for (p = packed_git; p; p = p->next) {
+		for (p = the_repository->objects.packed_git; p; p = p->next) {
 			if (!p->pack_local)
 				continue;
 			if (open_pack_index(p))
builtin/fsck.c +5 -2
index 1048255da1..d4d249c2ed 100644
@@ -2,6 +2,7 @@
 #include "cache.h"
 #include "repository.h"
 #include "config.h"
+#include "object-store.h"
 #include "commit.h"
 #include "tree.h"
 #include "blob.h"
@@ -707,7 +708,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
 			prepare_packed_git();
 
 			if (show_progress) {
-				for (p = packed_git; p; p = p->next) {
+				for (p = the_repository->objects.packed_git; p;
+				     p = p->next) {
 					if (open_pack_index(p))
 						continue;
 					total += p->num_objects;
@@ -715,7 +717,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
 
 				progress = start_progress(_("Checking objects"), total);
 			}
-			for (p = packed_git; p; p = p->next) {
+			for (p = the_repository->objects.packed_git; p;
+			     p = p->next) {
 				/* verify gives error messages itself */
 				if (verify_pack(p, fsck_obj_buffer,
 						progress, count))
builtin/gc.c +3 -1
index 3c5eae0edf..6970f325e5 100644
@@ -11,6 +11,7 @@
  */
 
 #include "builtin.h"
+#include "repository.h"
 #include "config.h"
 #include "tempfile.h"
 #include "lockfile.h"
@@ -18,6 +19,7 @@
 #include "run-command.h"
 #include "sigchain.h"
 #include "argv-array.h"
+#include "object-store.h"
 #include "commit.h"
 #include "packfile.h"
 
@@ -173,7 +175,7 @@ static int too_many_packs(void)
 		return 0;
 
 	prepare_packed_git();
-	for (cnt = 0, p = packed_git; p; p = p->next) {
+	for (cnt = 0, p = the_repository->objects.packed_git; p; p = p->next) {
 		if (!p->pack_local)
 			continue;
 		if (p->pack_keep)
builtin/index-pack.c +1 -0
index 4c51aec81f..1902d4e096 100644
@@ -12,6 +12,7 @@
 #include "exec_cmd.h"
 #include "streaming.h"
 #include "thread-utils.h"
+#include "object-store.h"
 #include "packfile.h"
 
 static const char index_pack_usage[] =
builtin/pack-objects.c +13 -8
index 6b9cfc289d..2ee8b69238 100644
@@ -1,6 +1,8 @@
 #include "builtin.h"
 #include "cache.h"
+#include "repository.h"
 #include "config.h"
+#include "object-store.h"
 #include "attr.h"
 #include "object.h"
 #include "blob.h"
@@ -1023,7 +1025,8 @@ static int want_object_in_pack(const struct object_id *oid,
 			return want;
 	}
 
-	for (entry = packed_git_mru.head; entry; entry = entry->next) {
+	for (entry = the_repository->objects.packed_git_mru.head; entry;
+	     entry = entry->next) {
 		struct packed_git *p = entry->item;
 		off_t offset;
 
@@ -1041,7 +1044,8 @@ static int want_object_in_pack(const struct object_id *oid,
 			}
 			want = want_found_object(exclude, p);
 			if (!exclude && want > 0)
-				mru_mark(&packed_git_mru, entry);
+				mru_mark(&the_repository->objects.packed_git_mru,
+					 entry);
 			if (want != -1)
 				return want;
 		}
@@ -2648,7 +2652,7 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs)
 
 	memset(&in_pack, 0, sizeof(in_pack));
 
-	for (p = packed_git; p; p = p->next) {
+	for (p = the_repository->objects.packed_git; p; p = p->next) {
 		struct object_id oid;
 		struct object *o;
 
@@ -2711,7 +2715,8 @@ static int has_sha1_pack_kept_or_nonlocal(const struct object_id *oid)
 	static struct packed_git *last_found = (void *)1;
 	struct packed_git *p;
 
-	p = (last_found != (void *)1) ? last_found : packed_git;
+	p = (last_found != (void *)1) ? last_found :
+					the_repository->objects.packed_git;
 
 	while (p) {
 		if ((!p->pack_local || p->pack_keep) &&
@@ -2720,7 +2725,7 @@ static int has_sha1_pack_kept_or_nonlocal(const struct object_id *oid)
 			return 1;
 		}
 		if (p == last_found)
-			p = packed_git;
+			p = the_repository->objects.packed_git;
 		else
 			p = p->next;
 		if (p == last_found)
@@ -2756,7 +2761,7 @@ static void loosen_unused_packed_objects(struct rev_info *revs)
 	uint32_t i;
 	struct object_id oid;
 
-	for (p = packed_git; p; p = p->next) {
+	for (p = the_repository->objects.packed_git; p; p = p->next) {
 		if (!p->pack_local || p->pack_keep)
 			continue;
 
@@ -3119,7 +3124,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
 	prepare_packed_git();
 	if (ignore_packed_keep) {
 		struct packed_git *p;
-		for (p = packed_git; p; p = p->next)
+		for (p = the_repository->objects.packed_git; p; p = p->next)
 			if (p->pack_local && p->pack_keep)
 				break;
 		if (!p) /* no keep-able packs found */
@@ -3132,7 +3137,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
 		 * also covers non-local objects
 		 */
 		struct packed_git *p;
-		for (p = packed_git; p; p = p->next) {
+		for (p = the_repository->objects.packed_git; p; p = p->next) {
 			if (!p->pack_local) {
 				have_non_local_packs = 1;
 				break;
builtin/pack-redundant.c +4 -2
index aaa8136322..55462bc826 100644
@@ -7,6 +7,8 @@
 */
 
 #include "builtin.h"
+#include "repository.h"
+#include "object-store.h"
 #include "packfile.h"
 
 #define BLKSIZE 512
@@ -571,7 +573,7 @@ static struct pack_list * add_pack(struct packed_git *p)
 
 static struct pack_list * add_pack_file(const char *filename)
 {
-	struct packed_git *p = packed_git;
+	struct packed_git *p = the_repository->objects.packed_git;
 
 	if (strlen(filename) < 40)
 		die("Bad pack filename: %s", filename);
@@ -586,7 +588,7 @@ static struct pack_list * add_pack_file(const char *filename)
 
 static void load_all(void)
 {
-	struct packed_git *p = packed_git;
+	struct packed_git *p = the_repository->objects.packed_git;
 
 	while (p) {
 		add_pack(p);
builtin/receive-pack.c +1 -0
index b7ce7c7f52..b2eac79a6e 100644
@@ -7,6 +7,7 @@
 #include "sideband.h"
 #include "run-command.h"
 #include "exec_cmd.h"
+#include "object-store.h"
 #include "commit.h"
 #include "object.h"
 #include "remote.h"
cache.h +0 -28
index 918c2f15b4..459fd01dbb 100644
@@ -1633,34 +1633,6 @@ struct pack_window {
 	unsigned int inuse_cnt;
 };
 
-extern struct packed_git {
-	struct packed_git *next;
-	struct pack_window *windows;
-	off_t pack_size;
-	const void *index_data;
-	size_t index_size;
-	uint32_t num_objects;
-	uint32_t num_bad_objects;
-	unsigned char *bad_object_sha1;
-	int index_version;
-	time_t mtime;
-	int pack_fd;
-	unsigned pack_local:1,
-		 pack_keep:1,
-		 freshened:1,
-		 do_not_close:1;
-	unsigned char sha1[20];
-	struct revindex_entry *revindex;
-	/* something like ".git/objects/pack/xxxxx.pack" */
-	char pack_name[FLEX_ARRAY]; /* more */
-} *packed_git;
-
-/*
- * A most-recently-used ordered version of the packed_git list, which can
- * be iterated instead of packed_git (and marked via mru_mark).
- */
-extern struct mru packed_git_mru;
-
 struct pack_entry {
 	off_t offset;
 	unsigned char sha1[20];
contrib/coccinelle/packed_git.cocci new file +7 -0
new file mode 100644
index 0000000000..da317a51a9
@@ -0,0 +1,7 @@
+@@ @@
+- packed_git
++ the_repository->objects.packed_git
+
+@@ @@
+- packed_git_mru
++ the_repository->objects.packed_git_mru
fast-import.c +4 -2
index b70ac025e0..1685fe59a2 100644
@@ -154,8 +154,10 @@ Format of STDIN stream:
 
 #include "builtin.h"
 #include "cache.h"
+#include "repository.h"
 #include "config.h"
 #include "lockfile.h"
+#include "object-store.h"
 #include "object.h"
 #include "blob.h"
 #include "tree.h"
@@ -1110,7 +1112,7 @@ static int store_object(
 	if (e->idx.offset) {
 		duplicate_count_by_type[type]++;
 		return 1;
-	} else if (find_sha1_pack(oid.hash, packed_git)) {
+	} else if (find_sha1_pack(oid.hash, the_repository->objects.packed_git)) {
 		e->type = type;
 		e->pack_id = MAX_PACK_ID;
 		e->idx.offset = 1; /* just not zero! */
@@ -1305,7 +1307,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
 		duplicate_count_by_type[OBJ_BLOB]++;
 		truncate_pack(&checkpoint);
 
-	} else if (find_sha1_pack(oid.hash, packed_git)) {
+	} else if (find_sha1_pack(oid.hash, the_repository->objects.packed_git)) {
 		e->type = OBJ_BLOB;
 		e->pack_id = MAX_PACK_ID;
 		e->idx.offset = 1; /* just not zero! */
http-backend.c +4 -2
index f3dc218b2a..4d93126c15 100644
@@ -1,7 +1,9 @@
 #include "cache.h"
 #include "config.h"
+#include "repository.h"
 #include "refs.h"
 #include "pkt-line.h"
+#include "object-store.h"
 #include "object.h"
 #include "tag.h"
 #include "exec_cmd.h"
@@ -518,13 +520,13 @@ static void get_info_packs(struct strbuf *hdr, char *arg)
 
 	select_getanyfile(hdr);
 	prepare_packed_git();
-	for (p = packed_git; p; p = p->next) {
+	for (p = the_repository->objects.packed_git; p; p = p->next) {
 		if (p->pack_local)
 			cnt++;
 	}
 
 	strbuf_grow(&buf, cnt * 53 + 2);
-	for (p = packed_git; p; p = p->next) {
+	for (p = the_repository->objects.packed_git; p; p = p->next) {
 		if (p->pack_local)
 			strbuf_addf(&buf, "P %s\n", p->pack_name + objdirlen + 6);
 	}
http-push.c +1 -0
index 14435ab65d..34c5d030b7 100644
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "object-store.h"
 #include "commit.h"
 #include "tag.h"
 #include "blob.h"
http-walker.c +1 -0
index 1ae8363de2..a1c6f2639b 100644
@@ -4,6 +4,7 @@
 #include "http.h"
 #include "list.h"
 #include "transport.h"
+#include "object-store.h"
 #include "packfile.h"
 
 struct alt_base {
http.c +1 -0
index 5977712712..ab989b88dd 100644
@@ -1,6 +1,7 @@
 #include "git-compat-util.h"
 #include "http.h"
 #include "config.h"
+#include "object-store.h"
 #include "pack.h"
 #include "sideband.h"
 #include "run-command.h"
mru.h +1 -0
index 42e4aeaa10..d7de81efb9 100644
@@ -37,6 +37,7 @@ struct mru_entry {
 struct mru {
 	struct mru_entry *head, *tail;
 };
+#define MRU_INIT { NULL, NULL }
 
 void mru_append(struct mru *mru, void *item);
 void mru_mark(struct mru *mru, struct mru_entry *entry);
object-store.h +32 -1
index ace3efbfab..e2a59a0611 100644
@@ -2,11 +2,42 @@
 #define OBJECT_STORE_H
 
 #include "cache.h"
+#include "mru.h"
 
 struct object_store {
+	struct packed_git *packed_git;
+
+	/*
+	 * A most-recently-used ordered version of the packed_git list, which can
+	 * be iterated instead of packed_git (and marked via mru_mark).
+	 */
+	struct mru packed_git_mru;
+
 	struct alternate_object_database *alt_odb_list;
 	struct alternate_object_database **alt_odb_tail;
 };
-#define OBJECT_STORE_INIT { NULL, NULL }
+#define OBJECT_STORE_INIT { NULL, MRU_INIT, NULL, NULL }
+
+struct packed_git {
+	struct packed_git *next;
+	struct pack_window *windows;
+	off_t pack_size;
+	const void *index_data;
+	size_t index_size;
+	uint32_t num_objects;
+	uint32_t num_bad_objects;
+	unsigned char *bad_object_sha1;
+	int index_version;
+	time_t mtime;
+	int pack_fd;
+	unsigned pack_local:1,
+		 pack_keep:1,
+		 freshened:1,
+		 do_not_close:1;
+	unsigned char sha1[20];
+	struct revindex_entry *revindex;
+	/* something like ".git/objects/pack/xxxxx.pack" */
+	char pack_name[FLEX_ARRAY]; /* more */
+};
 
 #endif /* OBJECT_STORE_H */
pack-bitmap.c +3 -1
index 9270983e5f..d51172b1d5 100644
@@ -5,11 +5,13 @@
 #include "revision.h"
 #include "progress.h"
 #include "list-objects.h"
+#include "object-store.h"
 #include "pack.h"
 #include "pack-bitmap.h"
 #include "pack-revindex.h"
 #include "pack-objects.h"
 #include "packfile.h"
+#include "repository.h"
 
 /*
  * An entry on the bitmap index, representing the bitmap for a given
@@ -335,7 +337,7 @@ static int open_pack_bitmap(void)
 	assert(!bitmap_git.map && !bitmap_git.loaded);
 
 	prepare_packed_git();
-	for (p = packed_git; p; p = p->next) {
+	for (p = the_repository->objects.packed_git; p; p = p->next) {
 		if (open_pack_bitmap_1(p) == 0)
 			ret = 0;
 	}
pack-check.c +1 -0
index 073c1fbd46..c80c3ed8fd 100644
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "pack.h"
+#include "object-store.h"
 #include "pack-revindex.h"
 #include "progress.h"
 #include "packfile.h"
pack-revindex.c +1 -0
index 1b7ebd8d7e..82c3119652 100644
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "pack-revindex.h"
+#include "object-store.h"
 
 /*
  * Pack index for existing packs give us easy access to the offsets into
packfile.c +20 -19
index d61076faaf..11b0e6613c 100644
@@ -7,6 +7,7 @@
 #include "packfile.h"
 #include "delta.h"
 #include "list.h"
+#include "object-store.h"
 #include "streaming.h"
 #include "sha1-lookup.h"
 
@@ -40,8 +41,6 @@ static unsigned int pack_open_fds;
 static unsigned int pack_max_fds;
 static size_t peak_pack_mapped;
 static size_t pack_mapped;
-struct packed_git *packed_git;
-struct mru packed_git_mru;
 
 #define SZ_FMT PRIuMAX
 static inline uintmax_t sz_fmt(size_t s) { return s; }
@@ -241,7 +240,7 @@ static int unuse_one_window(struct packed_git *current)
 
 	if (current)
 		scan_windows(current, &lru_p, &lru_w, &lru_l);
-	for (p = packed_git; p; p = p->next)
+	for (p = the_repository->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);
@@ -311,7 +310,7 @@ void close_all_packs(void)
 {
 	struct packed_git *p;
 
-	for (p = packed_git; p; p = p->next)
+	for (p = the_repository->objects.packed_git; p; p = p->next)
 		if (p->do_not_close)
 			die("BUG: want to close pack marked 'do-not-close'");
 		else
@@ -379,7 +378,7 @@ static int close_one_pack(void)
 	struct pack_window *mru_w = NULL;
 	int accept_windows_inuse = 1;
 
-	for (p = packed_git; p; p = p->next) {
+	for (p = the_repository->objects.packed_git; p; p = p->next) {
 		if (p->pack_fd == -1)
 			continue;
 		find_lru_pack(p, &lru_p, &mru_w, &accept_windows_inuse);
@@ -677,8 +676,8 @@ void install_packed_git(struct packed_git *pack)
 	if (pack->pack_fd != -1)
 		pack_open_fds++;
 
-	pack->next = packed_git;
-	packed_git = pack;
+	pack->next = the_repository->objects.packed_git;
+	the_repository->objects.packed_git = pack;
 }
 
 void (*report_garbage)(unsigned seen_bits, const char *path);
@@ -760,7 +759,8 @@ static void prepare_packed_git_one(char *objdir, int local)
 		base_len = path.len;
 		if (strip_suffix_mem(path.buf, &base_len, ".idx")) {
 			/* Don't reopen a pack we already have. */
-			for (p = packed_git; p; p = p->next) {
+			for (p = the_repository->objects.packed_git; p;
+			     p = p->next) {
 				size_t len;
 				if (strip_suffix(p->pack_name, ".pack", &len) &&
 				    len == base_len &&
@@ -810,7 +810,7 @@ unsigned long approximate_object_count(void)
 
 		prepare_packed_git();
 		count = 0;
-		for (p = packed_git; p; p = p->next) {
+		for (p = the_repository->objects.packed_git; p; p = p->next) {
 			if (open_pack_index(p))
 				continue;
 			count += p->num_objects;
@@ -859,17 +859,18 @@ static int sort_pack(const void *a_, const void *b_)
 
 static void rearrange_packed_git(void)
 {
-	packed_git = llist_mergesort(packed_git, get_next_packed_git,
-				     set_next_packed_git, sort_pack);
+	the_repository->objects.packed_git = llist_mergesort(
+		the_repository->objects.packed_git, get_next_packed_git,
+		set_next_packed_git, sort_pack);
 }
 
 static void prepare_packed_git_mru(void)
 {
 	struct packed_git *p;
 
-	mru_clear(&packed_git_mru);
-	for (p = packed_git; p; p = p->next)
-		mru_append(&packed_git_mru, p);
+	mru_clear(&the_repository->objects.packed_git_mru);
+	for (p = the_repository->objects.packed_git; p; p = p->next)
+		mru_append(&the_repository->objects.packed_git_mru, p);
 }
 
 static int prepare_packed_git_run_once = 0;
@@ -1003,7 +1004,7 @@ const struct packed_git *has_packed_and_bad(const unsigned char *sha1)
 	struct packed_git *p;
 	unsigned i;
 
-	for (p = packed_git; p; p = p->next)
+	for (p = the_repository->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;
@@ -1835,12 +1836,12 @@ int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)
 	struct mru_entry *p;
 
 	prepare_packed_git();
-	if (!packed_git)
+	if (!the_repository->objects.packed_git)
 		return 0;
 
-	for (p = packed_git_mru.head; p; p = p->next) {
+	for (p = the_repository->objects.packed_git_mru.head; p; p = p->next) {
 		if (fill_pack_entry(sha1, e, p->item)) {
-			mru_mark(&packed_git_mru, p);
+			mru_mark(&the_repository->objects.packed_git_mru, p);
 			return 1;
 		}
 	}
@@ -1887,7 +1888,7 @@ int for_each_packed_object(each_packed_object_fn cb, void *data, unsigned flags)
 	int pack_errors = 0;
 
 	prepare_packed_git();
-	for (p = packed_git; p; p = p->next) {
+	for (p = the_repository->objects.packed_git; p; p = p->next) {
 		if ((flags & FOR_EACH_OBJECT_LOCAL_ONLY) && !p->pack_local)
 			continue;
 		if (open_pack_index(p)) {
reachable.c +1 -0
index 88d7d679da..59ed16ba76 100644
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "refs.h"
+#include "object-store.h"
 #include "tag.h"
 #include "commit.h"
 #include "blob.h"
server-info.c +4 -2
index 26a6c20b7d..96885c45f6 100644
@@ -1,5 +1,7 @@
 #include "cache.h"
+#include "repository.h"
 #include "refs.h"
+#include "object-store.h"
 #include "object.h"
 #include "commit.h"
 #include "tag.h"
@@ -200,7 +202,7 @@ static void init_pack_info(const char *infofile, int force)
 	objdirlen = strlen(objdir);
 
 	prepare_packed_git();
-	for (p = packed_git; p; p = p->next) {
+	for (p = the_repository->objects.packed_git; p; p = p->next) {
 		/* we ignore things on alternate path since they are
 		 * not available to the pullers in general.
 		 */
@@ -210,7 +212,7 @@ static void init_pack_info(const char *infofile, int force)
 	}
 	num_pack = i;
 	info = xcalloc(num_pack, sizeof(struct pack_info *));
-	for (i = 0, p = packed_git; p; p = p->next) {
+	for (i = 0, p = the_repository->objects.packed_git; p; p = p->next) {
 		if (!p->pack_local)
 			continue;
 		info[i] = xcalloc(1, sizeof(struct pack_info));
sha1_name.c +3 -2
index 957ce25680..016c883b5c 100644
@@ -196,7 +196,8 @@ static void find_short_packed_object(struct disambiguate_state *ds)
 	struct packed_git *p;
 
 	prepare_packed_git();
-	for (p = packed_git; p && !ds->ambiguous; p = p->next)
+	for (p = the_repository->objects.packed_git; p && !ds->ambiguous;
+	     p = p->next)
 		unique_in_pack(p, ds);
 }
 
@@ -566,7 +567,7 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad)
 	struct packed_git *p;
 
 	prepare_packed_git();
-	for (p = packed_git; p; p = p->next)
+	for (p = the_repository->objects.packed_git; p; p = p->next)
 		find_abbrev_len_for_pack(p, mad);
 }
 
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#4 lore raw

Re: [PATCH 003/194] object-store: move packed_git and packed_git_mru to object store

Quoted 4 lines · Stefan Beller

Patch generated by

2. Applying the semantic patch contrib/coccinelle/packed_git.cocci to adjust callers.

About this part...

contrib/coccinelle/packed_git.cocci line 7

Quoted 13 lines
contrib/coccinelle/packed_git.cocci new file +7 -0
new file mode 100644
index 0000000000..da317a51a9
@@ -0,0 +1,7 @@
+@@ @@
+- packed_git
++ the_repository->objects.packed_git
+
+@@ @@
+- packed_git_mru
++ the_repository->objects.packed_git_mru

The above is correct for one-time transition turning pre-transition code to post the_repository world, but I am not sure if we want to have it in contrib/coccinelle/, where "make coccicheck" looks at, as a way to continuously keep an eye on "style" violations like using strbuf_addf() for a constant when strbuf_addstr() suffices.

Wouldn't we need a mechanism to ensure that this file will *not* be used in "make coccicheck" somehow?

#5 lore raw

Re: [PATCH 003/194] object-store: move packed_git and packed_git_mru to object store

Quoted 29 lines · Junio C Hamano
Quoted 4 lines · Stefan Beller

Patch generated by

2. Applying the semantic patch contrib/coccinelle/packed_git.cocci to adjust callers.

About this part...

contrib/coccinelle/packed_git.cocci line 7

Quoted 13 lines
contrib/coccinelle/packed_git.cocci new file +7 -0
new file mode 100644
index 0000000000..da317a51a9
@@ -0,0 +1,7 @@
+@@ @@
+- packed_git
++ the_repository->objects.packed_git
+
+@@ @@
+- packed_git_mru
++ the_repository->objects.packed_git_mru

The above is correct for one-time transition turning pre-transition code to post the_repository world, but I am not sure if we want to have it in contrib/coccinelle/, where "make coccicheck" looks at, as a way to continuously keep an eye on "style" violations like using strbuf_addf() for a constant when strbuf_addstr() suffices.

Quoted 3 lines

Wouldn't we need a mechanism to ensure that this file will *not* be used in "make coccicheck" somehow?

I can omit the cocci files from the patches, if that is better for maintenance.

I thought it may be a helpful
for merging this series with the rest of the evolved code base which may make use of one of the converted functions. So instead of fixing that new instance manually, cocinelle could do that instead.

Stefan

#6 lore raw

Re: [PATCH 003/194] object-store: move packed_git and packed_git_mru to object store

Quoted 4 lines · Stefan Beller

I thought it may be a helpful
for merging this series with the rest of the evolved code base which may make use of one of the converted functions. So instead of fixing that new instance manually, cocinelle could do that instead.

Having the .cocci used for the conversion *somewhere* would indeed be helpful, as it allows me to (1) try reproducing this patch by somebody else using the file and following the steps in order to audit this patch and (2) catch new places that need to be migrated in in-flight topics.

But placing it in contrib/coccinelle/ has other side effects.

I can think of two precedents in this project, namely:

- fixup-builtins in 36e5e70e ("Start deprecating "git-command" in favor of "git command"", 2007-06-30)

- convert-cache in d98b46f8 ("Do SHA1 hash _before_ compression.", 2005-04-20)

that are about tools that is useful during a transition period but can and should be removed after transition is over. These two were done as one-off and added at the top-level, but perhaps we want a new directory at the top (e.g. devtools/) to add things like this and hold them while they are relevant?

#7 lore raw

Re: [PATCH 003/194] object-store: move packed_git and packed_git_mru to object store

Am 12.02.2018 um 22:04 schrieb Junio C Hamano:

Quoted 7 lines
Quoted 4 lines · Stefan Beller

I thought it may be a helpful
for merging this series with the rest of the evolved code base which may make use of one of the converted functions. So instead of fixing that new instance manually, cocinelle could do that instead.

Quoted 7 lines

Having the .cocci used for the conversion *somewhere* would indeed be helpful, as it allows me to (1) try reproducing this patch by somebody else using the file and following the steps in order to audit this patch and (2) catch new places that need to be migrated in in-flight topics.

But placing it in contrib/coccinelle/ has other side effects.

Running "make coccicheck" takes longer. What other downsides are there?

Quoted 5 lines

I can think of two precedents in this project, namely:

- fixup-builtins in 36e5e70e ("Start deprecating "git-command" in

    favor of "git command"", 2007-06-30)
Quoted 8 lines

- convert-cache in d98b46f8 ("Do SHA1 hash _before_ compression.",

    2005-04-20)

that are about tools that is useful during a transition period but can and should be removed after transition is over. These two were done as one-off and added at the top-level, but perhaps we want a new directory at the top (e.g. devtools/) to add things like this and hold them while they are relevant?

Semantic patches for completed transformations can be removed as well (or archived, e.g. by renaming to .cocci.done or so).

René

#8 lore raw

Re: [PATCH 003/194] object-store: move packed_git and packed_git_mru to object store

Quoted 14 lines · René Scharfe

Am 12.02.2018 um 22:04 schrieb Junio C Hamano:

Quoted 13 lines
Quoted 4 lines · Stefan Beller

I thought it may be a helpful
for merging this series with the rest of the evolved code base which may make use of one of the converted functions. So instead of fixing that new instance manually, cocinelle could do that instead.

Having the .cocci used for the conversion *somewhere* would indeed be helpful, as it allows me to (1) try reproducing this patch by somebody else using the file and following the steps in order to audit this patch and (2) catch new places that need to be migrated in in-flight topics.

Quoted 4 lines
Quoted 1 line

But placing it in contrib/coccinelle/ has other side effects.

Running "make coccicheck" takes longer. What other downsides are there?

Once the global variable packed_git has been migrated out of existence, no new code that relies on it would be referring to that global variable. If coccicheck finds something, the suggested rewrite would be turning an unrelated packed_git (which may not even be the right type) to a reference to a field in a global variable, that would certainly be wrong.

#9 lore raw

Re: [PATCH 003/194] object-store: move packed_git and packed_git_mru to object store

Am 12.02.2018 um 22:48 schrieb Junio C Hamano:

Quoted 21 lines
Quoted 14 lines · René Scharfe

Am 12.02.2018 um 22:04 schrieb Junio C Hamano:

Quoted 13 lines
Quoted 4 lines · Stefan Beller

I thought it may be a helpful
for merging this series with the rest of the evolved code base which may make use of one of the converted functions. So instead of fixing that new instance manually, cocinelle could do that instead.

Having the .cocci used for the conversion *somewhere* would indeed be helpful, as it allows me to (1) try reproducing this patch by somebody else using the file and following the steps in order to audit this patch and (2) catch new places that need to be migrated in in-flight topics.

Quoted 4 lines
Quoted 1 line

But placing it in contrib/coccinelle/ has other side effects.

Running "make coccicheck" takes longer. What other downsides are there?

Quoted 6 lines

Once the global variable packed_git has been migrated out of existence, no new code that relies on it would be referring to that global variable. If coccicheck finds something, the suggested rewrite would be turning an unrelated packed_git (which may not even be the right type) to a reference to a field in a global variable, that would certainly be wrong.

Ugh, yes. The semantic patch in question doesn't contain any type information. I don't know how to match a variable by name *and* type. Here's the closest I can come up with to a safe and complete transformation, but it only handles assignments:

	@@
	struct packed_git *A;
	identifier B = packed_git;
	@@
	- A = B
	+ A = the_repository->objects.packed_git

Seeing the many for loops, I'm tempted to suggest adding a for_each_packed_git macro to hide the global variable and thus reduce the number of places to change at cutover. Coccinelle doesn't seem to like them, though.

A short semantic patch with a limited time of usefulness and possible side-effects can easily be included in a commit message, of course..

René

#10 lore raw

Re: [PATCH 003/194] object-store: move packed_git and packed_git_mru to object store

Quoted 34 lines · René Scharfe

Am 12.02.2018 um 22:48 schrieb Junio C Hamano:

Quoted 21 lines
Quoted 14 lines · René Scharfe

Am 12.02.2018 um 22:04 schrieb Junio C Hamano:

Quoted 13 lines
Quoted 4 lines · Stefan Beller

I thought it may be a helpful
for merging this series with the rest of the evolved code base which may make use of one of the converted functions. So instead of fixing that new instance manually, cocinelle could do that instead.

Having the .cocci used for the conversion *somewhere* would indeed be helpful, as it allows me to (1) try reproducing this patch by somebody else using the file and following the steps in order to audit this patch and (2) catch new places that need to be migrated in in-flight topics.

Quoted 4 lines
Quoted 1 line

But placing it in contrib/coccinelle/ has other side effects.

Running "make coccicheck" takes longer. What other downsides are there?

Quoted 6 lines

Once the global variable packed_git has been migrated out of existence, no new code that relies on it would be referring to that global variable. If coccicheck finds something, the suggested rewrite would be turning an unrelated packed_git (which may not even be the right type) to a reference to a field in a global variable, that would certainly be wrong.

Ugh, yes. The semantic patch in question doesn't contain any type information. I don't know how to match a variable by name *and* type. Here's the closest I can come up with to a safe and complete transformation, but it only handles assignments:

Quoted 7 lines
        @@
        struct packed_git *A;
        identifier B = packed_git;
        @@
        - A = B
        + A = the_repository->objects.packed_git

I'll need to play more with coccinelle. :) Thanks for this patch.

Quoted 7 lines

Seeing the many for loops, I'm tempted to suggest adding a for_each_packed_git macro to hide the global variable and thus reduce the number of places to change at cutover. Coccinelle doesn't seem to like them, though.

A short semantic patch with a limited time of usefulness and possible side-effects can easily be included in a commit message, of course..

In the shorter reroll I moved the semantic patch into a subdir of contrib/coccinelle, but in the next reroll I'll just put it into the commit message.

Thanks,
Stefan

#11 lore raw

Re: [PATCH 003/194] object-store: move packed_git and packed_git_mru to object store

In reply to René Scharfe
Quoted 2 lines · René Scharfe

A short semantic patch with a limited time of usefulness and possible side-effects can easily be included in a commit message, of course..

Yeah, I think that is Jonathan's favourite approach as well, and I do not have problem with that. This transition spatch is unlike the "avoid strbuf_addf when we do not have to use it" one, in that there is a definite cut-over where the old way becomes an invalid C code and compilers can help us spot unconverted places (as opposed to a valid but unwanted way that can come into the codebase after one round of code cleaning is done, which is a useful thing to catch with the "make coccicheck" target).

#12 lore raw

Re: [PATCH 003/194] object-store: move packed_git and packed_git_mru to object store

In reply to Stefan Beller

[removed [email protected] from cc:; I lost that domain a few
years ago. Thanks for the heads-up, Stefan!]

Am 12.02.2018 um 20:00 schrieb Stefan Beller:

Quoted 30 lines · Junio C Hamano
Quoted 29 lines
Quoted 4 lines · Stefan Beller

Patch generated by

2. Applying the semantic patch contrib/coccinelle/packed_git.cocci to adjust callers.

About this part...

contrib/coccinelle/packed_git.cocci line 7

Quoted 13 lines
contrib/coccinelle/packed_git.cocci new file +7 -0
new file mode 100644
index 0000000000..da317a51a9
@@ -0,0 +1,7 @@
+@@ @@
+- packed_git
++ the_repository->objects.packed_git
+
+@@ @@
+- packed_git_mru
++ the_repository->objects.packed_git_mru

The above is correct for one-time transition turning pre-transition code to post the_repository world, but I am not sure if we want to have it in contrib/coccinelle/, where "make coccicheck" looks at, as a way to continuously keep an eye on "style" violations like using strbuf_addf() for a constant when strbuf_addstr() suffices.

Quoted 2 lines
Quoted 2 lines

Wouldn't we need a mechanism to ensure that this file will *not* be used in "make coccicheck" somehow?

object_id.cocci is similar in this regard -- once the conversion is done, we won't need it anymore.

Quoted 6 lines

I can omit the cocci files from the patches, if that is better for maintenance.

I thought it may be a helpful
for merging this series with the rest of the evolved code base which may make use of one of the converted functions. So instead of fixing that new instance manually, cocinelle could do that instead.

Right, merging should be easier -- instead of fixing conflicts manually, Coccinelle could regenerate the patch.

René

#13 lore raw

PATCH 4/194 pack: move prepare_packed_git_run_once to object store

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

Each repository's object store can be initialized independently, so they must not share a run_once variable.

---
 object-store.h | 8 +++++++-
 packfile.c     | 7 +++----
 2 files changed, 10 insertions(+), 5 deletions(-)
object-store.h +7 -1
index e2a59a0611..14129fbba1 100644
@@ -15,8 +15,14 @@ struct object_store {
 
 	struct alternate_object_database *alt_odb_list;
 	struct alternate_object_database **alt_odb_tail;
+
+	/*
+	 * Whether packed_git has already been populated with this repository's
+	 * packs.
+	 */
+	unsigned packed_git_initialized : 1;
 };
-#define OBJECT_STORE_INIT { NULL, MRU_INIT, NULL, NULL }
+#define OBJECT_STORE_INIT { NULL, MRU_INIT, NULL, NULL, 0 }
 
 struct packed_git {
 	struct packed_git *next;
packfile.c +3 -4
index 11b0e6613c..177aa219f9 100644
@@ -873,12 +873,11 @@ static void prepare_packed_git_mru(void)
 		mru_append(&the_repository->objects.packed_git_mru, p);
 }
 
-static int prepare_packed_git_run_once = 0;
 void prepare_packed_git(void)
 {
 	struct alternate_object_database *alt;
 
-	if (prepare_packed_git_run_once)
+	if (the_repository->objects.packed_git_initialized)
 		return;
 	prepare_packed_git_one(get_object_directory(), 1);
 	prepare_alt_odb();
@@ -886,13 +885,13 @@ void prepare_packed_git(void)
 		prepare_packed_git_one(alt->path, 0);
 	rearrange_packed_git();
 	prepare_packed_git_mru();
-	prepare_packed_git_run_once = 1;
+	the_repository->objects.packed_git_initialized = 1;
 }
 
 void reprepare_packed_git(void)
 {
 	approximate_object_count_valid = 0;
-	prepare_packed_git_run_once = 0;
+	the_repository->objects.packed_git_initialized = 0;
 	prepare_packed_git();
 }
 
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#14 lore raw

PATCH 5/194 pack: move approximate object count to object store

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

The approximate_object_count() function maintains a rough count of objects in a repository to estimate how long object name abbreviates should be. Object names are scoped to a repository and the appropriate length may differ by repository, so the object count should not be global.

---
 object-store.h | 10 +++++++++-
 packfile.c     | 11 +++++------
 2 files changed, 14 insertions(+), 7 deletions(-)
object-store.h +9 -1
index 14129fbba1..99f77d10cd 100644
@@ -16,13 +16,21 @@ struct object_store {
 	struct alternate_object_database *alt_odb_list;
 	struct alternate_object_database **alt_odb_tail;
 
+	/*
+	 * A fast, rough count of the number of objects in the repository.
+	 * These two fields are not meant for direct access. Use
+	 * approximate_object_count() instead.
+	 */
+	unsigned long approximate_object_count;
+	unsigned approximate_object_count_valid : 1;
+
 	/*
 	 * Whether packed_git has already been populated with this repository's
 	 * packs.
 	 */
 	unsigned packed_git_initialized : 1;
 };
-#define OBJECT_STORE_INIT { NULL, MRU_INIT, NULL, NULL, 0 }
+#define OBJECT_STORE_INIT { NULL, MRU_INIT, NULL, NULL, 0, 0, 0 }
 
 struct packed_git {
 	struct packed_git *next;
packfile.c +5 -6
index 177aa219f9..31c4ea54ae 100644
@@ -793,8 +793,6 @@ static void prepare_packed_git_one(char *objdir, int local)
 	strbuf_release(&path);
 }
 
-static int approximate_object_count_valid;
-
 /*
  * Give a fast, rough count of the number of objects in the repository. This
  * ignores loose objects completely. If you have a lot of them, then either
@@ -804,8 +802,8 @@ static int approximate_object_count_valid;
  */
 unsigned long approximate_object_count(void)
 {
-	static unsigned long count;
-	if (!approximate_object_count_valid) {
+	if (!the_repository->objects.approximate_object_count_valid) {
+		unsigned long count;
 		struct packed_git *p;
 
 		prepare_packed_git();
@@ -815,8 +813,9 @@ unsigned long approximate_object_count(void)
 				continue;
 			count += p->num_objects;
 		}
+		the_repository->objects.approximate_object_count = count;
 	}
-	return count;
+	return the_repository->objects.approximate_object_count;
 }
 
 static void *get_next_packed_git(const void *p)
@@ -890,7 +889,7 @@ void prepare_packed_git(void)
 
 void reprepare_packed_git(void)
 {
-	approximate_object_count_valid = 0;
+	the_repository->objects.approximate_object_count_valid = 0;
 	the_repository->objects.packed_git_initialized = 0;
 	prepare_packed_git();
 }
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#15 lore raw

PATCH 6/194 sha1_file: add repository argument to alt_odb_usable

In reply to Stefan Beller

Add a repository argument to allow the alt_odb_usable caller 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.

Since the implementation does not yet work with other repositories, use a wrapper macro to enforce that the caller passes in the_repository as the first argument. It would be more appealing to use BUILD_ASSERT_OR_ZERO to enforce this, but that doesn't work because it requires a compile-time constant and common compilers like gcc 4.8.4 do not consider "r == the_repository" a compile-time constant.

---
 sha1_file.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
sha1_file.c +4 -2
index 2826d5d6ed..ca002a272d 100644
@@ -350,7 +350,9 @@ static const char *alt_sha1_path(struct alternate_object_database *alt,
 /*
  * Return non-zero iff the path is usable as an alternate object database.
  */
-static int alt_odb_usable(struct strbuf *path, const char *normalized_objdir)
+#define alt_odb_usable(r, p, n) alt_odb_usable_##r(p, n)
+static int alt_odb_usable_the_repository(struct strbuf *path,
+					 const char *normalized_objdir)
 {
 	struct alternate_object_database *alt;
 
@@ -418,7 +420,7 @@ static int link_alt_odb_entry(const char *entry, const char *relative_base,
 	while (pathbuf.len && pathbuf.buf[pathbuf.len - 1] == '/')
 		strbuf_setlen(&pathbuf, pathbuf.len - 1);
 
-	if (!alt_odb_usable(&pathbuf, normalized_objdir)) {
+	if (!alt_odb_usable(the_repository, &pathbuf, normalized_objdir)) {
 		strbuf_release(&pathbuf);
 		return -1;
 	}
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#16 lore raw

PATCH 7/194 sha1_file: add repository argument to link_alt_odb_entry

In reply to Stefan Beller

Add a repository argument to allow the link_alt_odb_entry caller 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 commit, use a macro to catch callers passing a repository other than the_repository at compile time.

---
 sha1_file.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
sha1_file.c +5 -3
index ca002a272d..1e17246f5c 100644
@@ -394,8 +394,9 @@ static int alt_odb_usable_the_repository(struct strbuf *path,
  * terminating NUL.
  */
 static void read_info_alternates(const char * relative_base, int depth);
-static int link_alt_odb_entry(const char *entry, const char *relative_base,
-	int depth, const char *normalized_objdir)
+#define link_alt_odb_entry(r, e, rb, d, n) link_alt_odb_entry_##r(e, rb, d, n)
+static int link_alt_odb_entry_the_repository(const char *entry,
+	const char *relative_base, int depth, const char *normalized_objdir)
 {
 	struct alternate_object_database *ent;
 	struct strbuf pathbuf = STRBUF_INIT;
@@ -492,7 +493,8 @@ static void link_alt_odb_entries(const char *alt, int sep,
 		alt = parse_alt_odb_entry(alt, sep, &entry);
 		if (!entry.len)
 			continue;
-		link_alt_odb_entry(entry.buf, relative_base, depth, objdirbuf.buf);
+		link_alt_odb_entry(the_repository, entry.buf,
+				   relative_base, depth, objdirbuf.buf);
 	}
 	strbuf_release(&entry);
 	strbuf_release(&objdirbuf);
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#17 lore raw

PATCH 8/194 sha1_file: add repository argument to read_info_alternates

In reply to Stefan Beller

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

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

---
 sha1_file.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
sha1_file.c +7 -4
index 1e17246f5c..acb00b9680 100644
@@ -393,7 +393,9 @@ static int alt_odb_usable_the_repository(struct strbuf *path,
  * SHA1, an extra slash for the first level indirection, and the
  * terminating NUL.
  */
-static void read_info_alternates(const char * relative_base, int depth);
+#define read_info_alternates(r, rb, d) read_info_alternates_##r(rb, d)
+static void read_info_alternates_the_repository(const char *relative_base,
+						int depth);
 #define link_alt_odb_entry(r, e, rb, d, n) link_alt_odb_entry_##r(e, rb, d, n)
 static int link_alt_odb_entry_the_repository(const char *entry,
 	const char *relative_base, int depth, const char *normalized_objdir)
@@ -434,7 +436,7 @@ static int link_alt_odb_entry_the_repository(const char *entry,
 	ent->next = NULL;
 
 	/* recursively add alternates */
-	read_info_alternates(pathbuf.buf, depth + 1);
+	read_info_alternates(the_repository, pathbuf.buf, depth + 1);
 
 	strbuf_release(&pathbuf);
 	return 0;
@@ -500,7 +502,8 @@ static void link_alt_odb_entries(const char *alt, int sep,
 	strbuf_release(&objdirbuf);
 }
 
-static void read_info_alternates(const char * relative_base, int depth)
+static void read_info_alternates_the_repository(const char *relative_base,
+						int depth)
 {
 	char *path;
 	struct strbuf buf = STRBUF_INIT;
@@ -684,7 +687,7 @@ void prepare_alt_odb(void)
 			&the_repository->objects.alt_odb_list;
 	link_alt_odb_entries(alt, PATH_SEP, NULL, 0);
 
-	read_info_alternates(get_object_directory(), 0);
+	read_info_alternates(the_repository, get_object_directory(), 0);
 }
 
 /* Returns 1 if we have successfully freshened the file, 0 otherwise. */
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#18 lore raw

PATCH 9/194 sha1_file: add repository argument to link_alt_odb_entries

In reply to Stefan Beller

Add a repository argument to allow the link_alt_odb_entries caller 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.

---
 sha1_file.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
sha1_file.c +13 -6
index acb00b9680..d9f9046f31 100644
@@ -471,8 +471,12 @@ static const char *parse_alt_odb_entry(const char *string,
 	return end;
 }
 
-static void link_alt_odb_entries(const char *alt, int sep,
-				 const char *relative_base, int depth)
+#define link_alt_odb_entries(r, a, s, rb, d) \
+	link_alt_odb_entries_##r(a, s, rb, d)
+static void link_alt_odb_entries_the_repository(const char *alt,
+						int sep,
+						const char *relative_base,
+						int depth)
 {
 	struct strbuf objdirbuf = STRBUF_INIT;
 	struct strbuf entry = STRBUF_INIT;
@@ -515,7 +519,7 @@ static void read_info_alternates_the_repository(const char *relative_base,
 		return;
 	}
 
-	link_alt_odb_entries(buf.buf, '\n', relative_base, depth);
+	link_alt_odb_entries(the_repository, buf.buf, '\n', relative_base, depth);
 	strbuf_release(&buf);
 	free(path);
 }
@@ -569,7 +573,8 @@ void add_to_alternates_file(const char *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(reference, '\n', NULL, 0);
+			link_alt_odb_entries(the_repository, reference,
+					     '\n', NULL, 0);
 	}
 	free(alts);
 }
@@ -582,7 +587,8 @@ void add_to_alternates_memory(const char *reference)
 	 */
 	prepare_alt_odb();
 
-	link_alt_odb_entries(reference, '\n', NULL, 0);
+	link_alt_odb_entries(the_repository, reference,
+			     '\n', NULL, 0);
 }
 
 /*
@@ -685,7 +691,8 @@ void prepare_alt_odb(void)
 
 	the_repository->objects.alt_odb_tail =
 			&the_repository->objects.alt_odb_list;
-	link_alt_odb_entries(alt, PATH_SEP, NULL, 0);
+	link_alt_odb_entries(the_repository, alt,
+			     PATH_SEP, NULL, 0);
 
 	read_info_alternates(the_repository, get_object_directory(), 0);
 }
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#19 lore raw

PATCH 10/194 sha1_file: add repository argument to stat_sha1_file

In reply to Stefan Beller

Add a repository argument to allow the stat_sha1_file caller 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.

---
 sha1_file.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
sha1_file.c +5 -4
index d9f9046f31..6abdb8c488 100644
@@ -875,8 +875,9 @@ int git_open_cloexec(const char *name, int flags)
  * Note that it may point to static storage and is only valid until another
  * call to sha1_file_name(), etc.
  */
-static int stat_sha1_file(const unsigned char *sha1, struct stat *st,
-			  const char **path)
+#define stat_sha1_file(r, s, st, p) stat_sha1_file_##r(s, st, p)
+static int stat_sha1_file_the_repository(const unsigned char *sha1,
+					 struct stat *st, const char **path)
 {
 	struct alternate_object_database *alt;
 
@@ -1174,7 +1175,7 @@ static int sha1_loose_object_info(const unsigned char *sha1,
 	if (!oi->typep && !oi->typename && !oi->sizep && !oi->contentp) {
 		const char *path;
 		struct stat st;
-		if (stat_sha1_file(sha1, &st, &path) < 0)
+		if (stat_sha1_file(the_repository, sha1, &st, &path) < 0)
 			return -1;
 		if (oi->disk_sizep)
 			*oi->disk_sizep = st.st_size;
@@ -1373,7 +1374,7 @@ void *read_sha1_file_extended(const unsigned char *sha1,
 		die("replacement %s not found for %s",
 		    sha1_to_hex(repl), sha1_to_hex(sha1));
 
-	if (!stat_sha1_file(repl, &st, &path))
+	if (!stat_sha1_file(the_repository, repl, &st, &path))
 		die("loose object %s (stored in %s) is corrupt",
 		    sha1_to_hex(repl), path);
 
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#20 lore raw

PATCH 11/194 sha1_file: add repository argument to open_sha1_file

In reply to Stefan Beller

Add a repository argument to allow the open_sha1_file caller 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.

---
 sha1_file.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
sha1_file.c +4 -2
index 6abdb8c488..9fa7243907 100644
@@ -900,7 +900,9 @@ static int stat_sha1_file_the_repository(const unsigned char *sha1,
  * Like stat_sha1_file(), but actually open the object and return the
  * descriptor. See the caveats on the "path" parameter above.
  */
-static int open_sha1_file(const unsigned char *sha1, const char **path)
+#define open_sha1_file(r, s, p) open_sha1_file_##r(s, p)
+static int open_sha1_file_the_repository(const unsigned char *sha1,
+					 const char **path)
 {
 	int fd;
 	struct alternate_object_database *alt;
@@ -939,7 +941,7 @@ static void *map_sha1_file_1(const char *path,
 	if (path)
 		fd = git_open(path);
 	else
-		fd = open_sha1_file(sha1, &path);
+		fd = open_sha1_file(the_repository, sha1, &path);
 	map = NULL;
 	if (fd >= 0) {
 		struct stat st;
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#21 lore raw

PATCH 12/194 sha1_file: add repository argument to map_sha1_file_1

In reply to Stefan Beller

Add a repository argument to allow the map_sha1_file_1 caller 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.

---
 sha1_file.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
sha1_file.c +6 -5
index 9fa7243907..24832c4b32 100644
@@ -931,9 +931,10 @@ static int open_sha1_file_the_repository(const unsigned char *sha1,
  * Map the loose object at "path" if it is not NULL, or the path found by
  * searching for a loose object named "sha1".
  */
-static void *map_sha1_file_1(const char *path,
-			     const unsigned char *sha1,
-			     unsigned long *size)
+#define map_sha1_file_1(r, p, s, si) map_sha1_file_1_##r(p, s, si)
+static void *map_sha1_file_1_the_repository(const char *path,
+					    const unsigned char *sha1,
+					    unsigned long *size)
 {
 	void *map;
 	int fd;
@@ -962,7 +963,7 @@ static void *map_sha1_file_1(const char *path,
 
 void *map_sha1_file(const unsigned char *sha1, unsigned long *size)
 {
-	return map_sha1_file_1(NULL, sha1, size);
+	return map_sha1_file_1(the_repository, NULL, sha1, size);
 }
 
 static int unpack_sha1_short_header(git_zstream *stream,
@@ -2174,7 +2175,7 @@ int read_loose_object(const char *path,
 
 	*contents = NULL;
 
-	map = map_sha1_file_1(path, NULL, &mapsize);
+	map = map_sha1_file_1(the_repository, path, NULL, &mapsize);
 	if (!map) {
 		error_errno("unable to mmap %s", path);
 		goto out;
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#22 lore raw

PATCH 13/194 sha1_file: add repository argument to sha1_loose_object_info

In reply to Stefan Beller

Add a repository argument to allow the sha1_loose_object_info caller 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.

---
 sha1_file.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
sha1_file.c +5 -4
index 24832c4b32..514f59c390 100644
@@ -1152,9 +1152,10 @@ int parse_sha1_header(const char *hdr, unsigned long *sizep)
 	return parse_sha1_header_extended(hdr, &oi, 0);
 }
 
-static int sha1_loose_object_info(const unsigned char *sha1,
-				  struct object_info *oi,
-				  int flags)
+#define sha1_loose_object_info(r, s, o, f) sha1_loose_object_info_##r(s, o, f)
+static int sha1_loose_object_info_the_repository(const unsigned char *sha1,
+						 struct object_info *oi,
+						 int flags)
 {
 	int status = 0;
 	unsigned long mapsize;
@@ -1267,7 +1268,7 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,
 
 	if (!find_pack_entry(real, &e)) {
 		/* Most likely it's a loose object. */
-		if (!sha1_loose_object_info(real, oi, flags))
+		if (!sha1_loose_object_info(the_repository, real, oi, flags))
 			return 0;
 
 		/* Not a loose object; someone else may have just packed it. */
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#23 lore raw

PATCH 14/194 object-store: add repository argument to prepare_alt_odb

In reply to Stefan Beller

Add a repository argument to allow prepare_alt_odb callers 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.

While at it, move the declaration to object-store.h, where it should be easier to find.

---
 builtin/fsck.c |  2 +-
 cache.h        |  1 -
 object-store.h |  3 +++
 packfile.c     |  2 +-
 sha1_file.c    | 13 +++++++------
 sha1_name.c    |  3 ++-
 6 files changed, 14 insertions(+), 10 deletions(-)
builtin/fsck.c +1 -1
index d4d249c2ed..00ec8eecf0 100644
@@ -695,7 +695,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
 	} else {
 		fsck_object_dir(get_object_directory());
 
-		prepare_alt_odb();
+		prepare_alt_odb(the_repository);
 		for (alt = the_repository->objects.alt_odb_list;
 				alt; alt = alt->next)
 			fsck_object_dir(alt->path);
cache.h +0 -1
index 459fd01dbb..70518e24ce 100644
@@ -1592,7 +1592,6 @@ struct alternate_object_database {
 
 	char path[FLEX_ARRAY];
 };
-extern void prepare_alt_odb(void);
 extern char *compute_alternate_path(const char *path, struct strbuf *err);
 typedef int alt_odb_fn(struct alternate_object_database *, void *);
 extern int foreach_alt_odb(alt_odb_fn, void*);
object-store.h +3 -0
index 99f77d10cd..e749c952d5 100644
@@ -54,4 +54,7 @@ struct packed_git {
 	char pack_name[FLEX_ARRAY]; /* more */
 };
 
+#define prepare_alt_odb(r) prepare_alt_odb_##r()
+extern void prepare_alt_odb_the_repository(void);
+
 #endif /* OBJECT_STORE_H */
packfile.c +1 -1
index 31c4ea54ae..fbb2385bad 100644
@@ -879,7 +879,7 @@ void prepare_packed_git(void)
 	if (the_repository->objects.packed_git_initialized)
 		return;
 	prepare_packed_git_one(get_object_directory(), 1);
-	prepare_alt_odb();
+	prepare_alt_odb(the_repository);
 	for (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next)
 		prepare_packed_git_one(alt->path, 0);
 	rearrange_packed_git();
sha1_file.c +7 -6
index 514f59c390..779bfd4079 100644
@@ -23,6 +23,7 @@
 #include "sha1-lookup.h"
 #include "bulk-checkin.h"
 #include "repository.h"
+#include "object-store.h"
 #include "streaming.h"
 #include "dir.h"
 #include "mru.h"
@@ -585,7 +586,7 @@ void add_to_alternates_memory(const char *reference)
 	 * Make sure alternates are initialized, or else our entry may be
 	 * overwritten when they are.
 	 */
-	prepare_alt_odb();
+	prepare_alt_odb(the_repository);
 
 	link_alt_odb_entries(the_repository, reference,
 			     '\n', NULL, 0);
@@ -671,7 +672,7 @@ int foreach_alt_odb(alt_odb_fn fn, void *cb)
 	struct alternate_object_database *ent;
 	int r = 0;
 
-	prepare_alt_odb();
+	prepare_alt_odb(the_repository);
 	for (ent = the_repository->objects.alt_odb_list; ent; ent = ent->next) {
 		r = fn(ent, cb);
 		if (r)
@@ -680,7 +681,7 @@ int foreach_alt_odb(alt_odb_fn fn, void *cb)
 	return r;
 }
 
-void prepare_alt_odb(void)
+void prepare_alt_odb_the_repository(void)
 {
 	const char *alt;
 
@@ -729,7 +730,7 @@ static int check_and_freshen_local(const unsigned char *sha1, int freshen)
 static int check_and_freshen_nonlocal(const unsigned char *sha1, int freshen)
 {
 	struct alternate_object_database *alt;
-	prepare_alt_odb();
+	prepare_alt_odb(the_repository);
 	for (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next) {
 		const char *path = alt_sha1_path(alt, sha1);
 		if (check_and_freshen_file(path, freshen))
@@ -885,7 +886,7 @@ static int stat_sha1_file_the_repository(const unsigned char *sha1,
 	if (!lstat(*path, st))
 		return 0;
 
-	prepare_alt_odb();
+	prepare_alt_odb(the_repository);
 	errno = ENOENT;
 	for (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next) {
 		*path = alt_sha1_path(alt, sha1);
@@ -914,7 +915,7 @@ static int open_sha1_file_the_repository(const unsigned char *sha1,
 		return fd;
 	most_interesting_errno = errno;
 
-	prepare_alt_odb();
+	prepare_alt_odb(the_repository);
 	for (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next) {
 		*path = alt_sha1_path(alt, sha1);
 		fd = git_open(*path);
sha1_name.c +2 -1
index 016c883b5c..3e490ee8f6 100644
@@ -11,6 +11,7 @@
 #include "sha1-array.h"
 #include "packfile.h"
 #include "repository.h"
+#include "object-store.h"
 
 static int get_oid_oneline(const char *, struct object_id *, struct commit_list *);
 
@@ -353,7 +354,7 @@ static int init_object_disambiguation(const char *name, int len,
 
 	ds->len = len;
 	ds->hex_pfx[len] = '\0';
-	prepare_alt_odb();
+	prepare_alt_odb(the_repository);
 	return 0;
 }
 
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#24 lore raw

PATCH 15/194 object-store: add repository argument to foreach_alt_odb

In reply to Stefan Beller

Add a repository argument to allow foreach_alt_odb callers 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.

While at it, move the declaration to object-store.h, where it should be easier to find.

---
 builtin/count-objects.c     | 2 +-
 builtin/submodule--helper.c | 4 +++-
 cache.h                     | 2 --
 object-store.h              | 4 ++++
 sha1_file.c                 | 4 ++--
 transport.c                 | 4 +++-
 6 files changed, 13 insertions(+), 7 deletions(-)
builtin/count-objects.c +1 -1
index 9334648dcc..843a7d7d7e 100644
@@ -155,7 +155,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
 		printf("prune-packable: %lu\n", packed_loose);
 		printf("garbage: %lu\n", garbage);
 		printf("size-garbage: %s\n", garbage_buf.buf);
-		foreach_alt_odb(print_alternate, NULL);
+		foreach_alt_odb(the_repository, print_alternate, NULL);
 		strbuf_release(&loose_buf);
 		strbuf_release(&pack_buf);
 		strbuf_release(&garbage_buf);
builtin/submodule--helper.c +3 -1
index a5c4a8a694..8005adbf3d 100644
@@ -6,6 +6,7 @@
 #include "quote.h"
 #include "pathspec.h"
 #include "dir.h"
+#include "object-store.h"
 #include "submodule.h"
 #include "submodule-config.h"
 #include "string-list.h"
@@ -835,7 +836,8 @@ static void prepare_possible_alternates(const char *sm_name,
 		die(_("Value '%s' for submodule.alternateErrorStrategy is not recognized"), error_strategy);
 
 	if (!strcmp(sm_alternate, "superproject"))
-		foreach_alt_odb(add_possible_reference_from_superproject, &sas);
+		foreach_alt_odb(the_repository,
+				add_possible_reference_from_superproject, &sas);
 	else if (!strcmp(sm_alternate, "no"))
 		; /* do nothing */
 	else
cache.h +0 -2
index 70518e24ce..bba53f356d 100644
@@ -1593,8 +1593,6 @@ struct alternate_object_database {
 	char path[FLEX_ARRAY];
 };
 extern char *compute_alternate_path(const char *path, struct strbuf *err);
-typedef int alt_odb_fn(struct alternate_object_database *, void *);
-extern int foreach_alt_odb(alt_odb_fn, void*);
 
 /*
  * Allocate a "struct alternate_object_database" but do _not_ actually
object-store.h +4 -0
index e749c952d5..eef8d3b653 100644
@@ -57,4 +57,8 @@ struct packed_git {
 #define prepare_alt_odb(r) prepare_alt_odb_##r()
 extern void prepare_alt_odb_the_repository(void);
 
+typedef int alt_odb_fn(struct alternate_object_database *, void *);
+#define foreach_alt_odb(r, fn, cb) foreach_alt_odb_##r(fn, cb)
+extern int foreach_alt_odb_the_repository(alt_odb_fn, void*);
+
 #endif /* OBJECT_STORE_H */
sha1_file.c +2 -2
index 779bfd4079..7662692ee5 100644
@@ -667,7 +667,7 @@ char *compute_alternate_path(const char *path, struct strbuf *err)
 	return ref_git;
 }
 
-int foreach_alt_odb(alt_odb_fn fn, void *cb)
+int foreach_alt_odb_the_repository(alt_odb_fn fn, void *cb)
 {
 	struct alternate_object_database *ent;
 	int r = 0;
@@ -2103,7 +2103,7 @@ int for_each_loose_object(each_loose_object_fn cb, void *data, unsigned flags)
 
 	alt.cb = cb;
 	alt.data = data;
-	return foreach_alt_odb(loose_from_alt_odb, &alt);
+	return foreach_alt_odb(the_repository, loose_from_alt_odb, &alt);
 }
 
 static int check_stream_sha1(git_zstream *stream,
transport.c +3 -1
index fc802260f6..3f97fbe7c5 100644
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "config.h"
 #include "transport.h"
+#include "repository.h"
 #include "run-command.h"
 #include "pkt-line.h"
 #include "fetch-pack.h"
@@ -11,6 +12,7 @@
 #include "bundle.h"
 #include "dir.h"
 #include "refs.h"
+#include "object-store.h"
 #include "branch.h"
 #include "url.h"
 #include "submodule.h"
@@ -1294,5 +1296,5 @@ void for_each_alternate_ref(alternate_ref_fn fn, void *data)
 	struct alternate_refs_data cb;
 	cb.fn = fn;
 	cb.data = data;
-	foreach_alt_odb(refs_from_alternate_cb, &cb);
+	foreach_alt_odb(the_repository, refs_from_alternate_cb, &cb);
 }
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#25 lore raw

PATCH 16/194 pack: add repository argument to install_packed_git

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

Add a repository argument to allow install_packed_git callers 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.

---
 fast-import.c | 2 +-
 http.c        | 3 ++-
 packfile.c    | 4 ++--
 packfile.h    | 3 ++-
 4 files changed, 7 insertions(+), 5 deletions(-)
fast-import.c +1 -1
index 1685fe59a2..67550584da 100644
@@ -1038,7 +1038,7 @@ static void end_packfile(void)
 		if (!new_p)
 			die("core git rejected index %s", idx_name);
 		all_packs[pack_id] = new_p;
-		install_packed_git(new_p);
+		install_packed_git(the_repository, new_p);
 		free(idx_name);
 
 		/* Print the boundary */
http.c +2 -1
index ab989b88dd..979d9b3e46 100644
@@ -1,5 +1,6 @@
 #include "git-compat-util.h"
 #include "http.h"
+#include "repository.h"
 #include "config.h"
 #include "object-store.h"
 #include "pack.h"
@@ -2068,7 +2069,7 @@ int finish_http_pack_request(struct http_pack_request *preq)
 		return -1;
 	}
 
-	install_packed_git(p);
+	install_packed_git(the_repository, p);
 	free(tmp_idx);
 	return 0;
 }
packfile.c +2 -2
index fbb2385bad..0f63ec79c8 100644
@@ -671,7 +671,7 @@ struct packed_git *add_packed_git(const char *path, size_t path_len, int local)
 	return p;
 }
 
-void install_packed_git(struct packed_git *pack)
+void install_packed_git_the_repository(struct packed_git *pack)
 {
 	if (pack->pack_fd != -1)
 		pack_open_fds++;
@@ -773,7 +773,7 @@ static void prepare_packed_git_one(char *objdir, int local)
 			     * corresponding .pack file that we can map.
 			     */
 			    (p = add_packed_git(path.buf, path.len, local)) != NULL)
-				install_packed_git(p);
+				install_packed_git(the_repository, p);
 		}
 
 		if (!report_garbage)
packfile.h +2 -1
index 0cdeb54dcd..7e6959d440 100644
@@ -34,7 +34,8 @@ extern void (*report_garbage)(unsigned seen_bits, const char *path);
 
 extern void prepare_packed_git(void);
 extern void reprepare_packed_git(void);
-extern void install_packed_git(struct packed_git *pack);
+#define install_packed_git(r, p) install_packed_git_##r(p)
+extern void install_packed_git_the_repository(struct packed_git *pack);
 
 /*
  * Give a rough count of objects in the repository. This sacrifices accuracy
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#26 lore raw

PATCH 17/194 pack: add repository argument to prepare_packed_git_one

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

Add a repository argument to allow the prepare_packed_git_one caller 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.

---
 packfile.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
packfile.c +4 -3
index 0f63ec79c8..58473660cd 100644
@@ -726,7 +726,8 @@ static void report_pack_garbage(struct string_list *list)
 	report_helper(list, seen_bits, first, list->nr);
 }
 
-static void prepare_packed_git_one(char *objdir, int local)
+#define prepare_packed_git_one(r, o, l) prepare_packed_git_one_##r(o, l)
+static void prepare_packed_git_one_the_repository(char *objdir, int local)
 {
 	struct strbuf path = STRBUF_INIT;
 	size_t dirnamelen;
@@ -878,10 +879,10 @@ void prepare_packed_git(void)
 
 	if (the_repository->objects.packed_git_initialized)
 		return;
-	prepare_packed_git_one(get_object_directory(), 1);
+	prepare_packed_git_one(the_repository, get_object_directory(), 1);
 	prepare_alt_odb(the_repository);
 	for (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next)
-		prepare_packed_git_one(alt->path, 0);
+		prepare_packed_git_one(the_repository, alt->path, 0);
 	rearrange_packed_git();
 	prepare_packed_git_mru();
 	the_repository->objects.packed_git_initialized = 1;
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#27 lore raw

PATCH 18/194 pack: add repository argument to rearrange_packed_git

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

Add a repository argument to allow the rearrange_packed_git caller 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.

---
 packfile.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
packfile.c +3 -2
index 58473660cd..52cf9182c4 100644
@@ -857,7 +857,8 @@ static int sort_pack(const void *a_, const void *b_)
 	return -1;
 }
 
-static void rearrange_packed_git(void)
+#define rearrange_packed_git(r) rearrange_packed_git_##r()
+static void rearrange_packed_git_the_repository(void)
 {
 	the_repository->objects.packed_git = llist_mergesort(
 		the_repository->objects.packed_git, get_next_packed_git,
@@ -883,7 +884,7 @@ void prepare_packed_git(void)
 	prepare_alt_odb(the_repository);
 	for (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next)
 		prepare_packed_git_one(the_repository, alt->path, 0);
-	rearrange_packed_git();
+	rearrange_packed_git(the_repository);
 	prepare_packed_git_mru();
 	the_repository->objects.packed_git_initialized = 1;
 }
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#28 lore raw

PATCH 19/194 pack: add repository argument to prepare_packed_git_mru

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

Add a repository argument to allow the prepare_packed_git_mru caller 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.

---
 packfile.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
packfile.c +3 -2
index 52cf9182c4..b4ace96f0c 100644
@@ -865,7 +865,8 @@ static void rearrange_packed_git_the_repository(void)
 		set_next_packed_git, sort_pack);
 }
 
-static void prepare_packed_git_mru(void)
+#define prepare_packed_git_mru(r) prepare_packed_git_mru_##r()
+static void prepare_packed_git_mru_the_repository(void)
 {
 	struct packed_git *p;
 
@@ -885,7 +886,7 @@ void prepare_packed_git(void)
 	for (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next)
 		prepare_packed_git_one(the_repository, alt->path, 0);
 	rearrange_packed_git(the_repository);
-	prepare_packed_git_mru();
+	prepare_packed_git_mru(the_repository);
 	the_repository->objects.packed_git_initialized = 1;
 }
 
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#29 lore raw

PATCH 20/194 pack: add repository argument to prepare_packed_git

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

Add a repository argument to allow prepare_packed_git_mru callers 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.

Callers adapted using contrib/coccinelle/packed_git.cocci.

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

---
 builtin/count-objects.c             |  2 +-
 builtin/fsck.c                      |  2 +-
 builtin/gc.c                        |  2 +-
 builtin/pack-objects.c              |  2 +-
 builtin/pack-redundant.c            |  2 +-
 contrib/coccinelle/packed_git.cocci |  4 ++++
 fast-import.c                       |  2 +-
 http-backend.c                      |  2 +-
 pack-bitmap.c                       |  2 +-
 packfile.c                          | 10 +++++-----
 packfile.h                          |  3 ++-
 server-info.c                       |  2 +-
 sha1_name.c                         |  4 ++--
 13 files changed, 22 insertions(+), 17 deletions(-)
builtin/count-objects.c +1 -1
index 843a7d7d7e..e340b3e3c3 100644
@@ -123,7 +123,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
 		struct strbuf pack_buf = STRBUF_INIT;
 		struct strbuf garbage_buf = STRBUF_INIT;
 		if (!the_repository->objects.packed_git)
-			prepare_packed_git();
+			prepare_packed_git(the_repository);
 		for (p = the_repository->objects.packed_git; p; p = p->next) {
 			if (!p->pack_local)
 				continue;
builtin/fsck.c +1 -1
index 00ec8eecf0..0e78f4ba72 100644
@@ -705,7 +705,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
 			uint32_t total = 0, count = 0;
 			struct progress *progress = NULL;
 
-			prepare_packed_git();
+			prepare_packed_git(the_repository);
 
 			if (show_progress) {
 				for (p = the_repository->objects.packed_git; p;
builtin/gc.c +1 -1
index 6970f325e5..00a3b402a8 100644
@@ -174,7 +174,7 @@ static int too_many_packs(void)
 	if (gc_auto_pack_limit <= 0)
 		return 0;
 
-	prepare_packed_git();
+	prepare_packed_git(the_repository);
 	for (cnt = 0, p = the_repository->objects.packed_git; p; p = p->next) {
 		if (!p->pack_local)
 			continue;
builtin/pack-objects.c +1 -1
index 2ee8b69238..d42df2a2b9 100644
@@ -3121,7 +3121,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
 	if (progress && all_progress_implied)
 		progress = 2;
 
-	prepare_packed_git();
+	prepare_packed_git(the_repository);
 	if (ignore_packed_keep) {
 		struct packed_git *p;
 		for (p = the_repository->objects.packed_git; p; p = p->next)
builtin/pack-redundant.c +1 -1
index 55462bc826..83d2395dae 100644
@@ -631,7 +631,7 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix)
 			break;
 	}
 
-	prepare_packed_git();
+	prepare_packed_git(the_repository);
 
 	if (load_all_packs)
 		load_all();
contrib/coccinelle/packed_git.cocci +4 -0
index da317a51a9..7554f4773c 100644
@@ -5,3 +5,7 @@
 @@ @@
 - packed_git_mru
 + the_repository->objects.packed_git_mru
+
+@@ @@
+- prepare_packed_git()
++ prepare_packed_git(the_repository)
fast-import.c +1 -1
index 67550584da..39cd0b7540 100644
@@ -3471,7 +3471,7 @@ int cmd_main(int argc, const char **argv)
 		rc_free[i].next = &rc_free[i + 1];
 	rc_free[cmd_save - 1].next = NULL;
 
-	prepare_packed_git();
+	prepare_packed_git(the_repository);
 	start_packfile();
 	set_die_routine(die_nicely);
 	set_checkpoint_signal();
http-backend.c +1 -1
index 4d93126c15..4950078c93 100644
@@ -519,7 +519,7 @@ static void get_info_packs(struct strbuf *hdr, char *arg)
 	size_t cnt = 0;
 
 	select_getanyfile(hdr);
-	prepare_packed_git();
+	prepare_packed_git(the_repository);
 	for (p = the_repository->objects.packed_git; p; p = p->next) {
 		if (p->pack_local)
 			cnt++;
pack-bitmap.c +1 -1
index d51172b1d5..273bdfb631 100644
@@ -336,7 +336,7 @@ static int open_pack_bitmap(void)
 
 	assert(!bitmap_git.map && !bitmap_git.loaded);
 
-	prepare_packed_git();
+	prepare_packed_git(the_repository);
 	for (p = the_repository->objects.packed_git; p; p = p->next) {
 		if (open_pack_bitmap_1(p) == 0)
 			ret = 0;
packfile.c +5 -5
index b4ace96f0c..bf7e6d22ce 100644
@@ -807,7 +807,7 @@ unsigned long approximate_object_count(void)
 		unsigned long count;
 		struct packed_git *p;
 
-		prepare_packed_git();
+		prepare_packed_git(the_repository);
 		count = 0;
 		for (p = the_repository->objects.packed_git; p; p = p->next) {
 			if (open_pack_index(p))
@@ -875,7 +875,7 @@ static void prepare_packed_git_mru_the_repository(void)
 		mru_append(&the_repository->objects.packed_git_mru, p);
 }
 
-void prepare_packed_git(void)
+void prepare_packed_git_the_repository(void)
 {
 	struct alternate_object_database *alt;
 
@@ -894,7 +894,7 @@ void reprepare_packed_git(void)
 {
 	the_repository->objects.approximate_object_count_valid = 0;
 	the_repository->objects.packed_git_initialized = 0;
-	prepare_packed_git();
+	prepare_packed_git(the_repository);
 }
 
 unsigned long unpack_object_header_buffer(const unsigned char *buf,
@@ -1836,7 +1836,7 @@ int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)
 {
 	struct mru_entry *p;
 
-	prepare_packed_git();
+	prepare_packed_git(the_repository);
 	if (!the_repository->objects.packed_git)
 		return 0;
 
@@ -1888,7 +1888,7 @@ int for_each_packed_object(each_packed_object_fn cb, void *data, unsigned flags)
 	int r = 0;
 	int pack_errors = 0;
 
-	prepare_packed_git();
+	prepare_packed_git(the_repository);
 	for (p = the_repository->objects.packed_git; p; p = p->next) {
 		if ((flags & FOR_EACH_OBJECT_LOCAL_ONLY) && !p->pack_local)
 			continue;
packfile.h +2 -1
index 7e6959d440..e543a98b23 100644
@@ -32,7 +32,8 @@ extern struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_
 #define PACKDIR_FILE_GARBAGE 4
 extern void (*report_garbage)(unsigned seen_bits, const char *path);
 
-extern void prepare_packed_git(void);
+#define prepare_packed_git(r) prepare_packed_git_##r()
+extern void prepare_packed_git_the_repository(void);
 extern void reprepare_packed_git(void);
 #define install_packed_git(r, p) install_packed_git_##r(p)
 extern void install_packed_git_the_repository(struct packed_git *pack);
server-info.c +1 -1
index 96885c45f6..6cd1506e5e 100644
@@ -201,7 +201,7 @@ static void init_pack_info(const char *infofile, int force)
 	objdir = get_object_directory();
 	objdirlen = strlen(objdir);
 
-	prepare_packed_git();
+	prepare_packed_git(the_repository);
 	for (p = the_repository->objects.packed_git; p; p = p->next) {
 		/* we ignore things on alternate path since they are
 		 * not available to the pullers in general.
sha1_name.c +2 -2
index 3e490ee8f6..d3769713ea 100644
@@ -196,7 +196,7 @@ static void find_short_packed_object(struct disambiguate_state *ds)
 {
 	struct packed_git *p;
 
-	prepare_packed_git();
+	prepare_packed_git(the_repository);
 	for (p = the_repository->objects.packed_git; p && !ds->ambiguous;
 	     p = p->next)
 		unique_in_pack(p, ds);
@@ -567,7 +567,7 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad)
 {
 	struct packed_git *p;
 
-	prepare_packed_git();
+	prepare_packed_git(the_repository);
 	for (p = the_repository->objects.packed_git; p; p = p->next)
 		find_abbrev_len_for_pack(p, mad);
 }
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#30 lore raw

PATCH 21/194 pack: add repository argument to reprepare_packed_git

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

Add a repository argument to allow reprepare_packed_git_mru callers 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.

Callers adapted using contrib/coccinelle/packed_git.cocci.

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

---
 builtin/gc.c                        | 2 +-
 builtin/receive-pack.c              | 3 ++-
 bulk-checkin.c                      | 3 ++-
 contrib/coccinelle/packed_git.cocci | 4 ++++
 fetch-pack.c                        | 3 ++-
 packfile.c                          | 2 +-
 packfile.h                          | 3 ++-
 sha1_file.c                         | 2 +-
 8 files changed, 15 insertions(+), 7 deletions(-)
builtin/gc.c +1 -1
index 00a3b402a8..a3a4d4d4f3 100644
@@ -475,7 +475,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
 		return error(FAILED_RUN, rerere.argv[0]);
 
 	report_garbage = report_pack_garbage;
-	reprepare_packed_git();
+	reprepare_packed_git(the_repository);
 	if (pack_garbage.nr > 0)
 		clean_pack_garbage();
 
builtin/receive-pack.c +2 -1
index b2eac79a6e..744fe29366 100644
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "repository.h"
 #include "config.h"
 #include "lockfile.h"
 #include "pack.h"
@@ -1778,7 +1779,7 @@ static const char *unpack(int err_fd, struct shallow_info *si)
 		status = finish_command(&child);
 		if (status)
 			return "index-pack abnormal exit";
-		reprepare_packed_git();
+		reprepare_packed_git(the_repository);
 	}
 	return NULL;
 }
bulk-checkin.c +2 -1
index 3310fd210a..eadc2d5172 100644
@@ -3,6 +3,7 @@
  */
 #include "cache.h"
 #include "bulk-checkin.h"
+#include "repository.h"
 #include "csum-file.h"
 #include "pack.h"
 #include "strbuf.h"
@@ -57,7 +58,7 @@ static void finish_bulk_checkin(struct bulk_checkin_state *state)
 
 	strbuf_release(&packname);
 	/* Make objects we just wrote available to ourselves */
-	reprepare_packed_git();
+	reprepare_packed_git(the_repository);
 }
 
 static int already_written(struct bulk_checkin_state *state, unsigned char sha1[])
contrib/coccinelle/packed_git.cocci +4 -0
index 7554f4773c..0cb0e95f82 100644
@@ -9,3 +9,7 @@
 @@ @@
 - prepare_packed_git()
 + prepare_packed_git(the_repository)
+
+@@ @@
+- reprepare_packed_git()
++ reprepare_packed_git(the_repository)
fetch-pack.c +2 -1
index 9f6b07ad91..9c189ff3ec 100644
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "repository.h"
 #include "config.h"
 #include "lockfile.h"
 #include "refs.h"
@@ -1169,7 +1170,7 @@ struct ref *fetch_pack(struct fetch_pack_args *args,
 	prepare_shallow_info(&si, shallow);
 	ref_cpy = do_fetch_pack(args, fd, ref, sought, nr_sought,
 				&si, pack_lockfile);
-	reprepare_packed_git();
+	reprepare_packed_git(the_repository);
 	update_shallow(args, sought, nr_sought, &si);
 	clear_shallow_info(&si);
 	return ref_cpy;
packfile.c +1 -1
index bf7e6d22ce..6a1c8107ed 100644
@@ -890,7 +890,7 @@ void prepare_packed_git_the_repository(void)
 	the_repository->objects.packed_git_initialized = 1;
 }
 
-void reprepare_packed_git(void)
+void reprepare_packed_git_the_repository(void)
 {
 	the_repository->objects.approximate_object_count_valid = 0;
 	the_repository->objects.packed_git_initialized = 0;
packfile.h +2 -1
index e543a98b23..74f293c439 100644
@@ -34,7 +34,8 @@ extern void (*report_garbage)(unsigned seen_bits, const char *path);
 
 #define prepare_packed_git(r) prepare_packed_git_##r()
 extern void prepare_packed_git_the_repository(void);
-extern void reprepare_packed_git(void);
+#define reprepare_packed_git(r) reprepare_packed_git_##r()
+extern void reprepare_packed_git_the_repository(void);
 #define install_packed_git(r, p) install_packed_git_##r(p)
 extern void install_packed_git_the_repository(struct packed_git *pack);
 
sha1_file.c +1 -1
index 7662692ee5..f6e982880e 100644
@@ -1276,7 +1276,7 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,
 		if (flags & OBJECT_INFO_QUICK) {
 			return -1;
 		} else {
-			reprepare_packed_git();
+			reprepare_packed_git(the_repository);
 			if (!find_pack_entry(real, &e))
 				return -1;
 		}
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#31 lore raw

PATCH 21/194 pack: add repository argument to reprepare_packed_git

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

Add a repository argument to allow reprepare_packed_git_mru callers 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.

Callers adapted using contrib/coccinelle/packed_git.cocci.

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

---
 builtin/gc.c                        | 2 +-
 builtin/receive-pack.c              | 3 ++-
 bulk-checkin.c                      | 3 ++-
 contrib/coccinelle/packed_git.cocci | 4 ++++
 fetch-pack.c                        | 3 ++-
 packfile.c                          | 2 +-
 packfile.h                          | 3 ++-
 sha1_file.c                         | 2 +-
 8 files changed, 15 insertions(+), 7 deletions(-)
builtin/gc.c +1 -1
index 00a3b402a8..a3a4d4d4f3 100644
@@ -475,7 +475,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
 		return error(FAILED_RUN, rerere.argv[0]);
 
 	report_garbage = report_pack_garbage;
-	reprepare_packed_git();
+	reprepare_packed_git(the_repository);
 	if (pack_garbage.nr > 0)
 		clean_pack_garbage();
 
builtin/receive-pack.c +2 -1
index b2eac79a6e..744fe29366 100644
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "repository.h"
 #include "config.h"
 #include "lockfile.h"
 #include "pack.h"
@@ -1778,7 +1779,7 @@ static const char *unpack(int err_fd, struct shallow_info *si)
 		status = finish_command(&child);
 		if (status)
 			return "index-pack abnormal exit";
-		reprepare_packed_git();
+		reprepare_packed_git(the_repository);
 	}
 	return NULL;
 }
bulk-checkin.c +2 -1
index 3310fd210a..eadc2d5172 100644
@@ -3,6 +3,7 @@
  */
 #include "cache.h"
 #include "bulk-checkin.h"
+#include "repository.h"
 #include "csum-file.h"
 #include "pack.h"
 #include "strbuf.h"
@@ -57,7 +58,7 @@ static void finish_bulk_checkin(struct bulk_checkin_state *state)
 
 	strbuf_release(&packname);
 	/* Make objects we just wrote available to ourselves */
-	reprepare_packed_git();
+	reprepare_packed_git(the_repository);
 }
 
 static int already_written(struct bulk_checkin_state *state, unsigned char sha1[])
contrib/coccinelle/packed_git.cocci +4 -0
index 7554f4773c..0cb0e95f82 100644
@@ -9,3 +9,7 @@
 @@ @@
 - prepare_packed_git()
 + prepare_packed_git(the_repository)
+
+@@ @@
+- reprepare_packed_git()
++ reprepare_packed_git(the_repository)
fetch-pack.c +2 -1
index 9f6b07ad91..9c189ff3ec 100644
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "repository.h"
 #include "config.h"
 #include "lockfile.h"
 #include "refs.h"
@@ -1169,7 +1170,7 @@ struct ref *fetch_pack(struct fetch_pack_args *args,
 	prepare_shallow_info(&si, shallow);
 	ref_cpy = do_fetch_pack(args, fd, ref, sought, nr_sought,
 				&si, pack_lockfile);
-	reprepare_packed_git();
+	reprepare_packed_git(the_repository);
 	update_shallow(args, sought, nr_sought, &si);
 	clear_shallow_info(&si);
 	return ref_cpy;
packfile.c +1 -1
index bf7e6d22ce..6a1c8107ed 100644
@@ -890,7 +890,7 @@ void prepare_packed_git_the_repository(void)
 	the_repository->objects.packed_git_initialized = 1;
 }
 
-void reprepare_packed_git(void)
+void reprepare_packed_git_the_repository(void)
 {
 	the_repository->objects.approximate_object_count_valid = 0;
 	the_repository->objects.packed_git_initialized = 0;
packfile.h +2 -1
index e543a98b23..74f293c439 100644
@@ -34,7 +34,8 @@ extern void (*report_garbage)(unsigned seen_bits, const char *path);
 
 #define prepare_packed_git(r) prepare_packed_git_##r()
 extern void prepare_packed_git_the_repository(void);
-extern void reprepare_packed_git(void);
+#define reprepare_packed_git(r) reprepare_packed_git_##r()
+extern void reprepare_packed_git_the_repository(void);
 #define install_packed_git(r, p) install_packed_git_##r(p)
 extern void install_packed_git_the_repository(struct packed_git *pack);
 
sha1_file.c +1 -1
index 7662692ee5..f6e982880e 100644
@@ -1276,7 +1276,7 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,
 		if (flags & OBJECT_INFO_QUICK) {
 			return -1;
 		} else {
-			reprepare_packed_git();
+			reprepare_packed_git(the_repository);
 			if (!find_pack_entry(real, &e))
 				return -1;
 		}
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#32 lore raw

PATCH 22/194 pack: add repository argument to sha1_file_name

From: Jonathan Nieder <[email protected]>

Add a repository argument to allow sha1_file_name callers 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.

While at it, move the declaration to object-store.h, where it should be easier to find.

---
 cache.h        |  8 --------
 http-walker.c  |  3 ++-
 http.c         |  5 +++--
 object-store.h |  9 +++++++++
 sha1_file.c    | 11 ++++++-----
 5 files changed, 20 insertions(+), 16 deletions(-)
cache.h +0 -8
index bba53f356d..63ed5ccf0a 100644
@@ -956,14 +956,6 @@ extern void check_repository_format(void);
 #define DATA_CHANGED    0x0020
 #define TYPE_CHANGED    0x0040
 
-/*
- * Return the name of the file in the local object database that would
- * be used to store a loose object with the specified sha1.  The
- * return value is a pointer to a statically allocated buffer that is
- * overwritten each time the function is called.
- */
-extern const char *sha1_file_name(const unsigned char *sha1);
-
 /*
  * Return an abbreviated sha1 unique within this repository's object database.
  * The result will be at least `len` characters long, and will be NUL
http-walker.c +2 -1
index a1c6f2639b..96873bdfed 100644
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "repository.h"
 #include "commit.h"
 #include "walker.h"
 #include "http.h"
@@ -546,7 +547,7 @@ static int fetch_object(struct walker *walker, unsigned char *sha1)
 		ret = error("File %s has bad hash", hex);
 	} else if (req->rename < 0) {
 		ret = error("unable to write sha1 filename %s",
-			    sha1_file_name(req->sha1));
+			    sha1_file_name(the_repository, req->sha1));
 	}
 
 	release_http_object_request(req);
http.c +3 -2
index 979d9b3e46..ad57476635 100644
@@ -2182,7 +2182,7 @@ struct http_object_request *new_http_object_request(const char *base_url,
 	hashcpy(freq->sha1, sha1);
 	freq->localfile = -1;
 
-	filename = sha1_file_name(sha1);
+	filename = sha1_file_name(the_repository, sha1);
 	snprintf(freq->tmpfile, sizeof(freq->tmpfile),
 		 "%s.temp", filename);
 
@@ -2330,7 +2330,8 @@ int finish_http_object_request(struct http_object_request *freq)
 		return -1;
 	}
 	freq->rename =
-		finalize_object_file(freq->tmpfile, sha1_file_name(freq->sha1));
+		finalize_object_file(freq->tmpfile,
+				     sha1_file_name(the_repository, freq->sha1));
 
 	return freq->rename;
 }
object-store.h +9 -0
index eef8d3b653..228c2ce8ae 100644
@@ -54,6 +54,15 @@ struct packed_git {
 	char pack_name[FLEX_ARRAY]; /* more */
 };
 
+/*
+ * Return the name of the file in a repository's local object database
+ * that would be used to store a loose object with the specified sha1.
+ * The return value is a pointer to a statically allocated buffer that
+ * is overwritten each time the function is called.
+ */
+#define sha1_file_name(r, s) sha1_file_name_##r(s)
+extern const char *sha1_file_name_the_repository(const unsigned char *sha1);
+
 #define prepare_alt_odb(r) prepare_alt_odb_##r()
 extern void prepare_alt_odb_the_repository(void);
 
sha1_file.c +6 -5
index f6e982880e..caad178b14 100644
@@ -323,7 +323,7 @@ static void fill_sha1_path(struct strbuf *buf, const unsigned char *sha1)
 	}
 }
 
-const char *sha1_file_name(const unsigned char *sha1)
+const char *sha1_file_name_the_repository(const unsigned char *sha1)
 {
 	static struct strbuf buf = STRBUF_INIT;
 
@@ -724,7 +724,8 @@ int check_and_freshen_file(const char *fn, int freshen)
 
 static int check_and_freshen_local(const unsigned char *sha1, int freshen)
 {
-	return check_and_freshen_file(sha1_file_name(sha1), freshen);
+	return check_and_freshen_file(sha1_file_name(the_repository, sha1),
+				      freshen);
 }
 
 static int check_and_freshen_nonlocal(const unsigned char *sha1, int freshen)
@@ -882,7 +883,7 @@ static int stat_sha1_file_the_repository(const unsigned char *sha1,
 {
 	struct alternate_object_database *alt;
 
-	*path = sha1_file_name(sha1);
+	*path = sha1_file_name(the_repository, sha1);
 	if (!lstat(*path, st))
 		return 0;
 
@@ -909,7 +910,7 @@ static int open_sha1_file_the_repository(const unsigned char *sha1,
 	struct alternate_object_database *alt;
 	int most_interesting_errno;
 
-	*path = sha1_file_name(sha1);
+	*path = sha1_file_name(the_repository, sha1);
 	fd = git_open(*path);
 	if (fd >= 0)
 		return fd;
@@ -1576,7 +1577,7 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
 	git_SHA_CTX c;
 	unsigned char parano_sha1[20];
 	static struct strbuf tmp_file = STRBUF_INIT;
-	const char *filename = sha1_file_name(sha1);
+	const char *filename = sha1_file_name(the_repository, sha1);
 
 	fd = create_tmpfile(&tmp_file, filename);
 	if (fd < 0) {
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#33 lore raw

PATCH 23/194 pack: add repository argument to map_sha1_file

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

Add a repository argument to allow map_sha1_file callers 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.

While at it, move the declaration to object-store.h, where it should be easier to find.

---
 cache.h        | 1 -
 object-store.h | 2 ++
 sha1_file.c    | 4 ++--
 streaming.c    | 5 ++++-
 4 files changed, 8 insertions(+), 4 deletions(-)
cache.h +0 -1
index 63ed5ccf0a..051a77c49a 100644
@@ -1237,7 +1237,6 @@ 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 int git_open_cloexec(const char *name, int flags);
 #define git_open(name) git_open_cloexec(name, O_RDONLY)
-extern void *map_sha1_file(const unsigned char *sha1, unsigned long *size);
 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);
 
object-store.h +2 -0
index 228c2ce8ae..92fbf4a9ca 100644
@@ -62,6 +62,8 @@ struct packed_git {
  */
 #define sha1_file_name(r, s) sha1_file_name_##r(s)
 extern const char *sha1_file_name_the_repository(const unsigned char *sha1);
+#define map_sha1_file(r, s, sz) map_sha1_file_##r(s, sz)
+extern void *map_sha1_file_the_repository(const unsigned char *sha1, unsigned long *size);
 
 #define prepare_alt_odb(r) prepare_alt_odb_##r()
 extern void prepare_alt_odb_the_repository(void);
sha1_file.c +2 -2
index caad178b14..af0bf57e07 100644
@@ -963,7 +963,7 @@ static void *map_sha1_file_1_the_repository(const char *path,
 	return map;
 }
 
-void *map_sha1_file(const unsigned char *sha1, unsigned long *size)
+void *map_sha1_file_the_repository(const unsigned char *sha1, unsigned long *size)
 {
 	return map_sha1_file_1(the_repository, NULL, sha1, size);
 }
@@ -1188,7 +1188,7 @@ static int sha1_loose_object_info_the_repository(const unsigned char *sha1,
 		return 0;
 	}
 
-	map = map_sha1_file(sha1, &mapsize);
+	map = map_sha1_file(the_repository, sha1, &mapsize);
 	if (!map)
 		return -1;
 
streaming.c +4 -1
index 5892b50bd8..22d27df55e 100644
@@ -3,6 +3,8 @@
  */
 #include "cache.h"
 #include "streaming.h"
+#include "repository.h"
+#include "object-store.h"
 #include "packfile.h"
 
 enum input_source {
@@ -335,7 +337,8 @@ static struct stream_vtbl loose_vtbl = {
 
 static open_method_decl(loose)
 {
-	st->u.loose.mapped = map_sha1_file(sha1, &st->u.loose.mapsize);
+	st->u.loose.mapped = map_sha1_file(the_repository,
+					   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
#34 lore raw

PATCH 24/194 sha1_file: allow alt_odb_usable to handle arbitrary repositories

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

---
 sha1_file.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
sha1_file.c +9 -7
index af0bf57e07..c639c52f5f 100644
@@ -25,6 +25,7 @@
 #include "repository.h"
 #include "object-store.h"
 #include "streaming.h"
+#include "path.h"
 #include "dir.h"
 #include "mru.h"
 #include "list.h"
@@ -351,17 +352,18 @@ static const char *alt_sha1_path(struct alternate_object_database *alt,
 /*
  * Return non-zero iff the path is usable as an alternate object database.
  */
-#define alt_odb_usable(r, p, n) alt_odb_usable_##r(p, n)
-static int alt_odb_usable_the_repository(struct strbuf *path,
-					 const char *normalized_objdir)
+static int alt_odb_usable(struct repository *r, struct strbuf *path,
+			  const char *normalized_objdir)
 {
 	struct alternate_object_database *alt;
 
 	/* Detect cases where alternate disappeared */
 	if (!is_directory(path->buf)) {
-		error("object directory %s does not exist; "
-		      "check .git/objects/info/alternates.",
-		      path->buf);
+		struct strbuf sb = STRBUF_INIT;
+		strbuf_repo_git_path(&sb, r, "objects/info/alternates");
+		error("object directory %s does not exist; check %s",
+		      path->buf, sb.buf);
+		strbuf_release(&sb);
 		return 0;
 	}
 
@@ -369,7 +371,7 @@ static int alt_odb_usable_the_repository(struct strbuf *path,
 	 * Prevent the common mistake of listing the same
 	 * thing twice, or object directory itself.
 	 */
-	for (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next) {
+	for (alt = r->objects.alt_odb_list; alt; alt = alt->next) {
 		if (!fspathcmp(path->buf, alt->path))
 			return 0;
 	}
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#35 lore raw

PATCH 25/194 object-store: allow prepare_alt_odb to handle arbitrary repositories

In reply to Stefan Beller
---
 cache.h        |  4 ++++
 object-store.h |  3 +--
 sha1_file.c    | 63 ++++++++++++++++++++++++++++++----------------------------
 3 files changed, 38 insertions(+), 32 deletions(-)
cache.h +4 -0
index 051a77c49a..ce309cfe3f 100644
@@ -1581,6 +1581,10 @@ struct alternate_object_database {
 	char loose_objects_subdir_seen[256];
 	struct oid_array loose_objects_cache;
 
+	/*
+	 * Path to the alternate object database, relative to the
+	 * current working directory.
+	 */
 	char path[FLEX_ARRAY];
 };
 extern char *compute_alternate_path(const char *path, struct strbuf *err);
object-store.h +1 -2
index 92fbf4a9ca..fcf36c7370 100644
@@ -65,8 +65,7 @@ extern const char *sha1_file_name_the_repository(const unsigned char *sha1);
 #define map_sha1_file(r, s, sz) map_sha1_file_##r(s, sz)
 extern void *map_sha1_file_the_repository(const unsigned char *sha1, unsigned long *size);
 
-#define prepare_alt_odb(r) prepare_alt_odb_##r()
-extern void prepare_alt_odb_the_repository(void);
+extern void prepare_alt_odb(struct repository *r);
 
 typedef int alt_odb_fn(struct alternate_object_database *, void *);
 #define foreach_alt_odb(r, fn, cb) foreach_alt_odb_##r(fn, cb)
sha1_file.c +33 -30

125 lines not on this page · raw message

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

Re: [PATCH 025/194] object-store: allow prepare_alt_odb to handle arbitrary repositories

sha1_file.c static int link_alt_odb_entry_the_repository(const char *entry, · line 438

Quoted 9 lines · Stefan Beller
sha1_file.c +2 -2
@@ -434,12 +433,12 @@ static int link_alt_odb_entry_the_repository(const char *entry,
 	ent = alloc_alt_odb(pathbuf.buf);
 
 	/* add the alternate entry */
-	*the_repository->objects.alt_odb_tail = ent;
-	the_repository->objects.alt_odb_tail = &(ent->next);
+	*r->objects.alt_odb_tail = ent;
+	r->objects.alt_odb_tail = &(ent->next);
 	ent->next = NULL;

I'm sure I'm missing something obvious, but it's not clear to me that this transformation is correct. Could you perhaps say a few words about why it is?

Signature · 3 lines
brian m. carlson / brian with sandals: Houston, Texas, US
https://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: https://keybase.io/bk2204
#37 lore raw

Re: [PATCH 025/194] object-store: allow prepare_alt_odb to handle arbitrary repositories

Quoted 4 lines · brian m. carlson
Quoted 3 lines · Stefan Beller
sha1_file.c +0 -0
@@ -434,12 +433,12 @@ static int link_alt_odb_entry_the_repository(const char *entry,
  	ent = alloc_alt_odb(pathbuf.buf);
 
Quoted 9 lines

sha1_file.c static int link_alt_odb_entry_the_repository(const char *entry, · line 438

Quoted 6 lines
sha1_file.c +2 -2
  	/* add the alternate entry */
-	*the_repository->objects.alt_odb_tail = ent;
-	the_repository->objects.alt_odb_tail = &(ent->next);
+	*r->objects.alt_odb_tail = ent;
+	r->objects.alt_odb_tail = &(ent->next);
  	ent->next = NULL;

I'm sure I'm missing something obvious, but it's not clear to me that this transformation is correct. Could you perhaps say a few words about why it is?

I believe the reason it is correct is due to this change, higher up:

+static void read_info_alternates(struct repository *r,
+ const char *relative_base,
+ int depth);

Now the method takes a 'struct repository' pointer (which at this moment will always be the_repository) but it allows callers to use a different repository, when they are ready.

Thanks,
-Stolee

#38 lore raw

Re: [PATCH 025/194] object-store: allow prepare_alt_odb to handle arbitrary repositories

In reply to brian m. carlson
Quoted 4 lines · brian m. carlson
Quoted 3 lines · Stefan Beller
sha1_file.c +0 -0
@@ -434,12 +433,12 @@ static int link_alt_odb_entry_the_repository(const char *entry,
      ent = alloc_alt_odb(pathbuf.buf);
 
Quoted 10 lines

sha1_file.c static int link_alt_odb_entry_the_repository(const char *entry, · line 438

Quoted 6 lines
sha1_file.c +2 -2
      /* add the alternate entry */
-     *the_repository->objects.alt_odb_tail = ent;
-     the_repository->objects.alt_odb_tail = &(ent->next);
+     *r->objects.alt_odb_tail = ent;
+     r->objects.alt_odb_tail = &(ent->next);
      ent->next = NULL;

I'm sure I'm missing something obvious, but it's not clear to me that this transformation is correct. Could you perhaps say a few words about why it is?

This is a pretty open ended question, so I'll give it a try:

* ent is a local variable that is newly allocated using alloc_alt_odb. alloc_alt_odb has no hidden dependencies on a specific repository, it uses FLEX_ALLOC_STR, which is defined in cache.h as a wrapper around xcalloc/memcpy

* Before this patch we always used the_repository->objects.alt_odb_tail, but with this patch there is no reference "alt_odb.tail" of the_repository, but only of a given arbitrary repository.

Usually we convert only one function at a time. (Chose that function, which calls only already converted functions, because then passing in r instead of the_repository still compiles correctly)

The additional messiness comes from a cycle:
read_info_alternates

    -> link_alt_odb_entries
      -> link_alt_odb_entry
        -> read_info_alternates

That is why we cannot just convert one function, but we have to convert the whole strongly connected component in this graph of functions. This is why this patch is so messy and touches multiple functions at once.

* While I hope this helps, I assume you want me to repeat this or other hints in the commit message, too.

Thanks,
Stefan

#39 lore raw

Re: [PATCH 025/194] object-store: allow prepare_alt_odb to handle arbitrary repositories

Quoted 17 lines · Stefan Beller
Quoted 4 lines · brian m. carlson
Quoted 3 lines · Stefan Beller
sha1_file.c +0 -0
@@ -434,12 +433,12 @@ static int link_alt_odb_entry_the_repository(const char *entry,
      ent = alloc_alt_odb(pathbuf.buf);
 
Quoted 10 lines

sha1_file.c static int link_alt_odb_entry_the_repository(const char *entry, · line 438

Quoted 6 lines
sha1_file.c +2 -2
      /* add the alternate entry */
-     *the_repository->objects.alt_odb_tail = ent;
-     the_repository->objects.alt_odb_tail = &(ent->next);
+     *r->objects.alt_odb_tail = ent;
+     r->objects.alt_odb_tail = &(ent->next);
      ent->next = NULL;

I'm sure I'm missing something obvious, but it's not clear to me that this transformation is correct. Could you perhaps say a few words about why it is?

Quoted 1 line

This is a pretty open ended question, so I'll give it a try:

I apologize. My question was about the use of ent and ent->next, but it appears I merely misread the patch as converting from ent to &(ent->next), but that's not the case.

Signature · 3 lines
brian m. carlson / brian with sandals: Houston, Texas, US
https://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: https://keybase.io/bk2204
#40 lore raw

Re: [PATCH 025/194] object-store: allow prepare_alt_odb to handle arbitrary repositories

In reply to Stefan Beller

cache.h struct alternate_object_database { · line 1588

Quoted 5 lines · On Mon, 5 Feb 2018 15:54:46 -0800 Stefan Beller <[email protected]> wrote:
cache.h +4 -0
+	/*
+	 * Path to the alternate object database, relative to the
+	 * current working directory.
+	 */
 	char path[FLEX_ARRAY];

I would prefer this to be commented:

Path to the alternative object store. If this is a relative path, it is relative to the current working directory.

to show that it is not necessarily relative, but the current version is fine too.

sha1_file.c int foreach_alt_odb_the_repository(alt_odb_fn fn, void *cb) · line 700

Quoted 7 lines
sha1_file.c +7 -0
+		/*
+		 * Paths in alt are relative to the cwd. We ignore environment
+		 * settings like this for all repositories except for
+		 * the_repository, so we don't have to worry about transforming
+		 * the path to be relative to another repository.
+		 */
+		link_alt_odb_entries(r, alt, PATH_SEP, NULL, 0);

I find the comment confusing - it makes more sense for the reason for us not worrying about transforming the path is that the paths as stored in struct alternate_object_database are relative to the CWD, not that we ignore environment variables for certain repositories.

I think it's best to remove this comment, and instead add a comment to read_info_alternates() before its call to link_alt_odb_entries(), explaining that paths in the alternates file are relative to "info/alternates", not to the CWD (since that is the exceptional case).

All the patches prior to this look good. Thanks especially for the consistent naming convention of the patch titles.

#41 lore raw

PATCH 26/194 object-store: allow foreach_alt_odb to handle arbitrary repositories

In reply to Stefan Beller
---
 object-store.h |  3 +--
 sha1_file.c    | 14 +++++++-------
 2 files changed, 8 insertions(+), 9 deletions(-)
object-store.h +1 -2
index fcf36c7370..518da80367 100644
@@ -68,7 +68,6 @@ extern void *map_sha1_file_the_repository(const unsigned char *sha1, unsigned lo
 extern void prepare_alt_odb(struct repository *r);
 
 typedef int alt_odb_fn(struct alternate_object_database *, void *);
-#define foreach_alt_odb(r, fn, cb) foreach_alt_odb_##r(fn, cb)
-extern int foreach_alt_odb_the_repository(alt_odb_fn, void*);
+extern int foreach_alt_odb(struct repository *r, alt_odb_fn, void*);
 
 #endif /* OBJECT_STORE_H */
sha1_file.c +7 -7
index be67c69c75..ca492eb741 100644
@@ -665,18 +665,18 @@ char *compute_alternate_path(const char *path, struct strbuf *err)
 	return ref_git;
 }
 
-int foreach_alt_odb_the_repository(alt_odb_fn fn, void *cb)
+int foreach_alt_odb(struct repository *r, alt_odb_fn fn, void *cb)
 {
 	struct alternate_object_database *ent;
-	int r = 0;
+	int ret = 0;
 
-	prepare_alt_odb(the_repository);
-	for (ent = the_repository->objects.alt_odb_list; ent; ent = ent->next) {
-		r = fn(ent, cb);
-		if (r)
+	prepare_alt_odb(r);
+	for (ent = r->objects.alt_odb_list; ent; ent = ent->next) {
+		ret = fn(ent, cb);
+		if (ret)
 			break;
 	}
-	return r;
+	return ret;
 }
 
 void prepare_alt_odb(struct repository *r)
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#42 lore raw

PATCH 27/194 pack: allow install_packed_git to handle arbitrary repositories

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

---
 packfile.c | 6 +++---
 packfile.h | 3 +--
 2 files changed, 4 insertions(+), 5 deletions(-)
packfile.c +3 -3
index 6a1c8107ed..05b4505b2c 100644
@@ -671,13 +671,13 @@ struct packed_git *add_packed_git(const char *path, size_t path_len, int local)
 	return p;
 }
 
-void install_packed_git_the_repository(struct packed_git *pack)
+void install_packed_git(struct repository *r, struct packed_git *pack)
 {
 	if (pack->pack_fd != -1)
 		pack_open_fds++;
 
-	pack->next = the_repository->objects.packed_git;
-	the_repository->objects.packed_git = pack;
+	pack->next = r->objects.packed_git;
+	r->objects.packed_git = pack;
 }
 
 void (*report_garbage)(unsigned seen_bits, const char *path);
packfile.h +1 -2
index 74f293c439..ba6f08be99 100644
@@ -36,8 +36,7 @@ extern void (*report_garbage)(unsigned seen_bits, const char *path);
 extern void prepare_packed_git_the_repository(void);
 #define reprepare_packed_git(r) reprepare_packed_git_##r()
 extern void reprepare_packed_git_the_repository(void);
-#define install_packed_git(r, p) install_packed_git_##r(p)
-extern void install_packed_git_the_repository(struct packed_git *pack);
+extern void install_packed_git(struct repository *r, struct packed_git *pack);
 
 /*
  * Give a rough count of objects in the repository. This sacrifices accuracy
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#43 lore raw

PATCH 28/194 pack: allow rearrange_packed_git to handle arbitrary repositories

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

---
 packfile.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
packfile.c +3 -4
index 05b4505b2c..d1533ec948 100644
@@ -857,11 +857,10 @@ static int sort_pack(const void *a_, const void *b_)
 	return -1;
 }
 
-#define rearrange_packed_git(r) rearrange_packed_git_##r()
-static void rearrange_packed_git_the_repository(void)
+static void rearrange_packed_git(struct repository *r)
 {
-	the_repository->objects.packed_git = llist_mergesort(
-		the_repository->objects.packed_git, get_next_packed_git,
+	r->objects.packed_git = llist_mergesort(
+		r->objects.packed_git, get_next_packed_git,
 		set_next_packed_git, sort_pack);
 }
 
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#44 lore raw

PATCH 29/194 pack: allow prepare_packed_git_mru to handle arbitrary repositories

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

---
 packfile.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
packfile.c +4 -5
index d1533ec948..fd7dfc816e 100644
@@ -864,14 +864,13 @@ static void rearrange_packed_git(struct repository *r)
 		set_next_packed_git, sort_pack);
 }
 
-#define prepare_packed_git_mru(r) prepare_packed_git_mru_##r()
-static void prepare_packed_git_mru_the_repository(void)
+static void prepare_packed_git_mru(struct repository *r)
 {
 	struct packed_git *p;
 
-	mru_clear(&the_repository->objects.packed_git_mru);
-	for (p = the_repository->objects.packed_git; p; p = p->next)
-		mru_append(&the_repository->objects.packed_git_mru, p);
+	mru_clear(&r->objects.packed_git_mru);
+	for (p = r->objects.packed_git; p; p = p->next)
+		mru_append(&r->objects.packed_git_mru, p);
 }
 
 void prepare_packed_git_the_repository(void)
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#45 lore raw

PATCH 30/194 pack: allow prepare_packed_git_one to handle arbitrary repositories

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

---
 packfile.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
packfile.c +4 -5
index fd7dfc816e..2b73e62a44 100644
@@ -726,8 +726,8 @@ static void report_pack_garbage(struct string_list *list)
 	report_helper(list, seen_bits, first, list->nr);
 }
 
-#define prepare_packed_git_one(r, o, l) prepare_packed_git_one_##r(o, l)
-static void prepare_packed_git_one_the_repository(char *objdir, int local)
+static void prepare_packed_git_one(struct repository *r,
+				   char *objdir, int local)
 {
 	struct strbuf path = STRBUF_INIT;
 	size_t dirnamelen;
@@ -760,8 +760,7 @@ static void prepare_packed_git_one_the_repository(char *objdir, int local)
 		base_len = path.len;
 		if (strip_suffix_mem(path.buf, &base_len, ".idx")) {
 			/* Don't reopen a pack we already have. */
-			for (p = the_repository->objects.packed_git; p;
-			     p = p->next) {
+			for (p = r->objects.packed_git; p; p = p->next) {
 				size_t len;
 				if (strip_suffix(p->pack_name, ".pack", &len) &&
 				    len == base_len &&
@@ -774,7 +773,7 @@ static void prepare_packed_git_one_the_repository(char *objdir, int local)
 			     * corresponding .pack file that we can map.
 			     */
 			    (p = add_packed_git(path.buf, path.len, local)) != NULL)
-				install_packed_git(the_repository, p);
+				install_packed_git(r, p);
 		}
 
 		if (!report_garbage)
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#46 lore raw

PATCH 31/194 pack: allow prepare_packed_git to handle arbitrary repositories

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

---
 packfile.c | 18 +++++++++---------
 packfile.h |  3 +--
 2 files changed, 10 insertions(+), 11 deletions(-)
packfile.c +9 -9
index 2b73e62a44..7dc7e8e383 100644
@@ -872,19 +872,19 @@ static void prepare_packed_git_mru(struct repository *r)
 		mru_append(&r->objects.packed_git_mru, p);
 }
 
-void prepare_packed_git_the_repository(void)
+void prepare_packed_git(struct repository *r)
 {
 	struct alternate_object_database *alt;
 
-	if (the_repository->objects.packed_git_initialized)
+	if (r->objects.packed_git_initialized)
 		return;
-	prepare_packed_git_one(the_repository, get_object_directory(), 1);
-	prepare_alt_odb(the_repository);
-	for (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next)
-		prepare_packed_git_one(the_repository, alt->path, 0);
-	rearrange_packed_git(the_repository);
-	prepare_packed_git_mru(the_repository);
-	the_repository->objects.packed_git_initialized = 1;
+	prepare_packed_git_one(r, r->objectdir, 1);
+	prepare_alt_odb(r);
+	for (alt = r->objects.alt_odb_list; alt; alt = alt->next)
+		prepare_packed_git_one(r, alt->path, 0);
+	rearrange_packed_git(r);
+	prepare_packed_git_mru(r);
+	r->objects.packed_git_initialized = 1;
 }
 
 void reprepare_packed_git_the_repository(void)
packfile.h +1 -2
index ba6f08be99..75be3cb877 100644
@@ -32,8 +32,7 @@ extern struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_
 #define PACKDIR_FILE_GARBAGE 4
 extern void (*report_garbage)(unsigned seen_bits, const char *path);
 
-#define prepare_packed_git(r) prepare_packed_git_##r()
-extern void prepare_packed_git_the_repository(void);
+extern void prepare_packed_git(struct repository *r);
 #define reprepare_packed_git(r) reprepare_packed_git_##r()
 extern void reprepare_packed_git_the_repository(void);
 extern void install_packed_git(struct repository *r, struct packed_git *pack);
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#47 lore raw

PATCH 32/194 pack: allow reprepare_packed_git to handle arbitrary repositories

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

---
 packfile.c | 8 ++++----
 packfile.h | 3 +--
 2 files changed, 5 insertions(+), 6 deletions(-)
packfile.c +4 -4
index 7dc7e8e383..7aa69dd3c0 100644
@@ -887,11 +887,11 @@ void prepare_packed_git(struct repository *r)
 	r->objects.packed_git_initialized = 1;
 }
 
-void reprepare_packed_git_the_repository(void)
+void reprepare_packed_git(struct repository *r)
 {
-	the_repository->objects.approximate_object_count_valid = 0;
-	the_repository->objects.packed_git_initialized = 0;
-	prepare_packed_git(the_repository);
+	r->objects.approximate_object_count_valid = 0;
+	r->objects.packed_git_initialized = 0;
+	prepare_packed_git(r);
 }
 
 unsigned long unpack_object_header_buffer(const unsigned char *buf,
packfile.h +1 -2
index 75be3cb877..b3138816e7 100644
@@ -33,8 +33,7 @@ extern struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_
 extern void (*report_garbage)(unsigned seen_bits, const char *path);
 
 extern void prepare_packed_git(struct repository *r);
-#define reprepare_packed_git(r) reprepare_packed_git_##r()
-extern void reprepare_packed_git_the_repository(void);
+extern void reprepare_packed_git(struct repository *r);
 extern void install_packed_git(struct repository *r, struct packed_git *pack);
 
 /*
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#48 lore raw

PATCH 33/194 pack: allow sha1_file_name to handle arbitrary repositories

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

---
 object-store.h | 3 +--
 sha1_file.c    | 4 ++--
 2 files changed, 3 insertions(+), 4 deletions(-)
object-store.h +1 -2
index 518da80367..fe2187fd65 100644
@@ -60,8 +60,7 @@ struct packed_git {
  * The return value is a pointer to a statically allocated buffer that
  * is overwritten each time the function is called.
  */
-#define sha1_file_name(r, s) sha1_file_name_##r(s)
-extern const char *sha1_file_name_the_repository(const unsigned char *sha1);
+extern const char *sha1_file_name(struct repository *r, const unsigned char *sha1);
 #define map_sha1_file(r, s, sz) map_sha1_file_##r(s, sz)
 extern void *map_sha1_file_the_repository(const unsigned char *sha1, unsigned long *size);
 
sha1_file.c +2 -2
index ca492eb741..5d4c39bd45 100644
@@ -324,12 +324,12 @@ static void fill_sha1_path(struct strbuf *buf, const unsigned char *sha1)
 	}
 }
 
-const char *sha1_file_name_the_repository(const unsigned char *sha1)
+const char *sha1_file_name(struct repository *r, const unsigned char *sha1)
 {
 	static struct strbuf buf = STRBUF_INIT;
 
 	strbuf_reset(&buf);
-	strbuf_addf(&buf, "%s/", get_object_directory());
+	strbuf_addf(&buf, "%s/", r->objectdir);
 
 	fill_sha1_path(&buf, sha1);
 	return buf.buf;
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#49 lore raw

PATCH 34/194 pack: allow stat_sha1_file to handle arbitrary repositories

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

---
 sha1_file.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
sha1_file.c +5 -6
index 5d4c39bd45..6887543d5e 100644
@@ -882,19 +882,18 @@ int git_open_cloexec(const char *name, int flags)
  * Note that it may point to static storage and is only valid until another
  * call to sha1_file_name(), etc.
  */
-#define stat_sha1_file(r, s, st, p) stat_sha1_file_##r(s, st, p)
-static int stat_sha1_file_the_repository(const unsigned char *sha1,
-					 struct stat *st, const char **path)
+static int stat_sha1_file(struct repository *r, const unsigned char *sha1,
+			  struct stat *st, const char **path)
 {
 	struct alternate_object_database *alt;
 
-	*path = sha1_file_name(the_repository, sha1);
+	*path = sha1_file_name(r, sha1);
 	if (!lstat(*path, st))
 		return 0;
 
-	prepare_alt_odb(the_repository);
+	prepare_alt_odb(r);
 	errno = ENOENT;
-	for (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next) {
+	for (alt = r->objects.alt_odb_list; alt; alt = alt->next) {
 		*path = alt_sha1_path(alt, sha1);
 		if (!lstat(*path, st))
 			return 0;
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#50 lore raw

PATCH 35/194 pack: allow open_sha1_file to handle arbitrary repositories

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

---
 sha1_file.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
sha1_file.c +5 -6
index 6887543d5e..a0f438b493 100644
@@ -906,22 +906,21 @@ static int stat_sha1_file(struct repository *r, const unsigned char *sha1,
  * Like stat_sha1_file(), but actually open the object and return the
  * descriptor. See the caveats on the "path" parameter above.
  */
-#define open_sha1_file(r, s, p) open_sha1_file_##r(s, p)
-static int open_sha1_file_the_repository(const unsigned char *sha1,
-					 const char **path)
+static int open_sha1_file(struct repository *r,
+			  const unsigned char *sha1, const char **path)
 {
 	int fd;
 	struct alternate_object_database *alt;
 	int most_interesting_errno;
 
-	*path = sha1_file_name(the_repository, sha1);
+	*path = sha1_file_name(r, sha1);
 	fd = git_open(*path);
 	if (fd >= 0)
 		return fd;
 	most_interesting_errno = errno;
 
-	prepare_alt_odb(the_repository);
-	for (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next) {
+	prepare_alt_odb(r);
+	for (alt = r->objects.alt_odb_list; alt; alt = alt->next) {
 		*path = alt_sha1_path(alt, sha1);
 		fd = git_open(*path);
 		if (fd >= 0)
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#51 lore raw

PATCH 36/194 pack: allow map_sha1_file_1 to handle arbitrary repositories

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

---
 sha1_file.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
sha1_file.c +3 -5
index a0f438b493..590b857391 100644
@@ -936,10 +936,8 @@ static int open_sha1_file(struct repository *r,
  * Map the loose object at "path" if it is not NULL, or the path found by
  * searching for a loose object named "sha1".
  */
-#define map_sha1_file_1(r, p, s, si) map_sha1_file_1_##r(p, s, si)
-static void *map_sha1_file_1_the_repository(const char *path,
-					    const unsigned char *sha1,
-					    unsigned long *size)
+static void *map_sha1_file_1(struct repository *r, const char *path,
+			     const unsigned char *sha1, unsigned long *size)
 {
 	void *map;
 	int fd;
@@ -947,7 +945,7 @@ static void *map_sha1_file_1_the_repository(const char *path,
 	if (path)
 		fd = git_open(path);
 	else
-		fd = open_sha1_file(the_repository, sha1, &path);
+		fd = open_sha1_file(r, sha1, &path);
 	map = NULL;
 	if (fd >= 0) {
 		struct stat st;
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#52 lore raw

PATCH 37/194 pack: allow map_sha1_file to handle arbitrary repositories

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

---
 object-store.h | 3 +--
 sha1_file.c    | 5 +++--
 2 files changed, 4 insertions(+), 4 deletions(-)
object-store.h +1 -2
index fe2187fd65..57b8d89738 100644
@@ -61,8 +61,7 @@ struct packed_git {
  * is overwritten each time the function is called.
  */
 extern const char *sha1_file_name(struct repository *r, const unsigned char *sha1);
-#define map_sha1_file(r, s, sz) map_sha1_file_##r(s, sz)
-extern void *map_sha1_file_the_repository(const unsigned char *sha1, unsigned long *size);
+extern void *map_sha1_file(struct repository *r, const unsigned char *sha1, unsigned long *size);
 
 extern void prepare_alt_odb(struct repository *r);
 
sha1_file.c +3 -2
index 590b857391..786e904eab 100644
@@ -964,9 +964,10 @@ static void *map_sha1_file_1(struct repository *r, const char *path,
 	return map;
 }
 
-void *map_sha1_file_the_repository(const unsigned char *sha1, unsigned long *size)
+void *map_sha1_file(struct repository *r,
+		    const unsigned char *sha1, unsigned long *size)
 {
-	return map_sha1_file_1(the_repository, NULL, sha1, size);
+	return map_sha1_file_1(r, NULL, sha1, size);
 }
 
 static int unpack_sha1_short_header(git_zstream *stream,
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#53 lore raw

PATCH 38/194 pack: allow sha1_loose_object_info to handle arbitrary repositories

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

---
 sha1_file.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
sha1_file.c +5 -6
index 786e904eab..1e867bc293 100644
@@ -1156,10 +1156,9 @@ int parse_sha1_header(const char *hdr, unsigned long *sizep)
 	return parse_sha1_header_extended(hdr, &oi, 0);
 }
 
-#define sha1_loose_object_info(r, s, o, f) sha1_loose_object_info_##r(s, o, f)
-static int sha1_loose_object_info_the_repository(const unsigned char *sha1,
-						 struct object_info *oi,
-						 int flags)
+static int sha1_loose_object_info(struct repository *r,
+				  const unsigned char *sha1,
+				  struct object_info *oi, int flags)
 {
 	int status = 0;
 	unsigned long mapsize;
@@ -1183,14 +1182,14 @@ static int sha1_loose_object_info_the_repository(const unsigned char *sha1,
 	if (!oi->typep && !oi->typename && !oi->sizep && !oi->contentp) {
 		const char *path;
 		struct stat st;
-		if (stat_sha1_file(the_repository, sha1, &st, &path) < 0)
+		if (stat_sha1_file(r, sha1, &st, &path) < 0)
 			return -1;
 		if (oi->disk_sizep)
 			*oi->disk_sizep = st.st_size;
 		return 0;
 	}
 
-	map = map_sha1_file(the_repository, sha1, &mapsize);
+	map = map_sha1_file(r, sha1, &mapsize);
 	if (!map)
 		return -1;
 
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#54 lore raw

Re: [PATCH 038/194] pack: allow sha1_loose_object_info to handle arbitrary repositories

Quoted 7 lines · On Mon, 5 Feb 2018 15:54:59 -0800 Stefan Beller <[email protected]> wrote:

From: Jonathan Nieder <[email protected]>

---
 sha1_file.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

Thanks - I can see that this has been a lot of work, and it brings a lot of benefit. Among other things, this will probably allow me to remove the "fetch_if_missing" global variable that we need to set and reset in the partial clone series, replacing it with a setting in either the repo or the object store (and when fetching a missing object, first cloning the repo/store and then setting that setting, so that objects are not recursively fetched).

If we're planning to split the series up for merging in batches (which, as a reviewer, I'm very much in favor of), I think this is a good stopping point for the first batch, so I'll stop my review here for now. After these 38 patches, the net benefit is a better position of the packed object variables (in struct repository) and permitting the reading of loose objects in any repository. (Permitting the reading of any object in any repository, I see, will only come later in patch 74.)

#55 lore raw

Re: [PATCH 038/194] pack: allow sha1_loose_object_info to handle arbitrary repositories

Quoted 11 lines · Jonathan Tan
Quoted 7 lines · On Mon, 5 Feb 2018 15:54:59 -0800 Stefan Beller <[email protected]> wrote:

From: Jonathan Nieder <[email protected]>

---
 sha1_file.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
Quoted 7 lines

Thanks - I can see that this has been a lot of work, and it brings a lot of benefit. Among other things, this will probably allow me to remove the "fetch_if_missing" global variable that we need to set and reset in the partial clone series, replacing it with a setting in either the repo or the object store (and when fetching a missing object, first cloning the repo/store and then setting that setting, so that objects are not recursively fetched).

That sounds intriguing.

Quoted 3 lines

If we're planning to split the series up for merging in batches (which, as a reviewer, I'm very much in favor of), I think this is a good stopping point for the first batch, so I'll stop my review here for now.

Thanks for identifying a good spot.

I'll look at this part of the series closer for a reroll, and need to make sure there are no leftovers with the #define trick.

Quoted 4 lines

After these 38 patches, the net benefit is a better position of the packed object variables (in struct repository) and permitting the reading of loose objects in any repository. (Permitting the reading of any object in any repository, I see, will only come later in patch 74.)

which would then be a good portion for the next series.

Thanks for the review!

#56 lore raw

PATCH 39/194 replace_object.c: rename to use dash in file name

In reply to Stefan Beller

This is more consistent with the project style. The majority of Git's source files use dashes in preference to underscores in their file names.

Noticed while adding a header corresponding to this file.

---
 Makefile                             | 2 +-
 replace_object.c => replace-object.c | 0
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename replace_object.c => replace-object.c (100%)
Makefile +1 -1
index 1a9b23b679..84aeabe320 100644
@@ -873,7 +873,7 @@ LIB_OBJS += refs/packed-backend.o
 LIB_OBJS += refs/ref-cache.o
 LIB_OBJS += ref-filter.o
 LIB_OBJS += remote.o
-LIB_OBJS += replace_object.o
+LIB_OBJS += replace-object.o
 LIB_OBJS += repository.o
 LIB_OBJS += rerere.o
 LIB_OBJS += resolve-undo.o
replace-object.c renamed from replace_object.c +0 -0
similarity index 100%
rename from replace_object.c
rename to replace-object.c
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#57 lore raw

PATCH 40/194 replace-object: move replace_object to object store

In reply to Stefan Beller

Refs belong to particular repositories, so the replacements defined by them should belong to a particular repository as well.

---
 object-store.h   |  9 ++++++++-
 replace-object.c | 42 ++++++++++++++++++------------------------
 replace-object.h | 20 ++++++++++++++++++++
 3 files changed, 46 insertions(+), 25 deletions(-)
 create mode 100644 replace-object.h
object-store.h +8 -1
index 57b8d89738..298e34e978 100644
@@ -3,6 +3,7 @@
 
 #include "cache.h"
 #include "mru.h"
+#include "replace-object.h"
 
 struct object_store {
 	struct packed_git *packed_git;
@@ -16,6 +17,12 @@ struct object_store {
 	struct alternate_object_database *alt_odb_list;
 	struct alternate_object_database **alt_odb_tail;
 
+	/*
+	 * Objects that should be substituted by other objects
+	 * (see git-replace(1)).
+	 */
+	struct replace_objects replacements;
+
 	/*
 	 * A fast, rough count of the number of objects in the repository.
 	 * These two fields are not meant for direct access. Use
@@ -30,7 +37,7 @@ struct object_store {
 	 */
 	unsigned packed_git_initialized : 1;
 };
-#define OBJECT_STORE_INIT { NULL, MRU_INIT, NULL, NULL, 0, 0, 0 }
+#define OBJECT_STORE_INIT { NULL, MRU_INIT, NULL, NULL, REPLACE_OBJECTS_INIT, 0, 0, 0 }
 
 struct packed_git {
 	struct packed_git *next;
replace-object.c +18 -24

78 lines not on this page · raw message

replace-object.h new file +20 -0
new file mode 100644
index 0000000000..483335ffcc
@@ -0,0 +1,20 @@
+#ifndef REPLACE_OBJECT_H
+#define REPLACE_OBJECT_H
+
+struct replace_objects {
+	/*
+	 * An array of replacements.  The array is kept sorted by the original
+	 * sha1.
+	 */
+	struct replace_object **items;
+
+	int alloc, nr;
+};
+#define REPLACE_OBJECTS_INIT { NULL, 0, 0 }
+
+struct replace_object {
+	unsigned char original[20];
+	unsigned char replacement[20];
+};
+
+#endif /* REPLACE_OBJECT_H */
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#58 lore raw

PATCH 41/194 sha1_file: add repository argument to sha1_object_info_extended

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

Add a repository argument to allow sha1_object_info_extended callers 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.

---
 builtin/cat-file.c |  6 +++---
 cache.h            |  4 +++-
 packfile.c         |  2 +-
 sha1_file.c        | 11 ++++++-----
 streaming.c        |  2 +-
 5 files changed, 14 insertions(+), 11 deletions(-)
builtin/cat-file.c +3 -3
index f5fa4fd75a..9d18efeb7c 100644
@@ -77,7 +77,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
 	switch (opt) {
 	case 't':
 		oi.typename = &sb;
-		if (sha1_object_info_extended(oid.hash, &oi, flags) < 0)
+		if (sha1_object_info_extended(the_repository, oid.hash, &oi, flags) < 0)
 			die("git cat-file: could not get object info");
 		if (sb.len) {
 			printf("%s\n", sb.buf);
@@ -88,7 +88,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
 
 	case 's':
 		oi.sizep = &size;
-		if (sha1_object_info_extended(oid.hash, &oi, flags) < 0)
+		if (sha1_object_info_extended(the_repository, oid.hash, &oi, flags) < 0)
 			die("git cat-file: could not get object info");
 		printf("%lu\n", size);
 		return 0;
@@ -340,7 +340,7 @@ static void batch_object_write(const char *obj_name, struct batch_options *opt,
 	struct strbuf buf = STRBUF_INIT;
 
 	if (!data->skip_object_info &&
-	    sha1_object_info_extended(data->oid.hash, &data->info,
+	    sha1_object_info_extended(the_repository, data->oid.hash, &data->info,
 				      OBJECT_INFO_LOOKUP_REPLACE) < 0) {
 		printf("%s missing\n",
 		       obj_name ? obj_name : oid_to_hex(&data->oid));
cache.h +3 -1
index ce309cfe3f..3410a93737 100644
@@ -1749,7 +1749,9 @@ struct object_info {
 #define OBJECT_INFO_SKIP_CACHED 4
 /* Do not retry packed storage after checking packed and loose storage */
 #define OBJECT_INFO_QUICK 8
-extern int sha1_object_info_extended(const unsigned char *, struct object_info *, unsigned flags);
+#define sha1_object_info_extended(r, s, oi, f) \
+		sha1_object_info_extended_##r(s, oi, f)
+extern int sha1_object_info_extended_the_repository(const unsigned char *, struct object_info *, unsigned flags);
 
 /* Dumb servers support */
 extern int update_server_info(int);
packfile.c +1 -1
index 7aa69dd3c0..0ca13a4ed7 100644
@@ -1450,7 +1450,7 @@ static void *read_object(const unsigned char *sha1, enum object_type *type,
 	oi.sizep = size;
 	oi.contentp = &content;
 
-	if (sha1_object_info_extended(sha1, &oi, 0) < 0)
+	if (sha1_object_info_extended(the_repository, sha1, &oi, 0) < 0)
 		return NULL;
 	return content;
 }
sha1_file.c +6 -5
index 1e867bc293..a5dcb76d96 100644
@@ -1234,7 +1234,7 @@ static int sha1_loose_object_info(struct repository *r,
 	return (status < 0) ? status : 0;
 }
 
-int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi, unsigned flags)
+int sha1_object_info_extended_the_repository(const unsigned char *sha1, struct object_info *oi, unsigned flags)
 {
 	static struct object_info blank_oi = OBJECT_INFO_INIT;
 	struct pack_entry e;
@@ -1294,7 +1294,8 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,
 	rtype = packed_object_info(e.p, e.offset, oi);
 	if (rtype < 0) {
 		mark_bad_packed_object(e.p, real);
-		return sha1_object_info_extended(real, oi, 0);
+		return sha1_object_info_extended(the_repository, real, oi,
+						 0);
 	} else if (oi->whence == OI_PACKED) {
 		oi->u.packed.offset = e.offset;
 		oi->u.packed.pack = e.p;
@@ -1313,7 +1314,7 @@ int sha1_object_info(const unsigned char *sha1, unsigned long *sizep)
 
 	oi.typep = &type;
 	oi.sizep = sizep;
-	if (sha1_object_info_extended(sha1, &oi,
+	if (sha1_object_info_extended(the_repository, sha1, &oi,
 				      OBJECT_INFO_LOOKUP_REPLACE) < 0)
 		return -1;
 	return type;
@@ -1328,7 +1329,7 @@ static void *read_object(const unsigned char *sha1, enum object_type *type,
 	oi.sizep = size;
 	oi.contentp = &content;
 
-	if (sha1_object_info_extended(sha1, &oi, 0) < 0)
+	if (sha1_object_info_extended(the_repository, sha1, &oi, 0) < 0)
 		return NULL;
 	return content;
 }
@@ -1715,7 +1716,7 @@ int has_sha1_file_with_flags(const unsigned char *sha1, int flags)
 {
 	if (!startup_info->have_repository)
 		return 0;
-	return sha1_object_info_extended(sha1, NULL,
+	return sha1_object_info_extended(the_repository, sha1, NULL,
 					 flags | OBJECT_INFO_SKIP_CACHED) >= 0;
 }
 
streaming.c +1 -1
index 22d27df55e..47fca9aba0 100644
@@ -116,7 +116,7 @@ static enum input_source istream_source(const unsigned char *sha1,
 
 	oi->typep = type;
 	oi->sizep = &size;
-	status = sha1_object_info_extended(sha1, oi, 0);
+	status = sha1_object_info_extended(the_repository, sha1, oi, 0);
 	if (status < 0)
 		return stream_error;
 
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#59 lore raw

PATCH 42/194 object-store: move alternates API to new alternates.h

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

This should make these functions easier to find and object-store.h less overwhelming to read.

---
 alternates.h                | 68 +++++++++++++++++++++++++++++++++++++++++++++
 builtin/clone.c             |  1 +
 builtin/count-objects.c     |  1 +
 builtin/fsck.c              |  3 +-
 builtin/grep.c              |  1 +
 builtin/submodule--helper.c |  1 +
 cache.h                     | 52 ----------------------------------
 object-store.h              | 16 +++++------
 packfile.c                  |  3 +-
 sha1_file.c                 | 23 +++++++--------
 sha1_name.c                 |  3 +-
 submodule.c                 |  1 +
 t/helper/test-ref-store.c   |  1 +
 tmp-objdir.c                |  1 +
 transport.c                 |  1 +
 15 files changed, 102 insertions(+), 74 deletions(-)
 create mode 100644 alternates.h
alternates.h new file +68 -0
new file mode 100644
index 0000000000..df5dc67e2e
@@ -0,0 +1,68 @@
+#ifndef ALTERNATES_H
+#define ALTERNATES_H
+
+#include "strbuf.h"
+#include "sha1-array.h"
+
+struct alternates {
+	struct alternate_object_database *list;
+	struct alternate_object_database **tail;
+};
+#define ALTERNATES_INIT { NULL, NULL }
+
+struct alternate_object_database {
+	struct alternate_object_database *next;
+
+	/* see alt_scratch_buf() */
+	struct strbuf scratch;
+	size_t base_len;
+
+	/*
+	 * Used to store the results of readdir(3) calls when searching
+	 * for unique abbreviated hashes.  This cache is never
+	 * invalidated, thus it's racy and not necessarily accurate.
+	 * That's fine for its purpose; don't use it for tasks requiring
+	 * greater accuracy!
+	 */
+	char loose_objects_subdir_seen[256];
+	struct oid_array loose_objects_cache;
+
+	/*
+	 * Path to the alternate object database, relative to the
+	 * current working directory.
+	 */
+	char path[FLEX_ARRAY];
+};
+extern void prepare_alt_odb(struct repository *r);
+extern char *compute_alternate_path(const char *path, struct strbuf *err);
+typedef int alt_odb_fn(struct alternate_object_database *, void *);
+extern int foreach_alt_odb(struct repository *r, alt_odb_fn, void*);
+
+/*
+ * Allocate a "struct alternate_object_database" but do _not_ actually
+ * add it to the list of alternates.
+ */
+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);
+
+/*
+ * Add the directory to the in-memory list of alternates (along with any
+ * recursive alternates it points to), but do not modify the on-disk alternates
+ * file.
+ */
+extern void add_to_alternates_memory(const char *dir);
+
+/*
+ * Returns a scratch strbuf pre-filled with the alternate object directory,
+ * including a trailing slash, which can be used to access paths in the
+ * alternate. Always use this over direct access to alt->scratch, as it
+ * cleans up any previous use of the scratch buffer.
+ */
+extern struct strbuf *alt_scratch_buf(struct alternate_object_database *alt);
+
+#endif /* ALTERNATES_H */
builtin/clone.c +1 -0
index 2da71db107..27463c8fc5 100644
@@ -11,6 +11,7 @@
 #include "builtin.h"
 #include "config.h"
 #include "lockfile.h"
+#include "alternates.h"
 #include "parse-options.h"
 #include "fetch-pack.h"
 #include "refs.h"
builtin/count-objects.c +1 -0
index e340b3e3c3..805803fedd 100644
@@ -8,6 +8,7 @@
 #include "config.h"
 #include "dir.h"
 #include "repository.h"
+#include "alternates.h"
 #include "object-store.h"
 #include "builtin.h"
 #include "parse-options.h"
builtin/fsck.c +2 -1
index 0e78f4ba72..571aa51579 100644
@@ -2,6 +2,7 @@
 #include "cache.h"
 #include "repository.h"
 #include "config.h"
+#include "alternates.h"
 #include "object-store.h"
 #include "commit.h"
 #include "tree.h"
@@ -696,7 +697,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
 		fsck_object_dir(get_object_directory());
 
 		prepare_alt_odb(the_repository);
-		for (alt = the_repository->objects.alt_odb_list;
+		for (alt = the_repository->objects.alt_odb.list;
 				alt; alt = alt->next)
 			fsck_object_dir(alt->path);
 
builtin/grep.c +1 -0
index 3ca4ac80d8..1c71dff341 100644
@@ -6,6 +6,7 @@
 #include "cache.h"
 #include "repository.h"
 #include "config.h"
+#include "alternates.h"
 #include "blob.h"
 #include "tree.h"
 #include "commit.h"
builtin/submodule--helper.c +1 -0
index 8005adbf3d..10024c2fa2 100644
@@ -2,6 +2,7 @@
 #include "repository.h"
 #include "cache.h"
 #include "config.h"
+#include "alternates.h"
 #include "parse-options.h"
 #include "quote.h"
 #include "pathspec.h"
cache.h +0 -52

58 lines not on this page · raw message

object-store.h +8 -8
index 298e34e978..967dd8af26 100644
@@ -4,6 +4,7 @@
 #include "cache.h"
 #include "mru.h"
 #include "replace-object.h"
+#include "alternates.h"
 
 struct object_store {
 	struct packed_git *packed_git;
@@ -14,8 +15,11 @@ struct object_store {
 	 */
 	struct mru packed_git_mru;
 
-	struct alternate_object_database *alt_odb_list;
-	struct alternate_object_database **alt_odb_tail;
+	/*
+	 * Additional object databases to fall back on when an object does not
+	 * exist in the current one (see --reference in git-clone(1)).
+	 */
+	struct alternates alt_odb;
 
 	/*
 	 * Objects that should be substituted by other objects
@@ -37,7 +41,8 @@ struct object_store {
 	 */
 	unsigned packed_git_initialized : 1;
 };
-#define OBJECT_STORE_INIT { NULL, MRU_INIT, NULL, NULL, REPLACE_OBJECTS_INIT, 0, 0, 0 }
+#define OBJECT_STORE_INIT \
+	{ NULL, MRU_INIT, ALTERNATES_INIT, REPLACE_OBJECTS_INIT, 0, 0, 0 }
 
 struct packed_git {
 	struct packed_git *next;
@@ -70,9 +75,4 @@ struct packed_git {
 extern const char *sha1_file_name(struct repository *r, const unsigned char *sha1);
 extern void *map_sha1_file(struct repository *r, const unsigned char *sha1, unsigned long *size);
 
-extern void prepare_alt_odb(struct repository *r);
-
-typedef int alt_odb_fn(struct alternate_object_database *, void *);
-extern int foreach_alt_odb(struct repository *r, alt_odb_fn, void*);
-
 #endif /* OBJECT_STORE_H */
packfile.c +2 -1
index 0ca13a4ed7..a7504debe5 100644
@@ -2,6 +2,7 @@
 #include "mru.h"
 #include "pack.h"
 #include "repository.h"
+#include "alternates.h"
 #include "dir.h"
 #include "mergesort.h"
 #include "packfile.h"
@@ -880,7 +881,7 @@ void prepare_packed_git(struct repository *r)
 		return;
 	prepare_packed_git_one(r, r->objectdir, 1);
 	prepare_alt_odb(r);
-	for (alt = r->objects.alt_odb_list; alt; alt = alt->next)
+	for (alt = r->objects.alt_odb.list; alt; alt = alt->next)
 		prepare_packed_git_one(r, alt->path, 0);
 	rearrange_packed_git(r);
 	prepare_packed_git_mru(r);
sha1_file.c +12 -11
index a5dcb76d96..84501d66e9 100644
@@ -10,6 +10,7 @@
 #include "config.h"
 #include "string-list.h"
 #include "lockfile.h"
+#include "alternates.h"
 #include "delta.h"
 #include "pack.h"
 #include "blob.h"
@@ -371,7 +372,7 @@ static int alt_odb_usable(struct repository *r, struct strbuf *path,
 	 * Prevent the common mistake of listing the same
 	 * thing twice, or object directory itself.
 	 */
-	for (alt = r->objects.alt_odb_list; alt; alt = alt->next) {
+	for (alt = r->objects.alt_odb.list; alt; alt = alt->next) {
 		if (!fspathcmp(path->buf, alt->path))
 			return 0;
 	}
@@ -384,7 +385,7 @@ static int alt_odb_usable(struct repository *r, struct strbuf *path,
 /*
  * Prepare alternate object database registry.
  *
- * The variable alt_odb_list points at the list of struct
+ * The variable objects.alt_odb.list points at the list of struct
  * alternate_object_database.  The elements on this list come from
  * non-empty elements from colon separated ALTERNATE_DB_ENVIRONMENT
  * environment variable, and $GIT_OBJECT_DIRECTORY/info/alternates,
@@ -433,8 +434,8 @@ static int link_alt_odb_entry(struct repository *r, const char *entry,
 	ent = alloc_alt_odb(pathbuf.buf);
 
 	/* add the alternate entry */
-	*r->objects.alt_odb_tail = ent;
-	r->objects.alt_odb_tail = &(ent->next);
+	*r->objects.alt_odb.tail = ent;
+	r->objects.alt_odb.tail = &(ent->next);
 	ent->next = NULL;
 
 	/* recursively add alternates */
@@ -571,7 +572,7 @@ void add_to_alternates_file(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)
+		if (the_repository->objects.alt_odb.tail)
 			link_alt_odb_entries(the_repository, reference,
 					     '\n', NULL, 0);
 	}
@@ -671,7 +672,7 @@ int foreach_alt_odb(struct repository *r, alt_odb_fn fn, void *cb)
 	int ret = 0;
 
 	prepare_alt_odb(r);
-	for (ent = r->objects.alt_odb_list; ent; ent = ent->next) {
+	for (ent = r->objects.alt_odb.list; ent; ent = ent->next) {
 		ret = fn(ent, cb);
 		if (ret)
 			break;
@@ -681,10 +682,10 @@ int foreach_alt_odb(struct repository *r, alt_odb_fn fn, void *cb)
 
 void prepare_alt_odb(struct repository *r)
 {
-	if (r->objects.alt_odb_tail)
+	if (r->objects.alt_odb.tail)
 		return;
 
-	r->objects.alt_odb_tail = &r->objects.alt_odb_list;
+	r->objects.alt_odb.tail = &r->objects.alt_odb.list;
 
 	if (!r->ignore_env) {
 		const char *alt = getenv(ALTERNATE_DB_ENVIRONMENT);
@@ -737,7 +738,7 @@ static int check_and_freshen_nonlocal(const unsigned char *sha1, int freshen)
 {
 	struct alternate_object_database *alt;
 	prepare_alt_odb(the_repository);
-	for (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next) {
+	for (alt = the_repository->objects.alt_odb.list; alt; alt = alt->next) {
 		const char *path = alt_sha1_path(alt, sha1);
 		if (check_and_freshen_file(path, freshen))
 			return 1;
@@ -893,7 +894,7 @@ static int stat_sha1_file(struct repository *r, const unsigned char *sha1,
 
 	prepare_alt_odb(r);
 	errno = ENOENT;
-	for (alt = r->objects.alt_odb_list; alt; alt = alt->next) {
+	for (alt = r->objects.alt_odb.list; alt; alt = alt->next) {
 		*path = alt_sha1_path(alt, sha1);
 		if (!lstat(*path, st))
 			return 0;
@@ -920,7 +921,7 @@ static int open_sha1_file(struct repository *r,
 	most_interesting_errno = errno;
 
 	prepare_alt_odb(r);
-	for (alt = r->objects.alt_odb_list; alt; alt = alt->next) {
+	for (alt = r->objects.alt_odb.list; alt; alt = alt->next) {
 		*path = alt_sha1_path(alt, sha1);
 		fd = git_open(*path);
 		if (fd >= 0)
sha1_name.c +2 -1
index d3769713ea..363f7e1d4d 100644
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "config.h"
+#include "alternates.h"
 #include "tag.h"
 #include "commit.h"
 #include "tree.h"
@@ -106,7 +107,7 @@ static void find_short_object_filename(struct disambiguate_state *ds)
 		 */
 		fakeent = alloc_alt_odb(get_object_directory());
 	}
-	fakeent->next = the_repository->objects.alt_odb_list;
+	fakeent->next = the_repository->objects.alt_odb.list;
 
 	for (alt = fakeent; alt && !ds->ambiguous; alt = alt->next) {
 		int pos;
submodule.c +1 -0
index 2967704317..f7736ec4b5 100644
@@ -5,6 +5,7 @@
 #include "config.h"
 #include "submodule-config.h"
 #include "submodule.h"
+#include "alternates.h"
 #include "dir.h"
 #include "diff.h"
 #include "commit.h"
t/helper/test-ref-store.c +1 -0
index 7120634b04..4b96dfe12f 100644
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "alternates.h"
 #include "refs.h"
 #include "worktree.h"
 
tmp-objdir.c +1 -0
index b2d9280f10..bf34315adf 100644
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "tmp-objdir.h"
+#include "alternates.h"
 #include "dir.h"
 #include "sigchain.h"
 #include "string-list.h"
transport.c +1 -0
index 3f97fbe7c5..00f90d7b20 100644
@@ -2,6 +2,7 @@
 #include "config.h"
 #include "transport.h"
 #include "repository.h"
+#include "alternates.h"
 #include "run-command.h"
 #include "pkt-line.h"
 #include "fetch-pack.h"
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#60 lore raw

Re: [PATCH 042/194] object-store: move alternates API to new alternates.h

Quoted 33 lines · Stefan Beller

From: Jonathan Nieder <[email protected]>

This should make these functions easier to find and object-store.h less overwhelming to read.

---
 alternates.h                | 68 +++++++++++++++++++++++++++++++++++++++++++++
 builtin/clone.c             |  1 +
 builtin/count-objects.c     |  1 +
 builtin/fsck.c              |  3 +-
 builtin/grep.c              |  1 +
 builtin/submodule--helper.c |  1 +
 cache.h                     | 52 ----------------------------------
 object-store.h              | 16 +++++------
 packfile.c                  |  3 +-
 sha1_file.c                 | 23 +++++++--------
 sha1_name.c                 |  3 +-
 submodule.c                 |  1 +
 t/helper/test-ref-store.c   |  1 +
 tmp-objdir.c                |  1 +
 transport.c                 |  1 +
 15 files changed, 102 insertions(+), 74 deletions(-)
 create mode 100644 alternates.h
alternates.h new file +1 -0
new file mode 100644
index 0000000000..df5dc67e2e
@@ -0,0 +1,68 @@
+#ifndef ALTERNATES_H

alternates.h line 11

Quoted 10 lines
alternates.h new file +10 -0
+#define ALTERNATES_H
+
+#include "strbuf.h"
+#include "sha1-array.h"
+
+struct alternates {
+	struct alternate_object_database *list;
+	struct alternate_object_database **tail;
+};
+#define ALTERNATES_INIT { NULL, NULL }

I was surprised to find that this patch not only moves the alternates API to a new location, but introduces this struct. I certainly think the struct is a good idea, but it should probably go in a separate patch, or at least get a mention in the commit message.

Signature · 3 lines
brian m. carlson / brian with sandals: Houston, Texas, US
https://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: https://keybase.io/bk2204
#61 lore raw

Re: [PATCH 042/194] object-store: move alternates API to new alternates.h

Quoted 41 lines · brian m. carlson
Quoted 40 lines · Stefan Beller

From: Jonathan Nieder <[email protected]>

This should make these functions easier to find and object-store.h less overwhelming to read.

---
 alternates.h                | 68 +++++++++++++++++++++++++++++++++++++++++++++
 builtin/clone.c             |  1 +
 builtin/count-objects.c     |  1 +
 builtin/fsck.c              |  3 +-
 builtin/grep.c              |  1 +
 builtin/submodule--helper.c |  1 +
 cache.h                     | 52 ----------------------------------
 object-store.h              | 16 +++++------
 packfile.c                  |  3 +-
 sha1_file.c                 | 23 +++++++--------
 sha1_name.c                 |  3 +-
 submodule.c                 |  1 +
 t/helper/test-ref-store.c   |  1 +
 tmp-objdir.c                |  1 +
 transport.c                 |  1 +
 15 files changed, 102 insertions(+), 74 deletions(-)
 create mode 100644 alternates.h
alternates.h new file +8 -0
new file mode 100644
index 0000000000..df5dc67e2e
@@ -0,0 +1,68 @@
+#ifndef ALTERNATES_H
+#define ALTERNATES_H
+
+#include "strbuf.h"
+#include "sha1-array.h"
+
+struct alternates {
+     struct alternate_object_database *list;
Quoted 8 lines

alternates.h line 11

Quoted 3 lines
alternates.h new file +3 -0
+     struct alternate_object_database **tail;
+};
+#define ALTERNATES_INIT { NULL, NULL }

I was surprised to find that this patch not only moves the alternates API to a new location, but introduces this struct. I certainly think the struct is a good idea, but it should probably go in a separate patch, or at least get a mention in the commit message.

ok, I'll fix the commit message.

Thanks,
Stefan

#62 lore raw

Re: [PATCH 042/194] object-store: move alternates API to new alternates.h

In reply to brian m. carlson
Quoted 5 lines · brian m. carlson
Quoted 5 lines
alternates.h new file +5 -0
+#include "strbuf.h"
+#include "sha1-array.h"
+
+struct alternates {
+	struct alternate_object_database *list;
Quoted 8 lines

alternates.h line 11

Quoted 3 lines
alternates.h new file +3 -0
+	struct alternate_object_database **tail;
+};
+#define ALTERNATES_INIT { NULL, NULL }

I was surprised to find that this patch not only moves the alternates API to a new location, but introduces this struct. I certainly think the struct is a good idea, but it should probably go in a separate patch, or at least get a mention in the commit message.

Yeah, I tend to agree that splitting it into two patches may make more sense, especially given that this is already close to 200 patch series ;-)

#63 lore raw

Re: [PATCH 042/194] object-store: move alternates API to new alternates.h

In reply to Stefan Beller
Quoted 2 lines · Stefan Beller

This should make these functions easier to find and object-store.h less overwhelming to read.

I think you mean: s/object-store.h/cache.h/

Quoted 5 lines
---
 cache.h                     | 52 ----------------------------------
 object-store.h              | 16 +++++------
#64 lore raw

Re: [PATCH 042/194] object-store: move alternates API to new alternates.h

Quoted 5 lines · Eric Sunshine
Quoted 2 lines · Stefan Beller

This should make these functions easier to find and object-store.h less overwhelming to read.

I think you mean: s/object-store.h/cache.h/

Probably both.

At the end of the series the object-store.h has grown a bit, such that we'd want to have specific things outside of it. Alternates are a good choice as they are coherent on their own.

I have given up on cache.h and its readability, but moving things out of there helps of course. And that is what the patch does.
So I'll change that.

Thanks,
Stefan

#65 lore raw

PATCH 43/194 object-store: move loose object functions to new loose-object.h

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

This should make these functions easier to find and cache.h less overwhelming to read.

---
 builtin/cat-file.c      |  1 +
 builtin/count-objects.c |  1 +
 builtin/fsck.c          |  1 +
 builtin/pack-objects.c  |  1 +
 builtin/prune-packed.c  |  1 +
 builtin/prune.c         |  1 +
 cache.h                 | 75 ++--------------------------------------
 http-walker.c           |  1 +
 http.c                  |  1 +
 loose-object.h          | 91 +++++++++++++++++++++++++++++++++++++++++++++++++
 object-store.h          |  7 ----
 reachable.c             |  1 +
 sha1_file.c             |  1 +
 sha1_name.c             |  1 +
 14 files changed, 105 insertions(+), 79 deletions(-)
 create mode 100644 loose-object.h
builtin/cat-file.c +1 -0
index 9d18efeb7c..fdc70aa419 100644
@@ -9,6 +9,7 @@
 #include "diff.h"
 #include "parse-options.h"
 #include "userdiff.h"
+#include "loose-object.h"
 #include "streaming.h"
 #include "tree-walk.h"
 #include "sha1-array.h"
builtin/count-objects.c +1 -0
index 805803fedd..34f2bfa44e 100644
@@ -10,6 +10,7 @@
 #include "repository.h"
 #include "alternates.h"
 #include "object-store.h"
+#include "loose-object.h"
 #include "builtin.h"
 #include "parse-options.h"
 #include "quote.h"
builtin/fsck.c +1 -0
index 571aa51579..920cc50923 100644
@@ -4,6 +4,7 @@
 #include "config.h"
 #include "alternates.h"
 #include "object-store.h"
+#include "loose-object.h"
 #include "commit.h"
 #include "tree.h"
 #include "blob.h"
builtin/pack-objects.c +1 -0
index d42df2a2b9..b998e139d1 100644
@@ -3,6 +3,7 @@
 #include "repository.h"
 #include "config.h"
 #include "object-store.h"
+#include "loose-object.h"
 #include "attr.h"
 #include "object.h"
 #include "blob.h"
builtin/prune-packed.c +1 -0
index 419238171d..2da1573359 100644
@@ -2,6 +2,7 @@
 #include "cache.h"
 #include "progress.h"
 #include "parse-options.h"
+#include "loose-object.h"
 #include "packfile.h"
 
 static const char * const prune_packed_usage[] = {
builtin/prune.c +1 -0
index d2fdae680a..52091f299e 100644
@@ -3,6 +3,7 @@
 #include "diff.h"
 #include "revision.h"
 #include "builtin.h"
+#include "loose-object.h"
 #include "reachable.h"
 #include "parse-options.h"
 #include "progress.h"
cache.h +3 -72

95 lines not on this page · raw message

http-walker.c +1 -0
index 96873bdfed..34594165b1 100644
@@ -6,6 +6,7 @@
 #include "list.h"
 #include "transport.h"
 #include "object-store.h"
+#include "loose-object.h"
 #include "packfile.h"
 
 struct alt_base {
http.c +1 -0
index ad57476635..e04eca601b 100644
@@ -3,6 +3,7 @@
 #include "repository.h"
 #include "config.h"
 #include "object-store.h"
+#include "loose-object.h"
 #include "pack.h"
 #include "sideband.h"
 #include "run-command.h"
loose-object.h new file +91 -0

91 lines not on this page · raw message

object-store.h +0 -7
index 967dd8af26..7a372baa79 100644
@@ -66,13 +66,6 @@ struct packed_git {
 	char pack_name[FLEX_ARRAY]; /* more */
 };
 
-/*
- * Return the name of the file in a repository's local object database
- * that would be used to store a loose object with the specified sha1.
- * The return value is a pointer to a statically allocated buffer that
- * is overwritten each time the function is called.
- */
-extern const char *sha1_file_name(struct repository *r, const unsigned char *sha1);
 extern void *map_sha1_file(struct repository *r, const unsigned char *sha1, unsigned long *size);
 
 #endif /* OBJECT_STORE_H */
reachable.c +1 -0
index 59ed16ba76..ac5224b9a5 100644
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "refs.h"
 #include "object-store.h"
+#include "loose-object.h"
 #include "tag.h"
 #include "commit.h"
 #include "blob.h"
sha1_file.c +1 -0
index 84501d66e9..2584465e9c 100644
@@ -25,6 +25,7 @@
 #include "bulk-checkin.h"
 #include "repository.h"
 #include "object-store.h"
+#include "loose-object.h"
 #include "streaming.h"
 #include "path.h"
 #include "dir.h"
sha1_name.c +1 -0
index 363f7e1d4d..03ce2ff7f2 100644
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "config.h"
 #include "alternates.h"
+#include "loose-object.h"
 #include "tag.h"
 #include "commit.h"
 #include "tree.h"
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#66 lore raw

PATCH 44/194 pack: move struct pack_window and pack_entry to packfile.h

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

This should make these functions easier to find and cache.h less overwhelming to read.

---
 builtin/pack-objects.c |  1 +
 cache.h                | 15 ---------------
 object-store.h         |  1 +
 pack.h                 |  1 +
 packfile.c             |  1 +
 packfile.h             | 19 +++++++++++++++++++
 6 files changed, 23 insertions(+), 15 deletions(-)
builtin/pack-objects.c +1 -0
index b998e139d1..7cb73c29ac 100644
@@ -10,6 +10,7 @@
 #include "commit.h"
 #include "tag.h"
 #include "tree.h"
+#include "packfile.h"
 #include "delta.h"
 #include "pack.h"
 #include "pack-revindex.h"
cache.h +0 -15
index 7be9a8ad27..c66e59733d 100644
@@ -1544,21 +1544,6 @@ extern int has_dirs_only_path(const char *name, int len, int prefix_len);
 extern void schedule_dir_for_removal(const char *name, int len);
 extern void remove_scheduled_dirs(void);
 
-struct pack_window {
-	struct pack_window *next;
-	unsigned char *base;
-	off_t offset;
-	size_t len;
-	unsigned int last_used;
-	unsigned int inuse_cnt;
-};
-
-struct pack_entry {
-	off_t offset;
-	unsigned char sha1[20];
-	struct packed_git *p;
-};
-
 /*
  * Create a temporary file rooted in the object database directory, or
  * die on failure. The filename is taken from "pattern", which should have the
object-store.h +1 -0
index 7a372baa79..3475e22021 100644
@@ -5,6 +5,7 @@
 #include "mru.h"
 #include "replace-object.h"
 #include "alternates.h"
+#include "packfile.h"
 
 struct object_store {
 	struct packed_git *packed_git;
pack.h +1 -0
index 8294341af1..c0ea2b6499 100644
@@ -2,6 +2,7 @@
 #define PACK_H
 
 #include "object.h"
+#include "packfile.h"
 #include "csum-file.h"
 
 /*
packfile.c +1 -0
index a7504debe5..b73814f2ce 100644
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "mru.h"
+#include "packfile.h"
 #include "pack.h"
 #include "repository.h"
 #include "alternates.h"
packfile.h +19 -0
index b3138816e7..1163fc7bb4 100644
@@ -1,6 +1,25 @@
 #ifndef PACKFILE_H
 #define PACKFILE_H
 
+/* in cache.h */
+enum object_type;
+struct object_info;
+
+struct pack_window {
+	struct pack_window *next;
+	unsigned char *base;
+	off_t offset;
+	size_t len;
+	unsigned int last_used;
+	unsigned int inuse_cnt;
+};
+
+struct pack_entry {
+	off_t offset;
+	unsigned char sha1[20];
+	struct packed_git *p;
+};
+
 /*
  * Generate the filename to be used for a pack file with checksum "sha1" and
  * extension "ext". The result is written into the strbuf "buf", overwriting
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#67 lore raw

PATCH 45/194 object-store: move object access functions to object-store.h

In reply to Stefan Beller

This should make these functions easier to find and cache.h less overwhelming to read.

In particular, this moves:
- read_sha1_file
- sha1_object_info
- write_sha1_file
- sha1_object_info

As a result, most of the codebase needs to #include object-store.h. In this patch the #include is only added to files that would fail to compile otherwise. It would be better to #include wherever identifiers from the header are used. That can happen later when we have better tooling for it.

---
 apply.c                  |   1 +
 archive-tar.c            |   1 +
 archive-zip.c            |   1 +
 archive.c                |   1 +
 blame.c                  |   1 +
 builtin/checkout.c       |   1 +
 builtin/clone.c          |   1 +
 builtin/commit-tree.c    |   1 +
 builtin/difftool.c       |   1 +
 builtin/fast-export.c    |   1 +
 builtin/fetch.c          |   1 +
 builtin/fmt-merge-msg.c  |   1 +
 builtin/hash-object.c    |   1 +
 builtin/log.c            |   1 +
 builtin/ls-tree.c        |   1 +
 builtin/merge-tree.c     |   1 +
 builtin/mktag.c          |   1 +
 builtin/mktree.c         |   1 +
 builtin/notes.c          |   1 +
 builtin/reflog.c         |   1 +
 builtin/remote.c         |   1 +
 builtin/replace.c        |   1 +
 builtin/rev-list.c       |   1 +
 builtin/show-ref.c       |   1 +
 builtin/tag.c            |   1 +
 builtin/unpack-file.c    |   1 +
 builtin/unpack-objects.c |   1 +
 builtin/verify-commit.c  |   1 +
 bundle.c                 |   1 +
 cache-tree.c             |   1 +
 cache.h                  | 102 ------------------------------------------
 combine-diff.c           |   1 +
 commit.c                 |   1 +
 convert.c                |   1 +
 diff.c                   |   1 +
 diffcore-rename.c        |   1 +
 dir.c                    |   1 +
 entry.c                  |   1 +
 fsck.c                   |   1 +
 grep.c                   |   1 +
 log-tree.c               |   1 +
 mailmap.c                |   1 +
 match-trees.c            |   1 +
 merge-blobs.c            |   1 +
 merge-recursive.c        |   1 +
 notes-cache.c            |   1 +
 notes-merge.c            |   1 +
 notes.c                  |   1 +
 object-store.h           | 112 ++++++++++++++++++++++++++++++++++++++++++++++-
 object.c                 |   1 +
 pack-bitmap-write.c      |   1 +
 packfile.h               |   3 ++
 read-cache.c             |   1 +
 ref-filter.c             |   1 +
 refs.c                   |   1 +
 remote-testsvn.c         |   1 +
 remote.c                 |   1 +
 rerere.c                 |   1 +
 revision.c               |   1 +
 send-pack.c              |   1 +
 sequencer.c              |   1 +
 shallow.c                |   1 +
 tag.c                    |   1 +
 tree-walk.c              |   1 +
 tree.c                   |   1 +
 upload-pack.c            |   1 +
 walker.c                 |   1 +
 xdiff-interface.c        |   1 +
 68 files changed, 178 insertions(+), 104 deletions(-)
apply.c +1 -0
index 321a9fa68d..de4440cd2a 100644
@@ -9,6 +9,7 @@
 
 #include "cache.h"
 #include "config.h"
+#include "object-store.h"
 #include "blob.h"
 #include "delta.h"
 #include "diff.h"
archive-tar.c +1 -0
index c6ed96ee74..909347c108 100644
@@ -5,6 +5,7 @@
 #include "config.h"
 #include "tar.h"
 #include "archive.h"
+#include "object-store.h"
 #include "streaming.h"
 #include "run-command.h"
 
archive-zip.c +1 -0
index e8913e5a26..233fed3a61 100644
@@ -6,6 +6,7 @@
 #include "archive.h"
 #include "streaming.h"
 #include "utf8.h"
+#include "object-store.h"
 #include "userdiff.h"
 #include "xdiff-interface.h"
 
archive.c +1 -0
index 0b7b62af0c..9b47041a6c 100644
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "config.h"
 #include "refs.h"
+#include "object-store.h"
 #include "commit.h"
 #include "tree-walk.h"
 #include "attr.h"
blame.c +1 -0
index 2893f3c103..61f0f6bb40 100644
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "refs.h"
+#include "object-store.h"
 #include "cache-tree.h"
 #include "mergesort.h"
 #include "diff.h"
builtin/checkout.c +1 -0
index 8bdc927d3f..c7271ed43f 100644
@@ -4,6 +4,7 @@
 #include "lockfile.h"
 #include "parse-options.h"
 #include "refs.h"
+#include "object-store.h"
 #include "commit.h"
 #include "tree.h"
 #include "tree-walk.h"
builtin/clone.c +1 -0
index 27463c8fc5..ecd71b9444 100644
@@ -15,6 +15,7 @@
 #include "parse-options.h"
 #include "fetch-pack.h"
 #include "refs.h"
+#include "object-store.h"
 #include "tree.h"
 #include "tree-walk.h"
 #include "unpack-trees.h"
builtin/commit-tree.c +1 -0
index 2177251e24..a54fb362ce 100644
@@ -5,6 +5,7 @@
  */
 #include "cache.h"
 #include "config.h"
+#include "object-store.h"
 #include "commit.h"
 #include "tree.h"
 #include "builtin.h"
builtin/difftool.c +1 -0
index bcc79d1888..d62094060d 100644
@@ -20,6 +20,7 @@
 #include "argv-array.h"
 #include "strbuf.h"
 #include "lockfile.h"
+#include "object-store.h"
 #include "dir.h"
 
 static char *diff_gui_tool;
builtin/fast-export.c +1 -0
index 796d0cd66c..f76b7bda79 100644
@@ -7,6 +7,7 @@
 #include "cache.h"
 #include "config.h"
 #include "refs.h"
+#include "object-store.h"
 #include "commit.h"
 #include "object.h"
 #include "tag.h"
builtin/fetch.c +1 -0
index 7bbcd26faf..9b7202953b 100644
@@ -5,6 +5,7 @@
 #include "config.h"
 #include "repository.h"
 #include "refs.h"
+#include "object-store.h"
 #include "commit.h"
 #include "builtin.h"
 #include "string-list.h"
builtin/fmt-merge-msg.c +1 -0
index 8e8a15ea4a..9dd5c85831 100644
@@ -2,6 +2,7 @@
 #include "cache.h"
 #include "config.h"
 #include "refs.h"
+#include "object-store.h"
 #include "commit.h"
 #include "diff.h"
 #include "revision.h"
builtin/hash-object.c +1 -0
index c532ff9320..956a798110 100644
@@ -6,6 +6,7 @@
  */
 #include "builtin.h"
 #include "config.h"
+#include "object-store.h"
 #include "blob.h"
 #include "quote.h"
 #include "parse-options.h"
builtin/log.c +1 -0
index 14fdf39165..de723fffc6 100644
@@ -7,6 +7,7 @@
 #include "cache.h"
 #include "config.h"
 #include "refs.h"
+#include "object-store.h"
 #include "color.h"
 #include "commit.h"
 #include "diff.h"
builtin/ls-tree.c +1 -0
index ef965408e8..78fcced566 100644
@@ -5,6 +5,7 @@
  */
 #include "cache.h"
 #include "config.h"
+#include "object-store.h"
 #include "blob.h"
 #include "tree.h"
 #include "commit.h"
builtin/merge-tree.c +1 -0
index d01ddecf66..ba51ad55a8 100644
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "tree-walk.h"
 #include "xdiff-interface.h"
+#include "object-store.h"
 #include "blob.h"
 #include "exec_cmd.h"
 #include "merge-blobs.h"
builtin/mktag.c +1 -0
index 031b750f06..04eadc7b24 100644
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "tag.h"
+#include "object-store.h"
 
 /*
  * A signature file has a very simple fixed format: four lines
builtin/mktree.c +1 -0
index da0fd8cd70..0f66946618 100644
@@ -7,6 +7,7 @@
 #include "quote.h"
 #include "tree.h"
 #include "parse-options.h"
+#include "object-store.h"
 
 static struct treeent {
 	unsigned mode;
builtin/notes.c +1 -0
index 7c81761645..1bd3994caa 100644
@@ -11,6 +11,7 @@
 #include "config.h"
 #include "builtin.h"
 #include "notes.h"
+#include "object-store.h"
 #include "blob.h"
 #include "pretty.h"
 #include "refs.h"
builtin/reflog.c +1 -0
index 2233725315..4b525c4448 100644
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "config.h"
 #include "lockfile.h"
+#include "object-store.h"
 #include "commit.h"
 #include "refs.h"
 #include "dir.h"
builtin/remote.c +1 -0
index d95bf904c3..7bd81bac6a 100644
@@ -7,6 +7,7 @@
 #include "strbuf.h"
 #include "run-command.h"
 #include "refs.h"
+#include "object-store.h"
 #include "argv-array.h"
 
 static const char * const builtin_remote_usage[] = {
builtin/replace.c +1 -0
index 10078ae371..ccde160228 100644
@@ -14,6 +14,7 @@
 #include "refs.h"
 #include "parse-options.h"
 #include "run-command.h"
+#include "object-store.h"
 #include "tag.h"
 
 static const char * const git_replace_usage[] = {
builtin/rev-list.c +1 -0
index d5345b6a2e..969efde30c 100644
@@ -6,6 +6,7 @@
 #include "list-objects.h"
 #include "list-objects-filter.h"
 #include "list-objects-filter-options.h"
+#include "object-store.h"
 #include "pack.h"
 #include "pack-bitmap.h"
 #include "builtin.h"
builtin/show-ref.c +1 -0
index 41e5e71cad..8f5827af62 100644
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "refs.h"
+#include "object-store.h"
 #include "object.h"
 #include "tag.h"
 #include "string-list.h"
builtin/tag.c +1 -0
index a7e6a5b0f2..7ed3506fff 100644
@@ -10,6 +10,7 @@
 #include "config.h"
 #include "builtin.h"
 #include "refs.h"
+#include "object-store.h"
 #include "tag.h"
 #include "run-command.h"
 #include "parse-options.h"
builtin/unpack-file.c +1 -0
index 32e0155577..b28e056c74 100644
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "config.h"
+#include "object-store.h"
 
 static char *create_temp_file(struct object_id *oid)
 {
builtin/unpack-objects.c +1 -0
index 62ea264c46..6d03ea2670 100644
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "config.h"
+#include "object-store.h"
 #include "object.h"
 #include "delta.h"
 #include "pack.h"
builtin/verify-commit.c +1 -0
index ba38ac9b15..29f5e5507c 100644
@@ -8,6 +8,7 @@
 #include "cache.h"
 #include "config.h"
 #include "builtin.h"
+#include "object-store.h"
 #include "commit.h"
 #include "run-command.h"
 #include <signal.h>
bundle.c +1 -0
index 93290962c9..d9376b7c77 100644
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "lockfile.h"
 #include "bundle.h"
+#include "object-store.h"
 #include "object.h"
 #include "commit.h"
 #include "diff.h"
cache-tree.c +1 -0
index e03e72c34a..2a98b15b92 100644
@@ -3,6 +3,7 @@
 #include "tree.h"
 #include "tree-walk.h"
 #include "cache-tree.h"
+#include "object-store.h"
 
 #ifndef DEBUG
 #define DEBUG 0
cache.h +0 -102

120 lines not on this page · raw message

combine-diff.c +1 -0
index 2505de119a..f45ab6f57c 100644
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "object-store.h"
 #include "commit.h"
 #include "blob.h"
 #include "diff.h"
commit.c +1 -0
index cab8d4455b..b60906d3f9 100644
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "tag.h"
 #include "commit.h"
+#include "object-store.h"
 #include "pkt-line.h"
 #include "utf8.h"
 #include "diff.h"
convert.c +1 -0
index 1a41a48e15..a090ed805f 100644
@@ -1,6 +1,7 @@
 #define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
+#include "object-store.h"
 #include "attr.h"
 #include "run-command.h"
 #include "quote.h"
diff.c +1 -0
index fb22b19f09..e89c7d9919 100644
@@ -13,6 +13,7 @@
 #include "attr.h"
 #include "run-command.h"
 #include "utf8.h"
+#include "object-store.h"
 #include "userdiff.h"
 #include "submodule-config.h"
 #include "submodule.h"
diffcore-rename.c +1 -0
index 245e999fe5..266b9ff03f 100644
@@ -4,6 +4,7 @@
 #include "cache.h"
 #include "diff.h"
 #include "diffcore.h"
+#include "object-store.h"
 #include "hashmap.h"
 #include "progress.h"
 
dir.c +1 -0
index 7c4b45e30e..4a7981abc4 100644
@@ -11,6 +11,7 @@
 #include "cache.h"
 #include "config.h"
 #include "dir.h"
+#include "object-store.h"
 #include "attr.h"
 #include "refs.h"
 #include "wildmatch.h"
entry.c +1 -0
index 30211447ac..02aa09bc83 100644
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "blob.h"
+#include "object-store.h"
 #include "dir.h"
 #include "streaming.h"
 #include "submodule.h"
fsck.c +1 -0
index 032699e9ac..d106714bf5 100644
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "object-store.h"
 #include "object.h"
 #include "blob.h"
 #include "tree.h"
grep.c +1 -0
index 3d7cd0e96f..6bccd7c7ea 100644
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "config.h"
 #include "grep.h"
+#include "object-store.h"
 #include "userdiff.h"
 #include "xdiff-interface.h"
 #include "diff.h"
log-tree.c +1 -0
index fca29d4799..b2fff6b5f6 100644
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "config.h"
 #include "diff.h"
+#include "object-store.h"
 #include "commit.h"
 #include "tag.h"
 #include "graph.h"
mailmap.c +1 -0
index cb921b4db6..6afa9cc56d 100644
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "string-list.h"
 #include "mailmap.h"
+#include "object-store.h"
 
 #define DEBUG_MAILMAP 0
 #if DEBUG_MAILMAP
match-trees.c +1 -0
index 396b7338df..bdfdfcaaab 100644
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "tree.h"
 #include "tree-walk.h"
+#include "object-store.h"
 
 static int score_missing(unsigned mode, const char *path)
 {
merge-blobs.c +1 -0
index 9b6eac22e4..f5e71bcd9b 100644
@@ -4,6 +4,7 @@
 #include "ll-merge.h"
 #include "blob.h"
 #include "merge-blobs.h"
+#include "object-store.h"
 
 static int fill_mmfile_blob(mmfile_t *f, struct blob *obj)
 {
merge-recursive.c +1 -0
index 0fc580d8ca..620e4f653c 100644
@@ -8,6 +8,7 @@
 #include "advice.h"
 #include "lockfile.h"
 #include "cache-tree.h"
+#include "object-store.h"
 #include "commit.h"
 #include "blob.h"
 #include "builtin.h"
notes-cache.c +1 -0
index 17ee8602b3..ee513e87a9 100644
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "notes-cache.h"
+#include "object-store.h"
 #include "commit.h"
 #include "refs.h"
 
notes-merge.c +1 -0
index 0f6573cb17..1053c65e83 100644
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "commit.h"
 #include "refs.h"
+#include "object-store.h"
 #include "diff.h"
 #include "diffcore.h"
 #include "xdiff-interface.h"
notes.c +1 -0
index c7f21fae44..b1478a8dca 100644
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "config.h"
 #include "notes.h"
+#include "object-store.h"
 #include "blob.h"
 #include "tree.h"
 #include "utf8.h"
object-store.h +110 -2

127 lines not on this page · raw message

object.c +1 -0
index b9a4a0e501..4d2ae6851c 100644
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "object.h"
+#include "object-store.h"
 #include "blob.h"
 #include "tree.h"
 #include "commit.h"
pack-bitmap-write.c +1 -0
index a8df5ce2ab..6a656104af 100644
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "object-store.h"
 #include "commit.h"
 #include "tag.h"
 #include "diff.h"
packfile.h +3 -0
index 1163fc7bb4..0c314eea93 100644
@@ -5,6 +5,9 @@
 enum object_type;
 struct object_info;
 
+/* in object-store.h */
+struct packed_git;
+
 struct pack_window {
 	struct pack_window *next;
 	unsigned char *base;
read-cache.c +1 -0
index 2eb81a66b9..45cad9272a 100644
@@ -11,6 +11,7 @@
 #include "cache-tree.h"
 #include "refs.h"
 #include "dir.h"
+#include "object-store.h"
 #include "tree.h"
 #include "commit.h"
 #include "blob.h"
ref-filter.c +1 -0
index 3f9161707e..0a106b888d 100644
@@ -3,6 +3,7 @@
 #include "parse-options.h"
 #include "refs.h"
 #include "wildmatch.h"
+#include "object-store.h"
 #include "commit.h"
 #include "remote.h"
 #include "color.h"
refs.c +1 -0
index 20ba82b434..968d33ac11 100644
@@ -9,6 +9,7 @@
 #include "iterator.h"
 #include "refs.h"
 #include "refs/refs-internal.h"
+#include "object-store.h"
 #include "object.h"
 #include "tag.h"
 #include "submodule.h"
remote-testsvn.c +1 -0
index bcebb4c789..387d4ae935 100644
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "refs.h"
 #include "remote.h"
+#include "object-store.h"
 #include "strbuf.h"
 #include "url.h"
 #include "exec_cmd.h"
remote.c +1 -0
index 4e93753e19..5112f370c3 100644
@@ -2,6 +2,7 @@
 #include "config.h"
 #include "remote.h"
 #include "refs.h"
+#include "object-store.h"
 #include "commit.h"
 #include "diff.h"
 #include "revision.h"
rerere.c +1 -0
index 1ce440f4bb..ab64d3f48e 100644
@@ -9,6 +9,7 @@
 #include "ll-merge.h"
 #include "attr.h"
 #include "pathspec.h"
+#include "object-store.h"
 #include "sha1-lookup.h"
 
 #define RESOLVED 0
revision.c +1 -0
index 72f2b4572e..9ede92c09e 100644
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "object-store.h"
 #include "tag.h"
 #include "blob.h"
 #include "tree.h"
send-pack.c +1 -0
index 2112d3b27a..c2856dcfd5 100644
@@ -2,6 +2,7 @@
 #include "config.h"
 #include "commit.h"
 #include "refs.h"
+#include "object-store.h"
 #include "pkt-line.h"
 #include "sideband.h"
 #include "run-command.h"
sequencer.c +1 -0
index 4d3f60594c..234addd4e7 100644
@@ -3,6 +3,7 @@
 #include "lockfile.h"
 #include "sequencer.h"
 #include "dir.h"
+#include "object-store.h"
 #include "object.h"
 #include "commit.h"
 #include "tag.h"
shallow.c +1 -0
index df4d44ea7a..c2f81a5a5a 100644
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "tempfile.h"
 #include "lockfile.h"
+#include "object-store.h"
 #include "commit.h"
 #include "tag.h"
 #include "pkt-line.h"
tag.c +1 -0
index fcbe012f7a..30798abf1f 100644
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "tag.h"
+#include "object-store.h"
 #include "commit.h"
 #include "tree.h"
 #include "blob.h"
tree-walk.c +1 -0
index 63a87ed666..8bd56eddd5 100644
@@ -2,6 +2,7 @@
 #include "tree-walk.h"
 #include "unpack-trees.h"
 #include "dir.h"
+#include "object-store.h"
 #include "tree.h"
 #include "pathspec.h"
 
tree.c +1 -0
index b224115e0f..653339db03 100644
@@ -2,6 +2,7 @@
 #include "cache.h"
 #include "cache-tree.h"
 #include "tree.h"
+#include "object-store.h"
 #include "blob.h"
 #include "commit.h"
 #include "tag.h"
upload-pack.c +1 -0
index d5de18127c..6db85ecdc4 100644
@@ -3,6 +3,7 @@
 #include "refs.h"
 #include "pkt-line.h"
 #include "sideband.h"
+#include "object-store.h"
 #include "tag.h"
 #include "object.h"
 #include "commit.h"
walker.c +1 -0
index 5d4d3733f7..49b6a96e6e 100644
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "walker.h"
+#include "object-store.h"
 #include "commit.h"
 #include "tree.h"
 #include "tree-walk.h"
xdiff-interface.c +1 -0
index 770e1f7f81..a2d0e05edd 100644
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "config.h"
+#include "object-store.h"
 #include "xdiff-interface.h"
 #include "xdiff/xtypes.h"
 #include "xdiff/xdiffi.h"
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#68 lore raw

PATCH 46/194 object-store: move replace_objects back to object-store

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

This way, object-store.h does not need to #include replace-object.h, avoiding a header dependency loop in an upcoming change to the inline definition of the lookup_replace_object function.

---
 object-store.h   | 13 ++++++++++---
 replace-object.h | 11 -----------
 2 files changed, 10 insertions(+), 14 deletions(-)
object-store.h +10 -3
index 31628c49dc..cf06a54782 100644
@@ -3,7 +3,6 @@
 
 #include "strbuf.h"
 #include "mru.h"
-#include "replace-object.h"
 #include "alternates.h"
 
 /* in packfile.h */
@@ -32,7 +31,15 @@ struct object_store {
 	 * Objects that should be substituted by other objects
 	 * (see git-replace(1)).
 	 */
-	struct replace_objects replacements;
+	struct replace_objects {
+		/*
+		 * An array of replacements.  The array is kept sorted by the original
+		 * sha1.
+		 */
+		struct replace_object **items;
+
+		int alloc, nr;
+	} replacements;
 
 	/*
 	 * A fast, rough count of the number of objects in the repository.
@@ -49,7 +56,7 @@ struct object_store {
 	unsigned packed_git_initialized : 1;
 };
 #define OBJECT_STORE_INIT \
-	{ NULL, MRU_INIT, ALTERNATES_INIT, REPLACE_OBJECTS_INIT, 0, 0, 0 }
+	{ NULL, MRU_INIT, ALTERNATES_INIT, { NULL, 0, 0 }, 0, 0, 0 }
 
 struct packed_git {
 	struct packed_git *next;
replace-object.h +0 -11
index 483335ffcc..e05713b951 100644
@@ -1,17 +1,6 @@
 #ifndef REPLACE_OBJECT_H
 #define REPLACE_OBJECT_H
 
-struct replace_objects {
-	/*
-	 * An array of replacements.  The array is kept sorted by the original
-	 * sha1.
-	 */
-	struct replace_object **items;
-
-	int alloc, nr;
-};
-#define REPLACE_OBJECTS_INIT { NULL, 0, 0 }
-
 struct replace_object {
 	unsigned char original[20];
 	unsigned char replacement[20];
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#69 lore raw

Re: [PATCH 046/194] object-store: move replace_objects back to object-store

Quoted 18 lines · Stefan Beller
object-store.h +9 -1
@@ -32,7 +31,15 @@ struct object_store {
 	 * Objects that should be substituted by other objects
 	 * (see git-replace(1)).
 	 */
-	struct replace_objects replacements;
+	struct replace_objects {
+		/*
+		 * An array of replacements.  The array is kept sorted by the original
+		 * sha1.
+		 */
+		struct replace_object **items;
+
+		int alloc, nr;
+	} replacements;
 
 	/*
 	 * A fast, rough count of the number of objects in the repository.

object-store.h struct object_store { · line 59

Quoted 5 lines
object-store.h +1 -1
@@ -49,7 +56,7 @@ struct object_store {
 	unsigned packed_git_initialized : 1;
 };
 #define OBJECT_STORE_INIT \
-	{ NULL, MRU_INIT, ALTERNATES_INIT, REPLACE_OBJECTS_INIT, 0, 0, 0 }
+	{ NULL, MRU_INIT, ALTERNATES_INIT, { NULL, 0, 0 }, 0, 0, 0 }

Not the primary thrust of this topic, but we may want to convert these to use designated initializers after this series is done.

#70 lore raw

Re: [PATCH 046/194] object-store: move replace_objects back to object-store

Quoted 17 lines · Junio C Hamano
Quoted 15 lines · Stefan Beller
object-store.h +9 -1
@@ -32,7 +31,15 @@ struct object_store {
       * Objects that should be substituted by other objects
       * (see git-replace(1)).
       */
-     struct replace_objects replacements;
+     struct replace_objects {
+             /*
+              * An array of replacements.  The array is kept sorted by the original
+              * sha1.
+              */
+             struct replace_object **items;
+
+             int alloc, nr;
+     } replacements;
 
Quoted 8 lines

object-store.h struct object_store { · line 59

Quoted 8 lines
object-store.h +1 -1
      /*
       * A fast, rough count of the number of objects in the repository.
@@ -49,7 +56,7 @@ struct object_store {
      unsigned packed_git_initialized : 1;
 };
 #define OBJECT_STORE_INIT \
-     { NULL, MRU_INIT, ALTERNATES_INIT, REPLACE_OBJECTS_INIT, 0, 0, 0 }
+     { NULL, MRU_INIT, ALTERNATES_INIT, { NULL, 0, 0 }, 0, 0, 0 }

Maybe we can move the REPLACE_OBJECTS_INIT just before the definition of OBJECT_STORE_INIT, so we'd not need to touch this line here.

Quoted 3 lines

Not the primary thrust of this topic, but we may want to convert these to use designated initializers after this series is done.

I agree.

I feel cbc0f81d96 (strbuf: use designated initializers in STRBUF_INIT, 2017-07-10)
may need longer cooking until all the interesting architectures have tried picking up
the latest release, though.

Stefan

#71 lore raw

PATCH 47/194 object-store: move lookup_replace_object to replace-object.h

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

lookup_replace_object is a low-level function that most users of the object store do not need to use directly.

Move it to replace-object.h to avoid a dependency loop in an upcoming change to its inline definition that will make use of repository.h.

---
 builtin/mktag.c  |  1 +
 object-store.h   | 19 -------------------
 object.c         |  1 +
 replace-object.h | 22 ++++++++++++++++++++++
 sha1_file.c      |  1 +
 streaming.c      |  1 +
 6 files changed, 26 insertions(+), 19 deletions(-)
builtin/mktag.c +1 -0
index 04eadc7b24..93934e8e4b 100644
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "tag.h"
 #include "object-store.h"
+#include "replace-object.h"
 
 /*
  * A signature file has a very simple fixed format: four lines
object-store.h +0 -19
index cf06a54782..4ac0ffdb98 100644
@@ -88,25 +88,6 @@ static inline void *read_sha1_file(const unsigned char *sha1, enum object_type *
 	return read_sha1_file_extended(sha1, type, size, 1);
 }
 
-/*
- * This internal function is only declared here for the benefit of
- * lookup_replace_object().  Please do not call it directly.
- */
-extern const unsigned char *do_lookup_replace_object(const unsigned char *sha1);
-
-/*
- * If object sha1 should be replaced, return the replacement object's
- * name (replaced recursively, if necessary).  The return value is
- * either sha1 or a pointer to a permanently-allocated value.  When
- * object replacement is suppressed, always return sha1.
- */
-static inline const unsigned char *lookup_replace_object(const unsigned char *sha1)
-{
-	if (!check_replace_refs)
-		return sha1;
-	return do_lookup_replace_object(sha1);
-}
-
 /* Read and unpack a sha1 file into memory, write memory to a sha1 file */
 extern int sha1_object_info(const unsigned char *, unsigned long *);
 extern int hash_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *sha1);
object.c +1 -0
index 4d2ae6851c..fc0ccbefef 100644
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "object.h"
 #include "object-store.h"
+#include "replace-object.h"
 #include "blob.h"
 #include "tree.h"
 #include "commit.h"
replace-object.h +22 -0
index e05713b951..668bbed1da 100644
@@ -1,9 +1,31 @@
 #ifndef REPLACE_OBJECT_H
 #define REPLACE_OBJECT_H
 
+#include "cache.h"
+#include "repository.h"
+
 struct replace_object {
 	unsigned char original[20];
 	unsigned char replacement[20];
 };
 
+/*
+ * This internal function is only declared here for the benefit of
+ * lookup_replace_object().  Please do not call it directly.
+ */
+extern const unsigned char *do_lookup_replace_object(const unsigned char *sha1);
+
+/*
+ * If object sha1 should be replaced, return the replacement object's
+ * name (replaced recursively, if necessary).  The return value is
+ * either sha1 or a pointer to a permanently-allocated value.  When
+ * object replacement is suppressed, always return sha1.
+ */
+static inline const unsigned char *lookup_replace_object(const unsigned char *sha1)
+{
+	if (!check_replace_refs)
+		return sha1;
+	return do_lookup_replace_object(sha1);
+}
+
 #endif /* REPLACE_OBJECT_H */
sha1_file.c +1 -0
index 2584465e9c..8ee86f8ede 100644
@@ -25,6 +25,7 @@
 #include "bulk-checkin.h"
 #include "repository.h"
 #include "object-store.h"
+#include "replace-object.h"
 #include "loose-object.h"
 #include "streaming.h"
 #include "path.h"
streaming.c +1 -0
index 47fca9aba0..c47600e719 100644
@@ -5,6 +5,7 @@
 #include "streaming.h"
 #include "repository.h"
 #include "object-store.h"
+#include "replace-object.h"
 #include "packfile.h"
 
 enum input_source {
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#72 lore raw

PATCH 48/194 replace-object: add repository argument to do_lookup_replace_object

In reply to Stefan Beller

Add a repository argument to allow the do_lookup_replace_object caller 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.

---
 replace-object.c | 2 +-
 replace-object.h | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)
replace-object.c +1 -1
index d26e180639..cf38c3df00 100644
@@ -94,7 +94,7 @@ static void prepare_replace_object(void)
  * permanently-allocated value.  This function always respects replace
  * references, regardless of the value of check_replace_refs.
  */
-const unsigned char *do_lookup_replace_object(const unsigned char *sha1)
+const unsigned char *do_lookup_replace_object_the_repository(const unsigned char *sha1)
 {
 	int pos, depth = MAXREPLACEDEPTH;
 	const unsigned char *cur = sha1;
replace-object.h +3 -2
index 668bbed1da..702020a3a0 100644
@@ -13,7 +13,8 @@ struct replace_object {
  * This internal function is only declared here for the benefit of
  * lookup_replace_object().  Please do not call it directly.
  */
-extern const unsigned char *do_lookup_replace_object(const unsigned char *sha1);
+#define do_lookup_replace_object(r, s) do_lookup_replace_object_##r(s)
+extern const unsigned char *do_lookup_replace_object_the_repository(const unsigned char *sha1);
 
 /*
  * If object sha1 should be replaced, return the replacement object's
@@ -25,7 +26,7 @@ static inline const unsigned char *lookup_replace_object(const unsigned char *sh
 {
 	if (!check_replace_refs)
 		return sha1;
-	return do_lookup_replace_object(sha1);
+	return do_lookup_replace_object(the_repository, sha1);
 }
 
 #endif /* REPLACE_OBJECT_H */
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#73 lore raw

PATCH 49/194 replace-object: move replace objects prepared flag to object store

In reply to Stefan Beller

Remove another global variable on the way.

---
 object-store.h   | 4 +++-
 replace-object.c | 6 ++----
 2 files changed, 5 insertions(+), 5 deletions(-)
object-store.h +3 -1
index 4ac0ffdb98..e1e592bdd5 100644
@@ -39,6 +39,8 @@ struct object_store {
 		struct replace_object **items;
 
 		int alloc, nr;
+
+		unsigned prepared : 1;
 	} replacements;
 
 	/*
@@ -56,7 +58,7 @@ struct object_store {
 	unsigned packed_git_initialized : 1;
 };
 #define OBJECT_STORE_INIT \
-	{ NULL, MRU_INIT, ALTERNATES_INIT, { NULL, 0, 0 }, 0, 0, 0 }
+	{ NULL, MRU_INIT, ALTERNATES_INIT, { NULL, 0, 0, 0 }, 0, 0, 0 }
 
 struct packed_git {
 	struct packed_git *next;
replace-object.c +2 -4
index cf38c3df00..c865eff0ba 100644
@@ -73,13 +73,11 @@ static int register_replace_ref(const char *refname,
 
 static void prepare_replace_object(void)
 {
-	static int replace_object_prepared;
-
-	if (replace_object_prepared)
+	if (the_repository->objects.replacements.prepared)
 		return;
 
 	for_each_replace_ref(register_replace_ref, NULL);
-	replace_object_prepared = 1;
+	the_repository->objects.replacements.prepared = 1;
 	if (!the_repository->objects.replacements.nr)
 		check_replace_refs = 0;
 }
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#74 lore raw

PATCH 50/194 replace-object: check_replace_refs is safe in multi repo environment

In reply to Stefan Beller

In e1111cef23 (inline lookup_replace_object() calls, 2011-05-15) a shortcut for checking the object replacement was added by setting check_replace_refs to 0 once the replacements were evaluated to not exist. This works fine in with the assumption of only one repository in existence.

The assumption won't hold true any more when we work on multiple instances of a repository structs (e.g. one struct per submodule), as the first repository to be inspected may have no replacements and would set the global variable. Other repositories would then completely omit their evaluation of replacements.

This reverts back the meaning of the flag check_replace_refs of "Do we need to check with the lookup table?" to "Do we need read the replacement definition?", adding the bypassing logic to lookup_replace_object after the replacement definition was read. As with the original patch, delay the renaming of the global variable

---
 environment.c    | 2 +-
 replace-object.c | 2 --
 replace-object.h | 4 +++-
 3 files changed, 4 insertions(+), 4 deletions(-)
environment.c +1 -1
index 63ac38a46f..249516cf6b 100644
@@ -46,7 +46,7 @@ const char *editor_program;
 const char *askpass_program;
 const char *excludes_file;
 enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;
-int check_replace_refs = 1;
+int check_replace_refs = 1; /* NEEDSWORK: rename to read_replace_refs */
 char *git_replace_ref_base;
 enum eol core_eol = EOL_UNSET;
 enum safe_crlf safe_crlf = SAFE_CRLF_WARN;
replace-object.c +0 -2
index c865eff0ba..91fedd9447 100644
@@ -78,8 +78,6 @@ static void prepare_replace_object(void)
 
 	for_each_replace_ref(register_replace_ref, NULL);
 	the_repository->objects.replacements.prepared = 1;
-	if (!the_repository->objects.replacements.nr)
-		check_replace_refs = 0;
 }
 
 /* We allow "recursive" replacement. Only within reason, though */
replace-object.h +3 -1
index 702020a3a0..8af730f5e3 100644
@@ -24,7 +24,9 @@ extern const unsigned char *do_lookup_replace_object_the_repository(const unsign
  */
 static inline const unsigned char *lookup_replace_object(const unsigned char *sha1)
 {
-	if (!check_replace_refs)
+	if (!check_replace_refs ||
+	    (the_repository->objects.replacements.prepared &&
+	     the_repository->objects.replacements.nr == 0))
 		return sha1;
 	return do_lookup_replace_object(the_repository, sha1);
 }
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#75 lore raw

Re: [PATCH 050/194] replace-object: check_replace_refs is safe in multi repo environment

Quoted 5 lines · Stefan Beller

In e1111cef23 (inline lookup_replace_object() calls, 2011-05-15) a shortcut for checking the object replacement was added by setting check_replace_refs to 0 once the replacements were evaluated to not exist. This works fine in with the assumption of only one repository in existence.

Quoted 8 lines

The assumption won't hold true any more when we work on multiple instances of a repository structs (e.g. one struct per submodule), as the first repository to be inspected may have no replacements and would set the global variable. Other repositories would then completely omit their evaluation of replacements.

This reverts back the meaning of the flag check_replace_refs of "Do we need to check with the lookup table?" to "Do we need read the

s/need read/need to read/

Quoted 5 lines

replacement definition?", adding the bypassing logic to lookup_replace_object after the replacement definition was read. As with the original patch, delay the renaming of the global variable

#76 lore raw

PATCH 51/194 refs: add repository argument to for_each_replace_ref

In reply to Stefan Beller

Add a repository argument to allow for_each_replace_ref callers 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/replace.c | 3 ++-
 refs.c            | 2 +-
 refs.h            | 4 +++-
 replace-object.c  | 2 +-
 4 files changed, 7 insertions(+), 4 deletions(-)
builtin/replace.c +2 -1
index ccde160228..6d27dd73f0 100644
@@ -15,6 +15,7 @@
 #include "parse-options.h"
 #include "run-command.h"
 #include "object-store.h"
+#include "repository.h"
 #include "tag.h"
 
 static const char * const git_replace_usage[] = {
@@ -84,7 +85,7 @@ static int list_replace_refs(const char *pattern, const char *format)
 		    "valid formats are 'short', 'medium' and 'long'\n",
 		    format);
 
-	for_each_replace_ref(show_reference, (void *)&data);
+	for_each_replace_ref(the_repository, show_reference, (void *)&data);
 
 	return 0;
 }
refs.c +1 -1
index 968d33ac11..5c26532cbd 100644
@@ -1415,7 +1415,7 @@ int refs_for_each_fullref_in(struct ref_store *refs, const char *prefix,
 	return do_for_each_ref(refs, prefix, fn, 0, flag, cb_data);
 }
 
-int for_each_replace_ref(each_ref_fn fn, void *cb_data)
+int for_each_replace_ref_the_repository(each_ref_fn fn, void *cb_data)
 {
 	return do_for_each_ref(get_main_ref_store(),
 			       git_replace_ref_base, fn,
refs.h +3 -1
index 01be5ae32f..546fa9e65a 100644
@@ -300,7 +300,9 @@ int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data,
 int for_each_tag_ref(each_ref_fn fn, void *cb_data);
 int for_each_branch_ref(each_ref_fn fn, void *cb_data);
 int for_each_remote_ref(each_ref_fn fn, void *cb_data);
-int for_each_replace_ref(each_ref_fn fn, void *cb_data);
+#define for_each_replace_ref(r, fn, cb) \
+	for_each_replace_ref_##r(fn, cb)
+int for_each_replace_ref_the_repository(each_ref_fn fn, void *cb_data);
 int for_each_glob_ref(each_ref_fn fn, const char *pattern, void *cb_data);
 int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,
 			 const char *prefix, void *cb_data);
replace-object.c +1 -1
index 91fedd9447..102e009927 100644
@@ -76,7 +76,7 @@ static void prepare_replace_object(void)
 	if (the_repository->objects.replacements.prepared)
 		return;
 
-	for_each_replace_ref(register_replace_ref, NULL);
+	for_each_replace_ref(the_repository, register_replace_ref, NULL);
 	the_repository->objects.replacements.prepared = 1;
 }
 
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#77 lore raw

PATCH 52/194 refs: add repository argument to get_main_ref_store

In reply to Stefan Beller

Add a repository argument to allow the get_main_ref_store caller 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/pack-refs.c       |  3 ++-
 refs.c                    | 67 ++++++++++++++++++++++++-----------------------
 refs.h                    |  4 ++-
 revision.c                |  5 ++--
 t/helper/test-ref-store.c |  3 ++-
 5 files changed, 44 insertions(+), 38 deletions(-)
builtin/pack-refs.c +2 -1
index b106a392a4..f3353564f9 100644
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "parse-options.h"
 #include "refs.h"
+#include "repository.h"
 
 static char const * const pack_refs_usage[] = {
 	N_("git pack-refs [<options>]"),
@@ -17,5 +18,5 @@ int cmd_pack_refs(int argc, const char **argv, const char *prefix)
 	};
 	if (parse_options(argc, argv, prefix, opts, pack_refs_usage, 0))
 		usage_with_options(pack_refs_usage, opts);
-	return refs_pack_refs(get_main_ref_store(), flags);
+	return refs_pack_refs(get_main_ref_store(the_repository), flags);
 }
refs.c +34 -33

269 lines not on this page · raw message

refs.h +3 -1
index 546fa9e65a..ab3d2bec2f 100644
@@ -760,7 +760,9 @@ int reflog_expire(const char *refname, const struct object_id *oid,
 
 int ref_storage_backend_exists(const char *name);
 
-struct ref_store *get_main_ref_store(void);
+#define get_main_ref_store(r) \
+	get_main_ref_store_##r()
+struct ref_store *get_main_ref_store_the_repository(void);
 /*
  * Return the ref_store instance for the specified submodule. For the
  * main repository, use submodule==NULL; such a call cannot fail. For
revision.c +3 -2
index 9ede92c09e..e98bdf2ac7 100644
@@ -7,6 +7,7 @@
 #include "diff.h"
 #include "refs.h"
 #include "revision.h"
+#include "repository.h"
 #include "graph.h"
 #include "grep.h"
 #include "reflog-walk.h"
@@ -1280,7 +1281,7 @@ void add_reflogs_to_pending(struct rev_info *revs, unsigned flags)
 
 	cb.all_revs = revs;
 	cb.all_flags = flags;
-	cb.refs = get_main_ref_store();
+	cb.refs = get_main_ref_store(the_repository);
 	for_each_reflog(handle_one_reflog, &cb);
 
 	if (!revs->single_worktree)
@@ -2168,7 +2169,7 @@ static int handle_revision_pseudo_opt(const char *submodule,
 			die("BUG: --single-worktree cannot be used together with submodule");
 		refs = get_submodule_ref_store(submodule);
 	} else
-		refs = get_main_ref_store();
+		refs = get_main_ref_store(the_repository);
 
 	/*
 	 * NOTE!
t/helper/test-ref-store.c +2 -1
index 4b96dfe12f..93ea6f781e 100644
@@ -2,6 +2,7 @@
 #include "alternates.h"
 #include "refs.h"
 #include "worktree.h"
+#include "repository.h"
 
 static const char *notnull(const char *arg, const char *name)
 {
@@ -22,7 +23,7 @@ static const char **get_store(const char **argv, struct ref_store **refs)
 	if (!argv[0]) {
 		die("ref store required");
 	} else if (!strcmp(argv[0], "main")) {
-		*refs = get_main_ref_store();
+		*refs = get_main_ref_store(the_repository);
 	} else if (skip_prefix(argv[0], "submodule:", &gitdir)) {
 		struct strbuf sb = STRBUF_INIT;
 		int ret;
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#78 lore raw

PATCH 53/194 replace-object: add repository argument to register_replace_object

In reply to Stefan Beller

Add a repository argument to allow the register_replace_object caller 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.

---
 replace-object.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
replace-object.c +5 -3
index 102e009927..1479530d34 100644
@@ -18,8 +18,10 @@ static int replace_object_pos(const unsigned char *sha1)
 			replace_sha1_access);
 }
 
-static int register_replace_object(struct replace_object *replace,
-				   int ignore_dups)
+#define register_replace_object(r, rp, i) \
+	register_replace_object_##r(rp, i)
+static int register_replace_object_the_repository(struct replace_object *replace,
+						  int ignore_dups)
 {
 	int pos = replace_object_pos(replace->original);
 
@@ -65,7 +67,7 @@ static int register_replace_ref(const char *refname,
 	hashcpy(repl_obj->replacement, oid->hash);
 
 	/* Register new object */
-	if (register_replace_object(repl_obj, 1))
+	if (register_replace_object(the_repository, repl_obj, 1))
 		die("duplicate replace ref: %s", refname);
 
 	return 0;
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#79 lore raw

PATCH 54/194 replace-object: add repository argument to register_replace_ref

In reply to Stefan Beller

Unlike the other conversions this just takes the repository as the cb_data.

NEEDSWORK: callback interface doesn't supply a repository argument, so we have to supply it ourselves as cb_data. It would be nicer to update the callback interface in for_each_replace_ref to pass on the repository at the same time as it gets a repository argument.

---
 replace-object.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
replace-object.c +4 -1
index 1479530d34..8d3e0a30fb 100644
@@ -52,6 +52,8 @@ static int register_replace_ref(const char *refname,
 				const struct object_id *oid,
 				int flag, void *cb_data)
 {
+	struct repository *r = cb_data;
+
 	/* Get sha1 from refname */
 	const char *slash = strrchr(refname, '/');
 	const char *hash = slash ? slash + 1 : refname;
@@ -67,6 +69,7 @@ static int register_replace_ref(const char *refname,
 	hashcpy(repl_obj->replacement, oid->hash);
 
 	/* Register new object */
+	(void)r;
 	if (register_replace_object(the_repository, repl_obj, 1))
 		die("duplicate replace ref: %s", refname);
 
@@ -78,7 +81,7 @@ static void prepare_replace_object(void)
 	if (the_repository->objects.replacements.prepared)
 		return;
 
-	for_each_replace_ref(the_repository, register_replace_ref, NULL);
+	for_each_replace_ref(the_repository, register_replace_ref, the_repository);
 	the_repository->objects.replacements.prepared = 1;
 }
 
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#80 lore raw

PATCH 55/194 replace-object: add repository argument to replace_object_pos

In reply to Stefan Beller

Add a repository argument to allow the replace_object_pos caller 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.

---
 replace-object.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
replace-object.c +5 -3
index 8d3e0a30fb..4a07f82aa0 100644
@@ -11,7 +11,9 @@ static const unsigned char *replace_sha1_access(size_t index, void *table)
 	return replace[index]->original;
 }
 
-static int replace_object_pos(const unsigned char *sha1)
+#define replace_object_pos(r, s) \
+	replace_object_pos_##r(s)
+static int replace_object_pos_the_repository(const unsigned char *sha1)
 {
 	return sha1_pos(sha1, the_repository->objects.replacements.items,
 			the_repository->objects.replacements.nr,
@@ -23,7 +25,7 @@ static int replace_object_pos(const unsigned char *sha1)
 static int register_replace_object_the_repository(struct replace_object *replace,
 						  int ignore_dups)
 {
-	int pos = replace_object_pos(replace->original);
+	int pos = replace_object_pos(the_repository, replace->original);
 
 	if (0 <= pos) {
 		if (ignore_dups)
@@ -108,7 +110,7 @@ const unsigned char *do_lookup_replace_object_the_repository(const unsigned char
 			die("replace depth too high for object %s",
 			    sha1_to_hex(sha1));
 
-		pos = replace_object_pos(cur);
+		pos = replace_object_pos(the_repository, cur);
 		if (0 <= pos)
 			cur = the_repository->objects.replacements.items[pos]->replacement;
 	} while (0 <= pos);
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#81 lore raw

PATCH 56/194 replace-object: allow replace_object_pos to handle arbitrary repositories

In reply to Stefan Beller
---
 replace-object.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
replace-object.c +3 -5
index 4a07f82aa0..c30bee2e69 100644
@@ -11,12 +11,10 @@ static const unsigned char *replace_sha1_access(size_t index, void *table)
 	return replace[index]->original;
 }
 
-#define replace_object_pos(r, s) \
-	replace_object_pos_##r(s)
-static int replace_object_pos_the_repository(const unsigned char *sha1)
+static int replace_object_pos(struct repository *r, const unsigned char *sha1)
 {
-	return sha1_pos(sha1, the_repository->objects.replacements.items,
-			the_repository->objects.replacements.nr,
+	return sha1_pos(sha1, r->objects.replacements.items,
+			r->objects.replacements.nr,
 			replace_sha1_access);
 }
 
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#82 lore raw

PATCH 57/194 replace-object: allow register_replace_object to handle arbitrary repositories

In reply to Stefan Beller
---
 replace-object.c | 33 ++++++++++++++++-----------------
 1 file changed, 16 insertions(+), 17 deletions(-)
replace-object.c +16 -17
index c30bee2e69..31b6b3044e 100644
@@ -18,33 +18,32 @@ static int replace_object_pos(struct repository *r, const unsigned char *sha1)
 			replace_sha1_access);
 }
 
-#define register_replace_object(r, rp, i) \
-	register_replace_object_##r(rp, i)
-static int register_replace_object_the_repository(struct replace_object *replace,
-						  int ignore_dups)
+static int register_replace_object(struct repository *r,
+				   struct replace_object *replace,
+				   int ignore_dups)
 {
-	int pos = replace_object_pos(the_repository, replace->original);
+	int pos = replace_object_pos(r, replace->original);
 
 	if (0 <= pos) {
 		if (ignore_dups)
 			free(replace);
 		else {
-			free(the_repository->objects.replacements.items[pos]);
-			the_repository->objects.replacements.items[pos] = replace;
+			free(r->objects.replacements.items[pos]);
+			r->objects.replacements.items[pos] = replace;
 		}
 		return 1;
 	}
 	pos = -pos - 1;
-	ALLOC_GROW(the_repository->objects.replacements.items,
-		   the_repository->objects.replacements.nr + 1,
-		   the_repository->objects.replacements.alloc);
-	the_repository->objects.replacements.nr++;
-	if (pos < the_repository->objects.replacements.nr)
-		memmove(the_repository->objects.replacements.items + pos + 1,
-			the_repository->objects.replacements.items + pos,
-			(the_repository->objects.replacements.nr - pos - 1) *
-			sizeof(*the_repository->objects.replacements.items));
-	the_repository->objects.replacements.items[pos] = replace;
+	ALLOC_GROW(r->objects.replacements.items,
+		   r->objects.replacements.nr + 1,
+		   r->objects.replacements.alloc);
+	r->objects.replacements.nr++;
+	if (pos < r->objects.replacements.nr)
+		memmove(r->objects.replacements.items + pos + 1,
+			r->objects.replacements.items + pos,
+			(r->objects.replacements.nr - pos - 1) *
+			sizeof(*r->objects.replacements.items));
+	r->objects.replacements.items[pos] = replace;
 	return 0;
 }
 
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#83 lore raw

PATCH 58/194 replace-object: add repository argument to prepare_replace_object

In reply to Stefan Beller

Add a repository argument to allow the prepare_replace_object caller 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.

---
 replace-object.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
replace-object.c +4 -2
index 31b6b3044e..cba88f50e3 100644
@@ -75,7 +75,9 @@ static int register_replace_ref(const char *refname,
 	return 0;
 }
 
-static void prepare_replace_object(void)
+#define prepare_replace_object(r) \
+	prepare_replace_object_##r()
+static void prepare_replace_object_the_repository(void)
 {
 	if (the_repository->objects.replacements.prepared)
 		return;
@@ -99,7 +101,7 @@ const unsigned char *do_lookup_replace_object_the_repository(const unsigned char
 	int pos, depth = MAXREPLACEDEPTH;
 	const unsigned char *cur = sha1;
 
-	prepare_replace_object();
+	prepare_replace_object(the_repository);
 
 	/* Try to recursively replace the object */
 	do {
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#84 lore raw

PATCH 59/194 refs: store the main ref store inside the repository struct

In reply to Stefan Beller
---
 refs.c       | 13 +++++--------
 refs.h       |  4 +---
 repository.c |  2 +-
 repository.h |  5 +++++
 4 files changed, 12 insertions(+), 12 deletions(-)
refs.c +5 -8
index c2dee7a69a..f079d65030 100644
@@ -1609,9 +1609,6 @@ static struct ref_store_hash_entry *alloc_ref_store_hash_entry(
 	return entry;
 }
 
-/* A pointer to the ref_store for the main repository: */
-static struct ref_store *main_ref_store;
-
 /* A hashmap of ref_stores, stored by submodule name: */
 static struct hashmap submodule_ref_stores;
 
@@ -1653,13 +1650,13 @@ static struct ref_store *ref_store_init(const char *gitdir,
 	return refs;
 }
 
-struct ref_store *get_main_ref_store_the_repository(void)
+struct ref_store *get_main_ref_store(struct repository *r)
 {
-	if (main_ref_store)
-		return main_ref_store;
+	if (r->main_ref_store)
+		return r->main_ref_store;
 
-	main_ref_store = ref_store_init(get_git_dir(), REF_STORE_ALL_CAPS);
-	return main_ref_store;
+	r->main_ref_store = ref_store_init(r->gitdir, REF_STORE_ALL_CAPS);
+	return r->main_ref_store;
 }
 
 /*
refs.h +1 -3
index ab3d2bec2f..f5ab68c0ed 100644
@@ -760,9 +760,7 @@ int reflog_expire(const char *refname, const struct object_id *oid,
 
 int ref_storage_backend_exists(const char *name);
 
-#define get_main_ref_store(r) \
-	get_main_ref_store_##r()
-struct ref_store *get_main_ref_store_the_repository(void);
+struct ref_store *get_main_ref_store(struct repository *r);
 /*
  * Return the ref_store instance for the specified submodule. For the
  * main repository, use submodule==NULL; such a call cannot fail. For
repository.c +1 -1
index 0ec9648f53..6f85fade82 100644
@@ -6,7 +6,7 @@
 
 /* The main repository */
 static struct repository the_repo = {
-	NULL, NULL, NULL, OBJECT_STORE_INIT,
+	NULL, NULL, NULL, OBJECT_STORE_INIT, NULL,
 	NULL, NULL, NULL, NULL, NULL, NULL, &the_index, NULL, 0, 0
 };
 struct repository *the_repository = &the_repo;
repository.h +5 -0
index ba7b3b7cb9..727ddcea5b 100644
@@ -33,6 +33,11 @@ struct repository {
 	 */
 	struct object_store objects;
 
+	/*
+	 * The store in which the refs are hold.
+	 */
+	struct ref_store *main_ref_store;
+
 	/*
 	 * Path to the repository's graft file.
 	 * Cannot be NULL after initialization.
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#85 lore raw

Re: [PATCH 059/194] refs: store the main ref store inside the repository struct

repository.h struct repository { · line 39

Quoted 13 lines · Stefan Beller
refs.c +0 -2
@@ -1609,9 +1609,6 @@ static struct ref_store_hash_entry *alloc_ref_store_hash_entry(
-/* A pointer to the ref_store for the main repository: */
-static struct ref_store *main_ref_store;
repository.h +4 -0
@@ -33,6 +33,11 @@ struct repository {
         */
        struct object_store objects;
 
+       /*
+        * The store in which the refs are hold.
+        */
+       struct ref_store *main_ref_store;

Do items moved to the 'repository' structure need to be freed when the 'repository' itself is freed? Is that being done by a different patch? If so, it would ease review burden for the freeing to happen in the same patch in which the item is moved to the 'repository'.

#86 lore raw

Re: [PATCH 059/194] refs: store the main ref store inside the repository struct

Quoted 10 lines · Eric Sunshine
Quoted 9 lines · Stefan Beller
refs.c +0 -2
@@ -1609,9 +1609,6 @@ static struct ref_store_hash_entry *alloc_ref_store_hash_entry(
-/* A pointer to the ref_store for the main repository: */
-static struct ref_store *main_ref_store;
repository.h +0 -0
@@ -33,6 +33,11 @@ struct repository {
         */
        struct object_store objects;
 
Quoted 9 lines

repository.h struct repository { · line 39

Quoted 4 lines
repository.h +4 -0
+       /*
+        * The store in which the refs are hold.
+        */
+       struct ref_store *main_ref_store;

Do items moved to the 'repository' structure need to be freed when the 'repository' itself is freed? Is that being done by a different patch? If so, it would ease review burden for the freeing to happen in the same patch in which the item is moved to the 'repository'.

There are two cases:

* the_repository
In the_repository we'll mostly have the globals as they exist (the_index, the_hash_algo, the_ref_store) and just as before these globals will not be freed at the end of the program.
* arbitrary repos:
For arbitrary repos, we usually need to allocate memory in repo_init and clear it out in repo_free/clear

This patch is incomplete and is leaking the main ref store for arbitrary repos.

Thanks for spotting the mem leak!
Stefan

#87 lore raw

PATCH 60/194 refs: allow for_each_replace_ref to handle arbitrary repositories

In reply to Stefan Beller
---
 refs.c | 4 ++--
 refs.h | 4 +---
 2 files changed, 3 insertions(+), 5 deletions(-)
refs.c +2 -2
index f079d65030..e534ff4256 100644
@@ -1416,9 +1416,9 @@ int refs_for_each_fullref_in(struct ref_store *refs, const char *prefix,
 	return do_for_each_ref(refs, prefix, fn, 0, flag, cb_data);
 }
 
-int for_each_replace_ref_the_repository(each_ref_fn fn, void *cb_data)
+int for_each_replace_ref(struct repository *r, each_ref_fn fn, void *cb_data)
 {
-	return do_for_each_ref(get_main_ref_store(the_repository),
+	return do_for_each_ref(get_main_ref_store(r),
 			       git_replace_ref_base, fn,
 			       strlen(git_replace_ref_base),
 			       DO_FOR_EACH_INCLUDE_BROKEN, cb_data);
refs.h +1 -3
index f5ab68c0ed..15f3a91cc4 100644
@@ -300,9 +300,7 @@ int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data,
 int for_each_tag_ref(each_ref_fn fn, void *cb_data);
 int for_each_branch_ref(each_ref_fn fn, void *cb_data);
 int for_each_remote_ref(each_ref_fn fn, void *cb_data);
-#define for_each_replace_ref(r, fn, cb) \
-	for_each_replace_ref_##r(fn, cb)
-int for_each_replace_ref_the_repository(each_ref_fn fn, void *cb_data);
+int for_each_replace_ref(struct repository *r, each_ref_fn fn, void *cb_data);
 int for_each_glob_ref(each_ref_fn fn, const char *pattern, void *cb_data);
 int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,
 			 const char *prefix, void *cb_data);
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#88 lore raw

PATCH 61/194 replace-object: allow prepare_replace_object to handle arbitrary repositories

In reply to Stefan Beller
---
 replace-object.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
replace-object.c +4 -6
index cba88f50e3..d9250a7cf8 100644
@@ -75,15 +75,13 @@ static int register_replace_ref(const char *refname,
 	return 0;
 }
 
-#define prepare_replace_object(r) \
-	prepare_replace_object_##r()
-static void prepare_replace_object_the_repository(void)
+static void prepare_replace_object(struct repository *r)
 {
-	if (the_repository->objects.replacements.prepared)
+	if (r->objects.replacements.prepared)
 		return;
 
-	for_each_replace_ref(the_repository, register_replace_ref, the_repository);
-	the_repository->objects.replacements.prepared = 1;
+	for_each_replace_ref(r, register_replace_ref, r);
+	r->objects.replacements.prepared = 1;
 }
 
 /* We allow "recursive" replacement. Only within reason, though */
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#89 lore raw

PATCH 62/194 replace_object: allow do_lookup_replace_object to handle arbitrary repositories

In reply to Stefan Beller
---
 replace-object.c | 9 +++++----
 replace-object.h | 3 +--
 2 files changed, 6 insertions(+), 6 deletions(-)
replace-object.c +5 -4
index d9250a7cf8..a6a34217d8 100644
@@ -94,12 +94,13 @@ static void prepare_replace_object(struct repository *r)
  * permanently-allocated value.  This function always respects replace
  * references, regardless of the value of check_replace_refs.
  */
-const unsigned char *do_lookup_replace_object_the_repository(const unsigned char *sha1)
+const unsigned char *do_lookup_replace_object(struct repository *r,
+					      const unsigned char *sha1)
 {
 	int pos, depth = MAXREPLACEDEPTH;
 	const unsigned char *cur = sha1;
 
-	prepare_replace_object(the_repository);
+	prepare_replace_object(r);
 
 	/* Try to recursively replace the object */
 	do {
@@ -107,9 +108,9 @@ const unsigned char *do_lookup_replace_object_the_repository(const unsigned char
 			die("replace depth too high for object %s",
 			    sha1_to_hex(sha1));
 
-		pos = replace_object_pos(the_repository, cur);
+		pos = replace_object_pos(r, cur);
 		if (0 <= pos)
-			cur = the_repository->objects.replacements.items[pos]->replacement;
+			cur = r->objects.replacements.items[pos]->replacement;
 	} while (0 <= pos);
 
 	return cur;
replace-object.h +1 -2
index 8af730f5e3..67a433d5a5 100644
@@ -13,8 +13,7 @@ struct replace_object {
  * This internal function is only declared here for the benefit of
  * lookup_replace_object().  Please do not call it directly.
  */
-#define do_lookup_replace_object(r, s) do_lookup_replace_object_##r(s)
-extern const unsigned char *do_lookup_replace_object_the_repository(const unsigned char *sha1);
+extern const unsigned char *do_lookup_replace_object(struct repository *r, const unsigned char *sha1);
 
 /*
  * If object sha1 should be replaced, return the replacement object's
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#90 lore raw

PATCH 63/194 replace-object: add repository argument to lookup_replace_object

In reply to Stefan Beller

Add a repository argument to allow callers of lookup_replace_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.

---
 builtin/mktag.c  | 2 +-
 object.c         | 2 +-
 replace-object.h | 3 ++-
 sha1_file.c      | 6 +++---
 streaming.c      | 2 +-
 5 files changed, 8 insertions(+), 7 deletions(-)
builtin/mktag.c +1 -1
index 93934e8e4b..ab41735f2a 100644
@@ -26,7 +26,7 @@ static int verify_object(const unsigned char *sha1, const char *expected_type)
 	enum object_type type;
 	unsigned long size;
 	void *buffer = read_sha1_file(sha1, &type, &size);
-	const unsigned char *repl = lookup_replace_object(sha1);
+	const unsigned char *repl = lookup_replace_object(the_repository, sha1);
 
 	if (buffer) {
 		if (type == type_from_string(expected_type))
object.c +1 -1
index fc0ccbefef..a5cafb10e7 100644
@@ -246,7 +246,7 @@ struct object *parse_object(const struct object_id *oid)
 	unsigned long size;
 	enum object_type type;
 	int eaten;
-	const unsigned char *repl = lookup_replace_object(oid->hash);
+	const unsigned char *repl = lookup_replace_object(the_repository, oid->hash);
 	void *buffer;
 	struct object *obj;
 
replace-object.h +2 -1
index 67a433d5a5..c61ee66e95 100644
@@ -21,7 +21,8 @@ extern const unsigned char *do_lookup_replace_object(struct repository *r, const
  * either sha1 or a pointer to a permanently-allocated value.  When
  * object replacement is suppressed, always return sha1.
  */
-static inline const unsigned char *lookup_replace_object(const unsigned char *sha1)
+#define lookup_replace_object(r, s) lookup_replace_object_##r(s)
+static inline const unsigned char *lookup_replace_object_the_repository(const unsigned char *sha1)
 {
 	if (!check_replace_refs ||
 	    (the_repository->objects.replacements.prepared &&
sha1_file.c +3 -3
index 8ee86f8ede..a6df4b61c7 100644
@@ -1243,7 +1243,7 @@ int sha1_object_info_extended_the_repository(const unsigned char *sha1, struct o
 	struct pack_entry e;
 	int rtype;
 	const unsigned char *real = (flags & OBJECT_INFO_LOOKUP_REPLACE) ?
-				    lookup_replace_object(sha1) :
+				    lookup_replace_object(the_repository, sha1) :
 				    sha1;
 
 	if (is_null_sha1(real))
@@ -1369,8 +1369,8 @@ void *read_sha1_file_extended(const unsigned char *sha1,
 	const struct packed_git *p;
 	const char *path;
 	struct stat st;
-	const unsigned char *repl = lookup_replace ? lookup_replace_object(sha1)
-						   : sha1;
+	const unsigned char *repl = lookup_replace ?
+		lookup_replace_object(the_repository, sha1) : sha1;
 
 	errno = 0;
 	data = read_object(repl, type, size);
streaming.c +1 -1
index c47600e719..bc3c4811ca 100644
@@ -140,7 +140,7 @@ struct git_istream *open_istream(const unsigned char *sha1,
 {
 	struct git_istream *st;
 	struct object_info oi = OBJECT_INFO_INIT;
-	const unsigned char *real = lookup_replace_object(sha1);
+	const unsigned char *real = lookup_replace_object(the_repository, sha1);
 	enum input_source src = istream_source(real, type, &oi);
 
 	if (src < 0)
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#91 lore raw

PATCH 64/194 repository: allow lookup_replace_object to handle arbitrary repositories

In reply to Stefan Beller
---
 replace-object.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
replace-object.h +5 -5
index c61ee66e95..f4666afc2a 100644
@@ -21,14 +21,14 @@ extern const unsigned char *do_lookup_replace_object(struct repository *r, const
  * either sha1 or a pointer to a permanently-allocated value.  When
  * object replacement is suppressed, always return sha1.
  */
-#define lookup_replace_object(r, s) lookup_replace_object_##r(s)
-static inline const unsigned char *lookup_replace_object_the_repository(const unsigned char *sha1)
+static inline const unsigned char *lookup_replace_object(struct repository *r,
+							 const unsigned char *sha1)
 {
 	if (!check_replace_refs ||
-	    (the_repository->objects.replacements.prepared &&
-	     the_repository->objects.replacements.nr == 0))
+	    (r->objects.replacements.prepared &&
+	     r->objects.replacements.nr == 0))
 		return sha1;
-	return do_lookup_replace_object(the_repository, sha1);
+	return do_lookup_replace_object(r, sha1);
 }
 
 #endif /* REPLACE_OBJECT_H */
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#92 lore raw

PATCH 65/194 object-store: add repository argument to sha1_object_info

In reply to Stefan Beller

Add a repository argument to allow the callers of sha1_object_info 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.

In the expanded macro the identifier the_repository is not actually used, so the compiler does not catch if the repository.h header is not included at the call site. call sites needing that #include were identified by changing the macro to definition to

  #define sha1_object_info(r, sha1, size) \
      (r, sha1_object_info_##r(sha1, size)).

This produces a compiler warning about the left hand side of the comma operator being unused, which can be suppressed using -Wno-unused-value.

To avoid breaking bisection, do not include this trick in the patch.

There is a large number of callers. The included coccinelle semantic patch will adapt any new callers in the diff produced by make coccicheck.

---
 archive-tar.c                             |  3 ++-
 archive-zip.c                             |  4 +++-
 blame.c                                   |  5 +++--
 builtin/cat-file.c                        |  6 +++---
 builtin/fast-export.c                     |  3 ++-
 builtin/fetch.c                           |  3 ++-
 builtin/fsck.c                            |  3 ++-
 builtin/index-pack.c                      |  7 +++++--
 builtin/ls-tree.c                         |  3 ++-
 builtin/mktree.c                          |  3 ++-
 builtin/pack-objects.c                    |  9 ++++++---
 builtin/prune.c                           |  3 ++-
 builtin/replace.c                         | 12 +++++++-----
 builtin/tag.c                             |  5 +++--
 builtin/unpack-objects.c                  |  4 +++-
 contrib/coccinelle/sha1_object_info.cocci |  7 +++++++
 diff.c                                    |  4 +++-
 fast-import.c                             | 16 +++++++++++-----
 list-objects-filter.c                     |  2 +-
 object-store.h                            |  5 ++++-
 object.c                                  |  2 +-
 pack-bitmap-write.c                       |  4 +++-
 packfile.c                                |  2 +-
 reachable.c                               |  2 +-
 refs.c                                    |  2 +-
 remote.c                                  |  3 ++-
 sequencer.c                               |  5 ++++-
 sha1_file.c                               |  4 ++--
 sha1_name.c                               | 12 ++++++------
 submodule.c                               |  2 +-
 tag.c                                     |  3 ++-
 31 files changed, 97 insertions(+), 51 deletions(-)
 create mode 100644 contrib/coccinelle/sha1_object_info.cocci
archive-tar.c +2 -1
index 909347c108..b10c9b8911 100644
@@ -5,6 +5,7 @@
 #include "config.h"
 #include "tar.h"
 #include "archive.h"
+#include "repository.h"
 #include "object-store.h"
 #include "streaming.h"
 #include "run-command.h"
@@ -277,7 +278,7 @@ static int write_tar_entry(struct archiver_args *args,
 		memcpy(header.name, path, pathlen);
 
 	if (S_ISREG(mode) && !args->convert &&
-	    sha1_object_info(sha1, &size) == OBJ_BLOB &&
+	    sha1_object_info(the_repository, sha1, &size) == OBJ_BLOB &&
 	    size > big_file_threshold)
 		buffer = NULL;
 	else if (S_ISLNK(mode) || S_ISREG(mode)) {
archive-zip.c +3 -1
index 233fed3a61..03321b9777 100644
@@ -6,6 +6,7 @@
 #include "archive.h"
 #include "streaming.h"
 #include "utf8.h"
+#include "repository.h"
 #include "object-store.h"
 #include "userdiff.h"
 #include "xdiff-interface.h"
@@ -326,7 +327,8 @@ static int write_zip_entry(struct archiver_args *args,
 		compressed_size = 0;
 		buffer = NULL;
 	} else if (S_ISREG(mode) || S_ISLNK(mode)) {
-		enum object_type type = sha1_object_info(sha1, &size);
+		enum object_type type = sha1_object_info(the_repository, sha1,
+							 &size);
 
 		method = 0;
 		attr2 = S_ISLNK(mode) ? ((mode | 0777) << 16) :
blame.c +3 -2
index 61f0f6bb40..f95a53898d 100644
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "refs.h"
+#include "repository.h"
 #include "object-store.h"
 #include "cache-tree.h"
 #include "mergesort.h"
@@ -82,7 +83,7 @@ static void verify_working_tree_path(struct commit *work_tree, const char *path)
 		unsigned mode;
 
 		if (!get_tree_entry(commit_oid->hash, path, blob_oid.hash, &mode) &&
-		    sha1_object_info(blob_oid.hash, NULL) == OBJ_BLOB)
+		    sha1_object_info(the_repository, blob_oid.hash, NULL) == OBJ_BLOB)
 			return;
 	}
 
@@ -507,7 +508,7 @@ static int fill_blob_sha1_and_mode(struct blame_origin *origin)
 			   origin->path,
 			   origin->blob_oid.hash, &origin->mode))
 		goto error_out;
-	if (sha1_object_info(origin->blob_oid.hash, NULL) != OBJ_BLOB)
+	if (sha1_object_info(the_repository, origin->blob_oid.hash, NULL) != OBJ_BLOB)
 		goto error_out;
 	return 0;
  error_out:
builtin/cat-file.c +3 -3
index fdc70aa419..96c834b8f4 100644
@@ -117,7 +117,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
 		/* else fallthrough */
 
 	case 'p':
-		type = sha1_object_info(oid.hash, NULL);
+		type = sha1_object_info(the_repository, oid.hash, NULL);
 		if (type < 0)
 			die("Not a valid object name %s", obj_name);
 
@@ -141,7 +141,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
 	case 0:
 		if (type_from_string(exp_type) == OBJ_BLOB) {
 			struct object_id blob_oid;
-			if (sha1_object_info(oid.hash, NULL) == OBJ_TAG) {
+			if (sha1_object_info(the_repository, oid.hash, NULL) == OBJ_TAG) {
 				char *buffer = read_sha1_file(oid.hash, &type, &size);
 				const char *target;
 				if (!skip_prefix(buffer, "object ", &target) ||
@@ -151,7 +151,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
 			} else
 				oidcpy(&blob_oid, &oid);
 
-			if (sha1_object_info(blob_oid.hash, NULL) == OBJ_BLOB)
+			if (sha1_object_info(the_repository, blob_oid.hash, NULL) == OBJ_BLOB)
 				return stream_blob_to_fd(1, &blob_oid, NULL, 0);
 			/*
 			 * we attempted to dereference a tag to a blob
builtin/fast-export.c +2 -1
index f76b7bda79..d4e53908c6 100644
@@ -7,6 +7,7 @@
 #include "cache.h"
 #include "config.h"
 #include "refs.h"
+#include "repository.h"
 #include "object-store.h"
 #include "commit.h"
 #include "object.h"
@@ -948,7 +949,7 @@ static void import_marks(char *input_file)
 		if (last_idnum < mark)
 			last_idnum = mark;
 
-		type = sha1_object_info(oid.hash, NULL);
+		type = sha1_object_info(the_repository, oid.hash, NULL);
 		if (type < 0)
 			die("object not found: %s", oid_to_hex(&oid));
 
builtin/fetch.c +2 -1
index 9b7202953b..276beebbb1 100644
@@ -5,6 +5,7 @@
 #include "config.h"
 #include "repository.h"
 #include "refs.h"
+#include "repository.h"
 #include "object-store.h"
 #include "commit.h"
 #include "builtin.h"
@@ -624,7 +625,7 @@ static int update_local_ref(struct ref *ref,
 	struct branch *current_branch = branch_get(NULL);
 	const char *pretty_ref = prettify_refname(ref->name);
 
-	type = sha1_object_info(ref->new_oid.hash, NULL);
+	type = sha1_object_info(the_repository, ref->new_oid.hash, NULL);
 	if (type < 0)
 		die(_("object %s not found"), oid_to_hex(&ref->new_oid));
 
builtin/fsck.c +2 -1
index 920cc50923..f5e3c51077 100644
@@ -69,7 +69,8 @@ static const char *printable_type(struct object *obj)
 	const char *ret;
 
 	if (obj->type == OBJ_NONE) {
-		enum object_type type = sha1_object_info(obj->oid.hash, NULL);
+		enum object_type type = sha1_object_info(the_repository,
+							 obj->oid.hash, NULL);
 		if (type > 0)
 			object_as_type(obj, type, 0);
 	}
builtin/index-pack.c +5 -2
index 1902d4e096..b9851ad69d 100644
@@ -12,6 +12,7 @@
 #include "exec_cmd.h"
 #include "streaming.h"
 #include "thread-utils.h"
+#include "repository.h"
 #include "object-store.h"
 #include "packfile.h"
 
@@ -222,7 +223,8 @@ static unsigned check_object(struct object *obj)
 
 	if (!(obj->flags & FLAG_CHECKED)) {
 		unsigned long size;
-		int type = sha1_object_info(obj->oid.hash, &size);
+		int type = sha1_object_info(the_repository, obj->oid.hash,
+					    &size);
 		if (type <= 0)
 			die(_("did not receive expected object %s"),
 			      oid_to_hex(&obj->oid));
@@ -811,7 +813,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
 		enum object_type has_type;
 		unsigned long has_size;
 		read_lock();
-		has_type = sha1_object_info(oid->hash, &has_size);
+		has_type = sha1_object_info(the_repository, oid->hash,
+					    &has_size);
 		if (has_type < 0)
 			die(_("cannot read existing object info %s"), oid_to_hex(oid));
 		if (has_type != type || has_size != size)
builtin/ls-tree.c +2 -1
index 78fcced566..d929da03b4 100644
@@ -5,6 +5,7 @@
  */
 #include "cache.h"
 #include "config.h"
+#include "repository.h"
 #include "object-store.h"
 #include "blob.h"
 #include "tree.h"
@@ -95,7 +96,7 @@ static int show_tree(const unsigned char *sha1, struct strbuf *base,
 			char size_text[24];
 			if (!strcmp(type, blob_type)) {
 				unsigned long size;
-				if (sha1_object_info(sha1, &size) == OBJ_BAD)
+				if (sha1_object_info(the_repository, sha1, &size) == OBJ_BAD)
 					xsnprintf(size_text, sizeof(size_text),
 						  "BAD");
 				else
builtin/mktree.c +2 -1
index 0f66946618..ccb3a7a897 100644
@@ -7,6 +7,7 @@
 #include "quote.h"
 #include "tree.h"
 #include "parse-options.h"
+#include "repository.h"
 #include "object-store.h"
 
 static struct treeent {
@@ -117,7 +118,7 @@ static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_miss
 	}
 
 	/* Check the type of object identified by sha1 */
-	obj_type = sha1_object_info(sha1, NULL);
+	obj_type = sha1_object_info(the_repository, sha1, NULL);
 	if (obj_type < 0) {
 		if (allow_missing) {
 			; /* no problem - missing objects are presumed to be of the right type */
builtin/pack-objects.c +6 -3
index 7cb73c29ac..79ec5c6842 100644
@@ -1519,7 +1519,8 @@ static void check_object(struct object_entry *entry)
 		unuse_pack(&w_curs);
 	}
 
-	entry->type = sha1_object_info(entry->idx.oid.hash, &entry->size);
+	entry->type = sha1_object_info(the_repository, entry->idx.oid.hash,
+				       &entry->size);
 	/*
 	 * The error condition is checked in prepare_pack().  This is
 	 * to permit a missing preferred base object to be ignored
@@ -1581,7 +1582,8 @@ static void drop_reused_delta(struct object_entry *entry)
 		 * And if that fails, the error will be recorded in entry->type
 		 * and dealt with in prepare_pack().
 		 */
-		entry->type = sha1_object_info(entry->idx.oid.hash,
+		entry->type = sha1_object_info(the_repository,
+					       entry->idx.oid.hash,
 					       &entry->size);
 	}
 }
@@ -2689,7 +2691,8 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs)
 static int add_loose_object(const struct object_id *oid, const char *path,
 			    void *data)
 {
-	enum object_type type = sha1_object_info(oid->hash, NULL);
+	enum object_type type = sha1_object_info(the_repository, oid->hash,
+						 NULL);
 
 	if (type < 0) {
 		warning("loose object at %s could not be examined", path);
builtin/prune.c +2 -1
index 52091f299e..7891048b35 100644
@@ -51,7 +51,8 @@ static int prune_object(const struct object_id *oid, const char *fullpath,
 	if (st.st_mtime > expire)
 		return 0;
 	if (show_only || verbose) {
-		enum object_type type = sha1_object_info(oid->hash, NULL);
+		enum object_type type = sha1_object_info(the_repository,
+							 oid->hash, NULL);
 		printf("%s %s\n", oid_to_hex(oid),
 		       (type > 0) ? typename(type) : "unknown");
 	}
builtin/replace.c +7 -5
index 6d27dd73f0..25322d2f73 100644
@@ -55,8 +55,10 @@ static int show_reference(const char *refname, const struct object_id *oid,
 			if (get_oid(refname, &object))
 				return error("Failed to resolve '%s' as a valid ref.", refname);
 
-			obj_type = sha1_object_info(object.hash, NULL);
-			repl_type = sha1_object_info(oid->hash, NULL);
+			obj_type = sha1_object_info(the_repository,
+						    object.hash, NULL);
+			repl_type = sha1_object_info(the_repository,
+						     oid->hash, NULL);
 
 			printf("%s (%s) -> %s (%s)\n", refname, typename(obj_type),
 			       oid_to_hex(oid), typename(repl_type));
@@ -164,8 +166,8 @@ static int replace_object_oid(const char *object_ref,
 	struct ref_transaction *transaction;
 	struct strbuf err = STRBUF_INIT;
 
-	obj_type = sha1_object_info(object->hash, NULL);
-	repl_type = sha1_object_info(repl->hash, NULL);
+	obj_type = sha1_object_info(the_repository, object->hash, NULL);
+	repl_type = sha1_object_info(the_repository, repl->hash, NULL);
 	if (!force && obj_type != repl_type)
 		die("Objects must be of the same type.\n"
 		    "'%s' points to a replaced object of type '%s'\n"
@@ -292,7 +294,7 @@ static int edit_and_replace(const char *object_ref, int force, int raw)
 	if (get_oid(object_ref, &old) < 0)
 		die("Not a valid object name: '%s'", object_ref);
 
-	type = sha1_object_info(old.hash, NULL);
+	type = sha1_object_info(the_repository, old.hash, NULL);
 	if (type < 0)
 		die("unable to get object type for %s", oid_to_hex(&old));
 
builtin/tag.c +3 -2
index 7ed3506fff..014d7c9e9b 100644
@@ -10,6 +10,7 @@
 #include "config.h"
 #include "builtin.h"
 #include "refs.h"
+#include "repository.h"
 #include "object-store.h"
 #include "tag.h"
 #include "run-command.h"
@@ -211,7 +212,7 @@ static void create_tag(const struct object_id *object, const char *tag,
 	struct strbuf header = STRBUF_INIT;
 	char *path = NULL;
 
-	type = sha1_object_info(object->hash, NULL);
+	type = sha1_object_info(the_repository, object->hash, NULL);
 	if (type <= OBJ_NONE)
 	    die(_("bad object type."));
 
@@ -294,7 +295,7 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb)
 	}
 
 	strbuf_addstr(sb, " (");
-	type = sha1_object_info(oid->hash, NULL);
+	type = sha1_object_info(the_repository, oid->hash, NULL);
 	switch (type) {
 	default:
 		strbuf_addstr(sb, "object of unknown type");
builtin/unpack-objects.c +3 -1
index 6d03ea2670..ee707068b3 100644
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "config.h"
+#include "repository.h"
 #include "object-store.h"
 #include "object.h"
 #include "delta.h"
@@ -198,7 +199,8 @@ static int check_object(struct object *obj, int type, void *data, struct fsck_op
 
 	if (!(obj->flags & FLAG_OPEN)) {
 		unsigned long size;
-		int type = sha1_object_info(obj->oid.hash, &size);
+		int type = sha1_object_info(the_repository, obj->oid.hash,
+					    &size);
 		if (type != obj->type || type <= 0)
 			die("object of unexpected type");
 		obj->flags |= FLAG_WRITTEN;
contrib/coccinelle/sha1_object_info.cocci new file +7 -0
new file mode 100644
index 0000000000..800e0581e5
@@ -0,0 +1,7 @@
+@@
+expression E;
+expression F;
+@@
+ sha1_object_info(
++the_repository,
+ E, F)
diff.c +3 -1
index e89c7d9919..08bff6e720 100644
@@ -13,6 +13,7 @@
 #include "attr.h"
 #include "run-command.h"
 #include "utf8.h"
+#include "repository.h"
 #include "object-store.h"
 #include "userdiff.h"
 #include "submodule-config.h"
@@ -3616,7 +3617,8 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)
 	else {
 		enum object_type type;
 		if (size_only || (flags & CHECK_BINARY)) {
-			type = sha1_object_info(s->oid.hash, &s->size);
+			type = sha1_object_info(the_repository, s->oid.hash,
+						&s->size);
 			if (type < 0)
 				die("unable to read %s",
 				    oid_to_hex(&s->oid));
fast-import.c +11 -5
index 39cd0b7540..2542f600ef 100644
@@ -1913,7 +1913,9 @@ static void read_marks(void)
 			die("corrupt mark line: %s", line);
 		e = find_object(&oid);
 		if (!e) {
-			enum object_type type = sha1_object_info(oid.hash, NULL);
+			enum object_type type = sha1_object_info(the_repository,
+								 oid.hash,
+								 NULL);
 			if (type < 0)
 				die("object not found: %s", oid_to_hex(&oid));
 			e = insert_object(&oid);
@@ -2443,7 +2445,8 @@ static void file_change_m(const char *p, struct branch *b)
 		enum object_type expected = S_ISDIR(mode) ?
 						OBJ_TREE: OBJ_BLOB;
 		enum object_type type = oe ? oe->type :
-					sha1_object_info(oid.hash, NULL);
+					sha1_object_info(the_repository,
+							 oid.hash, NULL);
 		if (type < 0)
 			die("%s not found: %s",
 					S_ISDIR(mode) ?  "Tree" : "Blob",
@@ -2603,7 +2606,8 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
 			die("Not a blob (actually a %s): %s",
 				typename(oe->type), command_buf.buf);
 	} else if (!is_null_oid(&oid)) {
-		enum object_type type = sha1_object_info(oid.hash, NULL);
+		enum object_type type = sha1_object_info(the_repository,
+							 oid.hash, NULL);
 		if (type < 0)
 			die("Blob not found: %s", command_buf.buf);
 		if (type != OBJ_BLOB)
@@ -2890,7 +2894,8 @@ static void parse_new_tag(const char *arg)
 	} else if (!get_oid(from, &oid)) {
 		struct object_entry *oe = find_object(&oid);
 		if (!oe) {
-			type = sha1_object_info(oid.hash, NULL);
+			type = sha1_object_info(the_repository, oid.hash,
+						NULL);
 			if (type < 0)
 				die("Not a valid object: %s", from);
 		} else
@@ -3048,7 +3053,8 @@ static struct object_entry *dereference(struct object_entry *oe,
 	unsigned long size;
 	char *buf = NULL;
 	if (!oe) {
-		enum object_type type = sha1_object_info(oid->hash, NULL);
+		enum object_type type = sha1_object_info(the_repository,
+							 oid->hash, NULL);
 		if (type < 0)
 			die("object not found: %s", oid_to_hex(oid));
 		/* cache it! */
list-objects-filter.c +1 -1
index 4356c45368..180d8729d9 100644
@@ -117,7 +117,7 @@ static enum list_objects_filter_result filter_blobs_limit(
 		assert(obj->type == OBJ_BLOB);
 		assert((obj->flags & SEEN) == 0);
 
-		t = sha1_object_info(obj->oid.hash, &object_length);
+		t = sha1_object_info(the_repository, obj->oid.hash, &object_length);
 		if (t != OBJ_BLOB) { /* probably OBJ_NONE */
 			/*
 			 * We DO NOT have the blob locally, so we cannot
object-store.h +4 -1
index e1e592bdd5..4ff60e3be0 100644
@@ -91,7 +91,10 @@ static inline void *read_sha1_file(const unsigned char *sha1, enum object_type *
 }
 
 /* Read and unpack a sha1 file into memory, write memory to a sha1 file */
-extern int sha1_object_info(const unsigned char *, unsigned long *);
+
+#define sha1_object_info(r, sha1, size) \
+	sha1_object_info_##r(sha1, size)
+extern int sha1_object_info_the_repository(const unsigned char *, unsigned long *);
 extern int hash_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *sha1);
 extern int write_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *return_sha1);
 extern int hash_sha1_file_literally(const void *buf, unsigned long len, const char *type, struct object_id *oid, unsigned flags);
object.c +1 -1
index a5cafb10e7..40f7c7bdab 100644
@@ -256,7 +256,7 @@ struct object *parse_object(const struct object_id *oid)
 
 	if ((obj && obj->type == OBJ_BLOB) ||
 	    (!obj && has_object_file(oid) &&
-	     sha1_object_info(oid->hash, NULL) == OBJ_BLOB)) {
+	     sha1_object_info(the_repository, oid->hash, NULL) == OBJ_BLOB)) {
 		if (check_sha1_signature(repl, NULL, 0, NULL) < 0) {
 			error("sha1 mismatch %s", oid_to_hex(oid));
 			return NULL;
pack-bitmap-write.c +3 -1
index 6a656104af..f684ed5ea2 100644
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "repository.h"
 #include "object-store.h"
 #include "commit.h"
 #include "tag.h"
@@ -74,7 +75,8 @@ void bitmap_writer_build_type_index(struct pack_idx_entry **index,
 			break;
 
 		default:
-			real_type = sha1_object_info(entry->idx.oid.hash,
+			real_type = sha1_object_info(the_repository,
+						     entry->idx.oid.hash,
 						     NULL);
 			break;
 		}
packfile.c +1 -1
index b73814f2ce..a1c1b1a42e 100644
@@ -1092,7 +1092,7 @@ static int retry_bad_packed_offset(struct packed_git *p, off_t obj_offset)
 		return OBJ_BAD;
 	sha1 = nth_packed_object_sha1(p, revidx->nr);
 	mark_bad_packed_object(p, sha1);
-	type = sha1_object_info(sha1, NULL);
+	type = sha1_object_info(the_repository, sha1, NULL);
 	if (type <= OBJ_NONE)
 		return OBJ_BAD;
 	return type;
reachable.c +1 -1
index ac5224b9a5..7e7b9525c0 100644
@@ -79,7 +79,7 @@ static void add_recent_object(const struct object_id *oid,
 	 * later processing, and the revision machinery expects
 	 * commits and tags to have been parsed.
 	 */
-	type = sha1_object_info(oid->hash, NULL);
+	type = sha1_object_info(the_repository, oid->hash, NULL);
 	if (type < 0)
 		die("unable to get object info for %s", oid_to_hex(oid));
 
refs.c +1 -1
index e534ff4256..ddcb4a908f 100644
@@ -303,7 +303,7 @@ enum peel_status peel_object(const struct object_id *name, struct object_id *oid
 	struct object *o = lookup_unknown_object(name->hash);
 
 	if (o->type == OBJ_NONE) {
-		int type = sha1_object_info(name->hash, NULL);
+		int type = sha1_object_info(the_repository, name->hash, NULL);
 		if (type < 0 || !object_as_type(o, type, 0))
 			return PEEL_INVALID;
 	}
remote.c +2 -1
index 5112f370c3..fd8cd8ce77 100644
@@ -2,6 +2,7 @@
 #include "config.h"
 #include "remote.h"
 #include "refs.h"
+#include "repository.h"
 #include "object-store.h"
 #include "commit.h"
 #include "diff.h"
@@ -1362,7 +1363,7 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds
 			continue; /* not a tag */
 		if (string_list_has_string(&dst_tag, ref->name))
 			continue; /* they already have it */
-		if (sha1_object_info(ref->new_oid.hash, NULL) != OBJ_TAG)
+		if (sha1_object_info(the_repository, ref->new_oid.hash, NULL) != OBJ_TAG)
 			continue; /* be conservative */
 		item = string_list_append(&src_tag, ref->name);
 		item->util = ref;
sequencer.c +4 -1
index 234addd4e7..311f00acda 100644
@@ -3,6 +3,7 @@
 #include "lockfile.h"
 #include "sequencer.h"
 #include "dir.h"
+#include "repository.h"
 #include "object-store.h"
 #include "object.h"
 #include "commit.h"
@@ -2347,7 +2348,9 @@ int sequencer_pick_revisions(struct replay_opts *opts)
 
 		if (!get_oid(name, &oid)) {
 			if (!lookup_commit_reference_gently(&oid, 1)) {
-				enum object_type type = sha1_object_info(oid.hash, NULL);
+				enum object_type type = sha1_object_info(the_repository,
+									 oid.hash,
+									 NULL);
 				return error(_("%s: can't cherry-pick a %s"),
 					name, typename(type));
 			}
sha1_file.c +2 -2
index a6df4b61c7..01bdb3cd7a 100644
@@ -1310,7 +1310,7 @@ int sha1_object_info_extended_the_repository(const unsigned char *sha1, struct o
 }
 
 /* returns enum object_type or negative */
-int sha1_object_info(const unsigned char *sha1, unsigned long *sizep)
+int sha1_object_info_the_repository(const unsigned char *sha1, unsigned long *sizep)
 {
 	enum object_type type;
 	struct object_info oi = OBJECT_INFO_INIT;
@@ -1962,7 +1962,7 @@ int read_pack_header(int fd, struct pack_header *header)
 
 void assert_sha1_type(const unsigned char *sha1, enum object_type expect)
 {
-	enum object_type type = sha1_object_info(sha1, NULL);
+	enum object_type type = sha1_object_info(the_repository, sha1, NULL);
 	if (type < 0)
 		die("%s is not a valid object", sha1_to_hex(sha1));
 	if (type != expect)
sha1_name.c +6 -6
index 03ce2ff7f2..190710c638 100644
@@ -243,7 +243,7 @@ static int finish_object_disambiguation(struct disambiguate_state *ds,
 
 static int disambiguate_commit_only(const struct object_id *oid, void *cb_data_unused)
 {
-	int kind = sha1_object_info(oid->hash, NULL);
+	int kind = sha1_object_info(the_repository, oid->hash, NULL);
 	return kind == OBJ_COMMIT;
 }
 
@@ -252,7 +252,7 @@ static int disambiguate_committish_only(const struct object_id *oid, void *cb_da
 	struct object *obj;
 	int kind;
 
-	kind = sha1_object_info(oid->hash, NULL);
+	kind = sha1_object_info(the_repository, oid->hash, NULL);
 	if (kind == OBJ_COMMIT)
 		return 1;
 	if (kind != OBJ_TAG)
@@ -267,7 +267,7 @@ static int disambiguate_committish_only(const struct object_id *oid, void *cb_da
 
 static int disambiguate_tree_only(const struct object_id *oid, void *cb_data_unused)
 {
-	int kind = sha1_object_info(oid->hash, NULL);
+	int kind = sha1_object_info(the_repository, oid->hash, NULL);
 	return kind == OBJ_TREE;
 }
 
@@ -276,7 +276,7 @@ static int disambiguate_treeish_only(const struct object_id *oid, void *cb_data_
 	struct object *obj;
 	int kind;
 
-	kind = sha1_object_info(oid->hash, NULL);
+	kind = sha1_object_info(the_repository, oid->hash, NULL);
 	if (kind == OBJ_TREE || kind == OBJ_COMMIT)
 		return 1;
 	if (kind != OBJ_TAG)
@@ -291,7 +291,7 @@ static int disambiguate_treeish_only(const struct object_id *oid, void *cb_data_
 
 static int disambiguate_blob_only(const struct object_id *oid, void *cb_data_unused)
 {
-	int kind = sha1_object_info(oid->hash, NULL);
+	int kind = sha1_object_info(the_repository, oid->hash, NULL);
 	return kind == OBJ_BLOB;
 }
 
@@ -370,7 +370,7 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)
 	if (ds->fn && !ds->fn(oid, ds->cb_data))
 		return 0;
 
-	type = sha1_object_info(oid->hash, NULL);
+	type = sha1_object_info(the_repository, oid->hash, NULL);
 	if (type == OBJ_COMMIT) {
 		struct commit *commit = lookup_commit(oid);
 		if (commit) {
submodule.c +1 -1
index f7736ec4b5..dc57c176e8 100644
@@ -818,7 +818,7 @@ static int check_has_commit(const struct object_id *oid, void *data)
 {
 	struct has_commit_data *cb = data;
 
-	enum object_type type = sha1_object_info(oid->hash, NULL);
+	enum object_type type = sha1_object_info(the_repository, oid->hash, NULL);
 
 	switch (type) {
 	case OBJ_COMMIT:
tag.c +2 -1
index 30798abf1f..7b32afd123 100644
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "tag.h"
+#include "repository.h"
 #include "object-store.h"
 #include "commit.h"
 #include "tree.h"
@@ -42,7 +43,7 @@ int gpg_verify_tag(const struct object_id *oid, const char *name_to_report,
 	unsigned long size;
 	int ret;
 
-	type = sha1_object_info(oid->hash, NULL);
+	type = sha1_object_info(the_repository, oid->hash, NULL);
 	if (type != OBJ_TAG)
 		return error("%s: cannot verify a non-tag object of type %s.",
 				name_to_report ?
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#93 lore raw

Re: [PATCH 065/194] object-store: add repository argument to sha1_object_info

Quoted 11 lines · Stefan Beller

Add a repository argument to allow the callers of sha1_object_info 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.

In the expanded macro the identifier the_repository is not actually used, so the compiler does not catch if the repository.h header is not included at the call site. call sites needing that #include were identified by

"Call sites" (capital at the beginning of the sentence).

Signature · 3 lines
brian m. carlson / brian with sandals: Houston, Texas, US
https://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: https://keybase.io/bk2204
#94 lore raw

PATCH 66/194 pack: add repository argument to retry_bad_packed_offset

In reply to Stefan Beller

Add a repository argument to allow the callers of retry_bad_packed_offset 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.

---
 packfile.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
packfile.c +5 -3
index a1c1b1a42e..66391b8a6f 100644
@@ -1082,7 +1082,9 @@ static const unsigned char *get_delta_base_sha1(struct packed_git *p,
 		return NULL;
 }
 
-static int retry_bad_packed_offset(struct packed_git *p, off_t obj_offset)
+#define retry_bad_packed_offset(r, p, o) \
+	retry_bad_packed_offset_##r(p, o)
+static int retry_bad_packed_offset_the_repository(struct packed_git *p, off_t obj_offset)
 {
 	int type;
 	struct revindex_entry *revidx;
@@ -1131,7 +1133,7 @@ static enum object_type packed_to_object_type(struct packed_git *p,
 		if (type <= OBJ_NONE) {
 			/* If getting the base itself fails, we first
 			 * retry the base, otherwise unwind */
-			type = retry_bad_packed_offset(p, base_offset);
+			type = retry_bad_packed_offset(the_repository, p, base_offset);
 			if (type > OBJ_NONE)
 				goto out;
 			goto unwind;
@@ -1159,7 +1161,7 @@ static enum object_type packed_to_object_type(struct packed_git *p,
 unwind:
 	while (poi_stack_nr) {
 		obj_offset = poi_stack[--poi_stack_nr];
-		type = retry_bad_packed_offset(p, obj_offset);
+		type = retry_bad_packed_offset(the_repository, p, obj_offset);
 		if (type > OBJ_NONE)
 			goto out;
 	}
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#95 lore raw

PATCH 67/194 pack: add repository argument to packed_to_object_type

In reply to Stefan Beller

Add a repository argument to allow the callers of packed_to_object_type 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.

---
 packfile.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
packfile.c +9 -7
index 66391b8a6f..250c9af1a7 100644
@@ -1102,11 +1102,13 @@ static int retry_bad_packed_offset_the_repository(struct packed_git *p, off_t ob
 
 #define POI_STACK_PREALLOC 64
 
-static enum object_type packed_to_object_type(struct packed_git *p,
-					      off_t obj_offset,
-					      enum object_type type,
-					      struct pack_window **w_curs,
-					      off_t curpos)
+#define packed_to_object_type(r, p, o, t, w, c) \
+	packed_to_object_type_##r(p, o, t, w, c)
+static enum object_type packed_to_object_type_the_repository(struct packed_git *p,
+							     off_t obj_offset,
+							     enum object_type type,
+							     struct pack_window **w_curs,
+							     off_t curpos)
 {
 	off_t small_poi_stack[POI_STACK_PREALLOC];
 	off_t *poi_stack = small_poi_stack;
@@ -1356,8 +1358,8 @@ int packed_object_info(struct packed_git *p, off_t obj_offset,
 
 	if (oi->typep || oi->typename) {
 		enum object_type ptot;
-		ptot = packed_to_object_type(p, obj_offset, type, &w_curs,
-					     curpos);
+		ptot = packed_to_object_type(the_repository, p, obj_offset,
+					     type, &w_curs, curpos);
 		if (oi->typep)
 			*oi->typep = ptot;
 		if (oi->typename) {
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#96 lore raw

PATCH 68/194 pack: add repository argument to packed_object_info

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

Add a repository argument to allow callers of packed_object_info 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/pack-objects.c | 3 ++-
 packfile.c             | 4 ++--
 packfile.h             | 3 ++-
 sha1_file.c            | 2 +-
 4 files changed, 7 insertions(+), 5 deletions(-)
builtin/pack-objects.c +2 -1
index 79ec5c6842..4e59e496dc 100644
@@ -1575,7 +1575,8 @@ static void drop_reused_delta(struct object_entry *entry)
 
 	oi.sizep = &entry->size;
 	oi.typep = &entry->type;
-	if (packed_object_info(entry->in_pack, entry->in_pack_offset, &oi) < 0) {
+	if (packed_object_info(the_repository, entry->in_pack,
+			       entry->in_pack_offset, &oi) < 0) {
 		/*
 		 * We failed to get the info from this pack for some reason;
 		 * fall back to sha1_object_info, which may find another copy.
packfile.c +2 -2
index 250c9af1a7..61e84a789c 100644
@@ -1311,8 +1311,8 @@ static void add_delta_base_cache(struct packed_git *p, off_t base_offset,
 	hashmap_add(&delta_base_cache, ent);
 }
 
-int packed_object_info(struct packed_git *p, off_t obj_offset,
-		       struct object_info *oi)
+int packed_object_info_the_repository(struct packed_git *p, off_t obj_offset,
+				      struct object_info *oi)
 {
 	struct pack_window *w_curs = NULL;
 	unsigned long size;
packfile.h +2 -1
index 0c314eea93..bb1d92b849 100644
@@ -135,7 +135,8 @@ extern void release_pack_memory(size_t);
 /* global flag to enable extra checks when accessing packed objects */
 extern int do_check_packed_object_crc;
 
-extern int packed_object_info(struct packed_git *pack, off_t offset, struct object_info *);
+#define packed_object_info(r, p, o, oi) packed_object_info_##r(p, o, oi)
+extern int packed_object_info_the_repository(struct packed_git *pack, 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);
sha1_file.c +1 -1
index 01bdb3cd7a..299e8be72c 100644
@@ -1294,7 +1294,7 @@ int sha1_object_info_extended_the_repository(const unsigned char *sha1, struct o
 		 */
 		return 0;
 
-	rtype = packed_object_info(e.p, e.offset, oi);
+	rtype = packed_object_info(the_repository, e.p, e.offset, oi);
 	if (rtype < 0) {
 		mark_bad_packed_object(e.p, real);
 		return sha1_object_info_extended(the_repository, real, oi,
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#97 lore raw

PATCH 69/194 pack: add repository argument to find_pack_entry

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

Add a repository argument to allow callers of find_pack_entry 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.

---
 packfile.c  | 4 ++--
 packfile.h  | 3 ++-
 sha1_file.c | 6 +++---
 3 files changed, 7 insertions(+), 6 deletions(-)
packfile.c +2 -2
index 61e84a789c..f641f6329a 100644
@@ -1835,7 +1835,7 @@ static int fill_pack_entry(const unsigned char *sha1,
  * Iff a pack file contains the object named by sha1, return true and
  * store its location to e.
  */
-int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)
+int find_pack_entry_the_repository(const unsigned char *sha1, struct pack_entry *e)
 {
 	struct mru_entry *p;
 
@@ -1855,7 +1855,7 @@ int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)
 int has_sha1_pack(const unsigned char *sha1)
 {
 	struct pack_entry e;
-	return find_pack_entry(sha1, &e);
+	return find_pack_entry(the_repository, sha1, &e);
 }
 
 int has_pack_index(const unsigned char *sha1)
packfile.h +2 -1
index bb1d92b849..b42e5c2db1 100644
@@ -141,7 +141,8 @@ extern int packed_object_info_the_repository(struct packed_git *pack, off_t offs
 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);
 
-extern int find_pack_entry(const unsigned char *sha1, struct pack_entry *e);
+#define find_pack_entry(r, s, e) find_pack_entry_##r(s, e)
+extern int find_pack_entry_the_repository(const unsigned char *sha1, struct pack_entry *e);
 
 extern int has_sha1_pack(const unsigned char *sha1);
 
sha1_file.c +3 -3
index 299e8be72c..7e06ece5f3 100644
@@ -1272,7 +1272,7 @@ int sha1_object_info_extended_the_repository(const unsigned char *sha1, struct o
 		}
 	}
 
-	if (!find_pack_entry(real, &e)) {
+	if (!find_pack_entry(the_repository, real, &e)) {
 		/* Most likely it's a loose object. */
 		if (!sha1_loose_object_info(the_repository, real, oi, flags))
 			return 0;
@@ -1282,7 +1282,7 @@ int sha1_object_info_extended_the_repository(const unsigned char *sha1, struct o
 			return -1;
 		} else {
 			reprepare_packed_git(the_repository);
-			if (!find_pack_entry(real, &e))
+			if (!find_pack_entry(the_repository, real, &e))
 				return -1;
 		}
 	}
@@ -1648,7 +1648,7 @@ static int freshen_loose_object(const unsigned char *sha1)
 static int freshen_packed_object(const unsigned char *sha1)
 {
 	struct pack_entry e;
-	if (!find_pack_entry(sha1, &e))
+	if (!find_pack_entry(the_repository, sha1, &e))
 		return 0;
 	if (e.p->freshened)
 		return 1;
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#98 lore raw

PATCH 70/194 packfile: add repository argument to read_object

In reply to Stefan Beller

Add a repository argument to allow the callers of read_object 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.

---
 packfile.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
packfile.c +5 -3
index f641f6329a..56b2db8b06 100644
@@ -1447,8 +1447,10 @@ struct unpack_entry_stack_ent {
 	unsigned long size;
 };
 
-static void *read_object(const unsigned char *sha1, enum object_type *type,
-			 unsigned long *size)
+#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;
 	void *content;
@@ -1592,7 +1594,7 @@ void *unpack_entry(struct packed_git *p, off_t obj_offset,
 				      sha1_to_hex(base_sha1), (uintmax_t)obj_offset,
 				      p->pack_name);
 				mark_bad_packed_object(p, base_sha1);
-				base = read_object(base_sha1, &type, &base_size);
+				base = read_object(the_repository, base_sha1, &type, &base_size);
 				external_base = base;
 			}
 		}
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#99 lore raw

PATCH 71/194 packfile: add repository argument to unpack_entry

In reply to Stefan Beller

Add a repository argument to allow the callers of unpack_entry 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.

---
 fast-import.c | 2 +-
 pack-check.c  | 3 ++-
 packfile.c    | 7 ++++---
 packfile.h    | 3 ++-
 4 files changed, 9 insertions(+), 6 deletions(-)
fast-import.c +1 -1
index 2542f600ef..5618087015 100644
@@ -1372,7 +1372,7 @@ static void *gfi_unpack_entry(
 		 */
 		p->pack_size = pack_size + 20;
 	}
-	return unpack_entry(p, oe->idx.offset, &type, sizep);
+	return unpack_entry(the_repository, p, oe->idx.offset, &type, sizep);
 }
 
 static const char *get_mode(const char *str, uint16_t *modep)
pack-check.c +2 -1
index c80c3ed8fd..25afd59c7d 100644
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "repository.h"
 #include "pack.h"
 #include "object-store.h"
 #include "pack-revindex.h"
@@ -134,7 +135,7 @@ static int verify_packfile(struct packed_git *p,
 			data = NULL;
 			data_valid = 0;
 		} else {
-			data = unpack_entry(p, entries[i].offset, &type, &size);
+			data = unpack_entry(the_repository, p, entries[i].offset, &type, &size);
 			data_valid = 1;
 		}
 
packfile.c +4 -3
index 56b2db8b06..69a1cedbe1 100644
@@ -1257,7 +1257,7 @@ static void *cache_or_unpack_entry(struct packed_git *p, off_t base_offset,
 
 	ent = get_delta_base_cache_entry(p, base_offset);
 	if (!ent)
-		return unpack_entry(p, base_offset, type, base_size);
+		return unpack_entry(the_repository, p, base_offset, type, base_size);
 
 	if (type)
 		*type = ent->type;
@@ -1463,8 +1463,9 @@ static void *read_object_the_repository(const unsigned char *sha1,
 	return content;
 }
 
-void *unpack_entry(struct packed_git *p, off_t obj_offset,
-		   enum object_type *final_type, unsigned long *final_size)
+void *unpack_entry_the_repository(struct packed_git *p, off_t obj_offset,
+				  enum object_type *final_type,
+				  unsigned long *final_size)
 {
 	struct pack_window *w_curs = NULL;
 	off_t curpos = obj_offset;
packfile.h +2 -1
index b42e5c2db1..615c58cbac 100644
@@ -125,7 +125,8 @@ extern off_t nth_packed_object_offset(const struct packed_git *, uint32_t n);
 extern off_t find_pack_entry_one(const unsigned char *sha1, struct packed_git *);
 
 extern int is_pack_valid(struct packed_git *);
-extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsigned long *);
+#define unpack_entry(r, p, of, ot, s) unpack_entry_##r(p, of, ot, s)
+extern void *unpack_entry_the_repository(struct packed_git *, off_t, enum object_type *, unsigned long *);
 extern unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep);
 extern unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t);
 extern int unpack_object_header(struct packed_git *, struct pack_window **, off_t *, unsigned long *);
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#100 lore raw

PATCH 72/194 packfile: add repository argument to cache_or_unpack_entry

In reply to Stefan Beller

Add a repository argument to allow the callers of cache_or_unpack_entry 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.

---
 packfile.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
packfile.c +3 -2
index 69a1cedbe1..9f7ca8f211 100644
@@ -1250,7 +1250,8 @@ static void detach_delta_base_cache_entry(struct delta_base_cache_entry *ent)
 	free(ent);
 }
 
-static void *cache_or_unpack_entry(struct packed_git *p, off_t base_offset,
+#define cache_or_unpack_entry(r, p, bo, bs, t) cache_or_unpack_entry_##r(p, bo, bs, t)
+static void *cache_or_unpack_entry_the_repository(struct packed_git *p, off_t base_offset,
 	unsigned long *base_size, enum object_type *type)
 {
 	struct delta_base_cache_entry *ent;
@@ -1324,7 +1325,7 @@ int packed_object_info_the_repository(struct packed_git *p, off_t obj_offset,
 	 * a "real" type later if the caller is interested.
 	 */
 	if (oi->contentp) {
-		*oi->contentp = cache_or_unpack_entry(p, obj_offset, oi->sizep,
+		*oi->contentp = cache_or_unpack_entry(the_repository, p, obj_offset, oi->sizep,
 						      &type);
 		if (!*oi->contentp)
 			type = OBJ_BAD;
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#101 lore raw

PATCH 73/194 pack: allow find_pack_entry to handle arbitrary repositories

In reply to Stefan Beller
---
 packfile.c | 12 +++++++-----
 packfile.h |  5 +++--
 2 files changed, 10 insertions(+), 7 deletions(-)
packfile.c +7 -5
index 9f7ca8f211..178d2e0ddd 100644
@@ -1839,17 +1839,19 @@ static int fill_pack_entry(const unsigned char *sha1,
  * Iff a pack file contains the object named by sha1, return true and
  * store its location to e.
  */
-int find_pack_entry_the_repository(const unsigned char *sha1, struct pack_entry *e)
+int find_pack_entry(struct repository *r,
+		    const unsigned char *sha1,
+		    struct pack_entry *e)
 {
 	struct mru_entry *p;
 
-	prepare_packed_git(the_repository);
-	if (!the_repository->objects.packed_git)
+	prepare_packed_git(r);
+	if (!r->objects.packed_git)
 		return 0;
 
-	for (p = the_repository->objects.packed_git_mru.head; p; p = p->next) {
+	for (p = r->objects.packed_git_mru.head; p; p = p->next) {
 		if (fill_pack_entry(sha1, e, p->item)) {
-			mru_mark(&the_repository->objects.packed_git_mru, p);
+			mru_mark(&r->objects.packed_git_mru, p);
 			return 1;
 		}
 	}
packfile.h +3 -2
index 615c58cbac..6d10871d25 100644
@@ -142,8 +142,9 @@ extern int packed_object_info_the_repository(struct packed_git *pack, off_t offs
 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 find_pack_entry(r, s, e) find_pack_entry_##r(s, e)
-extern int find_pack_entry_the_repository(const unsigned char *sha1, struct pack_entry *e);
+extern int find_pack_entry(struct repository *r,
+			   const unsigned char *sha1,
+			   struct pack_entry *e);
 
 extern int has_sha1_pack(const unsigned char *sha1);
 
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#102 lore raw

PATCH 74/194 object-store: allow sha1_object_info to handle arbitrary repositories

In reply to Stefan Beller

This involves also adapting sha1_object_info_extended and a some internal functions that are used to implement these. It all has to happen in one patch, because of a single recursive chain of calls visits all these functions.

---
 object-store.h | 13 ++++++-------
 packfile.c     | 58 ++++++++++++++++++++++++++++------------------------------
 packfile.h     |  8 ++++----
 sha1_file.c    | 24 +++++++++++++-----------
 4 files changed, 51 insertions(+), 52 deletions(-)
object-store.h +6 -7
index 4ff60e3be0..6930cfef82 100644
@@ -91,10 +91,7 @@ static inline void *read_sha1_file(const unsigned char *sha1, enum object_type *
 }
 
 /* Read and unpack a sha1 file into memory, write memory to a sha1 file */
-
-#define sha1_object_info(r, sha1, size) \
-	sha1_object_info_##r(sha1, size)
-extern int sha1_object_info_the_repository(const unsigned char *, unsigned long *);
+extern int sha1_object_info(struct repository *r, const unsigned char *sha1, unsigned long *sizep);
 extern int hash_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *sha1);
 extern int write_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *return_sha1);
 extern int hash_sha1_file_literally(const void *buf, unsigned long len, const char *type, struct object_id *oid, unsigned flags);
@@ -166,8 +163,10 @@ struct object_info {
 #define OBJECT_INFO_SKIP_CACHED 4
 /* Do not retry packed storage after checking packed and loose storage */
 #define OBJECT_INFO_QUICK 8
-#define sha1_object_info_extended(r, s, oi, f) \
-		sha1_object_info_extended_##r(s, oi, f)
-extern int sha1_object_info_extended_the_repository(const unsigned char *, struct object_info *, unsigned flags);
+
+extern int sha1_object_info_extended(struct repository *r,
+				     const unsigned char *sha1,
+				     struct object_info *oi,
+				     unsigned flags);
 
 #endif /* OBJECT_STORE_H */
packfile.c +28 -30

139 lines not on this page · raw message

packfile.h +4 -4
index 6d10871d25..f8d2825cce 100644
@@ -125,8 +125,7 @@ extern off_t nth_packed_object_offset(const struct packed_git *, uint32_t n);
 extern off_t find_pack_entry_one(const unsigned char *sha1, struct packed_git *);
 
 extern int is_pack_valid(struct packed_git *);
-#define unpack_entry(r, p, of, ot, s) unpack_entry_##r(p, of, ot, s)
-extern void *unpack_entry_the_repository(struct packed_git *, off_t, enum object_type *, unsigned long *);
+extern void *unpack_entry(struct repository *r, struct packed_git *, off_t, enum object_type *, unsigned long *);
 extern unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep);
 extern unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t);
 extern int unpack_object_header(struct packed_git *, struct pack_window **, off_t *, unsigned long *);
@@ -136,8 +135,9 @@ extern void release_pack_memory(size_t);
 /* global flag to enable extra checks when accessing packed objects */
 extern int do_check_packed_object_crc;
 
-#define packed_object_info(r, p, o, oi) packed_object_info_##r(p, o, oi)
-extern int packed_object_info_the_repository(struct packed_git *pack, off_t offset, struct object_info *);
+extern int packed_object_info(struct repository *r,
+			      struct packed_git *pack,
+			      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);
sha1_file.c +13 -11
index 7e06ece5f3..c296b76329 100644
@@ -1237,13 +1237,14 @@ static int sha1_loose_object_info(struct repository *r,
 	return (status < 0) ? status : 0;
 }
 
-int sha1_object_info_extended_the_repository(const unsigned char *sha1, struct object_info *oi, unsigned flags)
+int sha1_object_info_extended(struct repository *r, const unsigned char *sha1,
+			      struct object_info *oi, unsigned flags)
 {
 	static struct object_info blank_oi = OBJECT_INFO_INIT;
 	struct pack_entry e;
 	int rtype;
 	const unsigned char *real = (flags & OBJECT_INFO_LOOKUP_REPLACE) ?
-				    lookup_replace_object(the_repository, sha1) :
+				    lookup_replace_object(r, sha1) :
 				    sha1;
 
 	if (is_null_sha1(real))
@@ -1272,17 +1273,17 @@ int sha1_object_info_extended_the_repository(const unsigned char *sha1, struct o
 		}
 	}
 
-	if (!find_pack_entry(the_repository, real, &e)) {
+	if (!find_pack_entry(r, real, &e)) {
 		/* Most likely it's a loose object. */
-		if (!sha1_loose_object_info(the_repository, real, oi, flags))
+		if (!sha1_loose_object_info(r, real, oi, flags))
 			return 0;
 
 		/* Not a loose object; someone else may have just packed it. */
 		if (flags & OBJECT_INFO_QUICK) {
 			return -1;
 		} else {
-			reprepare_packed_git(the_repository);
-			if (!find_pack_entry(the_repository, real, &e))
+			reprepare_packed_git(r);
+			if (!find_pack_entry(r, real, &e))
 				return -1;
 		}
 	}
@@ -1294,11 +1295,10 @@ int sha1_object_info_extended_the_repository(const unsigned char *sha1, struct o
 		 */
 		return 0;
 
-	rtype = packed_object_info(the_repository, e.p, e.offset, oi);
+	rtype = packed_object_info(r, e.p, e.offset, oi);
 	if (rtype < 0) {
 		mark_bad_packed_object(e.p, real);
-		return sha1_object_info_extended(the_repository, real, oi,
-						 0);
+		return sha1_object_info_extended(r, real, oi, 0);
 	} else if (oi->whence == OI_PACKED) {
 		oi->u.packed.offset = e.offset;
 		oi->u.packed.pack = e.p;
@@ -1310,14 +1310,16 @@ int sha1_object_info_extended_the_repository(const unsigned char *sha1, struct o
 }
 
 /* returns enum object_type or negative */
-int sha1_object_info_the_repository(const unsigned char *sha1, unsigned long *sizep)
+int sha1_object_info(struct repository *r,
+		     const unsigned char *sha1,
+		     unsigned long *sizep)
 {
 	enum object_type type;
 	struct object_info oi = OBJECT_INFO_INIT;
 
 	oi.typep = &type;
 	oi.sizep = sizep;
-	if (sha1_object_info_extended(the_repository, sha1, &oi,
+	if (sha1_object_info_extended(r, sha1, &oi,
 				      OBJECT_INFO_LOOKUP_REPLACE) < 0)
 		return -1;
 	return type;
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#103 lore raw

PATCH 75/194 fetch, push: do not use submodule as alternate in has_commits check

In reply to Stefan Beller

Both fetch and push still use alternates to access submodules in some other code paths, but this is progress towards eliminating the alternates hack that conflates access to the_repository and other repositories.

---
 submodule.c | 52 ++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 38 insertions(+), 14 deletions(-)
submodule.c +38 -14
index dc57c176e8..1504812842 100644
@@ -811,14 +811,15 @@ static int append_oid_to_argv(const struct object_id *oid, void *data)
 
 struct has_commit_data {
 	int result;
-	const char *path;
+	struct repository *repo;
 };
 
 static int check_has_commit(const struct object_id *oid, void *data)
 {
 	struct has_commit_data *cb = data;
+	struct repository *r = cb->repo;
 
-	enum object_type type = sha1_object_info(the_repository, oid->hash, NULL);
+	enum object_type type = sha1_object_info(r, oid->hash, NULL);
 
 	switch (type) {
 	case OBJ_COMMIT:
@@ -832,24 +833,43 @@ static int check_has_commit(const struct object_id *oid, void *data)
 		return 0;
 	default:
 		die(_("submodule entry '%s' (%s) is a %s, not a commit"),
-		    cb->path, oid_to_hex(oid), typename(type));
+		    r->submodule_prefix, oid_to_hex(oid), typename(type));
 	}
 }
 
+/*
+ * Initialize 'out' based on the provided submodule path.
+ *
+ * Unlike repo_submodule_init, this tolerates submodules not present
+ * in .gitmodules. NEEDSWORK: The repo_submodule_init behavior is
+ * preferrable. This function exists only to preserve historical behavior.
+ *
+ * Returns 0 on success, -1 when the submodule is not present.
+ */
+static int open_submodule(struct repository *out, const char *path)
+{
+	struct strbuf sb = STRBUF_INIT;
+
+	if (submodule_to_gitdir(&sb, path))
+		return -1;
+
+	if (repo_init(out, sb.buf, NULL)) {
+		strbuf_release(&sb);
+		return -1;
+	}
+
+	out->submodule_prefix = xstrdup(path);
+
+	strbuf_release(&sb);
+	return 0;
+}
+
 static int submodule_has_commits(const char *path, struct oid_array *commits)
 {
-	struct has_commit_data has_commit = { 1, path };
+	struct repository sub;
+	struct has_commit_data has_commit = { 1, &sub };
 
-	/*
-	 * Perform a cheap, but incorrect check for the existence of 'commits'.
-	 * This is done by adding the submodule's object store to the in-core
-	 * object store, and then querying for each commit's existence.  If we
-	 * do not have the commit object anywhere, there is no chance we have
-	 * it in the object store of the correct submodule and have it
-	 * reachable from a ref, so we can fail early without spawning rev-list
-	 * which is expensive.
-	 */
-	if (add_submodule_odb(path))
+	if (open_submodule(&sub, path))
 		return 0;
 
 	oid_array_for_each_unique(commits, check_has_commit, &has_commit);
@@ -878,6 +898,7 @@ static int submodule_has_commits(const char *path, struct oid_array *commits)
 		strbuf_release(&out);
 	}
 
+	repo_clear(&sub);
 	return has_commit.result;
 }
 
@@ -897,6 +918,9 @@ static int submodule_needs_pushing(const char *path, struct oid_array *commits)
 		 */
 		return 0;
 
+	/* The submodule odb is needed for access to its refs. */
+	if (add_submodule_odb(path))
+		BUG("submodule '%s' is both present and absent", path);
 	if (for_each_remote_ref_submodule(path, has_remote, NULL) > 0) {
 		struct child_process cp = CHILD_PROCESS_INIT;
 		struct strbuf buf = STRBUF_INIT;
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#104 lore raw

Re: [PATCH 075/194] fetch, push: do not use submodule as alternate in has_commits check

Quoted 9 lines · Stefan Beller

Both fetch and push still use alternates to access submodules in some other code paths, but this is progress towards eliminating the alternates hack that conflates access to the_repository and other repositories.

---

submodule.c static int check_has_commit(const struct object_id *oid, void *data) · line 838

Quoted 6 lines
submodule.c +6 -0
@@ -832,24 +833,43 @@ static int check_has_commit(const struct object_id *oid, void *data)
+static int open_submodule(struct repository *out, const char *path)
+{
+       struct strbuf sb = STRBUF_INIT;
+
+       if (submodule_to_gitdir(&sb, path))
+               return -1;

submodule_to_gitdir() makes no promise that it has not made allocations to 'sb' when it returns -1, so this is potentially leaking. Therefore, you should strbuf_release() here.

submodule.c static int check_has_commit(const struct object_id *oid, void *data) · line 859

Quoted 5 lines
submodule.c +5 -0
+
+       if (repo_init(out, sb.buf, NULL)) {
+               strbuf_release(&sb);
+               return -1;
+       }

Or just combine these two error cases:

    if (submodule_to_gitdir(...) || repo_init(...)) {
        strbuf_release(...);
        return -1;
    }
Quoted 5 lines
submodule.c +5 -0
+       out->submodule_prefix = xstrdup(path);
+
+       strbuf_release(&sb);
+       return 0;
+}
#105 lore raw

Re: [PATCH 075/194] fetch, push: do not use submodule as alternate in has_commits check

Quoted 6 lines · Eric Sunshine

Or just combine these two error cases:

    if (submodule_to_gitdir(...) || repo_init(...)) {
        strbuf_release(...);
        return -1;
    }

will fix, thanks!

#106 lore raw

PATCH 76/194 push: add test showing bad interaction of replace refs and submodules

In reply to Stefan Beller

The ref subsystem has not been migrated yet to access the object store via passed in repository objects. As a result replace when the object store tries to access replace refs in a repository other than the_repository it produces errors:

error: refs/replace/3afabef75c627b894cccc3bcae86837abc7c32fe does not point to a valid object!

Add a test demonstrating this failure.

squash! push: add test showing bad interaction of replace refs and submodules

replace-objects: evaluate replacement refs without using the object store

Pass DO_FOR_EACH_INCLUDE_BROKEN when iterating over replacement refs so that the iteration does not require opening the named objects from the object store. This avoids a dependency cycle between object access and replace ref iteration.

Moreover the ref subsystem has not been migrated yet to access the object store via passed in repository objects. As a result, without this patch when the object store tries to access replace refs in a repository other than the_repository it produces errors:

error: refs/replace/3afabef75c627b894cccc3bcae86837abc7c32fe does not point to a valid object!

---
 t/t5531-deep-submodule-push.sh | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
t/t5531-deep-submodule-push.sh +16 -0
index 39cb2c1c34..8b2aa5a0f4 100755
@@ -308,6 +308,22 @@ test_expect_success 'submodule entry pointing at a tag is error' '
 	test_i18ngrep "is a tag, not a commit" err
 '
 
+test_expect_success 'replace ref does not interfere with submodule access' '
+	test_commit -C work/gar/bage one &&
+	test_commit -C work/gar/bage two &&
+	git -C work/gar/bage reset HEAD^^ &&
+	git -C work/gar/bage replace two one &&
+	test_when_finished "git -C work/gar/bage replace -d two" &&
+
+	test_commit -C work/gar/bage three &&
+	git -C work add gar/bage &&
+	git -C work commit -m "advance submodule" &&
+
+	git -C work push --recurse-submodules=on-demand ../pub.git master 2>err &&
+	! grep error err &&
+	! grep fatal err
+'
+
 test_expect_success 'push fails if recurse submodules option passed as yes' '
 	(
 		cd work/gar/bage &&
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#107 lore raw

Re: [PATCH 076/194] push: add test showing bad interaction of replace refs and submodules

Quoted 26 lines · Stefan Beller

The ref subsystem has not been migrated yet to access the object store via passed in repository objects. As a result replace when the object store tries to access replace refs in a repository other than the_repository it produces errors:

error: refs/replace/3afabef75c627b894cccc3bcae86837abc7c32fe does not point to a valid object!

Add a test demonstrating this failure.

squash! push: add test showing bad interaction of replace refs and submodules

replace-objects: evaluate replacement refs without using the object store

Pass DO_FOR_EACH_INCLUDE_BROKEN when iterating over replacement refs so that the iteration does not require opening the named objects from the object store. This avoids a dependency cycle between object access and replace ref iteration.

Moreover the ref subsystem has not been migrated yet to access the object store via passed in repository objects. As a result, without this patch when the object store tries to access replace refs in a repository other than the_repository it produces errors:

Quoted 4 lines

error: refs/replace/3afabef75c627b894cccc3bcae86837abc7c32fe does not point to a valid object!

It appears you have multiple independent commit messages here.

Signature · 3 lines
brian m. carlson / brian with sandals: Houston, Texas, US
https://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: https://keybase.io/bk2204
#108 lore raw

Re: [PATCH 076/194] push: add test showing bad interaction of replace refs and submodules

Quoted 27 lines · brian m. carlson
Quoted 26 lines · Stefan Beller

The ref subsystem has not been migrated yet to access the object store via passed in repository objects. As a result replace when the object store tries to access replace refs in a repository other than the_repository it produces errors:

error: refs/replace/3afabef75c627b894cccc3bcae86837abc7c32fe does not point to a valid object!

Add a test demonstrating this failure.

squash! push: add test showing bad interaction of replace refs and submodules

replace-objects: evaluate replacement refs without using the object store

Pass DO_FOR_EACH_INCLUDE_BROKEN when iterating over replacement refs so that the iteration does not require opening the named objects from the object store. This avoids a dependency cycle between object access and replace ref iteration.

Moreover the ref subsystem has not been migrated yet to access the object store via passed in repository objects. As a result, without this patch when the object store tries to access replace refs in a repository other than the_repository it produces errors:

Quoted 6 lines
Quoted 4 lines

error: refs/replace/3afabef75c627b894cccc3bcae86837abc7c32fe does not point to a valid object!

It appears you have multiple independent commit messages here.

I will drop this patch; it appears as if it was targeted to be part of 006f3f28af (replace-objects: evaluate replacement refs without using the object store, 2017-09-12), which landed.

We can revive this test outside of this long series if we feel inclined.

Thanks for spotting!
Stefan

#109 lore raw

PATCH 77/194 replace_object: allow register_replace_ref to handle arbitrary repositories

In reply to Stefan Beller
---
 replace-object.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
replace-object.c +1 -2
index a6a34217d8..96d339729a 100644
@@ -68,8 +68,7 @@ static int register_replace_ref(const char *refname,
 	hashcpy(repl_obj->replacement, oid->hash);
 
 	/* Register new object */
-	(void)r;
-	if (register_replace_object(the_repository, repl_obj, 1))
+	if (register_replace_object(r, repl_obj, 1))
 		die("duplicate replace ref: %s", refname);
 
 	return 0;
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#110 lore raw

PATCH 78/194 cache.h: migrate the definition of object_id to object.h

In reply to Stefan Beller

In the following patch we'll need the struct object completely accessible in object.h, which includes an object_id. Move the definition of the object_id there, to enable this.

---
 cache.h  | 13 +------------
 object.h | 12 ++++++++++++
 2 files changed, 13 insertions(+), 12 deletions(-)
cache.h +1 -12
index 22404de92b..634172cec4 100644
@@ -15,6 +15,7 @@
 #include "path.h"
 #include "sha1-array.h"
 #include "repository.h"
+#include "object.h"
 
 #ifndef platform_SHA_CTX
 /*
@@ -66,18 +67,6 @@ int git_deflate_end_gently(git_zstream *);
 int git_deflate(git_zstream *, int flush);
 unsigned long git_deflate_bound(git_zstream *, unsigned long);
 
-/* The length in bytes and in hex digits of an object name (SHA-1 value). */
-#define GIT_SHA1_RAWSZ 20
-#define GIT_SHA1_HEXSZ (2 * GIT_SHA1_RAWSZ)
-
-/* The length in byte and in hex digits of the largest possible hash value. */
-#define GIT_MAX_RAWSZ GIT_SHA1_RAWSZ
-#define GIT_MAX_HEXSZ GIT_SHA1_HEXSZ
-
-struct object_id {
-	unsigned char hash[GIT_MAX_RAWSZ];
-};
-
 #define the_hash_algo the_repository->hash_algo
 
 #if defined(DT_UNKNOWN) && !defined(NO_D_TYPE_IN_DIRENT)
object.h +12 -0
index f34461d4af..fbccb09257 100644
@@ -43,6 +43,18 @@ struct object_array {
  */
 #define FLAG_BITS  27
 
+/* The length in bytes and in hex digits of an object name (SHA-1 value). */
+#define GIT_SHA1_RAWSZ 20
+#define GIT_SHA1_HEXSZ (2 * GIT_SHA1_RAWSZ)
+
+/* The length in byte and in hex digits of the largest possible hash value. */
+#define GIT_MAX_RAWSZ GIT_SHA1_RAWSZ
+#define GIT_MAX_HEXSZ GIT_SHA1_HEXSZ
+
+struct object_id {
+	unsigned char hash[GIT_MAX_RAWSZ];
+};
+
 /*
  * The object type is stored in 3 bits.
  */
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#111 lore raw

PATCH 79/194 repository: introduce object parser field

In reply to Stefan Beller

Git's object access code can be thought of as containing two layers:
the raw object store provides access to raw object content, while the higher level obj_hash code parses raw objects and keeps track of parenthood and other object relationships using 'struct object'. Keeping these layers separate should make it easier to find relevant functions and to change the implementation of one without having to touch the other.

Add an object_parser field to 'struct repository' to prepare obj_hash to be handled per repository. Callers still only use the_repository for now --- later patches will adapt them to handle arbitrary repositories.

---
 object-store.h |  4 ++--
 object.c       | 42 +++++++++++++++++++++---------------------
 object.h       |  7 +++++++
 repository.c   |  2 +-
 repository.h   | 14 ++++++++++++--
 5 files changed, 43 insertions(+), 26 deletions(-)
object-store.h +2 -2
index 6930cfef82..d009f952f8 100644
@@ -12,7 +12,7 @@ struct pack_window;
 enum object_type;
 extern int check_replace_refs;
 
-struct object_store {
+struct raw_object_store {
 	struct packed_git *packed_git;
 
 	/*
@@ -57,7 +57,7 @@ struct object_store {
 	 */
 	unsigned packed_git_initialized : 1;
 };
-#define OBJECT_STORE_INIT \
+#define RAW_OBJECT_STORE_INIT \
 	{ NULL, MRU_INIT, ALTERNATES_INIT, { NULL, 0, 0, 0 }, 0, 0, 0 }
 
 struct packed_git {
object.c +21 -21

98 lines not on this page · raw message

object.h +7 -0
index fbccb09257..2cff106ff7 100644
@@ -1,6 +1,13 @@
 #ifndef OBJECT_H
 #define OBJECT_H
 
+struct object_parser {
+	struct object **obj_hash;
+	int nr_objs, obj_hash_size;
+};
+
+#define OBJECT_PARSER_INIT { NULL, 0, 0 }
+
 struct object_list {
 	struct object *item;
 	struct object_list *next;
repository.c +1 -1
index 6f85fade82..af62dfdc09 100644
@@ -6,7 +6,7 @@
 
 /* The main repository */
 static struct repository the_repo = {
-	NULL, NULL, NULL, OBJECT_STORE_INIT, NULL,
+	NULL, NULL, NULL, RAW_OBJECT_STORE_INIT, OBJECT_PARSER_INIT, NULL,
 	NULL, NULL, NULL, NULL, NULL, NULL, &the_index, NULL, 0, 0
 };
 struct repository *the_repository = &the_repo;
repository.h +12 -2
index 727ddcea5b..c8a34d1ac9 100644
@@ -2,6 +2,7 @@
 #define REPOSITORY_H
 
 #include "object-store.h"
+#include "object.h"
 
 struct config_set;
 struct index_state;
@@ -29,9 +30,18 @@ struct repository {
 	char *objectdir;
 
 	/*
-	 * Holds any information related to the object store.
+	 * Holds any information needed to retrieve the raw content
+	 * of objects. The object_parser uses this to get object
+	 * content which it then parses.
 	 */
-	struct object_store objects;
+	struct raw_object_store objects;
+
+	/*
+	 * State for the object parser. This owns all parsed objects
+	 * (struct object) so callers do not have to manage their
+	 * lifetime.
+	 */
+	struct object_parser parsed_objects;
 
 	/*
 	 * The store in which the refs are hold.
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#112 lore raw

PATCH 80/194 object: add repository argument to parse_object

In reply to Stefan Beller

Add a repository argument to allow the callers of parse_object 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/diff-tree.c                    |  3 ++-
 builtin/diff.c                         |  2 +-
 builtin/fast-export.c                  |  2 +-
 builtin/fmt-merge-msg.c                |  6 ++++--
 builtin/fsck.c                         |  4 ++--
 builtin/log.c                          |  3 ++-
 builtin/name-rev.c                     |  7 ++++---
 builtin/receive-pack.c                 |  6 +++---
 builtin/reflog.c                       |  3 ++-
 builtin/rev-list.c                     |  2 +-
 bundle.c                               |  3 ++-
 commit.c                               |  5 +++--
 contrib/coccinelle/object_parser.cocci |  6 ++++++
 fetch-pack.c                           | 16 +++++++++-------
 fsck.c                                 |  3 ++-
 http-backend.c                         |  2 +-
 http-push.c                            |  6 ++++--
 log-tree.c                             |  7 ++++---
 merge-recursive.c                      |  4 +++-
 object.c                               |  4 ++--
 object.h                               |  3 ++-
 pretty.c                               |  2 +-
 ref-filter.c                           |  3 ++-
 reflog-walk.c                          |  3 ++-
 refs/files-backend.c                   |  2 +-
 remote.c                               |  4 ++--
 revision.c                             | 12 ++++++------
 server-info.c                          |  2 +-
 sha1_name.c                            | 14 +++++++-------
 tag.c                                  |  5 +++--
 tree.c                                 |  5 +++--
 upload-pack.c                          |  9 +++++----
 walker.c                               |  3 ++-
 33 files changed, 95 insertions(+), 66 deletions(-)
 create mode 100644 contrib/coccinelle/object_parser.cocci
builtin/diff-tree.c +2 -1
index b775a75647..1f78308e33 100644
@@ -5,6 +5,7 @@
 #include "log-tree.h"
 #include "builtin.h"
 #include "submodule.h"
+#include "repository.h"
 
 static struct rev_info log_tree_opt;
 
@@ -68,7 +69,7 @@ static int diff_tree_stdin(char *line)
 	line[len-1] = 0;
 	if (parse_oid_hex(line, &oid, &p))
 		return -1;
-	obj = parse_object(&oid);
+	obj = parse_object(the_repository, &oid);
 	if (!obj)
 		return -1;
 	if (obj->type == OBJ_COMMIT)
builtin/diff.c +1 -1
index 16bfb22f73..ed6092ef1a 100644
@@ -393,7 +393,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
 		const char *name = entry->name;
 		int flags = (obj->flags & UNINTERESTING);
 		if (!obj->parsed)
-			obj = parse_object(&obj->oid);
+			obj = parse_object(the_repository, &obj->oid);
 		obj = deref_tag(obj, NULL, 0);
 		if (!obj)
 			die(_("invalid object '%s' given."), name);
builtin/fast-export.c +1 -1
index d4e53908c6..6140caf8d8 100644
@@ -798,7 +798,7 @@ static struct commit *get_commit(struct rev_cmdline_entry *e, char *full_name)
 
 		/* handle nested tags */
 		while (tag && tag->object.type == OBJ_TAG) {
-			parse_object(&tag->object.oid);
+			parse_object(the_repository, &tag->object.oid);
 			string_list_append(&extra_refs, full_name)->util = tag;
 			tag = (struct tag *)tag->tagged;
 		}
builtin/fmt-merge-msg.c +4 -2
index 9dd5c85831..dd74251690 100644
@@ -11,6 +11,7 @@
 #include "branch.h"
 #include "fmt-merge-msg.h"
 #include "gpg-interface.h"
+#include "repository.h"
 
 static const char * const fmt_merge_msg_usage[] = {
 	N_("git fmt-merge-msg [-m <message>] [--log[=<n>] | --no-log] [--file <file>]"),
@@ -343,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(oid), oid_to_hex(oid), GIT_SHA1_HEXSZ);
+	branch = deref_tag(parse_object(the_repository, oid), oid_to_hex(oid),
+			   GIT_SHA1_HEXSZ);
 	if (!branch || branch->type != OBJ_COMMIT)
 		return;
 
@@ -563,7 +565,7 @@ static void find_merge_parents(struct merge_parents *result,
 		 * "name" here and we do not want to contaminate its
 		 * util field yet.
 		 */
-		obj = parse_object(&oid);
+		obj = parse_object(the_repository, &oid);
 		parent = (struct commit *)peel_to_type(NULL, 0, obj, OBJ_COMMIT);
 		if (!parent)
 			continue;
builtin/fsck.c +2 -2
index f5e3c51077..9408ae5cc6 100644
@@ -437,7 +437,7 @@ static int fsck_handle_ref(const char *refname, const struct object_id *oid,
 {
 	struct object *obj;
 
-	obj = parse_object(oid);
+	obj = parse_object(the_repository, oid);
 	if (!obj) {
 		error("%s: invalid sha1 pointer %s", refname, oid_to_hex(oid));
 		errors_found |= ERROR_REACHABLE;
@@ -593,7 +593,7 @@ static int fsck_cache_tree(struct cache_tree *it)
 		fprintf(stderr, "Checking cache tree\n");
 
 	if (0 <= it->entry_count) {
-		struct object *obj = parse_object(&it->oid);
+		struct object *obj = parse_object(the_repository, &it->oid);
 		if (!obj) {
 			error("%s: invalid sha1 pointer in cache-tree",
 			      oid_to_hex(&it->oid));
builtin/log.c +2 -1
index de723fffc6..2c3579b1f7 100644
@@ -29,6 +29,7 @@
 #include "mailmap.h"
 #include "gpg-interface.h"
 #include "progress.h"
+#include "repository.h"
 
 /* Set a default date-time format for git log ("log.date" config variable) */
 static const char *default_date_mode = NULL;
@@ -613,7 +614,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
 			rev.shown_one = 1;
 			if (ret)
 				break;
-			o = parse_object(&t->tagged->oid);
+			o = parse_object(the_repository, &t->tagged->oid);
 			if (!o)
 				ret = error(_("Could not read object %s"),
 					    oid_to_hex(&t->tagged->oid));
builtin/name-rev.c +4 -3
index 9e088ebd11..c6b253eefb 100644
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "repository.h"
 #include "config.h"
 #include "commit.h"
 #include "tag.h"
@@ -187,7 +188,7 @@ static int tipcmp(const void *a_, const void *b_)
 
 static int name_ref(const char *path, const struct object_id *oid, int flags, void *cb_data)
 {
-	struct object *o = parse_object(oid);
+	struct object *o = parse_object(the_repository, oid);
 	struct name_ref_data *data = cb_data;
 	int can_abbreviate_output = data->tags_only && data->name_only;
 	int deref = 0;
@@ -245,7 +246,7 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo
 		struct tag *t = (struct tag *) o;
 		if (!t->tagged)
 			break; /* broken repository */
-		o = parse_object(&t->tagged->oid);
+		o = parse_object(the_repository, &t->tagged->oid);
 		deref = 1;
 		taggerdate = t->date;
 	}
@@ -434,7 +435,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
 		}
 
 		commit = NULL;
-		object = parse_object(&oid);
+		object = parse_object(the_repository, &oid);
 		if (object) {
 			struct object *peeled = deref_tag(object, *argv, 0);
 			if (peeled && peeled->type == OBJ_COMMIT)
builtin/receive-pack.c +3 -3
index 744fe29366..22d805a8ff 100644
@@ -1107,8 +1107,8 @@ static const char *update(struct command *cmd, struct shallow_info *si)
 		struct object *old_object, *new_object;
 		struct commit *old_commit, *new_commit;
 
-		old_object = parse_object(old_oid);
-		new_object = parse_object(new_oid);
+		old_object = parse_object(the_repository, old_oid);
+		new_object = parse_object(the_repository, new_oid);
 
 		if (!old_object || !new_object ||
 		    old_object->type != OBJ_COMMIT ||
@@ -1131,7 +1131,7 @@ static const char *update(struct command *cmd, struct shallow_info *si)
 
 	if (is_null_oid(new_oid)) {
 		struct strbuf err = STRBUF_INIT;
-		if (!parse_object(old_oid)) {
+		if (!parse_object(the_repository, old_oid)) {
 			old_oid = NULL;
 			if (ref_exists(name)) {
 				rp_warning("Allowing deletion of corrupt ref.");
builtin/reflog.c +2 -1
index 4b525c4448..18145d5494 100644
@@ -2,6 +2,7 @@
 #include "config.h"
 #include "lockfile.h"
 #include "object-store.h"
+#include "repository.h"
 #include "commit.h"
 #include "refs.h"
 #include "dir.h"
@@ -128,7 +129,7 @@ static int commit_is_complete(struct commit *commit)
 		struct commit_list *parent;
 
 		c = (struct commit *)object_array_pop(&study);
-		if (!c->object.parsed && !parse_object(&c->object.oid))
+		if (!c->object.parsed && !parse_object(the_repository, &c->object.oid))
 			c->object.flags |= INCOMPLETE;
 
 		if (c->object.flags & INCOMPLETE) {
builtin/rev-list.c +1 -1
index 969efde30c..3c2ae454ea 100644
@@ -222,7 +222,7 @@ static void finish_object(struct object *obj, const char *name, void *cb_data)
 	if (obj->type == OBJ_BLOB && !has_object_file(&obj->oid))
 		finish_object__ma(obj);
 	if (info->revs->verify_objects && !obj->parsed && obj->type != OBJ_COMMIT)
-		parse_object(&obj->oid);
+		parse_object(the_repository, &obj->oid);
 }
 
 static void show_object(struct object *obj, const char *name, void *cb_data)
bundle.c +2 -1
index d9376b7c77..1b5f1beb3b 100644
@@ -2,6 +2,7 @@
 #include "lockfile.h"
 #include "bundle.h"
 #include "object-store.h"
+#include "repository.h"
 #include "object.h"
 #include "commit.h"
 #include "diff.h"
@@ -143,7 +144,7 @@ int verify_bundle(struct bundle_header *header, int verbose)
 	init_revisions(&revs, NULL);
 	for (i = 0; i < p->nr; i++) {
 		struct ref_list_entry *e = p->list + i;
-		struct object *o = parse_object(&e->oid);
+		struct object *o = parse_object(the_repository, &e->oid);
 		if (o) {
 			o->flags |= PREREQ_MARK;
 			add_pending_object(&revs, o, e->name);
commit.c +3 -2
index b60906d3f9..742d710c86 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(oid), NULL, 0);
+	struct object *obj = deref_tag(parse_object(the_repository, oid),
+				       NULL, 0);
 
 	if (!obj)
 		return NULL;
@@ -1606,7 +1607,7 @@ struct commit *get_merge_parent(const char *name)
 	struct object_id oid;
 	if (get_oid(name, &oid))
 		return NULL;
-	obj = parse_object(&oid);
+	obj = parse_object(the_repository, &oid);
 	commit = (struct commit *)peel_to_type(name, 0, obj, OBJ_COMMIT);
 	if (commit && !commit->util)
 		set_merge_remote_desc(commit, name, obj);
contrib/coccinelle/object_parser.cocci new file +6 -0
new file mode 100644
index 0000000000..a9afe4bf7a
@@ -0,0 +1,6 @@
+@@
+expression E;
+@@
+ parse_object(
++ the_repository,
+ E)
fetch-pack.c +9 -7
index 9c189ff3ec..0f7aeabb64 100644
@@ -82,7 +82,7 @@ static void cache_one_alternate(const char *refname,
 				void *vcache)
 {
 	struct alternate_object_cache *cache = vcache;
-	struct object *obj = parse_object(oid);
+	struct object *obj = parse_object(the_repository, oid);
 
 	if (!obj || (obj->flags & ALTERNATE))
 		return;
@@ -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(oid), refname, 0);
+	struct object *o = deref_tag(parse_object(the_repository, oid),
+				     refname, 0);
 
 	if (o && o->type == OBJ_COMMIT)
 		rev_list_push((struct commit *)o, SEEN);
@@ -141,7 +142,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(oid), refname, 0);
+	struct object *o = deref_tag(parse_object(the_repository, oid),
+				     refname, 0);
 
 	if (o && o->type == OBJ_COMMIT)
 		clear_commit_marks((struct commit *)o,
@@ -430,7 +432,7 @@ static int find_common(struct fetch_pack_args *args,
 				if (!lookup_object(oid.hash))
 					die(_("object not found: %s"), line);
 				/* make sure that it is parsed as shallow */
-				if (!parse_object(&oid))
+				if (!parse_object(the_repository, &oid))
 					die(_("error in object: %s"), line);
 				if (unregister_shallow(&oid))
 					die(_("no shallow found: %s"), line);
@@ -561,14 +563,14 @@ static struct commit_list *complete;
 
 static int mark_complete(const struct object_id *oid)
 {
-	struct object *o = parse_object(oid);
+	struct object *o = parse_object(the_repository, oid);
 
 	while (o && o->type == OBJ_TAG) {
 		struct tag *t = (struct tag *) o;
 		if (!t->tagged)
 			break; /* broken repository */
 		o->flags |= COMPLETE;
-		o = parse_object(&t->tagged->oid);
+		o = parse_object(the_repository, &t->tagged->oid);
 	}
 	if (o && o->type == OBJ_COMMIT) {
 		struct commit *commit = (struct commit *)o;
@@ -721,7 +723,7 @@ static int everything_local(struct fetch_pack_args *args,
 						OBJECT_INFO_QUICK))
 			continue;
 
-		o = parse_object(&ref->old_oid);
+		o = parse_object(the_repository, &ref->old_oid);
 		if (!o)
 			continue;
 
fsck.c +2 -1
index d106714bf5..843ddc1035 100644
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "object-store.h"
+#include "repository.h"
 #include "object.h"
 #include "blob.h"
 #include "tree.h"
@@ -462,7 +463,7 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options)
 		return -1;
 
 	if (obj->type == OBJ_NONE)
-		parse_object(&obj->oid);
+		parse_object(the_repository, &obj->oid);
 
 	switch (obj->type) {
 	case OBJ_BLOB:
http-backend.c +1 -1
index 4950078c93..b76c8c4f3d 100644
@@ -435,7 +435,7 @@ static int show_text_ref(const char *name, const struct object_id *oid,
 {
 	const char *name_nons = strip_namespace(name);
 	struct strbuf *buf = cb_data;
-	struct object *o = parse_object(oid);
+	struct object *o = parse_object(the_repository, oid);
 	if (!o)
 		return 0;
 
http-push.c +4 -2
index 34c5d030b7..b4c3cd1cd7 100644
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "repository.h"
 #include "object-store.h"
 #include "commit.h"
 #include "tag.h"
@@ -14,6 +15,7 @@
 #include "argv-array.h"
 #include "packfile.h"
 
+
 #ifdef EXPAT_NEEDS_XMLPARSE_H
 #include <xmlparse.h>
 #else
@@ -722,7 +724,7 @@ static void one_remote_object(const struct object_id *oid)
 
 	obj = lookup_object(oid->hash);
 	if (!obj)
-		obj = parse_object(oid);
+		obj = parse_object(the_repository, oid);
 
 	/* Ignore remote objects that don't exist locally */
 	if (!obj)
@@ -1455,7 +1457,7 @@ static void add_remote_info_ref(struct remote_ls_ctx *ls)
 		return;
 	}
 
-	o = parse_object(&ref->old_oid);
+	o = parse_object(the_repository, &ref->old_oid);
 	if (!o) {
 		fprintf(stderr,
 			"Unable to parse object %s for remote ref %s\n",
log-tree.c +4 -3
index b2fff6b5f6..57d5e5f56d 100644
@@ -2,6 +2,7 @@
 #include "config.h"
 #include "diff.h"
 #include "object-store.h"
+#include "repository.h"
 #include "commit.h"
 #include "tag.h"
 #include "graph.h"
@@ -111,13 +112,13 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid,
 			warning("invalid replace ref %s", refname);
 			return 0;
 		}
-		obj = parse_object(&original_oid);
+		obj = parse_object(the_repository, &original_oid);
 		if (obj)
 			add_name_decoration(DECORATION_GRAFTED, "replaced", obj);
 		return 0;
 	}
 
-	obj = parse_object(oid);
+	obj = parse_object(the_repository, oid);
 	if (!obj)
 		return 0;
 
@@ -138,7 +139,7 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid,
 		if (!obj)
 			break;
 		if (!obj->parsed)
-			parse_object(&obj->oid);
+			parse_object(the_repository, &obj->oid);
 		add_name_decoration(DECORATION_REF_TAG, refname, obj);
 	}
 	return 0;
merge-recursive.c +3 -1
index 620e4f653c..e2c434c305 100644
@@ -9,6 +9,7 @@
 #include "lockfile.h"
 #include "cache-tree.h"
 #include "object-store.h"
+#include "repository.h"
 #include "commit.h"
 #include "blob.h"
 #include "builtin.h"
@@ -2151,7 +2152,8 @@ static struct commit *get_ref(const struct object_id *oid, const char *name)
 {
 	struct object *object;
 
-	object = deref_tag(parse_object(oid), name, strlen(name));
+	object = deref_tag(parse_object(the_repository, oid), name,
+			   strlen(name));
 	if (!object)
 		return NULL;
 	if (object->type == OBJ_TREE)
object.c +2 -2
index 18ea8cf574..c1154039df 100644
@@ -234,14 +234,14 @@ struct object *parse_object_buffer(const struct object_id *oid, enum object_type
 struct object *parse_object_or_die(const struct object_id *oid,
 				   const char *name)
 {
-	struct object *o = parse_object(oid);
+	struct object *o = parse_object(the_repository, oid);
 	if (o)
 		return o;
 
 	die(_("unable to parse object: %s"), name ? name : oid_to_hex(oid));
 }
 
-struct object *parse_object(const struct object_id *oid)
+struct object *parse_object_the_repository(const struct object_id *oid)
 {
 	unsigned long size;
 	enum object_type type;
object.h +2 -1
index 2cff106ff7..e5cad09fad 100644
@@ -109,7 +109,8 @@ void *object_as_type(struct object *obj, enum object_type type, int quiet);
  *
  * Returns NULL if the object is missing or corrupt.
  */
-struct object *parse_object(const struct object_id *oid);
+#define parse_object(r, oid) parse_object_##r(oid)
+struct object *parse_object_the_repository(const struct object_id *oid);
 
 /*
  * Like parse_object, but will die() instead of returning NULL. If the
pretty.c +1 -1
index f7ce490230..478af1a860 100644
@@ -1146,7 +1146,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
 
 	/* these depend on the commit */
 	if (!commit->object.parsed)
-		parse_object(&commit->object.oid);
+		parse_object(the_repository, &commit->object.oid);
 
 	switch (placeholder[0]) {
 	case 'H':		/* commit hash */
ref-filter.c +2 -1
index 0a106b888d..1d0bad5e36 100644
@@ -4,6 +4,7 @@
 #include "refs.h"
 #include "wildmatch.h"
 #include "object-store.h"
+#include "repository.h"
 #include "commit.h"
 #include "remote.h"
 #include "color.h"
@@ -1818,7 +1819,7 @@ static const struct object_id *match_points_at(struct oid_array *points_at,
 
 	if (oid_array_lookup(points_at, oid) >= 0)
 		return oid;
-	obj = parse_object(oid);
+	obj = parse_object(the_repository, oid);
 	if (!obj)
 		die(_("malformed object at '%s'"), refname);
 	if (obj->type == OBJ_TAG)
reflog-walk.c +2 -1
index 5008bbf6ad..3561a8b955 100644
@@ -305,7 +305,8 @@ static struct commit *next_reflog_commit(struct commit_reflog *log)
 {
 	for (; log->recno >= 0; log->recno--) {
 		struct reflog_info *entry = &log->reflogs->items[log->recno];
-		struct object *obj = parse_object(&entry->noid);
+		struct object *obj = parse_object(the_repository,
+						  &entry->noid);
 
 		if (obj && obj->type == OBJ_COMMIT)
 			return (struct commit *)obj;
refs/files-backend.c +1 -1
index f75d960e19..932fdc1f0b 100644
@@ -1658,7 +1658,7 @@ static int write_ref_to_lockfile(struct ref_lock *lock,
 	struct object *o;
 	int fd;
 
-	o = parse_object(oid);
+	o = parse_object(the_repository, oid);
 	if (!o) {
 		strbuf_addf(err,
 			    "trying to write ref '%s' with nonexistent object %s",
remote.c +2 -2
index fd8cd8ce77..2abc6baf84 100644
@@ -1980,12 +1980,12 @@ 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(old_oid), NULL, 0);
+	o = deref_tag(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(new_oid), NULL, 0);
+	o = deref_tag(parse_object(the_repository, new_oid), NULL, 0);
 	if (!o || o->type != OBJ_COMMIT)
 		return 0;
 	new = (struct commit *) o;
revision.c +6 -6
index e98bdf2ac7..5ccfc50447 100644
@@ -184,7 +184,7 @@ void add_head_to_pending(struct rev_info *revs)
 	struct object *obj;
 	if (get_oid("HEAD", &oid))
 		return;
-	obj = parse_object(&oid);
+	obj = parse_object(the_repository, &oid);
 	if (!obj)
 		return;
 	add_pending_object(revs, obj, "HEAD");
@@ -196,7 +196,7 @@ static struct object *get_reference(struct rev_info *revs, const char *name,
 {
 	struct object *object;
 
-	object = parse_object(oid);
+	object = parse_object(the_repository, oid);
 	if (!object) {
 		if (revs->ignore_missing)
 			return object;
@@ -231,7 +231,7 @@ static struct commit *handle_commit(struct rev_info *revs,
 			add_pending_object(revs, object, tag->tag);
 		if (!tag->tagged)
 			die("bad tag");
-		object = parse_object(&tag->tagged->oid);
+		object = parse_object(the_repository, &tag->tagged->oid);
 		if (!object) {
 			if (revs->ignore_missing_links || (flags & UNINTERESTING))
 				return NULL;
@@ -1222,7 +1222,7 @@ static void handle_one_reflog_commit(struct object_id *oid, void *cb_data)
 {
 	struct all_refs_cb *cb = cb_data;
 	if (!is_null_oid(oid)) {
-		struct object *o = parse_object(oid);
+		struct object *o = parse_object(the_repository, oid);
 		if (o) {
 			o->flags |= cb->all_flags;
 			/* ??? CMDLINEFLAGS ??? */
@@ -1549,8 +1549,8 @@ static int handle_dotdot_1(const char *arg, char *dotdot,
 		*dotdot = '\0';
 	}
 
-	a_obj = parse_object(&a_oid);
-	b_obj = parse_object(&b_oid);
+	a_obj = parse_object(the_repository, &a_oid);
+	b_obj = parse_object(the_repository, &b_oid);
 	if (!a_obj || !b_obj)
 		return dotdot_missing(arg, dotdot, revs, symmetric);
 
server-info.c +1 -1
index 6cd1506e5e..fd7ed2a383 100644
@@ -56,7 +56,7 @@ static int add_info_ref(const char *path, const struct object_id *oid,
 			int flag, void *cb_data)
 {
 	FILE *fp = cb_data;
-	struct object *o = parse_object(oid);
+	struct object *o = parse_object(the_repository, oid);
 	if (!o)
 		return -1;
 
sha1_name.c +7 -7
index 190710c638..0139b480a3 100644
@@ -259,7 +259,7 @@ 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(oid), NULL, 0);
+	obj = deref_tag(parse_object(the_repository, oid), NULL, 0);
 	if (obj && obj->type == OBJ_COMMIT)
 		return 1;
 	return 0;
@@ -283,7 +283,7 @@ 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(oid), NULL, 0);
+	obj = deref_tag(parse_object(the_repository, oid), NULL, 0);
 	if (obj && (obj->type == OBJ_TREE || obj->type == OBJ_COMMIT))
 		return 1;
 	return 0;
@@ -894,7 +894,7 @@ struct object *peel_to_type(const char *name, int namelen,
 	if (name && !namelen)
 		namelen = strlen(name);
 	while (1) {
-		if (!o || (!o->parsed && !parse_object(&o->oid)))
+		if (!o || (!o->parsed && !parse_object(the_repository, &o->oid)))
 			return NULL;
 		if (expected_type == OBJ_ANY || o->type == expected_type)
 			return o;
@@ -967,12 +967,12 @@ static int peel_onion(const char *name, int len, struct object_id *oid,
 	if (get_oid_1(name, sp - name - 2, &outer, lookup_flags))
 		return -1;
 
-	o = parse_object(&outer);
+	o = parse_object(the_repository, &outer);
 	if (!o)
 		return -1;
 	if (!expected_type) {
 		o = deref_tag(o, name, sp - name - 2);
-		if (!o || (!o->parsed && !parse_object(&o->oid)))
+		if (!o || (!o->parsed && !parse_object(the_repository, &o->oid)))
 			return -1;
 		oidcpy(oid, &o->oid);
 		return 0;
@@ -1099,7 +1099,7 @@ static int handle_one_ref(const char *path, const struct object_id *oid,
 			  int flag, void *cb_data)
 {
 	struct commit_list **list = cb_data;
-	struct object *object = parse_object(oid);
+	struct object *object = parse_object(the_repository, oid);
 	if (!object)
 		return 0;
 	if (object->type == OBJ_TAG) {
@@ -1145,7 +1145,7 @@ static int get_oid_oneline(const char *prefix, struct object_id *oid,
 		int matches;
 
 		commit = pop_most_recent_commit(&list, ONELINE_SEEN);
-		if (!parse_object(&commit->object.oid))
+		if (!parse_object(the_repository, &commit->object.oid))
 			continue;
 		buf = get_commit_buffer(commit, NULL);
 		p = strstr(buf, "\n\n");
tag.c +3 -2
index 7b32afd123..5207f70885 100644
@@ -68,7 +68,8 @@ struct object *deref_tag(struct object *o, const char *warn, int warnlen)
 {
 	while (o && o->type == OBJ_TAG)
 		if (((struct tag *)o)->tagged)
-			o = parse_object(&((struct tag *)o)->tagged->oid);
+			o = parse_object(the_repository,
+					 &((struct tag *)o)->tagged->oid);
 		else
 			o = NULL;
 	if (!o && warn) {
@@ -82,7 +83,7 @@ struct object *deref_tag(struct object *o, const char *warn, int warnlen)
 struct object *deref_tag_noverify(struct object *o)
 {
 	while (o && o->type == OBJ_TAG) {
-		o = parse_object(&o->oid);
+		o = parse_object(the_repository, &o->oid);
 		if (o && o->type == OBJ_TAG && ((struct tag *)o)->tagged)
 			o = ((struct tag *)o)->tagged;
 		else
tree.c +3 -2
index 653339db03..62d78fb4ba 100644
@@ -7,6 +7,7 @@
 #include "commit.h"
 #include "tag.h"
 #include "tree-walk.h"
+#include "repository.h"
 
 const char *tree_type = "tree";
 
@@ -242,7 +243,7 @@ void free_tree_buffer(struct tree *tree)
 
 struct tree *parse_tree_indirect(const struct object_id *oid)
 {
-	struct object *obj = parse_object(oid);
+	struct object *obj = parse_object(the_repository, oid);
 	do {
 		if (!obj)
 			return NULL;
@@ -255,6 +256,6 @@ struct tree *parse_tree_indirect(const struct object_id *oid)
 		else
 			return NULL;
 		if (!obj->parsed)
-			parse_object(&obj->oid);
+			parse_object(the_repository, &obj->oid);
 	} while (1);
 }
upload-pack.c +5 -4
index 6db85ecdc4..b076cbc5f7 100644
@@ -3,6 +3,7 @@
 #include "refs.h"
 #include "pkt-line.h"
 #include "sideband.h"
+#include "repository.h"
 #include "object-store.h"
 #include "tag.h"
 #include "object.h"
@@ -299,7 +300,7 @@ static int got_oid(const char *hex, struct object_id *oid)
 	if (!has_object_file(oid))
 		return -1;
 
-	o = parse_object(oid);
+	o = parse_object(the_repository, oid);
 	if (!o)
 		die("oops (%s)", oid_to_hex(oid));
 	if (o->type == OBJ_COMMIT) {
@@ -337,7 +338,7 @@ static int reachable(struct commit *want)
 			break;
 		}
 		if (!commit->object.parsed)
-			parse_object(&commit->object.oid);
+			parse_object(the_repository, &commit->object.oid);
 		if (commit->object.flags & REACHABLE)
 			continue;
 		commit->object.flags |= REACHABLE;
@@ -758,7 +759,7 @@ static void receive_needs(void)
 			struct object *object;
 			if (get_oid_hex(arg, &oid))
 				die("invalid shallow line: %s", line);
-			object = parse_object(&oid);
+			object = parse_object(the_repository, &oid);
 			if (!object)
 				continue;
 			if (object->type != OBJ_COMMIT)
@@ -824,7 +825,7 @@ static void receive_needs(void)
 		if (parse_feature_request(features, "include-tag"))
 			use_include_tag = 1;
 
-		o = parse_object(&oid_buf);
+		o = parse_object(the_repository, &oid_buf);
 		if (!o) {
 			packet_write_fmt(1,
 					 "ERR upload-pack: not our ref %s",
walker.c +2 -1
index 49b6a96e6e..492aea906f 100644
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "walker.h"
+#include "repository.h"
 #include "object-store.h"
 #include "commit.h"
 #include "tree.h"
@@ -181,7 +182,7 @@ static int loop(struct walker *walker)
 			}
 		}
 		if (!obj->type)
-			parse_object(&obj->oid);
+			parse_object(the_repository, &obj->oid);
 		if (process_object(walker, obj))
 			return -1;
 	}
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#113 lore raw

PATCH 81/194 object: add repository argument to create_object

In reply to Stefan Beller

Add a repository argument to allow the callers of create_object 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.

---
 blob.c                                 | 4 +++-
 commit.c                               | 3 ++-
 contrib/coccinelle/object_parser.cocci | 8 ++++++++
 object.c                               | 5 +++--
 object.h                               | 3 ++-
 tag.c                                  | 3 ++-
 tree.c                                 | 3 ++-
 7 files changed, 22 insertions(+), 7 deletions(-)
blob.c +3 -1
index fa2ab4f7a7..85c2143f29 100644
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "blob.h"
+#include "repository.h"
 
 const char *blob_type = "blob";
 
@@ -7,7 +8,8 @@ struct blob *lookup_blob(const struct object_id *oid)
 {
 	struct object *obj = lookup_object(oid->hash);
 	if (!obj)
-		return create_object(oid->hash, alloc_blob_node());
+		return create_object(the_repository, oid->hash,
+				     alloc_blob_node());
 	return object_as_type(obj, OBJ_BLOB, 0);
 }
 
commit.c +2 -1
index 742d710c86..e315d5435b 100644
@@ -52,7 +52,8 @@ struct commit *lookup_commit(const struct object_id *oid)
 {
 	struct object *obj = lookup_object(oid->hash);
 	if (!obj)
-		return create_object(oid->hash, alloc_commit_node());
+		return create_object(the_repository, oid->hash,
+				     alloc_commit_node());
 	return object_as_type(obj, OBJ_COMMIT, 0);
 }
 
contrib/coccinelle/object_parser.cocci +8 -0
index a9afe4bf7a..2a554084d1 100644
@@ -4,3 +4,11 @@ expression E;
  parse_object(
 + the_repository,
  E)
+
+@@
+expression E;
+expression F;
+@@
+ create_object(
++ the_repository,
+ E, F)
object.c +3 -2
index c1154039df..1126c7e278 100644
@@ -137,7 +137,7 @@ static void grow_object_hash(void)
 	the_repository->parsed_objects.obj_hash_size = new_hash_size;
 }
 
-void *create_object(const unsigned char *sha1, void *o)
+void *create_object_the_repository(const unsigned char *sha1, void *o)
 {
 	struct object *obj = o;
 
@@ -177,7 +177,8 @@ struct object *lookup_unknown_object(const unsigned char *sha1)
 {
 	struct object *obj = lookup_object(sha1);
 	if (!obj)
-		obj = create_object(sha1, alloc_object_node());
+		obj = create_object(the_repository, sha1,
+				    alloc_object_node());
 	return obj;
 }
 
object.h +2 -1
index e5cad09fad..ac12dc3629 100644
@@ -100,7 +100,8 @@ extern struct object *get_indexed_object(unsigned int);
  */
 struct object *lookup_object(const unsigned char *sha1);
 
-extern void *create_object(const unsigned char *sha1, void *obj);
+#define create_object(r, s, o) create_object_##r(s, o)
+extern void *create_object_the_repository(const unsigned char *sha1, void *obj);
 
 void *object_as_type(struct object *obj, enum object_type type, int quiet);
 
tag.c +2 -1
index 5207f70885..a9e5af4294 100644
@@ -96,7 +96,8 @@ struct tag *lookup_tag(const struct object_id *oid)
 {
 	struct object *obj = lookup_object(oid->hash);
 	if (!obj)
-		return create_object(oid->hash, alloc_tag_node());
+		return create_object(the_repository, oid->hash,
+				     alloc_tag_node());
 	return object_as_type(obj, OBJ_TAG, 0);
 }
 
tree.c +2 -1
index 62d78fb4ba..f8e1e6d63d 100644
@@ -198,7 +198,8 @@ struct tree *lookup_tree(const struct object_id *oid)
 {
 	struct object *obj = lookup_object(oid->hash);
 	if (!obj)
-		return create_object(oid->hash, alloc_tree_node());
+		return create_object(the_repository, oid->hash,
+				     alloc_tree_node());
 	return object_as_type(obj, OBJ_TREE, 0);
 }
 
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#114 lore raw

PATCH 82/194 object: add repository argument to lookup_object

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

Add a repository argument to allow callers of lookup_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.

---
 blob.c                                 | 2 +-
 builtin/fast-export.c                  | 5 +++--
 builtin/fsck.c                         | 5 +++--
 builtin/name-rev.c                     | 3 ++-
 builtin/prune.c                        | 2 +-
 builtin/unpack-objects.c               | 2 +-
 commit.c                               | 2 +-
 contrib/coccinelle/object_parser.cocci | 7 +++++++
 fetch-pack.c                           | 8 ++++----
 http-push.c                            | 2 +-
 object.c                               | 8 ++++----
 object.h                               | 3 ++-
 reachable.c                            | 4 ++--
 tag.c                                  | 2 +-
 tree.c                                 | 2 +-
 upload-pack.c                          | 2 +-
 16 files changed, 35 insertions(+), 24 deletions(-)
blob.c +1 -1
index 85c2143f29..a9f3aa2ec8 100644
@@ -6,7 +6,7 @@ const char *blob_type = "blob";
 
 struct blob *lookup_blob(const struct object_id *oid)
 {
-	struct object *obj = lookup_object(oid->hash);
+	struct object *obj = lookup_object(the_repository, oid->hash);
 	if (!obj)
 		return create_object(the_repository, oid->hash,
 				     alloc_blob_node());
builtin/fast-export.c +3 -2
index 6140caf8d8..642bafdd30 100644
@@ -230,7 +230,7 @@ static void export_blob(const struct object_id *oid)
 	if (is_null_oid(oid))
 		return;
 
-	object = lookup_object(oid->hash);
+	object = lookup_object(the_repository, oid->hash);
 	if (object && object->flags & SHOWN)
 		return;
 
@@ -402,7 +402,8 @@ static void show_filemodify(struct diff_queue_struct *q,
 						   anonymize_sha1(&spec->oid) :
 						   spec->oid.hash));
 			else {
-				struct object *object = lookup_object(spec->oid.hash);
+				struct object *object = lookup_object(the_repository,
+								      spec->oid.hash);
 				printf("M %06o :%d ", spec->mode,
 				       get_object_mark(object));
 			}
builtin/fsck.c +3 -2
index 9408ae5cc6..7645418821 100644
@@ -395,7 +395,7 @@ static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid,
 	struct object *obj;
 
 	if (!is_null_oid(oid)) {
-		obj = lookup_object(oid->hash);
+		obj = lookup_object(the_repository, oid->hash);
 		if (obj && (obj->flags & HAS_OBJ)) {
 			if (timestamp && name_objects)
 				add_decoration(fsck_walk_options.object_names,
@@ -736,7 +736,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
 		const char *arg = argv[i];
 		struct object_id oid;
 		if (!get_oid(arg, &oid)) {
-			struct object *obj = lookup_object(oid.hash);
+			struct object *obj = lookup_object(the_repository,
+							   oid.hash);
 
 			if (!obj || !(obj->flags & HAS_OBJ)) {
 				error("%s: object missing", oid_to_hex(&oid));
builtin/name-rev.c +2 -1
index c6b253eefb..45ec5515cc 100644
@@ -363,7 +363,8 @@ static void name_rev_line(char *p, struct name_ref_data *data)
 			*(p+1) = 0;
 			if (!get_oid(p - (GIT_SHA1_HEXSZ - 1), &oid)) {
 				struct object *o =
-					lookup_object(oid.hash);
+					lookup_object(the_repository,
+						      oid.hash);
 				if (o)
 					name = get_rev_name(o, &buf);
 			}
builtin/prune.c +1 -1
index 7891048b35..06e6de45b5 100644
@@ -40,7 +40,7 @@ static int prune_object(const struct object_id *oid, const char *fullpath,
 	 * Do we know about this object?
 	 * It must have been reachable
 	 */
-	if (lookup_object(oid->hash))
+	if (lookup_object(the_repository, oid->hash))
 		return 0;
 
 	if (lstat(fullpath, &st)) {
builtin/unpack-objects.c +1 -1
index ee707068b3..e26f673a15 100644
@@ -329,7 +329,7 @@ static int resolve_against_held(unsigned nr, const struct object_id *base,
 {
 	struct object *obj;
 	struct obj_buffer *obj_buffer;
-	obj = lookup_object(base->hash);
+	obj = lookup_object(the_repository, base->hash);
 	if (!obj)
 		return 0;
 	obj_buffer = lookup_object_buffer(obj);
commit.c +1 -1
index e315d5435b..68967e6c59 100644
@@ -50,7 +50,7 @@ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref
 
 struct commit *lookup_commit(const struct object_id *oid)
 {
-	struct object *obj = lookup_object(oid->hash);
+	struct object *obj = lookup_object(the_repository, oid->hash);
 	if (!obj)
 		return create_object(the_repository, oid->hash,
 				     alloc_commit_node());
contrib/coccinelle/object_parser.cocci +7 -0
index 2a554084d1..d57b0f16d4 100644
@@ -12,3 +12,10 @@ expression F;
  create_object(
 + the_repository,
  E, F)
+
+@@
+expression E;
+@@
+ lookup_object(
++the_repository,
+ E)
fetch-pack.c +4 -4
index 0f7aeabb64..02ac850967 100644
@@ -360,7 +360,7 @@ static int find_common(struct fetch_pack_args *args,
 		 * interested in the case we *know* the object is
 		 * reachable and we have already scanned it.
 		 */
-		if (((o = lookup_object(remote->hash)) != NULL) &&
+		if (((o = lookup_object(the_repository, remote->hash)) != NULL) &&
 				(o->flags & COMPLETE)) {
 			continue;
 		}
@@ -429,7 +429,7 @@ static int find_common(struct fetch_pack_args *args,
 			if (skip_prefix(line, "unshallow ", &arg)) {
 				if (get_oid_hex(arg, &oid))
 					die(_("invalid unshallow line: %s"), line);
-				if (!lookup_object(oid.hash))
+				if (!lookup_object(the_repository, oid.hash))
 					die(_("object not found: %s"), line);
 				/* make sure that it is parsed as shallow */
 				if (!parse_object(the_repository, &oid))
@@ -751,7 +751,7 @@ 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(ref->old_oid.hash),
+		struct object *o = deref_tag(lookup_object(the_repository, ref->old_oid.hash),
 					     NULL, 0);
 
 		if (!o || o->type != OBJ_COMMIT || !(o->flags & COMPLETE))
@@ -770,7 +770,7 @@ static int everything_local(struct fetch_pack_args *args,
 		const struct object_id *remote = &ref->old_oid;
 		struct object *o;
 
-		o = lookup_object(remote->hash);
+		o = lookup_object(the_repository, remote->hash);
 		if (!o || !(o->flags & COMPLETE)) {
 			retval = 0;
 			print_verbose(args, "want %s (%s)", oid_to_hex(remote),
http-push.c +1 -1
index b4c3cd1cd7..5149c1b425 100644
@@ -722,7 +722,7 @@ static void one_remote_object(const struct object_id *oid)
 {
 	struct object *obj;
 
-	obj = lookup_object(oid->hash);
+	obj = lookup_object(the_repository, oid->hash);
 	if (!obj)
 		obj = parse_object(the_repository, oid);
 
object.c +4 -4
index 1126c7e278..681fa40eb1 100644
@@ -81,7 +81,7 @@ 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(const unsigned char *sha1)
+struct object *lookup_object_the_repository(const unsigned char *sha1)
 {
 	unsigned int i, first;
 	struct object *obj;
@@ -175,7 +175,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 *obj = lookup_object(sha1);
+	struct object *obj = lookup_object(the_repository, sha1);
 	if (!obj)
 		obj = create_object(the_repository, sha1,
 				    alloc_object_node());
@@ -251,7 +251,7 @@ struct object *parse_object_the_repository(const struct object_id *oid)
 	void *buffer;
 	struct object *obj;
 
-	obj = lookup_object(oid->hash);
+	obj = lookup_object(the_repository, oid->hash);
 	if (obj && obj->parsed)
 		return obj;
 
@@ -263,7 +263,7 @@ struct object *parse_object_the_repository(const struct object_id *oid)
 			return NULL;
 		}
 		parse_blob_buffer(lookup_blob(oid), NULL, 0);
-		return lookup_object(oid->hash);
+		return lookup_object(the_repository, oid->hash);
 	}
 
 	buffer = read_sha1_file(oid->hash, &type, &size);
object.h +2 -1
index ac12dc3629..727a03ebd6 100644
@@ -98,7 +98,8 @@ extern struct object *get_indexed_object(unsigned int);
  * half-initialised objects, the caller is expected to initialize them
  * by calling parse_object() on them.
  */
-struct object *lookup_object(const unsigned char *sha1);
+#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);
reachable.c +2 -2
index 7e7b9525c0..4007c6428b 100644
@@ -109,7 +109,7 @@ static int add_recent_loose(const struct object_id *oid,
 			    const char *path, void *data)
 {
 	struct stat st;
-	struct object *obj = lookup_object(oid->hash);
+	struct object *obj = lookup_object(the_repository, oid->hash);
 
 	if (obj && obj->flags & SEEN)
 		return 0;
@@ -134,7 +134,7 @@ static int add_recent_packed(const struct object_id *oid,
 			     struct packed_git *p, uint32_t pos,
 			     void *data)
 {
-	struct object *obj = lookup_object(oid->hash);
+	struct object *obj = lookup_object(the_repository, oid->hash);
 
 	if (obj && obj->flags & SEEN)
 		return 0;
tag.c +1 -1
index a9e5af4294..3712ef7867 100644
@@ -94,7 +94,7 @@ struct object *deref_tag_noverify(struct object *o)
 
 struct tag *lookup_tag(const struct object_id *oid)
 {
-	struct object *obj = lookup_object(oid->hash);
+	struct object *obj = lookup_object(the_repository, oid->hash);
 	if (!obj)
 		return create_object(the_repository, oid->hash,
 				     alloc_tag_node());
tree.c +1 -1
index f8e1e6d63d..8f0ee6c8c0 100644
@@ -196,7 +196,7 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match,
 
 struct tree *lookup_tree(const struct object_id *oid)
 {
-	struct object *obj = lookup_object(oid->hash);
+	struct object *obj = lookup_object(the_repository, oid->hash);
 	if (!obj)
 		return create_object(the_repository, oid->hash,
 				     alloc_tree_node());
upload-pack.c +1 -1
index b076cbc5f7..8716e28d4f 100644
@@ -556,7 +556,7 @@ static int get_reachable_list(struct object_array *src,
 		if (namebuf[40] != '\n' || get_oid_hex(namebuf, &sha1))
 			break;
 
-		o = lookup_object(sha1.hash);
+		o = lookup_object(the_repository, sha1.hash);
 		if (o && o->type == OBJ_COMMIT) {
 			o->flags &= ~TMP_MARK;
 		}
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#115 lore raw

PATCH 83/194 object: add repository argument to grow_object_hash

In reply to Stefan Beller

From: Jonathan Nieder <[email protected]>

Add a repository argument to allow the caller of grow_object_hash 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.

---
 object.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
object.c +3 -2
index 681fa40eb1..225679188b 100644
@@ -115,7 +115,8 @@ 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.
  */
-static void grow_object_hash(void)
+#define grow_object_hash(r) grow_object_hash_##r()
+static void grow_object_hash_the_repository(void)
 {
 	int i;
 	/*
@@ -146,7 +147,7 @@ void *create_object_the_repository(const unsigned char *sha1, void *o)
 	hashcpy(obj->oid.hash, sha1);
 
 	if (the_repository->parsed_objects.obj_hash_size - 1 <= the_repository->parsed_objects.nr_objs * 2)
-		grow_object_hash();
+		grow_object_hash(the_repository);
 
 	insert_obj_hash(obj, the_repository->parsed_objects.obj_hash,
 			the_repository->parsed_objects.obj_hash_size);
Signature · 1 line
2.15.1.433.g936d1b9894.dirty
#116 lore raw

PATCH 84/194 blob: add repository argument to lookup_blob

In reply to Stefan Beller

Add a repository argument to allow the callers of lookup_blob 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.

---
 blob.c                                 | 2 +-
 blob.h                                 | 3 ++-
 builtin/describe.c                     | 2 +-
 builtin/fast-export.c                  | 2 +-
 builtin/fsck.c                         | 3 ++-
 builtin/index-pack.c                   | 2 +-
 builtin/merge-tree.c                   | 3 ++-
 builtin/unpack-objects.c               | 2 +-
 contrib/coccinelle/object_parser.cocci | 7 +++++++
 fsck.c                                 | 2 +-
 http-push.c                            | 3 ++-
 list-objects.c                         | 2 +-
 object.c                               | 4 ++--
 reachable.c                            | 2 +-
 revision.c                             | 4 ++--
 tag.c                                  | 2 +-
 walker.c                               | 3 ++-
 17 files changed, 30 insertions(+), 18 deletions(-)
blob.c +1 -1
index a9f3aa2ec8..25faf3e692 100644
@@ -4,7 +4,7 @@
 
 const char *blob_type = "blob";
 
-struct blob *lookup_blob(const struct object_id *oid)
+struct blob *lookup_blob_the_repository(const struct object_id *oid)
 {
 	struct object *obj = lookup_object(the_repository, oid->hash);
 	if (!obj)
blob.h +2 -1
index 4460616831..08bc34487a 100644
@@ -9,7 +9,8 @@ struct blob {
 	struct object object;
 };
 
-struct blob *lookup_blob(const struct object_id *oid);
+#define lookup_blob(r, o) lookup_blob_##r(o)
+struct blob *lookup_blob_the_repository(const struct object_id *oid);
 
 int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size);
 
builtin/describe.c +1 -1
index 3b0b204b1e..2add1e8d83 100644
@@ -499,7 +499,7 @@ static void describe(const char *arg, int last_one)
 
 	if (cmit)
 		describe_commit(&oid, &sb);
-	else if (lookup_blob(&oid))
+	else if (lookup_blob(the_repository, &oid))
 		describe_blob(oid, &sb);
 	else
 		die(_("%s is neither a commit nor blob"), arg);
builtin/fast-export.c +1 -1
index 642bafdd30..14a27d539f 100644
@@ -236,7 +236,7 @@ static void export_blob(const struct object_id *oid)
 
 	if (anonymize) {
 		buf = anonymize_blob(&size);
-		object = (struct object *)lookup_blob(oid);
+		object = (struct object *)lookup_blob(the_repository, oid);
 		eaten = 0;
 	} else {
 		buf = read_sha1_file(oid->hash, &type, &size);
builtin/fsck.c +2 -1
index 7645418821..79da01d338 100644
@@ -778,7 +778,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
 			mode = active_cache[i]->ce_mode;
 			if (S_ISGITLINK(mode))
 				continue;
-			blob = lookup_blob(&active_cache[i]->oid);
+			blob = lookup_blob(the_repository,
+					   &active_cache[i]->oid);
 			if (!blob)
 				continue;
 			obj = &blob->object;
builtin/index-pack.c +1 -1
index b9851ad69d..67db12fc43 100644
@@ -834,7 +834,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
 	if (strict) {
 		read_lock();
 		if (type == OBJ_BLOB) {
-			struct blob *blob = lookup_blob(oid);
+			struct blob *blob = lookup_blob(the_repository, oid);
 			if (blob)
 				blob->object.flags |= FLAG_CHECKED;
 			else
builtin/merge-tree.c +2 -1
index ba51ad55a8..41f1ae30cc 100644
@@ -2,6 +2,7 @@
 #include "tree-walk.h"
 #include "xdiff-interface.h"
 #include "object-store.h"
+#include "repository.h"
 #include "blob.h"
 #include "exec_cmd.h"
 #include "merge-blobs.h"
@@ -169,7 +170,7 @@ static struct merge_list *create_entry(unsigned stage, unsigned mode, const stru
 	res->stage = stage;
 	res->path = path;
 	res->mode = mode;
-	res->blob = lookup_blob(oid);
+	res->blob = lookup_blob(the_repository, oid);
 	return res;
 }
 
builtin/unpack-objects.c +1 -1
index e26f673a15..8d13c5145c 100644
@@ -252,7 +252,7 @@ static void write_object(unsigned nr, enum object_type type,
 		added_object(nr, type, buf, size);
 		free(buf);
 
-		blob = lookup_blob(&obj_list[nr].oid);
+		blob = lookup_blob(the_repository, &obj_list[nr].oid);
 		if (blob)
 			blob->object.flags |= FLAG_WRITTEN;
 		else
contrib/coccinelle/object_parser.cocci +7 -0
index d57b0f16d4..3bc38d2faa 100644
@@ -1,3 +1,10 @@
+@@
+expression E;
+@@
+ lookup_blob(
++the_repository,
+ E)
+
 @@
 expression E;
 @@
fsck.c +1 -1
index 843ddc1035..6d04981735 100644
@@ -367,7 +367,7 @@ static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *op
 			result = options->walk(obj, OBJ_TREE, data, options);
 		}
 		else if (S_ISREG(entry.mode) || S_ISLNK(entry.mode)) {
-			obj = (struct object *)lookup_blob(entry.oid);
+			obj = (struct object *)lookup_blob(the_repository, entry.oid);
 			if (name && obj)
 				put_object_name(options, obj, "%s%s", name,
 					entry.path);
http-push.c +2 -1
index 5149c1b425..6c60b12ad1 100644
@@ -1310,7 +1310,8 @@ static struct object_list **process_tree(struct tree *tree,
 			p = process_tree(lookup_tree(entry.oid), p);
 			break;
 		case OBJ_BLOB:
-			p = process_blob(lookup_blob(entry.oid), p);
+			p = process_blob(lookup_blob(the_repository, entry.oid),
+					 p);
 			break;
 		default:
 			/* Subproject commit - not in this repository */
list-objects.c +1 -1
index 0966cdc9fa..c11dc1281b 100644
@@ -139,7 +139,7 @@ static void process_tree(struct rev_info *revs,
 					cb_data);
 		else
 			process_blob(revs,
-				     lookup_blob(entry.oid),
+				     lookup_blob(the_repository, entry.oid),
 				     show, base, entry.path,
 				     cb_data, filter_fn, filter_data);
 	}
object.c +2 -2
index 225679188b..e0dac087c8 100644
@@ -190,7 +190,7 @@ struct object *parse_object_buffer(const struct object_id *oid, enum object_type
 
 	obj = NULL;
 	if (type == OBJ_BLOB) {
-		struct blob *blob = lookup_blob(oid);
+		struct blob *blob = lookup_blob(the_repository, oid);
 		if (blob) {
 			if (parse_blob_buffer(blob, buffer, size))
 				return NULL;
@@ -263,7 +263,7 @@ struct object *parse_object_the_repository(const struct object_id *oid)
 			error("sha1 mismatch %s", oid_to_hex(oid));
 			return NULL;
 		}
-		parse_blob_buffer(lookup_blob(oid), NULL, 0);
+		parse_blob_buffer(lookup_blob(the_repository, oid), NULL, 0);
 		return lookup_object(the_repository, oid->hash);
 	}
 
reachable.c +1 -1
index 4007c6428b..943e4518c2 100644
@@ -92,7 +92,7 @@ static void add_recent_object(const struct object_id *oid,
 		obj = (struct object *)lookup_tree(oid);
 		break;
 	case OBJ_BLOB:
-		obj = (struct object *)lookup_blob(oid);
+		obj = (struct object *)lookup_blob(the_repository, oid);
 		break;
 	default:
 		die("unknown object type for %s: %s",
revision.c +2 -2
index 5ccfc50447..a7b57e3452 100644
@@ -67,7 +67,7 @@ static void mark_tree_contents_uninteresting(struct tree *tree)
 			mark_tree_uninteresting(lookup_tree(entry.oid));
 			break;
 		case OBJ_BLOB:
-			mark_blob_uninteresting(lookup_blob(entry.oid));
+			mark_blob_uninteresting(lookup_blob(the_repository, entry.oid));
 			break;
 		default:
 			/* Subproject commit - not in this repository */
@@ -1321,7 +1321,7 @@ static void do_add_index_objects_to_pending(struct rev_info *revs,
 		if (S_ISGITLINK(ce->ce_mode))
 			continue;
 
-		blob = lookup_blob(&ce->oid);
+		blob = lookup_blob(the_repository, &ce->oid);
 		if (!blob)
 			die("unable to add index blob to traversal");
 		add_pending_object_with_path(revs, &blob->object, "",
tag.c +1 -1
index 3712ef7867..4cf449303b 100644
@@ -146,7 +146,7 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
 	bufptr = nl + 1;
 
 	if (!strcmp(type, blob_type)) {
-		item->tagged = (struct object *)lookup_blob(&oid);
+		item->tagged = (struct object *)lookup_blob(the_repository, &oid);
 	} else if (!strcmp(type, tree_type)) {
 		item->tagged = (struct object *)lookup_tree(&oid);
 	} else if (!strcmp(type, commit_type)) {
walker.c +2 -1
index 492aea906f..f5a221d48e 100644
@@ -54,7 +54,8 @@ static int process_tree(struct walker *walker, struct tree *tree)
 				obj = &tree->object;
 		}
 		else {
-			struct blob *blob = lookup_blob(entry.oid);
+			struct blob *blob = lookup_blob(the_repository,
+							entry.oid);
 			if (blob)
 				obj = &blob->object;
 		}
Signature · 1 line
2.15.1.433.g936d1b9894.dirty