git@vger.kernel.org mailing list mirror (one of many)
 help / Atom feed
* [RFC PATCH 000/194] Moving global state into the repository object
@ 2018-02-05 23:51 Stefan Beller
  2018-02-05 23:51 ` [PATCH 001/194] repository: introduce object store field Stefan Beller
                   ` (28 more replies)
  0 siblings, 29 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:51 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller

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

-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 001/194] repository: introduce object store field
  2018-02-05 23:51 [RFC PATCH 000/194] Moving global state into the repository object Stefan Beller
@ 2018-02-05 23:51 ` Stefan Beller
  2018-02-05 23:51 ` [PATCH 002/194] object-store: move alt_odb_list and alt_odb_tail to object store Stefan Beller
                   ` (27 subsequent siblings)
  28 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:51 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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).

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 object-store.h | 8 ++++++++
 repository.c   | 4 +++-
 repository.h   | 7 +++++++
 3 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100644 object-store.h

diff --git a/object-store.h b/object-store.h
new file mode 100644
index 0000000000..05722cdde0
--- /dev/null
+++ b/object-store.h
@@ -0,0 +1,8 @@
+#ifndef OBJECT_STORE_H
+#define OBJECT_STORE_H
+
+struct object_store {
+};
+#define OBJECT_STORE_INIT {}
+
+#endif /* OBJECT_STORE_H */
diff --git a/repository.c b/repository.c
index 998413b8bb..0ec9648f53 100644
--- a/repository.c
+++ b/repository.c
@@ -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;
 
diff --git a/repository.h b/repository.h
index 0329e40c7f..ba7b3b7cb9 100644
--- a/repository.h
+++ b/repository.h
@@ -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.
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 002/194] object-store: move alt_odb_list and alt_odb_tail to object store
  2018-02-05 23:51 [RFC PATCH 000/194] Moving global state into the repository object Stefan Beller
  2018-02-05 23:51 ` [PATCH 001/194] repository: introduce object store field Stefan Beller
@ 2018-02-05 23:51 ` Stefan Beller
  2018-02-05 23:51 ` [PATCH 003/194] object-store: move packed_git and packed_git_mru " Stefan Beller
                   ` (26 subsequent siblings)
  28 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:51 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 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(-)

diff --git a/builtin/fsck.c b/builtin/fsck.c
index 04846d46f9..1048255da1 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -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) {
diff --git a/cache.h b/cache.h
index d8b975a571..918c2f15b4 100644
--- a/cache.h
+++ b/cache.h
@@ -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 *);
diff --git a/object-store.h b/object-store.h
index 05722cdde0..ace3efbfab 100644
--- a/object-store.h
+++ b/object-store.h
@@ -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 */
diff --git a/packfile.c b/packfile.c
index 4a5fe7ab18..d61076faaf 100644
--- a/packfile.c
+++ b/packfile.c
@@ -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();
diff --git a/sha1_file.c b/sha1_file.c
index 3da70ac650..2826d5d6ed 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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)
diff --git a/sha1_name.c b/sha1_name.c
index 611c7d24dd..957ce25680 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -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;
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 003/194] object-store: move packed_git and packed_git_mru to object store
  2018-02-05 23:51 [RFC PATCH 000/194] Moving global state into the repository object Stefan Beller
  2018-02-05 23:51 ` [PATCH 001/194] repository: introduce object store field Stefan Beller
  2018-02-05 23:51 ` [PATCH 002/194] object-store: move alt_odb_list and alt_odb_tail to object store Stefan Beller
@ 2018-02-05 23:51 ` " Stefan Beller
  2018-02-09 22:09   ` Junio C Hamano
  2018-02-05 23:51 ` [PATCH 004/194] pack: move prepare_packed_git_run_once " Stefan Beller
                   ` (25 subsequent siblings)
  28 siblings, 1 reply; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:51 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 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

diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index 33343818c8..9334648dcc 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -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))
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 1048255da1..d4d249c2ed 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -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))
diff --git a/builtin/gc.c b/builtin/gc.c
index 3c5eae0edf..6970f325e5 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -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)
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 4c51aec81f..1902d4e096 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -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[] =
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 6b9cfc289d..2ee8b69238 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -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;
diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c
index aaa8136322..55462bc826 100644
--- a/builtin/pack-redundant.c
+++ b/builtin/pack-redundant.c
@@ -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);
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index b7ce7c7f52..b2eac79a6e 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -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"
diff --git a/cache.h b/cache.h
index 918c2f15b4..459fd01dbb 100644
--- a/cache.h
+++ b/cache.h
@@ -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];
diff --git a/contrib/coccinelle/packed_git.cocci b/contrib/coccinelle/packed_git.cocci
new file mode 100644
index 0000000000..da317a51a9
--- /dev/null
+++ b/contrib/coccinelle/packed_git.cocci
@@ -0,0 +1,7 @@
+@@ @@
+- packed_git
++ the_repository->objects.packed_git
+
+@@ @@
+- packed_git_mru
++ the_repository->objects.packed_git_mru
diff --git a/fast-import.c b/fast-import.c
index b70ac025e0..1685fe59a2 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -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! */
diff --git a/http-backend.c b/http-backend.c
index f3dc218b2a..4d93126c15 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -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);
 	}
diff --git a/http-push.c b/http-push.c
index 14435ab65d..34c5d030b7 100644
--- a/http-push.c
+++ b/http-push.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "object-store.h"
 #include "commit.h"
 #include "tag.h"
 #include "blob.h"
diff --git a/http-walker.c b/http-walker.c
index 1ae8363de2..a1c6f2639b 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -4,6 +4,7 @@
 #include "http.h"
 #include "list.h"
 #include "transport.h"
+#include "object-store.h"
 #include "packfile.h"
 
 struct alt_base {
diff --git a/http.c b/http.c
index 5977712712..ab989b88dd 100644
--- a/http.c
+++ b/http.c
@@ -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"
diff --git a/mru.h b/mru.h
index 42e4aeaa10..d7de81efb9 100644
--- a/mru.h
+++ b/mru.h
@@ -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);
diff --git a/object-store.h b/object-store.h
index ace3efbfab..e2a59a0611 100644
--- a/object-store.h
+++ b/object-store.h
@@ -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 */
diff --git a/pack-bitmap.c b/pack-bitmap.c
index 9270983e5f..d51172b1d5 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -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;
 	}
diff --git a/pack-check.c b/pack-check.c
index 073c1fbd46..c80c3ed8fd 100644
--- a/pack-check.c
+++ b/pack-check.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "pack.h"
+#include "object-store.h"
 #include "pack-revindex.h"
 #include "progress.h"
 #include "packfile.h"
diff --git a/pack-revindex.c b/pack-revindex.c
index 1b7ebd8d7e..82c3119652 100644
--- a/pack-revindex.c
+++ b/pack-revindex.c
@@ -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
diff --git a/packfile.c b/packfile.c
index d61076faaf..11b0e6613c 100644
--- a/packfile.c
+++ b/packfile.c
@@ -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)) {
diff --git a/reachable.c b/reachable.c
index 88d7d679da..59ed16ba76 100644
--- a/reachable.c
+++ b/reachable.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "refs.h"
+#include "object-store.h"
 #include "tag.h"
 #include "commit.h"
 #include "blob.h"
diff --git a/server-info.c b/server-info.c
index 26a6c20b7d..96885c45f6 100644
--- a/server-info.c
+++ b/server-info.c
@@ -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));
diff --git a/sha1_name.c b/sha1_name.c
index 957ce25680..016c883b5c 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -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);
 }
 
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 004/194] pack: move prepare_packed_git_run_once to object store
  2018-02-05 23:51 [RFC PATCH 000/194] Moving global state into the repository object Stefan Beller
                   ` (2 preceding siblings ...)
  2018-02-05 23:51 ` [PATCH 003/194] object-store: move packed_git and packed_git_mru " Stefan Beller
@ 2018-02-05 23:51 ` " Stefan Beller
  2018-02-05 23:51 ` [PATCH 005/194] pack: move approximate object count " Stefan Beller
                   ` (24 subsequent siblings)
  28 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:51 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 object-store.h | 8 +++++++-
 packfile.c     | 7 +++----
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/object-store.h b/object-store.h
index e2a59a0611..14129fbba1 100644
--- a/object-store.h
+++ b/object-store.h
@@ -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;
diff --git a/packfile.c b/packfile.c
index 11b0e6613c..177aa219f9 100644
--- a/packfile.c
+++ b/packfile.c
@@ -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();
 }
 
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 005/194] pack: move approximate object count to object store
  2018-02-05 23:51 [RFC PATCH 000/194] Moving global state into the repository object Stefan Beller
                   ` (3 preceding siblings ...)
  2018-02-05 23:51 ` [PATCH 004/194] pack: move prepare_packed_git_run_once " Stefan Beller
@ 2018-02-05 23:51 ` " Stefan Beller
  2018-02-05 23:52 ` [PATCH 006/194] sha1_file: add repository argument to alt_odb_usable Stefan Beller
                   ` (23 subsequent siblings)
  28 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:51 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 object-store.h | 10 +++++++++-
 packfile.c     | 11 +++++------
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/object-store.h b/object-store.h
index 14129fbba1..99f77d10cd 100644
--- a/object-store.h
+++ b/object-store.h
@@ -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;
diff --git a/packfile.c b/packfile.c
index 177aa219f9..31c4ea54ae 100644
--- a/packfile.c
+++ b/packfile.c
@@ -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();
 }
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 006/194] sha1_file: add repository argument to alt_odb_usable
  2018-02-05 23:51 [RFC PATCH 000/194] Moving global state into the repository object Stefan Beller
                   ` (4 preceding siblings ...)
  2018-02-05 23:51 ` [PATCH 005/194] pack: move approximate object count " Stefan Beller
@ 2018-02-05 23:52 ` Stefan Beller
  2018-02-05 23:52 ` [PATCH 007/194] sha1_file: add repository argument to link_alt_odb_entry Stefan Beller
                   ` (22 subsequent siblings)
  28 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:52 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 sha1_file.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/sha1_file.c b/sha1_file.c
index 2826d5d6ed..ca002a272d 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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;
 	}
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 007/194] sha1_file: add repository argument to link_alt_odb_entry
  2018-02-05 23:51 [RFC PATCH 000/194] Moving global state into the repository object Stefan Beller
                   ` (5 preceding siblings ...)
  2018-02-05 23:52 ` [PATCH 006/194] sha1_file: add repository argument to alt_odb_usable Stefan Beller
@ 2018-02-05 23:52 ` Stefan Beller
  2018-02-05 23:52 ` [PATCH 008/194] sha1_file: add repository argument to read_info_alternates Stefan Beller
                   ` (21 subsequent siblings)
  28 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:52 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 sha1_file.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/sha1_file.c b/sha1_file.c
index ca002a272d..1e17246f5c 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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);
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 008/194] sha1_file: add repository argument to read_info_alternates
  2018-02-05 23:51 [RFC PATCH 000/194] Moving global state into the repository object Stefan Beller
                   ` (6 preceding siblings ...)
  2018-02-05 23:52 ` [PATCH 007/194] sha1_file: add repository argument to link_alt_odb_entry Stefan Beller
@ 2018-02-05 23:52 ` Stefan Beller
  2018-02-05 23:52 ` [PATCH 009/194] sha1_file: add repository argument to link_alt_odb_entries Stefan Beller
                   ` (20 subsequent siblings)
  28 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:52 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 sha1_file.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/sha1_file.c b/sha1_file.c
index 1e17246f5c..acb00b9680 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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. */
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 009/194] sha1_file: add repository argument to link_alt_odb_entries
  2018-02-05 23:51 [RFC PATCH 000/194] Moving global state into the repository object Stefan Beller
                   ` (7 preceding siblings ...)
  2018-02-05 23:52 ` [PATCH 008/194] sha1_file: add repository argument to read_info_alternates Stefan Beller
@ 2018-02-05 23:52 ` Stefan Beller
  2018-02-05 23:52 ` [PATCH 010/194] sha1_file: add repository argument to stat_sha1_file Stefan Beller
                   ` (19 subsequent siblings)
  28 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:52 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 sha1_file.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/sha1_file.c b/sha1_file.c
index acb00b9680..d9f9046f31 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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);
 }
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 010/194] sha1_file: add repository argument to stat_sha1_file
  2018-02-05 23:51 [RFC PATCH 000/194] Moving global state into the repository object Stefan Beller
                   ` (8 preceding siblings ...)
  2018-02-05 23:52 ` [PATCH 009/194] sha1_file: add repository argument to link_alt_odb_entries Stefan Beller
@ 2018-02-05 23:52 ` Stefan Beller
  2018-02-05 23:52 ` [PATCH 011/194] sha1_file: add repository argument to open_sha1_file Stefan Beller
                   ` (18 subsequent siblings)
  28 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:52 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 sha1_file.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/sha1_file.c b/sha1_file.c
index d9f9046f31..6abdb8c488 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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);
 
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 011/194] sha1_file: add repository argument to open_sha1_file
  2018-02-05 23:51 [RFC PATCH 000/194] Moving global state into the repository object Stefan Beller
                   ` (9 preceding siblings ...)
  2018-02-05 23:52 ` [PATCH 010/194] sha1_file: add repository argument to stat_sha1_file Stefan Beller
@ 2018-02-05 23:52 ` Stefan Beller
  2018-02-05 23:52 ` [PATCH 012/194] sha1_file: add repository argument to map_sha1_file_1 Stefan Beller
                   ` (17 subsequent siblings)
  28 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:52 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 sha1_file.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/sha1_file.c b/sha1_file.c
index 6abdb8c488..9fa7243907 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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;
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 012/194] sha1_file: add repository argument to map_sha1_file_1
  2018-02-05 23:51 [RFC PATCH 000/194] Moving global state into the repository object Stefan Beller
                   ` (10 preceding siblings ...)
  2018-02-05 23:52 ` [PATCH 011/194] sha1_file: add repository argument to open_sha1_file Stefan Beller
@ 2018-02-05 23:52 ` Stefan Beller
  2018-02-05 23:52 ` [PATCH 013/194] sha1_file: add repository argument to sha1_loose_object_info Stefan Beller
                   ` (16 subsequent siblings)
  28 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:52 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 sha1_file.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/sha1_file.c b/sha1_file.c
index 9fa7243907..24832c4b32 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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;
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 013/194] sha1_file: add repository argument to sha1_loose_object_info
  2018-02-05 23:51 [RFC PATCH 000/194] Moving global state into the repository object Stefan Beller
                   ` (11 preceding siblings ...)
  2018-02-05 23:52 ` [PATCH 012/194] sha1_file: add repository argument to map_sha1_file_1 Stefan Beller
@ 2018-02-05 23:52 ` Stefan Beller
  2018-02-05 23:52 ` [PATCH 014/194] object-store: add repository argument to prepare_alt_odb Stefan Beller
                   ` (15 subsequent siblings)
  28 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:52 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 sha1_file.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/sha1_file.c b/sha1_file.c
index 24832c4b32..514f59c390 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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. */
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 014/194] object-store: add repository argument to prepare_alt_odb
  2018-02-05 23:51 [RFC PATCH 000/194] Moving global state into the repository object Stefan Beller
                   ` (12 preceding siblings ...)
  2018-02-05 23:52 ` [PATCH 013/194] sha1_file: add repository argument to sha1_loose_object_info Stefan Beller
@ 2018-02-05 23:52 ` Stefan Beller
  2018-02-05 23:52 ` [PATCH 015/194] object-store: add repository argument to foreach_alt_odb Stefan Beller
                   ` (14 subsequent siblings)
  28 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:52 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 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(-)

diff --git a/builtin/fsck.c b/builtin/fsck.c
index d4d249c2ed..00ec8eecf0 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -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);
diff --git a/cache.h b/cache.h
index 459fd01dbb..70518e24ce 100644
--- a/cache.h
+++ b/cache.h
@@ -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*);
diff --git a/object-store.h b/object-store.h
index 99f77d10cd..e749c952d5 100644
--- a/object-store.h
+++ b/object-store.h
@@ -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 */
diff --git a/packfile.c b/packfile.c
index 31c4ea54ae..fbb2385bad 100644
--- a/packfile.c
+++ b/packfile.c
@@ -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();
diff --git a/sha1_file.c b/sha1_file.c
index 514f59c390..779bfd4079 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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);
diff --git a/sha1_name.c b/sha1_name.c
index 016c883b5c..3e490ee8f6 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -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;
 }
 
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 015/194] object-store: add repository argument to foreach_alt_odb
  2018-02-05 23:51 [RFC PATCH 000/194] Moving global state into the repository object Stefan Beller
                   ` (13 preceding siblings ...)
  2018-02-05 23:52 ` [PATCH 014/194] object-store: add repository argument to prepare_alt_odb Stefan Beller
@ 2018-02-05 23:52 ` Stefan Beller
  2018-02-05 23:52 ` [PATCH 016/194] pack: add repository argument to install_packed_git Stefan Beller
                   ` (13 subsequent siblings)
  28 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:52 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 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(-)

diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index 9334648dcc..843a7d7d7e 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -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);
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index a5c4a8a694..8005adbf3d 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -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
diff --git a/cache.h b/cache.h
index 70518e24ce..bba53f356d 100644
--- a/cache.h
+++ b/cache.h
@@ -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
diff --git a/object-store.h b/object-store.h
index e749c952d5..eef8d3b653 100644
--- a/object-store.h
+++ b/object-store.h
@@ -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 */
diff --git a/sha1_file.c b/sha1_file.c
index 779bfd4079..7662692ee5 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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,
diff --git a/transport.c b/transport.c
index fc802260f6..3f97fbe7c5 100644
--- a/transport.c
+++ b/transport.c
@@ -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);
 }
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 016/194] pack: add repository argument to install_packed_git
  2018-02-05 23:51 [RFC PATCH 000/194] Moving global state into the repository object Stefan Beller
                   ` (14 preceding siblings ...)
  2018-02-05 23:52 ` [PATCH 015/194] object-store: add repository argument to foreach_alt_odb Stefan Beller
@ 2018-02-05 23:52 ` Stefan Beller
  2018-02-05 23:52 ` [PATCH 017/194] pack: add repository argument to prepare_packed_git_one Stefan Beller
                   ` (12 subsequent siblings)
  28 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:52 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 fast-import.c | 2 +-
 http.c        | 3 ++-
 packfile.c    | 4 ++--
 packfile.h    | 3 ++-
 4 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/fast-import.c b/fast-import.c
index 1685fe59a2..67550584da 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -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 */
diff --git a/http.c b/http.c
index ab989b88dd..979d9b3e46 100644
--- a/http.c
+++ b/http.c
@@ -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;
 }
diff --git a/packfile.c b/packfile.c
index fbb2385bad..0f63ec79c8 100644
--- a/packfile.c
+++ b/packfile.c
@@ -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)
diff --git a/packfile.h b/packfile.h
index 0cdeb54dcd..7e6959d440 100644
--- a/packfile.h
+++ b/packfile.h
@@ -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
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 017/194] pack: add repository argument to prepare_packed_git_one
  2018-02-05 23:51 [RFC PATCH 000/194] Moving global state into the repository object Stefan Beller
                   ` (15 preceding siblings ...)
  2018-02-05 23:52 ` [PATCH 016/194] pack: add repository argument to install_packed_git Stefan Beller
@ 2018-02-05 23:52 ` Stefan Beller
  2018-02-05 23:52 ` [PATCH 018/194] pack: add repository argument to rearrange_packed_git Stefan Beller
                   ` (11 subsequent siblings)
  28 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:52 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 packfile.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/packfile.c b/packfile.c
index 0f63ec79c8..58473660cd 100644
--- a/packfile.c
+++ b/packfile.c
@@ -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;
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 018/194] pack: add repository argument to rearrange_packed_git
  2018-02-05 23:51 [RFC PATCH 000/194] Moving global state into the repository object Stefan Beller
                   ` (16 preceding siblings ...)
  2018-02-05 23:52 ` [PATCH 017/194] pack: add repository argument to prepare_packed_git_one Stefan Beller
@ 2018-02-05 23:52 ` Stefan Beller
  2018-02-05 23:52 ` [PATCH 019/194] pack: add repository argument to prepare_packed_git_mru Stefan Beller
                   ` (10 subsequent siblings)
  28 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:52 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 packfile.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/packfile.c b/packfile.c
index 58473660cd..52cf9182c4 100644
--- a/packfile.c
+++ b/packfile.c
@@ -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;
 }
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 019/194] pack: add repository argument to prepare_packed_git_mru
  2018-02-05 23:51 [RFC PATCH 000/194] Moving global state into the repository object Stefan Beller
                   ` (17 preceding siblings ...)
  2018-02-05 23:52 ` [PATCH 018/194] pack: add repository argument to rearrange_packed_git Stefan Beller
@ 2018-02-05 23:52 ` Stefan Beller
  2018-02-05 23:52 ` [PATCH 020/194] pack: add repository argument to prepare_packed_git Stefan Beller
                   ` (9 subsequent siblings)
  28 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:52 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 packfile.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/packfile.c b/packfile.c
index 52cf9182c4..b4ace96f0c 100644
--- a/packfile.c
+++ b/packfile.c
@@ -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;
 }
 
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 020/194] pack: add repository argument to prepare_packed_git
  2018-02-05 23:51 [RFC PATCH 000/194] Moving global state into the repository object Stefan Beller
                   ` (18 preceding siblings ...)
  2018-02-05 23:52 ` [PATCH 019/194] pack: add repository argument to prepare_packed_git_mru Stefan Beller
@ 2018-02-05 23:52 ` Stefan Beller
  2018-02-05 23:52 ` [PATCH 021/194] pack: add repository argument to reprepare_packed_git Stefan Beller
                   ` (8 subsequent siblings)
  28 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:52 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 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(-)

diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index 843a7d7d7e..e340b3e3c3 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -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;
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 00ec8eecf0..0e78f4ba72 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -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;
diff --git a/builtin/gc.c b/builtin/gc.c
index 6970f325e5..00a3b402a8 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -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;
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 2ee8b69238..d42df2a2b9 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -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)
diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c
index 55462bc826..83d2395dae 100644
--- a/builtin/pack-redundant.c
+++ b/builtin/pack-redundant.c
@@ -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();
diff --git a/contrib/coccinelle/packed_git.cocci b/contrib/coccinelle/packed_git.cocci
index da317a51a9..7554f4773c 100644
--- a/contrib/coccinelle/packed_git.cocci
+++ b/contrib/coccinelle/packed_git.cocci
@@ -5,3 +5,7 @@
 @@ @@
 - packed_git_mru
 + the_repository->objects.packed_git_mru
+
+@@ @@
+- prepare_packed_git()
++ prepare_packed_git(the_repository)
diff --git a/fast-import.c b/fast-import.c
index 67550584da..39cd0b7540 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -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();
diff --git a/http-backend.c b/http-backend.c
index 4d93126c15..4950078c93 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -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++;
diff --git a/pack-bitmap.c b/pack-bitmap.c
index d51172b1d5..273bdfb631 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -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;
diff --git a/packfile.c b/packfile.c
index b4ace96f0c..bf7e6d22ce 100644
--- a/packfile.c
+++ b/packfile.c
@@ -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;
diff --git a/packfile.h b/packfile.h
index 7e6959d440..e543a98b23 100644
--- a/packfile.h
+++ b/packfile.h
@@ -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);
diff --git a/server-info.c b/server-info.c
index 96885c45f6..6cd1506e5e 100644
--- a/server-info.c
+++ b/server-info.c
@@ -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.
diff --git a/sha1_name.c b/sha1_name.c
index 3e490ee8f6..d3769713ea 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -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);
 }
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 021/194] pack: add repository argument to reprepare_packed_git
  2018-02-05 23:51 [RFC PATCH 000/194] Moving global state into the repository object Stefan Beller
                   ` (19 preceding siblings ...)
  2018-02-05 23:52 ` [PATCH 020/194] pack: add repository argument to prepare_packed_git Stefan Beller
@ 2018-02-05 23:52 ` Stefan Beller
  2018-02-05 23:54 ` Stefan Beller
                   ` (7 subsequent siblings)
  28 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:52 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 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(-)

diff --git a/builtin/gc.c b/builtin/gc.c
index 00a3b402a8..a3a4d4d4f3 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -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();
 
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index b2eac79a6e..744fe29366 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -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;
 }
diff --git a/bulk-checkin.c b/bulk-checkin.c
index 3310fd210a..eadc2d5172 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -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[])
diff --git a/contrib/coccinelle/packed_git.cocci b/contrib/coccinelle/packed_git.cocci
index 7554f4773c..0cb0e95f82 100644
--- a/contrib/coccinelle/packed_git.cocci
+++ b/contrib/coccinelle/packed_git.cocci
@@ -9,3 +9,7 @@
 @@ @@
 - prepare_packed_git()
 + prepare_packed_git(the_repository)
+
+@@ @@
+- reprepare_packed_git()
++ reprepare_packed_git(the_repository)
diff --git a/fetch-pack.c b/fetch-pack.c
index 9f6b07ad91..9c189ff3ec 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -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;
diff --git a/packfile.c b/packfile.c
index bf7e6d22ce..6a1c8107ed 100644
--- a/packfile.c
+++ b/packfile.c
@@ -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;
diff --git a/packfile.h b/packfile.h
index e543a98b23..74f293c439 100644
--- a/packfile.h
+++ b/packfile.h
@@ -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);
 
diff --git a/sha1_file.c b/sha1_file.c
index 7662692ee5..f6e982880e 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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;
 		}
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 021/194] pack: add repository argument to reprepare_packed_git
  2018-02-05 23:51 [RFC PATCH 000/194] Moving global state into the repository object Stefan Beller
                   ` (20 preceding siblings ...)
  2018-02-05 23:52 ` [PATCH 021/194] pack: add repository argument to reprepare_packed_git Stefan Beller
@ 2018-02-05 23:54 ` Stefan Beller
  2018-02-05 23:54   ` [PATCH 022/194] pack: add repository argument to sha1_file_name Stefan Beller
                     ` (76 more replies)
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                   ` (6 subsequent siblings)
  28 siblings, 77 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:54 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 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(-)

diff --git a/builtin/gc.c b/builtin/gc.c
index 00a3b402a8..a3a4d4d4f3 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -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();
 
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index b2eac79a6e..744fe29366 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -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;
 }
diff --git a/bulk-checkin.c b/bulk-checkin.c
index 3310fd210a..eadc2d5172 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -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[])
diff --git a/contrib/coccinelle/packed_git.cocci b/contrib/coccinelle/packed_git.cocci
index 7554f4773c..0cb0e95f82 100644
--- a/contrib/coccinelle/packed_git.cocci
+++ b/contrib/coccinelle/packed_git.cocci
@@ -9,3 +9,7 @@
 @@ @@
 - prepare_packed_git()
 + prepare_packed_git(the_repository)
+
+@@ @@
+- reprepare_packed_git()
++ reprepare_packed_git(the_repository)
diff --git a/fetch-pack.c b/fetch-pack.c
index 9f6b07ad91..9c189ff3ec 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -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;
diff --git a/packfile.c b/packfile.c
index bf7e6d22ce..6a1c8107ed 100644
--- a/packfile.c
+++ b/packfile.c
@@ -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;
diff --git a/packfile.h b/packfile.h
index e543a98b23..74f293c439 100644
--- a/packfile.h
+++ b/packfile.h
@@ -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);
 
diff --git a/sha1_file.c b/sha1_file.c
index 7662692ee5..f6e982880e 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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;
 		}
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 022/194] pack: add repository argument to sha1_file_name
  2018-02-05 23:54 ` Stefan Beller
@ 2018-02-05 23:54   ` Stefan Beller
  2018-02-05 23:54   ` [PATCH 023/194] pack: add repository argument to map_sha1_file Stefan Beller
                     ` (75 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:54 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 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(-)

diff --git a/cache.h b/cache.h
index bba53f356d..63ed5ccf0a 100644
--- a/cache.h
+++ b/cache.h
@@ -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
diff --git a/http-walker.c b/http-walker.c
index a1c6f2639b..96873bdfed 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -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);
diff --git a/http.c b/http.c
index 979d9b3e46..ad57476635 100644
--- a/http.c
+++ b/http.c
@@ -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;
 }
diff --git a/object-store.h b/object-store.h
index eef8d3b653..228c2ce8ae 100644
--- a/object-store.h
+++ b/object-store.h
@@ -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);
 
diff --git a/sha1_file.c b/sha1_file.c
index f6e982880e..caad178b14 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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) {
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 023/194] pack: add repository argument to map_sha1_file
  2018-02-05 23:54 ` Stefan Beller
  2018-02-05 23:54   ` [PATCH 022/194] pack: add repository argument to sha1_file_name Stefan Beller
@ 2018-02-05 23:54   ` Stefan Beller
  2018-02-05 23:54   ` [PATCH 024/194] sha1_file: allow alt_odb_usable to handle arbitrary repositories Stefan Beller
                     ` (74 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:54 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 cache.h        | 1 -
 object-store.h | 2 ++
 sha1_file.c    | 4 ++--
 streaming.c    | 5 ++++-
 4 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/cache.h b/cache.h
index 63ed5ccf0a..051a77c49a 100644
--- a/cache.h
+++ b/cache.h
@@ -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);
 
diff --git a/object-store.h b/object-store.h
index 228c2ce8ae..92fbf4a9ca 100644
--- a/object-store.h
+++ b/object-store.h
@@ -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);
diff --git a/sha1_file.c b/sha1_file.c
index caad178b14..af0bf57e07 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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;
 
diff --git a/streaming.c b/streaming.c
index 5892b50bd8..22d27df55e 100644
--- a/streaming.c
+++ b/streaming.c
@@ -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,
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 024/194] sha1_file: allow alt_odb_usable to handle arbitrary repositories
  2018-02-05 23:54 ` Stefan Beller
  2018-02-05 23:54   ` [PATCH 022/194] pack: add repository argument to sha1_file_name Stefan Beller
  2018-02-05 23:54   ` [PATCH 023/194] pack: add repository argument to map_sha1_file Stefan Beller
@ 2018-02-05 23:54   ` Stefan Beller
  2018-02-05 23:54   ` [PATCH 025/194] object-store: allow prepare_alt_odb " Stefan Beller
                     ` (73 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:54 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 sha1_file.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/sha1_file.c b/sha1_file.c
index af0bf57e07..c639c52f5f 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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;
 	}
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 025/194] object-store: allow prepare_alt_odb to handle arbitrary repositories
  2018-02-05 23:54 ` Stefan Beller
                     ` (2 preceding siblings ...)
  2018-02-05 23:54   ` [PATCH 024/194] sha1_file: allow alt_odb_usable to handle arbitrary repositories Stefan Beller
@ 2018-02-05 23:54   ` " Stefan Beller
  2018-02-06  1:19     ` brian m. carlson
  2018-02-07 22:06     ` Jonathan Tan
  2018-02-05 23:54   ` [PATCH 026/194] object-store: allow foreach_alt_odb " Stefan Beller
                     ` (72 subsequent siblings)
  76 siblings, 2 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:54 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 cache.h        |  4 ++++
 object-store.h |  3 +--
 sha1_file.c    | 63 ++++++++++++++++++++++++++++++----------------------------
 3 files changed, 38 insertions(+), 32 deletions(-)

diff --git a/cache.h b/cache.h
index 051a77c49a..ce309cfe3f 100644
--- a/cache.h
+++ b/cache.h
@@ -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);
diff --git a/object-store.h b/object-store.h
index 92fbf4a9ca..fcf36c7370 100644
--- a/object-store.h
+++ b/object-store.h
@@ -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)
diff --git a/sha1_file.c b/sha1_file.c
index c639c52f5f..be67c69c75 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -396,11 +396,10 @@ static int alt_odb_usable(struct repository *r, struct strbuf *path,
  * SHA1, an extra slash for the first level indirection, and the
  * terminating NUL.
  */
-#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,
+static void read_info_alternates(struct repository *r,
+				 const char *relative_base,
+				 int depth);
+static int link_alt_odb_entry(struct repository *r, const char *entry,
 	const char *relative_base, int depth, const char *normalized_objdir)
 {
 	struct alternate_object_database *ent;
@@ -426,7 +425,7 @@ static int link_alt_odb_entry_the_repository(const char *entry,
 	while (pathbuf.len && pathbuf.buf[pathbuf.len - 1] == '/')
 		strbuf_setlen(&pathbuf, pathbuf.len - 1);
 
-	if (!alt_odb_usable(the_repository, &pathbuf, normalized_objdir)) {
+	if (!alt_odb_usable(r, &pathbuf, normalized_objdir)) {
 		strbuf_release(&pathbuf);
 		return -1;
 	}
@@ -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;
 
 	/* recursively add alternates */
-	read_info_alternates(the_repository, pathbuf.buf, depth + 1);
+	read_info_alternates(r, pathbuf.buf, depth + 1);
 
 	strbuf_release(&pathbuf);
 	return 0;
@@ -474,12 +473,8 @@ static const char *parse_alt_odb_entry(const char *string,
 	return end;
 }
 
-#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)
+static void link_alt_odb_entries(struct repository *r, const char *alt,
+				 int sep, const char *relative_base, int depth)
 {
 	struct strbuf objdirbuf = STRBUF_INIT;
 	struct strbuf entry = STRBUF_INIT;
@@ -493,7 +488,7 @@ static void link_alt_odb_entries_the_repository(const char *alt,
 		return;
 	}
 
-	strbuf_add_absolute_path(&objdirbuf, get_object_directory());
+	strbuf_add_absolute_path(&objdirbuf, r->objectdir);
 	if (strbuf_normalize_path(&objdirbuf) < 0)
 		die("unable to normalize object directory: %s",
 		    objdirbuf.buf);
@@ -502,15 +497,16 @@ static void link_alt_odb_entries_the_repository(const char *alt,
 		alt = parse_alt_odb_entry(alt, sep, &entry);
 		if (!entry.len)
 			continue;
-		link_alt_odb_entry(the_repository, entry.buf,
+		link_alt_odb_entry(r, entry.buf,
 				   relative_base, depth, objdirbuf.buf);
 	}
 	strbuf_release(&entry);
 	strbuf_release(&objdirbuf);
 }
 
-static void read_info_alternates_the_repository(const char *relative_base,
-						int depth)
+static void read_info_alternates(struct repository *r,
+				 const char *relative_base,
+				 int depth)
 {
 	char *path;
 	struct strbuf buf = STRBUF_INIT;
@@ -522,7 +518,7 @@ static void read_info_alternates_the_repository(const char *relative_base,
 		return;
 	}
 
-	link_alt_odb_entries(the_repository, buf.buf, '\n', relative_base, depth);
+	link_alt_odb_entries(r, buf.buf, '\n', relative_base, depth);
 	strbuf_release(&buf);
 	free(path);
 }
@@ -683,21 +679,28 @@ int foreach_alt_odb_the_repository(alt_odb_fn fn, void *cb)
 	return r;
 }
 
-void prepare_alt_odb_the_repository(void)
+void prepare_alt_odb(struct repository *r)
 {
-	const char *alt;
-
-	if (the_repository->objects.alt_odb_tail)
+	if (r->objects.alt_odb_tail)
 		return;
 
-	alt = getenv(ALTERNATE_DB_ENVIRONMENT);
+	r->objects.alt_odb_tail = &r->objects.alt_odb_list;
+
+	if (!r->ignore_env) {
+		const char *alt = getenv(ALTERNATE_DB_ENVIRONMENT);
+		if (!alt)
+			alt = "";
 
-	the_repository->objects.alt_odb_tail =
-			&the_repository->objects.alt_odb_list;
-	link_alt_odb_entries(the_repository, alt,
-			     PATH_SEP, NULL, 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);
+	}
 
-	read_info_alternates(the_repository, get_object_directory(), 0);
+	read_info_alternates(r, r->objectdir, 0);
 }
 
 /* Returns 1 if we have successfully freshened the file, 0 otherwise. */
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 026/194] object-store: allow foreach_alt_odb to handle arbitrary repositories
  2018-02-05 23:54 ` Stefan Beller
                     ` (3 preceding siblings ...)
  2018-02-05 23:54   ` [PATCH 025/194] object-store: allow prepare_alt_odb " Stefan Beller
@ 2018-02-05 23:54   ` " Stefan Beller
  2018-02-05 23:54   ` [PATCH 027/194] pack: allow install_packed_git " Stefan Beller
                     ` (71 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:54 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 object-store.h |  3 +--
 sha1_file.c    | 14 +++++++-------
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/object-store.h b/object-store.h
index fcf36c7370..518da80367 100644
--- a/object-store.h
+++ b/object-store.h
@@ -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 */
diff --git a/sha1_file.c b/sha1_file.c
index be67c69c75..ca492eb741 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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)
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 027/194] pack: allow install_packed_git to handle arbitrary repositories
  2018-02-05 23:54 ` Stefan Beller
                     ` (4 preceding siblings ...)
  2018-02-05 23:54   ` [PATCH 026/194] object-store: allow foreach_alt_odb " Stefan Beller
@ 2018-02-05 23:54   ` " Stefan Beller
  2018-02-05 23:54   ` [PATCH 028/194] pack: allow rearrange_packed_git " Stefan Beller
                     ` (70 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:54 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 packfile.c | 6 +++---
 packfile.h | 3 +--
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/packfile.c b/packfile.c
index 6a1c8107ed..05b4505b2c 100644
--- a/packfile.c
+++ b/packfile.c
@@ -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);
diff --git a/packfile.h b/packfile.h
index 74f293c439..ba6f08be99 100644
--- a/packfile.h
+++ b/packfile.h
@@ -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
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 028/194] pack: allow rearrange_packed_git to handle arbitrary repositories
  2018-02-05 23:54 ` Stefan Beller
                     ` (5 preceding siblings ...)
  2018-02-05 23:54   ` [PATCH 027/194] pack: allow install_packed_git " Stefan Beller
@ 2018-02-05 23:54   ` " Stefan Beller
  2018-02-05 23:54   ` [PATCH 029/194] pack: allow prepare_packed_git_mru " Stefan Beller
                     ` (69 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:54 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 packfile.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/packfile.c b/packfile.c
index 05b4505b2c..d1533ec948 100644
--- a/packfile.c
+++ b/packfile.c
@@ -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);
 }
 
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 029/194] pack: allow prepare_packed_git_mru to handle arbitrary repositories
  2018-02-05 23:54 ` Stefan Beller
                     ` (6 preceding siblings ...)
  2018-02-05 23:54   ` [PATCH 028/194] pack: allow rearrange_packed_git " Stefan Beller
@ 2018-02-05 23:54   ` " Stefan Beller
  2018-02-05 23:54   ` [PATCH 030/194] pack: allow prepare_packed_git_one " Stefan Beller
                     ` (68 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:54 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 packfile.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/packfile.c b/packfile.c
index d1533ec948..fd7dfc816e 100644
--- a/packfile.c
+++ b/packfile.c
@@ -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)
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 030/194] pack: allow prepare_packed_git_one to handle arbitrary repositories
  2018-02-05 23:54 ` Stefan Beller
                     ` (7 preceding siblings ...)
  2018-02-05 23:54   ` [PATCH 029/194] pack: allow prepare_packed_git_mru " Stefan Beller
@ 2018-02-05 23:54   ` " Stefan Beller
  2018-02-05 23:54   ` [PATCH 031/194] pack: allow prepare_packed_git " Stefan Beller
                     ` (67 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:54 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 packfile.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/packfile.c b/packfile.c
index fd7dfc816e..2b73e62a44 100644
--- a/packfile.c
+++ b/packfile.c
@@ -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)
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 031/194] pack: allow prepare_packed_git to handle arbitrary repositories
  2018-02-05 23:54 ` Stefan Beller
                     ` (8 preceding siblings ...)
  2018-02-05 23:54   ` [PATCH 030/194] pack: allow prepare_packed_git_one " Stefan Beller
@ 2018-02-05 23:54   ` " Stefan Beller
  2018-02-05 23:54   ` [PATCH 032/194] pack: allow reprepare_packed_git " Stefan Beller
                     ` (66 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:54 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 packfile.c | 18 +++++++++---------
 packfile.h |  3 +--
 2 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/packfile.c b/packfile.c
index 2b73e62a44..7dc7e8e383 100644
--- a/packfile.c
+++ b/packfile.c
@@ -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)
diff --git a/packfile.h b/packfile.h
index ba6f08be99..75be3cb877 100644
--- a/packfile.h
+++ b/packfile.h
@@ -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);
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 032/194] pack: allow reprepare_packed_git to handle arbitrary repositories
  2018-02-05 23:54 ` Stefan Beller
                     ` (9 preceding siblings ...)
  2018-02-05 23:54   ` [PATCH 031/194] pack: allow prepare_packed_git " Stefan Beller
@ 2018-02-05 23:54   ` " Stefan Beller
  2018-02-05 23:54   ` [PATCH 033/194] pack: allow sha1_file_name " Stefan Beller
                     ` (65 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:54 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 packfile.c | 8 ++++----
 packfile.h | 3 +--
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/packfile.c b/packfile.c
index 7dc7e8e383..7aa69dd3c0 100644
--- a/packfile.c
+++ b/packfile.c
@@ -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,
diff --git a/packfile.h b/packfile.h
index 75be3cb877..b3138816e7 100644
--- a/packfile.h
+++ b/packfile.h
@@ -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);
 
 /*
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 033/194] pack: allow sha1_file_name to handle arbitrary repositories
  2018-02-05 23:54 ` Stefan Beller
                     ` (10 preceding siblings ...)
  2018-02-05 23:54   ` [PATCH 032/194] pack: allow reprepare_packed_git " Stefan Beller
@ 2018-02-05 23:54   ` " Stefan Beller
  2018-02-05 23:54   ` [PATCH 034/194] pack: allow stat_sha1_file " Stefan Beller
                     ` (64 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:54 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 object-store.h | 3 +--
 sha1_file.c    | 4 ++--
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/object-store.h b/object-store.h
index 518da80367..fe2187fd65 100644
--- a/object-store.h
+++ b/object-store.h
@@ -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);
 
diff --git a/sha1_file.c b/sha1_file.c
index ca492eb741..5d4c39bd45 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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;
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 034/194] pack: allow stat_sha1_file to handle arbitrary repositories
  2018-02-05 23:54 ` Stefan Beller
                     ` (11 preceding siblings ...)
  2018-02-05 23:54   ` [PATCH 033/194] pack: allow sha1_file_name " Stefan Beller
@ 2018-02-05 23:54   ` " Stefan Beller
  2018-02-05 23:54   ` [PATCH 035/194] pack: allow open_sha1_file " Stefan Beller
                     ` (63 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:54 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 sha1_file.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/sha1_file.c b/sha1_file.c
index 5d4c39bd45..6887543d5e 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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;
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 035/194] pack: allow open_sha1_file to handle arbitrary repositories
  2018-02-05 23:54 ` Stefan Beller
                     ` (12 preceding siblings ...)
  2018-02-05 23:54   ` [PATCH 034/194] pack: allow stat_sha1_file " Stefan Beller
@ 2018-02-05 23:54   ` " Stefan Beller
  2018-02-05 23:54   ` [PATCH 036/194] pack: allow map_sha1_file_1 " Stefan Beller
                     ` (62 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:54 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 sha1_file.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/sha1_file.c b/sha1_file.c
index 6887543d5e..a0f438b493 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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)
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 036/194] pack: allow map_sha1_file_1 to handle arbitrary repositories
  2018-02-05 23:54 ` Stefan Beller
                     ` (13 preceding siblings ...)
  2018-02-05 23:54   ` [PATCH 035/194] pack: allow open_sha1_file " Stefan Beller
@ 2018-02-05 23:54   ` " Stefan Beller
  2018-02-05 23:54   ` [PATCH 037/194] pack: allow map_sha1_file " Stefan Beller
                     ` (61 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:54 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 sha1_file.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/sha1_file.c b/sha1_file.c
index a0f438b493..590b857391 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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;
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 037/194] pack: allow map_sha1_file to handle arbitrary repositories
  2018-02-05 23:54 ` Stefan Beller
                     ` (14 preceding siblings ...)
  2018-02-05 23:54   ` [PATCH 036/194] pack: allow map_sha1_file_1 " Stefan Beller
@ 2018-02-05 23:54   ` " Stefan Beller
  2018-02-05 23:54   ` [PATCH 038/194] pack: allow sha1_loose_object_info " Stefan Beller
                     ` (60 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:54 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 object-store.h | 3 +--
 sha1_file.c    | 5 +++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/object-store.h b/object-store.h
index fe2187fd65..57b8d89738 100644
--- a/object-store.h
+++ b/object-store.h
@@ -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);
 
diff --git a/sha1_file.c b/sha1_file.c
index 590b857391..786e904eab 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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,
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 038/194] pack: allow sha1_loose_object_info to handle arbitrary repositories
  2018-02-05 23:54 ` Stefan Beller
                     ` (15 preceding siblings ...)
  2018-02-05 23:54   ` [PATCH 037/194] pack: allow map_sha1_file " Stefan Beller
@ 2018-02-05 23:54   ` " Stefan Beller
  2018-02-07 22:33     ` Jonathan Tan
  2018-02-05 23:55   ` [PATCH 039/194] replace_object.c: rename to use dash in file name Stefan Beller
                     ` (59 subsequent siblings)
  76 siblings, 1 reply; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:54 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 sha1_file.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/sha1_file.c b/sha1_file.c
index 786e904eab..1e867bc293 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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;
 
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 039/194] replace_object.c: rename to use dash in file name
  2018-02-05 23:54 ` Stefan Beller
                     ` (16 preceding siblings ...)
  2018-02-05 23:54   ` [PATCH 038/194] pack: allow sha1_loose_object_info " Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 040/194] replace-object: move replace_object to object store Stefan Beller
                     ` (58 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 Makefile                             | 2 +-
 replace_object.c => replace-object.c | 0
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename replace_object.c => replace-object.c (100%)

diff --git a/Makefile b/Makefile
index 1a9b23b679..84aeabe320 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/replace_object.c b/replace-object.c
similarity index 100%
rename from replace_object.c
rename to replace-object.c
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 040/194] replace-object: move replace_object to object store
  2018-02-05 23:54 ` Stefan Beller
                     ` (17 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 039/194] replace_object.c: rename to use dash in file name Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 041/194] sha1_file: add repository argument to sha1_object_info_extended Stefan Beller
                     ` (57 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 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

diff --git a/object-store.h b/object-store.h
index 57b8d89738..298e34e978 100644
--- a/object-store.h
+++ b/object-store.h
@@ -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;
diff --git a/replace-object.c b/replace-object.c
index f0b39f06d5..d26e180639 100644
--- a/replace-object.c
+++ b/replace-object.c
@@ -1,19 +1,10 @@
 #include "cache.h"
+#include "replace-object.h"
 #include "sha1-lookup.h"
 #include "refs.h"
+#include "repository.h"
 #include "commit.h"
 
-/*
- * An array of replacements.  The array is kept sorted by the original
- * sha1.
- */
-static struct replace_object {
-	unsigned char original[20];
-	unsigned char replacement[20];
-} **replace_object;
-
-static int replace_object_alloc, replace_object_nr;
-
 static const unsigned char *replace_sha1_access(size_t index, void *table)
 {
 	struct replace_object **replace = table;
@@ -22,7 +13,8 @@ static const unsigned char *replace_sha1_access(size_t index, void *table)
 
 static int replace_object_pos(const unsigned char *sha1)
 {
-	return sha1_pos(sha1, replace_object, replace_object_nr,
+	return sha1_pos(sha1, the_repository->objects.replacements.items,
+			the_repository->objects.replacements.nr,
 			replace_sha1_access);
 }
 
@@ -35,20 +27,22 @@ static int register_replace_object(struct replace_object *replace,
 		if (ignore_dups)
 			free(replace);
 		else {
-			free(replace_object[pos]);
-			replace_object[pos] = replace;
+			free(the_repository->objects.replacements.items[pos]);
+			the_repository->objects.replacements.items[pos] = replace;
 		}
 		return 1;
 	}
 	pos = -pos - 1;
-	ALLOC_GROW(replace_object, replace_object_nr + 1, replace_object_alloc);
-	replace_object_nr++;
-	if (pos < replace_object_nr)
-		memmove(replace_object + pos + 1,
-			replace_object + pos,
-			(replace_object_nr - pos - 1) *
-			sizeof(*replace_object));
-	replace_object[pos] = replace;
+	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;
 	return 0;
 }
 
@@ -86,7 +80,7 @@ static void prepare_replace_object(void)
 
 	for_each_replace_ref(register_replace_ref, NULL);
 	replace_object_prepared = 1;
-	if (!replace_object_nr)
+	if (!the_repository->objects.replacements.nr)
 		check_replace_refs = 0;
 }
 
@@ -115,7 +109,7 @@ const unsigned char *do_lookup_replace_object(const unsigned char *sha1)
 
 		pos = replace_object_pos(cur);
 		if (0 <= pos)
-			cur = replace_object[pos]->replacement;
+			cur = the_repository->objects.replacements.items[pos]->replacement;
 	} while (0 <= pos);
 
 	return cur;
diff --git a/replace-object.h b/replace-object.h
new file mode 100644
index 0000000000..483335ffcc
--- /dev/null
+++ b/replace-object.h
@@ -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 */
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 041/194] sha1_file: add repository argument to sha1_object_info_extended
  2018-02-05 23:54 ` Stefan Beller
                     ` (18 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 040/194] replace-object: move replace_object to object store Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 042/194] object-store: move alternates API to new alternates.h Stefan Beller
                     ` (56 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 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(-)

diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index f5fa4fd75a..9d18efeb7c 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -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));
diff --git a/cache.h b/cache.h
index ce309cfe3f..3410a93737 100644
--- a/cache.h
+++ b/cache.h
@@ -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);
diff --git a/packfile.c b/packfile.c
index 7aa69dd3c0..0ca13a4ed7 100644
--- a/packfile.c
+++ b/packfile.c
@@ -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;
 }
diff --git a/sha1_file.c b/sha1_file.c
index 1e867bc293..a5dcb76d96 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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;
 }
 
diff --git a/streaming.c b/streaming.c
index 22d27df55e..47fca9aba0 100644
--- a/streaming.c
+++ b/streaming.c
@@ -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;
 
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 042/194] object-store: move alternates API to new alternates.h
  2018-02-05 23:54 ` Stefan Beller
                     ` (19 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 041/194] sha1_file: add repository argument to sha1_object_info_extended Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-06  1:44     ` brian m. carlson
  2018-02-06  4:52     ` Eric Sunshine
  2018-02-05 23:55   ` [PATCH 043/194] object-store: move loose object functions to new loose-object.h Stefan Beller
                     ` (55 subsequent siblings)
  76 siblings, 2 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 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

diff --git a/alternates.h b/alternates.h
new file mode 100644
index 0000000000..df5dc67e2e
--- /dev/null
+++ b/alternates.h
@@ -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 */
diff --git a/builtin/clone.c b/builtin/clone.c
index 2da71db107..27463c8fc5 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -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"
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index e340b3e3c3..805803fedd 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -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"
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 0e78f4ba72..571aa51579 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -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);
 
diff --git a/builtin/grep.c b/builtin/grep.c
index 3ca4ac80d8..1c71dff341 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -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"
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 8005adbf3d..10024c2fa2 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -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"
diff --git a/cache.h b/cache.h
index 3410a93737..b002c9a96d 100644
--- a/cache.h
+++ b/cache.h
@@ -1564,58 +1564,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 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 char *compute_alternate_path(const char *path, struct strbuf *err);
-
-/*
- * 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);
-
 struct pack_window {
 	struct pack_window *next;
 	unsigned char *base;
diff --git a/object-store.h b/object-store.h
index 298e34e978..967dd8af26 100644
--- a/object-store.h
+++ b/object-store.h
@@ -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 */
diff --git a/packfile.c b/packfile.c
index 0ca13a4ed7..a7504debe5 100644
--- a/packfile.c
+++ b/packfile.c
@@ -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);
diff --git a/sha1_file.c b/sha1_file.c
index a5dcb76d96..84501d66e9 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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)
diff --git a/sha1_name.c b/sha1_name.c
index d3769713ea..363f7e1d4d 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -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;
diff --git a/submodule.c b/submodule.c
index 2967704317..f7736ec4b5 100644
--- a/submodule.c
+++ b/submodule.c
@@ -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"
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index 7120634b04..4b96dfe12f 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "alternates.h"
 #include "refs.h"
 #include "worktree.h"
 
diff --git a/tmp-objdir.c b/tmp-objdir.c
index b2d9280f10..bf34315adf 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "tmp-objdir.h"
+#include "alternates.h"
 #include "dir.h"
 #include "sigchain.h"
 #include "string-list.h"
diff --git a/transport.c b/transport.c
index 3f97fbe7c5..00f90d7b20 100644
--- a/transport.c
+++ b/transport.c
@@ -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"
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 043/194] object-store: move loose object functions to new loose-object.h
  2018-02-05 23:54 ` Stefan Beller
                     ` (20 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 042/194] object-store: move alternates API to new alternates.h Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 044/194] pack: move struct pack_window and pack_entry to packfile.h Stefan Beller
                     ` (54 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 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

diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 9d18efeb7c..fdc70aa419 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -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"
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index 805803fedd..34f2bfa44e 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -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"
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 571aa51579..920cc50923 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -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"
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index d42df2a2b9..b998e139d1 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -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"
diff --git a/builtin/prune-packed.c b/builtin/prune-packed.c
index 419238171d..2da1573359 100644
--- a/builtin/prune-packed.c
+++ b/builtin/prune-packed.c
@@ -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[] = {
diff --git a/builtin/prune.c b/builtin/prune.c
index d2fdae680a..52091f299e 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -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"
diff --git a/cache.h b/cache.h
index b002c9a96d..7be9a8ad27 100644
--- a/cache.h
+++ b/cache.h
@@ -1244,19 +1244,6 @@ extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned l
 
 extern int finalize_object_file(const char *tmpfile, const char *filename);
 
-/*
- * Open the loose object at path, check its sha1, and return the contents,
- * type, and size. If the object is a blob, then "contents" may return NULL,
- * to allow streaming of large blobs.
- *
- * Returns 0 on success, negative on error (details may be written to stderr).
- */
-int read_loose_object(const char *path,
-		      const unsigned char *expected_sha1,
-		      enum object_type *type,
-		      unsigned long *size,
-		      void **contents);
-
 /*
  * Convenience for sha1_object_info_extended() with a NULL struct
  * object_info. OBJECT_INFO_SKIP_CACHED is automatically set; pass
@@ -1272,13 +1259,6 @@ static inline int has_sha1_file(const unsigned char *sha1)
 extern int has_object_file(const struct object_id *oid);
 extern int has_object_file_with_flags(const struct object_id *oid, int flags);
 
-/*
- * Return true iff an alternate object database has a loose object
- * with the specified name.  This function does not respect replace
- * references.
- */
-extern int has_loose_object_nonlocal(const unsigned char *sha1);
-
 extern void assert_sha1_type(const unsigned char *sha1, enum object_type expect);
 
 /* Helper to check and "touch" a file */
@@ -1595,60 +1575,11 @@ extern int odb_mkstemp(struct strbuf *template, const char *pattern);
 extern int odb_pack_keep(const char *name);
 
 /*
- * Iterate over the files in the loose-object parts of the object
- * directory "path", triggering the following callbacks:
- *
- *  - loose_object is called for each loose object we find.
- *
- *  - loose_cruft is called for any files that do not appear to be
- *    loose objects. Note that we only look in the loose object
- *    directories "objects/[0-9a-f]{2}/", so we will not report
- *    "objects/foobar" as cruft.
- *
- *  - loose_subdir is called for each top-level hashed subdirectory
- *    of the object directory (e.g., "$OBJDIR/f0"). It is called
- *    after the objects in the directory are processed.
- *
- * Any callback that is NULL will be ignored. Callbacks returning non-zero
- * will end the iteration.
- *
- * In the "buf" variant, "path" is a strbuf which will also be used as a
- * scratch buffer, but restored to its original contents before
- * the function returns.
- */
-typedef int each_loose_object_fn(const struct object_id *oid,
-				 const char *path,
-				 void *data);
-typedef int each_loose_cruft_fn(const char *basename,
-				const char *path,
-				void *data);
-typedef int each_loose_subdir_fn(unsigned int nr,
-				 const char *path,
-				 void *data);
-int for_each_file_in_obj_subdir(unsigned int subdir_nr,
-				struct strbuf *path,
-				each_loose_object_fn obj_cb,
-				each_loose_cruft_fn cruft_cb,
-				each_loose_subdir_fn subdir_cb,
-				void *data);
-int for_each_loose_file_in_objdir(const char *path,
-				  each_loose_object_fn obj_cb,
-				  each_loose_cruft_fn cruft_cb,
-				  each_loose_subdir_fn subdir_cb,
-				  void *data);
-int for_each_loose_file_in_objdir_buf(struct strbuf *path,
-				      each_loose_object_fn obj_cb,
-				      each_loose_cruft_fn cruft_cb,
-				      each_loose_subdir_fn subdir_cb,
-				      void *data);
-
-/*
- * Iterate over loose objects in both the local
- * repository and any alternates repositories (unless the
- * LOCAL_ONLY flag is set).
+ * Flag for for_each_packed_object and for_each_loose_object to only iterate
+ * over objects in the local repository, and not any alternates (see
+ * alternates.h).
  */
 #define FOR_EACH_OBJECT_LOCAL_ONLY 0x1
-extern int for_each_loose_object(each_loose_object_fn, void *, unsigned flags);
 
 struct object_info {
 	/* Request */
diff --git a/http-walker.c b/http-walker.c
index 96873bdfed..34594165b1 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -6,6 +6,7 @@
 #include "list.h"
 #include "transport.h"
 #include "object-store.h"
+#include "loose-object.h"
 #include "packfile.h"
 
 struct alt_base {
diff --git a/http.c b/http.c
index ad57476635..e04eca601b 100644
--- a/http.c
+++ b/http.c
@@ -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"
diff --git a/loose-object.h b/loose-object.h
new file mode 100644
index 0000000000..7d721ae4f0
--- /dev/null
+++ b/loose-object.h
@@ -0,0 +1,91 @@
+#ifndef LOOSE_OBJECT_H
+#define LOOSE_OBJECT_H
+
+#include "cache.h"
+#include "strbuf.h"
+#include "repository.h"
+
+/*
+ * Open the loose object at path, check its sha1, and return the contents,
+ * type, and size. If the object is a blob, then "contents" may return NULL,
+ * to allow streaming of large blobs.
+ *
+ * Returns 0 on success, negative on error (details may be written to stderr).
+ */
+int read_loose_object(const char *path,
+		      const unsigned char *expected_sha1,
+		      enum object_type *type,
+		      unsigned long *size,
+		      void **contents);
+
+/*
+ * Return true iff an alternate object database has a loose object
+ * with the specified name.  This function does not respect replace
+ * references.
+ */
+extern int has_loose_object_nonlocal(const unsigned char *sha1);
+
+/*
+ * Iterate over the files in the loose-object parts of the object
+ * directory "path", triggering the following callbacks:
+ *
+ *  - loose_object is called for each loose object we find.
+ *
+ *  - loose_cruft is called for any files that do not appear to be
+ *    loose objects. Note that we only look in the loose object
+ *    directories "objects/[0-9a-f]{2}/", so we will not report
+ *    "objects/foobar" as cruft.
+ *
+ *  - loose_subdir is called for each top-level hashed subdirectory
+ *    of the object directory (e.g., "$OBJDIR/f0"). It is called
+ *    after the objects in the directory are processed.
+ *
+ * Any callback that is NULL will be ignored. Callbacks returning non-zero
+ * will end the iteration.
+ *
+ * In the "buf" variant, "path" is a strbuf which will also be used as a
+ * scratch buffer, but restored to its original contents before
+ * the function returns.
+ */
+typedef int each_loose_object_fn(const struct object_id *oid,
+				 const char *path,
+				 void *data);
+typedef int each_loose_cruft_fn(const char *basename,
+				const char *path,
+				void *data);
+typedef int each_loose_subdir_fn(unsigned int nr,
+				 const char *path,
+				 void *data);
+int for_each_file_in_obj_subdir(unsigned int subdir_nr,
+				struct strbuf *path,
+				each_loose_object_fn obj_cb,
+				each_loose_cruft_fn cruft_cb,
+				each_loose_subdir_fn subdir_cb,
+				void *data);
+int for_each_loose_file_in_objdir(const char *path,
+				  each_loose_object_fn obj_cb,
+				  each_loose_cruft_fn cruft_cb,
+				  each_loose_subdir_fn subdir_cb,
+				  void *data);
+int for_each_loose_file_in_objdir_buf(struct strbuf *path,
+				      each_loose_object_fn obj_cb,
+				      each_loose_cruft_fn cruft_cb,
+				      each_loose_subdir_fn subdir_cb,
+				      void *data);
+
+/*
+ * Iterate over loose objects in both the local
+ * repository and any alternates repositories (unless the
+ * FOR_EACH_OBJECT_LOCAL_ONLY flag, defined in cache.h, is set).
+ */
+extern int for_each_loose_object(each_loose_object_fn, void *, unsigned flags);
+
+/*
+ * 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);
+
+#endif
diff --git a/object-store.h b/object-store.h
index 967dd8af26..7a372baa79 100644
--- a/object-store.h
+++ b/object-store.h
@@ -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 */
diff --git a/reachable.c b/reachable.c
index 59ed16ba76..ac5224b9a5 100644
--- a/reachable.c
+++ b/reachable.c
@@ -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"
diff --git a/sha1_file.c b/sha1_file.c
index 84501d66e9..2584465e9c 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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"
diff --git a/sha1_name.c b/sha1_name.c
index 363f7e1d4d..03ce2ff7f2 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -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"
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 044/194] pack: move struct pack_window and pack_entry to packfile.h
  2018-02-05 23:54 ` Stefan Beller
                     ` (21 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 043/194] object-store: move loose object functions to new loose-object.h Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 045/194] object-store: move object access functions to object-store.h Stefan Beller
                     ` (53 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 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(-)

diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index b998e139d1..7cb73c29ac 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -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"
diff --git a/cache.h b/cache.h
index 7be9a8ad27..c66e59733d 100644
--- a/cache.h
+++ b/cache.h
@@ -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
diff --git a/object-store.h b/object-store.h
index 7a372baa79..3475e22021 100644
--- a/object-store.h
+++ b/object-store.h
@@ -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;
diff --git a/pack.h b/pack.h
index 8294341af1..c0ea2b6499 100644
--- a/pack.h
+++ b/pack.h
@@ -2,6 +2,7 @@
 #define PACK_H
 
 #include "object.h"
+#include "packfile.h"
 #include "csum-file.h"
 
 /*
diff --git a/packfile.c b/packfile.c
index a7504debe5..b73814f2ce 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "mru.h"
+#include "packfile.h"
 #include "pack.h"
 #include "repository.h"
 #include "alternates.h"
diff --git a/packfile.h b/packfile.h
index b3138816e7..1163fc7bb4 100644
--- a/packfile.h
+++ b/packfile.h
@@ -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
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 045/194] object-store: move object access functions to object-store.h
  2018-02-05 23:54 ` Stefan Beller
                     ` (22 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 044/194] pack: move struct pack_window and pack_entry to packfile.h Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 046/194] object-store: move replace_objects back to object-store Stefan Beller
                     ` (52 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 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(-)

diff --git a/apply.c b/apply.c
index 321a9fa68d..de4440cd2a 100644
--- a/apply.c
+++ b/apply.c
@@ -9,6 +9,7 @@
 
 #include "cache.h"
 #include "config.h"
+#include "object-store.h"
 #include "blob.h"
 #include "delta.h"
 #include "diff.h"
diff --git a/archive-tar.c b/archive-tar.c
index c6ed96ee74..909347c108 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -5,6 +5,7 @@
 #include "config.h"
 #include "tar.h"
 #include "archive.h"
+#include "object-store.h"
 #include "streaming.h"
 #include "run-command.h"
 
diff --git a/archive-zip.c b/archive-zip.c
index e8913e5a26..233fed3a61 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -6,6 +6,7 @@
 #include "archive.h"
 #include "streaming.h"
 #include "utf8.h"
+#include "object-store.h"
 #include "userdiff.h"
 #include "xdiff-interface.h"
 
diff --git a/archive.c b/archive.c
index 0b7b62af0c..9b47041a6c 100644
--- a/archive.c
+++ b/archive.c
@@ -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"
diff --git a/blame.c b/blame.c
index 2893f3c103..61f0f6bb40 100644
--- a/blame.c
+++ b/blame.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "refs.h"
+#include "object-store.h"
 #include "cache-tree.h"
 #include "mergesort.h"
 #include "diff.h"
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 8bdc927d3f..c7271ed43f 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -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"
diff --git a/builtin/clone.c b/builtin/clone.c
index 27463c8fc5..ecd71b9444 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -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"
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index 2177251e24..a54fb362ce 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -5,6 +5,7 @@
  */
 #include "cache.h"
 #include "config.h"
+#include "object-store.h"
 #include "commit.h"
 #include "tree.h"
 #include "builtin.h"
diff --git a/builtin/difftool.c b/builtin/difftool.c
index bcc79d1888..d62094060d 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -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;
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 796d0cd66c..f76b7bda79 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -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"
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 7bbcd26faf..9b7202953b 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -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"
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index 8e8a15ea4a..9dd5c85831 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -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"
diff --git a/builtin/hash-object.c b/builtin/hash-object.c
index c532ff9320..956a798110 100644
--- a/builtin/hash-object.c
+++ b/builtin/hash-object.c
@@ -6,6 +6,7 @@
  */
 #include "builtin.h"
 #include "config.h"
+#include "object-store.h"
 #include "blob.h"
 #include "quote.h"
 #include "parse-options.h"
diff --git a/builtin/log.c b/builtin/log.c
index 14fdf39165..de723fffc6 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -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"
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index ef965408e8..78fcced566 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -5,6 +5,7 @@
  */
 #include "cache.h"
 #include "config.h"
+#include "object-store.h"
 #include "blob.h"
 #include "tree.h"
 #include "commit.h"
diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c
index d01ddecf66..ba51ad55a8 100644
--- a/builtin/merge-tree.c
+++ b/builtin/merge-tree.c
@@ -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"
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 031b750f06..04eadc7b24 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -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
diff --git a/builtin/mktree.c b/builtin/mktree.c
index da0fd8cd70..0f66946618 100644
--- a/builtin/mktree.c
+++ b/builtin/mktree.c
@@ -7,6 +7,7 @@
 #include "quote.h"
 #include "tree.h"
 #include "parse-options.h"
+#include "object-store.h"
 
 static struct treeent {
 	unsigned mode;
diff --git a/builtin/notes.c b/builtin/notes.c
index 7c81761645..1bd3994caa 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -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"
diff --git a/builtin/reflog.c b/builtin/reflog.c
index 2233725315..4b525c4448 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -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"
diff --git a/builtin/remote.c b/builtin/remote.c
index d95bf904c3..7bd81bac6a 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -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[] = {
diff --git a/builtin/replace.c b/builtin/replace.c
index 10078ae371..ccde160228 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -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[] = {
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index d5345b6a2e..969efde30c 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -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"
diff --git a/builtin/show-ref.c b/builtin/show-ref.c
index 41e5e71cad..8f5827af62 100644
--- a/builtin/show-ref.c
+++ b/builtin/show-ref.c
@@ -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"
diff --git a/builtin/tag.c b/builtin/tag.c
index a7e6a5b0f2..7ed3506fff 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -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"
diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c
index 32e0155577..b28e056c74 100644
--- a/builtin/unpack-file.c
+++ b/builtin/unpack-file.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "config.h"
+#include "object-store.h"
 
 static char *create_temp_file(struct object_id *oid)
 {
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 62ea264c46..6d03ea2670 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -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"
diff --git a/builtin/verify-commit.c b/builtin/verify-commit.c
index ba38ac9b15..29f5e5507c 100644
--- a/builtin/verify-commit.c
+++ b/builtin/verify-commit.c
@@ -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>
diff --git a/bundle.c b/bundle.c
index 93290962c9..d9376b7c77 100644
--- a/bundle.c
+++ b/bundle.c
@@ -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"
diff --git a/cache-tree.c b/cache-tree.c
index e03e72c34a..2a98b15b92 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -3,6 +3,7 @@
 #include "tree.h"
 #include "tree-walk.h"
 #include "cache-tree.h"
+#include "object-store.h"
 
 #ifndef DEBUG
 #define DEBUG 0
diff --git a/cache.h b/cache.h
index c66e59733d..22404de92b 100644
--- a/cache.h
+++ b/cache.h
@@ -1201,40 +1201,6 @@ extern char *xdg_config_home(const char *filename);
  */
 extern char *xdg_cache_home(const char *filename);
 
-extern void *read_sha1_file_extended(const unsigned char *sha1,
-				     enum object_type *type,
-				     unsigned long *size, int lookup_replace);
-static inline void *read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size)
-{
-	return read_sha1_file_extended(sha1, type, size, 1);
-}
-
-/*
- * 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);
-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);
-extern int pretend_sha1_file(void *, unsigned long, enum object_type, unsigned char *);
-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 int unpack_sha1_header(git_zstream *stream, unsigned char *map, unsigned long mapsize, void *buffer, unsigned long bufsiz);
@@ -1244,23 +1210,6 @@ extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned l
 
 extern int finalize_object_file(const char *tmpfile, const char *filename);
 
-/*
- * Convenience for sha1_object_info_extended() with a NULL struct
- * object_info. OBJECT_INFO_SKIP_CACHED is automatically set; pass
- * nonzero flags to also set other flags.
- */
-extern int has_sha1_file_with_flags(const unsigned char *sha1, int flags);
-static inline int has_sha1_file(const unsigned char *sha1)
-{
-	return has_sha1_file_with_flags(sha1, 0);
-}
-
-/* Same as the above, except for struct object_id. */
-extern int has_object_file(const struct object_id *oid);
-extern int has_object_file_with_flags(const struct object_id *oid, int flags);
-
-extern void assert_sha1_type(const unsigned char *sha1, enum object_type expect);
-
 /* Helper to check and "touch" a file */
 extern int check_and_freshen_file(const char *fn, int freshen);
 
@@ -1566,57 +1515,6 @@ extern int odb_pack_keep(const char *name);
  */
 #define FOR_EACH_OBJECT_LOCAL_ONLY 0x1
 
-struct object_info {
-	/* Request */
-	enum object_type *typep;
-	unsigned long *sizep;
-	off_t *disk_sizep;
-	unsigned char *delta_base_sha1;
-	struct strbuf *typename;
-	void **contentp;
-
-	/* Response */
-	enum {
-		OI_CACHED,
-		OI_LOOSE,
-		OI_PACKED,
-		OI_DBCACHED
-	} whence;
-	union {
-		/*
-		 * struct {
-		 * 	... Nothing to expose in this case
-		 * } cached;
-		 * struct {
-		 * 	... Nothing to expose in this case
-		 * } loose;
-		 */
-		struct {
-			struct packed_git *pack;
-			off_t offset;
-			unsigned int is_delta;
-		} packed;
-	} u;
-};
-
-/*
- * Initializer for a "struct object_info" that wants no items. You may
- * also memset() the memory to all-zeroes.
- */
-#define OBJECT_INFO_INIT {NULL}
-
-/* Invoke lookup_replace_object() on the given hash */
-#define OBJECT_INFO_LOOKUP_REPLACE 1
-/* Allow reading from a loose object file of unknown/bogus type */
-#define OBJECT_INFO_ALLOW_UNKNOWN_TYPE 2
-/* Do not check cached storage */
-#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);
-
 /* Dumb servers support */
 extern int update_server_info(int);
 
diff --git a/combine-diff.c b/combine-diff.c
index 2505de119a..f45ab6f57c 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "object-store.h"
 #include "commit.h"
 #include "blob.h"
 #include "diff.h"
diff --git a/commit.c b/commit.c
index cab8d4455b..b60906d3f9 100644
--- a/commit.c
+++ b/commit.c
@@ -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"
diff --git a/convert.c b/convert.c
index 1a41a48e15..a090ed805f 100644
--- a/convert.c
+++ b/convert.c
@@ -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 --git a/diff.c b/diff.c
index fb22b19f09..e89c7d9919 100644
--- a/diff.c
+++ b/diff.c
@@ -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"
diff --git a/diffcore-rename.c b/diffcore-rename.c
index 245e999fe5..266b9ff03f 100644
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
@@ -4,6 +4,7 @@
 #include "cache.h"
 #include "diff.h"
 #include "diffcore.h"
+#include "object-store.h"
 #include "hashmap.h"
 #include "progress.h"
 
diff --git a/dir.c b/dir.c
index 7c4b45e30e..4a7981abc4 100644
--- a/dir.c
+++ b/dir.c
@@ -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"
diff --git a/entry.c b/entry.c
index 30211447ac..02aa09bc83 100644
--- a/entry.c
+++ b/entry.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "blob.h"
+#include "object-store.h"
 #include "dir.h"
 #include "streaming.h"
 #include "submodule.h"
diff --git a/fsck.c b/fsck.c
index 032699e9ac..d106714bf5 100644
--- a/fsck.c
+++ b/fsck.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "object-store.h"
 #include "object.h"
 #include "blob.h"
 #include "tree.h"
diff --git a/grep.c b/grep.c
index 3d7cd0e96f..6bccd7c7ea 100644
--- a/grep.c
+++ b/grep.c
@@ -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"
diff --git a/log-tree.c b/log-tree.c
index fca29d4799..b2fff6b5f6 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -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"
diff --git a/mailmap.c b/mailmap.c
index cb921b4db6..6afa9cc56d 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -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
diff --git a/match-trees.c b/match-trees.c
index 396b7338df..bdfdfcaaab 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -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)
 {
diff --git a/merge-blobs.c b/merge-blobs.c
index 9b6eac22e4..f5e71bcd9b 100644
--- a/merge-blobs.c
+++ b/merge-blobs.c
@@ -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)
 {
diff --git a/merge-recursive.c b/merge-recursive.c
index 0fc580d8ca..620e4f653c 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -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"
diff --git a/notes-cache.c b/notes-cache.c
index 17ee8602b3..ee513e87a9 100644
--- a/notes-cache.c
+++ b/notes-cache.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "notes-cache.h"
+#include "object-store.h"
 #include "commit.h"
 #include "refs.h"
 
diff --git a/notes-merge.c b/notes-merge.c
index 0f6573cb17..1053c65e83 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -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"
diff --git a/notes.c b/notes.c
index c7f21fae44..b1478a8dca 100644
--- a/notes.c
+++ b/notes.c
@@ -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"
diff --git a/object-store.h b/object-store.h
index 3475e22021..31628c49dc 100644
--- a/object-store.h
+++ b/object-store.h
@@ -1,11 +1,17 @@
 #ifndef OBJECT_STORE_H
 #define OBJECT_STORE_H
 
-#include "cache.h"
+#include "strbuf.h"
 #include "mru.h"
 #include "replace-object.h"
 #include "alternates.h"
-#include "packfile.h"
+
+/* in packfile.h */
+struct pack_window;
+
+/* in cache.h */
+enum object_type;
+extern int check_replace_refs;
 
 struct object_store {
 	struct packed_git *packed_git;
@@ -67,6 +73,108 @@ struct packed_git {
 	char pack_name[FLEX_ARRAY]; /* more */
 };
 
+extern void *read_sha1_file_extended(const unsigned char *sha1,
+				     enum object_type *type,
+				     unsigned long *size, int lookup_replace);
+static inline void *read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size)
+{
+	return read_sha1_file_extended(sha1, type, size, 1);
+}
+
+/*
+ * 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);
+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);
+extern int pretend_sha1_file(void *, unsigned long, enum object_type, unsigned char *);
+extern int force_object_loose(const unsigned char *sha1, time_t mtime);
 extern void *map_sha1_file(struct repository *r, const unsigned char *sha1, unsigned long *size);
 
+/*
+ * Convenience for sha1_object_info_extended() with a NULL struct
+ * object_info. OBJECT_INFO_SKIP_CACHED is automatically set; pass
+ * nonzero flags to also set other flags.
+ */
+extern int has_sha1_file_with_flags(const unsigned char *sha1, int flags);
+static inline int has_sha1_file(const unsigned char *sha1)
+{
+	return has_sha1_file_with_flags(sha1, 0);
+}
+
+/* Same as the above, except for struct object_id. */
+extern int has_object_file(const struct object_id *oid);
+extern int has_object_file_with_flags(const struct object_id *oid, int flags);
+
+extern void assert_sha1_type(const unsigned char *sha1, enum object_type expect);
+
+struct object_info {
+	/* Request */
+	enum object_type *typep;
+	unsigned long *sizep;
+	off_t *disk_sizep;
+	unsigned char *delta_base_sha1;
+	struct strbuf *typename;
+	void **contentp;
+
+	/* Response */
+	enum {
+		OI_CACHED,
+		OI_LOOSE,
+		OI_PACKED,
+		OI_DBCACHED
+	} whence;
+	union {
+		/*
+		 * struct {
+		 * 	... Nothing to expose in this case
+		 * } cached;
+		 * struct {
+		 * 	... Nothing to expose in this case
+		 * } loose;
+		 */
+		struct {
+			struct packed_git *pack;
+			off_t offset;
+			unsigned int is_delta;
+		} packed;
+	} u;
+};
+
+/*
+ * Initializer for a "struct object_info" that wants no items. You may
+ * also memset() the memory to all-zeroes.
+ */
+#define OBJECT_INFO_INIT {NULL}
+
+/* Invoke lookup_replace_object() on the given hash */
+#define OBJECT_INFO_LOOKUP_REPLACE 1
+/* Allow reading from a loose object file of unknown/bogus type */
+#define OBJECT_INFO_ALLOW_UNKNOWN_TYPE 2
+/* Do not check cached storage */
+#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);
+
 #endif /* OBJECT_STORE_H */
diff --git a/object.c b/object.c
index b9a4a0e501..4d2ae6851c 100644
--- a/object.c
+++ b/object.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "object.h"
+#include "object-store.h"
 #include "blob.h"
 #include "tree.h"
 #include "commit.h"
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index a8df5ce2ab..6a656104af 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "object-store.h"
 #include "commit.h"
 #include "tag.h"
 #include "diff.h"
diff --git a/packfile.h b/packfile.h
index 1163fc7bb4..0c314eea93 100644
--- a/packfile.h
+++ b/packfile.h
@@ -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;
diff --git a/read-cache.c b/read-cache.c
index 2eb81a66b9..45cad9272a 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -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"
diff --git a/ref-filter.c b/ref-filter.c
index 3f9161707e..0a106b888d 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -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"
diff --git a/refs.c b/refs.c
index 20ba82b434..968d33ac11 100644
--- a/refs.c
+++ b/refs.c
@@ -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"
diff --git a/remote-testsvn.c b/remote-testsvn.c
index bcebb4c789..387d4ae935 100644
--- a/remote-testsvn.c
+++ b/remote-testsvn.c
@@ -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"
diff --git a/remote.c b/remote.c
index 4e93753e19..5112f370c3 100644
--- a/remote.c
+++ b/remote.c
@@ -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"
diff --git a/rerere.c b/rerere.c
index 1ce440f4bb..ab64d3f48e 100644
--- a/rerere.c
+++ b/rerere.c
@@ -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
diff --git a/revision.c b/revision.c
index 72f2b4572e..9ede92c09e 100644
--- a/revision.c
+++ b/revision.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "object-store.h"
 #include "tag.h"
 #include "blob.h"
 #include "tree.h"
diff --git a/send-pack.c b/send-pack.c
index 2112d3b27a..c2856dcfd5 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -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"
diff --git a/sequencer.c b/sequencer.c
index 4d3f60594c..234addd4e7 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -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"
diff --git a/shallow.c b/shallow.c
index df4d44ea7a..c2f81a5a5a 100644
--- a/shallow.c
+++ b/shallow.c
@@ -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"
diff --git a/tag.c b/tag.c
index fcbe012f7a..30798abf1f 100644
--- a/tag.c
+++ b/tag.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "tag.h"
+#include "object-store.h"
 #include "commit.h"
 #include "tree.h"
 #include "blob.h"
diff --git a/tree-walk.c b/tree-walk.c
index 63a87ed666..8bd56eddd5 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -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"
 
diff --git a/tree.c b/tree.c
index b224115e0f..653339db03 100644
--- a/tree.c
+++ b/tree.c
@@ -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"
diff --git a/upload-pack.c b/upload-pack.c
index d5de18127c..6db85ecdc4 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -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"
diff --git a/walker.c b/walker.c
index 5d4d3733f7..49b6a96e6e 100644
--- a/walker.c
+++ b/walker.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "walker.h"
+#include "object-store.h"
 #include "commit.h"
 #include "tree.h"
 #include "tree-walk.h"
diff --git a/xdiff-interface.c b/xdiff-interface.c
index 770e1f7f81..a2d0e05edd 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -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"
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 046/194] object-store: move replace_objects back to object-store
  2018-02-05 23:54 ` Stefan Beller
                     ` (23 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 045/194] object-store: move object access functions to object-store.h Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-09 23:15     ` Junio C Hamano
  2018-02-05 23:55   ` [PATCH 047/194] object-store: move lookup_replace_object to replace-object.h Stefan Beller
                     ` (51 subsequent siblings)
  76 siblings, 1 reply; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 object-store.h   | 13 ++++++++++---
 replace-object.h | 11 -----------
 2 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/object-store.h b/object-store.h
index 31628c49dc..cf06a54782 100644
--- a/object-store.h
+++ b/object-store.h
@@ -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;
diff --git a/replace-object.h b/replace-object.h
index 483335ffcc..e05713b951 100644
--- a/replace-object.h
+++ b/replace-object.h
@@ -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];
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 047/194] object-store: move lookup_replace_object to replace-object.h
  2018-02-05 23:54 ` Stefan Beller
                     ` (24 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 046/194] object-store: move replace_objects back to object-store Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 048/194] replace-object: add repository argument to do_lookup_replace_object Stefan Beller
                     ` (50 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 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(-)

diff --git a/builtin/mktag.c b/builtin/mktag.c
index 04eadc7b24..93934e8e4b 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -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
diff --git a/object-store.h b/object-store.h
index cf06a54782..4ac0ffdb98 100644
--- a/object-store.h
+++ b/object-store.h
@@ -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);
diff --git a/object.c b/object.c
index 4d2ae6851c..fc0ccbefef 100644
--- a/object.c
+++ b/object.c
@@ -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"
diff --git a/replace-object.h b/replace-object.h
index e05713b951..668bbed1da 100644
--- a/replace-object.h
+++ b/replace-object.h
@@ -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 */
diff --git a/sha1_file.c b/sha1_file.c
index 2584465e9c..8ee86f8ede 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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"
diff --git a/streaming.c b/streaming.c
index 47fca9aba0..c47600e719 100644
--- a/streaming.c
+++ b/streaming.c
@@ -5,6 +5,7 @@
 #include "streaming.h"
 #include "repository.h"
 #include "object-store.h"
+#include "replace-object.h"
 #include "packfile.h"
 
 enum input_source {
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 048/194] replace-object: add repository argument to do_lookup_replace_object
  2018-02-05 23:54 ` Stefan Beller
                     ` (25 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 047/194] object-store: move lookup_replace_object to replace-object.h Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 049/194] replace-object: move replace objects prepared flag to object store Stefan Beller
                     ` (49 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 replace-object.c | 2 +-
 replace-object.h | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/replace-object.c b/replace-object.c
index d26e180639..cf38c3df00 100644
--- a/replace-object.c
+++ b/replace-object.c
@@ -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;
diff --git a/replace-object.h b/replace-object.h
index 668bbed1da..702020a3a0 100644
--- a/replace-object.h
+++ b/replace-object.h
@@ -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 */
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 049/194] replace-object: move replace objects prepared flag to object store
  2018-02-05 23:54 ` Stefan Beller
                     ` (26 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 048/194] replace-object: add repository argument to do_lookup_replace_object Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 050/194] replace-object: check_replace_refs is safe in multi repo environment Stefan Beller
                     ` (48 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

Remove another global variable on the way.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 object-store.h   | 4 +++-
 replace-object.c | 6 ++----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/object-store.h b/object-store.h
index 4ac0ffdb98..e1e592bdd5 100644
--- a/object-store.h
+++ b/object-store.h
@@ -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;
diff --git a/replace-object.c b/replace-object.c
index cf38c3df00..c865eff0ba 100644
--- a/replace-object.c
+++ b/replace-object.c
@@ -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;
 }
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 050/194] replace-object: check_replace_refs is safe in multi repo environment
  2018-02-05 23:54 ` Stefan Beller
                     ` (27 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 049/194] replace-object: move replace objects prepared flag to object store Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-06  4:30     ` Eric Sunshine
  2018-02-05 23:55   ` [PATCH 051/194] refs: add repository argument to for_each_replace_ref Stefan Beller
                     ` (47 subsequent siblings)
  76 siblings, 1 reply; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: 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

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 environment.c    | 2 +-
 replace-object.c | 2 --
 replace-object.h | 4 +++-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/environment.c b/environment.c
index 63ac38a46f..249516cf6b 100644
--- a/environment.c
+++ b/environment.c
@@ -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;
diff --git a/replace-object.c b/replace-object.c
index c865eff0ba..91fedd9447 100644
--- a/replace-object.c
+++ b/replace-object.c
@@ -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 */
diff --git a/replace-object.h b/replace-object.h
index 702020a3a0..8af730f5e3 100644
--- a/replace-object.h
+++ b/replace-object.h
@@ -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);
 }
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 051/194] refs: add repository argument to for_each_replace_ref
  2018-02-05 23:54 ` Stefan Beller
                     ` (28 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 050/194] replace-object: check_replace_refs is safe in multi repo environment Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 052/194] refs: add repository argument to get_main_ref_store Stefan Beller
                     ` (46 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 builtin/replace.c | 3 ++-
 refs.c            | 2 +-
 refs.h            | 4 +++-
 replace-object.c  | 2 +-
 4 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/builtin/replace.c b/builtin/replace.c
index ccde160228..6d27dd73f0 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -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;
 }
diff --git a/refs.c b/refs.c
index 968d33ac11..5c26532cbd 100644
--- a/refs.c
+++ b/refs.c
@@ -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,
diff --git a/refs.h b/refs.h
index 01be5ae32f..546fa9e65a 100644
--- a/refs.h
+++ b/refs.h
@@ -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);
diff --git a/replace-object.c b/replace-object.c
index 91fedd9447..102e009927 100644
--- a/replace-object.c
+++ b/replace-object.c
@@ -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;
 }
 
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 052/194] refs: add repository argument to get_main_ref_store
  2018-02-05 23:54 ` Stefan Beller
                     ` (29 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 051/194] refs: add repository argument to for_each_replace_ref Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 053/194] replace-object: add repository argument to register_replace_object Stefan Beller
                     ` (45 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 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(-)

diff --git a/builtin/pack-refs.c b/builtin/pack-refs.c
index b106a392a4..f3353564f9 100644
--- a/builtin/pack-refs.c
+++ b/builtin/pack-refs.c
@@ -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);
 }
diff --git a/refs.c b/refs.c
index 5c26532cbd..c2dee7a69a 100644
--- a/refs.c
+++ b/refs.c
@@ -14,6 +14,7 @@
 #include "tag.h"
 #include "submodule.h"
 #include "worktree.h"
+#include "repository.h"
 
 /*
  * List of all available backends
@@ -207,7 +208,7 @@ char *refs_resolve_refdup(struct ref_store *refs,
 char *resolve_refdup(const char *refname, int resolve_flags,
 		     struct object_id *oid, int *flags)
 {
-	return refs_resolve_refdup(get_main_ref_store(),
+	return refs_resolve_refdup(get_main_ref_store(the_repository),
 				   refname, resolve_flags,
 				   oid, flags);
 }
@@ -229,7 +230,7 @@ int refs_read_ref_full(struct ref_store *refs, const char *refname,
 
 int read_ref_full(const char *refname, int resolve_flags, struct object_id *oid, int *flags)
 {
-	return refs_read_ref_full(get_main_ref_store(), refname,
+	return refs_read_ref_full(get_main_ref_store(the_repository), refname,
 				  resolve_flags, oid, flags);
 }
 
@@ -376,7 +377,7 @@ int refs_for_each_tag_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data)
 
 int for_each_tag_ref(each_ref_fn fn, void *cb_data)
 {
-	return refs_for_each_tag_ref(get_main_ref_store(), fn, cb_data);
+	return refs_for_each_tag_ref(get_main_ref_store(the_repository), fn, cb_data);
 }
 
 int refs_for_each_branch_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data)
@@ -386,7 +387,7 @@ int refs_for_each_branch_ref(struct ref_store *refs, each_ref_fn fn, void *cb_da
 
 int for_each_branch_ref(each_ref_fn fn, void *cb_data)
 {
-	return refs_for_each_branch_ref(get_main_ref_store(), fn, cb_data);
+	return refs_for_each_branch_ref(get_main_ref_store(the_repository), fn, cb_data);
 }
 
 int refs_for_each_remote_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data)
@@ -396,7 +397,7 @@ int refs_for_each_remote_ref(struct ref_store *refs, each_ref_fn fn, void *cb_da
 
 int for_each_remote_ref(each_ref_fn fn, void *cb_data)
 {
-	return refs_for_each_remote_ref(get_main_ref_store(), fn, cb_data);
+	return refs_for_each_remote_ref(get_main_ref_store(the_repository), fn, cb_data);
 }
 
 int head_ref_namespaced(each_ref_fn fn, void *cb_data)
@@ -731,7 +732,7 @@ int refs_delete_ref(struct ref_store *refs, const char *msg,
 	struct strbuf err = STRBUF_INIT;
 
 	if (ref_type(refname) == REF_TYPE_PSEUDOREF) {
-		assert(refs == get_main_ref_store());
+		assert(refs == get_main_ref_store(the_repository));
 		return delete_pseudoref(refname, old_oid);
 	}
 
@@ -753,7 +754,7 @@ int refs_delete_ref(struct ref_store *refs, const char *msg,
 int delete_ref(const char *msg, const char *refname,
 	       const struct object_id *old_oid, unsigned int flags)
 {
-	return refs_delete_ref(get_main_ref_store(), msg, refname,
+	return refs_delete_ref(get_main_ref_store(the_repository), msg, refname,
 			       old_oid, flags);
 }
 
@@ -929,7 +930,7 @@ struct ref_transaction *ref_store_transaction_begin(struct ref_store *refs,
 
 struct ref_transaction *ref_transaction_begin(struct strbuf *err)
 {
-	return ref_store_transaction_begin(get_main_ref_store(), err);
+	return ref_store_transaction_begin(get_main_ref_store(the_repository), err);
 }
 
 void ref_transaction_free(struct ref_transaction *transaction)
@@ -1061,7 +1062,7 @@ int refs_update_ref(struct ref_store *refs, const char *msg,
 	int ret = 0;
 
 	if (ref_type(refname) == REF_TYPE_PSEUDOREF) {
-		assert(refs == get_main_ref_store());
+		assert(refs == get_main_ref_store(the_repository));
 		ret = write_pseudoref(refname, new_oid, old_oid, &err);
 	} else {
 		t = ref_store_transaction_begin(refs, &err);
@@ -1100,7 +1101,7 @@ int update_ref(const char *msg, const char *refname,
 	       const struct object_id *old_oid,
 	       unsigned int flags, enum action_on_err onerr)
 {
-	return refs_update_ref(get_main_ref_store(), msg, refname, new_oid,
+	return refs_update_ref(get_main_ref_store(the_repository), msg, refname, new_oid,
 			       old_oid, flags, onerr);
 }
 
@@ -1321,7 +1322,7 @@ int refs_head_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data)
 
 int head_ref(each_ref_fn fn, void *cb_data)
 {
-	return refs_head_ref(get_main_ref_store(), fn, cb_data);
+	return refs_head_ref(get_main_ref_store(the_repository), fn, cb_data);
 }
 
 struct ref_iterator *refs_ref_iterator_begin(
@@ -1380,7 +1381,7 @@ int refs_for_each_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data)
 
 int for_each_ref(each_ref_fn fn, void *cb_data)
 {
-	return refs_for_each_ref(get_main_ref_store(), fn, cb_data);
+	return refs_for_each_ref(get_main_ref_store(the_repository), fn, cb_data);
 }
 
 int refs_for_each_ref_in(struct ref_store *refs, const char *prefix,
@@ -1391,7 +1392,7 @@ int refs_for_each_ref_in(struct ref_store *refs, const char *prefix,
 
 int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data)
 {
-	return refs_for_each_ref_in(get_main_ref_store(), prefix, fn, cb_data);
+	return refs_for_each_ref_in(get_main_ref_store(the_repository), prefix, fn, cb_data);
 }
 
 int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data, unsigned int broken)
@@ -1400,7 +1401,7 @@ int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data, unsig
 
 	if (broken)
 		flag = DO_FOR_EACH_INCLUDE_BROKEN;
-	return do_for_each_ref(get_main_ref_store(),
+	return do_for_each_ref(get_main_ref_store(the_repository),
 			       prefix, fn, 0, flag, cb_data);
 }
 
@@ -1417,7 +1418,7 @@ int refs_for_each_fullref_in(struct ref_store *refs, const char *prefix,
 
 int for_each_replace_ref_the_repository(each_ref_fn fn, void *cb_data)
 {
-	return do_for_each_ref(get_main_ref_store(),
+	return do_for_each_ref(get_main_ref_store(the_repository),
 			       git_replace_ref_base, fn,
 			       strlen(git_replace_ref_base),
 			       DO_FOR_EACH_INCLUDE_BROKEN, cb_data);
@@ -1428,7 +1429,7 @@ int for_each_namespaced_ref(each_ref_fn fn, void *cb_data)
 	struct strbuf buf = STRBUF_INIT;
 	int ret;
 	strbuf_addf(&buf, "%srefs/", get_git_namespace());
-	ret = do_for_each_ref(get_main_ref_store(),
+	ret = do_for_each_ref(get_main_ref_store(the_repository),
 			      buf.buf, fn, 0, 0, cb_data);
 	strbuf_release(&buf);
 	return ret;
@@ -1442,7 +1443,7 @@ int refs_for_each_rawref(struct ref_store *refs, each_ref_fn fn, void *cb_data)
 
 int for_each_rawref(each_ref_fn fn, void *cb_data)
 {
-	return refs_for_each_rawref(get_main_ref_store(), fn, cb_data);
+	return refs_for_each_rawref(get_main_ref_store(the_repository), fn, cb_data);
 }
 
 int refs_read_raw_ref(struct ref_store *ref_store,
@@ -1548,7 +1549,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
 /* backend functions */
 int refs_init_db(struct strbuf *err)
 {
-	struct ref_store *refs = get_main_ref_store();
+	struct ref_store *refs = get_main_ref_store(the_repository);
 
 	return refs->be->init_db(refs, err);
 }
@@ -1556,7 +1557,7 @@ int refs_init_db(struct strbuf *err)
 const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
 			       struct object_id *oid, int *flags)
 {
-	return refs_resolve_ref_unsafe(get_main_ref_store(), refname,
+	return refs_resolve_ref_unsafe(get_main_ref_store(the_repository), refname,
 				       resolve_flags, oid, flags);
 }
 
@@ -1652,7 +1653,7 @@ static struct ref_store *ref_store_init(const char *gitdir,
 	return refs;
 }
 
-struct ref_store *get_main_ref_store(void)
+struct ref_store *get_main_ref_store_the_repository(void)
 {
 	if (main_ref_store)
 		return main_ref_store;
@@ -1727,7 +1728,7 @@ struct ref_store *get_worktree_ref_store(const struct worktree *wt)
 	const char *id;
 
 	if (wt->is_current)
-		return get_main_ref_store();
+		return get_main_ref_store(the_repository);
 
 	id = wt->id ? wt->id : "/";
 	refs = lookup_ref_store_map(&worktree_ref_stores, id);
@@ -1783,7 +1784,7 @@ int refs_peel_ref(struct ref_store *refs, const char *refname,
 
 int peel_ref(const char *refname, struct object_id *oid)
 {
-	return refs_peel_ref(get_main_ref_store(), refname, oid);
+	return refs_peel_ref(get_main_ref_store(the_repository), refname, oid);
 }
 
 int refs_create_symref(struct ref_store *refs,
@@ -1799,7 +1800,7 @@ int refs_create_symref(struct ref_store *refs,
 int create_symref(const char *ref_target, const char *refs_heads_master,
 		  const char *logmsg)
 {
-	return refs_create_symref(get_main_ref_store(), ref_target,
+	return refs_create_symref(get_main_ref_store(the_repository), ref_target,
 				  refs_heads_master, logmsg);
 }
 
@@ -2007,7 +2008,7 @@ int refs_for_each_reflog(struct ref_store *refs, each_ref_fn fn, void *cb_data)
 
 int for_each_reflog(each_ref_fn fn, void *cb_data)
 {
-	return refs_for_each_reflog(get_main_ref_store(), fn, cb_data);
+	return refs_for_each_reflog(get_main_ref_store(the_repository), fn, cb_data);
 }
 
 int refs_for_each_reflog_ent_reverse(struct ref_store *refs,
@@ -2022,7 +2023,7 @@ int refs_for_each_reflog_ent_reverse(struct ref_store *refs,
 int for_each_reflog_ent_reverse(const char *refname, each_reflog_ent_fn fn,
 				void *cb_data)
 {
-	return refs_for_each_reflog_ent_reverse(get_main_ref_store(),
+	return refs_for_each_reflog_ent_reverse(get_main_ref_store(the_repository),
 						refname, fn, cb_data);
 }
 
@@ -2035,7 +2036,7 @@ int refs_for_each_reflog_ent(struct ref_store *refs, const char *refname,
 int for_each_reflog_ent(const char *refname, each_reflog_ent_fn fn,
 			void *cb_data)
 {
-	return refs_for_each_reflog_ent(get_main_ref_store(), refname,
+	return refs_for_each_reflog_ent(get_main_ref_store(the_repository), refname,
 					fn, cb_data);
 }
 
@@ -2046,7 +2047,7 @@ int refs_reflog_exists(struct ref_store *refs, const char *refname)
 
 int reflog_exists(const char *refname)
 {
-	return refs_reflog_exists(get_main_ref_store(), refname);
+	return refs_reflog_exists(get_main_ref_store(the_repository), refname);
 }
 
 int refs_create_reflog(struct ref_store *refs, const char *refname,
@@ -2058,7 +2059,7 @@ int refs_create_reflog(struct ref_store *refs, const char *refname,
 int safe_create_reflog(const char *refname, int force_create,
 		       struct strbuf *err)
 {
-	return refs_create_reflog(get_main_ref_store(), refname,
+	return refs_create_reflog(get_main_ref_store(the_repository), refname,
 				  force_create, err);
 }
 
@@ -2069,7 +2070,7 @@ int refs_delete_reflog(struct ref_store *refs, const char *refname)
 
 int delete_reflog(const char *refname)
 {
-	return refs_delete_reflog(get_main_ref_store(), refname);
+	return refs_delete_reflog(get_main_ref_store(the_repository), refname);
 }
 
 int refs_reflog_expire(struct ref_store *refs,
@@ -2092,7 +2093,7 @@ int reflog_expire(const char *refname, const struct object_id *oid,
 		  reflog_expiry_cleanup_fn cleanup_fn,
 		  void *policy_cb_data)
 {
-	return refs_reflog_expire(get_main_ref_store(),
+	return refs_reflog_expire(get_main_ref_store(the_repository),
 				  refname, oid, flags,
 				  prepare_fn, should_prune_fn,
 				  cleanup_fn, policy_cb_data);
@@ -2115,7 +2116,7 @@ int refs_delete_refs(struct ref_store *refs, const char *msg,
 int delete_refs(const char *msg, struct string_list *refnames,
 		unsigned int flags)
 {
-	return refs_delete_refs(get_main_ref_store(), msg, refnames, flags);
+	return refs_delete_refs(get_main_ref_store(the_repository), msg, refnames, flags);
 }
 
 int refs_rename_ref(struct ref_store *refs, const char *oldref,
@@ -2126,7 +2127,7 @@ int refs_rename_ref(struct ref_store *refs, const char *oldref,
 
 int rename_ref(const char *oldref, const char *newref, const char *logmsg)
 {
-	return refs_rename_ref(get_main_ref_store(), oldref, newref, logmsg);
+	return refs_rename_ref(get_main_ref_store(the_repository), oldref, newref, logmsg);
 }
 
 int refs_copy_existing_ref(struct ref_store *refs, const char *oldref,
@@ -2137,5 +2138,5 @@ int refs_copy_existing_ref(struct ref_store *refs, const char *oldref,
 
 int copy_existing_ref(const char *oldref, const char *newref, const char *logmsg)
 {
-	return refs_copy_existing_ref(get_main_ref_store(), oldref, newref, logmsg);
+	return refs_copy_existing_ref(get_main_ref_store(the_repository), oldref, newref, logmsg);
 }
diff --git a/refs.h b/refs.h
index 546fa9e65a..ab3d2bec2f 100644
--- a/refs.h
+++ b/refs.h
@@ -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
diff --git a/revision.c b/revision.c
index 9ede92c09e..e98bdf2ac7 100644
--- a/revision.c
+++ b/revision.c
@@ -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!
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index 4b96dfe12f..93ea6f781e 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -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;
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 053/194] replace-object: add repository argument to register_replace_object
  2018-02-05 23:54 ` Stefan Beller
                     ` (30 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 052/194] refs: add repository argument to get_main_ref_store Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 054/194] replace-object: add repository argument to register_replace_ref Stefan Beller
                     ` (44 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 replace-object.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/replace-object.c b/replace-object.c
index 102e009927..1479530d34 100644
--- a/replace-object.c
+++ b/replace-object.c
@@ -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;
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 054/194] replace-object: add repository argument to register_replace_ref
  2018-02-05 23:54 ` Stefan Beller
                     ` (31 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 053/194] replace-object: add repository argument to register_replace_object Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 055/194] replace-object: add repository argument to replace_object_pos Stefan Beller
                     ` (43 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: 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.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 replace-object.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/replace-object.c b/replace-object.c
index 1479530d34..8d3e0a30fb 100644
--- a/replace-object.c
+++ b/replace-object.c
@@ -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;
 }
 
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 055/194] replace-object: add repository argument to replace_object_pos
  2018-02-05 23:54 ` Stefan Beller
                     ` (32 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 054/194] replace-object: add repository argument to register_replace_ref Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 056/194] replace-object: allow replace_object_pos to handle arbitrary repositories Stefan Beller
                     ` (42 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 replace-object.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/replace-object.c b/replace-object.c
index 8d3e0a30fb..4a07f82aa0 100644
--- a/replace-object.c
+++ b/replace-object.c
@@ -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);
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 056/194] replace-object: allow replace_object_pos to handle arbitrary repositories
  2018-02-05 23:54 ` Stefan Beller
                     ` (33 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 055/194] replace-object: add repository argument to replace_object_pos Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 057/194] replace-object: allow register_replace_object " Stefan Beller
                     ` (41 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 replace-object.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/replace-object.c b/replace-object.c
index 4a07f82aa0..c30bee2e69 100644
--- a/replace-object.c
+++ b/replace-object.c
@@ -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);
 }
 
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 057/194] replace-object: allow register_replace_object to handle arbitrary repositories
  2018-02-05 23:54 ` Stefan Beller
                     ` (34 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 056/194] replace-object: allow replace_object_pos to handle arbitrary repositories Stefan Beller
@ 2018-02-05 23:55   ` " Stefan Beller
  2018-02-05 23:55   ` [PATCH 058/194] replace-object: add repository argument to prepare_replace_object Stefan Beller
                     ` (40 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 replace-object.c | 33 ++++++++++++++++-----------------
 1 file changed, 16 insertions(+), 17 deletions(-)

diff --git a/replace-object.c b/replace-object.c
index c30bee2e69..31b6b3044e 100644
--- a/replace-object.c
+++ b/replace-object.c
@@ -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;
 }
 
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 058/194] replace-object: add repository argument to prepare_replace_object
  2018-02-05 23:54 ` Stefan Beller
                     ` (35 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 057/194] replace-object: allow register_replace_object " Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 059/194] refs: store the main ref store inside the repository struct Stefan Beller
                     ` (39 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 replace-object.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/replace-object.c b/replace-object.c
index 31b6b3044e..cba88f50e3 100644
--- a/replace-object.c
+++ b/replace-object.c
@@ -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 {
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 059/194] refs: store the main ref store inside the repository struct
  2018-02-05 23:54 ` Stefan Beller
                     ` (36 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 058/194] replace-object: add repository argument to prepare_replace_object Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-06  4:27     ` Eric Sunshine
  2018-02-05 23:55   ` [PATCH 060/194] refs: allow for_each_replace_ref to handle arbitrary repositories Stefan Beller
                     ` (38 subsequent siblings)
  76 siblings, 1 reply; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 refs.c       | 13 +++++--------
 refs.h       |  4 +---
 repository.c |  2 +-
 repository.h |  5 +++++
 4 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/refs.c b/refs.c
index c2dee7a69a..f079d65030 100644
--- a/refs.c
+++ b/refs.c
@@ -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;
 }
 
 /*
diff --git a/refs.h b/refs.h
index ab3d2bec2f..f5ab68c0ed 100644
--- a/refs.h
+++ b/refs.h
@@ -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
diff --git a/repository.c b/repository.c
index 0ec9648f53..6f85fade82 100644
--- a/repository.c
+++ b/repository.c
@@ -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;
diff --git a/repository.h b/repository.h
index ba7b3b7cb9..727ddcea5b 100644
--- a/repository.h
+++ b/repository.h
@@ -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.
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 060/194] refs: allow for_each_replace_ref to handle arbitrary repositories
  2018-02-05 23:54 ` Stefan Beller
                     ` (37 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 059/194] refs: store the main ref store inside the repository struct Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 061/194] replace-object: allow prepare_replace_object " Stefan Beller
                     ` (37 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 refs.c | 4 ++--
 refs.h | 4 +---
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/refs.c b/refs.c
index f079d65030..e534ff4256 100644
--- a/refs.c
+++ b/refs.c
@@ -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);
diff --git a/refs.h b/refs.h
index f5ab68c0ed..15f3a91cc4 100644
--- a/refs.h
+++ b/refs.h
@@ -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);
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 061/194] replace-object: allow prepare_replace_object to handle arbitrary repositories
  2018-02-05 23:54 ` Stefan Beller
                     ` (38 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 060/194] refs: allow for_each_replace_ref to handle arbitrary repositories Stefan Beller
@ 2018-02-05 23:55   ` " Stefan Beller
  2018-02-05 23:55   ` [PATCH 062/194] replace_object: allow do_lookup_replace_object " Stefan Beller
                     ` (36 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 replace-object.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/replace-object.c b/replace-object.c
index cba88f50e3..d9250a7cf8 100644
--- a/replace-object.c
+++ b/replace-object.c
@@ -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 */
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 062/194] replace_object: allow do_lookup_replace_object to handle arbitrary repositories
  2018-02-05 23:54 ` Stefan Beller
                     ` (39 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 061/194] replace-object: allow prepare_replace_object " Stefan Beller
@ 2018-02-05 23:55   ` " Stefan Beller
  2018-02-05 23:55   ` [PATCH 063/194] replace-object: add repository argument to lookup_replace_object Stefan Beller
                     ` (35 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 replace-object.c | 9 +++++----
 replace-object.h | 3 +--
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/replace-object.c b/replace-object.c
index d9250a7cf8..a6a34217d8 100644
--- a/replace-object.c
+++ b/replace-object.c
@@ -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;
diff --git a/replace-object.h b/replace-object.h
index 8af730f5e3..67a433d5a5 100644
--- a/replace-object.h
+++ b/replace-object.h
@@ -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
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 063/194] replace-object: add repository argument to lookup_replace_object
  2018-02-05 23:54 ` Stefan Beller
                     ` (40 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 062/194] replace_object: allow do_lookup_replace_object " Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 064/194] repository: allow lookup_replace_object to handle arbitrary repositories Stefan Beller
                     ` (34 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 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(-)

diff --git a/builtin/mktag.c b/builtin/mktag.c
index 93934e8e4b..ab41735f2a 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -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))
diff --git a/object.c b/object.c
index fc0ccbefef..a5cafb10e7 100644
--- a/object.c
+++ b/object.c
@@ -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;
 
diff --git a/replace-object.h b/replace-object.h
index 67a433d5a5..c61ee66e95 100644
--- a/replace-object.h
+++ b/replace-object.h
@@ -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 &&
diff --git a/sha1_file.c b/sha1_file.c
index 8ee86f8ede..a6df4b61c7 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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);
diff --git a/streaming.c b/streaming.c
index c47600e719..bc3c4811ca 100644
--- a/streaming.c
+++ b/streaming.c
@@ -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)
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 064/194] repository: allow lookup_replace_object to handle arbitrary repositories
  2018-02-05 23:54 ` Stefan Beller
                     ` (41 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 063/194] replace-object: add repository argument to lookup_replace_object Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 065/194] object-store: add repository argument to sha1_object_info Stefan Beller
                     ` (33 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 replace-object.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/replace-object.h b/replace-object.h
index c61ee66e95..f4666afc2a 100644
--- a/replace-object.h
+++ b/replace-object.h
@@ -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 */
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 065/194] object-store: add repository argument to sha1_object_info
  2018-02-05 23:54 ` Stefan Beller
                     ` (42 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 064/194] repository: allow lookup_replace_object to handle arbitrary repositories Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-06  1:55     ` brian m. carlson
  2018-02-05 23:55   ` [PATCH 066/194] pack: add repository argument to retry_bad_packed_offset Stefan Beller
                     ` (32 subsequent siblings)
  76 siblings, 1 reply; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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`.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 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

diff --git a/archive-tar.c b/archive-tar.c
index 909347c108..b10c9b8911 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -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)) {
diff --git a/archive-zip.c b/archive-zip.c
index 233fed3a61..03321b9777 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -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) :
diff --git a/blame.c b/blame.c
index 61f0f6bb40..f95a53898d 100644
--- a/blame.c
+++ b/blame.c
@@ -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:
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index fdc70aa419..96c834b8f4 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -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
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index f76b7bda79..d4e53908c6 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -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));
 
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 9b7202953b..276beebbb1 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -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));
 
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 920cc50923..f5e3c51077 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -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);
 	}
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 1902d4e096..b9851ad69d 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -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)
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index 78fcced566..d929da03b4 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -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
diff --git a/builtin/mktree.c b/builtin/mktree.c
index 0f66946618..ccb3a7a897 100644
--- a/builtin/mktree.c
+++ b/builtin/mktree.c
@@ -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 */
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 7cb73c29ac..79ec5c6842 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -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);
diff --git a/builtin/prune.c b/builtin/prune.c
index 52091f299e..7891048b35 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -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");
 	}
diff --git a/builtin/replace.c b/builtin/replace.c
index 6d27dd73f0..25322d2f73 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -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));
 
diff --git a/builtin/tag.c b/builtin/tag.c
index 7ed3506fff..014d7c9e9b 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -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");
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 6d03ea2670..ee707068b3 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -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;
diff --git a/contrib/coccinelle/sha1_object_info.cocci b/contrib/coccinelle/sha1_object_info.cocci
new file mode 100644
index 0000000000..800e0581e5
--- /dev/null
+++ b/contrib/coccinelle/sha1_object_info.cocci
@@ -0,0 +1,7 @@
+@@
+expression E;
+expression F;
+@@
+ sha1_object_info(
++the_repository,
+ E, F)
diff --git a/diff.c b/diff.c
index e89c7d9919..08bff6e720 100644
--- a/diff.c
+++ b/diff.c
@@ -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));
diff --git a/fast-import.c b/fast-import.c
index 39cd0b7540..2542f600ef 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -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! */
diff --git a/list-objects-filter.c b/list-objects-filter.c
index 4356c45368..180d8729d9 100644
--- a/list-objects-filter.c
+++ b/list-objects-filter.c
@@ -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
diff --git a/object-store.h b/object-store.h
index e1e592bdd5..4ff60e3be0 100644
--- a/object-store.h
+++ b/object-store.h
@@ -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);
diff --git a/object.c b/object.c
index a5cafb10e7..40f7c7bdab 100644
--- a/object.c
+++ b/object.c
@@ -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;
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 6a656104af..f684ed5ea2 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -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;
 		}
diff --git a/packfile.c b/packfile.c
index b73814f2ce..a1c1b1a42e 100644
--- a/packfile.c
+++ b/packfile.c
@@ -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;
diff --git a/reachable.c b/reachable.c
index ac5224b9a5..7e7b9525c0 100644
--- a/reachable.c
+++ b/reachable.c
@@ -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));
 
diff --git a/refs.c b/refs.c
index e534ff4256..ddcb4a908f 100644
--- a/refs.c
+++ b/refs.c
@@ -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;
 	}
diff --git a/remote.c b/remote.c
index 5112f370c3..fd8cd8ce77 100644
--- a/remote.c
+++ b/remote.c
@@ -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;
diff --git a/sequencer.c b/sequencer.c
index 234addd4e7..311f00acda 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -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));
 			}
diff --git a/sha1_file.c b/sha1_file.c
index a6df4b61c7..01bdb3cd7a 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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)
diff --git a/sha1_name.c b/sha1_name.c
index 03ce2ff7f2..190710c638 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -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) {
diff --git a/submodule.c b/submodule.c
index f7736ec4b5..dc57c176e8 100644
--- a/submodule.c
+++ b/submodule.c
@@ -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:
diff --git a/tag.c b/tag.c
index 30798abf1f..7b32afd123 100644
--- a/tag.c
+++ b/tag.c
@@ -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 ?
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 066/194] pack: add repository argument to retry_bad_packed_offset
  2018-02-05 23:54 ` Stefan Beller
                     ` (43 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 065/194] object-store: add repository argument to sha1_object_info Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 067/194] pack: add repository argument to packed_to_object_type Stefan Beller
                     ` (31 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 packfile.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/packfile.c b/packfile.c
index a1c1b1a42e..66391b8a6f 100644
--- a/packfile.c
+++ b/packfile.c
@@ -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;
 	}
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 067/194] pack: add repository argument to packed_to_object_type
  2018-02-05 23:54 ` Stefan Beller
                     ` (44 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 066/194] pack: add repository argument to retry_bad_packed_offset Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 068/194] pack: add repository argument to packed_object_info Stefan Beller
                     ` (30 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 packfile.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/packfile.c b/packfile.c
index 66391b8a6f..250c9af1a7 100644
--- a/packfile.c
+++ b/packfile.c
@@ -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) {
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 068/194] pack: add repository argument to packed_object_info
  2018-02-05 23:54 ` Stefan Beller
                     ` (45 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 067/194] pack: add repository argument to packed_to_object_type Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 069/194] pack: add repository argument to find_pack_entry Stefan Beller
                     ` (29 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 builtin/pack-objects.c | 3 ++-
 packfile.c             | 4 ++--
 packfile.h             | 3 ++-
 sha1_file.c            | 2 +-
 4 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 79ec5c6842..4e59e496dc 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -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.
diff --git a/packfile.c b/packfile.c
index 250c9af1a7..61e84a789c 100644
--- a/packfile.c
+++ b/packfile.c
@@ -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;
diff --git a/packfile.h b/packfile.h
index 0c314eea93..bb1d92b849 100644
--- a/packfile.h
+++ b/packfile.h
@@ -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);
diff --git a/sha1_file.c b/sha1_file.c
index 01bdb3cd7a..299e8be72c 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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,
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 069/194] pack: add repository argument to find_pack_entry
  2018-02-05 23:54 ` Stefan Beller
                     ` (46 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 068/194] pack: add repository argument to packed_object_info Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 070/194] packfile: add repository argument to read_object Stefan Beller
                     ` (28 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 packfile.c  | 4 ++--
 packfile.h  | 3 ++-
 sha1_file.c | 6 +++---
 3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/packfile.c b/packfile.c
index 61e84a789c..f641f6329a 100644
--- a/packfile.c
+++ b/packfile.c
@@ -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)
diff --git a/packfile.h b/packfile.h
index bb1d92b849..b42e5c2db1 100644
--- a/packfile.h
+++ b/packfile.h
@@ -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);
 
diff --git a/sha1_file.c b/sha1_file.c
index 299e8be72c..7e06ece5f3 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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;
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 070/194] packfile: add repository argument to read_object
  2018-02-05 23:54 ` Stefan Beller
                     ` (47 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 069/194] pack: add repository argument to find_pack_entry Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 071/194] packfile: add repository argument to unpack_entry Stefan Beller
                     ` (27 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 packfile.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/packfile.c b/packfile.c
index f641f6329a..56b2db8b06 100644
--- a/packfile.c
+++ b/packfile.c
@@ -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;
 			}
 		}
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 071/194] packfile: add repository argument to unpack_entry
  2018-02-05 23:54 ` Stefan Beller
                     ` (48 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 070/194] packfile: add repository argument to read_object Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 072/194] packfile: add repository argument to cache_or_unpack_entry Stefan Beller
                     ` (26 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 fast-import.c | 2 +-
 pack-check.c  | 3 ++-
 packfile.c    | 7 ++++---
 packfile.h    | 3 ++-
 4 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/fast-import.c b/fast-import.c
index 2542f600ef..5618087015 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -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)
diff --git a/pack-check.c b/pack-check.c
index c80c3ed8fd..25afd59c7d 100644
--- a/pack-check.c
+++ b/pack-check.c
@@ -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;
 		}
 
diff --git a/packfile.c b/packfile.c
index 56b2db8b06..69a1cedbe1 100644
--- a/packfile.c
+++ b/packfile.c
@@ -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;
diff --git a/packfile.h b/packfile.h
index b42e5c2db1..615c58cbac 100644
--- a/packfile.h
+++ b/packfile.h
@@ -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 *);
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 072/194] packfile: add repository argument to cache_or_unpack_entry
  2018-02-05 23:54 ` Stefan Beller
                     ` (49 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 071/194] packfile: add repository argument to unpack_entry Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 073/194] pack: allow find_pack_entry to handle arbitrary repositories Stefan Beller
                     ` (25 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 packfile.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/packfile.c b/packfile.c
index 69a1cedbe1..9f7ca8f211 100644
--- a/packfile.c
+++ b/packfile.c
@@ -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;
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 073/194] pack: allow find_pack_entry to handle arbitrary repositories
  2018-02-05 23:54 ` Stefan Beller
                     ` (50 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 072/194] packfile: add repository argument to cache_or_unpack_entry Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 074/194] object-store: allow sha1_object_info " Stefan Beller
                     ` (24 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 packfile.c | 12 +++++++-----
 packfile.h |  5 +++--
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/packfile.c b/packfile.c
index 9f7ca8f211..178d2e0ddd 100644
--- a/packfile.c
+++ b/packfile.c
@@ -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;
 		}
 	}
diff --git a/packfile.h b/packfile.h
index 615c58cbac..6d10871d25 100644
--- a/packfile.h
+++ b/packfile.h
@@ -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);
 
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 074/194] object-store: allow sha1_object_info to handle arbitrary repositories
  2018-02-05 23:54 ` Stefan Beller
                     ` (51 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 073/194] pack: allow find_pack_entry to handle arbitrary repositories Stefan Beller
@ 2018-02-05 23:55   ` " Stefan Beller
  2018-02-05 23:55   ` [PATCH 075/194] fetch, push: do not use submodule as alternate in has_commits check Stefan Beller
                     ` (23 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 object-store.h | 13 ++++++-------
 packfile.c     | 58 ++++++++++++++++++++++++++++------------------------------
 packfile.h     |  8 ++++----
 sha1_file.c    | 24 +++++++++++++-----------
 4 files changed, 51 insertions(+), 52 deletions(-)

diff --git a/object-store.h b/object-store.h
index 4ff60e3be0..6930cfef82 100644
--- a/object-store.h
+++ b/object-store.h
@@ -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 */
diff --git a/packfile.c b/packfile.c
index 178d2e0ddd..6a8d5edf6d 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1082,9 +1082,9 @@ static const unsigned char *get_delta_base_sha1(struct packed_git *p,
 		return NULL;
 }
 
-#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)
+static int retry_bad_packed_offset(struct repository *r,
+				   struct packed_git *p,
+				   off_t obj_offset)
 {
 	int type;
 	struct revindex_entry *revidx;
@@ -1094,7 +1094,7 @@ static int retry_bad_packed_offset_the_repository(struct packed_git *p, off_t ob
 		return OBJ_BAD;
 	sha1 = nth_packed_object_sha1(p, revidx->nr);
 	mark_bad_packed_object(p, sha1);
-	type = sha1_object_info(the_repository, sha1, NULL);
+	type = sha1_object_info(r, sha1, NULL);
 	if (type <= OBJ_NONE)
 		return OBJ_BAD;
 	return type;
@@ -1102,13 +1102,12 @@ static int retry_bad_packed_offset_the_repository(struct packed_git *p, off_t ob
 
 #define POI_STACK_PREALLOC 64
 
-#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)
+static enum object_type packed_to_object_type(struct repository *r,
+					      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;
@@ -1135,7 +1134,7 @@ static enum object_type packed_to_object_type_the_repository(struct packed_git *
 		if (type <= OBJ_NONE) {
 			/* If getting the base itself fails, we first
 			 * retry the base, otherwise unwind */
-			type = retry_bad_packed_offset(the_repository, p, base_offset);
+			type = retry_bad_packed_offset(r, p, base_offset);
 			if (type > OBJ_NONE)
 				goto out;
 			goto unwind;
@@ -1163,7 +1162,7 @@ static enum object_type packed_to_object_type_the_repository(struct packed_git *
 unwind:
 	while (poi_stack_nr) {
 		obj_offset = poi_stack[--poi_stack_nr];
-		type = retry_bad_packed_offset(the_repository, p, obj_offset);
+		type = retry_bad_packed_offset(r, p, obj_offset);
 		if (type > OBJ_NONE)
 			goto out;
 	}
@@ -1250,15 +1249,15 @@ static void detach_delta_base_cache_entry(struct delta_base_cache_entry *ent)
 	free(ent);
 }
 
-#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)
+static void *cache_or_unpack_entry(struct repository *r, struct packed_git *p,
+				   off_t base_offset, unsigned long *base_size,
+				   enum object_type *type)
 {
 	struct delta_base_cache_entry *ent;
 
 	ent = get_delta_base_cache_entry(p, base_offset);
 	if (!ent)
-		return unpack_entry(the_repository, p, base_offset, type, base_size);
+		return unpack_entry(r, p, base_offset, type, base_size);
 
 	if (type)
 		*type = ent->type;
@@ -1312,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_the_repository(struct packed_git *p, off_t obj_offset,
-				      struct object_info *oi)
+int packed_object_info(struct repository *r, struct packed_git *p,
+		       off_t obj_offset, struct object_info *oi)
 {
 	struct pack_window *w_curs = NULL;
 	unsigned long size;
@@ -1325,7 +1324,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(the_repository, p, obj_offset, oi->sizep,
+		*oi->contentp = cache_or_unpack_entry(r, p, obj_offset, oi->sizep,
 						      &type);
 		if (!*oi->contentp)
 			type = OBJ_BAD;
@@ -1359,7 +1358,7 @@ int packed_object_info_the_repository(struct packed_git *p, off_t obj_offset,
 
 	if (oi->typep || oi->typename) {
 		enum object_type ptot;
-		ptot = packed_to_object_type(the_repository, p, obj_offset,
+		ptot = packed_to_object_type(r, p, obj_offset,
 					     type, &w_curs, curpos);
 		if (oi->typep)
 			*oi->typep = ptot;
@@ -1448,10 +1447,10 @@ struct unpack_entry_stack_ent {
 	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)
+static void *read_object(struct repository *r,
+			 const unsigned char *sha1,
+			 enum object_type *type,
+			 unsigned long *size)
 {
 	struct object_info oi = OBJECT_INFO_INIT;
 	void *content;
@@ -1459,14 +1458,13 @@ static void *read_object_the_repository(const unsigned char *sha1,
 	oi.sizep = size;
 	oi.contentp = &content;
 
-	if (sha1_object_info_extended(the_repository, sha1, &oi, 0) < 0)
+	if (sha1_object_info_extended(r, sha1, &oi, 0) < 0)
 		return NULL;
 	return content;
 }
 
-void *unpack_entry_the_repository(struct packed_git *p, off_t obj_offset,
-				  enum object_type *final_type,
-				  unsigned long *final_size)
+void *unpack_entry(struct repository *r, 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;
@@ -1596,7 +1594,7 @@ void *unpack_entry_the_repository(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(the_repository, base_sha1, &type, &base_size);
+				base = read_object(r, base_sha1, &type, &base_size);
 				external_base = base;
 			}
 		}
diff --git a/packfile.h b/packfile.h
index 6d10871d25..f8d2825cce 100644
--- a/packfile.h
+++ b/packfile.h
@@ -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);
diff --git a/sha1_file.c b/sha1_file.c
index 7e06ece5f3..c296b76329 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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;
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 075/194] fetch, push: do not use submodule as alternate in has_commits check
  2018-02-05 23:54 ` Stefan Beller
                     ` (52 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 074/194] object-store: allow sha1_object_info " Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-06  4:20     ` Eric Sunshine
  2018-02-05 23:55   ` [PATCH 076/194] push: add test showing bad interaction of replace refs and submodules Stefan Beller
                     ` (22 subsequent siblings)
  76 siblings, 1 reply; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 submodule.c | 52 ++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 38 insertions(+), 14 deletions(-)

diff --git a/submodule.c b/submodule.c
index dc57c176e8..1504812842 100644
--- a/submodule.c
+++ b/submodule.c
@@ -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;
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 076/194] push: add test showing bad interaction of replace refs and submodules
  2018-02-05 23:54 ` Stefan Beller
                     ` (53 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 075/194] fetch, push: do not use submodule as alternate in has_commits check Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-06  2:20     ` brian m. carlson
  2018-02-05 23:55   ` [PATCH 077/194] replace_object: allow register_replace_ref to handle arbitrary repositories Stefan Beller
                     ` (21 subsequent siblings)
  76 siblings, 1 reply; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>

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!

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 t/t5531-deep-submodule-push.sh | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/t/t5531-deep-submodule-push.sh b/t/t5531-deep-submodule-push.sh
index 39cb2c1c34..8b2aa5a0f4 100755
--- a/t/t5531-deep-submodule-push.sh
+++ b/t/t5531-deep-submodule-push.sh
@@ -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 &&
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 077/194] replace_object: allow register_replace_ref to handle arbitrary repositories
  2018-02-05 23:54 ` Stefan Beller
                     ` (54 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 076/194] push: add test showing bad interaction of replace refs and submodules Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 078/194] cache.h: migrate the definition of object_id to object.h Stefan Beller
                     ` (20 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 replace-object.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/replace-object.c b/replace-object.c
index a6a34217d8..96d339729a 100644
--- a/replace-object.c
+++ b/replace-object.c
@@ -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;
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 078/194] cache.h: migrate the definition of object_id to object.h
  2018-02-05 23:54 ` Stefan Beller
                     ` (55 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 077/194] replace_object: allow register_replace_ref to handle arbitrary repositories Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 079/194] repository: introduce object parser field Stefan Beller
                     ` (19 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: 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.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 cache.h  | 13 +------------
 object.h | 12 ++++++++++++
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/cache.h b/cache.h
index 22404de92b..634172cec4 100644
--- a/cache.h
+++ b/cache.h
@@ -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)
diff --git a/object.h b/object.h
index f34461d4af..fbccb09257 100644
--- a/object.h
+++ b/object.h
@@ -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.
  */
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 079/194] repository: introduce object parser field
  2018-02-05 23:54 ` Stefan Beller
                     ` (56 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 078/194] cache.h: migrate the definition of object_id to object.h Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 080/194] object: add repository argument to parse_object Stefan Beller
                     ` (18 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 object-store.h |  4 ++--
 object.c       | 42 +++++++++++++++++++++---------------------
 object.h       |  7 +++++++
 repository.c   |  2 +-
 repository.h   | 14 ++++++++++++--
 5 files changed, 43 insertions(+), 26 deletions(-)

diff --git a/object-store.h b/object-store.h
index 6930cfef82..d009f952f8 100644
--- a/object-store.h
+++ b/object-store.h
@@ -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 {
diff --git a/object.c b/object.c
index 40f7c7bdab..18ea8cf574 100644
--- a/object.c
+++ b/object.c
@@ -7,17 +7,14 @@
 #include "commit.h"
 #include "tag.h"
 
-static struct object **obj_hash;
-static int nr_objs, obj_hash_size;
-
 unsigned int get_max_object_index(void)
 {
-	return obj_hash_size;
+	return the_repository->parsed_objects.obj_hash_size;
 }
 
 struct object *get_indexed_object(unsigned int idx)
 {
-	return obj_hash[idx];
+	return the_repository->parsed_objects.obj_hash[idx];
 }
 
 static const char *object_type_strings[] = {
@@ -89,15 +86,16 @@ struct object *lookup_object(const unsigned char *sha1)
 	unsigned int i, first;
 	struct object *obj;
 
-	if (!obj_hash)
+	if (!the_repository->parsed_objects.obj_hash)
 		return NULL;
 
-	first = i = hash_obj(sha1, obj_hash_size);
-	while ((obj = obj_hash[i]) != NULL) {
+	first = i = hash_obj(sha1,
+			     the_repository->parsed_objects.obj_hash_size);
+	while ((obj = the_repository->parsed_objects.obj_hash[i]) != NULL) {
 		if (!hashcmp(sha1, obj->oid.hash))
 			break;
 		i++;
-		if (i == obj_hash_size)
+		if (i == the_repository->parsed_objects.obj_hash_size)
 			i = 0;
 	}
 	if (obj && i != first) {
@@ -106,7 +104,8 @@ struct object *lookup_object(const unsigned char *sha1)
 		 * that we do not need to walk the hash table the next
 		 * time we look for it.
 		 */
-		SWAP(obj_hash[i], obj_hash[first]);
+		SWAP(the_repository->parsed_objects.obj_hash[i],
+		     the_repository->parsed_objects.obj_hash[first]);
 	}
 	return obj;
 }
@@ -123,19 +122,19 @@ static void grow_object_hash(void)
 	 * Note that this size must always be power-of-2 to match hash_obj
 	 * above.
 	 */
-	int new_hash_size = obj_hash_size < 32 ? 32 : 2 * obj_hash_size;
+	int new_hash_size = the_repository->parsed_objects.obj_hash_size < 32 ? 32 : 2 * the_repository->parsed_objects.obj_hash_size;
 	struct object **new_hash;
 
 	new_hash = xcalloc(new_hash_size, sizeof(struct object *));
-	for (i = 0; i < obj_hash_size; i++) {
-		struct object *obj = obj_hash[i];
+	for (i = 0; i < the_repository->parsed_objects.obj_hash_size; i++) {
+		struct object *obj = the_repository->parsed_objects.obj_hash[i];
 		if (!obj)
 			continue;
 		insert_obj_hash(obj, new_hash, new_hash_size);
 	}
-	free(obj_hash);
-	obj_hash = new_hash;
-	obj_hash_size = new_hash_size;
+	free(the_repository->parsed_objects.obj_hash);
+	the_repository->parsed_objects.obj_hash = new_hash;
+	the_repository->parsed_objects.obj_hash_size = new_hash_size;
 }
 
 void *create_object(const unsigned char *sha1, void *o)
@@ -146,11 +145,12 @@ void *create_object(const unsigned char *sha1, void *o)
 	obj->flags = 0;
 	hashcpy(obj->oid.hash, sha1);
 
-	if (obj_hash_size - 1 <= nr_objs * 2)
+	if (the_repository->parsed_objects.obj_hash_size - 1 <= the_repository->parsed_objects.nr_objs * 2)
 		grow_object_hash();
 
-	insert_obj_hash(obj, obj_hash, obj_hash_size);
-	nr_objs++;
+	insert_obj_hash(obj, the_repository->parsed_objects.obj_hash,
+			the_repository->parsed_objects.obj_hash_size);
+	the_repository->parsed_objects.nr_objs++;
 	return obj;
 }
 
@@ -430,8 +430,8 @@ void clear_object_flags(unsigned flags)
 {
 	int i;
 
-	for (i=0; i < obj_hash_size; i++) {
-		struct object *obj = obj_hash[i];
+	for (i=0; i < the_repository->parsed_objects.obj_hash_size; i++) {
+		struct object *obj = the_repository->parsed_objects.obj_hash[i];
 		if (obj)
 			obj->flags &= ~flags;
 	}
diff --git a/object.h b/object.h
index fbccb09257..2cff106ff7 100644
--- a/object.h
+++ b/object.h
@@ -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;
diff --git a/repository.c b/repository.c
index 6f85fade82..af62dfdc09 100644
--- a/repository.c
+++ b/repository.c
@@ -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;
diff --git a/repository.h b/repository.h
index 727ddcea5b..c8a34d1ac9 100644
--- a/repository.h
+++ b/repository.h
@@ -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.
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 080/194] object: add repository argument to parse_object
  2018-02-05 23:54 ` Stefan Beller
                     ` (57 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 079/194] repository: introduce object parser field Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 081/194] object: add repository argument to create_object Stefan Beller
                     ` (17 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 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

diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c
index b775a75647..1f78308e33 100644
--- a/builtin/diff-tree.c
+++ b/builtin/diff-tree.c
@@ -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)
diff --git a/builtin/diff.c b/builtin/diff.c
index 16bfb22f73..ed6092ef1a 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -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);
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index d4e53908c6..6140caf8d8 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -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;
 		}
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index 9dd5c85831..dd74251690 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -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;
diff --git a/builtin/fsck.c b/builtin/fsck.c
index f5e3c51077..9408ae5cc6 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -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));
diff --git a/builtin/log.c b/builtin/log.c
index de723fffc6..2c3579b1f7 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -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));
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index 9e088ebd11..c6b253eefb 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -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)
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 744fe29366..22d805a8ff 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -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.");
diff --git a/builtin/reflog.c b/builtin/reflog.c
index 4b525c4448..18145d5494 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -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) {
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index 969efde30c..3c2ae454ea 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -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)
diff --git a/bundle.c b/bundle.c
index d9376b7c77..1b5f1beb3b 100644
--- a/bundle.c
+++ b/bundle.c
@@ -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);
diff --git a/commit.c b/commit.c
index b60906d3f9..742d710c86 100644
--- a/commit.c
+++ b/commit.c
@@ -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);
diff --git a/contrib/coccinelle/object_parser.cocci b/contrib/coccinelle/object_parser.cocci
new file mode 100644
index 0000000000..a9afe4bf7a
--- /dev/null
+++ b/contrib/coccinelle/object_parser.cocci
@@ -0,0 +1,6 @@
+@@
+expression E;
+@@
+ parse_object(
++ the_repository,
+ E)
diff --git a/fetch-pack.c b/fetch-pack.c
index 9c189ff3ec..0f7aeabb64 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -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;
 
diff --git a/fsck.c b/fsck.c
index d106714bf5..843ddc1035 100644
--- a/fsck.c
+++ b/fsck.c
@@ -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:
diff --git a/http-backend.c b/http-backend.c
index 4950078c93..b76c8c4f3d 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -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;
 
diff --git a/http-push.c b/http-push.c
index 34c5d030b7..b4c3cd1cd7 100644
--- a/http-push.c
+++ b/http-push.c
@@ -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",
diff --git a/log-tree.c b/log-tree.c
index b2fff6b5f6..57d5e5f56d 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -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;
diff --git a/merge-recursive.c b/merge-recursive.c
index 620e4f653c..e2c434c305 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -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)
diff --git a/object.c b/object.c
index 18ea8cf574..c1154039df 100644
--- a/object.c
+++ b/object.c
@@ -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;
diff --git a/object.h b/object.h
index 2cff106ff7..e5cad09fad 100644
--- a/object.h
+++ b/object.h
@@ -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
diff --git a/pretty.c b/pretty.c
index f7ce490230..478af1a860 100644
--- a/pretty.c
+++ b/pretty.c
@@ -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 */
diff --git a/ref-filter.c b/ref-filter.c
index 0a106b888d..1d0bad5e36 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -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)
diff --git a/reflog-walk.c b/reflog-walk.c
index 5008bbf6ad..3561a8b955 100644
--- a/reflog-walk.c
+++ b/reflog-walk.c
@@ -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;
diff --git a/refs/files-backend.c b/refs/files-backend.c
index f75d960e19..932fdc1f0b 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -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",
diff --git a/remote.c b/remote.c
index fd8cd8ce77..2abc6baf84 100644
--- a/remote.c
+++ b/remote.c
@@ -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;
diff --git a/revision.c b/revision.c
index e98bdf2ac7..5ccfc50447 100644
--- a/revision.c
+++ b/revision.c
@@ -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);
 
diff --git a/server-info.c b/server-info.c
index 6cd1506e5e..fd7ed2a383 100644
--- a/server-info.c
+++ b/server-info.c
@@ -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;
 
diff --git a/sha1_name.c b/sha1_name.c
index 190710c638..0139b480a3 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -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");
diff --git a/tag.c b/tag.c
index 7b32afd123..5207f70885 100644
--- a/tag.c
+++ b/tag.c
@@ -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
diff --git a/tree.c b/tree.c
index 653339db03..62d78fb4ba 100644
--- a/tree.c
+++ b/tree.c
@@ -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);
 }
diff --git a/upload-pack.c b/upload-pack.c
index 6db85ecdc4..b076cbc5f7 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -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",
diff --git a/walker.c b/walker.c
index 49b6a96e6e..492aea906f 100644
--- a/walker.c
+++ b/walker.c
@@ -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;
 	}
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 081/194] object: add repository argument to create_object
  2018-02-05 23:54 ` Stefan Beller
                     ` (58 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 080/194] object: add repository argument to parse_object Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 082/194] object: add repository argument to lookup_object Stefan Beller
                     ` (16 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 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(-)

diff --git a/blob.c b/blob.c
index fa2ab4f7a7..85c2143f29 100644
--- a/blob.c
+++ b/blob.c
@@ -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);
 }
 
diff --git a/commit.c b/commit.c
index 742d710c86..e315d5435b 100644
--- a/commit.c
+++ b/commit.c
@@ -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);
 }
 
diff --git a/contrib/coccinelle/object_parser.cocci b/contrib/coccinelle/object_parser.cocci
index a9afe4bf7a..2a554084d1 100644
--- a/contrib/coccinelle/object_parser.cocci
+++ b/contrib/coccinelle/object_parser.cocci
@@ -4,3 +4,11 @@ expression E;
  parse_object(
 + the_repository,
  E)
+
+@@
+expression E;
+expression F;
+@@
+ create_object(
++ the_repository,
+ E, F)
diff --git a/object.c b/object.c
index c1154039df..1126c7e278 100644
--- a/object.c
+++ b/object.c
@@ -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;
 }
 
diff --git a/object.h b/object.h
index e5cad09fad..ac12dc3629 100644
--- a/object.h
+++ b/object.h
@@ -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);
 
diff --git a/tag.c b/tag.c
index 5207f70885..a9e5af4294 100644
--- a/tag.c
+++ b/tag.c
@@ -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);
 }
 
diff --git a/tree.c b/tree.c
index 62d78fb4ba..f8e1e6d63d 100644
--- a/tree.c
+++ b/tree.c
@@ -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);
 }
 
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 082/194] object: add repository argument to lookup_object
  2018-02-05 23:54 ` Stefan Beller
                     ` (59 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 081/194] object: add repository argument to create_object Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 083/194] object: add repository argument to grow_object_hash Stefan Beller
                     ` (15 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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`.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 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(-)

diff --git a/blob.c b/blob.c
index 85c2143f29..a9f3aa2ec8 100644
--- a/blob.c
+++ b/blob.c
@@ -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());
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 6140caf8d8..642bafdd30 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -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));
 			}
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 9408ae5cc6..7645418821 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -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));
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index c6b253eefb..45ec5515cc 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -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);
 			}
diff --git a/builtin/prune.c b/builtin/prune.c
index 7891048b35..06e6de45b5 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -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)) {
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index ee707068b3..e26f673a15 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -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);
diff --git a/commit.c b/commit.c
index e315d5435b..68967e6c59 100644
--- a/commit.c
+++ b/commit.c
@@ -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());
diff --git a/contrib/coccinelle/object_parser.cocci b/contrib/coccinelle/object_parser.cocci
index 2a554084d1..d57b0f16d4 100644
--- a/contrib/coccinelle/object_parser.cocci
+++ b/contrib/coccinelle/object_parser.cocci
@@ -12,3 +12,10 @@ expression F;
  create_object(
 + the_repository,
  E, F)
+
+@@
+expression E;
+@@
+ lookup_object(
++the_repository,
+ E)
diff --git a/fetch-pack.c b/fetch-pack.c
index 0f7aeabb64..02ac850967 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -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),
diff --git a/http-push.c b/http-push.c
index b4c3cd1cd7..5149c1b425 100644
--- a/http-push.c
+++ b/http-push.c
@@ -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);
 
diff --git a/object.c b/object.c
index 1126c7e278..681fa40eb1 100644
--- a/object.c
+++ b/object.c
@@ -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);
diff --git a/object.h b/object.h
index ac12dc3629..727a03ebd6 100644
--- a/object.h
+++ b/object.h
@@ -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);
diff --git a/reachable.c b/reachable.c
index 7e7b9525c0..4007c6428b 100644
--- a/reachable.c
+++ b/reachable.c
@@ -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;
diff --git a/tag.c b/tag.c
index a9e5af4294..3712ef7867 100644
--- a/tag.c
+++ b/tag.c
@@ -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());
diff --git a/tree.c b/tree.c
index f8e1e6d63d..8f0ee6c8c0 100644
--- a/tree.c
+++ b/tree.c
@@ -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());
diff --git a/upload-pack.c b/upload-pack.c
index b076cbc5f7..8716e28d4f 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -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;
 		}
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 083/194] object: add repository argument to grow_object_hash
  2018-02-05 23:54 ` Stefan Beller
                     ` (60 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 082/194] object: add repository argument to lookup_object Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 084/194] blob: add repository argument to lookup_blob Stefan Beller
                     ` (14 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 object.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/object.c b/object.c
index 681fa40eb1..225679188b 100644
--- a/object.c
+++ b/object.c
@@ -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);
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 084/194] blob: add repository argument to lookup_blob
  2018-02-05 23:54 ` Stefan Beller
                     ` (61 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 083/194] object: add repository argument to grow_object_hash Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 085/194] tree: add repository argument to lookup_tree Stefan Beller
                     ` (13 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 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(-)

diff --git a/blob.c b/blob.c
index a9f3aa2ec8..25faf3e692 100644
--- a/blob.c
+++ b/blob.c
@@ -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)
diff --git a/blob.h b/blob.h
index 4460616831..08bc34487a 100644
--- a/blob.h
+++ b/blob.h
@@ -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);
 
diff --git a/builtin/describe.c b/builtin/describe.c
index 3b0b204b1e..2add1e8d83 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -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);
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 642bafdd30..14a27d539f 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -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);
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 7645418821..79da01d338 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -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;
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index b9851ad69d..67db12fc43 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -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
diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c
index ba51ad55a8..41f1ae30cc 100644
--- a/builtin/merge-tree.c
+++ b/builtin/merge-tree.c
@@ -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;
 }
 
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index e26f673a15..8d13c5145c 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -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
diff --git a/contrib/coccinelle/object_parser.cocci b/contrib/coccinelle/object_parser.cocci
index d57b0f16d4..3bc38d2faa 100644
--- a/contrib/coccinelle/object_parser.cocci
+++ b/contrib/coccinelle/object_parser.cocci
@@ -1,3 +1,10 @@
+@@
+expression E;
+@@
+ lookup_blob(
++the_repository,
+ E)
+
 @@
 expression E;
 @@
diff --git a/fsck.c b/fsck.c
index 843ddc1035..6d04981735 100644
--- a/fsck.c
+++ b/fsck.c
@@ -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);
diff --git a/http-push.c b/http-push.c
index 5149c1b425..6c60b12ad1 100644
--- a/http-push.c
+++ b/http-push.c
@@ -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 */
diff --git a/list-objects.c b/list-objects.c
index 0966cdc9fa..c11dc1281b 100644
--- a/list-objects.c
+++ b/list-objects.c
@@ -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);
 	}
diff --git a/object.c b/object.c
index 225679188b..e0dac087c8 100644
--- a/object.c
+++ b/object.c
@@ -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);
 	}
 
diff --git a/reachable.c b/reachable.c
index 4007c6428b..943e4518c2 100644
--- a/reachable.c
+++ b/reachable.c
@@ -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",
diff --git a/revision.c b/revision.c
index 5ccfc50447..a7b57e3452 100644
--- a/revision.c
+++ b/revision.c
@@ -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, "",
diff --git a/tag.c b/tag.c
index 3712ef7867..4cf449303b 100644
--- a/tag.c
+++ b/tag.c
@@ -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)) {
diff --git a/walker.c b/walker.c
index 492aea906f..f5a221d48e 100644
--- a/walker.c
+++ b/walker.c
@@ -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;
 		}
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 085/194] tree: add repository argument to lookup_tree
  2018-02-05 23:54 ` Stefan Beller
                     ` (62 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 084/194] blob: add repository argument to lookup_blob Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 086/194] tag: add repository argument to lookup_tag Stefan Beller
                     ` (12 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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

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

Add the cocci patch that converted the callers.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 builtin/am.c                           | 6 ++++--
 builtin/diff-tree.c                    | 2 +-
 builtin/diff.c                         | 3 ++-
 builtin/reflog.c                       | 2 +-
 cache-tree.c                           | 3 ++-
 commit.c                               | 2 +-
 contrib/coccinelle/object_parser.cocci | 8 ++++++++
 fsck.c                                 | 2 +-
 http-push.c                            | 3 ++-
 list-objects.c                         | 2 +-
 merge-recursive.c                      | 6 +++---
 object.c                               | 2 +-
 reachable.c                            | 2 +-
 revision.c                             | 4 ++--
 sequencer.c                            | 2 +-
 tag.c                                  | 2 +-
 tree.c                                 | 4 ++--
 tree.h                                 | 3 ++-
 walker.c                               | 3 ++-
 19 files changed, 38 insertions(+), 23 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 086/194] tag: add repository argument to lookup_tag
  2018-02-05 23:54 ` Stefan Beller
                     ` (63 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 085/194] tree: add repository argument to lookup_tree Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 087/194] tag: add repository argument to parse_tag_buffer Stefan Beller
                     ` (11 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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

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

Add the cocci patch that converted the callers.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 builtin/describe.c                     | 6 +++---
 builtin/pack-objects.c                 | 2 +-
 builtin/replace.c                      | 2 +-
 contrib/coccinelle/object_parser.cocci | 7 +++++++
 log-tree.c                             | 2 +-
 object.c                               | 2 +-
 sha1_name.c                            | 2 +-
 tag.c                                  | 4 ++--
 tag.h                                  | 4 ++--
 9 files changed, 19 insertions(+), 12 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 087/194] tag: add repository argument to parse_tag_buffer
  2018-02-05 23:54 ` Stefan Beller
                     ` (64 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 086/194] tag: add repository argument to lookup_tag Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 088/194] tag: add repository argument to deref_tag Stefan Beller
                     ` (10 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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

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

Add the cocci patch that converted the callers.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 builtin/replace.c                      | 2 +-
 contrib/coccinelle/object_parser.cocci | 9 +++++++++
 log-tree.c                             | 2 +-
 object.c                               | 2 +-
 sha1_file.c                            | 2 +-
 tag.c                                  | 4 ++--
 tag.h                                  | 3 ++-
 7 files changed, 17 insertions(+), 7 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 088/194] tag: add repository argument to deref_tag
  2018-02-05 23:54 ` Stefan Beller
                     ` (65 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 087/194] tag: add repository argument to parse_tag_buffer Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 089/194] object: add repository argument to lookup_commit_reference_gently Stefan Beller
                     ` (9 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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

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

Add the cocci patch that converted the callers.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 blame.c                                |  6 +++---
 builtin/diff.c                         |  2 +-
 builtin/fmt-merge-msg.c                |  3 ++-
 builtin/grep.c                         |  3 ++-
 builtin/name-rev.c                     |  3 ++-
 commit.c                               |  3 ++-
 contrib/coccinelle/object_parser.cocci |  9 +++++++++
 fetch-pack.c                           |  9 ++++++---
 http-backend.c                         |  2 +-
 http-push.c                            |  2 +-
 line-log.c                             |  2 +-
 merge-recursive.c                      |  3 ++-
 remote.c                               |  6 ++++--
 server-info.c                          |  2 +-
 sha1_name.c                            | 11 +++++++----
 shallow.c                              |  4 +++-
 tag.c                                  |  2 +-
 tag.h                                  |  3 ++-
 upload-pack.c                          |  2 +-
 19 files changed, 51 insertions(+), 26 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 089/194] object: add repository argument to lookup_commit_reference_gently
  2018-02-05 23:54 ` Stefan Beller
                     ` (66 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 088/194] tag: add repository argument to deref_tag Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 090/194] object: add repository argument to lookup_commit_reference Stefan Beller
                     ` (8 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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

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

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

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 archive.c                              |  2 +-
 blame.c                                |  3 ++-
 builtin/checkout.c                     |  7 ++++---
 builtin/describe.c                     |  5 +++--
 builtin/fetch.c                        |  9 ++++++---
 builtin/reflog.c                       | 10 ++++++----
 builtin/show-branch.c                  |  3 ++-
 commit.c                               |  9 +++++----
 commit.h                               |  5 ++++-
 contrib/coccinelle/object_parser.cocci |  8 ++++++++
 fast-import.c                          |  6 ++++--
 notes-cache.c                          |  3 ++-
 ref-filter.c                           |  6 ++++--
 remote.c                               |  9 +++++----
 sequencer.c                            |  2 +-
 sha1_name.c                            |  4 ++--
 shallow.c                              |  9 ++++++---
 walker.c                               |  3 ++-
 wt-status.c                            |  2 +-
 19 files changed, 68 insertions(+), 37 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 090/194] object: add repository argument to lookup_commit_reference
  2018-02-05 23:54 ` Stefan Beller
                     ` (67 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 089/194] object: add repository argument to lookup_commit_reference_gently Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 091/194] object: add repository argument to lookup_commit Stefan Beller
                     ` (7 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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

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

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

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 bisect.c                               |  2 +-
 blame.c                                |  2 +-
 branch.c                               |  2 +-
 builtin/branch.c                       |  7 ++++---
 builtin/clone.c                        |  3 ++-
 builtin/describe.c                     |  2 +-
 builtin/diff-tree.c                    |  2 +-
 builtin/log.c                          |  7 ++++---
 builtin/merge-base.c                   |  5 +++--
 builtin/notes.c                        |  3 ++-
 builtin/pull.c                         | 15 ++++++++++-----
 builtin/reset.c                        |  4 ++--
 builtin/rev-parse.c                    |  6 +++---
 builtin/show-branch.c                  |  2 +-
 builtin/tag.c                          |  2 +-
 bundle.c                               |  3 ++-
 commit.c                               |  6 +++---
 commit.h                               |  4 +++-
 contrib/coccinelle/object_parser.cocci |  7 +++++++
 notes-merge.c                          |  5 +++--
 parse-options-cb.c                     |  2 +-
 remote.c                               |  4 ++--
 revision.c                             |  4 ++--
 sequencer.c                            |  4 ++--
 sha1_name.c                            |  4 ++--
 submodule.c                            | 10 +++++-----
 26 files changed, 69 insertions(+), 48 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 091/194] object: add repository argument to lookup_commit
  2018-02-05 23:54 ` Stefan Beller
                     ` (68 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 090/194] object: add repository argument to lookup_commit_reference Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 092/194] object: move grafts to object parser Stefan Beller
                     ` (6 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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

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

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

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 builtin/am.c                           |  3 ++-
 builtin/commit-tree.c                  |  4 +++-
 builtin/commit.c                       |  2 +-
 builtin/diff-tree.c                    |  2 +-
 builtin/fast-export.c                  |  2 +-
 builtin/fmt-merge-msg.c                |  2 +-
 builtin/merge-base.c                   |  2 +-
 builtin/verify-commit.c                |  4 +++-
 commit.c                               |  7 ++++---
 commit.h                               |  3 ++-
 contrib/coccinelle/object_parser.cocci |  7 +++++++
 fetch-pack.c                           |  3 ++-
 log-tree.c                             |  2 +-
 notes-utils.c                          |  4 +++-
 object.c                               |  2 +-
 sequencer.c                            |  2 +-
 sha1_name.c                            |  2 +-
 shallow.c                              | 17 ++++++++++-------
 tag.c                                  |  2 +-
 tree.c                                 |  2 +-
 20 files changed, 47 insertions(+), 27 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 092/194] object: move grafts to object parser
  2018-02-05 23:54 ` Stefan Beller
                     ` (69 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 091/194] object: add repository argument to lookup_commit Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-06  4:07     ` Eric Sunshine
  2018-02-05 23:55   ` [PATCH 093/194] object: add repository argument to commit_graft_pos Stefan Beller
                     ` (5 subsequent siblings)
  76 siblings, 1 reply; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 commit.c | 44 +++++++++++++++++++++++---------------------
 object.h |  6 +++++-
 2 files changed, 28 insertions(+), 22 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 093/194] object: add repository argument to commit_graft_pos
  2018-02-05 23:54 ` Stefan Beller
                     ` (70 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 092/194] object: move grafts to object parser Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 094/194] commit: add repository argument to parse_commit_buffer Stefan Beller
                     ` (4 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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

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

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 commit.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 094/194] commit: add repository argument to parse_commit_buffer
  2018-02-05 23:54 ` Stefan Beller
                     ` (71 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 093/194] object: add repository argument to commit_graft_pos Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 095/194] object: add repository argument to register_commit_graft Stefan Beller
                     ` (3 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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

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

Add the cocci patch that converted the callers.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 commit.c                               | 4 ++--
 commit.h                               | 3 ++-
 contrib/coccinelle/object_parser.cocci | 9 +++++++++
 object.c                               | 2 +-
 sha1_file.c                            | 2 +-
 5 files changed, 15 insertions(+), 5 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 095/194] object: add repository argument to register_commit_graft
  2018-02-05 23:54 ` Stefan Beller
                     ` (72 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 094/194] commit: add repository argument to parse_commit_buffer Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 096/194] object: add repository argument to read_graft_file Stefan Beller
                     ` (2 subsequent siblings)
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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

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

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 builtin/blame.c                        | 3 ++-
 commit.c                               | 4 ++--
 commit.h                               | 3 ++-
 contrib/coccinelle/object_parser.cocci | 8 ++++++++
 shallow.c                              | 3 ++-
 5 files changed, 16 insertions(+), 5 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 096/194] object: add repository argument to read_graft_file
  2018-02-05 23:54 ` Stefan Beller
                     ` (73 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 095/194] object: add repository argument to register_commit_graft Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 097/194] object: add repository argument to prepare_commit_graft Stefan Beller
  2018-02-05 23:55   ` [PATCH 098/194] object: add repository argument to lookup_commit_graft Stefan Beller
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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

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

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 commit.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/commit.c b/commit.c
index ce18e41e33..d2c6367f85 100644
--- a/commit.c
+++ b/commit.c
@@ -178,7 +178,8 @@ struct commit_graft *read_graft_line(struct strbuf *line)
 	return NULL;
 }
 
-static int read_graft_file(const char *graft_file)
+#define read_graft_file(r, f) read_graft_file_##r(f)
+static int read_graft_file_the_repository(const char *graft_file)
 {
 	FILE *fp = fopen_or_warn(graft_file, "r");
 	struct strbuf buf = STRBUF_INIT;
@@ -205,7 +206,7 @@ static void prepare_commit_graft(void)
 	if (commit_graft_prepared)
 		return;
 	graft_file = get_graft_file();
-	read_graft_file(graft_file);
+	read_graft_file(the_repository, graft_file);
 	/* make sure shallows are read */
 	is_repository_shallow();
 	commit_graft_prepared = 1;
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 097/194] object: add repository argument to prepare_commit_graft
  2018-02-05 23:54 ` Stefan Beller
                     ` (74 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 096/194] object: add repository argument to read_graft_file Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  2018-02-05 23:55   ` [PATCH 098/194] object: add repository argument to lookup_commit_graft Stefan Beller
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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

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

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 commit.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/commit.c b/commit.c
index d2c6367f85..fbe27cf436 100644
--- a/commit.c
+++ b/commit.c
@@ -198,7 +198,8 @@ static int read_graft_file_the_repository(const char *graft_file)
 	return 0;
 }
 
-static void prepare_commit_graft(void)
+#define prepare_commit_graft(r) prepare_commit_graft_##r()
+static void prepare_commit_graft_the_repository(void)
 {
 	static int commit_graft_prepared;
 	char *graft_file;
@@ -215,7 +216,7 @@ static void prepare_commit_graft(void)
 struct commit_graft *lookup_commit_graft(const struct object_id *oid)
 {
 	int pos;
-	prepare_commit_graft();
+	prepare_commit_graft(the_repository);
 	pos = commit_graft_pos(the_repository, oid->hash);
 	if (pos < 0)
 		return NULL;
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 098/194] object: add repository argument to lookup_commit_graft
  2018-02-05 23:54 ` Stefan Beller
                     ` (75 preceding siblings ...)
  2018-02-05 23:55   ` [PATCH 097/194] object: add repository argument to prepare_commit_graft Stefan Beller
@ 2018-02-05 23:55   ` Stefan Beller
  76 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-05 23:55 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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

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

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

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 commit.c                               | 4 ++--
 commit.h                               | 3 ++-
 contrib/coccinelle/object_parser.cocci | 7 +++++++
 fsck.c                                 | 2 +-
 shallow.c                              | 5 +++--
 5 files changed, 15 insertions(+), 6 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories
  2018-02-05 23:51 [RFC PATCH 000/194] Moving global state into the repository object Stefan Beller
                   ` (21 preceding siblings ...)
  2018-02-05 23:54 ` Stefan Beller
@ 2018-02-06  0:16 ` Stefan Beller
  2018-02-06  0:16   ` [PATCH 100/194] object: allow create_object " Stefan Beller
                     ` (93 more replies)
  2018-02-06  0:54 ` [RFC PATCH 000/194] Moving global state into the repository object Stefan Beller
                   ` (5 subsequent siblings)
  28 siblings, 94 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 object.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/object.c b/object.c
index f518e5703b..be5d6c0931 100644
--- a/object.c
+++ b/object.c
@@ -115,27 +115,28 @@ struct object *lookup_object_the_repository(const unsigned char *sha1)
  * power of 2 (but at least 32).  Copy the existing values to the new
  * hash map.
  */
-#define grow_object_hash(r) grow_object_hash_##r()
-static void grow_object_hash_the_repository(void)
+static void grow_object_hash(struct repository *r)
 {
 	int i;
 	/*
 	 * Note that this size must always be power-of-2 to match hash_obj
 	 * above.
 	 */
-	int new_hash_size = the_repository->parsed_objects.obj_hash_size < 32 ? 32 : 2 * the_repository->parsed_objects.obj_hash_size;
+	int new_hash_size = r->parsed_objects.obj_hash_size < 32
+				? 32
+				: 2 * r->parsed_objects.obj_hash_size;
 	struct object **new_hash;
 
 	new_hash = xcalloc(new_hash_size, sizeof(struct object *));
-	for (i = 0; i < the_repository->parsed_objects.obj_hash_size; i++) {
-		struct object *obj = the_repository->parsed_objects.obj_hash[i];
+	for (i = 0; i < r->parsed_objects.obj_hash_size; i++) {
+		struct object *obj = r->parsed_objects.obj_hash[i];
 		if (!obj)
 			continue;
 		insert_obj_hash(obj, new_hash, new_hash_size);
 	}
-	free(the_repository->parsed_objects.obj_hash);
-	the_repository->parsed_objects.obj_hash = new_hash;
-	the_repository->parsed_objects.obj_hash_size = new_hash_size;
+	free(r->parsed_objects.obj_hash);
+	r->parsed_objects.obj_hash = new_hash;
+	r->parsed_objects.obj_hash_size = new_hash_size;
 }
 
 void *create_object_the_repository(const unsigned char *sha1, void *o)
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 100/194] object: allow create_object to handle arbitrary repositories
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
@ 2018-02-06  0:16   ` " Stefan Beller
  2018-02-06  0:16   ` [PATCH 101/194] object: allow lookup_object " Stefan Beller
                     ` (92 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 object.c | 12 ++++++------
 object.h |  3 +--
 2 files changed, 7 insertions(+), 8 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 101/194] object: allow lookup_object to handle arbitrary repositories
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
  2018-02-06  0:16   ` [PATCH 100/194] object: allow create_object " Stefan Beller
@ 2018-02-06  0:16   ` " Stefan Beller
  2018-02-06  0:16   ` [PATCH 102/194] object: add repository argument to lookup_unknown_object Stefan Beller
                     ` (91 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 object.c | 15 +++++++--------
 object.h |  3 +--
 2 files changed, 8 insertions(+), 10 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 102/194] object: add repository argument to lookup_unknown_object
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
  2018-02-06  0:16   ` [PATCH 100/194] object: allow create_object " Stefan Beller
  2018-02-06  0:16   ` [PATCH 101/194] object: allow lookup_object " Stefan Beller
@ 2018-02-06  0:16   ` Stefan Beller
  2018-02-06  0:16   ` [PATCH 103/194] object: allow lookup_unknown_object to handle arbitrary repositories Stefan Beller
                     ` (90 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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

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

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

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 builtin/fsck.c                         | 2 +-
 builtin/pack-objects.c                 | 2 +-
 contrib/coccinelle/object_parser.cocci | 7 +++++++
 http-push.c                            | 2 +-
 object.c                               | 2 +-
 object.h                               | 3 ++-
 refs.c                                 | 2 +-
 t/helper/test-example-decorate.c       | 6 +++---
 upload-pack.c                          | 2 +-
 walker.c                               | 2 +-
 10 files changed, 19 insertions(+), 11 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 103/194] object: allow lookup_unknown_object to handle arbitrary repositories
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (2 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 102/194] object: add repository argument to lookup_unknown_object Stefan Beller
@ 2018-02-06  0:16   ` Stefan Beller
  2018-02-06  0:16   ` [PATCH 104/194] object: add repository argument to parse_object_buffer Stefan Beller
                     ` (89 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 object.c | 7 ++++---
 object.h | 3 +--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/object.c b/object.c
index 3eb12bec49..9edddbe1d4 100644
--- a/object.c
+++ b/object.c
@@ -174,11 +174,12 @@ void *object_as_type(struct object *obj, enum object_type type, int quiet)
 	}
 }
 
-struct object *lookup_unknown_object_the_repository(const unsigned char *sha1)
+struct object *lookup_unknown_object(struct repository *r,
+				     const unsigned char *sha1)
 {
-	struct object *obj = lookup_object(the_repository, sha1);
+	struct object *obj = lookup_object(r, sha1);
 	if (!obj)
-		obj = create_object(the_repository, sha1,
+		obj = create_object(r, sha1,
 				    alloc_object_node());
 	return obj;
 }
diff --git a/object.h b/object.h
index 083111d7b7..dd009a03ec 100644
--- a/object.h
+++ b/object.h
@@ -130,8 +130,7 @@ struct object *parse_object_or_die(const struct object_id *oid, const char *name
 struct object *parse_object_buffer(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p);
 
 /** Returns the object, with potentially excess memory allocated. **/
-#define lookup_unknown_object(r, s) lookup_unknown_object_##r(s)
-struct object *lookup_unknown_object_the_repository(const unsigned char *sha1);
+struct object *lookup_unknown_object(struct repository *r, const unsigned char *sha1);
 
 struct object_list *object_list_insert(struct object *item,
 				       struct object_list **list_p);
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 104/194] object: add repository argument to parse_object_buffer
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (3 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 103/194] object: allow lookup_unknown_object to handle arbitrary repositories Stefan Beller
@ 2018-02-06  0:16   ` Stefan Beller
  2018-02-06  0:16   ` [PATCH 105/194] repository: keep track of all open repositories Stefan Beller
                     ` (88 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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

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

Add the cocci patch that converted the callers.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 builtin/fast-export.c                  |  3 ++-
 builtin/fsck.c                         |  6 ++++--
 builtin/index-pack.c                   |  3 ++-
 builtin/unpack-objects.c               |  3 ++-
 contrib/coccinelle/object_parser.cocci | 11 +++++++++++
 object.c                               |  5 +++--
 object.h                               |  3 ++-
 ref-filter.c                           |  3 ++-
 8 files changed, 28 insertions(+), 9 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 105/194] repository: keep track of all open repositories
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (4 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 104/194] object: add repository argument to parse_object_buffer Stefan Beller
@ 2018-02-06  0:16   ` Stefan Beller
  2018-02-06  0:16   ` [PATCH 106/194] Rename sha1_object_info.cocci to object_store.cocci Stefan Beller
                     ` (87 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 builtin/grep.c     |  2 +-
 builtin/ls-files.c |  2 +-
 packfile.c         |  9 ++++++--
 repository.c       | 66 +++++++++++++++++++++++++++++++++++++-----------------
 repository.h       |  6 ++++-
 submodule.c        |  2 +-
 6 files changed, 61 insertions(+), 26 deletions(-)

diff --git a/builtin/grep.c b/builtin/grep.c
index 2c43307f02..a9a908d92a 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -465,7 +465,7 @@ static int grep_submodule(struct grep_opt *opt, struct repository *superproject,
 		hit = grep_cache(opt, &submodule, pathspec, 1);
 	}
 
-	repo_clear(&submodule);
+	repo_free(&submodule);
 	return hit;
 }
 
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 2fc836e330..a6d824a2ba 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -215,7 +215,7 @@ static void show_submodule(struct repository *superproject,
 
 	show_files(&submodule, dir);
 
-	repo_clear(&submodule);
+	repo_free(&submodule);
 }
 
 static void show_ce(struct repository *repo, struct dir_struct *dir,
diff --git a/packfile.c b/packfile.c
index 6a8d5edf6d..f7e8a81ded 100644
--- a/packfile.c
+++ b/packfile.c
@@ -237,13 +237,18 @@ static void scan_windows(struct packed_git *p,
 
 static int unuse_one_window(struct packed_git *current)
 {
+	int i = 0;
 	struct packed_git *p, *lru_p = NULL;
 	struct pack_window *lru_w = NULL, *lru_l = NULL;
 
 	if (current)
 		scan_windows(current, &lru_p, &lru_w, &lru_l);
-	for (p = the_repository->objects.packed_git; p; p = p->next)
-		scan_windows(p, &lru_p, &lru_w, &lru_l);
+	for (i = -1; i < open_repos_nr; i++) {
+		struct repository *r = i == -1 ? the_repository : open_repos[i];
+		for (p = r->objects.packed_git; p; p = p->next)
+			scan_windows(p, &lru_p, &lru_w, &lru_l);
+	}
+
 	if (lru_p) {
 		munmap(lru_w->base, lru_w->len);
 		pack_mapped -= lru_w->len;
diff --git a/repository.c b/repository.c
index af62dfdc09..361e503824 100644
--- a/repository.c
+++ b/repository.c
@@ -126,6 +126,36 @@ static int read_and_verify_repository_format(struct repository_format *format,
 	return ret;
 }
 
+struct repository **open_repos;
+int open_repos_nr;
+static int open_repos_alloc;
+
+static void repo_clear(struct repository *repo)
+{
+	FREE_AND_NULL(repo->gitdir);
+	FREE_AND_NULL(repo->commondir);
+	FREE_AND_NULL(repo->objectdir);
+	FREE_AND_NULL(repo->graft_file);
+	FREE_AND_NULL(repo->index_file);
+	FREE_AND_NULL(repo->worktree);
+	FREE_AND_NULL(repo->submodule_prefix);
+
+	if (repo->config) {
+		git_configset_clear(repo->config);
+		FREE_AND_NULL(repo->config);
+	}
+
+	if (repo->submodule_cache) {
+		submodule_cache_free(repo->submodule_cache);
+		repo->submodule_cache = NULL;
+	}
+
+	if (repo->index) {
+		discard_index(repo->index);
+		FREE_AND_NULL(repo->index);
+	}
+}
+
 /*
  * Initialize 'repo' based on the provided 'gitdir'.
  * Return 0 upon success and a non-zero value upon failure.
@@ -148,6 +178,9 @@ int repo_init(struct repository *repo, const char *gitdir, const char *worktree)
 	if (worktree)
 		repo_set_worktree(repo, worktree);
 
+	ALLOC_GROW(open_repos, open_repos_nr + 1, open_repos_alloc);
+	open_repos[open_repos_nr++] = repo;
+
 	return 0;
 
 error:
@@ -207,30 +240,23 @@ int repo_submodule_init(struct repository *submodule,
 	return ret;
 }
 
-void repo_clear(struct repository *repo)
+void repo_free(struct repository *repo)
 {
-	FREE_AND_NULL(repo->gitdir);
-	FREE_AND_NULL(repo->commondir);
-	FREE_AND_NULL(repo->objectdir);
-	FREE_AND_NULL(repo->graft_file);
-	FREE_AND_NULL(repo->index_file);
-	FREE_AND_NULL(repo->worktree);
-	FREE_AND_NULL(repo->submodule_prefix);
-
-	if (repo->config) {
-		git_configset_clear(repo->config);
-		FREE_AND_NULL(repo->config);
+	int i;
+	for (i = 0; i < open_repos_nr; i++) {
+		if (open_repos[i] != repo)
+			continue;
+		MOVE_ARRAY(open_repos + i,
+			   open_repos + i + 1,
+			   open_repos_nr - i - 1);
+		break;
 	}
 
-	if (repo->submodule_cache) {
-		submodule_cache_free(repo->submodule_cache);
-		repo->submodule_cache = NULL;
-	}
+	if (i == open_repos_nr)
+		BUG("free'ing non-open repo?");
 
-	if (repo->index) {
-		discard_index(repo->index);
-		FREE_AND_NULL(repo->index);
-	}
+	open_repos_nr--;
+	repo_clear(repo);
 }
 
 int repo_read_index(struct repository *repo)
diff --git a/repository.h b/repository.h
index c8a34d1ac9..74b2b27986 100644
--- a/repository.h
+++ b/repository.h
@@ -110,6 +110,10 @@ struct repository {
 
 extern struct repository *the_repository;
 
+/* Any open repo except the_repository */
+extern struct repository **open_repos;
+extern int open_repos_nr;
+
 extern void repo_set_gitdir(struct repository *repo, const char *path);
 extern void repo_set_worktree(struct repository *repo, const char *path);
 extern void repo_set_hash_algo(struct repository *repo, int algo);
@@ -117,7 +121,7 @@ extern int repo_init(struct repository *repo, const char *gitdir, const char *wo
 extern int repo_submodule_init(struct repository *submodule,
 			       struct repository *superproject,
 			       const char *path);
-extern void repo_clear(struct repository *repo);
+extern void repo_free(struct repository *repo);
 
 /*
  * Populates the repository's index from its index_file, an index struct will
diff --git a/submodule.c b/submodule.c
index aec62e6c7d..9c4c01ba73 100644
--- a/submodule.c
+++ b/submodule.c
@@ -898,7 +898,7 @@ static int submodule_has_commits(const char *path, struct oid_array *commits)
 		strbuf_release(&out);
 	}
 
-	repo_clear(&sub);
+	repo_free(&sub);
 	return has_commit.result;
 }
 
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 106/194] Rename sha1_object_info.cocci to object_store.cocci
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (5 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 105/194] repository: keep track of all open repositories Stefan Beller
@ 2018-02-06  0:16   ` Stefan Beller
  2018-02-06  0:16   ` [PATCH 107/194] alternates: add repository argument to add_to_alternates_file Stefan Beller
                     ` (86 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 contrib/coccinelle/{sha1_object_info.cocci => object_store.cocci} | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename contrib/coccinelle/{sha1_object_info.cocci => object_store.cocci} (100%)

diff --git a/contrib/coccinelle/sha1_object_info.cocci b/contrib/coccinelle/object_store.cocci
similarity index 100%
rename from contrib/coccinelle/sha1_object_info.cocci
rename to contrib/coccinelle/object_store.cocci
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 107/194] alternates: add repository argument to add_to_alternates_file
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (6 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 106/194] Rename sha1_object_info.cocci to object_store.cocci Stefan Beller
@ 2018-02-06  0:16   ` Stefan Beller
  2018-02-06  0:16   ` [PATCH 108/194] alternates: add repository argument to add_to_alternates_memory Stefan Beller
                     ` (85 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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

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

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 alternates.h    | 3 ++-
 builtin/clone.c | 9 +++++----
 sha1_file.c     | 2 +-
 3 files changed, 8 insertions(+), 6 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 108/194] alternates: add repository argument to add_to_alternates_memory
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (7 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 107/194] alternates: add repository argument to add_to_alternates_file Stefan Beller
@ 2018-02-06  0:16   ` Stefan Beller
  2018-02-06  0:16   ` [PATCH 109/194] object-store: move check_sha1_signature to object-store.h Stefan Beller
                     ` (84 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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

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

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 alternates.h              | 3 ++-
 builtin/grep.c            | 2 +-
 sha1_file.c               | 2 +-
 submodule.c               | 2 +-
 t/helper/test-ref-store.c | 2 +-
 tmp-objdir.c              | 2 +-
 6 files changed, 7 insertions(+), 6 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 109/194] object-store: move check_sha1_signature to object-store.h
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (8 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 108/194] alternates: add repository argument to add_to_alternates_memory Stefan Beller
@ 2018-02-06  0:16   ` Stefan Beller
  2018-02-06  0:16   ` [PATCH 110/194] object-store: add repository argument to check_sha1_signature Stefan Beller
                     ` (83 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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

While at it, clarify the comment describing its API.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 cache.h        | 2 --
 object-store.h | 9 +++++++++
 sha1_file.c    | 6 ------
 3 files changed, 9 insertions(+), 8 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 110/194] object-store: add repository argument to check_sha1_signature
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (9 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 109/194] object-store: move check_sha1_signature to object-store.h Stefan Beller
@ 2018-02-06  0:16   ` Stefan Beller
  2018-02-06  0:16   ` [PATCH 111/194] object-store: add repository argument to read_object Stefan Beller
                     ` (82 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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

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

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

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 builtin/fast-export.c                 |  2 +-
 builtin/index-pack.c                  |  2 +-
 builtin/mktag.c                       |  4 +++-
 contrib/coccinelle/object_store.cocci | 10 ++++++++++
 object-store.h                        |  3 ++-
 object.c                              |  4 ++--
 pack-check.c                          |  2 +-
 sha1_file.c                           |  4 ++--
 8 files changed, 22 insertions(+), 9 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 111/194] object-store: add repository argument to read_object
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (10 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 110/194] object-store: add repository argument to check_sha1_signature Stefan Beller
@ 2018-02-06  0:16   ` Stefan Beller
  2018-02-06  0:16   ` [PATCH 112/194] object-store: add repository argument to read_sha1_file_extended Stefan Beller
                     ` (81 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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

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

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 sha1_file.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 112/194] object-store: add repository argument to read_sha1_file_extended
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (11 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 111/194] object-store: add repository argument to read_object Stefan Beller
@ 2018-02-06  0:16   ` Stefan Beller
  2018-02-06  0:16   ` [PATCH 113/194] object-store: add repository argument to read_sha1_file Stefan Beller
                     ` (80 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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

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

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

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 contrib/coccinelle/object_store.cocci | 10 ++++++++++
 object-store.h                        |  5 +++--
 sha1_file.c                           |  2 +-
 streaming.c                           |  3 ++-
 4 files changed, 16 insertions(+), 4 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 113/194] object-store: add repository argument to read_sha1_file
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (12 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 112/194] object-store: add repository argument to read_sha1_file_extended Stefan Beller
@ 2018-02-06  0:16   ` Stefan Beller
  2018-02-06  0:16   ` [PATCH 114/194] object: move read_object_with_reference to object.h Stefan Beller
                     ` (79 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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

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

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

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 apply.c                               |  7 +++++--
 archive.c                             |  3 ++-
 bisect.c                              |  4 +++-
 blame.c                               |  7 +++++--
 builtin/cat-file.c                    | 15 ++++++++++-----
 builtin/difftool.c                    |  4 +++-
 builtin/fast-export.c                 |  6 ++++--
 builtin/fmt-merge-msg.c               |  3 ++-
 builtin/grep.c                        |  2 +-
 builtin/index-pack.c                  |  6 ++++--
 builtin/log.c                         |  2 +-
 builtin/merge-tree.c                  |  8 ++++++--
 builtin/mktag.c                       |  2 +-
 builtin/notes.c                       |  7 ++++---
 builtin/pack-objects.c                | 17 +++++++++++------
 builtin/reflog.c                      |  3 ++-
 builtin/tag.c                         |  4 ++--
 builtin/unpack-file.c                 |  3 ++-
 builtin/unpack-objects.c              |  3 ++-
 builtin/verify-commit.c               |  2 +-
 bundle.c                              |  2 +-
 combine-diff.c                        |  4 +++-
 commit.c                              |  9 ++++++---
 config.c                              |  2 +-
 contrib/coccinelle/object_store.cocci |  9 +++++++++
 diff.c                                |  3 ++-
 dir.c                                 |  3 ++-
 entry.c                               |  4 +++-
 fast-import.c                         |  9 ++++++---
 fsck.c                                |  3 ++-
 grep.c                                |  4 +++-
 http-push.c                           |  3 ++-
 mailmap.c                             |  3 ++-
 match-trees.c                         |  5 +++--
 merge-blobs.c                         |  7 +++++--
 merge-recursive.c                     |  5 +++--
 notes-cache.c                         |  3 ++-
 notes-merge.c                         |  2 +-
 notes.c                               | 11 +++++++----
 object-store.h                        |  3 ++-
 object.c                              |  2 +-
 read-cache.c                          |  6 ++++--
 ref-filter.c                          |  2 +-
 remote-testsvn.c                      |  5 +++--
 rerere.c                              |  4 +++-
 sha1_file.c                           |  3 ++-
 submodule-config.c                    |  3 ++-
 tag.c                                 |  5 +++--
 tree-walk.c                           |  4 +++-
 tree.c                                |  3 ++-
 xdiff-interface.c                     |  3 ++-
 51 files changed, 162 insertions(+), 80 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 114/194] object: move read_object_with_reference to object.h
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (13 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 113/194] object-store: add repository argument to read_sha1_file Stefan Beller
@ 2018-02-06  0:16   ` Stefan Beller
  2018-02-06  0:16   ` [PATCH 115/194] packfile: add repository argument to has_packed_and_bad Stefan Beller
                     ` (78 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Jonathan Nieder, Stefan Beller

From: Jonathan Nieder <jrnieder@gmail.com>

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

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

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 cache.h  |  5 -----
 object.h | 16 ++++++++++++++++
 2 files changed, 16 insertions(+), 5 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 115/194] packfile: add repository argument to has_packed_and_bad
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (14 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 114/194] object: move read_object_with_reference to object.h Stefan Beller
@ 2018-02-06  0:16   ` Stefan Beller
  2018-02-06  0:16   ` [PATCH 116/194] packfile: allow has_packed_and_bad to handle arbitrary repositories Stefan Beller
                     ` (77 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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

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

Add the cocci patch that converted the callers.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 packfile.c  | 2 +-
 packfile.h  | 4 +++-
 sha1_file.c | 2 +-
 3 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/packfile.c b/packfile.c
index f7e8a81ded..28453739b2 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1004,7 +1004,7 @@ void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1)
 	p->num_bad_objects++;
 }
 
-const struct packed_git *has_packed_and_bad(const unsigned char *sha1)
+const struct packed_git *has_packed_and_bad_the_repository(const unsigned char *sha1)
 {
 	struct packed_git *p;
 	unsigned i;
diff --git a/packfile.h b/packfile.h
index f8d2825cce..b5122d455e 100644
--- a/packfile.h
+++ b/packfile.h
@@ -140,7 +140,9 @@ extern int packed_object_info(struct repository *r,
 			      off_t offset, struct object_info *);
 
 extern void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1);
-extern const struct packed_git *has_packed_and_bad(const unsigned char *sha1);
+
+#define has_packed_and_bad(r, s) has_packed_and_bad_##r(s)
+extern const struct packed_git *has_packed_and_bad_the_repository(const unsigned char *sha1);
 
 extern int find_pack_entry(struct repository *r,
 			   const unsigned char *sha1,
diff --git a/sha1_file.c b/sha1_file.c
index ca567b64d6..e1427c0982 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1386,7 +1386,7 @@ void *read_sha1_file_extended_the_repository(const unsigned char *sha1,
 		die("loose object %s (stored in %s) is corrupt",
 		    sha1_to_hex(repl), path);
 
-	if ((p = has_packed_and_bad(repl)) != NULL)
+	if ((p = has_packed_and_bad(the_repository, repl)) != NULL)
 		die("packed object %s (stored in %s) is corrupt",
 		    sha1_to_hex(repl), p->pack_name);
 
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 116/194] packfile: allow has_packed_and_bad to handle arbitrary repositories
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (15 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 115/194] packfile: add repository argument to has_packed_and_bad Stefan Beller
@ 2018-02-06  0:16   ` Stefan Beller
  2018-02-06  0:16   ` [PATCH 117/194] streaming: add repository argument to open_istream_fn Stefan Beller
                     ` (76 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 packfile.c | 4 ++--
 packfile.h | 3 +--
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/packfile.c b/packfile.c
index 28453739b2..21ca15b1ce 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1004,12 +1004,12 @@ void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1)
 	p->num_bad_objects++;
 }
 
-const struct packed_git *has_packed_and_bad_the_repository(const unsigned char *sha1)
+const struct packed_git *has_packed_and_bad(struct repository *r, const unsigned char *sha1)
 {
 	struct packed_git *p;
 	unsigned i;
 
-	for (p = the_repository->objects.packed_git; p; p = p->next)
+	for (p = r->objects.packed_git; p; p = p->next)
 		for (i = 0; i < p->num_bad_objects; i++)
 			if (!hashcmp(sha1, p->bad_object_sha1 + 20 * i))
 				return p;
diff --git a/packfile.h b/packfile.h
index b5122d455e..42593940b0 100644
--- a/packfile.h
+++ b/packfile.h
@@ -141,8 +141,7 @@ extern int packed_object_info(struct repository *r,
 
 extern void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1);
 
-#define has_packed_and_bad(r, s) has_packed_and_bad_##r(s)
-extern const struct packed_git *has_packed_and_bad_the_repository(const unsigned char *sha1);
+extern const struct packed_git *has_packed_and_bad(struct repository *r, const unsigned char *sha1);
 
 extern int find_pack_entry(struct repository *r,
 			   const unsigned char *sha1,
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 117/194] streaming: add repository argument to open_istream_fn
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (16 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 116/194] packfile: allow has_packed_and_bad to handle arbitrary repositories Stefan Beller
@ 2018-02-06  0:16   ` Stefan Beller
  2018-02-06  0:16   ` [PATCH 119/194] streaming: add repository argument to istream_source Stefan Beller
                     ` (75 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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

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

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 streaming.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 119/194] streaming: add repository argument to istream_source
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (17 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 117/194] streaming: add repository argument to open_istream_fn Stefan Beller
@ 2018-02-06  0:16   ` Stefan Beller
  2018-02-06  0:16   ` [PATCH 120/194] streaming: allow istream_source to handle arbitrary repositories Stefan Beller
                     ` (74 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

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

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

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 streaming.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/streaming.c b/streaming.c
index 90acf7448f..5d2c24798e 100644
--- a/streaming.c
+++ b/streaming.c
@@ -111,7 +111,8 @@ ssize_t read_istream(struct git_istream *st, void *buf, size_t sz)
 	return st->vtbl->read(st, buf, sz);
 }
 
-static enum input_source istream_source(const unsigned char *sha1,
+#define istream_source(r, s, t, o) istream_source_##r(s, t, o)
+static enum input_source istream_source_the_repository(const unsigned char *sha1,
 					enum object_type *type,
 					struct object_info *oi)
 {
@@ -144,7 +145,7 @@ struct git_istream *open_istream_the_repository(const unsigned char *sha1,
 	struct git_istream *st;
 	struct object_info oi = OBJECT_INFO_INIT;
 	const unsigned char *real = lookup_replace_object(the_repository, sha1);
-	enum input_source src = istream_source(real, type, &oi);
+	enum input_source src = istream_source(the_repository, real, type, &oi);
 
 	if (src < 0)
 		return NULL;
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 120/194] streaming: allow istream_source to handle arbitrary repositories
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (18 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 119/194] streaming: add repository argument to istream_source Stefan Beller
@ 2018-02-06  0:16   ` Stefan Beller
  2018-02-06  0:16   ` [PATCH 121/194] sha1_file: allow read_object " Stefan Beller
                     ` (73 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 streaming.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/streaming.c b/streaming.c
index 5d2c24798e..cb7f8b2042 100644
--- a/streaming.c
+++ b/streaming.c
@@ -111,8 +111,8 @@ ssize_t read_istream(struct git_istream *st, void *buf, size_t sz)
 	return st->vtbl->read(st, buf, sz);
 }
 
-#define istream_source(r, s, t, o) istream_source_##r(s, t, o)
-static enum input_source istream_source_the_repository(const unsigned char *sha1,
+static enum input_source istream_source(struct repository *r,
+					const unsigned char *sha1,
 					enum object_type *type,
 					struct object_info *oi)
 {
@@ -121,7 +121,7 @@ static enum input_source istream_source_the_repository(const unsigned char *sha1
 
 	oi->typep = type;
 	oi->sizep = &size;
-	status = sha1_object_info_extended(the_repository, sha1, oi, 0);
+	status = sha1_object_info_extended(r, sha1, oi, 0);
 	if (status < 0)
 		return stream_error;
 
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 121/194] sha1_file: allow read_object to handle arbitrary repositories
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (19 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 120/194] streaming: allow istream_source to handle arbitrary repositories Stefan Beller
@ 2018-02-06  0:16   ` " Stefan Beller
  2018-02-06  0:16   ` [PATCH 122/194] object-store.h: allow read_sha1_file{_extended} " Stefan Beller
                     ` (72 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 sha1_file.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/sha1_file.c b/sha1_file.c
index a5ad67143d..6164ba29c5 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1319,9 +1319,8 @@ int sha1_object_info(struct repository *r,
 	return type;
 }
 
-#define read_object(r, s, t, sz) read_object_##r(s, t, sz)
-static void *read_object_the_repository(const unsigned char *sha1, enum object_type *type,
-			 unsigned long *size)
+static void *read_object(struct repository *r, const unsigned char *sha1,
+			 enum object_type *type, unsigned long *size)
 {
 	struct object_info oi = OBJECT_INFO_INIT;
 	void *content;
@@ -1329,7 +1328,7 @@ static void *read_object_the_repository(const unsigned char *sha1, enum object_t
 	oi.sizep = size;
 	oi.contentp = &content;
 
-	if (sha1_object_info_extended(the_repository, sha1, &oi, 0) < 0)
+	if (sha1_object_info_extended(r, sha1, &oi, 0) < 0)
 		return NULL;
 	return content;
 }
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 122/194] object-store.h: allow read_sha1_file{_extended} to handle arbitrary repositories
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (20 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 121/194] sha1_file: allow read_object " Stefan Beller
@ 2018-02-06  0:16   ` " Stefan Beller
  2018-02-06  0:16   ` [PATCH 123/194] streaming: allow open_istream_incore " Stefan Beller
                     ` (71 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 object-store.h | 10 +++++-----
 sha1_file.c    | 11 ++++++-----
 2 files changed, 11 insertions(+), 10 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 123/194] streaming: allow open_istream_incore to handle arbitrary repositories
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (21 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 122/194] object-store.h: allow read_sha1_file{_extended} " Stefan Beller
@ 2018-02-06  0:16   ` " Stefan Beller
  2018-02-06  0:16   ` [PATCH 124/194] streaming: allow open_istream_pack_non_delta " Stefan Beller
                     ` (70 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 streaming.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/streaming.c b/streaming.c
index cb7f8b2042..94651ffbf0 100644
--- a/streaming.c
+++ b/streaming.c
@@ -500,10 +500,7 @@ static struct stream_vtbl incore_vtbl = {
 
 static open_method_decl(incore)
 {
-	if (r != the_repository)
-		BUG("r != the_repository");
-
-	st->u.incore.buf = read_sha1_file_extended(the_repository, sha1,
+	st->u.incore.buf = read_sha1_file_extended(r, sha1,
 						   type, &st->size, 0);
 	st->u.incore.read_ptr = 0;
 	st->vtbl = &incore_vtbl;
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 124/194] streaming: allow open_istream_pack_non_delta to handle arbitrary repositories
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (22 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 123/194] streaming: allow open_istream_incore " Stefan Beller
@ 2018-02-06  0:16   ` " Stefan Beller
  2018-02-06  0:16   ` [PATCH 125/194] streaming: allow open_istream_loose " Stefan Beller
                     ` (69 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 streaming.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/streaming.c b/streaming.c
index 94651ffbf0..21bd069315 100644
--- a/streaming.c
+++ b/streaming.c
@@ -440,9 +440,6 @@ static open_method_decl(pack_non_delta)
 	struct pack_window *window;
 	enum object_type in_pack_type;
 
-	if (r != the_repository)
-		BUG("r != the_repository");
-
 	st->u.in_pack.pack = oi->u.packed.pack;
 	st->u.in_pack.pos = oi->u.packed.offset;
 	window = NULL;
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 125/194] streaming: allow open_istream_loose to handle arbitrary repositories
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (23 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 124/194] streaming: allow open_istream_pack_non_delta " Stefan Beller
@ 2018-02-06  0:16   ` " Stefan Beller
  2018-02-06  0:16   ` [PATCH 126/194] streaming: allow open_istream " Stefan Beller
                     ` (68 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 streaming.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/streaming.c b/streaming.c
index 21bd069315..cd52f517eb 100644
--- a/streaming.c
+++ b/streaming.c
@@ -342,11 +342,7 @@ static struct stream_vtbl loose_vtbl = {
 
 static open_method_decl(loose)
 {
-	if (r != the_repository)
-		BUG("r != the_repository");
-
-	st->u.loose.mapped = map_sha1_file(the_repository,
-					   sha1, &st->u.loose.mapsize);
+	st->u.loose.mapped = map_sha1_file(r, sha1, &st->u.loose.mapsize);
 	if (!st->u.loose.mapped)
 		return -1;
 	if ((unpack_sha1_header(&st->z,
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 126/194] streaming: allow open_istream to handle arbitrary repositories
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (24 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 125/194] streaming: allow open_istream_loose " Stefan Beller
@ 2018-02-06  0:16   ` " Stefan Beller
  2018-02-06  0:16   ` [PATCH 127/194] alternates: convert add_to_alternates_memory to handle arbitrary repos Stefan Beller
                     ` (67 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Jonathan Nieder

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 streaming.c | 11 ++++++-----
 streaming.h |  3 +--
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/streaming.c b/streaming.c
index cd52f517eb..2373395afe 100644
--- a/streaming.c
+++ b/streaming.c
@@ -137,22 +137,23 @@ static enum input_source istream_source(struct repository *r,
 	}
 }
 
-struct git_istream *open_istream_the_repository(const unsigned char *sha1,
+struct git_istream *open_istream(struct repository *r,
+				 const unsigned char *sha1,
 				 enum object_type *type,
 				 unsigned long *size,
 				 struct stream_filter *filter)
 {
 	struct git_istream *st;
 	struct object_info oi = OBJECT_INFO_INIT;
-	const unsigned char *real = lookup_replace_object(the_repository, sha1);
-	enum input_source src = istream_source(the_repository, real, type, &oi);
+	const unsigned char *real = lookup_replace_object(r, sha1);
+	enum input_source src = istream_source(r, real, type, &oi);
 
 	if (src < 0)
 		return NULL;
 
 	st = xmalloc(sizeof(*st));
-	if (open_istream_tbl[src](the_repository, st, &oi, real, type)) {
-		if (open_istream_incore(the_repository, st, &oi, real, type)) {
+	if (open_istream_tbl[src](r, st, &oi, real, type)) {
+		if (open_istream_incore(r, st, &oi, real, type)) {
 			free(st);
 			return NULL;
 		}
diff --git a/streaming.h b/streaming.h
index 9f4d5aeee2..cb36ce4c02 100644
--- a/streaming.h
+++ b/streaming.h
@@ -8,8 +8,7 @@
 /* opaque */
 struct git_istream;
 
-#define open_istream(r, s, t, sz, f) open_istream_##r(s, t, sz, f)
-extern struct git_istream *open_istream_the_repository(const unsigned char *, enum object_type *, unsigned long *, struct stream_filter *);
+extern struct git_istream *open_istream(struct repository *, const unsigned char *, enum object_type *, unsigned long *, struct stream_filter *);
 extern int close_istream(struct git_istream *);
 extern ssize_t read_istream(struct git_istream *, void *, size_t);
 
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 127/194] alternates: convert add_to_alternates_memory to handle arbitrary repos
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (25 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 126/194] streaming: allow open_istream " Stefan Beller
@ 2018-02-06  0:16   ` Stefan Beller
  2018-02-06  0:16   ` [PATCH 128/194] object: add repository argument to object_as_type Stefan Beller
                     ` (66 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 alternates.h | 3 +--
 sha1_file.c  | 7 +++----
 tmp-objdir.c | 1 +
 3 files changed, 5 insertions(+), 6 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 128/194] object: add repository argument to object_as_type
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (26 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 127/194] alternates: convert add_to_alternates_memory to handle arbitrary repos Stefan Beller
@ 2018-02-06  0:16   ` Stefan Beller
  2018-02-06  0:16   ` [PATCH 129/194] alloc: add repository argument to alloc_blob_node Stefan Beller
                     ` (65 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 blob.c         | 2 +-
 builtin/fsck.c | 2 +-
 commit.c       | 4 ++--
 object.c       | 2 +-
 object.h       | 3 ++-
 refs.c         | 2 +-
 tag.c          | 2 +-
 tree.c         | 2 +-
 8 files changed, 10 insertions(+), 9 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 129/194] alloc: add repository argument to alloc_blob_node
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (27 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 128/194] object: add repository argument to object_as_type Stefan Beller
@ 2018-02-06  0:16   ` Stefan Beller
  2018-02-06  0:16   ` [PATCH 130/194] alloc: add repository argument to alloc_tree_node Stefan Beller
                     ` (64 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 alloc.c | 2 +-
 blob.c  | 2 +-
 cache.h | 3 ++-
 3 files changed, 4 insertions(+), 3 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 130/194] alloc: add repository argument to alloc_tree_node
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (28 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 129/194] alloc: add repository argument to alloc_blob_node Stefan Beller
@ 2018-02-06  0:16   ` Stefan Beller
  2018-02-06  0:16   ` [PATCH 131/194] alloc: add repository argument to alloc_commit_node Stefan Beller
                     ` (63 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 alloc.c | 2 +-
 cache.h | 3 ++-
 tree.c  | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/alloc.c b/alloc.c
index 6c5c376a25..2c8d143075 100644
--- a/alloc.c
+++ b/alloc.c
@@ -57,7 +57,7 @@ void *alloc_blob_node_the_repository(void)
 }
 
 static struct alloc_state tree_state;
-void *alloc_tree_node(void)
+void *alloc_tree_node_the_repository(void)
 {
 	struct tree *t = alloc_node(&tree_state, sizeof(struct tree));
 	t->object.type = OBJ_TREE;
diff --git a/cache.h b/cache.h
index 6ee415d9f7..6a794aa903 100644
--- a/cache.h
+++ b/cache.h
@@ -1577,7 +1577,8 @@ void encode_85(char *buf, const unsigned char *data, int bytes);
 /* alloc.c */
 #define alloc_blob_node(r) alloc_blob_node_##r()
 extern void *alloc_blob_node_the_repository(void);
-extern void *alloc_tree_node(void);
+#define alloc_tree_node(r) alloc_tree_node_##r()
+extern void *alloc_tree_node_the_repository(void);
 extern void *alloc_commit_node(void);
 extern void *alloc_tag_node(void);
 extern void *alloc_object_node(void);
diff --git a/tree.c b/tree.c
index 37fec8623b..07cea88450 100644
--- a/tree.c
+++ b/tree.c
@@ -199,7 +199,7 @@ struct tree *lookup_tree_the_repository(const struct object_id *oid)
 	struct object *obj = lookup_object(the_repository, oid->hash);
 	if (!obj)
 		return create_object(the_repository, oid->hash,
-				     alloc_tree_node());
+				     alloc_tree_node(the_repository));
 	return object_as_type(the_repository, obj, OBJ_TREE, 0);
 }
 
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 131/194] alloc: add repository argument to alloc_commit_node
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (29 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 130/194] alloc: add repository argument to alloc_tree_node Stefan Beller
@ 2018-02-06  0:16   ` Stefan Beller
  2018-02-06  0:16   ` [PATCH 132/194] alloc: add repository argument to alloc_tag_node Stefan Beller
                     ` (62 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 alloc.c           | 2 +-
 blame.c           | 2 +-
 cache.h           | 3 ++-
 commit.c          | 2 +-
 merge-recursive.c | 2 +-
 5 files changed, 6 insertions(+), 5 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 132/194] alloc: add repository argument to alloc_tag_node
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (30 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 131/194] alloc: add repository argument to alloc_commit_node Stefan Beller
@ 2018-02-06  0:16   ` Stefan Beller
  2018-02-06  0:16   ` [PATCH 133/194] alloc: add repository argument to alloc_object_node Stefan Beller
                     ` (61 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 alloc.c | 2 +-
 cache.h | 3 ++-
 tag.c   | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/alloc.c b/alloc.c
index 9e2b897ec1..290250e359 100644
--- a/alloc.c
+++ b/alloc.c
@@ -65,7 +65,7 @@ void *alloc_tree_node_the_repository(void)
 }
 
 static struct alloc_state tag_state;
-void *alloc_tag_node(void)
+void *alloc_tag_node_the_repository(void)
 {
 	struct tag *t = alloc_node(&tag_state, sizeof(struct tag));
 	t->object.type = OBJ_TAG;
diff --git a/cache.h b/cache.h
index cb41e22123..36c01bdcf5 100644
--- a/cache.h
+++ b/cache.h
@@ -1581,7 +1581,8 @@ extern void *alloc_blob_node_the_repository(void);
 extern void *alloc_tree_node_the_repository(void);
 #define alloc_commit_node(r) alloc_commit_node_##r()
 extern void *alloc_commit_node_the_repository(void);
-extern void *alloc_tag_node(void);
+#define alloc_tag_node(r) alloc_tag_node_##r()
+extern void *alloc_tag_node_the_repository(void);
 extern void *alloc_object_node(void);
 extern void alloc_report(void);
 extern unsigned int alloc_commit_index(void);
diff --git a/tag.c b/tag.c
index abba1b8d88..e0b695cb60 100644
--- a/tag.c
+++ b/tag.c
@@ -97,7 +97,7 @@ struct tag *lookup_tag_the_repository(const struct object_id *oid)
 	struct object *obj = lookup_object(the_repository, oid->hash);
 	if (!obj)
 		return create_object(the_repository, oid->hash,
-				     alloc_tag_node());
+				     alloc_tag_node(the_repository));
 	return object_as_type(the_repository, obj, OBJ_TAG, 0);
 }
 
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 133/194] alloc: add repository argument to alloc_object_node
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (31 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 132/194] alloc: add repository argument to alloc_tag_node Stefan Beller
@ 2018-02-06  0:16   ` Stefan Beller
  2018-02-06  0:16   ` [PATCH 134/194] alloc: add repository argument to alloc_report Stefan Beller
                     ` (60 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 alloc.c  | 2 +-
 cache.h  | 3 ++-
 object.c | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/alloc.c b/alloc.c
index 290250e359..f031ce422d 100644
--- a/alloc.c
+++ b/alloc.c
@@ -73,7 +73,7 @@ void *alloc_tag_node_the_repository(void)
 }
 
 static struct alloc_state object_state;
-void *alloc_object_node(void)
+void *alloc_object_node_the_repository(void)
 {
 	struct object *obj = alloc_node(&object_state, sizeof(union any_object));
 	obj->type = OBJ_NONE;
diff --git a/cache.h b/cache.h
index 36c01bdcf5..e0916d1a73 100644
--- a/cache.h
+++ b/cache.h
@@ -1583,7 +1583,8 @@ extern void *alloc_tree_node_the_repository(void);
 extern void *alloc_commit_node_the_repository(void);
 #define alloc_tag_node(r) alloc_tag_node_##r()
 extern void *alloc_tag_node_the_repository(void);
-extern void *alloc_object_node(void);
+#define alloc_object_node(r) alloc_object_node_##r()
+extern void *alloc_object_node_the_repository(void);
 extern void alloc_report(void);
 extern unsigned int alloc_commit_index(void);
 
diff --git a/object.c b/object.c
index 156fbae15e..cd73d41d87 100644
--- a/object.c
+++ b/object.c
@@ -180,7 +180,7 @@ struct object *lookup_unknown_object(struct repository *r,
 	struct object *obj = lookup_object(r, sha1);
 	if (!obj)
 		obj = create_object(r, sha1,
-				    alloc_object_node());
+				    alloc_object_node(the_repository));
 	return obj;
 }
 
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 134/194] alloc: add repository argument to alloc_report
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (32 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 133/194] alloc: add repository argument to alloc_object_node Stefan Beller
@ 2018-02-06  0:16   ` Stefan Beller
  2018-02-06  0:16   ` [PATCH 135/194] alloc: add repository argument to alloc_commit_index Stefan Beller
                     ` (59 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 alloc.c | 2 +-
 cache.h | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/alloc.c b/alloc.c
index f031ce422d..28b85b2214 100644
--- a/alloc.c
+++ b/alloc.c
@@ -105,7 +105,7 @@ static void report(const char *name, unsigned int count, size_t size)
 #define REPORT(name, type)	\
     report(#name, name##_state.count, name##_state.count * sizeof(type) >> 10)
 
-void alloc_report(void)
+void alloc_report_the_repository(void)
 {
 	REPORT(blob, struct blob);
 	REPORT(tree, struct tree);
diff --git a/cache.h b/cache.h
index e0916d1a73..5c9807fa8f 100644
--- a/cache.h
+++ b/cache.h
@@ -1585,7 +1585,8 @@ extern void *alloc_commit_node_the_repository(void);
 extern void *alloc_tag_node_the_repository(void);
 #define alloc_object_node(r) alloc_object_node_##r()
 extern void *alloc_object_node_the_repository(void);
-extern void alloc_report(void);
+#define alloc_report(r) alloc_report_##r()
+extern void alloc_report_the_repository(void);
 extern unsigned int alloc_commit_index(void);
 
 /* pkt-line.c */
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 135/194] alloc: add repository argument to alloc_commit_index
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (33 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 134/194] alloc: add repository argument to alloc_report Stefan Beller
@ 2018-02-06  0:16   ` Stefan Beller
  2018-02-06  0:16   ` [PATCH 136/194] alloc: allow arbitrary repositories for alloc functions Stefan Beller
                     ` (58 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 alloc.c  | 4 ++--
 cache.h  | 3 ++-
 object.c | 2 +-
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/alloc.c b/alloc.c
index 28b85b2214..277dadd221 100644
--- a/alloc.c
+++ b/alloc.c
@@ -82,7 +82,7 @@ void *alloc_object_node_the_repository(void)
 
 static struct alloc_state commit_state;
 
-unsigned int alloc_commit_index(void)
+unsigned int alloc_commit_index_the_repository(void)
 {
 	static unsigned int count;
 	return count++;
@@ -92,7 +92,7 @@ void *alloc_commit_node_the_repository(void)
 {
 	struct commit *c = alloc_node(&commit_state, sizeof(struct commit));
 	c->object.type = OBJ_COMMIT;
-	c->index = alloc_commit_index();
+	c->index = alloc_commit_index(the_repository);
 	return c;
 }
 
diff --git a/cache.h b/cache.h
index 5c9807fa8f..40aa3f25aa 100644
--- a/cache.h
+++ b/cache.h
@@ -1587,7 +1587,8 @@ extern void *alloc_tag_node_the_repository(void);
 extern void *alloc_object_node_the_repository(void);
 #define alloc_report(r) alloc_report_##r()
 extern void alloc_report_the_repository(void);
-extern unsigned int alloc_commit_index(void);
+#define alloc_commit_index(r) alloc_commit_index_##r()
+extern unsigned int alloc_commit_index_the_repository(void);
 
 /* pkt-line.c */
 void packet_trace_identity(const char *prog);
diff --git a/object.c b/object.c
index cd73d41d87..e84447f229 100644
--- a/object.c
+++ b/object.c
@@ -161,7 +161,7 @@ void *object_as_type_the_repository(struct object *obj, enum object_type type, i
 		return obj;
 	else if (obj->type == OBJ_NONE) {
 		if (type == OBJ_COMMIT)
-			((struct commit *)obj)->index = alloc_commit_index();
+			((struct commit *)obj)->index = alloc_commit_index(the_repository);
 		obj->type = type;
 		return obj;
 	}
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 136/194] alloc: allow arbitrary repositories for alloc functions
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (34 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 135/194] alloc: add repository argument to alloc_commit_index Stefan Beller
@ 2018-02-06  0:16   ` Stefan Beller
  2018-02-06  3:35     ` Eric Sunshine
  2018-02-06  0:16   ` [PATCH 137/194] object: allow object_as_type to handle arbitrary repositories Stefan Beller
                     ` (57 subsequent siblings)
  93 siblings, 1 reply; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller

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

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 alloc.c      | 48 ++++++++++++++++++++++++++----------------------
 cache.h      | 22 ++++++++--------------
 object.h     | 20 +++++++++++++++++++-
 repository.c |  6 ++++++
 4 files changed, 59 insertions(+), 37 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 137/194] object: allow object_as_type to handle arbitrary repositories
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (35 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 136/194] alloc: allow arbitrary repositories for alloc functions Stefan Beller
@ 2018-02-06  0:16   ` Stefan Beller
  2018-02-06  0:16   ` [PATCH 138/194] commit: allow lookup_commit " Stefan Beller
                     ` (56 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 object.c | 4 ++--
 object.h | 3 +--
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/object.c b/object.c
index e84447f229..db15de6623 100644
--- a/object.c
+++ b/object.c
@@ -155,13 +155,13 @@ void *create_object(struct repository *r, const unsigned char *sha1, void *o)
 	return obj;
 }
 
-void *object_as_type_the_repository(struct object *obj, enum object_type type, int quiet)
+void *object_as_type(struct repository *r, struct object *obj, enum object_type type, int quiet)
 {
 	if (obj->type == type)
 		return obj;
 	else if (obj->type == OBJ_NONE) {
 		if (type == OBJ_COMMIT)
-			((struct commit *)obj)->index = alloc_commit_index(the_repository);
+			((struct commit *)obj)->index = alloc_commit_index(r);
 		obj->type = type;
 		return obj;
 	}
diff --git a/object.h b/object.h
index 587db55dfe..513f5eaef4 100644
--- a/object.h
+++ b/object.h
@@ -124,8 +124,7 @@ struct object *lookup_object(struct repository *r, const unsigned char *sha1);
 
 extern void *create_object(struct repository *r, const unsigned char *sha1, void *obj);
 
-#define object_as_type(r, o, t, q) object_as_type_##r(o, t, q)
-void *object_as_type_the_repository(struct object *obj, enum object_type type, int quiet);
+void *object_as_type(struct repository *r, struct object *obj, enum object_type type, int quiet);
 
 /*
  * Resolves 'sha1' to an object of the specified type and returns the
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 138/194] commit: allow lookup_commit to handle arbitrary repositories
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (36 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 137/194] object: allow object_as_type to handle arbitrary repositories Stefan Beller
@ 2018-02-06  0:16   ` " Stefan Beller
  2018-02-06  0:16   ` [PATCH 139/194] sha1_file: allow add_to_alternates_file " Stefan Beller
                     ` (55 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 commit.c | 10 +++++-----
 commit.h |  3 +--
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/commit.c b/commit.c
index 17bdd13e0d..435735ed2c 100644
--- a/commit.c
+++ b/commit.c
@@ -50,13 +50,13 @@ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref
 	return c;
 }
 
-struct commit *lookup_commit_the_repository(const struct object_id *oid)
+struct commit *lookup_commit(struct repository *r, const struct object_id *oid)
 {
-	struct object *obj = lookup_object(the_repository, oid->hash);
+	struct object *obj = lookup_object(r, oid->hash);
 	if (!obj)
-		return create_object(the_repository, oid->hash,
-				     alloc_commit_node(the_repository));
-	return object_as_type(the_repository, obj, OBJ_COMMIT, 0);
+		return create_object(r, oid->hash,
+				     alloc_commit_node(r));
+	return object_as_type(r, obj, OBJ_COMMIT, 0);
 }
 
 struct commit *lookup_commit_reference_by_name(const char *name)
diff --git a/commit.h b/commit.h
index f791a55379..41a8947b33 100644
--- a/commit.h
+++ b/commit.h
@@ -46,8 +46,7 @@ enum decoration_type {
 void add_name_decoration(enum decoration_type type, const char *name, struct object *obj);
 const struct name_decoration *get_name_decoration(const struct object *obj);
 
-#define lookup_commit(r, o) lookup_commit_##r(o)
-struct commit *lookup_commit_the_repository(const struct object_id *oid);
+struct commit *lookup_commit(struct repository *r, const struct object_id *oid);
 #define lookup_commit_reference(r, o) \
 		lookup_commit_reference_##r(o)
 struct commit *lookup_commit_reference_the_repository(const struct object_id *oid);
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 139/194] sha1_file: allow add_to_alternates_file to handle arbitrary repositories
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (37 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 138/194] commit: allow lookup_commit " Stefan Beller
@ 2018-02-06  0:16   ` " Stefan Beller
  2018-02-06  0:16   ` [PATCH 140/194] commit: convert commit_graft_pos() " Stefan Beller
                     ` (54 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Brandon Williams, Stefan Beller

From: Brandon Williams <bmwill@google.com>

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 alternates.h | 3 +--
 sha1_file.c  | 8 ++++----
 2 files changed, 5 insertions(+), 6 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 140/194] commit: convert commit_graft_pos() to handle arbitrary repositories
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (38 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 139/194] sha1_file: allow add_to_alternates_file " Stefan Beller
@ 2018-02-06  0:16   ` " Stefan Beller
  2018-02-06  0:16   ` [PATCH 141/194] commit: convert register_commit_graft " Stefan Beller
                     ` (53 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Brandon Williams, Stefan Beller

From: Brandon Williams <bmwill@google.com>

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 commit.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/commit.c b/commit.c
index 435735ed2c..0d006ab1bb 100644
--- a/commit.c
+++ b/commit.c
@@ -105,11 +105,10 @@ static const unsigned char *commit_graft_sha1_access(size_t index, void *table)
 	return commit_graft_table[index]->oid.hash;
 }
 
-#define commit_graft_pos(r, s) commit_graft_pos_##r(s)
-static int commit_graft_pos_the_repository(const unsigned char *sha1)
+static int commit_graft_pos(struct repository *r, const unsigned char *sha1)
 {
-	return sha1_pos(sha1, the_repository->parsed_objects.grafts,
-			the_repository->parsed_objects.grafts_nr,
+	return sha1_pos(sha1, r->parsed_objects.grafts,
+			r->parsed_objects.grafts_nr,
 			commit_graft_sha1_access);
 }
 
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 141/194] commit: convert register_commit_graft to handle arbitrary repositories
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (39 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 140/194] commit: convert commit_graft_pos() " Stefan Beller
@ 2018-02-06  0:16   ` " Stefan Beller
  2018-02-06  0:16   ` [PATCH 142/194] commit: convert read_graft_file " Stefan Beller
                     ` (52 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Brandon Williams, Stefan Beller

From: Brandon Williams <bmwill@google.com>

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 commit.c | 29 +++++++++++++++--------------
 commit.h |  3 +--
 2 files changed, 16 insertions(+), 16 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 142/194] commit: convert read_graft_file to handle arbitrary repositories
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (40 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 141/194] commit: convert register_commit_graft " Stefan Beller
@ 2018-02-06  0:16   ` " Stefan Beller
  2018-02-06  0:16   ` [PATCH 143/194] object: add repository argument to parse_commit_gently Stefan Beller
                     ` (51 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Brandon Williams, Stefan Beller

From: Brandon Williams <bmwill@google.com>

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 commit.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 143/194] object: add repository argument to parse_commit_gently
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (41 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 142/194] commit: convert read_graft_file " Stefan Beller
@ 2018-02-06  0:16   ` Stefan Beller
  2018-02-06  0:16   ` [PATCH 144/194] commit: add repository argument to parse_commit Stefan Beller
                     ` (50 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller

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

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

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

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 commit.c                              | 2 +-
 commit.h                              | 5 +++--
 contrib/coccinelle/object_store.cocci | 9 +++++++++
 revision.c                            | 4 ++--
 4 files changed, 15 insertions(+), 5 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 144/194] commit: add repository argument to parse_commit
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (42 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 143/194] object: add repository argument to parse_commit_gently Stefan Beller
@ 2018-02-06  0:16   ` Stefan Beller
  2018-02-06  0:17   ` [PATCH 145/194] commit: add repository argument to set_commit_buffer Stefan Beller
                     ` (49 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:16 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller

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

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

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

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 blame.c                               |  4 ++--
 builtin/checkout.c                    |  4 ++--
 builtin/commit.c                      |  4 ++--
 builtin/describe.c                    |  4 ++--
 builtin/merge-base.c                  |  2 +-
 builtin/name-rev.c                    |  2 +-
 builtin/notes.c                       |  2 +-
 builtin/reflog.c                      |  2 +-
 builtin/show-branch.c                 |  4 ++--
 commit.c                              | 18 +++++++++---------
 commit.h                              |  3 ++-
 contrib/coccinelle/object_store.cocci |  7 +++++++
 fetch-pack.c                          |  6 +++---
 fsck.c                                |  2 +-
 merge-recursive.c                     |  4 ++--
 notes-utils.c                         |  2 +-
 remote.c                              |  2 +-
 revision.c                            |  6 +++---
 sequencer.c                           | 12 ++++++------
 sha1_name.c                           |  4 ++--
 shallow.c                             |  4 ++--
 tree.c                                |  2 +-
 walker.c                              |  2 +-
 23 files changed, 55 insertions(+), 47 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 145/194] commit: add repository argument to set_commit_buffer
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (43 preceding siblings ...)
  2018-02-06  0:16   ` [PATCH 144/194] commit: add repository argument to parse_commit Stefan Beller
@ 2018-02-06  0:17   ` Stefan Beller
  2018-02-06  0:17   ` [PATCH 146/194] commit: add repository argument to get_cached_commit_buffer Stefan Beller
                     ` (48 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:17 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller

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

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

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

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 blame.c  | 2 +-
 commit.c | 4 ++--
 commit.h | 3 ++-
 object.c | 2 +-
 4 files changed, 6 insertions(+), 5 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 146/194] commit: add repository argument to get_cached_commit_buffer
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (44 preceding siblings ...)
  2018-02-06  0:17   ` [PATCH 145/194] commit: add repository argument to set_commit_buffer Stefan Beller
@ 2018-02-06  0:17   ` Stefan Beller
  2018-02-06  0:17   ` [PATCH 147/194] commit: add repository argument to unuse_commit_buffer Stefan Beller
                     ` (47 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:17 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller

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

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

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 builtin/rev-list.c | 2 +-
 commit.c           | 4 ++--
 commit.h           | 3 ++-
 log-tree.c         | 2 +-
 object.c           | 2 +-
 pretty.c           | 2 +-
 6 files changed, 8 insertions(+), 7 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 147/194] commit: add repository argument to unuse_commit_buffer
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (45 preceding siblings ...)
  2018-02-06  0:17   ` [PATCH 146/194] commit: add repository argument to get_cached_commit_buffer Stefan Beller
@ 2018-02-06  0:17   ` Stefan Beller
  2018-02-06  0:17   ` [PATCH 148/194] commit: add repository argument to free_commit_buffer Stefan Beller
                     ` (46 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:17 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller

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

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

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

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 builtin/am.c                          |  2 +-
 builtin/blame.c                       |  4 ++--
 builtin/fast-export.c                 |  2 +-
 builtin/fmt-merge-msg.c               |  2 +-
 builtin/log.c                         |  2 +-
 builtin/replace.c                     |  2 +-
 builtin/reset.c                       |  2 +-
 commit.c                              |  8 ++++----
 commit.h                              |  3 ++-
 contrib/coccinelle/object_store.cocci |  7 +++++++
 fsck.c                                |  2 +-
 merge-recursive.c                     |  2 +-
 notes-merge.c                         |  2 +-
 pretty.c                              |  6 +++---
 revision.c                            |  2 +-
 sequencer.c                           | 16 +++++++++-------
 sha1_name.c                           |  2 +-
 17 files changed, 38 insertions(+), 28 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 148/194] commit: add repository argument to free_commit_buffer
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (46 preceding siblings ...)
  2018-02-06  0:17   ` [PATCH 147/194] commit: add repository argument to unuse_commit_buffer Stefan Beller
@ 2018-02-06  0:17   ` Stefan Beller
  2018-02-06  0:17   ` [PATCH 149/194] commit: allow commit buffer functions to handle arbitrary repositories Stefan Beller
                     ` (45 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:17 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller

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

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

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 builtin/fsck.c     | 2 +-
 builtin/log.c      | 4 ++--
 builtin/rev-list.c | 2 +-
 commit.c           | 2 +-
 commit.h           | 3 ++-
 5 files changed, 7 insertions(+), 6 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 149/194] commit: allow commit buffer functions to handle arbitrary repositories
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (47 preceding siblings ...)
  2018-02-06  0:17   ` [PATCH 148/194] commit: add repository argument to free_commit_buffer Stefan Beller
@ 2018-02-06  0:17   ` Stefan Beller
  2018-02-06  0:17   ` [PATCH 150/194] tree: allow lookup_tree " Stefan Beller
                     ` (44 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:17 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 builtin/index-pack.c |  2 +-
 commit.c             | 33 ++++++++++++++++++++++-----------
 commit.h             | 17 ++++++++---------
 object.h             |  6 +++++-
 repository.c         |  6 ++++++
 5 files changed, 42 insertions(+), 22 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 150/194] tree: allow lookup_tree to handle arbitrary repositories
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (48 preceding siblings ...)
  2018-02-06  0:17   ` [PATCH 149/194] commit: allow commit buffer functions to handle arbitrary repositories Stefan Beller
@ 2018-02-06  0:17   ` " Stefan Beller
  2018-02-06  0:17   ` [PATCH 151/194] cache: convert get_graft_file " Stefan Beller
                     ` (43 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:17 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 tree.c | 10 +++++-----
 tree.h |  3 +--
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/tree.c b/tree.c
index 1635a01794..e8150ba54b 100644
--- a/tree.c
+++ b/tree.c
@@ -194,13 +194,13 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match,
 	return 0;
 }
 
-struct tree *lookup_tree_the_repository(const struct object_id *oid)
+struct tree *lookup_tree(struct repository *r, const struct object_id *oid)
 {
-	struct object *obj = lookup_object(the_repository, oid->hash);
+	struct object *obj = lookup_object(r, oid->hash);
 	if (!obj)
-		return create_object(the_repository, oid->hash,
-				     alloc_tree_node(the_repository));
-	return object_as_type(the_repository, obj, OBJ_TREE, 0);
+		return create_object(r, oid->hash,
+				     alloc_tree_node(r));
+	return object_as_type(r, obj, OBJ_TREE, 0);
 }
 
 int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size)
diff --git a/tree.h b/tree.h
index 8195db473f..5e7988d390 100644
--- a/tree.h
+++ b/tree.h
@@ -12,8 +12,7 @@ struct tree {
 	unsigned long size;
 };
 
-#define lookup_tree(r, oid) lookup_tree_##r(oid)
-struct tree *lookup_tree_the_repository(const struct object_id *oid);
+struct tree *lookup_tree(struct repository *r, const struct object_id *oid);
 
 int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size);
 
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 151/194] cache: convert get_graft_file to handle arbitrary repositories
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (49 preceding siblings ...)
  2018-02-06  0:17   ` [PATCH 150/194] tree: allow lookup_tree " Stefan Beller
@ 2018-02-06  0:17   ` " Stefan Beller
  2018-02-06  0:17   ` [PATCH 152/194] shallow: add repository argument to set_alternate_shallow_file Stefan Beller
                     ` (42 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:17 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 cache.h       | 2 +-
 commit.c      | 2 +-
 environment.c | 6 +++---
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/cache.h b/cache.h
index ee01daf130..a74a10fe1f 100644
--- a/cache.h
+++ b/cache.h
@@ -489,7 +489,7 @@ extern const char *get_git_dir(void);
 extern const char *get_git_common_dir(void);
 extern char *get_object_directory(void);
 extern char *get_index_file(void);
-extern char *get_graft_file(void);
+extern char *get_graft_file(struct repository *r);
 extern int set_git_dir(const char *path);
 extern int get_common_dir_noenv(struct strbuf *sb, const char *gitdir);
 extern int get_common_dir(struct strbuf *sb, const char *gitdir);
diff --git a/commit.c b/commit.c
index a5e570f057..32eda5f7c9 100644
--- a/commit.c
+++ b/commit.c
@@ -205,7 +205,7 @@ static void prepare_commit_graft_the_repository(void)
 
 	if (commit_graft_prepared)
 		return;
-	graft_file = get_graft_file();
+	graft_file = get_graft_file(the_repository);
 	read_graft_file(the_repository, graft_file);
 	/* make sure shallows are read */
 	is_repository_shallow();
diff --git a/environment.c b/environment.c
index 249516cf6b..972ade61d8 100644
--- a/environment.c
+++ b/environment.c
@@ -287,11 +287,11 @@ char *get_index_file(void)
 	return the_repository->index_file;
 }
 
-char *get_graft_file(void)
+char *get_graft_file(struct repository *r)
 {
-	if (!the_repository->graft_file)
+	if (!r->graft_file)
 		BUG("git environment hasn't been setup");
-	return the_repository->graft_file;
+	return r->graft_file;
 }
 
 int set_git_dir(const char *path)
-- 
2.15.1.433.g936d1b9894.dirty


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 152/194] shallow: add repository argument to set_alternate_shallow_file
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (50 preceding siblings ...)
  2018-02-06  0:17   ` [PATCH 151/194] cache: convert get_graft_file " Stefan Beller
@ 2018-02-06  0:17   ` Stefan Beller
  2018-02-06  0:17   ` [PATCH 153/194] shallow: add repository argument to register_shallow Stefan Beller
                     ` (41 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:17 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 commit.h      | 3 ++-
 environment.c | 2 +-
 git.c         | 2 +-
 shallow.c     | 2 +-
 4 files changed, 5 insertions(+), 4 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 153/194] shallow: add repository argument to register_shallow
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (51 preceding siblings ...)
  2018-02-06  0:17   ` [PATCH 152/194] shallow: add repository argument to set_alternate_shallow_file Stefan Beller
@ 2018-02-06  0:17   ` Stefan Beller
  2018-02-06  0:17   ` [PATCH 154/194] shallow: add repository argument to check_shallow_file_for_update Stefan Beller
                     ` (40 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:17 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 builtin/pack-objects.c | 2 +-
 builtin/receive-pack.c | 2 +-
 commit.h               | 3 ++-
 fetch-pack.c           | 2 +-
 shallow.c              | 4 ++--
 upload-pack.c          | 7 ++++---
 6 files changed, 11 insertions(+), 9 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 154/194] shallow: add repository argument to check_shallow_file_for_update
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (52 preceding siblings ...)
  2018-02-06  0:17   ` [PATCH 153/194] shallow: add repository argument to register_shallow Stefan Beller
@ 2018-02-06  0:17   ` Stefan Beller
  2018-02-06  0:17   ` [PATCH 155/194] shallow: add repository argument to is_repository_shallow Stefan Beller
                     ` (39 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:17 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 shallow.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 155/194] shallow: add repository argument to is_repository_shallow
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (53 preceding siblings ...)
  2018-02-06  0:17   ` [PATCH 154/194] shallow: add repository argument to check_shallow_file_for_update Stefan Beller
@ 2018-02-06  0:17   ` Stefan Beller
  2018-02-06  0:17   ` [PATCH 156/194] migrate cached path to use the_repository Stefan Beller
                     ` (38 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:17 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 builtin/fetch.c                       | 2 +-
 builtin/pack-objects.c                | 4 ++--
 builtin/prune.c                       | 2 +-
 builtin/rev-parse.c                   | 3 ++-
 commit.c                              | 2 +-
 commit.h                              | 2 ++
 contrib/coccinelle/object_store.cocci | 5 +++++
 fetch-pack.c                          | 4 ++--
 send-pack.c                           | 6 +++---
 shallow.c                             | 8 ++++----
 upload-pack.c                         | 2 +-
 11 files changed, 24 insertions(+), 16 deletions(-)

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


^ permalink raw reply	[flat|nested] 239+ messages in thread

* [PATCH 156/194] migrate cached path to use the_repository
  2018-02-06  0:16 ` [PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories Stefan Beller
                     ` (54 preceding siblings ...)
  2018-02-06  0:17   ` [PATCH 155/194] shallow: add repository argument to is_repository_shallow Stefan Beller
@ 2018-02-06  0:17   ` Stefan Beller
  2018-02-06  0:17   ` [PATCH 157/194] shallow: migrate shallow information into the object parser Stefan Beller
                     ` (37 subsequent siblings)
  93 siblings, 0 replies; 239+ messages in thread
From: Stefan Beller @ 2018-02-06  0:17 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 blame.c                              |  8 ++++---
 branch.c                             | 14 ++++++------
 builtin/commit.c                     | 38 +++++++++++++++----------------
 builtin/fetch.c                      |  4 ++--
 builtin/merge.c                      | 37 +++++++++++++++---------------
 builtin/pull.c                       |  4 ++--
 builtin/reset.c                      |  2 +-
 contrib/coccinelle/cached_path.cocci | 44 ++++++++++++++++++++++++++++++++++++
 fetch-pack.c                         |  2 +-
 path.c                               | 18 +++++++--------
 path.h                               | 40 ++++++++++++++++++++++++--------
 repository.c                         |  2 +-
 repository.h                         |  5 ++++
 rerere.c                             |  7 +++---
 sequencer.c                          | 33 ++++++++++++++-------------
 shallow.c                            | 12 ++++++----
 wt-status.c                          |  8 +++----
 17 files changed, 178 insertions(+), 100 deletions(-)
 create mode 100644 contrib/coccinelle/cached_path.cocci

diff --git a/blame.c b/blame.c
index 1cd39e7a17..6832271319 100644
--- a/blame.c
+++ b/blame.c
@@ -112,17 +112,19 @@ static void append_merge_parents(struct commit_list **tail)
 	int merge_head;
 	struct strbuf line = STRBUF_INIT;
 
-	merge_head = open(git_path_merge_head(), O_RDONLY);
+	merge_head = open(git_path_merge_head(the_repository), O_RDONLY);
 	if (merge_head < 0) {
 		if (errno == ENOENT)
 			return;
-		die("cannot open '%s' for reading", git_path_merge_head());
+		die("cannot open '%s' for reading",
+		    git_path_merge_head(the_repository));
 	}
 
 	while (!strbuf_getwholeline_fd(&line, merge_head, '\n')) {
 		struct object_id oid;
 		if (line.len < GIT_SHA1_HEXSZ || get_oid_hex(line.buf, &oid))
-			die("unknown line in '%s': %s", git_path_merge_head(), line.buf);
+			die("unknown line in '%s': %s",
+			    git_path_merge_head(the_repository), line.buf);
 		tail = append_parent(tail, &oid);
 	}
 	close(merge_head);
diff --git a/branch.c b/branch.c
index 0b7aaa1aca..08d4efc1be 100644
--- a/branch.c
+++ b/branch.c
@@ -339,13 +339,13 @@ void create_branch(const char *name, const char *start_name,
 
 void remove_branch_state(void)
 {
-	unlink(git_path_cherry_pick_head());
-	unlink(git_path_revert_head());
-	unlink(git_path_merge_head());
-	unlink(git_path_merge_rr());
-	unlink(git_path_merge_msg());
-	unlink(git_path_merge_mode());
-	unlink(git_path_squash_msg());
+	unlink(git_path_cherry_pick_head(the_repository));
+	unlink(git_path_revert_head(the_repository));
+	unlink(git_path_merge_head(the_repository));
+	unlink(git_path_merge_rr(the_repository));
+	unlink(git_path_merge_msg(the_repository));
+	unlink(git_path_merge_mode(the_repository));
+	unlink(git_path_squash_msg(the_repository));
 }
 
 void die_if_checked_out(const char *branch, int ignore_current_worktree)
diff --git a/builtin/commit.c b/builtin/commit.c
index d15592ad45..cceb965569 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -179,9 +179,9 @@ static int opt_parse_m(const struct option *opt, const char *arg, int unset)
 
 static void determine_whence(struct wt_status *s)
 {
-	if (file_exists(git_path_merge_head()))
+	if (file_exists(git_path_merge_head(the_repository)))
 		whence = FROM_MERGE;
-	else if (file_exists(git_path_cherry_pick_head())) {
+	else if (file_exists(git_path_cherry_pick_head(the_repository))) {
 		whence = FROM_CHERRY_PICK;
 		if (file_exists(git_path_seq_dir()))
 			sequencer_in_use = 1;
@@ -732,21 +732,21 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 		format_commit_message(commit, "fixup! %s\n\n",
 				      &sb, &ctx);
 		hook_arg1 = "message";
-	} else if (!stat(git_path_merge_msg(), &statbuf)) {
+	} else if (!stat(git_path_merge_msg(the_repository), &statbuf)) {
 		/*
 		 * prepend SQUASH_MSG here if it exists and a
 		 * "merge --squash" was originally performed
 		 */
-		if (!stat(git_path_squash_msg(), &statbuf)) {
-			if (strbuf_read_file(&sb, git_path_squash_msg(), 0) < 0)
+		if (!stat(git_path_squash_msg(the_repository), &statbuf)) {
+			if (strbuf_read_file(&sb, git_path_squash_msg(the_repository), 0) < 0)
 				die_errno(_("could not read SQUASH_MSG"));
 			hook_arg1 = "squash";
 		} else
 			hook_arg1 = "merge";
-		if (strbuf_read_file(&sb, git_path_merge_msg(), 0) < 0)
+		if (strbuf_read_file(&sb, git_path_merge_msg(the_repository), 0) < 0)
 			die_errno(_("could not read MERGE_MSG"));
-	} else if (!stat(git_path_squash_msg(), &statbuf)) {
-		if (strbuf_read_file(&sb, git_path_squash_msg(), 0) < 0)
+	} else if (!stat(git_path_squash_msg(the_repository), &statbuf)) {
+		if (strbuf_read_file(&sb, git_path_squash_msg(the_repository), 0) < 0)
 			die_errno(_("could not read SQUASH_MSG"));
 		hook_arg1 = "squash";
 	} else if (te