{"thread":{"id":"47765","subject":"[RFC PATCH 000/194] Moving global state into the repository object","startedAt":"2018-02-05T23:55:39Z","lastAt":"2018-02-14T01:27:01Z","messageCount":239,"participants":["Stefan Beller","brian m. carlson","Eric Sunshine","Derrick Stolee","Duy Nguyen","Jeff Hostetler","Jonathan Tan","Elijah Newren","Junio C Hamano","René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":194},"messages":[{"id":"338265","messageId":"20180205235508.216277-1-sbeller@google.com","threadId":"47765","inReplyTo":null,"subject":"[RFC PATCH 000/194] Moving global state into the repository object","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:51:54Z","receivedAt":"2018-02-05T23:55:39Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"This series moves a lot of global state into the repository struct.\nIt applies on top of 2512f15446149235156528dafbe75930c712b29e (2.16.0)\nIt can be found at https://github.com/stefanbeller/git/tree/object-store\n\nMotivation for this series:\n* Easier to reason about code when all state is stored in one place,\n  for example for multithreading\n* Easier to move to processing submodules in-process instead of\n  calling a processes for the submodule handling.\n  The last patch demonstrates this.\n\nUsually when approaching large refactoring series, a lot of tedious review\nwork is involved and yet it is hard to be convinced the series did everything\nright.\n\nWhen reviewing this series in particular it is hard to be convinced if\nany function that is converted to take the repository as an argument\nis fully converted or if there are any hidden dependencies that are not\nobvious from code review.\n\nThis is why this series tries to be reviewer friendly by utilizing\nmachine assistance as much as possible. There are 3 types of patches\nin this series:\n\n(A) <area>: add repository argument to <function_foo>\n  This sort of patch is just adding the repository as an argument to that\n  function. It assumes the given repository is `the_repository` and has\n  a compile time check for that assertion using a preprocessor trick.\n  As did a compile check after each commit of the series, I don't expect\n  the review burden on these patches to be high. Review on these patches\n  is mostly checking for formatting errors or if I sneak in malicious\n  code -- if you're inclined to believe that.\n\n(B) <area>: allow <function_foo> to handle arbitrary repositories\n  This sort of patch is touching code inside the given function only,\n  usually replacing all occurrences of `the_repository` by the argument\n  `r`. Here the review is critical: Did I miss any function that relies\n  on state of `the_repository` ?\n  This series was developed by converting all functions of\n  packfile/sha1-file/commit/etc using (A); after the demo patch\n  was possible, all patches that did (A), but not (B) were deleted.\n  Therefore I was confident at time of writing that patch that\n  the conversion of a function which doesn't take a repository argument\n  is okay.\n\n(C) other patches, such as moving code around,\n    demoing this series in the last patch\n\nThis approach was chosen as I think it is review friendly, despite the\nhuge number of patches.\n\nA weakness of this approach is the buildup of a large series, which ignores\nthe ongoing development. Rebasing that series turned out to be ok, but merging\nit with confidence is an issue.\n\nThis series was developed partially as a pair programming exercise with\nJonathan Nieder and Brandon Williams.\n\nThe idea with the #define trick to separate the two very separate issues\nof touching a lot of code and reasoning about its correctness (hidden deps)\nis mostly from Jonathan Tan.\n\nAny suggestions welcome!\n\nThanks,\nStefan\n\nBrandon Williams (4):\n  sha1_file: allow add_to_alternates_file to handle arbitrary\n    repositories\n  commit: convert commit_graft_pos() to handle arbitrary repositories\n  commit: convert register_commit_graft to handle arbitrary repositories\n  commit: convert read_graft_file to handle arbitrary repositories\n\nJonathan Nieder (50):\n  object-store: move packed_git and packed_git_mru to object store\n  pack: move prepare_packed_git_run_once to object store\n  pack: move approximate object count to object store\n  pack: add repository argument to install_packed_git\n  pack: add repository argument to prepare_packed_git_one\n  pack: add repository argument to rearrange_packed_git\n  pack: add repository argument to prepare_packed_git_mru\n  pack: add repository argument to prepare_packed_git\n  pack: add repository argument to reprepare_packed_git\n  pack: add repository argument to sha1_file_name\n  pack: add repository argument to map_sha1_file\n  sha1_file: allow alt_odb_usable to handle arbitrary repositories\n  pack: allow install_packed_git to handle arbitrary repositories\n  pack: allow rearrange_packed_git to handle arbitrary repositories\n  pack: allow prepare_packed_git_mru to handle arbitrary repositories\n  pack: allow prepare_packed_git_one to handle arbitrary repositories\n  pack: allow prepare_packed_git to handle arbitrary repositories\n  pack: allow reprepare_packed_git to handle arbitrary repositories\n  pack: allow sha1_file_name to handle arbitrary repositories\n  pack: allow stat_sha1_file to handle arbitrary repositories\n  pack: allow open_sha1_file to handle arbitrary repositories\n  pack: allow map_sha1_file_1 to handle arbitrary repositories\n  pack: allow map_sha1_file to handle arbitrary repositories\n  pack: allow sha1_loose_object_info to handle arbitrary repositories\n  sha1_file: add repository argument to sha1_object_info_extended\n  object-store: move alternates API to new alternates.h\n  object-store: move loose object functions to new loose-object.h\n  pack: move struct pack_window and pack_entry to packfile.h\n  object-store: move replace_objects back to object-store\n  object-store: move lookup_replace_object to replace-object.h\n  pack: add repository argument to packed_object_info\n  pack: add repository argument to find_pack_entry\n  object: add repository argument to lookup_object\n  object: add repository argument to grow_object_hash\n  object: add repository argument to lookup_commit_reference_gently\n  object: add repository argument to lookup_commit\n  object: move grafts to object parser\n  object: add repository argument to commit_graft_pos\n  object: add repository argument to register_commit_graft\n  object: add repository argument to read_graft_file\n  object: add repository argument to prepare_commit_graft\n  object: add repository argument to lookup_commit_graft\n  object: add repository argument to lookup_unknown_object\n  Rename sha1_object_info.cocci to object_store.cocci\n  alternates: add repository argument to add_to_alternates_memory\n  object-store: move check_sha1_signature to object-store.h\n  object-store: add repository argument to check_sha1_signature\n  object-store: add repository argument to read_object\n  object-store: add repository argument to read_sha1_file_extended\n  object: move read_object_with_reference to object.h\n\nStefan Beller (140):\n  repository: introduce object store field\n  object-store: move alt_odb_list and alt_odb_tail to object store\n  sha1_file: add repository argument to alt_odb_usable\n  sha1_file: add repository argument to link_alt_odb_entry\n  sha1_file: add repository argument to read_info_alternates\n  sha1_file: add repository argument to link_alt_odb_entries\n  sha1_file: add repository argument to stat_sha1_file\n  sha1_file: add repository argument to open_sha1_file\n  sha1_file: add repository argument to map_sha1_file_1\n  sha1_file: add repository argument to sha1_loose_object_info\n  object-store: add repository argument to prepare_alt_odb\n  object-store: add repository argument to foreach_alt_odb\n  object-store: allow prepare_alt_odb to handle arbitrary repositories\n  object-store: allow foreach_alt_odb to handle arbitrary repositories\n  replace_object.c: rename to use dash in file name\n  replace-object: move replace_object to object store\n  object-store: move object access functions to object-store.h\n  replace-object: add repository argument to do_lookup_replace_object\n  replace-object: move replace objects prepared flag to object store\n  replace-object: check_replace_refs is safe in multi repo environment\n  refs: add repository argument to for_each_replace_ref\n  refs: add repository argument to get_main_ref_store\n  replace-object: add repository argument to register_replace_object\n  replace-object: add repository argument to register_replace_ref\n  replace-object: add repository argument to replace_object_pos\n  replace-object: allow replace_object_pos to handle arbitrary\n    repositories\n  replace-object: allow register_replace_object to handle arbitrary\n    repositories\n  replace-object: add repository argument to prepare_replace_object\n  refs: store the main ref store inside the repository struct\n  refs: allow for_each_replace_ref to handle arbitrary repositories\n  replace-object: allow prepare_replace_object to handle arbitrary\n    repositories\n  replace_object: allow do_lookup_replace_object to handle arbitrary\n    repositories\n  replace-object: add repository argument to lookup_replace_object\n  repository: allow lookup_replace_object to handle arbitrary\n    repositories\n  object-store: add repository argument to sha1_object_info\n  pack: add repository argument to retry_bad_packed_offset\n  pack: add repository argument to packed_to_object_type\n  packfile: add repository argument to read_object\n  packfile: add repository argument to unpack_entry\n  packfile: add repository argument to cache_or_unpack_entry\n  pack: allow find_pack_entry to handle arbitrary repositories\n  object-store: allow sha1_object_info to handle arbitrary repositories\n  fetch, push: do not use submodule as alternate in has_commits check\n  push: add test showing bad interaction of replace refs and submodules\n  replace_object: allow register_replace_ref to handle arbitrary\n    repositories\n  cache.h: migrate the definition of object_id to object.h\n  repository: introduce object parser field\n  object: add repository argument to parse_object\n  object: add repository argument to create_object\n  blob: add repository argument to lookup_blob\n  tree: add repository argument to lookup_tree\n  tag: add repository argument to lookup_tag\n  tag: add repository argument to parse_tag_buffer\n  tag: add repository argument to deref_tag\n  object: add repository argument to lookup_commit_reference\n  commit: add repository argument to parse_commit_buffer\n  object: allow grow_object_hash to handle arbitrary repositories\n  object: allow create_object to handle arbitrary repositories\n  object: allow lookup_object to handle arbitrary repositories\n  object: allow lookup_unknown_object to handle arbitrary repositories\n  object: add repository argument to parse_object_buffer\n  repository: keep track of all open repositories\n  alternates: add repository argument to add_to_alternates_file\n  object-store: add repository argument to read_sha1_file\n  packfile: add repository argument to has_packed_and_bad\n  packfile: allow has_packed_and_bad to handle arbitrary repositories\n  streaming: add repository argument to open_istream_fn\n  streaming: add repository argument to open_istream\n  streaming: add repository argument to istream_source\n  streaming: allow istream_source to handle arbitrary repositories\n  sha1_file: allow read_object to handle arbitrary repositories\n  object-store.h: allow read_sha1_file{_extended} to handle arbitrary\n    repositories\n  streaming: allow open_istream_incore to handle arbitrary repositories\n  streaming: allow open_istream_pack_non_delta to handle arbitrary\n    repositories\n  streaming: allow open_istream_loose to handle arbitrary repositories\n  streaming: allow open_istream to handle arbitrary repositories\n  alternates: convert add_to_alternates_memory to handle arbitrary repos\n  object: add repository argument to object_as_type\n  alloc: add repository argument to alloc_blob_node\n  alloc: add repository argument to alloc_tree_node\n  alloc: add repository argument to alloc_commit_node\n  alloc: add repository argument to alloc_tag_node\n  alloc: add repository argument to alloc_object_node\n  alloc: add repository argument to alloc_report\n  alloc: add repository argument to alloc_commit_index\n  alloc: allow arbitrary repositories for alloc functions\n  object: allow object_as_type to handle arbitrary repositories\n  commit: allow lookup_commit to handle arbitrary repositories\n  object: add repository argument to parse_commit_gently\n  commit: add repository argument to parse_commit\n  commit: add repository argument to set_commit_buffer\n  commit: add repository argument to get_cached_commit_buffer\n  commit: add repository argument to unuse_commit_buffer\n  commit: add repository argument to free_commit_buffer\n  commit: allow commit buffer functions to handle arbitrary repositories\n  tree: allow lookup_tree to handle arbitrary repositories\n  cache: convert get_graft_file to handle arbitrary repositories\n  shallow: add repository argument to set_alternate_shallow_file\n  shallow: add repository argument to register_shallow\n  shallow: add repository argument to check_shallow_file_for_update\n  shallow: add repository argument to is_repository_shallow\n  migrate cached path to use the_repository\n  shallow: migrate shallow information into the object parser\n  commit: allow prepare_commit_graft to handle arbitrary repositories\n  commit: allow lookup_commit_graft to handle arbitrary repositories\n  commit: allow arbitrary repository argument for parse_commit_buffer\n  commit: allow parse_commit_gently to handle arbitrary repository\n  commit: add repository argument to get_merge_bases_many_0\n  commit: add repository argument to merge_bases_many\n  commit: add repository argument to paint_down_to_common\n  commit: allow parse_commit to handle arbitrary repositories\n  commit: allow paint_down_to_common to handle arbitrary repositories\n  commit: allow merge_bases_many to handle arbitrary repositories\n  commit: add repository argument to remove_redundant\n  commit: allow remove_redundant to handle arbitrary repositories\n  commit: allow get_merge_bases_many_0 to handle arbitrary repositories\n  commit: add repository argument to get_merge_bases\n  commit: allow get_merge_bases to handle arbitrary repositories\n  blob: allow lookup_blob to handle arbitrary repositories\n  tag: allow lookup_tag to handle arbitrary repositories\n  tag: allow parse_tag_buffer to handle arbitrary repositories\n  object: allow parse_object_buffer to handle arbitrary repositories\n  objects: allow check_sha1_signature to handle arbitrary repositories\n  object: allow parse_object to handle arbitrary repositories\n  tag: allow deref_tag to handle arbitrary repositories\n  commit: allow lookup_commit_reference_gently to handle arbitrary\n    repositories\n  commit: allow lookup_commit_reference to handle arbitrary repositories\n  commit: add repository argument to get_commit_buffer\n  commit: add repository argument to logmsg_reencode\n  pretty: add repository argument to format_commit_message\n  commit: allow get_commit_buffer to handle arbitrary repositories\n  pretty: allow logmsg_reencode to handle arbitrary repositories\n  commit: add repository argument to in_merge_bases_many\n  commit: add repository argument to in_merge_bases\n  commit: allow in_merge_bases_many to handle arbitrary repositories\n  commit: allow in_merge_bases to handle arbitrary repositories\n  pretty: allow format_commit_message to handle arbitrary repositories\n  submodule: add repository argument to print_submodule_summary\n  submodule: Reorder open_submodule function\n  submodule: use submodule repos for object lookup\n\n Makefile                                   |   2 +-\n alloc.c                                    |  48 +++--\n alternates.h                               |  68 +++++++\n apply.c                                    |   8 +-\n archive-tar.c                              |   6 +-\n archive-zip.c                              |   8 +-\n archive.c                                  |   9 +-\n bisect.c                                   |   6 +-\n blame.c                                    |  40 ++--\n blob.c                                     |  10 +-\n blob.h                                     |   2 +-\n branch.c                                   |  16 +-\n builtin/am.c                               |  14 +-\n builtin/blame.c                            |   9 +-\n builtin/branch.c                           |  11 +-\n builtin/cat-file.c                         |  28 ++-\n builtin/checkout.c                         |  12 +-\n builtin/clone.c                            |  14 +-\n builtin/commit-tree.c                      |   5 +-\n builtin/commit.c                           |  63 +++---\n builtin/count-objects.c                    |  12 +-\n builtin/describe.c                         |  19 +-\n builtin/diff-tree.c                        |   9 +-\n builtin/diff.c                             |   7 +-\n builtin/difftool.c                         |   5 +-\n builtin/fast-export.c                      |  30 +--\n builtin/fetch.c                            |  21 +-\n builtin/fmt-merge-msg.c                    |  19 +-\n builtin/fsck.c                             |  44 ++--\n builtin/gc.c                               |   8 +-\n builtin/grep.c                             |  10 +-\n builtin/hash-object.c                      |   1 +\n builtin/index-pack.c                       |  26 ++-\n builtin/log.c                              |  26 ++-\n builtin/ls-files.c                         |   2 +-\n builtin/ls-tree.c                          |   4 +-\n builtin/merge-base.c                       |  11 +-\n builtin/merge-tree.c                       |  12 +-\n builtin/merge.c                            |  41 ++--\n builtin/mktag.c                            |  10 +-\n builtin/mktree.c                           |   4 +-\n builtin/name-rev.c                         |  15 +-\n builtin/notes.c                            |  16 +-\n builtin/pack-objects.c                     |  66 +++---\n builtin/pack-redundant.c                   |   8 +-\n builtin/pack-refs.c                        |   3 +-\n builtin/prune-packed.c                     |   1 +\n builtin/prune.c                            |   8 +-\n builtin/pull.c                             |  19 +-\n builtin/receive-pack.c                     |  14 +-\n builtin/reflog.c                           |  21 +-\n builtin/remote.c                           |   1 +\n builtin/replace.c                          |  24 ++-\n builtin/reset.c                            |  11 +-\n builtin/rev-list.c                         |   7 +-\n builtin/rev-parse.c                        |  11 +-\n builtin/shortlog.c                         |   5 +-\n builtin/show-branch.c                      |   9 +-\n builtin/show-ref.c                         |   1 +\n builtin/submodule--helper.c                |   5 +-\n builtin/tag.c                              |  12 +-\n builtin/unpack-file.c                      |   4 +-\n builtin/unpack-objects.c                   |  15 +-\n builtin/verify-commit.c                    |   7 +-\n bulk-checkin.c                             |   3 +-\n bundle.c                                   |   9 +-\n cache-tree.c                               |   4 +-\n cache.h                                    | 315 ++---------------------------\n combine-diff.c                             |   5 +-\n commit.c                                   | 241 ++++++++++++----------\n commit.h                                   |  49 +++--\n config.c                                   |   2 +-\n contrib/coccinelle/cached_path.cocci       |  44 ++++\n contrib/coccinelle/object_parser.cocci     | 125 ++++++++++++\n contrib/coccinelle/object_store.cocci      |  74 +++++++\n contrib/coccinelle/packed_git.cocci        |  15 ++\n contrib/coccinelle/submodule_reading.cocci |  34 ++++\n convert.c                                  |   1 +\n diff.c                                     |   8 +-\n diffcore-rename.c                          |   1 +\n dir.c                                      |   4 +-\n entry.c                                    |   5 +-\n environment.c                              |  10 +-\n fast-import.c                              |  45 +++--\n fetch-pack.c                               |  47 +++--\n fsck.c                                     |  20 +-\n git.c                                      |   2 +-\n grep.c                                     |   5 +-\n http-backend.c                             |  12 +-\n http-push.c                                |  24 ++-\n http-walker.c                              |   5 +-\n http.c                                     |  10 +-\n line-log.c                                 |   2 +-\n list-objects-filter.c                      |   2 +-\n list-objects.c                             |   4 +-\n log-tree.c                                 |  18 +-\n loose-object.h                             |  91 +++++++++\n mailmap.c                                  |   4 +-\n match-trees.c                              |   6 +-\n merge-blobs.c                              |   8 +-\n merge-recursive.c                          |  30 +--\n mru.h                                      |   1 +\n notes-cache.c                              |   9 +-\n notes-merge.c                              |  15 +-\n notes-utils.c                              |   6 +-\n notes.c                                    |  12 +-\n object-store.h                             | 183 +++++++++++++++++\n object.c                                   | 106 +++++-----\n object.h                                   |  82 +++++++-\n pack-bitmap-write.c                        |   7 +-\n pack-bitmap.c                              |   6 +-\n pack-check.c                               |   6 +-\n pack-revindex.c                            |   1 +\n pack.h                                     |   1 +\n packfile.c                                 | 149 ++++++++------\n packfile.h                                 |  41 +++-\n parse-options-cb.c                         |   2 +-\n path.c                                     |  18 +-\n path.h                                     |  40 +++-\n pretty.c                                   |  24 ++-\n pretty.h                                   |   2 +-\n reachable.c                                |  12 +-\n read-cache.c                               |   7 +-\n ref-filter.c                               |  15 +-\n reflog-walk.c                              |   3 +-\n refs.c                                     |  87 ++++----\n refs.h                                     |   4 +-\n refs/files-backend.c                       |   2 +-\n remote-testsvn.c                           |   6 +-\n remote.c                                   |  27 ++-\n replace_object.c => replace-object.c       |  70 +++----\n replace-object.h                           |  34 ++++\n repository.c                               |  84 ++++++--\n repository.h                               |  33 ++-\n rerere.c                                   |  12 +-\n revision.c                                 |  48 ++---\n send-pack.c                                |   7 +-\n sequencer.c                                |  93 +++++----\n server-info.c                              |  12 +-\n sha1_file.c                                | 236 +++++++++++----------\n sha1_name.c                                |  75 ++++---\n shallow.c                                  | 113 ++++++-----\n streaming.c                                |  33 +--\n streaming.h                                |   2 +-\n submodule-config.c                         |   3 +-\n submodule.c                                | 100 +++++----\n t/helper/test-example-decorate.c           |   6 +-\n t/helper/test-ref-store.c                  |   6 +-\n t/helper/test-revision-walking.c           |   2 +-\n t/t5531-deep-submodule-push.sh             |  16 ++\n tag.c                                      |  36 ++--\n tag.h                                      |   7 +-\n tmp-objdir.c                               |   4 +-\n transport.c                                |   5 +-\n tree-walk.c                                |   5 +-\n tree.c                                     |  24 ++-\n tree.h                                     |   2 +-\n upload-pack.c                              |  25 ++-\n walker.c                                   |  17 +-\n wt-status.c                                |  10 +-\n xdiff-interface.c                          |   4 +-\n 161 files changed, 2669 insertions(+), 1596 deletions(-)\n create mode 100644 alternates.h\n create mode 100644 contrib/coccinelle/cached_path.cocci\n create mode 100644 contrib/coccinelle/object_parser.cocci\n create mode 100644 contrib/coccinelle/object_store.cocci\n create mode 100644 contrib/coccinelle/packed_git.cocci\n create mode 100644 contrib/coccinelle/submodule_reading.cocci\n create mode 100644 loose-object.h\n create mode 100644 object-store.h\n rename replace_object.c => replace-object.c (55%)\n create mode 100644 replace-object.h\n\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338266","messageId":"20180205235508.216277-2-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235508.216277-1-sbeller@google.com","subject":"[PATCH 001/194] repository: introduce object store field","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:51:55Z","receivedAt":"2018-02-05T23:55:43Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"The object store field will contain any objects needed for access to\nobjects in a given repository.\n\nThis patch introduces the object store but for now it is empty.  C99\nforbids empty structs, but common C compilers cope well with them and\nthis struct will gain members very soon (starting with the next\npatch).\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n object-store.h | 8 ++++++++\n repository.c   | 4 +++-\n repository.h   | 7 +++++++\n 3 files changed, 18 insertions(+), 1 deletion(-)\n create mode 100644 object-store.h\n\ndiff --git a/object-store.h b/object-store.h\nnew file mode 100644\nindex 0000000000..05722cdde0\n--- /dev/null\n+++ b/object-store.h\n@@ -0,0 +1,8 @@\n+#ifndef OBJECT_STORE_H\n+#define OBJECT_STORE_H\n+\n+struct object_store {\n+};\n+#define OBJECT_STORE_INIT {}\n+\n+#endif /* OBJECT_STORE_H */\ndiff --git a/repository.c b/repository.c\nindex 998413b8bb..0ec9648f53 100644\n--- a/repository.c\n+++ b/repository.c\n@@ -1,11 +1,13 @@\n #include \"cache.h\"\n #include \"repository.h\"\n+#include \"object-store.h\"\n #include \"config.h\"\n #include \"submodule-config.h\"\n \n /* The main repository */\n static struct repository the_repo = {\n-\tNULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &the_index, NULL, 0, 0\n+\tNULL, NULL, NULL, OBJECT_STORE_INIT,\n+\tNULL, NULL, NULL, NULL, NULL, NULL, &the_index, NULL, 0, 0\n };\n struct repository *the_repository = &the_repo;\n \ndiff --git a/repository.h b/repository.h\nindex 0329e40c7f..ba7b3b7cb9 100644\n--- a/repository.h\n+++ b/repository.h\n@@ -1,6 +1,8 @@\n #ifndef REPOSITORY_H\n #define REPOSITORY_H\n \n+#include \"object-store.h\"\n+\n struct config_set;\n struct index_state;\n struct submodule_cache;\n@@ -26,6 +28,11 @@ struct repository {\n \t */\n \tchar *objectdir;\n \n+\t/*\n+\t * Holds any information related to the object store.\n+\t */\n+\tstruct object_store objects;\n+\n \t/*\n \t * Path to the repository's graft file.\n \t * Cannot be NULL after initialization.\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338267","messageId":"20180205235508.216277-3-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235508.216277-1-sbeller@google.com","subject":"[PATCH 002/194] object-store: move alt_odb_list and alt_odb_tail to object store","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:51:56Z","receivedAt":"2018-02-05T23:55:45Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"In a process with multiple repositories open, alternates should be\nassociated to a single repository and not shared globally. Move\nalt_odb_list and alt_odb_tail into the_repository and adjust callers\nto reflect this.\n\nNo functional change intended.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n builtin/fsck.c |  4 +++-\n cache.h        |  4 ++--\n object-store.h |  6 +++++-\n packfile.c     |  3 ++-\n sha1_file.c    | 25 ++++++++++++-------------\n sha1_name.c    |  3 ++-\n 6 files changed, 26 insertions(+), 19 deletions(-)\n\ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex 04846d46f9..1048255da1 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -1,5 +1,6 @@\n #include \"builtin.h\"\n #include \"cache.h\"\n+#include \"repository.h\"\n #include \"config.h\"\n #include \"commit.h\"\n #include \"tree.h\"\n@@ -694,7 +695,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)\n \t\tfsck_object_dir(get_object_directory());\n \n \t\tprepare_alt_odb();\n-\t\tfor (alt = alt_odb_list; alt; alt = alt->next)\n+\t\tfor (alt = the_repository->objects.alt_odb_list;\n+\t\t\t\talt; alt = alt->next)\n \t\t\tfsck_object_dir(alt->path);\n \n \t\tif (check_full) {\ndiff --git a/cache.h b/cache.h\nindex d8b975a571..918c2f15b4 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1573,7 +1573,7 @@ extern int has_dirs_only_path(const char *name, int len, int prefix_len);\n extern void schedule_dir_for_removal(const char *name, int len);\n extern void remove_scheduled_dirs(void);\n \n-extern struct alternate_object_database {\n+struct alternate_object_database {\n \tstruct alternate_object_database *next;\n \n \t/* see alt_scratch_buf() */\n@@ -1591,7 +1591,7 @@ extern struct alternate_object_database {\n \tstruct oid_array loose_objects_cache;\n \n \tchar path[FLEX_ARRAY];\n-} *alt_odb_list;\n+};\n extern void prepare_alt_odb(void);\n extern char *compute_alternate_path(const char *path, struct strbuf *err);\n typedef int alt_odb_fn(struct alternate_object_database *, void *);\ndiff --git a/object-store.h b/object-store.h\nindex 05722cdde0..ace3efbfab 100644\n--- a/object-store.h\n+++ b/object-store.h\n@@ -1,8 +1,12 @@\n #ifndef OBJECT_STORE_H\n #define OBJECT_STORE_H\n \n+#include \"cache.h\"\n+\n struct object_store {\n+\tstruct alternate_object_database *alt_odb_list;\n+\tstruct alternate_object_database **alt_odb_tail;\n };\n-#define OBJECT_STORE_INIT {}\n+#define OBJECT_STORE_INIT { NULL, NULL }\n \n #endif /* OBJECT_STORE_H */\ndiff --git a/packfile.c b/packfile.c\nindex 4a5fe7ab18..d61076faaf 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -1,6 +1,7 @@\n #include \"cache.h\"\n #include \"mru.h\"\n #include \"pack.h\"\n+#include \"repository.h\"\n #include \"dir.h\"\n #include \"mergesort.h\"\n #include \"packfile.h\"\n@@ -880,7 +881,7 @@ void prepare_packed_git(void)\n \t\treturn;\n \tprepare_packed_git_one(get_object_directory(), 1);\n \tprepare_alt_odb();\n-\tfor (alt = alt_odb_list; alt; alt = alt->next)\n+\tfor (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next)\n \t\tprepare_packed_git_one(alt->path, 0);\n \trearrange_packed_git();\n \tprepare_packed_git_mru();\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 3da70ac650..2826d5d6ed 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -22,6 +22,7 @@\n #include \"pack-revindex.h\"\n #include \"sha1-lookup.h\"\n #include \"bulk-checkin.h\"\n+#include \"repository.h\"\n #include \"streaming.h\"\n #include \"dir.h\"\n #include \"mru.h\"\n@@ -346,9 +347,6 @@ static const char *alt_sha1_path(struct alternate_object_database *alt,\n \treturn buf->buf;\n }\n \n-struct alternate_object_database *alt_odb_list;\n-static struct alternate_object_database **alt_odb_tail;\n-\n /*\n  * Return non-zero iff the path is usable as an alternate object database.\n  */\n@@ -368,7 +366,7 @@ static int alt_odb_usable(struct strbuf *path, const char *normalized_objdir)\n \t * Prevent the common mistake of listing the same\n \t * thing twice, or object directory itself.\n \t */\n-\tfor (alt = alt_odb_list; alt; alt = alt->next) {\n+\tfor (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next) {\n \t\tif (!fspathcmp(path->buf, alt->path))\n \t\t\treturn 0;\n \t}\n@@ -428,8 +426,8 @@ static int link_alt_odb_entry(const char *entry, const char *relative_base,\n \tent = alloc_alt_odb(pathbuf.buf);\n \n \t/* add the alternate entry */\n-\t*alt_odb_tail = ent;\n-\talt_odb_tail = &(ent->next);\n+\t*the_repository->objects.alt_odb_tail = ent;\n+\tthe_repository->objects.alt_odb_tail = &(ent->next);\n \tent->next = NULL;\n \n \t/* recursively add alternates */\n@@ -563,7 +561,7 @@ void add_to_alternates_file(const char *reference)\n \t\tfprintf_or_die(out, \"%s\\n\", reference);\n \t\tif (commit_lock_file(&lock))\n \t\t\tdie_errno(\"unable to move new alternates file into place\");\n-\t\tif (alt_odb_tail)\n+\t\tif (the_repository->objects.alt_odb_tail)\n \t\t\tlink_alt_odb_entries(reference, '\\n', NULL, 0);\n \t}\n \tfree(alts);\n@@ -661,7 +659,7 @@ int foreach_alt_odb(alt_odb_fn fn, void *cb)\n \tint r = 0;\n \n \tprepare_alt_odb();\n-\tfor (ent = alt_odb_list; ent; ent = ent->next) {\n+\tfor (ent = the_repository->objects.alt_odb_list; ent; ent = ent->next) {\n \t\tr = fn(ent, cb);\n \t\tif (r)\n \t\t\tbreak;\n@@ -673,12 +671,13 @@ void prepare_alt_odb(void)\n {\n \tconst char *alt;\n \n-\tif (alt_odb_tail)\n+\tif (the_repository->objects.alt_odb_tail)\n \t\treturn;\n \n \talt = getenv(ALTERNATE_DB_ENVIRONMENT);\n \n-\talt_odb_tail = &alt_odb_list;\n+\tthe_repository->objects.alt_odb_tail =\n+\t\t\t&the_repository->objects.alt_odb_list;\n \tlink_alt_odb_entries(alt, PATH_SEP, NULL, 0);\n \n \tread_info_alternates(get_object_directory(), 0);\n@@ -717,7 +716,7 @@ static int check_and_freshen_nonlocal(const unsigned char *sha1, int freshen)\n {\n \tstruct alternate_object_database *alt;\n \tprepare_alt_odb();\n-\tfor (alt = alt_odb_list; alt; alt = alt->next) {\n+\tfor (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next) {\n \t\tconst char *path = alt_sha1_path(alt, sha1);\n \t\tif (check_and_freshen_file(path, freshen))\n \t\t\treturn 1;\n@@ -873,7 +872,7 @@ static int stat_sha1_file(const unsigned char *sha1, struct stat *st,\n \n \tprepare_alt_odb();\n \terrno = ENOENT;\n-\tfor (alt = alt_odb_list; alt; alt = alt->next) {\n+\tfor (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next) {\n \t\t*path = alt_sha1_path(alt, sha1);\n \t\tif (!lstat(*path, st))\n \t\t\treturn 0;\n@@ -899,7 +898,7 @@ static int open_sha1_file(const unsigned char *sha1, const char **path)\n \tmost_interesting_errno = errno;\n \n \tprepare_alt_odb();\n-\tfor (alt = alt_odb_list; alt; alt = alt->next) {\n+\tfor (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next) {\n \t\t*path = alt_sha1_path(alt, sha1);\n \t\tfd = git_open(*path);\n \t\tif (fd >= 0)\ndiff --git a/sha1_name.c b/sha1_name.c\nindex 611c7d24dd..957ce25680 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -10,6 +10,7 @@\n #include \"dir.h\"\n #include \"sha1-array.h\"\n #include \"packfile.h\"\n+#include \"repository.h\"\n \n static int get_oid_oneline(const char *, struct object_id *, struct commit_list *);\n \n@@ -104,7 +105,7 @@ static void find_short_object_filename(struct disambiguate_state *ds)\n \t\t */\n \t\tfakeent = alloc_alt_odb(get_object_directory());\n \t}\n-\tfakeent->next = alt_odb_list;\n+\tfakeent->next = the_repository->objects.alt_odb_list;\n \n \tfor (alt = fakeent; alt && !ds->ambiguous; alt = alt->next) {\n \t\tint pos;\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338268","messageId":"20180205235508.216277-4-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235508.216277-1-sbeller@google.com","subject":"[PATCH 003/194] object-store: move packed_git and packed_git_mru to object store","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:51:57Z","receivedAt":"2018-02-05T23:55:48Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nIn a process with multiple repositories open, packfile accessors\nshould be associated to a single repository and not shared globally.\nMove packed_git and packed_git_mru into the_repository and adjust\ncallers to reflect this.\n\nPatch generated by\n\n 1. Moving the struct packed_git declaration to object-store.h\n    and packed_git, packed_git_mru globals to struct object_store.\n\n 2. Applying the semantic patch contrib/coccinelle/packed_git.cocci\n    to adjust callers.\n\n 3. Applying line wrapping fixes from \"make style\" to break the\n    resulting long lines.\n\n 4. Adding missing #includes of repository.h and object-store.h\n    where needed.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n builtin/count-objects.c             |  6 ++++--\n builtin/fsck.c                      |  7 +++++--\n builtin/gc.c                        |  4 +++-\n builtin/index-pack.c                |  1 +\n builtin/pack-objects.c              | 21 ++++++++++++--------\n builtin/pack-redundant.c            |  6 ++++--\n builtin/receive-pack.c              |  1 +\n cache.h                             | 28 --------------------------\n contrib/coccinelle/packed_git.cocci |  7 +++++++\n fast-import.c                       |  6 ++++--\n http-backend.c                      |  6 ++++--\n http-push.c                         |  1 +\n http-walker.c                       |  1 +\n http.c                              |  1 +\n mru.h                               |  1 +\n object-store.h                      | 33 ++++++++++++++++++++++++++++++-\n pack-bitmap.c                       |  4 +++-\n pack-check.c                        |  1 +\n pack-revindex.c                     |  1 +\n packfile.c                          | 39 +++++++++++++++++++------------------\n reachable.c                         |  1 +\n server-info.c                       |  6 ++++--\n sha1_name.c                         |  5 +++--\n 23 files changed, 115 insertions(+), 72 deletions(-)\n create mode 100644 contrib/coccinelle/packed_git.cocci\n\ndiff --git a/builtin/count-objects.c b/builtin/count-objects.c\nindex 33343818c8..9334648dcc 100644\n--- a/builtin/count-objects.c\n+++ b/builtin/count-objects.c\n@@ -7,6 +7,8 @@\n #include \"cache.h\"\n #include \"config.h\"\n #include \"dir.h\"\n+#include \"repository.h\"\n+#include \"object-store.h\"\n #include \"builtin.h\"\n #include \"parse-options.h\"\n #include \"quote.h\"\n@@ -120,9 +122,9 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)\n \t\tstruct strbuf loose_buf = STRBUF_INIT;\n \t\tstruct strbuf pack_buf = STRBUF_INIT;\n \t\tstruct strbuf garbage_buf = STRBUF_INIT;\n-\t\tif (!packed_git)\n+\t\tif (!the_repository->objects.packed_git)\n \t\t\tprepare_packed_git();\n-\t\tfor (p = packed_git; p; p = p->next) {\n+\t\tfor (p = the_repository->objects.packed_git; p; p = p->next) {\n \t\t\tif (!p->pack_local)\n \t\t\t\tcontinue;\n \t\t\tif (open_pack_index(p))\ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex 1048255da1..d4d249c2ed 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -2,6 +2,7 @@\n #include \"cache.h\"\n #include \"repository.h\"\n #include \"config.h\"\n+#include \"object-store.h\"\n #include \"commit.h\"\n #include \"tree.h\"\n #include \"blob.h\"\n@@ -707,7 +708,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)\n \t\t\tprepare_packed_git();\n \n \t\t\tif (show_progress) {\n-\t\t\t\tfor (p = packed_git; p; p = p->next) {\n+\t\t\t\tfor (p = the_repository->objects.packed_git; p;\n+\t\t\t\t     p = p->next) {\n \t\t\t\t\tif (open_pack_index(p))\n \t\t\t\t\t\tcontinue;\n \t\t\t\t\ttotal += p->num_objects;\n@@ -715,7 +717,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)\n \n \t\t\t\tprogress = start_progress(_(\"Checking objects\"), total);\n \t\t\t}\n-\t\t\tfor (p = packed_git; p; p = p->next) {\n+\t\t\tfor (p = the_repository->objects.packed_git; p;\n+\t\t\t     p = p->next) {\n \t\t\t\t/* verify gives error messages itself */\n \t\t\t\tif (verify_pack(p, fsck_obj_buffer,\n \t\t\t\t\t\tprogress, count))\ndiff --git a/builtin/gc.c b/builtin/gc.c\nindex 3c5eae0edf..6970f325e5 100644\n--- a/builtin/gc.c\n+++ b/builtin/gc.c\n@@ -11,6 +11,7 @@\n  */\n \n #include \"builtin.h\"\n+#include \"repository.h\"\n #include \"config.h\"\n #include \"tempfile.h\"\n #include \"lockfile.h\"\n@@ -18,6 +19,7 @@\n #include \"run-command.h\"\n #include \"sigchain.h\"\n #include \"argv-array.h\"\n+#include \"object-store.h\"\n #include \"commit.h\"\n #include \"packfile.h\"\n \n@@ -173,7 +175,7 @@ static int too_many_packs(void)\n \t\treturn 0;\n \n \tprepare_packed_git();\n-\tfor (cnt = 0, p = packed_git; p; p = p->next) {\n+\tfor (cnt = 0, p = the_repository->objects.packed_git; p; p = p->next) {\n \t\tif (!p->pack_local)\n \t\t\tcontinue;\n \t\tif (p->pack_keep)\ndiff --git a/builtin/index-pack.c b/builtin/index-pack.c\nindex 4c51aec81f..1902d4e096 100644\n--- a/builtin/index-pack.c\n+++ b/builtin/index-pack.c\n@@ -12,6 +12,7 @@\n #include \"exec_cmd.h\"\n #include \"streaming.h\"\n #include \"thread-utils.h\"\n+#include \"object-store.h\"\n #include \"packfile.h\"\n \n static const char index_pack_usage[] =\ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex 6b9cfc289d..2ee8b69238 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -1,6 +1,8 @@\n #include \"builtin.h\"\n #include \"cache.h\"\n+#include \"repository.h\"\n #include \"config.h\"\n+#include \"object-store.h\"\n #include \"attr.h\"\n #include \"object.h\"\n #include \"blob.h\"\n@@ -1023,7 +1025,8 @@ static int want_object_in_pack(const struct object_id *oid,\n \t\t\treturn want;\n \t}\n \n-\tfor (entry = packed_git_mru.head; entry; entry = entry->next) {\n+\tfor (entry = the_repository->objects.packed_git_mru.head; entry;\n+\t     entry = entry->next) {\n \t\tstruct packed_git *p = entry->item;\n \t\toff_t offset;\n \n@@ -1041,7 +1044,8 @@ static int want_object_in_pack(const struct object_id *oid,\n \t\t\t}\n \t\t\twant = want_found_object(exclude, p);\n \t\t\tif (!exclude && want > 0)\n-\t\t\t\tmru_mark(&packed_git_mru, entry);\n+\t\t\t\tmru_mark(&the_repository->objects.packed_git_mru,\n+\t\t\t\t\t entry);\n \t\t\tif (want != -1)\n \t\t\t\treturn want;\n \t\t}\n@@ -2648,7 +2652,7 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs)\n \n \tmemset(&in_pack, 0, sizeof(in_pack));\n \n-\tfor (p = packed_git; p; p = p->next) {\n+\tfor (p = the_repository->objects.packed_git; p; p = p->next) {\n \t\tstruct object_id oid;\n \t\tstruct object *o;\n \n@@ -2711,7 +2715,8 @@ static int has_sha1_pack_kept_or_nonlocal(const struct object_id *oid)\n \tstatic struct packed_git *last_found = (void *)1;\n \tstruct packed_git *p;\n \n-\tp = (last_found != (void *)1) ? last_found : packed_git;\n+\tp = (last_found != (void *)1) ? last_found :\n+\t\t\t\t\tthe_repository->objects.packed_git;\n \n \twhile (p) {\n \t\tif ((!p->pack_local || p->pack_keep) &&\n@@ -2720,7 +2725,7 @@ static int has_sha1_pack_kept_or_nonlocal(const struct object_id *oid)\n \t\t\treturn 1;\n \t\t}\n \t\tif (p == last_found)\n-\t\t\tp = packed_git;\n+\t\t\tp = the_repository->objects.packed_git;\n \t\telse\n \t\t\tp = p->next;\n \t\tif (p == last_found)\n@@ -2756,7 +2761,7 @@ static void loosen_unused_packed_objects(struct rev_info *revs)\n \tuint32_t i;\n \tstruct object_id oid;\n \n-\tfor (p = packed_git; p; p = p->next) {\n+\tfor (p = the_repository->objects.packed_git; p; p = p->next) {\n \t\tif (!p->pack_local || p->pack_keep)\n \t\t\tcontinue;\n \n@@ -3119,7 +3124,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)\n \tprepare_packed_git();\n \tif (ignore_packed_keep) {\n \t\tstruct packed_git *p;\n-\t\tfor (p = packed_git; p; p = p->next)\n+\t\tfor (p = the_repository->objects.packed_git; p; p = p->next)\n \t\t\tif (p->pack_local && p->pack_keep)\n \t\t\t\tbreak;\n \t\tif (!p) /* no keep-able packs found */\n@@ -3132,7 +3137,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)\n \t\t * also covers non-local objects\n \t\t */\n \t\tstruct packed_git *p;\n-\t\tfor (p = packed_git; p; p = p->next) {\n+\t\tfor (p = the_repository->objects.packed_git; p; p = p->next) {\n \t\t\tif (!p->pack_local) {\n \t\t\t\thave_non_local_packs = 1;\n \t\t\t\tbreak;\ndiff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c\nindex aaa8136322..55462bc826 100644\n--- a/builtin/pack-redundant.c\n+++ b/builtin/pack-redundant.c\n@@ -7,6 +7,8 @@\n */\n \n #include \"builtin.h\"\n+#include \"repository.h\"\n+#include \"object-store.h\"\n #include \"packfile.h\"\n \n #define BLKSIZE 512\n@@ -571,7 +573,7 @@ static struct pack_list * add_pack(struct packed_git *p)\n \n static struct pack_list * add_pack_file(const char *filename)\n {\n-\tstruct packed_git *p = packed_git;\n+\tstruct packed_git *p = the_repository->objects.packed_git;\n \n \tif (strlen(filename) < 40)\n \t\tdie(\"Bad pack filename: %s\", filename);\n@@ -586,7 +588,7 @@ static struct pack_list * add_pack_file(const char *filename)\n \n static void load_all(void)\n {\n-\tstruct packed_git *p = packed_git;\n+\tstruct packed_git *p = the_repository->objects.packed_git;\n \n \twhile (p) {\n \t\tadd_pack(p);\ndiff --git a/builtin/receive-pack.c b/builtin/receive-pack.c\nindex b7ce7c7f52..b2eac79a6e 100644\n--- a/builtin/receive-pack.c\n+++ b/builtin/receive-pack.c\n@@ -7,6 +7,7 @@\n #include \"sideband.h\"\n #include \"run-command.h\"\n #include \"exec_cmd.h\"\n+#include \"object-store.h\"\n #include \"commit.h\"\n #include \"object.h\"\n #include \"remote.h\"\ndiff --git a/cache.h b/cache.h\nindex 918c2f15b4..459fd01dbb 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1633,34 +1633,6 @@ struct pack_window {\n \tunsigned int inuse_cnt;\n };\n \n-extern struct packed_git {\n-\tstruct packed_git *next;\n-\tstruct pack_window *windows;\n-\toff_t pack_size;\n-\tconst void *index_data;\n-\tsize_t index_size;\n-\tuint32_t num_objects;\n-\tuint32_t num_bad_objects;\n-\tunsigned char *bad_object_sha1;\n-\tint index_version;\n-\ttime_t mtime;\n-\tint pack_fd;\n-\tunsigned pack_local:1,\n-\t\t pack_keep:1,\n-\t\t freshened:1,\n-\t\t do_not_close:1;\n-\tunsigned char sha1[20];\n-\tstruct revindex_entry *revindex;\n-\t/* something like \".git/objects/pack/xxxxx.pack\" */\n-\tchar pack_name[FLEX_ARRAY]; /* more */\n-} *packed_git;\n-\n-/*\n- * A most-recently-used ordered version of the packed_git list, which can\n- * be iterated instead of packed_git (and marked via mru_mark).\n- */\n-extern struct mru packed_git_mru;\n-\n struct pack_entry {\n \toff_t offset;\n \tunsigned char sha1[20];\ndiff --git a/contrib/coccinelle/packed_git.cocci b/contrib/coccinelle/packed_git.cocci\nnew file mode 100644\nindex 0000000000..da317a51a9\n--- /dev/null\n+++ b/contrib/coccinelle/packed_git.cocci\n@@ -0,0 +1,7 @@\n+@@ @@\n+- packed_git\n++ the_repository->objects.packed_git\n+\n+@@ @@\n+- packed_git_mru\n++ the_repository->objects.packed_git_mru\ndiff --git a/fast-import.c b/fast-import.c\nindex b70ac025e0..1685fe59a2 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -154,8 +154,10 @@ Format of STDIN stream:\n \n #include \"builtin.h\"\n #include \"cache.h\"\n+#include \"repository.h\"\n #include \"config.h\"\n #include \"lockfile.h\"\n+#include \"object-store.h\"\n #include \"object.h\"\n #include \"blob.h\"\n #include \"tree.h\"\n@@ -1110,7 +1112,7 @@ static int store_object(\n \tif (e->idx.offset) {\n \t\tduplicate_count_by_type[type]++;\n \t\treturn 1;\n-\t} else if (find_sha1_pack(oid.hash, packed_git)) {\n+\t} else if (find_sha1_pack(oid.hash, the_repository->objects.packed_git)) {\n \t\te->type = type;\n \t\te->pack_id = MAX_PACK_ID;\n \t\te->idx.offset = 1; /* just not zero! */\n@@ -1305,7 +1307,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)\n \t\tduplicate_count_by_type[OBJ_BLOB]++;\n \t\ttruncate_pack(&checkpoint);\n \n-\t} else if (find_sha1_pack(oid.hash, packed_git)) {\n+\t} else if (find_sha1_pack(oid.hash, the_repository->objects.packed_git)) {\n \t\te->type = OBJ_BLOB;\n \t\te->pack_id = MAX_PACK_ID;\n \t\te->idx.offset = 1; /* just not zero! */\ndiff --git a/http-backend.c b/http-backend.c\nindex f3dc218b2a..4d93126c15 100644\n--- a/http-backend.c\n+++ b/http-backend.c\n@@ -1,7 +1,9 @@\n #include \"cache.h\"\n #include \"config.h\"\n+#include \"repository.h\"\n #include \"refs.h\"\n #include \"pkt-line.h\"\n+#include \"object-store.h\"\n #include \"object.h\"\n #include \"tag.h\"\n #include \"exec_cmd.h\"\n@@ -518,13 +520,13 @@ static void get_info_packs(struct strbuf *hdr, char *arg)\n \n \tselect_getanyfile(hdr);\n \tprepare_packed_git();\n-\tfor (p = packed_git; p; p = p->next) {\n+\tfor (p = the_repository->objects.packed_git; p; p = p->next) {\n \t\tif (p->pack_local)\n \t\t\tcnt++;\n \t}\n \n \tstrbuf_grow(&buf, cnt * 53 + 2);\n-\tfor (p = packed_git; p; p = p->next) {\n+\tfor (p = the_repository->objects.packed_git; p; p = p->next) {\n \t\tif (p->pack_local)\n \t\t\tstrbuf_addf(&buf, \"P %s\\n\", p->pack_name + objdirlen + 6);\n \t}\ndiff --git a/http-push.c b/http-push.c\nindex 14435ab65d..34c5d030b7 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -1,4 +1,5 @@\n #include \"cache.h\"\n+#include \"object-store.h\"\n #include \"commit.h\"\n #include \"tag.h\"\n #include \"blob.h\"\ndiff --git a/http-walker.c b/http-walker.c\nindex 1ae8363de2..a1c6f2639b 100644\n--- a/http-walker.c\n+++ b/http-walker.c\n@@ -4,6 +4,7 @@\n #include \"http.h\"\n #include \"list.h\"\n #include \"transport.h\"\n+#include \"object-store.h\"\n #include \"packfile.h\"\n \n struct alt_base {\ndiff --git a/http.c b/http.c\nindex 5977712712..ab989b88dd 100644\n--- a/http.c\n+++ b/http.c\n@@ -1,6 +1,7 @@\n #include \"git-compat-util.h\"\n #include \"http.h\"\n #include \"config.h\"\n+#include \"object-store.h\"\n #include \"pack.h\"\n #include \"sideband.h\"\n #include \"run-command.h\"\ndiff --git a/mru.h b/mru.h\nindex 42e4aeaa10..d7de81efb9 100644\n--- a/mru.h\n+++ b/mru.h\n@@ -37,6 +37,7 @@ struct mru_entry {\n struct mru {\n \tstruct mru_entry *head, *tail;\n };\n+#define MRU_INIT { NULL, NULL }\n \n void mru_append(struct mru *mru, void *item);\n void mru_mark(struct mru *mru, struct mru_entry *entry);\ndiff --git a/object-store.h b/object-store.h\nindex ace3efbfab..e2a59a0611 100644\n--- a/object-store.h\n+++ b/object-store.h\n@@ -2,11 +2,42 @@\n #define OBJECT_STORE_H\n \n #include \"cache.h\"\n+#include \"mru.h\"\n \n struct object_store {\n+\tstruct packed_git *packed_git;\n+\n+\t/*\n+\t * A most-recently-used ordered version of the packed_git list, which can\n+\t * be iterated instead of packed_git (and marked via mru_mark).\n+\t */\n+\tstruct mru packed_git_mru;\n+\n \tstruct alternate_object_database *alt_odb_list;\n \tstruct alternate_object_database **alt_odb_tail;\n };\n-#define OBJECT_STORE_INIT { NULL, NULL }\n+#define OBJECT_STORE_INIT { NULL, MRU_INIT, NULL, NULL }\n+\n+struct packed_git {\n+\tstruct packed_git *next;\n+\tstruct pack_window *windows;\n+\toff_t pack_size;\n+\tconst void *index_data;\n+\tsize_t index_size;\n+\tuint32_t num_objects;\n+\tuint32_t num_bad_objects;\n+\tunsigned char *bad_object_sha1;\n+\tint index_version;\n+\ttime_t mtime;\n+\tint pack_fd;\n+\tunsigned pack_local:1,\n+\t\t pack_keep:1,\n+\t\t freshened:1,\n+\t\t do_not_close:1;\n+\tunsigned char sha1[20];\n+\tstruct revindex_entry *revindex;\n+\t/* something like \".git/objects/pack/xxxxx.pack\" */\n+\tchar pack_name[FLEX_ARRAY]; /* more */\n+};\n \n #endif /* OBJECT_STORE_H */\ndiff --git a/pack-bitmap.c b/pack-bitmap.c\nindex 9270983e5f..d51172b1d5 100644\n--- a/pack-bitmap.c\n+++ b/pack-bitmap.c\n@@ -5,11 +5,13 @@\n #include \"revision.h\"\n #include \"progress.h\"\n #include \"list-objects.h\"\n+#include \"object-store.h\"\n #include \"pack.h\"\n #include \"pack-bitmap.h\"\n #include \"pack-revindex.h\"\n #include \"pack-objects.h\"\n #include \"packfile.h\"\n+#include \"repository.h\"\n \n /*\n  * An entry on the bitmap index, representing the bitmap for a given\n@@ -335,7 +337,7 @@ static int open_pack_bitmap(void)\n \tassert(!bitmap_git.map && !bitmap_git.loaded);\n \n \tprepare_packed_git();\n-\tfor (p = packed_git; p; p = p->next) {\n+\tfor (p = the_repository->objects.packed_git; p; p = p->next) {\n \t\tif (open_pack_bitmap_1(p) == 0)\n \t\t\tret = 0;\n \t}\ndiff --git a/pack-check.c b/pack-check.c\nindex 073c1fbd46..c80c3ed8fd 100644\n--- a/pack-check.c\n+++ b/pack-check.c\n@@ -1,5 +1,6 @@\n #include \"cache.h\"\n #include \"pack.h\"\n+#include \"object-store.h\"\n #include \"pack-revindex.h\"\n #include \"progress.h\"\n #include \"packfile.h\"\ndiff --git a/pack-revindex.c b/pack-revindex.c\nindex 1b7ebd8d7e..82c3119652 100644\n--- a/pack-revindex.c\n+++ b/pack-revindex.c\n@@ -1,5 +1,6 @@\n #include \"cache.h\"\n #include \"pack-revindex.h\"\n+#include \"object-store.h\"\n \n /*\n  * Pack index for existing packs give us easy access to the offsets into\ndiff --git a/packfile.c b/packfile.c\nindex d61076faaf..11b0e6613c 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -7,6 +7,7 @@\n #include \"packfile.h\"\n #include \"delta.h\"\n #include \"list.h\"\n+#include \"object-store.h\"\n #include \"streaming.h\"\n #include \"sha1-lookup.h\"\n \n@@ -40,8 +41,6 @@ static unsigned int pack_open_fds;\n static unsigned int pack_max_fds;\n static size_t peak_pack_mapped;\n static size_t pack_mapped;\n-struct packed_git *packed_git;\n-struct mru packed_git_mru;\n \n #define SZ_FMT PRIuMAX\n static inline uintmax_t sz_fmt(size_t s) { return s; }\n@@ -241,7 +240,7 @@ static int unuse_one_window(struct packed_git *current)\n \n \tif (current)\n \t\tscan_windows(current, &lru_p, &lru_w, &lru_l);\n-\tfor (p = packed_git; p; p = p->next)\n+\tfor (p = the_repository->objects.packed_git; p; p = p->next)\n \t\tscan_windows(p, &lru_p, &lru_w, &lru_l);\n \tif (lru_p) {\n \t\tmunmap(lru_w->base, lru_w->len);\n@@ -311,7 +310,7 @@ void close_all_packs(void)\n {\n \tstruct packed_git *p;\n \n-\tfor (p = packed_git; p; p = p->next)\n+\tfor (p = the_repository->objects.packed_git; p; p = p->next)\n \t\tif (p->do_not_close)\n \t\t\tdie(\"BUG: want to close pack marked 'do-not-close'\");\n \t\telse\n@@ -379,7 +378,7 @@ static int close_one_pack(void)\n \tstruct pack_window *mru_w = NULL;\n \tint accept_windows_inuse = 1;\n \n-\tfor (p = packed_git; p; p = p->next) {\n+\tfor (p = the_repository->objects.packed_git; p; p = p->next) {\n \t\tif (p->pack_fd == -1)\n \t\t\tcontinue;\n \t\tfind_lru_pack(p, &lru_p, &mru_w, &accept_windows_inuse);\n@@ -677,8 +676,8 @@ void install_packed_git(struct packed_git *pack)\n \tif (pack->pack_fd != -1)\n \t\tpack_open_fds++;\n \n-\tpack->next = packed_git;\n-\tpacked_git = pack;\n+\tpack->next = the_repository->objects.packed_git;\n+\tthe_repository->objects.packed_git = pack;\n }\n \n void (*report_garbage)(unsigned seen_bits, const char *path);\n@@ -760,7 +759,8 @@ static void prepare_packed_git_one(char *objdir, int local)\n \t\tbase_len = path.len;\n \t\tif (strip_suffix_mem(path.buf, &base_len, \".idx\")) {\n \t\t\t/* Don't reopen a pack we already have. */\n-\t\t\tfor (p = packed_git; p; p = p->next) {\n+\t\t\tfor (p = the_repository->objects.packed_git; p;\n+\t\t\t     p = p->next) {\n \t\t\t\tsize_t len;\n \t\t\t\tif (strip_suffix(p->pack_name, \".pack\", &len) &&\n \t\t\t\t    len == base_len &&\n@@ -810,7 +810,7 @@ unsigned long approximate_object_count(void)\n \n \t\tprepare_packed_git();\n \t\tcount = 0;\n-\t\tfor (p = packed_git; p; p = p->next) {\n+\t\tfor (p = the_repository->objects.packed_git; p; p = p->next) {\n \t\t\tif (open_pack_index(p))\n \t\t\t\tcontinue;\n \t\t\tcount += p->num_objects;\n@@ -859,17 +859,18 @@ static int sort_pack(const void *a_, const void *b_)\n \n static void rearrange_packed_git(void)\n {\n-\tpacked_git = llist_mergesort(packed_git, get_next_packed_git,\n-\t\t\t\t     set_next_packed_git, sort_pack);\n+\tthe_repository->objects.packed_git = llist_mergesort(\n+\t\tthe_repository->objects.packed_git, get_next_packed_git,\n+\t\tset_next_packed_git, sort_pack);\n }\n \n static void prepare_packed_git_mru(void)\n {\n \tstruct packed_git *p;\n \n-\tmru_clear(&packed_git_mru);\n-\tfor (p = packed_git; p; p = p->next)\n-\t\tmru_append(&packed_git_mru, p);\n+\tmru_clear(&the_repository->objects.packed_git_mru);\n+\tfor (p = the_repository->objects.packed_git; p; p = p->next)\n+\t\tmru_append(&the_repository->objects.packed_git_mru, p);\n }\n \n static int prepare_packed_git_run_once = 0;\n@@ -1003,7 +1004,7 @@ const struct packed_git *has_packed_and_bad(const unsigned char *sha1)\n \tstruct packed_git *p;\n \tunsigned i;\n \n-\tfor (p = packed_git; p; p = p->next)\n+\tfor (p = the_repository->objects.packed_git; p; p = p->next)\n \t\tfor (i = 0; i < p->num_bad_objects; i++)\n \t\t\tif (!hashcmp(sha1, p->bad_object_sha1 + 20 * i))\n \t\t\t\treturn p;\n@@ -1835,12 +1836,12 @@ int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)\n \tstruct mru_entry *p;\n \n \tprepare_packed_git();\n-\tif (!packed_git)\n+\tif (!the_repository->objects.packed_git)\n \t\treturn 0;\n \n-\tfor (p = packed_git_mru.head; p; p = p->next) {\n+\tfor (p = the_repository->objects.packed_git_mru.head; p; p = p->next) {\n \t\tif (fill_pack_entry(sha1, e, p->item)) {\n-\t\t\tmru_mark(&packed_git_mru, p);\n+\t\t\tmru_mark(&the_repository->objects.packed_git_mru, p);\n \t\t\treturn 1;\n \t\t}\n \t}\n@@ -1887,7 +1888,7 @@ int for_each_packed_object(each_packed_object_fn cb, void *data, unsigned flags)\n \tint pack_errors = 0;\n \n \tprepare_packed_git();\n-\tfor (p = packed_git; p; p = p->next) {\n+\tfor (p = the_repository->objects.packed_git; p; p = p->next) {\n \t\tif ((flags & FOR_EACH_OBJECT_LOCAL_ONLY) && !p->pack_local)\n \t\t\tcontinue;\n \t\tif (open_pack_index(p)) {\ndiff --git a/reachable.c b/reachable.c\nindex 88d7d679da..59ed16ba76 100644\n--- a/reachable.c\n+++ b/reachable.c\n@@ -1,5 +1,6 @@\n #include \"cache.h\"\n #include \"refs.h\"\n+#include \"object-store.h\"\n #include \"tag.h\"\n #include \"commit.h\"\n #include \"blob.h\"\ndiff --git a/server-info.c b/server-info.c\nindex 26a6c20b7d..96885c45f6 100644\n--- a/server-info.c\n+++ b/server-info.c\n@@ -1,5 +1,7 @@\n #include \"cache.h\"\n+#include \"repository.h\"\n #include \"refs.h\"\n+#include \"object-store.h\"\n #include \"object.h\"\n #include \"commit.h\"\n #include \"tag.h\"\n@@ -200,7 +202,7 @@ static void init_pack_info(const char *infofile, int force)\n \tobjdirlen = strlen(objdir);\n \n \tprepare_packed_git();\n-\tfor (p = packed_git; p; p = p->next) {\n+\tfor (p = the_repository->objects.packed_git; p; p = p->next) {\n \t\t/* we ignore things on alternate path since they are\n \t\t * not available to the pullers in general.\n \t\t */\n@@ -210,7 +212,7 @@ static void init_pack_info(const char *infofile, int force)\n \t}\n \tnum_pack = i;\n \tinfo = xcalloc(num_pack, sizeof(struct pack_info *));\n-\tfor (i = 0, p = packed_git; p; p = p->next) {\n+\tfor (i = 0, p = the_repository->objects.packed_git; p; p = p->next) {\n \t\tif (!p->pack_local)\n \t\t\tcontinue;\n \t\tinfo[i] = xcalloc(1, sizeof(struct pack_info));\ndiff --git a/sha1_name.c b/sha1_name.c\nindex 957ce25680..016c883b5c 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -196,7 +196,8 @@ static void find_short_packed_object(struct disambiguate_state *ds)\n \tstruct packed_git *p;\n \n \tprepare_packed_git();\n-\tfor (p = packed_git; p && !ds->ambiguous; p = p->next)\n+\tfor (p = the_repository->objects.packed_git; p && !ds->ambiguous;\n+\t     p = p->next)\n \t\tunique_in_pack(p, ds);\n }\n \n@@ -566,7 +567,7 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad)\n \tstruct packed_git *p;\n \n \tprepare_packed_git();\n-\tfor (p = packed_git; p; p = p->next)\n+\tfor (p = the_repository->objects.packed_git; p; p = p->next)\n \t\tfind_abbrev_len_for_pack(p, mad);\n }\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338269","messageId":"20180205235508.216277-6-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235508.216277-1-sbeller@google.com","subject":"[PATCH 005/194] pack: move approximate object count to object store","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:51:59Z","receivedAt":"2018-02-05T23:55:53Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nThe approximate_object_count() function maintains a rough count of\nobjects in a repository to estimate how long object name abbreviates\nshould be.  Object names are scoped to a repository and the\nappropriate length may differ by repository, so the object count\nshould not be global.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n object-store.h | 10 +++++++++-\n packfile.c     | 11 +++++------\n 2 files changed, 14 insertions(+), 7 deletions(-)\n\ndiff --git a/object-store.h b/object-store.h\nindex 14129fbba1..99f77d10cd 100644\n--- a/object-store.h\n+++ b/object-store.h\n@@ -16,13 +16,21 @@ struct object_store {\n \tstruct alternate_object_database *alt_odb_list;\n \tstruct alternate_object_database **alt_odb_tail;\n \n+\t/*\n+\t * A fast, rough count of the number of objects in the repository.\n+\t * These two fields are not meant for direct access. Use\n+\t * approximate_object_count() instead.\n+\t */\n+\tunsigned long approximate_object_count;\n+\tunsigned approximate_object_count_valid : 1;\n+\n \t/*\n \t * Whether packed_git has already been populated with this repository's\n \t * packs.\n \t */\n \tunsigned packed_git_initialized : 1;\n };\n-#define OBJECT_STORE_INIT { NULL, MRU_INIT, NULL, NULL, 0 }\n+#define OBJECT_STORE_INIT { NULL, MRU_INIT, NULL, NULL, 0, 0, 0 }\n \n struct packed_git {\n \tstruct packed_git *next;\ndiff --git a/packfile.c b/packfile.c\nindex 177aa219f9..31c4ea54ae 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -793,8 +793,6 @@ static void prepare_packed_git_one(char *objdir, int local)\n \tstrbuf_release(&path);\n }\n \n-static int approximate_object_count_valid;\n-\n /*\n  * Give a fast, rough count of the number of objects in the repository. This\n  * ignores loose objects completely. If you have a lot of them, then either\n@@ -804,8 +802,8 @@ static int approximate_object_count_valid;\n  */\n unsigned long approximate_object_count(void)\n {\n-\tstatic unsigned long count;\n-\tif (!approximate_object_count_valid) {\n+\tif (!the_repository->objects.approximate_object_count_valid) {\n+\t\tunsigned long count;\n \t\tstruct packed_git *p;\n \n \t\tprepare_packed_git();\n@@ -815,8 +813,9 @@ unsigned long approximate_object_count(void)\n \t\t\t\tcontinue;\n \t\t\tcount += p->num_objects;\n \t\t}\n+\t\tthe_repository->objects.approximate_object_count = count;\n \t}\n-\treturn count;\n+\treturn the_repository->objects.approximate_object_count;\n }\n \n static void *get_next_packed_git(const void *p)\n@@ -890,7 +889,7 @@ void prepare_packed_git(void)\n \n void reprepare_packed_git(void)\n {\n-\tapproximate_object_count_valid = 0;\n+\tthe_repository->objects.approximate_object_count_valid = 0;\n \tthe_repository->objects.packed_git_initialized = 0;\n \tprepare_packed_git();\n }\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338270","messageId":"20180205235508.216277-5-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235508.216277-1-sbeller@google.com","subject":"[PATCH 004/194] pack: move prepare_packed_git_run_once to object store","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:51:58Z","receivedAt":"2018-02-05T23:55:54Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nEach repository's object store can be initialized independently, so\nthey must not share a run_once variable.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n object-store.h | 8 +++++++-\n packfile.c     | 7 +++----\n 2 files changed, 10 insertions(+), 5 deletions(-)\n\ndiff --git a/object-store.h b/object-store.h\nindex e2a59a0611..14129fbba1 100644\n--- a/object-store.h\n+++ b/object-store.h\n@@ -15,8 +15,14 @@ struct object_store {\n \n \tstruct alternate_object_database *alt_odb_list;\n \tstruct alternate_object_database **alt_odb_tail;\n+\n+\t/*\n+\t * Whether packed_git has already been populated with this repository's\n+\t * packs.\n+\t */\n+\tunsigned packed_git_initialized : 1;\n };\n-#define OBJECT_STORE_INIT { NULL, MRU_INIT, NULL, NULL }\n+#define OBJECT_STORE_INIT { NULL, MRU_INIT, NULL, NULL, 0 }\n \n struct packed_git {\n \tstruct packed_git *next;\ndiff --git a/packfile.c b/packfile.c\nindex 11b0e6613c..177aa219f9 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -873,12 +873,11 @@ static void prepare_packed_git_mru(void)\n \t\tmru_append(&the_repository->objects.packed_git_mru, p);\n }\n \n-static int prepare_packed_git_run_once = 0;\n void prepare_packed_git(void)\n {\n \tstruct alternate_object_database *alt;\n \n-\tif (prepare_packed_git_run_once)\n+\tif (the_repository->objects.packed_git_initialized)\n \t\treturn;\n \tprepare_packed_git_one(get_object_directory(), 1);\n \tprepare_alt_odb();\n@@ -886,13 +885,13 @@ void prepare_packed_git(void)\n \t\tprepare_packed_git_one(alt->path, 0);\n \trearrange_packed_git();\n \tprepare_packed_git_mru();\n-\tprepare_packed_git_run_once = 1;\n+\tthe_repository->objects.packed_git_initialized = 1;\n }\n \n void reprepare_packed_git(void)\n {\n \tapproximate_object_count_valid = 0;\n-\tprepare_packed_git_run_once = 0;\n+\tthe_repository->objects.packed_git_initialized = 0;\n \tprepare_packed_git();\n }\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338271","messageId":"20180205235508.216277-7-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235508.216277-1-sbeller@google.com","subject":"[PATCH 006/194] sha1_file: add repository argument to alt_odb_usable","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:52:00Z","receivedAt":"2018-02-05T23:55:56Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow the alt_odb_usable caller to be\nmore specific about which repository to act on. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nSince the implementation does not yet work with other repositories,\nuse a wrapper macro to enforce that the caller passes in\nthe_repository as the first argument. It would be more appealing to\nuse BUILD_ASSERT_OR_ZERO to enforce this, but that doesn't work\nbecause it requires a compile-time constant and common compilers like\ngcc 4.8.4 do not consider \"r == the_repository\" a compile-time\nconstant.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n sha1_file.c | 6 ++++--\n 1 file changed, 4 insertions(+), 2 deletions(-)\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 2826d5d6ed..ca002a272d 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -350,7 +350,9 @@ static const char *alt_sha1_path(struct alternate_object_database *alt,\n /*\n  * Return non-zero iff the path is usable as an alternate object database.\n  */\n-static int alt_odb_usable(struct strbuf *path, const char *normalized_objdir)\n+#define alt_odb_usable(r, p, n) alt_odb_usable_##r(p, n)\n+static int alt_odb_usable_the_repository(struct strbuf *path,\n+\t\t\t\t\t const char *normalized_objdir)\n {\n \tstruct alternate_object_database *alt;\n \n@@ -418,7 +420,7 @@ static int link_alt_odb_entry(const char *entry, const char *relative_base,\n \twhile (pathbuf.len && pathbuf.buf[pathbuf.len - 1] == '/')\n \t\tstrbuf_setlen(&pathbuf, pathbuf.len - 1);\n \n-\tif (!alt_odb_usable(&pathbuf, normalized_objdir)) {\n+\tif (!alt_odb_usable(the_repository, &pathbuf, normalized_objdir)) {\n \t\tstrbuf_release(&pathbuf);\n \t\treturn -1;\n \t}\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338272","messageId":"20180205235508.216277-8-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235508.216277-1-sbeller@google.com","subject":"[PATCH 007/194] sha1_file: add repository argument to link_alt_odb_entry","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:52:01Z","receivedAt":"2018-02-05T23:55:59Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow the link_alt_odb_entry caller to be\nmore specific about which repository to act on. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commit, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n sha1_file.c | 8 +++++---\n 1 file changed, 5 insertions(+), 3 deletions(-)\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex ca002a272d..1e17246f5c 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -394,8 +394,9 @@ static int alt_odb_usable_the_repository(struct strbuf *path,\n  * terminating NUL.\n  */\n static void read_info_alternates(const char * relative_base, int depth);\n-static int link_alt_odb_entry(const char *entry, const char *relative_base,\n-\tint depth, const char *normalized_objdir)\n+#define link_alt_odb_entry(r, e, rb, d, n) link_alt_odb_entry_##r(e, rb, d, n)\n+static int link_alt_odb_entry_the_repository(const char *entry,\n+\tconst char *relative_base, int depth, const char *normalized_objdir)\n {\n \tstruct alternate_object_database *ent;\n \tstruct strbuf pathbuf = STRBUF_INIT;\n@@ -492,7 +493,8 @@ static void link_alt_odb_entries(const char *alt, int sep,\n \t\talt = parse_alt_odb_entry(alt, sep, &entry);\n \t\tif (!entry.len)\n \t\t\tcontinue;\n-\t\tlink_alt_odb_entry(entry.buf, relative_base, depth, objdirbuf.buf);\n+\t\tlink_alt_odb_entry(the_repository, entry.buf,\n+\t\t\t\t   relative_base, depth, objdirbuf.buf);\n \t}\n \tstrbuf_release(&entry);\n \tstrbuf_release(&objdirbuf);\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338273","messageId":"20180205235508.216277-9-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235508.216277-1-sbeller@google.com","subject":"[PATCH 008/194] sha1_file: add repository argument to read_info_alternates","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:52:02Z","receivedAt":"2018-02-05T23:56:03Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow the read_info_alternates caller to\nbe more specific about which repository to read from. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commit, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n sha1_file.c | 11 +++++++----\n 1 file changed, 7 insertions(+), 4 deletions(-)\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 1e17246f5c..acb00b9680 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -393,7 +393,9 @@ static int alt_odb_usable_the_repository(struct strbuf *path,\n  * SHA1, an extra slash for the first level indirection, and the\n  * terminating NUL.\n  */\n-static void read_info_alternates(const char * relative_base, int depth);\n+#define read_info_alternates(r, rb, d) read_info_alternates_##r(rb, d)\n+static void read_info_alternates_the_repository(const char *relative_base,\n+\t\t\t\t\t\tint depth);\n #define link_alt_odb_entry(r, e, rb, d, n) link_alt_odb_entry_##r(e, rb, d, n)\n static int link_alt_odb_entry_the_repository(const char *entry,\n \tconst char *relative_base, int depth, const char *normalized_objdir)\n@@ -434,7 +436,7 @@ static int link_alt_odb_entry_the_repository(const char *entry,\n \tent->next = NULL;\n \n \t/* recursively add alternates */\n-\tread_info_alternates(pathbuf.buf, depth + 1);\n+\tread_info_alternates(the_repository, pathbuf.buf, depth + 1);\n \n \tstrbuf_release(&pathbuf);\n \treturn 0;\n@@ -500,7 +502,8 @@ static void link_alt_odb_entries(const char *alt, int sep,\n \tstrbuf_release(&objdirbuf);\n }\n \n-static void read_info_alternates(const char * relative_base, int depth)\n+static void read_info_alternates_the_repository(const char *relative_base,\n+\t\t\t\t\t\tint depth)\n {\n \tchar *path;\n \tstruct strbuf buf = STRBUF_INIT;\n@@ -684,7 +687,7 @@ void prepare_alt_odb(void)\n \t\t\t&the_repository->objects.alt_odb_list;\n \tlink_alt_odb_entries(alt, PATH_SEP, NULL, 0);\n \n-\tread_info_alternates(get_object_directory(), 0);\n+\tread_info_alternates(the_repository, get_object_directory(), 0);\n }\n \n /* Returns 1 if we have successfully freshened the file, 0 otherwise. */\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338274","messageId":"20180205235508.216277-10-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235508.216277-1-sbeller@google.com","subject":"[PATCH 009/194] sha1_file: add repository argument to link_alt_odb_entries","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:52:03Z","receivedAt":"2018-02-05T23:56:04Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow the link_alt_odb_entries caller to\nbe more specific about which repository to act on. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n sha1_file.c | 19 +++++++++++++------\n 1 file changed, 13 insertions(+), 6 deletions(-)\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex acb00b9680..d9f9046f31 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -471,8 +471,12 @@ static const char *parse_alt_odb_entry(const char *string,\n \treturn end;\n }\n \n-static void link_alt_odb_entries(const char *alt, int sep,\n-\t\t\t\t const char *relative_base, int depth)\n+#define link_alt_odb_entries(r, a, s, rb, d) \\\n+\tlink_alt_odb_entries_##r(a, s, rb, d)\n+static void link_alt_odb_entries_the_repository(const char *alt,\n+\t\t\t\t\t\tint sep,\n+\t\t\t\t\t\tconst char *relative_base,\n+\t\t\t\t\t\tint depth)\n {\n \tstruct strbuf objdirbuf = STRBUF_INIT;\n \tstruct strbuf entry = STRBUF_INIT;\n@@ -515,7 +519,7 @@ static void read_info_alternates_the_repository(const char *relative_base,\n \t\treturn;\n \t}\n \n-\tlink_alt_odb_entries(buf.buf, '\\n', relative_base, depth);\n+\tlink_alt_odb_entries(the_repository, buf.buf, '\\n', relative_base, depth);\n \tstrbuf_release(&buf);\n \tfree(path);\n }\n@@ -569,7 +573,8 @@ void add_to_alternates_file(const char *reference)\n \t\tif (commit_lock_file(&lock))\n \t\t\tdie_errno(\"unable to move new alternates file into place\");\n \t\tif (the_repository->objects.alt_odb_tail)\n-\t\t\tlink_alt_odb_entries(reference, '\\n', NULL, 0);\n+\t\t\tlink_alt_odb_entries(the_repository, reference,\n+\t\t\t\t\t     '\\n', NULL, 0);\n \t}\n \tfree(alts);\n }\n@@ -582,7 +587,8 @@ void add_to_alternates_memory(const char *reference)\n \t */\n \tprepare_alt_odb();\n \n-\tlink_alt_odb_entries(reference, '\\n', NULL, 0);\n+\tlink_alt_odb_entries(the_repository, reference,\n+\t\t\t     '\\n', NULL, 0);\n }\n \n /*\n@@ -685,7 +691,8 @@ void prepare_alt_odb(void)\n \n \tthe_repository->objects.alt_odb_tail =\n \t\t\t&the_repository->objects.alt_odb_list;\n-\tlink_alt_odb_entries(alt, PATH_SEP, NULL, 0);\n+\tlink_alt_odb_entries(the_repository, alt,\n+\t\t\t     PATH_SEP, NULL, 0);\n \n \tread_info_alternates(the_repository, get_object_directory(), 0);\n }\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338275","messageId":"20180205235508.216277-11-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235508.216277-1-sbeller@google.com","subject":"[PATCH 010/194] sha1_file: add repository argument to stat_sha1_file","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:52:04Z","receivedAt":"2018-02-05T23:56:08Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow the stat_sha1_file caller to be\nmore specific about which repository to act on. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n sha1_file.c | 9 +++++----\n 1 file changed, 5 insertions(+), 4 deletions(-)\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex d9f9046f31..6abdb8c488 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -875,8 +875,9 @@ int git_open_cloexec(const char *name, int flags)\n  * Note that it may point to static storage and is only valid until another\n  * call to sha1_file_name(), etc.\n  */\n-static int stat_sha1_file(const unsigned char *sha1, struct stat *st,\n-\t\t\t  const char **path)\n+#define stat_sha1_file(r, s, st, p) stat_sha1_file_##r(s, st, p)\n+static int stat_sha1_file_the_repository(const unsigned char *sha1,\n+\t\t\t\t\t struct stat *st, const char **path)\n {\n \tstruct alternate_object_database *alt;\n \n@@ -1174,7 +1175,7 @@ static int sha1_loose_object_info(const unsigned char *sha1,\n \tif (!oi->typep && !oi->typename && !oi->sizep && !oi->contentp) {\n \t\tconst char *path;\n \t\tstruct stat st;\n-\t\tif (stat_sha1_file(sha1, &st, &path) < 0)\n+\t\tif (stat_sha1_file(the_repository, sha1, &st, &path) < 0)\n \t\t\treturn -1;\n \t\tif (oi->disk_sizep)\n \t\t\t*oi->disk_sizep = st.st_size;\n@@ -1373,7 +1374,7 @@ void *read_sha1_file_extended(const unsigned char *sha1,\n \t\tdie(\"replacement %s not found for %s\",\n \t\t    sha1_to_hex(repl), sha1_to_hex(sha1));\n \n-\tif (!stat_sha1_file(repl, &st, &path))\n+\tif (!stat_sha1_file(the_repository, repl, &st, &path))\n \t\tdie(\"loose object %s (stored in %s) is corrupt\",\n \t\t    sha1_to_hex(repl), path);\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338276","messageId":"20180205235508.216277-13-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235508.216277-1-sbeller@google.com","subject":"[PATCH 012/194] sha1_file: add repository argument to map_sha1_file_1","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:52:06Z","receivedAt":"2018-02-05T23:56:11Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow the map_sha1_file_1 caller to be\nmore specific about which repository to act on. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n sha1_file.c | 11 ++++++-----\n 1 file changed, 6 insertions(+), 5 deletions(-)\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 9fa7243907..24832c4b32 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -931,9 +931,10 @@ static int open_sha1_file_the_repository(const unsigned char *sha1,\n  * Map the loose object at \"path\" if it is not NULL, or the path found by\n  * searching for a loose object named \"sha1\".\n  */\n-static void *map_sha1_file_1(const char *path,\n-\t\t\t     const unsigned char *sha1,\n-\t\t\t     unsigned long *size)\n+#define map_sha1_file_1(r, p, s, si) map_sha1_file_1_##r(p, s, si)\n+static void *map_sha1_file_1_the_repository(const char *path,\n+\t\t\t\t\t    const unsigned char *sha1,\n+\t\t\t\t\t    unsigned long *size)\n {\n \tvoid *map;\n \tint fd;\n@@ -962,7 +963,7 @@ static void *map_sha1_file_1(const char *path,\n \n void *map_sha1_file(const unsigned char *sha1, unsigned long *size)\n {\n-\treturn map_sha1_file_1(NULL, sha1, size);\n+\treturn map_sha1_file_1(the_repository, NULL, sha1, size);\n }\n \n static int unpack_sha1_short_header(git_zstream *stream,\n@@ -2174,7 +2175,7 @@ int read_loose_object(const char *path,\n \n \t*contents = NULL;\n \n-\tmap = map_sha1_file_1(path, NULL, &mapsize);\n+\tmap = map_sha1_file_1(the_repository, path, NULL, &mapsize);\n \tif (!map) {\n \t\terror_errno(\"unable to mmap %s\", path);\n \t\tgoto out;\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338277","messageId":"20180205235508.216277-14-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235508.216277-1-sbeller@google.com","subject":"[PATCH 013/194] sha1_file: add repository argument to sha1_loose_object_info","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:52:07Z","receivedAt":"2018-02-05T23:56:14Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow the sha1_loose_object_info caller\nto be more specific about which repository to act on. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n sha1_file.c | 9 +++++----\n 1 file changed, 5 insertions(+), 4 deletions(-)\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 24832c4b32..514f59c390 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -1152,9 +1152,10 @@ int parse_sha1_header(const char *hdr, unsigned long *sizep)\n \treturn parse_sha1_header_extended(hdr, &oi, 0);\n }\n \n-static int sha1_loose_object_info(const unsigned char *sha1,\n-\t\t\t\t  struct object_info *oi,\n-\t\t\t\t  int flags)\n+#define sha1_loose_object_info(r, s, o, f) sha1_loose_object_info_##r(s, o, f)\n+static int sha1_loose_object_info_the_repository(const unsigned char *sha1,\n+\t\t\t\t\t\t struct object_info *oi,\n+\t\t\t\t\t\t int flags)\n {\n \tint status = 0;\n \tunsigned long mapsize;\n@@ -1267,7 +1268,7 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,\n \n \tif (!find_pack_entry(real, &e)) {\n \t\t/* Most likely it's a loose object. */\n-\t\tif (!sha1_loose_object_info(real, oi, flags))\n+\t\tif (!sha1_loose_object_info(the_repository, real, oi, flags))\n \t\t\treturn 0;\n \n \t\t/* Not a loose object; someone else may have just packed it. */\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338278","messageId":"20180205235508.216277-12-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235508.216277-1-sbeller@google.com","subject":"[PATCH 011/194] sha1_file: add repository argument to open_sha1_file","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:52:05Z","receivedAt":"2018-02-05T23:56:16Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow the open_sha1_file caller to be\nmore specific about which repository to act on. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n sha1_file.c | 6 ++++--\n 1 file changed, 4 insertions(+), 2 deletions(-)\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 6abdb8c488..9fa7243907 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -900,7 +900,9 @@ static int stat_sha1_file_the_repository(const unsigned char *sha1,\n  * Like stat_sha1_file(), but actually open the object and return the\n  * descriptor. See the caveats on the \"path\" parameter above.\n  */\n-static int open_sha1_file(const unsigned char *sha1, const char **path)\n+#define open_sha1_file(r, s, p) open_sha1_file_##r(s, p)\n+static int open_sha1_file_the_repository(const unsigned char *sha1,\n+\t\t\t\t\t const char **path)\n {\n \tint fd;\n \tstruct alternate_object_database *alt;\n@@ -939,7 +941,7 @@ static void *map_sha1_file_1(const char *path,\n \tif (path)\n \t\tfd = git_open(path);\n \telse\n-\t\tfd = open_sha1_file(sha1, &path);\n+\t\tfd = open_sha1_file(the_repository, sha1, &path);\n \tmap = NULL;\n \tif (fd >= 0) {\n \t\tstruct stat st;\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338279","messageId":"20180205235508.216277-15-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235508.216277-1-sbeller@google.com","subject":"[PATCH 014/194] object-store: add repository argument to prepare_alt_odb","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:52:08Z","receivedAt":"2018-02-05T23:56:19Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow prepare_alt_odb callers to be more\nspecific about which repository to handle. This is a small mechanical\nchange; it doesn't change the implementation to handle repositories\nother than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nWhile at it, move the declaration to object-store.h, where it should\nbe easier to find.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n builtin/fsck.c |  2 +-\n cache.h        |  1 -\n object-store.h |  3 +++\n packfile.c     |  2 +-\n sha1_file.c    | 13 +++++++------\n sha1_name.c    |  3 ++-\n 6 files changed, 14 insertions(+), 10 deletions(-)\n\ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex d4d249c2ed..00ec8eecf0 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -695,7 +695,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)\n \t} else {\n \t\tfsck_object_dir(get_object_directory());\n \n-\t\tprepare_alt_odb();\n+\t\tprepare_alt_odb(the_repository);\n \t\tfor (alt = the_repository->objects.alt_odb_list;\n \t\t\t\talt; alt = alt->next)\n \t\t\tfsck_object_dir(alt->path);\ndiff --git a/cache.h b/cache.h\nindex 459fd01dbb..70518e24ce 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1592,7 +1592,6 @@ struct alternate_object_database {\n \n \tchar path[FLEX_ARRAY];\n };\n-extern void prepare_alt_odb(void);\n extern char *compute_alternate_path(const char *path, struct strbuf *err);\n typedef int alt_odb_fn(struct alternate_object_database *, void *);\n extern int foreach_alt_odb(alt_odb_fn, void*);\ndiff --git a/object-store.h b/object-store.h\nindex 99f77d10cd..e749c952d5 100644\n--- a/object-store.h\n+++ b/object-store.h\n@@ -54,4 +54,7 @@ struct packed_git {\n \tchar pack_name[FLEX_ARRAY]; /* more */\n };\n \n+#define prepare_alt_odb(r) prepare_alt_odb_##r()\n+extern void prepare_alt_odb_the_repository(void);\n+\n #endif /* OBJECT_STORE_H */\ndiff --git a/packfile.c b/packfile.c\nindex 31c4ea54ae..fbb2385bad 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -879,7 +879,7 @@ void prepare_packed_git(void)\n \tif (the_repository->objects.packed_git_initialized)\n \t\treturn;\n \tprepare_packed_git_one(get_object_directory(), 1);\n-\tprepare_alt_odb();\n+\tprepare_alt_odb(the_repository);\n \tfor (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next)\n \t\tprepare_packed_git_one(alt->path, 0);\n \trearrange_packed_git();\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 514f59c390..779bfd4079 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -23,6 +23,7 @@\n #include \"sha1-lookup.h\"\n #include \"bulk-checkin.h\"\n #include \"repository.h\"\n+#include \"object-store.h\"\n #include \"streaming.h\"\n #include \"dir.h\"\n #include \"mru.h\"\n@@ -585,7 +586,7 @@ void add_to_alternates_memory(const char *reference)\n \t * Make sure alternates are initialized, or else our entry may be\n \t * overwritten when they are.\n \t */\n-\tprepare_alt_odb();\n+\tprepare_alt_odb(the_repository);\n \n \tlink_alt_odb_entries(the_repository, reference,\n \t\t\t     '\\n', NULL, 0);\n@@ -671,7 +672,7 @@ int foreach_alt_odb(alt_odb_fn fn, void *cb)\n \tstruct alternate_object_database *ent;\n \tint r = 0;\n \n-\tprepare_alt_odb();\n+\tprepare_alt_odb(the_repository);\n \tfor (ent = the_repository->objects.alt_odb_list; ent; ent = ent->next) {\n \t\tr = fn(ent, cb);\n \t\tif (r)\n@@ -680,7 +681,7 @@ int foreach_alt_odb(alt_odb_fn fn, void *cb)\n \treturn r;\n }\n \n-void prepare_alt_odb(void)\n+void prepare_alt_odb_the_repository(void)\n {\n \tconst char *alt;\n \n@@ -729,7 +730,7 @@ static int check_and_freshen_local(const unsigned char *sha1, int freshen)\n static int check_and_freshen_nonlocal(const unsigned char *sha1, int freshen)\n {\n \tstruct alternate_object_database *alt;\n-\tprepare_alt_odb();\n+\tprepare_alt_odb(the_repository);\n \tfor (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next) {\n \t\tconst char *path = alt_sha1_path(alt, sha1);\n \t\tif (check_and_freshen_file(path, freshen))\n@@ -885,7 +886,7 @@ static int stat_sha1_file_the_repository(const unsigned char *sha1,\n \tif (!lstat(*path, st))\n \t\treturn 0;\n \n-\tprepare_alt_odb();\n+\tprepare_alt_odb(the_repository);\n \terrno = ENOENT;\n \tfor (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next) {\n \t\t*path = alt_sha1_path(alt, sha1);\n@@ -914,7 +915,7 @@ static int open_sha1_file_the_repository(const unsigned char *sha1,\n \t\treturn fd;\n \tmost_interesting_errno = errno;\n \n-\tprepare_alt_odb();\n+\tprepare_alt_odb(the_repository);\n \tfor (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next) {\n \t\t*path = alt_sha1_path(alt, sha1);\n \t\tfd = git_open(*path);\ndiff --git a/sha1_name.c b/sha1_name.c\nindex 016c883b5c..3e490ee8f6 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -11,6 +11,7 @@\n #include \"sha1-array.h\"\n #include \"packfile.h\"\n #include \"repository.h\"\n+#include \"object-store.h\"\n \n static int get_oid_oneline(const char *, struct object_id *, struct commit_list *);\n \n@@ -353,7 +354,7 @@ static int init_object_disambiguation(const char *name, int len,\n \n \tds->len = len;\n \tds->hex_pfx[len] = '\\0';\n-\tprepare_alt_odb();\n+\tprepare_alt_odb(the_repository);\n \treturn 0;\n }\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338280","messageId":"20180205235508.216277-16-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235508.216277-1-sbeller@google.com","subject":"[PATCH 015/194] object-store: add repository argument to foreach_alt_odb","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:52:09Z","receivedAt":"2018-02-05T23:56:22Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow foreach_alt_odb callers to be more\nspecific about which repository to handle. This is a small mechanical\nchange; it doesn't change the implementation to handle repositories\nother than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nWhile at it, move the declaration to object-store.h, where it should\nbe easier to find.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n builtin/count-objects.c     | 2 +-\n builtin/submodule--helper.c | 4 +++-\n cache.h                     | 2 --\n object-store.h              | 4 ++++\n sha1_file.c                 | 4 ++--\n transport.c                 | 4 +++-\n 6 files changed, 13 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin/count-objects.c b/builtin/count-objects.c\nindex 9334648dcc..843a7d7d7e 100644\n--- a/builtin/count-objects.c\n+++ b/builtin/count-objects.c\n@@ -155,7 +155,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)\n \t\tprintf(\"prune-packable: %lu\\n\", packed_loose);\n \t\tprintf(\"garbage: %lu\\n\", garbage);\n \t\tprintf(\"size-garbage: %s\\n\", garbage_buf.buf);\n-\t\tforeach_alt_odb(print_alternate, NULL);\n+\t\tforeach_alt_odb(the_repository, print_alternate, NULL);\n \t\tstrbuf_release(&loose_buf);\n \t\tstrbuf_release(&pack_buf);\n \t\tstrbuf_release(&garbage_buf);\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex a5c4a8a694..8005adbf3d 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -6,6 +6,7 @@\n #include \"quote.h\"\n #include \"pathspec.h\"\n #include \"dir.h\"\n+#include \"object-store.h\"\n #include \"submodule.h\"\n #include \"submodule-config.h\"\n #include \"string-list.h\"\n@@ -835,7 +836,8 @@ static void prepare_possible_alternates(const char *sm_name,\n \t\tdie(_(\"Value '%s' for submodule.alternateErrorStrategy is not recognized\"), error_strategy);\n \n \tif (!strcmp(sm_alternate, \"superproject\"))\n-\t\tforeach_alt_odb(add_possible_reference_from_superproject, &sas);\n+\t\tforeach_alt_odb(the_repository,\n+\t\t\t\tadd_possible_reference_from_superproject, &sas);\n \telse if (!strcmp(sm_alternate, \"no\"))\n \t\t; /* do nothing */\n \telse\ndiff --git a/cache.h b/cache.h\nindex 70518e24ce..bba53f356d 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1593,8 +1593,6 @@ struct alternate_object_database {\n \tchar path[FLEX_ARRAY];\n };\n extern char *compute_alternate_path(const char *path, struct strbuf *err);\n-typedef int alt_odb_fn(struct alternate_object_database *, void *);\n-extern int foreach_alt_odb(alt_odb_fn, void*);\n \n /*\n  * Allocate a \"struct alternate_object_database\" but do _not_ actually\ndiff --git a/object-store.h b/object-store.h\nindex e749c952d5..eef8d3b653 100644\n--- a/object-store.h\n+++ b/object-store.h\n@@ -57,4 +57,8 @@ struct packed_git {\n #define prepare_alt_odb(r) prepare_alt_odb_##r()\n extern void prepare_alt_odb_the_repository(void);\n \n+typedef int alt_odb_fn(struct alternate_object_database *, void *);\n+#define foreach_alt_odb(r, fn, cb) foreach_alt_odb_##r(fn, cb)\n+extern int foreach_alt_odb_the_repository(alt_odb_fn, void*);\n+\n #endif /* OBJECT_STORE_H */\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 779bfd4079..7662692ee5 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -667,7 +667,7 @@ char *compute_alternate_path(const char *path, struct strbuf *err)\n \treturn ref_git;\n }\n \n-int foreach_alt_odb(alt_odb_fn fn, void *cb)\n+int foreach_alt_odb_the_repository(alt_odb_fn fn, void *cb)\n {\n \tstruct alternate_object_database *ent;\n \tint r = 0;\n@@ -2103,7 +2103,7 @@ int for_each_loose_object(each_loose_object_fn cb, void *data, unsigned flags)\n \n \talt.cb = cb;\n \talt.data = data;\n-\treturn foreach_alt_odb(loose_from_alt_odb, &alt);\n+\treturn foreach_alt_odb(the_repository, loose_from_alt_odb, &alt);\n }\n \n static int check_stream_sha1(git_zstream *stream,\ndiff --git a/transport.c b/transport.c\nindex fc802260f6..3f97fbe7c5 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -1,6 +1,7 @@\n #include \"cache.h\"\n #include \"config.h\"\n #include \"transport.h\"\n+#include \"repository.h\"\n #include \"run-command.h\"\n #include \"pkt-line.h\"\n #include \"fetch-pack.h\"\n@@ -11,6 +12,7 @@\n #include \"bundle.h\"\n #include \"dir.h\"\n #include \"refs.h\"\n+#include \"object-store.h\"\n #include \"branch.h\"\n #include \"url.h\"\n #include \"submodule.h\"\n@@ -1294,5 +1296,5 @@ void for_each_alternate_ref(alternate_ref_fn fn, void *data)\n \tstruct alternate_refs_data cb;\n \tcb.fn = fn;\n \tcb.data = data;\n-\tforeach_alt_odb(refs_from_alternate_cb, &cb);\n+\tforeach_alt_odb(the_repository, refs_from_alternate_cb, &cb);\n }\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338281","messageId":"20180205235508.216277-17-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235508.216277-1-sbeller@google.com","subject":"[PATCH 016/194] pack: add repository argument to install_packed_git","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:52:10Z","receivedAt":"2018-02-05T23:56:25Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nAdd a repository argument to allow install_packed_git callers to be\nmore specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n fast-import.c | 2 +-\n http.c        | 3 ++-\n packfile.c    | 4 ++--\n packfile.h    | 3 ++-\n 4 files changed, 7 insertions(+), 5 deletions(-)\n\ndiff --git a/fast-import.c b/fast-import.c\nindex 1685fe59a2..67550584da 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -1038,7 +1038,7 @@ static void end_packfile(void)\n \t\tif (!new_p)\n \t\t\tdie(\"core git rejected index %s\", idx_name);\n \t\tall_packs[pack_id] = new_p;\n-\t\tinstall_packed_git(new_p);\n+\t\tinstall_packed_git(the_repository, new_p);\n \t\tfree(idx_name);\n \n \t\t/* Print the boundary */\ndiff --git a/http.c b/http.c\nindex ab989b88dd..979d9b3e46 100644\n--- a/http.c\n+++ b/http.c\n@@ -1,5 +1,6 @@\n #include \"git-compat-util.h\"\n #include \"http.h\"\n+#include \"repository.h\"\n #include \"config.h\"\n #include \"object-store.h\"\n #include \"pack.h\"\n@@ -2068,7 +2069,7 @@ int finish_http_pack_request(struct http_pack_request *preq)\n \t\treturn -1;\n \t}\n \n-\tinstall_packed_git(p);\n+\tinstall_packed_git(the_repository, p);\n \tfree(tmp_idx);\n \treturn 0;\n }\ndiff --git a/packfile.c b/packfile.c\nindex fbb2385bad..0f63ec79c8 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -671,7 +671,7 @@ struct packed_git *add_packed_git(const char *path, size_t path_len, int local)\n \treturn p;\n }\n \n-void install_packed_git(struct packed_git *pack)\n+void install_packed_git_the_repository(struct packed_git *pack)\n {\n \tif (pack->pack_fd != -1)\n \t\tpack_open_fds++;\n@@ -773,7 +773,7 @@ static void prepare_packed_git_one(char *objdir, int local)\n \t\t\t     * corresponding .pack file that we can map.\n \t\t\t     */\n \t\t\t    (p = add_packed_git(path.buf, path.len, local)) != NULL)\n-\t\t\t\tinstall_packed_git(p);\n+\t\t\t\tinstall_packed_git(the_repository, p);\n \t\t}\n \n \t\tif (!report_garbage)\ndiff --git a/packfile.h b/packfile.h\nindex 0cdeb54dcd..7e6959d440 100644\n--- a/packfile.h\n+++ b/packfile.h\n@@ -34,7 +34,8 @@ extern void (*report_garbage)(unsigned seen_bits, const char *path);\n \n extern void prepare_packed_git(void);\n extern void reprepare_packed_git(void);\n-extern void install_packed_git(struct packed_git *pack);\n+#define install_packed_git(r, p) install_packed_git_##r(p)\n+extern void install_packed_git_the_repository(struct packed_git *pack);\n \n /*\n  * Give a rough count of objects in the repository. This sacrifices accuracy\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338282","messageId":"20180205235508.216277-19-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235508.216277-1-sbeller@google.com","subject":"[PATCH 018/194] pack: add repository argument to rearrange_packed_git","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:52:12Z","receivedAt":"2018-02-05T23:56:28Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nAdd a repository argument to allow the rearrange_packed_git caller to\nbe more specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n packfile.c | 5 +++--\n 1 file changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/packfile.c b/packfile.c\nindex 58473660cd..52cf9182c4 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -857,7 +857,8 @@ static int sort_pack(const void *a_, const void *b_)\n \treturn -1;\n }\n \n-static void rearrange_packed_git(void)\n+#define rearrange_packed_git(r) rearrange_packed_git_##r()\n+static void rearrange_packed_git_the_repository(void)\n {\n \tthe_repository->objects.packed_git = llist_mergesort(\n \t\tthe_repository->objects.packed_git, get_next_packed_git,\n@@ -883,7 +884,7 @@ void prepare_packed_git(void)\n \tprepare_alt_odb(the_repository);\n \tfor (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next)\n \t\tprepare_packed_git_one(the_repository, alt->path, 0);\n-\trearrange_packed_git();\n+\trearrange_packed_git(the_repository);\n \tprepare_packed_git_mru();\n \tthe_repository->objects.packed_git_initialized = 1;\n }\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338283","messageId":"20180205235508.216277-18-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235508.216277-1-sbeller@google.com","subject":"[PATCH 017/194] pack: add repository argument to prepare_packed_git_one","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:52:11Z","receivedAt":"2018-02-05T23:56:31Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nAdd a repository argument to allow the prepare_packed_git_one caller\nto be more specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n packfile.c | 7 ++++---\n 1 file changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/packfile.c b/packfile.c\nindex 0f63ec79c8..58473660cd 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -726,7 +726,8 @@ static void report_pack_garbage(struct string_list *list)\n \treport_helper(list, seen_bits, first, list->nr);\n }\n \n-static void prepare_packed_git_one(char *objdir, int local)\n+#define prepare_packed_git_one(r, o, l) prepare_packed_git_one_##r(o, l)\n+static void prepare_packed_git_one_the_repository(char *objdir, int local)\n {\n \tstruct strbuf path = STRBUF_INIT;\n \tsize_t dirnamelen;\n@@ -878,10 +879,10 @@ void prepare_packed_git(void)\n \n \tif (the_repository->objects.packed_git_initialized)\n \t\treturn;\n-\tprepare_packed_git_one(get_object_directory(), 1);\n+\tprepare_packed_git_one(the_repository, get_object_directory(), 1);\n \tprepare_alt_odb(the_repository);\n \tfor (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next)\n-\t\tprepare_packed_git_one(alt->path, 0);\n+\t\tprepare_packed_git_one(the_repository, alt->path, 0);\n \trearrange_packed_git();\n \tprepare_packed_git_mru();\n \tthe_repository->objects.packed_git_initialized = 1;\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338284","messageId":"20180205235508.216277-20-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235508.216277-1-sbeller@google.com","subject":"[PATCH 019/194] pack: add repository argument to prepare_packed_git_mru","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:52:13Z","receivedAt":"2018-02-05T23:56:35Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nAdd a repository argument to allow the prepare_packed_git_mru caller\nto be more specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n packfile.c | 5 +++--\n 1 file changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/packfile.c b/packfile.c\nindex 52cf9182c4..b4ace96f0c 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -865,7 +865,8 @@ static void rearrange_packed_git_the_repository(void)\n \t\tset_next_packed_git, sort_pack);\n }\n \n-static void prepare_packed_git_mru(void)\n+#define prepare_packed_git_mru(r) prepare_packed_git_mru_##r()\n+static void prepare_packed_git_mru_the_repository(void)\n {\n \tstruct packed_git *p;\n \n@@ -885,7 +886,7 @@ void prepare_packed_git(void)\n \tfor (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next)\n \t\tprepare_packed_git_one(the_repository, alt->path, 0);\n \trearrange_packed_git(the_repository);\n-\tprepare_packed_git_mru();\n+\tprepare_packed_git_mru(the_repository);\n \tthe_repository->objects.packed_git_initialized = 1;\n }\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338285","messageId":"20180205235508.216277-21-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235508.216277-1-sbeller@google.com","subject":"[PATCH 020/194] pack: add repository argument to prepare_packed_git","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:52:14Z","receivedAt":"2018-02-05T23:56:37Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nAdd a repository argument to allow prepare_packed_git_mru callers to\nbe more specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nCallers adapted using contrib/coccinelle/packed_git.cocci.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n builtin/count-objects.c             |  2 +-\n builtin/fsck.c                      |  2 +-\n builtin/gc.c                        |  2 +-\n builtin/pack-objects.c              |  2 +-\n builtin/pack-redundant.c            |  2 +-\n contrib/coccinelle/packed_git.cocci |  4 ++++\n fast-import.c                       |  2 +-\n http-backend.c                      |  2 +-\n pack-bitmap.c                       |  2 +-\n packfile.c                          | 10 +++++-----\n packfile.h                          |  3 ++-\n server-info.c                       |  2 +-\n sha1_name.c                         |  4 ++--\n 13 files changed, 22 insertions(+), 17 deletions(-)\n\ndiff --git a/builtin/count-objects.c b/builtin/count-objects.c\nindex 843a7d7d7e..e340b3e3c3 100644\n--- a/builtin/count-objects.c\n+++ b/builtin/count-objects.c\n@@ -123,7 +123,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)\n \t\tstruct strbuf pack_buf = STRBUF_INIT;\n \t\tstruct strbuf garbage_buf = STRBUF_INIT;\n \t\tif (!the_repository->objects.packed_git)\n-\t\t\tprepare_packed_git();\n+\t\t\tprepare_packed_git(the_repository);\n \t\tfor (p = the_repository->objects.packed_git; p; p = p->next) {\n \t\t\tif (!p->pack_local)\n \t\t\t\tcontinue;\ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex 00ec8eecf0..0e78f4ba72 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -705,7 +705,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)\n \t\t\tuint32_t total = 0, count = 0;\n \t\t\tstruct progress *progress = NULL;\n \n-\t\t\tprepare_packed_git();\n+\t\t\tprepare_packed_git(the_repository);\n \n \t\t\tif (show_progress) {\n \t\t\t\tfor (p = the_repository->objects.packed_git; p;\ndiff --git a/builtin/gc.c b/builtin/gc.c\nindex 6970f325e5..00a3b402a8 100644\n--- a/builtin/gc.c\n+++ b/builtin/gc.c\n@@ -174,7 +174,7 @@ static int too_many_packs(void)\n \tif (gc_auto_pack_limit <= 0)\n \t\treturn 0;\n \n-\tprepare_packed_git();\n+\tprepare_packed_git(the_repository);\n \tfor (cnt = 0, p = the_repository->objects.packed_git; p; p = p->next) {\n \t\tif (!p->pack_local)\n \t\t\tcontinue;\ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex 2ee8b69238..d42df2a2b9 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -3121,7 +3121,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)\n \tif (progress && all_progress_implied)\n \t\tprogress = 2;\n \n-\tprepare_packed_git();\n+\tprepare_packed_git(the_repository);\n \tif (ignore_packed_keep) {\n \t\tstruct packed_git *p;\n \t\tfor (p = the_repository->objects.packed_git; p; p = p->next)\ndiff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c\nindex 55462bc826..83d2395dae 100644\n--- a/builtin/pack-redundant.c\n+++ b/builtin/pack-redundant.c\n@@ -631,7 +631,7 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix)\n \t\t\tbreak;\n \t}\n \n-\tprepare_packed_git();\n+\tprepare_packed_git(the_repository);\n \n \tif (load_all_packs)\n \t\tload_all();\ndiff --git a/contrib/coccinelle/packed_git.cocci b/contrib/coccinelle/packed_git.cocci\nindex da317a51a9..7554f4773c 100644\n--- a/contrib/coccinelle/packed_git.cocci\n+++ b/contrib/coccinelle/packed_git.cocci\n@@ -5,3 +5,7 @@\n @@ @@\n - packed_git_mru\n + the_repository->objects.packed_git_mru\n+\n+@@ @@\n+- prepare_packed_git()\n++ prepare_packed_git(the_repository)\ndiff --git a/fast-import.c b/fast-import.c\nindex 67550584da..39cd0b7540 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -3471,7 +3471,7 @@ int cmd_main(int argc, const char **argv)\n \t\trc_free[i].next = &rc_free[i + 1];\n \trc_free[cmd_save - 1].next = NULL;\n \n-\tprepare_packed_git();\n+\tprepare_packed_git(the_repository);\n \tstart_packfile();\n \tset_die_routine(die_nicely);\n \tset_checkpoint_signal();\ndiff --git a/http-backend.c b/http-backend.c\nindex 4d93126c15..4950078c93 100644\n--- a/http-backend.c\n+++ b/http-backend.c\n@@ -519,7 +519,7 @@ static void get_info_packs(struct strbuf *hdr, char *arg)\n \tsize_t cnt = 0;\n \n \tselect_getanyfile(hdr);\n-\tprepare_packed_git();\n+\tprepare_packed_git(the_repository);\n \tfor (p = the_repository->objects.packed_git; p; p = p->next) {\n \t\tif (p->pack_local)\n \t\t\tcnt++;\ndiff --git a/pack-bitmap.c b/pack-bitmap.c\nindex d51172b1d5..273bdfb631 100644\n--- a/pack-bitmap.c\n+++ b/pack-bitmap.c\n@@ -336,7 +336,7 @@ static int open_pack_bitmap(void)\n \n \tassert(!bitmap_git.map && !bitmap_git.loaded);\n \n-\tprepare_packed_git();\n+\tprepare_packed_git(the_repository);\n \tfor (p = the_repository->objects.packed_git; p; p = p->next) {\n \t\tif (open_pack_bitmap_1(p) == 0)\n \t\t\tret = 0;\ndiff --git a/packfile.c b/packfile.c\nindex b4ace96f0c..bf7e6d22ce 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -807,7 +807,7 @@ unsigned long approximate_object_count(void)\n \t\tunsigned long count;\n \t\tstruct packed_git *p;\n \n-\t\tprepare_packed_git();\n+\t\tprepare_packed_git(the_repository);\n \t\tcount = 0;\n \t\tfor (p = the_repository->objects.packed_git; p; p = p->next) {\n \t\t\tif (open_pack_index(p))\n@@ -875,7 +875,7 @@ static void prepare_packed_git_mru_the_repository(void)\n \t\tmru_append(&the_repository->objects.packed_git_mru, p);\n }\n \n-void prepare_packed_git(void)\n+void prepare_packed_git_the_repository(void)\n {\n \tstruct alternate_object_database *alt;\n \n@@ -894,7 +894,7 @@ void reprepare_packed_git(void)\n {\n \tthe_repository->objects.approximate_object_count_valid = 0;\n \tthe_repository->objects.packed_git_initialized = 0;\n-\tprepare_packed_git();\n+\tprepare_packed_git(the_repository);\n }\n \n unsigned long unpack_object_header_buffer(const unsigned char *buf,\n@@ -1836,7 +1836,7 @@ int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)\n {\n \tstruct mru_entry *p;\n \n-\tprepare_packed_git();\n+\tprepare_packed_git(the_repository);\n \tif (!the_repository->objects.packed_git)\n \t\treturn 0;\n \n@@ -1888,7 +1888,7 @@ int for_each_packed_object(each_packed_object_fn cb, void *data, unsigned flags)\n \tint r = 0;\n \tint pack_errors = 0;\n \n-\tprepare_packed_git();\n+\tprepare_packed_git(the_repository);\n \tfor (p = the_repository->objects.packed_git; p; p = p->next) {\n \t\tif ((flags & FOR_EACH_OBJECT_LOCAL_ONLY) && !p->pack_local)\n \t\t\tcontinue;\ndiff --git a/packfile.h b/packfile.h\nindex 7e6959d440..e543a98b23 100644\n--- a/packfile.h\n+++ b/packfile.h\n@@ -32,7 +32,8 @@ extern struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_\n #define PACKDIR_FILE_GARBAGE 4\n extern void (*report_garbage)(unsigned seen_bits, const char *path);\n \n-extern void prepare_packed_git(void);\n+#define prepare_packed_git(r) prepare_packed_git_##r()\n+extern void prepare_packed_git_the_repository(void);\n extern void reprepare_packed_git(void);\n #define install_packed_git(r, p) install_packed_git_##r(p)\n extern void install_packed_git_the_repository(struct packed_git *pack);\ndiff --git a/server-info.c b/server-info.c\nindex 96885c45f6..6cd1506e5e 100644\n--- a/server-info.c\n+++ b/server-info.c\n@@ -201,7 +201,7 @@ static void init_pack_info(const char *infofile, int force)\n \tobjdir = get_object_directory();\n \tobjdirlen = strlen(objdir);\n \n-\tprepare_packed_git();\n+\tprepare_packed_git(the_repository);\n \tfor (p = the_repository->objects.packed_git; p; p = p->next) {\n \t\t/* we ignore things on alternate path since they are\n \t\t * not available to the pullers in general.\ndiff --git a/sha1_name.c b/sha1_name.c\nindex 3e490ee8f6..d3769713ea 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -196,7 +196,7 @@ static void find_short_packed_object(struct disambiguate_state *ds)\n {\n \tstruct packed_git *p;\n \n-\tprepare_packed_git();\n+\tprepare_packed_git(the_repository);\n \tfor (p = the_repository->objects.packed_git; p && !ds->ambiguous;\n \t     p = p->next)\n \t\tunique_in_pack(p, ds);\n@@ -567,7 +567,7 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad)\n {\n \tstruct packed_git *p;\n \n-\tprepare_packed_git();\n+\tprepare_packed_git(the_repository);\n \tfor (p = the_repository->objects.packed_git; p; p = p->next)\n \t\tfind_abbrev_len_for_pack(p, mad);\n }\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338286","messageId":"20180205235508.216277-22-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235508.216277-1-sbeller@google.com","subject":"[PATCH 021/194] pack: add repository argument to reprepare_packed_git","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:52:15Z","receivedAt":"2018-02-05T23:56:40Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nAdd a repository argument to allow reprepare_packed_git_mru callers to\nbe more specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nCallers adapted using contrib/coccinelle/packed_git.cocci.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n builtin/gc.c                        | 2 +-\n builtin/receive-pack.c              | 3 ++-\n bulk-checkin.c                      | 3 ++-\n contrib/coccinelle/packed_git.cocci | 4 ++++\n fetch-pack.c                        | 3 ++-\n packfile.c                          | 2 +-\n packfile.h                          | 3 ++-\n sha1_file.c                         | 2 +-\n 8 files changed, 15 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin/gc.c b/builtin/gc.c\nindex 00a3b402a8..a3a4d4d4f3 100644\n--- a/builtin/gc.c\n+++ b/builtin/gc.c\n@@ -475,7 +475,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)\n \t\treturn error(FAILED_RUN, rerere.argv[0]);\n \n \treport_garbage = report_pack_garbage;\n-\treprepare_packed_git();\n+\treprepare_packed_git(the_repository);\n \tif (pack_garbage.nr > 0)\n \t\tclean_pack_garbage();\n \ndiff --git a/builtin/receive-pack.c b/builtin/receive-pack.c\nindex b2eac79a6e..744fe29366 100644\n--- a/builtin/receive-pack.c\n+++ b/builtin/receive-pack.c\n@@ -1,4 +1,5 @@\n #include \"builtin.h\"\n+#include \"repository.h\"\n #include \"config.h\"\n #include \"lockfile.h\"\n #include \"pack.h\"\n@@ -1778,7 +1779,7 @@ static const char *unpack(int err_fd, struct shallow_info *si)\n \t\tstatus = finish_command(&child);\n \t\tif (status)\n \t\t\treturn \"index-pack abnormal exit\";\n-\t\treprepare_packed_git();\n+\t\treprepare_packed_git(the_repository);\n \t}\n \treturn NULL;\n }\ndiff --git a/bulk-checkin.c b/bulk-checkin.c\nindex 3310fd210a..eadc2d5172 100644\n--- a/bulk-checkin.c\n+++ b/bulk-checkin.c\n@@ -3,6 +3,7 @@\n  */\n #include \"cache.h\"\n #include \"bulk-checkin.h\"\n+#include \"repository.h\"\n #include \"csum-file.h\"\n #include \"pack.h\"\n #include \"strbuf.h\"\n@@ -57,7 +58,7 @@ static void finish_bulk_checkin(struct bulk_checkin_state *state)\n \n \tstrbuf_release(&packname);\n \t/* Make objects we just wrote available to ourselves */\n-\treprepare_packed_git();\n+\treprepare_packed_git(the_repository);\n }\n \n static int already_written(struct bulk_checkin_state *state, unsigned char sha1[])\ndiff --git a/contrib/coccinelle/packed_git.cocci b/contrib/coccinelle/packed_git.cocci\nindex 7554f4773c..0cb0e95f82 100644\n--- a/contrib/coccinelle/packed_git.cocci\n+++ b/contrib/coccinelle/packed_git.cocci\n@@ -9,3 +9,7 @@\n @@ @@\n - prepare_packed_git()\n + prepare_packed_git(the_repository)\n+\n+@@ @@\n+- reprepare_packed_git()\n++ reprepare_packed_git(the_repository)\ndiff --git a/fetch-pack.c b/fetch-pack.c\nindex 9f6b07ad91..9c189ff3ec 100644\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -1,4 +1,5 @@\n #include \"cache.h\"\n+#include \"repository.h\"\n #include \"config.h\"\n #include \"lockfile.h\"\n #include \"refs.h\"\n@@ -1169,7 +1170,7 @@ struct ref *fetch_pack(struct fetch_pack_args *args,\n \tprepare_shallow_info(&si, shallow);\n \tref_cpy = do_fetch_pack(args, fd, ref, sought, nr_sought,\n \t\t\t\t&si, pack_lockfile);\n-\treprepare_packed_git();\n+\treprepare_packed_git(the_repository);\n \tupdate_shallow(args, sought, nr_sought, &si);\n \tclear_shallow_info(&si);\n \treturn ref_cpy;\ndiff --git a/packfile.c b/packfile.c\nindex bf7e6d22ce..6a1c8107ed 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -890,7 +890,7 @@ void prepare_packed_git_the_repository(void)\n \tthe_repository->objects.packed_git_initialized = 1;\n }\n \n-void reprepare_packed_git(void)\n+void reprepare_packed_git_the_repository(void)\n {\n \tthe_repository->objects.approximate_object_count_valid = 0;\n \tthe_repository->objects.packed_git_initialized = 0;\ndiff --git a/packfile.h b/packfile.h\nindex e543a98b23..74f293c439 100644\n--- a/packfile.h\n+++ b/packfile.h\n@@ -34,7 +34,8 @@ extern void (*report_garbage)(unsigned seen_bits, const char *path);\n \n #define prepare_packed_git(r) prepare_packed_git_##r()\n extern void prepare_packed_git_the_repository(void);\n-extern void reprepare_packed_git(void);\n+#define reprepare_packed_git(r) reprepare_packed_git_##r()\n+extern void reprepare_packed_git_the_repository(void);\n #define install_packed_git(r, p) install_packed_git_##r(p)\n extern void install_packed_git_the_repository(struct packed_git *pack);\n \ndiff --git a/sha1_file.c b/sha1_file.c\nindex 7662692ee5..f6e982880e 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -1276,7 +1276,7 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,\n \t\tif (flags & OBJECT_INFO_QUICK) {\n \t\t\treturn -1;\n \t\t} else {\n-\t\t\treprepare_packed_git();\n+\t\t\treprepare_packed_git(the_repository);\n \t\t\tif (!find_pack_entry(real, &e))\n \t\t\t\treturn -1;\n \t\t}\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338287","messageId":"20180205235735.216710-1-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235508.216277-1-sbeller@google.com","subject":"[PATCH 021/194] pack: add repository argument to reprepare_packed_git","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:54:42Z","receivedAt":"2018-02-05T23:57:48Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nAdd a repository argument to allow reprepare_packed_git_mru callers to\nbe more specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nCallers adapted using contrib/coccinelle/packed_git.cocci.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n builtin/gc.c                        | 2 +-\n builtin/receive-pack.c              | 3 ++-\n bulk-checkin.c                      | 3 ++-\n contrib/coccinelle/packed_git.cocci | 4 ++++\n fetch-pack.c                        | 3 ++-\n packfile.c                          | 2 +-\n packfile.h                          | 3 ++-\n sha1_file.c                         | 2 +-\n 8 files changed, 15 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin/gc.c b/builtin/gc.c\nindex 00a3b402a8..a3a4d4d4f3 100644\n--- a/builtin/gc.c\n+++ b/builtin/gc.c\n@@ -475,7 +475,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)\n \t\treturn error(FAILED_RUN, rerere.argv[0]);\n \n \treport_garbage = report_pack_garbage;\n-\treprepare_packed_git();\n+\treprepare_packed_git(the_repository);\n \tif (pack_garbage.nr > 0)\n \t\tclean_pack_garbage();\n \ndiff --git a/builtin/receive-pack.c b/builtin/receive-pack.c\nindex b2eac79a6e..744fe29366 100644\n--- a/builtin/receive-pack.c\n+++ b/builtin/receive-pack.c\n@@ -1,4 +1,5 @@\n #include \"builtin.h\"\n+#include \"repository.h\"\n #include \"config.h\"\n #include \"lockfile.h\"\n #include \"pack.h\"\n@@ -1778,7 +1779,7 @@ static const char *unpack(int err_fd, struct shallow_info *si)\n \t\tstatus = finish_command(&child);\n \t\tif (status)\n \t\t\treturn \"index-pack abnormal exit\";\n-\t\treprepare_packed_git();\n+\t\treprepare_packed_git(the_repository);\n \t}\n \treturn NULL;\n }\ndiff --git a/bulk-checkin.c b/bulk-checkin.c\nindex 3310fd210a..eadc2d5172 100644\n--- a/bulk-checkin.c\n+++ b/bulk-checkin.c\n@@ -3,6 +3,7 @@\n  */\n #include \"cache.h\"\n #include \"bulk-checkin.h\"\n+#include \"repository.h\"\n #include \"csum-file.h\"\n #include \"pack.h\"\n #include \"strbuf.h\"\n@@ -57,7 +58,7 @@ static void finish_bulk_checkin(struct bulk_checkin_state *state)\n \n \tstrbuf_release(&packname);\n \t/* Make objects we just wrote available to ourselves */\n-\treprepare_packed_git();\n+\treprepare_packed_git(the_repository);\n }\n \n static int already_written(struct bulk_checkin_state *state, unsigned char sha1[])\ndiff --git a/contrib/coccinelle/packed_git.cocci b/contrib/coccinelle/packed_git.cocci\nindex 7554f4773c..0cb0e95f82 100644\n--- a/contrib/coccinelle/packed_git.cocci\n+++ b/contrib/coccinelle/packed_git.cocci\n@@ -9,3 +9,7 @@\n @@ @@\n - prepare_packed_git()\n + prepare_packed_git(the_repository)\n+\n+@@ @@\n+- reprepare_packed_git()\n++ reprepare_packed_git(the_repository)\ndiff --git a/fetch-pack.c b/fetch-pack.c\nindex 9f6b07ad91..9c189ff3ec 100644\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -1,4 +1,5 @@\n #include \"cache.h\"\n+#include \"repository.h\"\n #include \"config.h\"\n #include \"lockfile.h\"\n #include \"refs.h\"\n@@ -1169,7 +1170,7 @@ struct ref *fetch_pack(struct fetch_pack_args *args,\n \tprepare_shallow_info(&si, shallow);\n \tref_cpy = do_fetch_pack(args, fd, ref, sought, nr_sought,\n \t\t\t\t&si, pack_lockfile);\n-\treprepare_packed_git();\n+\treprepare_packed_git(the_repository);\n \tupdate_shallow(args, sought, nr_sought, &si);\n \tclear_shallow_info(&si);\n \treturn ref_cpy;\ndiff --git a/packfile.c b/packfile.c\nindex bf7e6d22ce..6a1c8107ed 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -890,7 +890,7 @@ void prepare_packed_git_the_repository(void)\n \tthe_repository->objects.packed_git_initialized = 1;\n }\n \n-void reprepare_packed_git(void)\n+void reprepare_packed_git_the_repository(void)\n {\n \tthe_repository->objects.approximate_object_count_valid = 0;\n \tthe_repository->objects.packed_git_initialized = 0;\ndiff --git a/packfile.h b/packfile.h\nindex e543a98b23..74f293c439 100644\n--- a/packfile.h\n+++ b/packfile.h\n@@ -34,7 +34,8 @@ extern void (*report_garbage)(unsigned seen_bits, const char *path);\n \n #define prepare_packed_git(r) prepare_packed_git_##r()\n extern void prepare_packed_git_the_repository(void);\n-extern void reprepare_packed_git(void);\n+#define reprepare_packed_git(r) reprepare_packed_git_##r()\n+extern void reprepare_packed_git_the_repository(void);\n #define install_packed_git(r, p) install_packed_git_##r(p)\n extern void install_packed_git_the_repository(struct packed_git *pack);\n \ndiff --git a/sha1_file.c b/sha1_file.c\nindex 7662692ee5..f6e982880e 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -1276,7 +1276,7 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,\n \t\tif (flags & OBJECT_INFO_QUICK) {\n \t\t\treturn -1;\n \t\t} else {\n-\t\t\treprepare_packed_git();\n+\t\t\treprepare_packed_git(the_repository);\n \t\t\tif (!find_pack_entry(real, &e))\n \t\t\t\treturn -1;\n \t\t}\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338288","messageId":"20180205235735.216710-2-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 022/194] pack: add repository argument to sha1_file_name","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:54:43Z","receivedAt":"2018-02-05T23:57:51Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nAdd a repository argument to allow sha1_file_name callers to be more\nspecific about which repository to handle. This is a small mechanical\nchange; it doesn't change the implementation to handle repositories\nother than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nWhile at it, move the declaration to object-store.h, where it should\nbe easier to find.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n cache.h        |  8 --------\n http-walker.c  |  3 ++-\n http.c         |  5 +++--\n object-store.h |  9 +++++++++\n sha1_file.c    | 11 ++++++-----\n 5 files changed, 20 insertions(+), 16 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex bba53f356d..63ed5ccf0a 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -956,14 +956,6 @@ extern void check_repository_format(void);\n #define DATA_CHANGED    0x0020\n #define TYPE_CHANGED    0x0040\n \n-/*\n- * Return the name of the file in the local object database that would\n- * be used to store a loose object with the specified sha1.  The\n- * return value is a pointer to a statically allocated buffer that is\n- * overwritten each time the function is called.\n- */\n-extern const char *sha1_file_name(const unsigned char *sha1);\n-\n /*\n  * Return an abbreviated sha1 unique within this repository's object database.\n  * The result will be at least `len` characters long, and will be NUL\ndiff --git a/http-walker.c b/http-walker.c\nindex a1c6f2639b..96873bdfed 100644\n--- a/http-walker.c\n+++ b/http-walker.c\n@@ -1,4 +1,5 @@\n #include \"cache.h\"\n+#include \"repository.h\"\n #include \"commit.h\"\n #include \"walker.h\"\n #include \"http.h\"\n@@ -546,7 +547,7 @@ static int fetch_object(struct walker *walker, unsigned char *sha1)\n \t\tret = error(\"File %s has bad hash\", hex);\n \t} else if (req->rename < 0) {\n \t\tret = error(\"unable to write sha1 filename %s\",\n-\t\t\t    sha1_file_name(req->sha1));\n+\t\t\t    sha1_file_name(the_repository, req->sha1));\n \t}\n \n \trelease_http_object_request(req);\ndiff --git a/http.c b/http.c\nindex 979d9b3e46..ad57476635 100644\n--- a/http.c\n+++ b/http.c\n@@ -2182,7 +2182,7 @@ struct http_object_request *new_http_object_request(const char *base_url,\n \thashcpy(freq->sha1, sha1);\n \tfreq->localfile = -1;\n \n-\tfilename = sha1_file_name(sha1);\n+\tfilename = sha1_file_name(the_repository, sha1);\n \tsnprintf(freq->tmpfile, sizeof(freq->tmpfile),\n \t\t \"%s.temp\", filename);\n \n@@ -2330,7 +2330,8 @@ int finish_http_object_request(struct http_object_request *freq)\n \t\treturn -1;\n \t}\n \tfreq->rename =\n-\t\tfinalize_object_file(freq->tmpfile, sha1_file_name(freq->sha1));\n+\t\tfinalize_object_file(freq->tmpfile,\n+\t\t\t\t     sha1_file_name(the_repository, freq->sha1));\n \n \treturn freq->rename;\n }\ndiff --git a/object-store.h b/object-store.h\nindex eef8d3b653..228c2ce8ae 100644\n--- a/object-store.h\n+++ b/object-store.h\n@@ -54,6 +54,15 @@ struct packed_git {\n \tchar pack_name[FLEX_ARRAY]; /* more */\n };\n \n+/*\n+ * Return the name of the file in a repository's local object database\n+ * that would be used to store a loose object with the specified sha1.\n+ * The return value is a pointer to a statically allocated buffer that\n+ * is overwritten each time the function is called.\n+ */\n+#define sha1_file_name(r, s) sha1_file_name_##r(s)\n+extern const char *sha1_file_name_the_repository(const unsigned char *sha1);\n+\n #define prepare_alt_odb(r) prepare_alt_odb_##r()\n extern void prepare_alt_odb_the_repository(void);\n \ndiff --git a/sha1_file.c b/sha1_file.c\nindex f6e982880e..caad178b14 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -323,7 +323,7 @@ static void fill_sha1_path(struct strbuf *buf, const unsigned char *sha1)\n \t}\n }\n \n-const char *sha1_file_name(const unsigned char *sha1)\n+const char *sha1_file_name_the_repository(const unsigned char *sha1)\n {\n \tstatic struct strbuf buf = STRBUF_INIT;\n \n@@ -724,7 +724,8 @@ int check_and_freshen_file(const char *fn, int freshen)\n \n static int check_and_freshen_local(const unsigned char *sha1, int freshen)\n {\n-\treturn check_and_freshen_file(sha1_file_name(sha1), freshen);\n+\treturn check_and_freshen_file(sha1_file_name(the_repository, sha1),\n+\t\t\t\t      freshen);\n }\n \n static int check_and_freshen_nonlocal(const unsigned char *sha1, int freshen)\n@@ -882,7 +883,7 @@ static int stat_sha1_file_the_repository(const unsigned char *sha1,\n {\n \tstruct alternate_object_database *alt;\n \n-\t*path = sha1_file_name(sha1);\n+\t*path = sha1_file_name(the_repository, sha1);\n \tif (!lstat(*path, st))\n \t\treturn 0;\n \n@@ -909,7 +910,7 @@ static int open_sha1_file_the_repository(const unsigned char *sha1,\n \tstruct alternate_object_database *alt;\n \tint most_interesting_errno;\n \n-\t*path = sha1_file_name(sha1);\n+\t*path = sha1_file_name(the_repository, sha1);\n \tfd = git_open(*path);\n \tif (fd >= 0)\n \t\treturn fd;\n@@ -1576,7 +1577,7 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,\n \tgit_SHA_CTX c;\n \tunsigned char parano_sha1[20];\n \tstatic struct strbuf tmp_file = STRBUF_INIT;\n-\tconst char *filename = sha1_file_name(sha1);\n+\tconst char *filename = sha1_file_name(the_repository, sha1);\n \n \tfd = create_tmpfile(&tmp_file, filename);\n \tif (fd < 0) {\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338289","messageId":"20180205235735.216710-4-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 024/194] sha1_file: allow alt_odb_usable to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:54:45Z","receivedAt":"2018-02-05T23:58:35Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n sha1_file.c | 16 +++++++++-------\n 1 file changed, 9 insertions(+), 7 deletions(-)\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex af0bf57e07..c639c52f5f 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -25,6 +25,7 @@\n #include \"repository.h\"\n #include \"object-store.h\"\n #include \"streaming.h\"\n+#include \"path.h\"\n #include \"dir.h\"\n #include \"mru.h\"\n #include \"list.h\"\n@@ -351,17 +352,18 @@ static const char *alt_sha1_path(struct alternate_object_database *alt,\n /*\n  * Return non-zero iff the path is usable as an alternate object database.\n  */\n-#define alt_odb_usable(r, p, n) alt_odb_usable_##r(p, n)\n-static int alt_odb_usable_the_repository(struct strbuf *path,\n-\t\t\t\t\t const char *normalized_objdir)\n+static int alt_odb_usable(struct repository *r, struct strbuf *path,\n+\t\t\t  const char *normalized_objdir)\n {\n \tstruct alternate_object_database *alt;\n \n \t/* Detect cases where alternate disappeared */\n \tif (!is_directory(path->buf)) {\n-\t\terror(\"object directory %s does not exist; \"\n-\t\t      \"check .git/objects/info/alternates.\",\n-\t\t      path->buf);\n+\t\tstruct strbuf sb = STRBUF_INIT;\n+\t\tstrbuf_repo_git_path(&sb, r, \"objects/info/alternates\");\n+\t\terror(\"object directory %s does not exist; check %s\",\n+\t\t      path->buf, sb.buf);\n+\t\tstrbuf_release(&sb);\n \t\treturn 0;\n \t}\n \n@@ -369,7 +371,7 @@ static int alt_odb_usable_the_repository(struct strbuf *path,\n \t * Prevent the common mistake of listing the same\n \t * thing twice, or object directory itself.\n \t */\n-\tfor (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next) {\n+\tfor (alt = r->objects.alt_odb_list; alt; alt = alt->next) {\n \t\tif (!fspathcmp(path->buf, alt->path))\n \t\t\treturn 0;\n \t}\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338290","messageId":"20180205235735.216710-5-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 025/194] object-store: allow prepare_alt_odb to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:54:46Z","receivedAt":"2018-02-05T23:58:50Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n cache.h        |  4 ++++\n object-store.h |  3 +--\n sha1_file.c    | 63 ++++++++++++++++++++++++++++++----------------------------\n 3 files changed, 38 insertions(+), 32 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 051a77c49a..ce309cfe3f 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1581,6 +1581,10 @@ struct alternate_object_database {\n \tchar loose_objects_subdir_seen[256];\n \tstruct oid_array loose_objects_cache;\n \n+\t/*\n+\t * Path to the alternate object database, relative to the\n+\t * current working directory.\n+\t */\n \tchar path[FLEX_ARRAY];\n };\n extern char *compute_alternate_path(const char *path, struct strbuf *err);\ndiff --git a/object-store.h b/object-store.h\nindex 92fbf4a9ca..fcf36c7370 100644\n--- a/object-store.h\n+++ b/object-store.h\n@@ -65,8 +65,7 @@ extern const char *sha1_file_name_the_repository(const unsigned char *sha1);\n #define map_sha1_file(r, s, sz) map_sha1_file_##r(s, sz)\n extern void *map_sha1_file_the_repository(const unsigned char *sha1, unsigned long *size);\n \n-#define prepare_alt_odb(r) prepare_alt_odb_##r()\n-extern void prepare_alt_odb_the_repository(void);\n+extern void prepare_alt_odb(struct repository *r);\n \n typedef int alt_odb_fn(struct alternate_object_database *, void *);\n #define foreach_alt_odb(r, fn, cb) foreach_alt_odb_##r(fn, cb)\ndiff --git a/sha1_file.c b/sha1_file.c\nindex c639c52f5f..be67c69c75 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -396,11 +396,10 @@ static int alt_odb_usable(struct repository *r, struct strbuf *path,\n  * SHA1, an extra slash for the first level indirection, and the\n  * terminating NUL.\n  */\n-#define read_info_alternates(r, rb, d) read_info_alternates_##r(rb, d)\n-static void read_info_alternates_the_repository(const char *relative_base,\n-\t\t\t\t\t\tint depth);\n-#define link_alt_odb_entry(r, e, rb, d, n) link_alt_odb_entry_##r(e, rb, d, n)\n-static int link_alt_odb_entry_the_repository(const char *entry,\n+static void read_info_alternates(struct repository *r,\n+\t\t\t\t const char *relative_base,\n+\t\t\t\t int depth);\n+static int link_alt_odb_entry(struct repository *r, const char *entry,\n \tconst char *relative_base, int depth, const char *normalized_objdir)\n {\n \tstruct alternate_object_database *ent;\n@@ -426,7 +425,7 @@ static int link_alt_odb_entry_the_repository(const char *entry,\n \twhile (pathbuf.len && pathbuf.buf[pathbuf.len - 1] == '/')\n \t\tstrbuf_setlen(&pathbuf, pathbuf.len - 1);\n \n-\tif (!alt_odb_usable(the_repository, &pathbuf, normalized_objdir)) {\n+\tif (!alt_odb_usable(r, &pathbuf, normalized_objdir)) {\n \t\tstrbuf_release(&pathbuf);\n \t\treturn -1;\n \t}\n@@ -434,12 +433,12 @@ static int link_alt_odb_entry_the_repository(const char *entry,\n \tent = alloc_alt_odb(pathbuf.buf);\n \n \t/* add the alternate entry */\n-\t*the_repository->objects.alt_odb_tail = ent;\n-\tthe_repository->objects.alt_odb_tail = &(ent->next);\n+\t*r->objects.alt_odb_tail = ent;\n+\tr->objects.alt_odb_tail = &(ent->next);\n \tent->next = NULL;\n \n \t/* recursively add alternates */\n-\tread_info_alternates(the_repository, pathbuf.buf, depth + 1);\n+\tread_info_alternates(r, pathbuf.buf, depth + 1);\n \n \tstrbuf_release(&pathbuf);\n \treturn 0;\n@@ -474,12 +473,8 @@ static const char *parse_alt_odb_entry(const char *string,\n \treturn end;\n }\n \n-#define link_alt_odb_entries(r, a, s, rb, d) \\\n-\tlink_alt_odb_entries_##r(a, s, rb, d)\n-static void link_alt_odb_entries_the_repository(const char *alt,\n-\t\t\t\t\t\tint sep,\n-\t\t\t\t\t\tconst char *relative_base,\n-\t\t\t\t\t\tint depth)\n+static void link_alt_odb_entries(struct repository *r, const char *alt,\n+\t\t\t\t int sep, const char *relative_base, int depth)\n {\n \tstruct strbuf objdirbuf = STRBUF_INIT;\n \tstruct strbuf entry = STRBUF_INIT;\n@@ -493,7 +488,7 @@ static void link_alt_odb_entries_the_repository(const char *alt,\n \t\treturn;\n \t}\n \n-\tstrbuf_add_absolute_path(&objdirbuf, get_object_directory());\n+\tstrbuf_add_absolute_path(&objdirbuf, r->objectdir);\n \tif (strbuf_normalize_path(&objdirbuf) < 0)\n \t\tdie(\"unable to normalize object directory: %s\",\n \t\t    objdirbuf.buf);\n@@ -502,15 +497,16 @@ static void link_alt_odb_entries_the_repository(const char *alt,\n \t\talt = parse_alt_odb_entry(alt, sep, &entry);\n \t\tif (!entry.len)\n \t\t\tcontinue;\n-\t\tlink_alt_odb_entry(the_repository, entry.buf,\n+\t\tlink_alt_odb_entry(r, entry.buf,\n \t\t\t\t   relative_base, depth, objdirbuf.buf);\n \t}\n \tstrbuf_release(&entry);\n \tstrbuf_release(&objdirbuf);\n }\n \n-static void read_info_alternates_the_repository(const char *relative_base,\n-\t\t\t\t\t\tint depth)\n+static void read_info_alternates(struct repository *r,\n+\t\t\t\t const char *relative_base,\n+\t\t\t\t int depth)\n {\n \tchar *path;\n \tstruct strbuf buf = STRBUF_INIT;\n@@ -522,7 +518,7 @@ static void read_info_alternates_the_repository(const char *relative_base,\n \t\treturn;\n \t}\n \n-\tlink_alt_odb_entries(the_repository, buf.buf, '\\n', relative_base, depth);\n+\tlink_alt_odb_entries(r, buf.buf, '\\n', relative_base, depth);\n \tstrbuf_release(&buf);\n \tfree(path);\n }\n@@ -683,21 +679,28 @@ int foreach_alt_odb_the_repository(alt_odb_fn fn, void *cb)\n \treturn r;\n }\n \n-void prepare_alt_odb_the_repository(void)\n+void prepare_alt_odb(struct repository *r)\n {\n-\tconst char *alt;\n-\n-\tif (the_repository->objects.alt_odb_tail)\n+\tif (r->objects.alt_odb_tail)\n \t\treturn;\n \n-\talt = getenv(ALTERNATE_DB_ENVIRONMENT);\n+\tr->objects.alt_odb_tail = &r->objects.alt_odb_list;\n+\n+\tif (!r->ignore_env) {\n+\t\tconst char *alt = getenv(ALTERNATE_DB_ENVIRONMENT);\n+\t\tif (!alt)\n+\t\t\talt = \"\";\n \n-\tthe_repository->objects.alt_odb_tail =\n-\t\t\t&the_repository->objects.alt_odb_list;\n-\tlink_alt_odb_entries(the_repository, alt,\n-\t\t\t     PATH_SEP, NULL, 0);\n+\t\t/*\n+\t\t * Paths in alt are relative to the cwd. We ignore environment\n+\t\t * settings like this for all repositories except for\n+\t\t * the_repository, so we don't have to worry about transforming\n+\t\t * the path to be relative to another repository.\n+\t\t */\n+\t\tlink_alt_odb_entries(r, alt, PATH_SEP, NULL, 0);\n+\t}\n \n-\tread_info_alternates(the_repository, get_object_directory(), 0);\n+\tread_info_alternates(r, r->objectdir, 0);\n }\n \n /* Returns 1 if we have successfully freshened the file, 0 otherwise. */\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338291","messageId":"20180205235735.216710-6-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 026/194] object-store: allow foreach_alt_odb to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:54:47Z","receivedAt":"2018-02-05T23:59:08Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n object-store.h |  3 +--\n sha1_file.c    | 14 +++++++-------\n 2 files changed, 8 insertions(+), 9 deletions(-)\n\ndiff --git a/object-store.h b/object-store.h\nindex fcf36c7370..518da80367 100644\n--- a/object-store.h\n+++ b/object-store.h\n@@ -68,7 +68,6 @@ extern void *map_sha1_file_the_repository(const unsigned char *sha1, unsigned lo\n extern void prepare_alt_odb(struct repository *r);\n \n typedef int alt_odb_fn(struct alternate_object_database *, void *);\n-#define foreach_alt_odb(r, fn, cb) foreach_alt_odb_##r(fn, cb)\n-extern int foreach_alt_odb_the_repository(alt_odb_fn, void*);\n+extern int foreach_alt_odb(struct repository *r, alt_odb_fn, void*);\n \n #endif /* OBJECT_STORE_H */\ndiff --git a/sha1_file.c b/sha1_file.c\nindex be67c69c75..ca492eb741 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -665,18 +665,18 @@ char *compute_alternate_path(const char *path, struct strbuf *err)\n \treturn ref_git;\n }\n \n-int foreach_alt_odb_the_repository(alt_odb_fn fn, void *cb)\n+int foreach_alt_odb(struct repository *r, alt_odb_fn fn, void *cb)\n {\n \tstruct alternate_object_database *ent;\n-\tint r = 0;\n+\tint ret = 0;\n \n-\tprepare_alt_odb(the_repository);\n-\tfor (ent = the_repository->objects.alt_odb_list; ent; ent = ent->next) {\n-\t\tr = fn(ent, cb);\n-\t\tif (r)\n+\tprepare_alt_odb(r);\n+\tfor (ent = r->objects.alt_odb_list; ent; ent = ent->next) {\n+\t\tret = fn(ent, cb);\n+\t\tif (ret)\n \t\t\tbreak;\n \t}\n-\treturn r;\n+\treturn ret;\n }\n \n void prepare_alt_odb(struct repository *r)\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338292","messageId":"20180205235735.216710-8-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 028/194] pack: allow rearrange_packed_git to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:54:49Z","receivedAt":"2018-02-05T23:59:20Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n packfile.c | 7 +++----\n 1 file changed, 3 insertions(+), 4 deletions(-)\n\ndiff --git a/packfile.c b/packfile.c\nindex 05b4505b2c..d1533ec948 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -857,11 +857,10 @@ static int sort_pack(const void *a_, const void *b_)\n \treturn -1;\n }\n \n-#define rearrange_packed_git(r) rearrange_packed_git_##r()\n-static void rearrange_packed_git_the_repository(void)\n+static void rearrange_packed_git(struct repository *r)\n {\n-\tthe_repository->objects.packed_git = llist_mergesort(\n-\t\tthe_repository->objects.packed_git, get_next_packed_git,\n+\tr->objects.packed_git = llist_mergesort(\n+\t\tr->objects.packed_git, get_next_packed_git,\n \t\tset_next_packed_git, sort_pack);\n }\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338293","messageId":"20180205235735.216710-3-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 023/194] pack: add repository argument to map_sha1_file","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:54:44Z","receivedAt":"2018-02-05T23:59:27Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nAdd a repository argument to allow map_sha1_file callers to be more\nspecific about which repository to handle. This is a small mechanical\nchange; it doesn't change the implementation to handle repositories\nother than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nWhile at it, move the declaration to object-store.h, where it should\nbe easier to find.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n cache.h        | 1 -\n object-store.h | 2 ++\n sha1_file.c    | 4 ++--\n streaming.c    | 5 ++++-\n 4 files changed, 8 insertions(+), 4 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 63ed5ccf0a..051a77c49a 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1237,7 +1237,6 @@ extern int pretend_sha1_file(void *, unsigned long, enum object_type, unsigned c\n extern int force_object_loose(const unsigned char *sha1, time_t mtime);\n extern int git_open_cloexec(const char *name, int flags);\n #define git_open(name) git_open_cloexec(name, O_RDONLY)\n-extern void *map_sha1_file(const unsigned char *sha1, unsigned long *size);\n extern int unpack_sha1_header(git_zstream *stream, unsigned char *map, unsigned long mapsize, void *buffer, unsigned long bufsiz);\n extern int parse_sha1_header(const char *hdr, unsigned long *sizep);\n \ndiff --git a/object-store.h b/object-store.h\nindex 228c2ce8ae..92fbf4a9ca 100644\n--- a/object-store.h\n+++ b/object-store.h\n@@ -62,6 +62,8 @@ struct packed_git {\n  */\n #define sha1_file_name(r, s) sha1_file_name_##r(s)\n extern const char *sha1_file_name_the_repository(const unsigned char *sha1);\n+#define map_sha1_file(r, s, sz) map_sha1_file_##r(s, sz)\n+extern void *map_sha1_file_the_repository(const unsigned char *sha1, unsigned long *size);\n \n #define prepare_alt_odb(r) prepare_alt_odb_##r()\n extern void prepare_alt_odb_the_repository(void);\ndiff --git a/sha1_file.c b/sha1_file.c\nindex caad178b14..af0bf57e07 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -963,7 +963,7 @@ static void *map_sha1_file_1_the_repository(const char *path,\n \treturn map;\n }\n \n-void *map_sha1_file(const unsigned char *sha1, unsigned long *size)\n+void *map_sha1_file_the_repository(const unsigned char *sha1, unsigned long *size)\n {\n \treturn map_sha1_file_1(the_repository, NULL, sha1, size);\n }\n@@ -1188,7 +1188,7 @@ static int sha1_loose_object_info_the_repository(const unsigned char *sha1,\n \t\treturn 0;\n \t}\n \n-\tmap = map_sha1_file(sha1, &mapsize);\n+\tmap = map_sha1_file(the_repository, sha1, &mapsize);\n \tif (!map)\n \t\treturn -1;\n \ndiff --git a/streaming.c b/streaming.c\nindex 5892b50bd8..22d27df55e 100644\n--- a/streaming.c\n+++ b/streaming.c\n@@ -3,6 +3,8 @@\n  */\n #include \"cache.h\"\n #include \"streaming.h\"\n+#include \"repository.h\"\n+#include \"object-store.h\"\n #include \"packfile.h\"\n \n enum input_source {\n@@ -335,7 +337,8 @@ static struct stream_vtbl loose_vtbl = {\n \n static open_method_decl(loose)\n {\n-\tst->u.loose.mapped = map_sha1_file(sha1, &st->u.loose.mapsize);\n+\tst->u.loose.mapped = map_sha1_file(the_repository,\n+\t\t\t\t\t   sha1, &st->u.loose.mapsize);\n \tif (!st->u.loose.mapped)\n \t\treturn -1;\n \tif ((unpack_sha1_header(&st->z,\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338294","messageId":"20180205235735.216710-7-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 027/194] pack: allow install_packed_git to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:54:48Z","receivedAt":"2018-02-05T23:59:35Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n packfile.c | 6 +++---\n packfile.h | 3 +--\n 2 files changed, 4 insertions(+), 5 deletions(-)\n\ndiff --git a/packfile.c b/packfile.c\nindex 6a1c8107ed..05b4505b2c 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -671,13 +671,13 @@ struct packed_git *add_packed_git(const char *path, size_t path_len, int local)\n \treturn p;\n }\n \n-void install_packed_git_the_repository(struct packed_git *pack)\n+void install_packed_git(struct repository *r, struct packed_git *pack)\n {\n \tif (pack->pack_fd != -1)\n \t\tpack_open_fds++;\n \n-\tpack->next = the_repository->objects.packed_git;\n-\tthe_repository->objects.packed_git = pack;\n+\tpack->next = r->objects.packed_git;\n+\tr->objects.packed_git = pack;\n }\n \n void (*report_garbage)(unsigned seen_bits, const char *path);\ndiff --git a/packfile.h b/packfile.h\nindex 74f293c439..ba6f08be99 100644\n--- a/packfile.h\n+++ b/packfile.h\n@@ -36,8 +36,7 @@ extern void (*report_garbage)(unsigned seen_bits, const char *path);\n extern void prepare_packed_git_the_repository(void);\n #define reprepare_packed_git(r) reprepare_packed_git_##r()\n extern void reprepare_packed_git_the_repository(void);\n-#define install_packed_git(r, p) install_packed_git_##r(p)\n-extern void install_packed_git_the_repository(struct packed_git *pack);\n+extern void install_packed_git(struct repository *r, struct packed_git *pack);\n \n /*\n  * Give a rough count of objects in the repository. This sacrifices accuracy\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338295","messageId":"20180205235735.216710-9-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 029/194] pack: allow prepare_packed_git_mru to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:54:50Z","receivedAt":"2018-02-05T23:59:40Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n packfile.c | 9 ++++-----\n 1 file changed, 4 insertions(+), 5 deletions(-)\n\ndiff --git a/packfile.c b/packfile.c\nindex d1533ec948..fd7dfc816e 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -864,14 +864,13 @@ static void rearrange_packed_git(struct repository *r)\n \t\tset_next_packed_git, sort_pack);\n }\n \n-#define prepare_packed_git_mru(r) prepare_packed_git_mru_##r()\n-static void prepare_packed_git_mru_the_repository(void)\n+static void prepare_packed_git_mru(struct repository *r)\n {\n \tstruct packed_git *p;\n \n-\tmru_clear(&the_repository->objects.packed_git_mru);\n-\tfor (p = the_repository->objects.packed_git; p; p = p->next)\n-\t\tmru_append(&the_repository->objects.packed_git_mru, p);\n+\tmru_clear(&r->objects.packed_git_mru);\n+\tfor (p = r->objects.packed_git; p; p = p->next)\n+\t\tmru_append(&r->objects.packed_git_mru, p);\n }\n \n void prepare_packed_git_the_repository(void)\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338296","messageId":"20180205235735.216710-10-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 030/194] pack: allow prepare_packed_git_one to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:54:51Z","receivedAt":"2018-02-05T23:59:43Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n packfile.c | 9 ++++-----\n 1 file changed, 4 insertions(+), 5 deletions(-)\n\ndiff --git a/packfile.c b/packfile.c\nindex fd7dfc816e..2b73e62a44 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -726,8 +726,8 @@ static void report_pack_garbage(struct string_list *list)\n \treport_helper(list, seen_bits, first, list->nr);\n }\n \n-#define prepare_packed_git_one(r, o, l) prepare_packed_git_one_##r(o, l)\n-static void prepare_packed_git_one_the_repository(char *objdir, int local)\n+static void prepare_packed_git_one(struct repository *r,\n+\t\t\t\t   char *objdir, int local)\n {\n \tstruct strbuf path = STRBUF_INIT;\n \tsize_t dirnamelen;\n@@ -760,8 +760,7 @@ static void prepare_packed_git_one_the_repository(char *objdir, int local)\n \t\tbase_len = path.len;\n \t\tif (strip_suffix_mem(path.buf, &base_len, \".idx\")) {\n \t\t\t/* Don't reopen a pack we already have. */\n-\t\t\tfor (p = the_repository->objects.packed_git; p;\n-\t\t\t     p = p->next) {\n+\t\t\tfor (p = r->objects.packed_git; p; p = p->next) {\n \t\t\t\tsize_t len;\n \t\t\t\tif (strip_suffix(p->pack_name, \".pack\", &len) &&\n \t\t\t\t    len == base_len &&\n@@ -774,7 +773,7 @@ static void prepare_packed_git_one_the_repository(char *objdir, int local)\n \t\t\t     * corresponding .pack file that we can map.\n \t\t\t     */\n \t\t\t    (p = add_packed_git(path.buf, path.len, local)) != NULL)\n-\t\t\t\tinstall_packed_git(the_repository, p);\n+\t\t\t\tinstall_packed_git(r, p);\n \t\t}\n \n \t\tif (!report_garbage)\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338297","messageId":"20180205235735.216710-11-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 031/194] pack: allow prepare_packed_git to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:54:52Z","receivedAt":"2018-02-06T00:00:11Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n packfile.c | 18 +++++++++---------\n packfile.h |  3 +--\n 2 files changed, 10 insertions(+), 11 deletions(-)\n\ndiff --git a/packfile.c b/packfile.c\nindex 2b73e62a44..7dc7e8e383 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -872,19 +872,19 @@ static void prepare_packed_git_mru(struct repository *r)\n \t\tmru_append(&r->objects.packed_git_mru, p);\n }\n \n-void prepare_packed_git_the_repository(void)\n+void prepare_packed_git(struct repository *r)\n {\n \tstruct alternate_object_database *alt;\n \n-\tif (the_repository->objects.packed_git_initialized)\n+\tif (r->objects.packed_git_initialized)\n \t\treturn;\n-\tprepare_packed_git_one(the_repository, get_object_directory(), 1);\n-\tprepare_alt_odb(the_repository);\n-\tfor (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next)\n-\t\tprepare_packed_git_one(the_repository, alt->path, 0);\n-\trearrange_packed_git(the_repository);\n-\tprepare_packed_git_mru(the_repository);\n-\tthe_repository->objects.packed_git_initialized = 1;\n+\tprepare_packed_git_one(r, r->objectdir, 1);\n+\tprepare_alt_odb(r);\n+\tfor (alt = r->objects.alt_odb_list; alt; alt = alt->next)\n+\t\tprepare_packed_git_one(r, alt->path, 0);\n+\trearrange_packed_git(r);\n+\tprepare_packed_git_mru(r);\n+\tr->objects.packed_git_initialized = 1;\n }\n \n void reprepare_packed_git_the_repository(void)\ndiff --git a/packfile.h b/packfile.h\nindex ba6f08be99..75be3cb877 100644\n--- a/packfile.h\n+++ b/packfile.h\n@@ -32,8 +32,7 @@ extern struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_\n #define PACKDIR_FILE_GARBAGE 4\n extern void (*report_garbage)(unsigned seen_bits, const char *path);\n \n-#define prepare_packed_git(r) prepare_packed_git_##r()\n-extern void prepare_packed_git_the_repository(void);\n+extern void prepare_packed_git(struct repository *r);\n #define reprepare_packed_git(r) reprepare_packed_git_##r()\n extern void reprepare_packed_git_the_repository(void);\n extern void install_packed_git(struct repository *r, struct packed_git *pack);\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338298","messageId":"20180205235735.216710-12-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 032/194] pack: allow reprepare_packed_git to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:54:53Z","receivedAt":"2018-02-06T00:00:14Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n packfile.c | 8 ++++----\n packfile.h | 3 +--\n 2 files changed, 5 insertions(+), 6 deletions(-)\n\ndiff --git a/packfile.c b/packfile.c\nindex 7dc7e8e383..7aa69dd3c0 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -887,11 +887,11 @@ void prepare_packed_git(struct repository *r)\n \tr->objects.packed_git_initialized = 1;\n }\n \n-void reprepare_packed_git_the_repository(void)\n+void reprepare_packed_git(struct repository *r)\n {\n-\tthe_repository->objects.approximate_object_count_valid = 0;\n-\tthe_repository->objects.packed_git_initialized = 0;\n-\tprepare_packed_git(the_repository);\n+\tr->objects.approximate_object_count_valid = 0;\n+\tr->objects.packed_git_initialized = 0;\n+\tprepare_packed_git(r);\n }\n \n unsigned long unpack_object_header_buffer(const unsigned char *buf,\ndiff --git a/packfile.h b/packfile.h\nindex 75be3cb877..b3138816e7 100644\n--- a/packfile.h\n+++ b/packfile.h\n@@ -33,8 +33,7 @@ extern struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_\n extern void (*report_garbage)(unsigned seen_bits, const char *path);\n \n extern void prepare_packed_git(struct repository *r);\n-#define reprepare_packed_git(r) reprepare_packed_git_##r()\n-extern void reprepare_packed_git_the_repository(void);\n+extern void reprepare_packed_git(struct repository *r);\n extern void install_packed_git(struct repository *r, struct packed_git *pack);\n \n /*\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338299","messageId":"20180205235735.216710-13-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 033/194] pack: allow sha1_file_name to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:54:54Z","receivedAt":"2018-02-06T00:00:35Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n object-store.h | 3 +--\n sha1_file.c    | 4 ++--\n 2 files changed, 3 insertions(+), 4 deletions(-)\n\ndiff --git a/object-store.h b/object-store.h\nindex 518da80367..fe2187fd65 100644\n--- a/object-store.h\n+++ b/object-store.h\n@@ -60,8 +60,7 @@ struct packed_git {\n  * The return value is a pointer to a statically allocated buffer that\n  * is overwritten each time the function is called.\n  */\n-#define sha1_file_name(r, s) sha1_file_name_##r(s)\n-extern const char *sha1_file_name_the_repository(const unsigned char *sha1);\n+extern const char *sha1_file_name(struct repository *r, const unsigned char *sha1);\n #define map_sha1_file(r, s, sz) map_sha1_file_##r(s, sz)\n extern void *map_sha1_file_the_repository(const unsigned char *sha1, unsigned long *size);\n \ndiff --git a/sha1_file.c b/sha1_file.c\nindex ca492eb741..5d4c39bd45 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -324,12 +324,12 @@ static void fill_sha1_path(struct strbuf *buf, const unsigned char *sha1)\n \t}\n }\n \n-const char *sha1_file_name_the_repository(const unsigned char *sha1)\n+const char *sha1_file_name(struct repository *r, const unsigned char *sha1)\n {\n \tstatic struct strbuf buf = STRBUF_INIT;\n \n \tstrbuf_reset(&buf);\n-\tstrbuf_addf(&buf, \"%s/\", get_object_directory());\n+\tstrbuf_addf(&buf, \"%s/\", r->objectdir);\n \n \tfill_sha1_path(&buf, sha1);\n \treturn buf.buf;\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338300","messageId":"20180205235735.216710-14-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 034/194] pack: allow stat_sha1_file to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:54:55Z","receivedAt":"2018-02-06T00:00:38Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n sha1_file.c | 11 +++++------\n 1 file changed, 5 insertions(+), 6 deletions(-)\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 5d4c39bd45..6887543d5e 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -882,19 +882,18 @@ int git_open_cloexec(const char *name, int flags)\n  * Note that it may point to static storage and is only valid until another\n  * call to sha1_file_name(), etc.\n  */\n-#define stat_sha1_file(r, s, st, p) stat_sha1_file_##r(s, st, p)\n-static int stat_sha1_file_the_repository(const unsigned char *sha1,\n-\t\t\t\t\t struct stat *st, const char **path)\n+static int stat_sha1_file(struct repository *r, const unsigned char *sha1,\n+\t\t\t  struct stat *st, const char **path)\n {\n \tstruct alternate_object_database *alt;\n \n-\t*path = sha1_file_name(the_repository, sha1);\n+\t*path = sha1_file_name(r, sha1);\n \tif (!lstat(*path, st))\n \t\treturn 0;\n \n-\tprepare_alt_odb(the_repository);\n+\tprepare_alt_odb(r);\n \terrno = ENOENT;\n-\tfor (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next) {\n+\tfor (alt = r->objects.alt_odb_list; alt; alt = alt->next) {\n \t\t*path = alt_sha1_path(alt, sha1);\n \t\tif (!lstat(*path, st))\n \t\t\treturn 0;\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338301","messageId":"20180205235735.216710-15-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 035/194] pack: allow open_sha1_file to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:54:56Z","receivedAt":"2018-02-06T00:01:04Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n sha1_file.c | 11 +++++------\n 1 file changed, 5 insertions(+), 6 deletions(-)\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 6887543d5e..a0f438b493 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -906,22 +906,21 @@ static int stat_sha1_file(struct repository *r, const unsigned char *sha1,\n  * Like stat_sha1_file(), but actually open the object and return the\n  * descriptor. See the caveats on the \"path\" parameter above.\n  */\n-#define open_sha1_file(r, s, p) open_sha1_file_##r(s, p)\n-static int open_sha1_file_the_repository(const unsigned char *sha1,\n-\t\t\t\t\t const char **path)\n+static int open_sha1_file(struct repository *r,\n+\t\t\t  const unsigned char *sha1, const char **path)\n {\n \tint fd;\n \tstruct alternate_object_database *alt;\n \tint most_interesting_errno;\n \n-\t*path = sha1_file_name(the_repository, sha1);\n+\t*path = sha1_file_name(r, sha1);\n \tfd = git_open(*path);\n \tif (fd >= 0)\n \t\treturn fd;\n \tmost_interesting_errno = errno;\n \n-\tprepare_alt_odb(the_repository);\n-\tfor (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next) {\n+\tprepare_alt_odb(r);\n+\tfor (alt = r->objects.alt_odb_list; alt; alt = alt->next) {\n \t\t*path = alt_sha1_path(alt, sha1);\n \t\tfd = git_open(*path);\n \t\tif (fd >= 0)\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338302","messageId":"20180205235735.216710-16-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 036/194] pack: allow map_sha1_file_1 to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:54:57Z","receivedAt":"2018-02-06T00:01:07Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n sha1_file.c | 8 +++-----\n 1 file changed, 3 insertions(+), 5 deletions(-)\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex a0f438b493..590b857391 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -936,10 +936,8 @@ static int open_sha1_file(struct repository *r,\n  * Map the loose object at \"path\" if it is not NULL, or the path found by\n  * searching for a loose object named \"sha1\".\n  */\n-#define map_sha1_file_1(r, p, s, si) map_sha1_file_1_##r(p, s, si)\n-static void *map_sha1_file_1_the_repository(const char *path,\n-\t\t\t\t\t    const unsigned char *sha1,\n-\t\t\t\t\t    unsigned long *size)\n+static void *map_sha1_file_1(struct repository *r, const char *path,\n+\t\t\t     const unsigned char *sha1, unsigned long *size)\n {\n \tvoid *map;\n \tint fd;\n@@ -947,7 +945,7 @@ static void *map_sha1_file_1_the_repository(const char *path,\n \tif (path)\n \t\tfd = git_open(path);\n \telse\n-\t\tfd = open_sha1_file(the_repository, sha1, &path);\n+\t\tfd = open_sha1_file(r, sha1, &path);\n \tmap = NULL;\n \tif (fd >= 0) {\n \t\tstruct stat st;\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338303","messageId":"20180205235735.216710-17-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 037/194] pack: allow map_sha1_file to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:54:58Z","receivedAt":"2018-02-06T00:01:31Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n object-store.h | 3 +--\n sha1_file.c    | 5 +++--\n 2 files changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/object-store.h b/object-store.h\nindex fe2187fd65..57b8d89738 100644\n--- a/object-store.h\n+++ b/object-store.h\n@@ -61,8 +61,7 @@ struct packed_git {\n  * is overwritten each time the function is called.\n  */\n extern const char *sha1_file_name(struct repository *r, const unsigned char *sha1);\n-#define map_sha1_file(r, s, sz) map_sha1_file_##r(s, sz)\n-extern void *map_sha1_file_the_repository(const unsigned char *sha1, unsigned long *size);\n+extern void *map_sha1_file(struct repository *r, const unsigned char *sha1, unsigned long *size);\n \n extern void prepare_alt_odb(struct repository *r);\n \ndiff --git a/sha1_file.c b/sha1_file.c\nindex 590b857391..786e904eab 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -964,9 +964,10 @@ static void *map_sha1_file_1(struct repository *r, const char *path,\n \treturn map;\n }\n \n-void *map_sha1_file_the_repository(const unsigned char *sha1, unsigned long *size)\n+void *map_sha1_file(struct repository *r,\n+\t\t    const unsigned char *sha1, unsigned long *size)\n {\n-\treturn map_sha1_file_1(the_repository, NULL, sha1, size);\n+\treturn map_sha1_file_1(r, NULL, sha1, size);\n }\n \n static int unpack_sha1_short_header(git_zstream *stream,\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338304","messageId":"20180205235735.216710-18-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 038/194] pack: allow sha1_loose_object_info to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:54:59Z","receivedAt":"2018-02-06T00:01:33Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n sha1_file.c | 11 +++++------\n 1 file changed, 5 insertions(+), 6 deletions(-)\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 786e904eab..1e867bc293 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -1156,10 +1156,9 @@ int parse_sha1_header(const char *hdr, unsigned long *sizep)\n \treturn parse_sha1_header_extended(hdr, &oi, 0);\n }\n \n-#define sha1_loose_object_info(r, s, o, f) sha1_loose_object_info_##r(s, o, f)\n-static int sha1_loose_object_info_the_repository(const unsigned char *sha1,\n-\t\t\t\t\t\t struct object_info *oi,\n-\t\t\t\t\t\t int flags)\n+static int sha1_loose_object_info(struct repository *r,\n+\t\t\t\t  const unsigned char *sha1,\n+\t\t\t\t  struct object_info *oi, int flags)\n {\n \tint status = 0;\n \tunsigned long mapsize;\n@@ -1183,14 +1182,14 @@ static int sha1_loose_object_info_the_repository(const unsigned char *sha1,\n \tif (!oi->typep && !oi->typename && !oi->sizep && !oi->contentp) {\n \t\tconst char *path;\n \t\tstruct stat st;\n-\t\tif (stat_sha1_file(the_repository, sha1, &st, &path) < 0)\n+\t\tif (stat_sha1_file(r, sha1, &st, &path) < 0)\n \t\t\treturn -1;\n \t\tif (oi->disk_sizep)\n \t\t\t*oi->disk_sizep = st.st_size;\n \t\treturn 0;\n \t}\n \n-\tmap = map_sha1_file(the_repository, sha1, &mapsize);\n+\tmap = map_sha1_file(r, sha1, &mapsize);\n \tif (!map)\n \t\treturn -1;\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338305","messageId":"20180205235735.216710-19-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 039/194] replace_object.c: rename to use dash in file name","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:00Z","receivedAt":"2018-02-06T00:01:58Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"This is more consistent with the project style. The majority of\nGit's source files use dashes in preference to underscores in their file\nnames.\n\nNoticed while adding a header corresponding to this file.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n Makefile                             | 2 +-\n replace_object.c => replace-object.c | 0\n 2 files changed, 1 insertion(+), 1 deletion(-)\n rename replace_object.c => replace-object.c (100%)\n\ndiff --git a/Makefile b/Makefile\nindex 1a9b23b679..84aeabe320 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -873,7 +873,7 @@ LIB_OBJS += refs/packed-backend.o\n LIB_OBJS += refs/ref-cache.o\n LIB_OBJS += ref-filter.o\n LIB_OBJS += remote.o\n-LIB_OBJS += replace_object.o\n+LIB_OBJS += replace-object.o\n LIB_OBJS += repository.o\n LIB_OBJS += rerere.o\n LIB_OBJS += resolve-undo.o\ndiff --git a/replace_object.c b/replace-object.c\nsimilarity index 100%\nrename from replace_object.c\nrename to replace-object.c\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338306","messageId":"20180205235735.216710-20-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 040/194] replace-object: move replace_object to object store","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:01Z","receivedAt":"2018-02-06T00:02:02Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Refs belong to particular repositories, so the replacements defined by them\nshould belong to a particular repository as well.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n object-store.h   |  9 ++++++++-\n replace-object.c | 42 ++++++++++++++++++------------------------\n replace-object.h | 20 ++++++++++++++++++++\n 3 files changed, 46 insertions(+), 25 deletions(-)\n create mode 100644 replace-object.h\n\ndiff --git a/object-store.h b/object-store.h\nindex 57b8d89738..298e34e978 100644\n--- a/object-store.h\n+++ b/object-store.h\n@@ -3,6 +3,7 @@\n \n #include \"cache.h\"\n #include \"mru.h\"\n+#include \"replace-object.h\"\n \n struct object_store {\n \tstruct packed_git *packed_git;\n@@ -16,6 +17,12 @@ struct object_store {\n \tstruct alternate_object_database *alt_odb_list;\n \tstruct alternate_object_database **alt_odb_tail;\n \n+\t/*\n+\t * Objects that should be substituted by other objects\n+\t * (see git-replace(1)).\n+\t */\n+\tstruct replace_objects replacements;\n+\n \t/*\n \t * A fast, rough count of the number of objects in the repository.\n \t * These two fields are not meant for direct access. Use\n@@ -30,7 +37,7 @@ struct object_store {\n \t */\n \tunsigned packed_git_initialized : 1;\n };\n-#define OBJECT_STORE_INIT { NULL, MRU_INIT, NULL, NULL, 0, 0, 0 }\n+#define OBJECT_STORE_INIT { NULL, MRU_INIT, NULL, NULL, REPLACE_OBJECTS_INIT, 0, 0, 0 }\n \n struct packed_git {\n \tstruct packed_git *next;\ndiff --git a/replace-object.c b/replace-object.c\nindex f0b39f06d5..d26e180639 100644\n--- a/replace-object.c\n+++ b/replace-object.c\n@@ -1,19 +1,10 @@\n #include \"cache.h\"\n+#include \"replace-object.h\"\n #include \"sha1-lookup.h\"\n #include \"refs.h\"\n+#include \"repository.h\"\n #include \"commit.h\"\n \n-/*\n- * An array of replacements.  The array is kept sorted by the original\n- * sha1.\n- */\n-static struct replace_object {\n-\tunsigned char original[20];\n-\tunsigned char replacement[20];\n-} **replace_object;\n-\n-static int replace_object_alloc, replace_object_nr;\n-\n static const unsigned char *replace_sha1_access(size_t index, void *table)\n {\n \tstruct replace_object **replace = table;\n@@ -22,7 +13,8 @@ static const unsigned char *replace_sha1_access(size_t index, void *table)\n \n static int replace_object_pos(const unsigned char *sha1)\n {\n-\treturn sha1_pos(sha1, replace_object, replace_object_nr,\n+\treturn sha1_pos(sha1, the_repository->objects.replacements.items,\n+\t\t\tthe_repository->objects.replacements.nr,\n \t\t\treplace_sha1_access);\n }\n \n@@ -35,20 +27,22 @@ static int register_replace_object(struct replace_object *replace,\n \t\tif (ignore_dups)\n \t\t\tfree(replace);\n \t\telse {\n-\t\t\tfree(replace_object[pos]);\n-\t\t\treplace_object[pos] = replace;\n+\t\t\tfree(the_repository->objects.replacements.items[pos]);\n+\t\t\tthe_repository->objects.replacements.items[pos] = replace;\n \t\t}\n \t\treturn 1;\n \t}\n \tpos = -pos - 1;\n-\tALLOC_GROW(replace_object, replace_object_nr + 1, replace_object_alloc);\n-\treplace_object_nr++;\n-\tif (pos < replace_object_nr)\n-\t\tmemmove(replace_object + pos + 1,\n-\t\t\treplace_object + pos,\n-\t\t\t(replace_object_nr - pos - 1) *\n-\t\t\tsizeof(*replace_object));\n-\treplace_object[pos] = replace;\n+\tALLOC_GROW(the_repository->objects.replacements.items,\n+\t\t   the_repository->objects.replacements.nr + 1,\n+\t\t   the_repository->objects.replacements.alloc);\n+\tthe_repository->objects.replacements.nr++;\n+\tif (pos < the_repository->objects.replacements.nr)\n+\t\tmemmove(the_repository->objects.replacements.items + pos + 1,\n+\t\t\tthe_repository->objects.replacements.items + pos,\n+\t\t\t(the_repository->objects.replacements.nr - pos - 1) *\n+\t\t\tsizeof(*the_repository->objects.replacements.items));\n+\tthe_repository->objects.replacements.items[pos] = replace;\n \treturn 0;\n }\n \n@@ -86,7 +80,7 @@ static void prepare_replace_object(void)\n \n \tfor_each_replace_ref(register_replace_ref, NULL);\n \treplace_object_prepared = 1;\n-\tif (!replace_object_nr)\n+\tif (!the_repository->objects.replacements.nr)\n \t\tcheck_replace_refs = 0;\n }\n \n@@ -115,7 +109,7 @@ const unsigned char *do_lookup_replace_object(const unsigned char *sha1)\n \n \t\tpos = replace_object_pos(cur);\n \t\tif (0 <= pos)\n-\t\t\tcur = replace_object[pos]->replacement;\n+\t\t\tcur = the_repository->objects.replacements.items[pos]->replacement;\n \t} while (0 <= pos);\n \n \treturn cur;\ndiff --git a/replace-object.h b/replace-object.h\nnew file mode 100644\nindex 0000000000..483335ffcc\n--- /dev/null\n+++ b/replace-object.h\n@@ -0,0 +1,20 @@\n+#ifndef REPLACE_OBJECT_H\n+#define REPLACE_OBJECT_H\n+\n+struct replace_objects {\n+\t/*\n+\t * An array of replacements.  The array is kept sorted by the original\n+\t * sha1.\n+\t */\n+\tstruct replace_object **items;\n+\n+\tint alloc, nr;\n+};\n+#define REPLACE_OBJECTS_INIT { NULL, 0, 0 }\n+\n+struct replace_object {\n+\tunsigned char original[20];\n+\tunsigned char replacement[20];\n+};\n+\n+#endif /* REPLACE_OBJECT_H */\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338307","messageId":"20180205235735.216710-21-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 041/194] sha1_file: add repository argument to sha1_object_info_extended","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:02Z","receivedAt":"2018-02-06T00:02:29Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nAdd a repository argument to allow sha1_object_info_extended callers\nto be more specific about which repository to act on. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n builtin/cat-file.c |  6 +++---\n cache.h            |  4 +++-\n packfile.c         |  2 +-\n sha1_file.c        | 11 ++++++-----\n streaming.c        |  2 +-\n 5 files changed, 14 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex f5fa4fd75a..9d18efeb7c 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -77,7 +77,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,\n \tswitch (opt) {\n \tcase 't':\n \t\toi.typename = &sb;\n-\t\tif (sha1_object_info_extended(oid.hash, &oi, flags) < 0)\n+\t\tif (sha1_object_info_extended(the_repository, oid.hash, &oi, flags) < 0)\n \t\t\tdie(\"git cat-file: could not get object info\");\n \t\tif (sb.len) {\n \t\t\tprintf(\"%s\\n\", sb.buf);\n@@ -88,7 +88,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,\n \n \tcase 's':\n \t\toi.sizep = &size;\n-\t\tif (sha1_object_info_extended(oid.hash, &oi, flags) < 0)\n+\t\tif (sha1_object_info_extended(the_repository, oid.hash, &oi, flags) < 0)\n \t\t\tdie(\"git cat-file: could not get object info\");\n \t\tprintf(\"%lu\\n\", size);\n \t\treturn 0;\n@@ -340,7 +340,7 @@ static void batch_object_write(const char *obj_name, struct batch_options *opt,\n \tstruct strbuf buf = STRBUF_INIT;\n \n \tif (!data->skip_object_info &&\n-\t    sha1_object_info_extended(data->oid.hash, &data->info,\n+\t    sha1_object_info_extended(the_repository, data->oid.hash, &data->info,\n \t\t\t\t      OBJECT_INFO_LOOKUP_REPLACE) < 0) {\n \t\tprintf(\"%s missing\\n\",\n \t\t       obj_name ? obj_name : oid_to_hex(&data->oid));\ndiff --git a/cache.h b/cache.h\nindex ce309cfe3f..3410a93737 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1749,7 +1749,9 @@ struct object_info {\n #define OBJECT_INFO_SKIP_CACHED 4\n /* Do not retry packed storage after checking packed and loose storage */\n #define OBJECT_INFO_QUICK 8\n-extern int sha1_object_info_extended(const unsigned char *, struct object_info *, unsigned flags);\n+#define sha1_object_info_extended(r, s, oi, f) \\\n+\t\tsha1_object_info_extended_##r(s, oi, f)\n+extern int sha1_object_info_extended_the_repository(const unsigned char *, struct object_info *, unsigned flags);\n \n /* Dumb servers support */\n extern int update_server_info(int);\ndiff --git a/packfile.c b/packfile.c\nindex 7aa69dd3c0..0ca13a4ed7 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -1450,7 +1450,7 @@ static void *read_object(const unsigned char *sha1, enum object_type *type,\n \toi.sizep = size;\n \toi.contentp = &content;\n \n-\tif (sha1_object_info_extended(sha1, &oi, 0) < 0)\n+\tif (sha1_object_info_extended(the_repository, sha1, &oi, 0) < 0)\n \t\treturn NULL;\n \treturn content;\n }\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 1e867bc293..a5dcb76d96 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -1234,7 +1234,7 @@ static int sha1_loose_object_info(struct repository *r,\n \treturn (status < 0) ? status : 0;\n }\n \n-int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi, unsigned flags)\n+int sha1_object_info_extended_the_repository(const unsigned char *sha1, struct object_info *oi, unsigned flags)\n {\n \tstatic struct object_info blank_oi = OBJECT_INFO_INIT;\n \tstruct pack_entry e;\n@@ -1294,7 +1294,8 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,\n \trtype = packed_object_info(e.p, e.offset, oi);\n \tif (rtype < 0) {\n \t\tmark_bad_packed_object(e.p, real);\n-\t\treturn sha1_object_info_extended(real, oi, 0);\n+\t\treturn sha1_object_info_extended(the_repository, real, oi,\n+\t\t\t\t\t\t 0);\n \t} else if (oi->whence == OI_PACKED) {\n \t\toi->u.packed.offset = e.offset;\n \t\toi->u.packed.pack = e.p;\n@@ -1313,7 +1314,7 @@ int sha1_object_info(const unsigned char *sha1, unsigned long *sizep)\n \n \toi.typep = &type;\n \toi.sizep = sizep;\n-\tif (sha1_object_info_extended(sha1, &oi,\n+\tif (sha1_object_info_extended(the_repository, sha1, &oi,\n \t\t\t\t      OBJECT_INFO_LOOKUP_REPLACE) < 0)\n \t\treturn -1;\n \treturn type;\n@@ -1328,7 +1329,7 @@ static void *read_object(const unsigned char *sha1, enum object_type *type,\n \toi.sizep = size;\n \toi.contentp = &content;\n \n-\tif (sha1_object_info_extended(sha1, &oi, 0) < 0)\n+\tif (sha1_object_info_extended(the_repository, sha1, &oi, 0) < 0)\n \t\treturn NULL;\n \treturn content;\n }\n@@ -1715,7 +1716,7 @@ int has_sha1_file_with_flags(const unsigned char *sha1, int flags)\n {\n \tif (!startup_info->have_repository)\n \t\treturn 0;\n-\treturn sha1_object_info_extended(sha1, NULL,\n+\treturn sha1_object_info_extended(the_repository, sha1, NULL,\n \t\t\t\t\t flags | OBJECT_INFO_SKIP_CACHED) >= 0;\n }\n \ndiff --git a/streaming.c b/streaming.c\nindex 22d27df55e..47fca9aba0 100644\n--- a/streaming.c\n+++ b/streaming.c\n@@ -116,7 +116,7 @@ static enum input_source istream_source(const unsigned char *sha1,\n \n \toi->typep = type;\n \toi->sizep = &size;\n-\tstatus = sha1_object_info_extended(sha1, oi, 0);\n+\tstatus = sha1_object_info_extended(the_repository, sha1, oi, 0);\n \tif (status < 0)\n \t\treturn stream_error;\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338308","messageId":"20180205235735.216710-22-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 042/194] object-store: move alternates API to new alternates.h","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:03Z","receivedAt":"2018-02-06T00:02:32Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nThis should make these functions easier to find and object-store.h\nless overwhelming to read.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n alternates.h                | 68 +++++++++++++++++++++++++++++++++++++++++++++\n builtin/clone.c             |  1 +\n builtin/count-objects.c     |  1 +\n builtin/fsck.c              |  3 +-\n builtin/grep.c              |  1 +\n builtin/submodule--helper.c |  1 +\n cache.h                     | 52 ----------------------------------\n object-store.h              | 16 +++++------\n packfile.c                  |  3 +-\n sha1_file.c                 | 23 +++++++--------\n sha1_name.c                 |  3 +-\n submodule.c                 |  1 +\n t/helper/test-ref-store.c   |  1 +\n tmp-objdir.c                |  1 +\n transport.c                 |  1 +\n 15 files changed, 102 insertions(+), 74 deletions(-)\n create mode 100644 alternates.h\n\ndiff --git a/alternates.h b/alternates.h\nnew file mode 100644\nindex 0000000000..df5dc67e2e\n--- /dev/null\n+++ b/alternates.h\n@@ -0,0 +1,68 @@\n+#ifndef ALTERNATES_H\n+#define ALTERNATES_H\n+\n+#include \"strbuf.h\"\n+#include \"sha1-array.h\"\n+\n+struct alternates {\n+\tstruct alternate_object_database *list;\n+\tstruct alternate_object_database **tail;\n+};\n+#define ALTERNATES_INIT { NULL, NULL }\n+\n+struct alternate_object_database {\n+\tstruct alternate_object_database *next;\n+\n+\t/* see alt_scratch_buf() */\n+\tstruct strbuf scratch;\n+\tsize_t base_len;\n+\n+\t/*\n+\t * Used to store the results of readdir(3) calls when searching\n+\t * for unique abbreviated hashes.  This cache is never\n+\t * invalidated, thus it's racy and not necessarily accurate.\n+\t * That's fine for its purpose; don't use it for tasks requiring\n+\t * greater accuracy!\n+\t */\n+\tchar loose_objects_subdir_seen[256];\n+\tstruct oid_array loose_objects_cache;\n+\n+\t/*\n+\t * Path to the alternate object database, relative to the\n+\t * current working directory.\n+\t */\n+\tchar path[FLEX_ARRAY];\n+};\n+extern void prepare_alt_odb(struct repository *r);\n+extern char *compute_alternate_path(const char *path, struct strbuf *err);\n+typedef int alt_odb_fn(struct alternate_object_database *, void *);\n+extern int foreach_alt_odb(struct repository *r, alt_odb_fn, void*);\n+\n+/*\n+ * Allocate a \"struct alternate_object_database\" but do _not_ actually\n+ * add it to the list of alternates.\n+ */\n+struct alternate_object_database *alloc_alt_odb(const char *dir);\n+\n+/*\n+ * Add the directory to the on-disk alternates file; the new entry will also\n+ * take effect in the current process.\n+ */\n+extern void add_to_alternates_file(const char *dir);\n+\n+/*\n+ * Add the directory to the in-memory list of alternates (along with any\n+ * recursive alternates it points to), but do not modify the on-disk alternates\n+ * file.\n+ */\n+extern void add_to_alternates_memory(const char *dir);\n+\n+/*\n+ * Returns a scratch strbuf pre-filled with the alternate object directory,\n+ * including a trailing slash, which can be used to access paths in the\n+ * alternate. Always use this over direct access to alt->scratch, as it\n+ * cleans up any previous use of the scratch buffer.\n+ */\n+extern struct strbuf *alt_scratch_buf(struct alternate_object_database *alt);\n+\n+#endif /* ALTERNATES_H */\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex 2da71db107..27463c8fc5 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -11,6 +11,7 @@\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"lockfile.h\"\n+#include \"alternates.h\"\n #include \"parse-options.h\"\n #include \"fetch-pack.h\"\n #include \"refs.h\"\ndiff --git a/builtin/count-objects.c b/builtin/count-objects.c\nindex e340b3e3c3..805803fedd 100644\n--- a/builtin/count-objects.c\n+++ b/builtin/count-objects.c\n@@ -8,6 +8,7 @@\n #include \"config.h\"\n #include \"dir.h\"\n #include \"repository.h\"\n+#include \"alternates.h\"\n #include \"object-store.h\"\n #include \"builtin.h\"\n #include \"parse-options.h\"\ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex 0e78f4ba72..571aa51579 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -2,6 +2,7 @@\n #include \"cache.h\"\n #include \"repository.h\"\n #include \"config.h\"\n+#include \"alternates.h\"\n #include \"object-store.h\"\n #include \"commit.h\"\n #include \"tree.h\"\n@@ -696,7 +697,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)\n \t\tfsck_object_dir(get_object_directory());\n \n \t\tprepare_alt_odb(the_repository);\n-\t\tfor (alt = the_repository->objects.alt_odb_list;\n+\t\tfor (alt = the_repository->objects.alt_odb.list;\n \t\t\t\talt; alt = alt->next)\n \t\t\tfsck_object_dir(alt->path);\n \ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex 3ca4ac80d8..1c71dff341 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -6,6 +6,7 @@\n #include \"cache.h\"\n #include \"repository.h\"\n #include \"config.h\"\n+#include \"alternates.h\"\n #include \"blob.h\"\n #include \"tree.h\"\n #include \"commit.h\"\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex 8005adbf3d..10024c2fa2 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -2,6 +2,7 @@\n #include \"repository.h\"\n #include \"cache.h\"\n #include \"config.h\"\n+#include \"alternates.h\"\n #include \"parse-options.h\"\n #include \"quote.h\"\n #include \"pathspec.h\"\ndiff --git a/cache.h b/cache.h\nindex 3410a93737..b002c9a96d 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1564,58 +1564,6 @@ extern int has_dirs_only_path(const char *name, int len, int prefix_len);\n extern void schedule_dir_for_removal(const char *name, int len);\n extern void remove_scheduled_dirs(void);\n \n-struct alternate_object_database {\n-\tstruct alternate_object_database *next;\n-\n-\t/* see alt_scratch_buf() */\n-\tstruct strbuf scratch;\n-\tsize_t base_len;\n-\n-\t/*\n-\t * Used to store the results of readdir(3) calls when searching\n-\t * for unique abbreviated hashes.  This cache is never\n-\t * invalidated, thus it's racy and not necessarily accurate.\n-\t * That's fine for its purpose; don't use it for tasks requiring\n-\t * greater accuracy!\n-\t */\n-\tchar loose_objects_subdir_seen[256];\n-\tstruct oid_array loose_objects_cache;\n-\n-\t/*\n-\t * Path to the alternate object database, relative to the\n-\t * current working directory.\n-\t */\n-\tchar path[FLEX_ARRAY];\n-};\n-extern char *compute_alternate_path(const char *path, struct strbuf *err);\n-\n-/*\n- * Allocate a \"struct alternate_object_database\" but do _not_ actually\n- * add it to the list of alternates.\n- */\n-struct alternate_object_database *alloc_alt_odb(const char *dir);\n-\n-/*\n- * Add the directory to the on-disk alternates file; the new entry will also\n- * take effect in the current process.\n- */\n-extern void add_to_alternates_file(const char *dir);\n-\n-/*\n- * Add the directory to the in-memory list of alternates (along with any\n- * recursive alternates it points to), but do not modify the on-disk alternates\n- * file.\n- */\n-extern void add_to_alternates_memory(const char *dir);\n-\n-/*\n- * Returns a scratch strbuf pre-filled with the alternate object directory,\n- * including a trailing slash, which can be used to access paths in the\n- * alternate. Always use this over direct access to alt->scratch, as it\n- * cleans up any previous use of the scratch buffer.\n- */\n-extern struct strbuf *alt_scratch_buf(struct alternate_object_database *alt);\n-\n struct pack_window {\n \tstruct pack_window *next;\n \tunsigned char *base;\ndiff --git a/object-store.h b/object-store.h\nindex 298e34e978..967dd8af26 100644\n--- a/object-store.h\n+++ b/object-store.h\n@@ -4,6 +4,7 @@\n #include \"cache.h\"\n #include \"mru.h\"\n #include \"replace-object.h\"\n+#include \"alternates.h\"\n \n struct object_store {\n \tstruct packed_git *packed_git;\n@@ -14,8 +15,11 @@ struct object_store {\n \t */\n \tstruct mru packed_git_mru;\n \n-\tstruct alternate_object_database *alt_odb_list;\n-\tstruct alternate_object_database **alt_odb_tail;\n+\t/*\n+\t * Additional object databases to fall back on when an object does not\n+\t * exist in the current one (see --reference in git-clone(1)).\n+\t */\n+\tstruct alternates alt_odb;\n \n \t/*\n \t * Objects that should be substituted by other objects\n@@ -37,7 +41,8 @@ struct object_store {\n \t */\n \tunsigned packed_git_initialized : 1;\n };\n-#define OBJECT_STORE_INIT { NULL, MRU_INIT, NULL, NULL, REPLACE_OBJECTS_INIT, 0, 0, 0 }\n+#define OBJECT_STORE_INIT \\\n+\t{ NULL, MRU_INIT, ALTERNATES_INIT, REPLACE_OBJECTS_INIT, 0, 0, 0 }\n \n struct packed_git {\n \tstruct packed_git *next;\n@@ -70,9 +75,4 @@ struct packed_git {\n extern const char *sha1_file_name(struct repository *r, const unsigned char *sha1);\n extern void *map_sha1_file(struct repository *r, const unsigned char *sha1, unsigned long *size);\n \n-extern void prepare_alt_odb(struct repository *r);\n-\n-typedef int alt_odb_fn(struct alternate_object_database *, void *);\n-extern int foreach_alt_odb(struct repository *r, alt_odb_fn, void*);\n-\n #endif /* OBJECT_STORE_H */\ndiff --git a/packfile.c b/packfile.c\nindex 0ca13a4ed7..a7504debe5 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -2,6 +2,7 @@\n #include \"mru.h\"\n #include \"pack.h\"\n #include \"repository.h\"\n+#include \"alternates.h\"\n #include \"dir.h\"\n #include \"mergesort.h\"\n #include \"packfile.h\"\n@@ -880,7 +881,7 @@ void prepare_packed_git(struct repository *r)\n \t\treturn;\n \tprepare_packed_git_one(r, r->objectdir, 1);\n \tprepare_alt_odb(r);\n-\tfor (alt = r->objects.alt_odb_list; alt; alt = alt->next)\n+\tfor (alt = r->objects.alt_odb.list; alt; alt = alt->next)\n \t\tprepare_packed_git_one(r, alt->path, 0);\n \trearrange_packed_git(r);\n \tprepare_packed_git_mru(r);\ndiff --git a/sha1_file.c b/sha1_file.c\nindex a5dcb76d96..84501d66e9 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -10,6 +10,7 @@\n #include \"config.h\"\n #include \"string-list.h\"\n #include \"lockfile.h\"\n+#include \"alternates.h\"\n #include \"delta.h\"\n #include \"pack.h\"\n #include \"blob.h\"\n@@ -371,7 +372,7 @@ static int alt_odb_usable(struct repository *r, struct strbuf *path,\n \t * Prevent the common mistake of listing the same\n \t * thing twice, or object directory itself.\n \t */\n-\tfor (alt = r->objects.alt_odb_list; alt; alt = alt->next) {\n+\tfor (alt = r->objects.alt_odb.list; alt; alt = alt->next) {\n \t\tif (!fspathcmp(path->buf, alt->path))\n \t\t\treturn 0;\n \t}\n@@ -384,7 +385,7 @@ static int alt_odb_usable(struct repository *r, struct strbuf *path,\n /*\n  * Prepare alternate object database registry.\n  *\n- * The variable alt_odb_list points at the list of struct\n+ * The variable objects.alt_odb.list points at the list of struct\n  * alternate_object_database.  The elements on this list come from\n  * non-empty elements from colon separated ALTERNATE_DB_ENVIRONMENT\n  * environment variable, and $GIT_OBJECT_DIRECTORY/info/alternates,\n@@ -433,8 +434,8 @@ static int link_alt_odb_entry(struct repository *r, const char *entry,\n \tent = alloc_alt_odb(pathbuf.buf);\n \n \t/* add the alternate entry */\n-\t*r->objects.alt_odb_tail = ent;\n-\tr->objects.alt_odb_tail = &(ent->next);\n+\t*r->objects.alt_odb.tail = ent;\n+\tr->objects.alt_odb.tail = &(ent->next);\n \tent->next = NULL;\n \n \t/* recursively add alternates */\n@@ -571,7 +572,7 @@ void add_to_alternates_file(const char *reference)\n \t\tfprintf_or_die(out, \"%s\\n\", reference);\n \t\tif (commit_lock_file(&lock))\n \t\t\tdie_errno(\"unable to move new alternates file into place\");\n-\t\tif (the_repository->objects.alt_odb_tail)\n+\t\tif (the_repository->objects.alt_odb.tail)\n \t\t\tlink_alt_odb_entries(the_repository, reference,\n \t\t\t\t\t     '\\n', NULL, 0);\n \t}\n@@ -671,7 +672,7 @@ int foreach_alt_odb(struct repository *r, alt_odb_fn fn, void *cb)\n \tint ret = 0;\n \n \tprepare_alt_odb(r);\n-\tfor (ent = r->objects.alt_odb_list; ent; ent = ent->next) {\n+\tfor (ent = r->objects.alt_odb.list; ent; ent = ent->next) {\n \t\tret = fn(ent, cb);\n \t\tif (ret)\n \t\t\tbreak;\n@@ -681,10 +682,10 @@ int foreach_alt_odb(struct repository *r, alt_odb_fn fn, void *cb)\n \n void prepare_alt_odb(struct repository *r)\n {\n-\tif (r->objects.alt_odb_tail)\n+\tif (r->objects.alt_odb.tail)\n \t\treturn;\n \n-\tr->objects.alt_odb_tail = &r->objects.alt_odb_list;\n+\tr->objects.alt_odb.tail = &r->objects.alt_odb.list;\n \n \tif (!r->ignore_env) {\n \t\tconst char *alt = getenv(ALTERNATE_DB_ENVIRONMENT);\n@@ -737,7 +738,7 @@ static int check_and_freshen_nonlocal(const unsigned char *sha1, int freshen)\n {\n \tstruct alternate_object_database *alt;\n \tprepare_alt_odb(the_repository);\n-\tfor (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next) {\n+\tfor (alt = the_repository->objects.alt_odb.list; alt; alt = alt->next) {\n \t\tconst char *path = alt_sha1_path(alt, sha1);\n \t\tif (check_and_freshen_file(path, freshen))\n \t\t\treturn 1;\n@@ -893,7 +894,7 @@ static int stat_sha1_file(struct repository *r, const unsigned char *sha1,\n \n \tprepare_alt_odb(r);\n \terrno = ENOENT;\n-\tfor (alt = r->objects.alt_odb_list; alt; alt = alt->next) {\n+\tfor (alt = r->objects.alt_odb.list; alt; alt = alt->next) {\n \t\t*path = alt_sha1_path(alt, sha1);\n \t\tif (!lstat(*path, st))\n \t\t\treturn 0;\n@@ -920,7 +921,7 @@ static int open_sha1_file(struct repository *r,\n \tmost_interesting_errno = errno;\n \n \tprepare_alt_odb(r);\n-\tfor (alt = r->objects.alt_odb_list; alt; alt = alt->next) {\n+\tfor (alt = r->objects.alt_odb.list; alt; alt = alt->next) {\n \t\t*path = alt_sha1_path(alt, sha1);\n \t\tfd = git_open(*path);\n \t\tif (fd >= 0)\ndiff --git a/sha1_name.c b/sha1_name.c\nindex d3769713ea..363f7e1d4d 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -1,5 +1,6 @@\n #include \"cache.h\"\n #include \"config.h\"\n+#include \"alternates.h\"\n #include \"tag.h\"\n #include \"commit.h\"\n #include \"tree.h\"\n@@ -106,7 +107,7 @@ static void find_short_object_filename(struct disambiguate_state *ds)\n \t\t */\n \t\tfakeent = alloc_alt_odb(get_object_directory());\n \t}\n-\tfakeent->next = the_repository->objects.alt_odb_list;\n+\tfakeent->next = the_repository->objects.alt_odb.list;\n \n \tfor (alt = fakeent; alt && !ds->ambiguous; alt = alt->next) {\n \t\tint pos;\ndiff --git a/submodule.c b/submodule.c\nindex 2967704317..f7736ec4b5 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -5,6 +5,7 @@\n #include \"config.h\"\n #include \"submodule-config.h\"\n #include \"submodule.h\"\n+#include \"alternates.h\"\n #include \"dir.h\"\n #include \"diff.h\"\n #include \"commit.h\"\ndiff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c\nindex 7120634b04..4b96dfe12f 100644\n--- a/t/helper/test-ref-store.c\n+++ b/t/helper/test-ref-store.c\n@@ -1,4 +1,5 @@\n #include \"cache.h\"\n+#include \"alternates.h\"\n #include \"refs.h\"\n #include \"worktree.h\"\n \ndiff --git a/tmp-objdir.c b/tmp-objdir.c\nindex b2d9280f10..bf34315adf 100644\n--- a/tmp-objdir.c\n+++ b/tmp-objdir.c\n@@ -1,5 +1,6 @@\n #include \"cache.h\"\n #include \"tmp-objdir.h\"\n+#include \"alternates.h\"\n #include \"dir.h\"\n #include \"sigchain.h\"\n #include \"string-list.h\"\ndiff --git a/transport.c b/transport.c\nindex 3f97fbe7c5..00f90d7b20 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -2,6 +2,7 @@\n #include \"config.h\"\n #include \"transport.h\"\n #include \"repository.h\"\n+#include \"alternates.h\"\n #include \"run-command.h\"\n #include \"pkt-line.h\"\n #include \"fetch-pack.h\"\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338309","messageId":"20180205235735.216710-23-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 043/194] object-store: move loose object functions to new loose-object.h","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:04Z","receivedAt":"2018-02-06T00:03:44Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nThis should make these functions easier to find and cache.h less\noverwhelming to read.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n builtin/cat-file.c      |  1 +\n builtin/count-objects.c |  1 +\n builtin/fsck.c          |  1 +\n builtin/pack-objects.c  |  1 +\n builtin/prune-packed.c  |  1 +\n builtin/prune.c         |  1 +\n cache.h                 | 75 ++--------------------------------------\n http-walker.c           |  1 +\n http.c                  |  1 +\n loose-object.h          | 91 +++++++++++++++++++++++++++++++++++++++++++++++++\n object-store.h          |  7 ----\n reachable.c             |  1 +\n sha1_file.c             |  1 +\n sha1_name.c             |  1 +\n 14 files changed, 105 insertions(+), 79 deletions(-)\n create mode 100644 loose-object.h\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 9d18efeb7c..fdc70aa419 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -9,6 +9,7 @@\n #include \"diff.h\"\n #include \"parse-options.h\"\n #include \"userdiff.h\"\n+#include \"loose-object.h\"\n #include \"streaming.h\"\n #include \"tree-walk.h\"\n #include \"sha1-array.h\"\ndiff --git a/builtin/count-objects.c b/builtin/count-objects.c\nindex 805803fedd..34f2bfa44e 100644\n--- a/builtin/count-objects.c\n+++ b/builtin/count-objects.c\n@@ -10,6 +10,7 @@\n #include \"repository.h\"\n #include \"alternates.h\"\n #include \"object-store.h\"\n+#include \"loose-object.h\"\n #include \"builtin.h\"\n #include \"parse-options.h\"\n #include \"quote.h\"\ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex 571aa51579..920cc50923 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -4,6 +4,7 @@\n #include \"config.h\"\n #include \"alternates.h\"\n #include \"object-store.h\"\n+#include \"loose-object.h\"\n #include \"commit.h\"\n #include \"tree.h\"\n #include \"blob.h\"\ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex d42df2a2b9..b998e139d1 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -3,6 +3,7 @@\n #include \"repository.h\"\n #include \"config.h\"\n #include \"object-store.h\"\n+#include \"loose-object.h\"\n #include \"attr.h\"\n #include \"object.h\"\n #include \"blob.h\"\ndiff --git a/builtin/prune-packed.c b/builtin/prune-packed.c\nindex 419238171d..2da1573359 100644\n--- a/builtin/prune-packed.c\n+++ b/builtin/prune-packed.c\n@@ -2,6 +2,7 @@\n #include \"cache.h\"\n #include \"progress.h\"\n #include \"parse-options.h\"\n+#include \"loose-object.h\"\n #include \"packfile.h\"\n \n static const char * const prune_packed_usage[] = {\ndiff --git a/builtin/prune.c b/builtin/prune.c\nindex d2fdae680a..52091f299e 100644\n--- a/builtin/prune.c\n+++ b/builtin/prune.c\n@@ -3,6 +3,7 @@\n #include \"diff.h\"\n #include \"revision.h\"\n #include \"builtin.h\"\n+#include \"loose-object.h\"\n #include \"reachable.h\"\n #include \"parse-options.h\"\n #include \"progress.h\"\ndiff --git a/cache.h b/cache.h\nindex b002c9a96d..7be9a8ad27 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1244,19 +1244,6 @@ extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned l\n \n extern int finalize_object_file(const char *tmpfile, const char *filename);\n \n-/*\n- * Open the loose object at path, check its sha1, and return the contents,\n- * type, and size. If the object is a blob, then \"contents\" may return NULL,\n- * to allow streaming of large blobs.\n- *\n- * Returns 0 on success, negative on error (details may be written to stderr).\n- */\n-int read_loose_object(const char *path,\n-\t\t      const unsigned char *expected_sha1,\n-\t\t      enum object_type *type,\n-\t\t      unsigned long *size,\n-\t\t      void **contents);\n-\n /*\n  * Convenience for sha1_object_info_extended() with a NULL struct\n  * object_info. OBJECT_INFO_SKIP_CACHED is automatically set; pass\n@@ -1272,13 +1259,6 @@ static inline int has_sha1_file(const unsigned char *sha1)\n extern int has_object_file(const struct object_id *oid);\n extern int has_object_file_with_flags(const struct object_id *oid, int flags);\n \n-/*\n- * Return true iff an alternate object database has a loose object\n- * with the specified name.  This function does not respect replace\n- * references.\n- */\n-extern int has_loose_object_nonlocal(const unsigned char *sha1);\n-\n extern void assert_sha1_type(const unsigned char *sha1, enum object_type expect);\n \n /* Helper to check and \"touch\" a file */\n@@ -1595,60 +1575,11 @@ extern int odb_mkstemp(struct strbuf *template, const char *pattern);\n extern int odb_pack_keep(const char *name);\n \n /*\n- * Iterate over the files in the loose-object parts of the object\n- * directory \"path\", triggering the following callbacks:\n- *\n- *  - loose_object is called for each loose object we find.\n- *\n- *  - loose_cruft is called for any files that do not appear to be\n- *    loose objects. Note that we only look in the loose object\n- *    directories \"objects/[0-9a-f]{2}/\", so we will not report\n- *    \"objects/foobar\" as cruft.\n- *\n- *  - loose_subdir is called for each top-level hashed subdirectory\n- *    of the object directory (e.g., \"$OBJDIR/f0\"). It is called\n- *    after the objects in the directory are processed.\n- *\n- * Any callback that is NULL will be ignored. Callbacks returning non-zero\n- * will end the iteration.\n- *\n- * In the \"buf\" variant, \"path\" is a strbuf which will also be used as a\n- * scratch buffer, but restored to its original contents before\n- * the function returns.\n- */\n-typedef int each_loose_object_fn(const struct object_id *oid,\n-\t\t\t\t const char *path,\n-\t\t\t\t void *data);\n-typedef int each_loose_cruft_fn(const char *basename,\n-\t\t\t\tconst char *path,\n-\t\t\t\tvoid *data);\n-typedef int each_loose_subdir_fn(unsigned int nr,\n-\t\t\t\t const char *path,\n-\t\t\t\t void *data);\n-int for_each_file_in_obj_subdir(unsigned int subdir_nr,\n-\t\t\t\tstruct strbuf *path,\n-\t\t\t\teach_loose_object_fn obj_cb,\n-\t\t\t\teach_loose_cruft_fn cruft_cb,\n-\t\t\t\teach_loose_subdir_fn subdir_cb,\n-\t\t\t\tvoid *data);\n-int for_each_loose_file_in_objdir(const char *path,\n-\t\t\t\t  each_loose_object_fn obj_cb,\n-\t\t\t\t  each_loose_cruft_fn cruft_cb,\n-\t\t\t\t  each_loose_subdir_fn subdir_cb,\n-\t\t\t\t  void *data);\n-int for_each_loose_file_in_objdir_buf(struct strbuf *path,\n-\t\t\t\t      each_loose_object_fn obj_cb,\n-\t\t\t\t      each_loose_cruft_fn cruft_cb,\n-\t\t\t\t      each_loose_subdir_fn subdir_cb,\n-\t\t\t\t      void *data);\n-\n-/*\n- * Iterate over loose objects in both the local\n- * repository and any alternates repositories (unless the\n- * LOCAL_ONLY flag is set).\n+ * Flag for for_each_packed_object and for_each_loose_object to only iterate\n+ * over objects in the local repository, and not any alternates (see\n+ * alternates.h).\n  */\n #define FOR_EACH_OBJECT_LOCAL_ONLY 0x1\n-extern int for_each_loose_object(each_loose_object_fn, void *, unsigned flags);\n \n struct object_info {\n \t/* Request */\ndiff --git a/http-walker.c b/http-walker.c\nindex 96873bdfed..34594165b1 100644\n--- a/http-walker.c\n+++ b/http-walker.c\n@@ -6,6 +6,7 @@\n #include \"list.h\"\n #include \"transport.h\"\n #include \"object-store.h\"\n+#include \"loose-object.h\"\n #include \"packfile.h\"\n \n struct alt_base {\ndiff --git a/http.c b/http.c\nindex ad57476635..e04eca601b 100644\n--- a/http.c\n+++ b/http.c\n@@ -3,6 +3,7 @@\n #include \"repository.h\"\n #include \"config.h\"\n #include \"object-store.h\"\n+#include \"loose-object.h\"\n #include \"pack.h\"\n #include \"sideband.h\"\n #include \"run-command.h\"\ndiff --git a/loose-object.h b/loose-object.h\nnew file mode 100644\nindex 0000000000..7d721ae4f0\n--- /dev/null\n+++ b/loose-object.h\n@@ -0,0 +1,91 @@\n+#ifndef LOOSE_OBJECT_H\n+#define LOOSE_OBJECT_H\n+\n+#include \"cache.h\"\n+#include \"strbuf.h\"\n+#include \"repository.h\"\n+\n+/*\n+ * Open the loose object at path, check its sha1, and return the contents,\n+ * type, and size. If the object is a blob, then \"contents\" may return NULL,\n+ * to allow streaming of large blobs.\n+ *\n+ * Returns 0 on success, negative on error (details may be written to stderr).\n+ */\n+int read_loose_object(const char *path,\n+\t\t      const unsigned char *expected_sha1,\n+\t\t      enum object_type *type,\n+\t\t      unsigned long *size,\n+\t\t      void **contents);\n+\n+/*\n+ * Return true iff an alternate object database has a loose object\n+ * with the specified name.  This function does not respect replace\n+ * references.\n+ */\n+extern int has_loose_object_nonlocal(const unsigned char *sha1);\n+\n+/*\n+ * Iterate over the files in the loose-object parts of the object\n+ * directory \"path\", triggering the following callbacks:\n+ *\n+ *  - loose_object is called for each loose object we find.\n+ *\n+ *  - loose_cruft is called for any files that do not appear to be\n+ *    loose objects. Note that we only look in the loose object\n+ *    directories \"objects/[0-9a-f]{2}/\", so we will not report\n+ *    \"objects/foobar\" as cruft.\n+ *\n+ *  - loose_subdir is called for each top-level hashed subdirectory\n+ *    of the object directory (e.g., \"$OBJDIR/f0\"). It is called\n+ *    after the objects in the directory are processed.\n+ *\n+ * Any callback that is NULL will be ignored. Callbacks returning non-zero\n+ * will end the iteration.\n+ *\n+ * In the \"buf\" variant, \"path\" is a strbuf which will also be used as a\n+ * scratch buffer, but restored to its original contents before\n+ * the function returns.\n+ */\n+typedef int each_loose_object_fn(const struct object_id *oid,\n+\t\t\t\t const char *path,\n+\t\t\t\t void *data);\n+typedef int each_loose_cruft_fn(const char *basename,\n+\t\t\t\tconst char *path,\n+\t\t\t\tvoid *data);\n+typedef int each_loose_subdir_fn(unsigned int nr,\n+\t\t\t\t const char *path,\n+\t\t\t\t void *data);\n+int for_each_file_in_obj_subdir(unsigned int subdir_nr,\n+\t\t\t\tstruct strbuf *path,\n+\t\t\t\teach_loose_object_fn obj_cb,\n+\t\t\t\teach_loose_cruft_fn cruft_cb,\n+\t\t\t\teach_loose_subdir_fn subdir_cb,\n+\t\t\t\tvoid *data);\n+int for_each_loose_file_in_objdir(const char *path,\n+\t\t\t\t  each_loose_object_fn obj_cb,\n+\t\t\t\t  each_loose_cruft_fn cruft_cb,\n+\t\t\t\t  each_loose_subdir_fn subdir_cb,\n+\t\t\t\t  void *data);\n+int for_each_loose_file_in_objdir_buf(struct strbuf *path,\n+\t\t\t\t      each_loose_object_fn obj_cb,\n+\t\t\t\t      each_loose_cruft_fn cruft_cb,\n+\t\t\t\t      each_loose_subdir_fn subdir_cb,\n+\t\t\t\t      void *data);\n+\n+/*\n+ * Iterate over loose objects in both the local\n+ * repository and any alternates repositories (unless the\n+ * FOR_EACH_OBJECT_LOCAL_ONLY flag, defined in cache.h, is set).\n+ */\n+extern int for_each_loose_object(each_loose_object_fn, void *, unsigned flags);\n+\n+/*\n+ * Return the name of the file in a repository's local object database\n+ * that would be used to store a loose object with the specified sha1.\n+ * The return value is a pointer to a statically allocated buffer that\n+ * is overwritten each time the function is called.\n+ */\n+extern const char *sha1_file_name(struct repository *r, const unsigned char *sha1);\n+\n+#endif\ndiff --git a/object-store.h b/object-store.h\nindex 967dd8af26..7a372baa79 100644\n--- a/object-store.h\n+++ b/object-store.h\n@@ -66,13 +66,6 @@ struct packed_git {\n \tchar pack_name[FLEX_ARRAY]; /* more */\n };\n \n-/*\n- * Return the name of the file in a repository's local object database\n- * that would be used to store a loose object with the specified sha1.\n- * The return value is a pointer to a statically allocated buffer that\n- * is overwritten each time the function is called.\n- */\n-extern const char *sha1_file_name(struct repository *r, const unsigned char *sha1);\n extern void *map_sha1_file(struct repository *r, const unsigned char *sha1, unsigned long *size);\n \n #endif /* OBJECT_STORE_H */\ndiff --git a/reachable.c b/reachable.c\nindex 59ed16ba76..ac5224b9a5 100644\n--- a/reachable.c\n+++ b/reachable.c\n@@ -1,6 +1,7 @@\n #include \"cache.h\"\n #include \"refs.h\"\n #include \"object-store.h\"\n+#include \"loose-object.h\"\n #include \"tag.h\"\n #include \"commit.h\"\n #include \"blob.h\"\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 84501d66e9..2584465e9c 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -25,6 +25,7 @@\n #include \"bulk-checkin.h\"\n #include \"repository.h\"\n #include \"object-store.h\"\n+#include \"loose-object.h\"\n #include \"streaming.h\"\n #include \"path.h\"\n #include \"dir.h\"\ndiff --git a/sha1_name.c b/sha1_name.c\nindex 363f7e1d4d..03ce2ff7f2 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -1,6 +1,7 @@\n #include \"cache.h\"\n #include \"config.h\"\n #include \"alternates.h\"\n+#include \"loose-object.h\"\n #include \"tag.h\"\n #include \"commit.h\"\n #include \"tree.h\"\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338310","messageId":"20180205235735.216710-24-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 044/194] pack: move struct pack_window and pack_entry to packfile.h","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:05Z","receivedAt":"2018-02-06T00:04:05Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nThis should make these functions easier to find and cache.h less\noverwhelming to read.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n builtin/pack-objects.c |  1 +\n cache.h                | 15 ---------------\n object-store.h         |  1 +\n pack.h                 |  1 +\n packfile.c             |  1 +\n packfile.h             | 19 +++++++++++++++++++\n 6 files changed, 23 insertions(+), 15 deletions(-)\n\ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex b998e139d1..7cb73c29ac 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -10,6 +10,7 @@\n #include \"commit.h\"\n #include \"tag.h\"\n #include \"tree.h\"\n+#include \"packfile.h\"\n #include \"delta.h\"\n #include \"pack.h\"\n #include \"pack-revindex.h\"\ndiff --git a/cache.h b/cache.h\nindex 7be9a8ad27..c66e59733d 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1544,21 +1544,6 @@ extern int has_dirs_only_path(const char *name, int len, int prefix_len);\n extern void schedule_dir_for_removal(const char *name, int len);\n extern void remove_scheduled_dirs(void);\n \n-struct pack_window {\n-\tstruct pack_window *next;\n-\tunsigned char *base;\n-\toff_t offset;\n-\tsize_t len;\n-\tunsigned int last_used;\n-\tunsigned int inuse_cnt;\n-};\n-\n-struct pack_entry {\n-\toff_t offset;\n-\tunsigned char sha1[20];\n-\tstruct packed_git *p;\n-};\n-\n /*\n  * Create a temporary file rooted in the object database directory, or\n  * die on failure. The filename is taken from \"pattern\", which should have the\ndiff --git a/object-store.h b/object-store.h\nindex 7a372baa79..3475e22021 100644\n--- a/object-store.h\n+++ b/object-store.h\n@@ -5,6 +5,7 @@\n #include \"mru.h\"\n #include \"replace-object.h\"\n #include \"alternates.h\"\n+#include \"packfile.h\"\n \n struct object_store {\n \tstruct packed_git *packed_git;\ndiff --git a/pack.h b/pack.h\nindex 8294341af1..c0ea2b6499 100644\n--- a/pack.h\n+++ b/pack.h\n@@ -2,6 +2,7 @@\n #define PACK_H\n \n #include \"object.h\"\n+#include \"packfile.h\"\n #include \"csum-file.h\"\n \n /*\ndiff --git a/packfile.c b/packfile.c\nindex a7504debe5..b73814f2ce 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -1,5 +1,6 @@\n #include \"cache.h\"\n #include \"mru.h\"\n+#include \"packfile.h\"\n #include \"pack.h\"\n #include \"repository.h\"\n #include \"alternates.h\"\ndiff --git a/packfile.h b/packfile.h\nindex b3138816e7..1163fc7bb4 100644\n--- a/packfile.h\n+++ b/packfile.h\n@@ -1,6 +1,25 @@\n #ifndef PACKFILE_H\n #define PACKFILE_H\n \n+/* in cache.h */\n+enum object_type;\n+struct object_info;\n+\n+struct pack_window {\n+\tstruct pack_window *next;\n+\tunsigned char *base;\n+\toff_t offset;\n+\tsize_t len;\n+\tunsigned int last_used;\n+\tunsigned int inuse_cnt;\n+};\n+\n+struct pack_entry {\n+\toff_t offset;\n+\tunsigned char sha1[20];\n+\tstruct packed_git *p;\n+};\n+\n /*\n  * Generate the filename to be used for a pack file with checksum \"sha1\" and\n  * extension \"ext\". The result is written into the strbuf \"buf\", overwriting\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338311","messageId":"20180205235735.216710-25-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 045/194] object-store: move object access functions to object-store.h","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:06Z","receivedAt":"2018-02-06T00:04:07Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"This should make these functions easier to find and cache.h less\noverwhelming to read.\n\nIn particular, this moves:\n- read_sha1_file\n- sha1_object_info\n- write_sha1_file\n- sha1_object_info\n\nAs a result, most of the codebase needs to #include object-store.h.\nIn this patch the #include is only added to files that would fail to\ncompile otherwise.  It would be better to #include wherever\nidentifiers from the header are used.  That can happen later when we\nhave better tooling for it.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n apply.c                  |   1 +\n archive-tar.c            |   1 +\n archive-zip.c            |   1 +\n archive.c                |   1 +\n blame.c                  |   1 +\n builtin/checkout.c       |   1 +\n builtin/clone.c          |   1 +\n builtin/commit-tree.c    |   1 +\n builtin/difftool.c       |   1 +\n builtin/fast-export.c    |   1 +\n builtin/fetch.c          |   1 +\n builtin/fmt-merge-msg.c  |   1 +\n builtin/hash-object.c    |   1 +\n builtin/log.c            |   1 +\n builtin/ls-tree.c        |   1 +\n builtin/merge-tree.c     |   1 +\n builtin/mktag.c          |   1 +\n builtin/mktree.c         |   1 +\n builtin/notes.c          |   1 +\n builtin/reflog.c         |   1 +\n builtin/remote.c         |   1 +\n builtin/replace.c        |   1 +\n builtin/rev-list.c       |   1 +\n builtin/show-ref.c       |   1 +\n builtin/tag.c            |   1 +\n builtin/unpack-file.c    |   1 +\n builtin/unpack-objects.c |   1 +\n builtin/verify-commit.c  |   1 +\n bundle.c                 |   1 +\n cache-tree.c             |   1 +\n cache.h                  | 102 ------------------------------------------\n combine-diff.c           |   1 +\n commit.c                 |   1 +\n convert.c                |   1 +\n diff.c                   |   1 +\n diffcore-rename.c        |   1 +\n dir.c                    |   1 +\n entry.c                  |   1 +\n fsck.c                   |   1 +\n grep.c                   |   1 +\n log-tree.c               |   1 +\n mailmap.c                |   1 +\n match-trees.c            |   1 +\n merge-blobs.c            |   1 +\n merge-recursive.c        |   1 +\n notes-cache.c            |   1 +\n notes-merge.c            |   1 +\n notes.c                  |   1 +\n object-store.h           | 112 ++++++++++++++++++++++++++++++++++++++++++++++-\n object.c                 |   1 +\n pack-bitmap-write.c      |   1 +\n packfile.h               |   3 ++\n read-cache.c             |   1 +\n ref-filter.c             |   1 +\n refs.c                   |   1 +\n remote-testsvn.c         |   1 +\n remote.c                 |   1 +\n rerere.c                 |   1 +\n revision.c               |   1 +\n send-pack.c              |   1 +\n sequencer.c              |   1 +\n shallow.c                |   1 +\n tag.c                    |   1 +\n tree-walk.c              |   1 +\n tree.c                   |   1 +\n upload-pack.c            |   1 +\n walker.c                 |   1 +\n xdiff-interface.c        |   1 +\n 68 files changed, 178 insertions(+), 104 deletions(-)\n\ndiff --git a/apply.c b/apply.c\nindex 321a9fa68d..de4440cd2a 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -9,6 +9,7 @@\n \n #include \"cache.h\"\n #include \"config.h\"\n+#include \"object-store.h\"\n #include \"blob.h\"\n #include \"delta.h\"\n #include \"diff.h\"\ndiff --git a/archive-tar.c b/archive-tar.c\nindex c6ed96ee74..909347c108 100644\n--- a/archive-tar.c\n+++ b/archive-tar.c\n@@ -5,6 +5,7 @@\n #include \"config.h\"\n #include \"tar.h\"\n #include \"archive.h\"\n+#include \"object-store.h\"\n #include \"streaming.h\"\n #include \"run-command.h\"\n \ndiff --git a/archive-zip.c b/archive-zip.c\nindex e8913e5a26..233fed3a61 100644\n--- a/archive-zip.c\n+++ b/archive-zip.c\n@@ -6,6 +6,7 @@\n #include \"archive.h\"\n #include \"streaming.h\"\n #include \"utf8.h\"\n+#include \"object-store.h\"\n #include \"userdiff.h\"\n #include \"xdiff-interface.h\"\n \ndiff --git a/archive.c b/archive.c\nindex 0b7b62af0c..9b47041a6c 100644\n--- a/archive.c\n+++ b/archive.c\n@@ -1,6 +1,7 @@\n #include \"cache.h\"\n #include \"config.h\"\n #include \"refs.h\"\n+#include \"object-store.h\"\n #include \"commit.h\"\n #include \"tree-walk.h\"\n #include \"attr.h\"\ndiff --git a/blame.c b/blame.c\nindex 2893f3c103..61f0f6bb40 100644\n--- a/blame.c\n+++ b/blame.c\n@@ -1,5 +1,6 @@\n #include \"cache.h\"\n #include \"refs.h\"\n+#include \"object-store.h\"\n #include \"cache-tree.h\"\n #include \"mergesort.h\"\n #include \"diff.h\"\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex 8bdc927d3f..c7271ed43f 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -4,6 +4,7 @@\n #include \"lockfile.h\"\n #include \"parse-options.h\"\n #include \"refs.h\"\n+#include \"object-store.h\"\n #include \"commit.h\"\n #include \"tree.h\"\n #include \"tree-walk.h\"\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex 27463c8fc5..ecd71b9444 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -15,6 +15,7 @@\n #include \"parse-options.h\"\n #include \"fetch-pack.h\"\n #include \"refs.h\"\n+#include \"object-store.h\"\n #include \"tree.h\"\n #include \"tree-walk.h\"\n #include \"unpack-trees.h\"\ndiff --git a/builtin/commit-tree.c b/builtin/commit-tree.c\nindex 2177251e24..a54fb362ce 100644\n--- a/builtin/commit-tree.c\n+++ b/builtin/commit-tree.c\n@@ -5,6 +5,7 @@\n  */\n #include \"cache.h\"\n #include \"config.h\"\n+#include \"object-store.h\"\n #include \"commit.h\"\n #include \"tree.h\"\n #include \"builtin.h\"\ndiff --git a/builtin/difftool.c b/builtin/difftool.c\nindex bcc79d1888..d62094060d 100644\n--- a/builtin/difftool.c\n+++ b/builtin/difftool.c\n@@ -20,6 +20,7 @@\n #include \"argv-array.h\"\n #include \"strbuf.h\"\n #include \"lockfile.h\"\n+#include \"object-store.h\"\n #include \"dir.h\"\n \n static char *diff_gui_tool;\ndiff --git a/builtin/fast-export.c b/builtin/fast-export.c\nindex 796d0cd66c..f76b7bda79 100644\n--- a/builtin/fast-export.c\n+++ b/builtin/fast-export.c\n@@ -7,6 +7,7 @@\n #include \"cache.h\"\n #include \"config.h\"\n #include \"refs.h\"\n+#include \"object-store.h\"\n #include \"commit.h\"\n #include \"object.h\"\n #include \"tag.h\"\ndiff --git a/builtin/fetch.c b/builtin/fetch.c\nindex 7bbcd26faf..9b7202953b 100644\n--- a/builtin/fetch.c\n+++ b/builtin/fetch.c\n@@ -5,6 +5,7 @@\n #include \"config.h\"\n #include \"repository.h\"\n #include \"refs.h\"\n+#include \"object-store.h\"\n #include \"commit.h\"\n #include \"builtin.h\"\n #include \"string-list.h\"\ndiff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c\nindex 8e8a15ea4a..9dd5c85831 100644\n--- a/builtin/fmt-merge-msg.c\n+++ b/builtin/fmt-merge-msg.c\n@@ -2,6 +2,7 @@\n #include \"cache.h\"\n #include \"config.h\"\n #include \"refs.h\"\n+#include \"object-store.h\"\n #include \"commit.h\"\n #include \"diff.h\"\n #include \"revision.h\"\ndiff --git a/builtin/hash-object.c b/builtin/hash-object.c\nindex c532ff9320..956a798110 100644\n--- a/builtin/hash-object.c\n+++ b/builtin/hash-object.c\n@@ -6,6 +6,7 @@\n  */\n #include \"builtin.h\"\n #include \"config.h\"\n+#include \"object-store.h\"\n #include \"blob.h\"\n #include \"quote.h\"\n #include \"parse-options.h\"\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 14fdf39165..de723fffc6 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -7,6 +7,7 @@\n #include \"cache.h\"\n #include \"config.h\"\n #include \"refs.h\"\n+#include \"object-store.h\"\n #include \"color.h\"\n #include \"commit.h\"\n #include \"diff.h\"\ndiff --git a/builtin/ls-tree.c b/builtin/ls-tree.c\nindex ef965408e8..78fcced566 100644\n--- a/builtin/ls-tree.c\n+++ b/builtin/ls-tree.c\n@@ -5,6 +5,7 @@\n  */\n #include \"cache.h\"\n #include \"config.h\"\n+#include \"object-store.h\"\n #include \"blob.h\"\n #include \"tree.h\"\n #include \"commit.h\"\ndiff --git a/builtin/merge-tree.c b/builtin/merge-tree.c\nindex d01ddecf66..ba51ad55a8 100644\n--- a/builtin/merge-tree.c\n+++ b/builtin/merge-tree.c\n@@ -1,6 +1,7 @@\n #include \"builtin.h\"\n #include \"tree-walk.h\"\n #include \"xdiff-interface.h\"\n+#include \"object-store.h\"\n #include \"blob.h\"\n #include \"exec_cmd.h\"\n #include \"merge-blobs.h\"\ndiff --git a/builtin/mktag.c b/builtin/mktag.c\nindex 031b750f06..04eadc7b24 100644\n--- a/builtin/mktag.c\n+++ b/builtin/mktag.c\n@@ -1,5 +1,6 @@\n #include \"builtin.h\"\n #include \"tag.h\"\n+#include \"object-store.h\"\n \n /*\n  * A signature file has a very simple fixed format: four lines\ndiff --git a/builtin/mktree.c b/builtin/mktree.c\nindex da0fd8cd70..0f66946618 100644\n--- a/builtin/mktree.c\n+++ b/builtin/mktree.c\n@@ -7,6 +7,7 @@\n #include \"quote.h\"\n #include \"tree.h\"\n #include \"parse-options.h\"\n+#include \"object-store.h\"\n \n static struct treeent {\n \tunsigned mode;\ndiff --git a/builtin/notes.c b/builtin/notes.c\nindex 7c81761645..1bd3994caa 100644\n--- a/builtin/notes.c\n+++ b/builtin/notes.c\n@@ -11,6 +11,7 @@\n #include \"config.h\"\n #include \"builtin.h\"\n #include \"notes.h\"\n+#include \"object-store.h\"\n #include \"blob.h\"\n #include \"pretty.h\"\n #include \"refs.h\"\ndiff --git a/builtin/reflog.c b/builtin/reflog.c\nindex 2233725315..4b525c4448 100644\n--- a/builtin/reflog.c\n+++ b/builtin/reflog.c\n@@ -1,6 +1,7 @@\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"lockfile.h\"\n+#include \"object-store.h\"\n #include \"commit.h\"\n #include \"refs.h\"\n #include \"dir.h\"\ndiff --git a/builtin/remote.c b/builtin/remote.c\nindex d95bf904c3..7bd81bac6a 100644\n--- a/builtin/remote.c\n+++ b/builtin/remote.c\n@@ -7,6 +7,7 @@\n #include \"strbuf.h\"\n #include \"run-command.h\"\n #include \"refs.h\"\n+#include \"object-store.h\"\n #include \"argv-array.h\"\n \n static const char * const builtin_remote_usage[] = {\ndiff --git a/builtin/replace.c b/builtin/replace.c\nindex 10078ae371..ccde160228 100644\n--- a/builtin/replace.c\n+++ b/builtin/replace.c\n@@ -14,6 +14,7 @@\n #include \"refs.h\"\n #include \"parse-options.h\"\n #include \"run-command.h\"\n+#include \"object-store.h\"\n #include \"tag.h\"\n \n static const char * const git_replace_usage[] = {\ndiff --git a/builtin/rev-list.c b/builtin/rev-list.c\nindex d5345b6a2e..969efde30c 100644\n--- a/builtin/rev-list.c\n+++ b/builtin/rev-list.c\n@@ -6,6 +6,7 @@\n #include \"list-objects.h\"\n #include \"list-objects-filter.h\"\n #include \"list-objects-filter-options.h\"\n+#include \"object-store.h\"\n #include \"pack.h\"\n #include \"pack-bitmap.h\"\n #include \"builtin.h\"\ndiff --git a/builtin/show-ref.c b/builtin/show-ref.c\nindex 41e5e71cad..8f5827af62 100644\n--- a/builtin/show-ref.c\n+++ b/builtin/show-ref.c\n@@ -1,6 +1,7 @@\n #include \"builtin.h\"\n #include \"cache.h\"\n #include \"refs.h\"\n+#include \"object-store.h\"\n #include \"object.h\"\n #include \"tag.h\"\n #include \"string-list.h\"\ndiff --git a/builtin/tag.c b/builtin/tag.c\nindex a7e6a5b0f2..7ed3506fff 100644\n--- a/builtin/tag.c\n+++ b/builtin/tag.c\n@@ -10,6 +10,7 @@\n #include \"config.h\"\n #include \"builtin.h\"\n #include \"refs.h\"\n+#include \"object-store.h\"\n #include \"tag.h\"\n #include \"run-command.h\"\n #include \"parse-options.h\"\ndiff --git a/builtin/unpack-file.c b/builtin/unpack-file.c\nindex 32e0155577..b28e056c74 100644\n--- a/builtin/unpack-file.c\n+++ b/builtin/unpack-file.c\n@@ -1,5 +1,6 @@\n #include \"builtin.h\"\n #include \"config.h\"\n+#include \"object-store.h\"\n \n static char *create_temp_file(struct object_id *oid)\n {\ndiff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c\nindex 62ea264c46..6d03ea2670 100644\n--- a/builtin/unpack-objects.c\n+++ b/builtin/unpack-objects.c\n@@ -1,6 +1,7 @@\n #include \"builtin.h\"\n #include \"cache.h\"\n #include \"config.h\"\n+#include \"object-store.h\"\n #include \"object.h\"\n #include \"delta.h\"\n #include \"pack.h\"\ndiff --git a/builtin/verify-commit.c b/builtin/verify-commit.c\nindex ba38ac9b15..29f5e5507c 100644\n--- a/builtin/verify-commit.c\n+++ b/builtin/verify-commit.c\n@@ -8,6 +8,7 @@\n #include \"cache.h\"\n #include \"config.h\"\n #include \"builtin.h\"\n+#include \"object-store.h\"\n #include \"commit.h\"\n #include \"run-command.h\"\n #include <signal.h>\ndiff --git a/bundle.c b/bundle.c\nindex 93290962c9..d9376b7c77 100644\n--- a/bundle.c\n+++ b/bundle.c\n@@ -1,6 +1,7 @@\n #include \"cache.h\"\n #include \"lockfile.h\"\n #include \"bundle.h\"\n+#include \"object-store.h\"\n #include \"object.h\"\n #include \"commit.h\"\n #include \"diff.h\"\ndiff --git a/cache-tree.c b/cache-tree.c\nindex e03e72c34a..2a98b15b92 100644\n--- a/cache-tree.c\n+++ b/cache-tree.c\n@@ -3,6 +3,7 @@\n #include \"tree.h\"\n #include \"tree-walk.h\"\n #include \"cache-tree.h\"\n+#include \"object-store.h\"\n \n #ifndef DEBUG\n #define DEBUG 0\ndiff --git a/cache.h b/cache.h\nindex c66e59733d..22404de92b 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1201,40 +1201,6 @@ extern char *xdg_config_home(const char *filename);\n  */\n extern char *xdg_cache_home(const char *filename);\n \n-extern void *read_sha1_file_extended(const unsigned char *sha1,\n-\t\t\t\t     enum object_type *type,\n-\t\t\t\t     unsigned long *size, int lookup_replace);\n-static inline void *read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size)\n-{\n-\treturn read_sha1_file_extended(sha1, type, size, 1);\n-}\n-\n-/*\n- * This internal function is only declared here for the benefit of\n- * lookup_replace_object().  Please do not call it directly.\n- */\n-extern const unsigned char *do_lookup_replace_object(const unsigned char *sha1);\n-\n-/*\n- * If object sha1 should be replaced, return the replacement object's\n- * name (replaced recursively, if necessary).  The return value is\n- * either sha1 or a pointer to a permanently-allocated value.  When\n- * object replacement is suppressed, always return sha1.\n- */\n-static inline const unsigned char *lookup_replace_object(const unsigned char *sha1)\n-{\n-\tif (!check_replace_refs)\n-\t\treturn sha1;\n-\treturn do_lookup_replace_object(sha1);\n-}\n-\n-/* Read and unpack a sha1 file into memory, write memory to a sha1 file */\n-extern int sha1_object_info(const unsigned char *, unsigned long *);\n-extern int hash_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *sha1);\n-extern int write_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *return_sha1);\n-extern int hash_sha1_file_literally(const void *buf, unsigned long len, const char *type, struct object_id *oid, unsigned flags);\n-extern int pretend_sha1_file(void *, unsigned long, enum object_type, unsigned char *);\n-extern int force_object_loose(const unsigned char *sha1, time_t mtime);\n extern int git_open_cloexec(const char *name, int flags);\n #define git_open(name) git_open_cloexec(name, O_RDONLY)\n extern int unpack_sha1_header(git_zstream *stream, unsigned char *map, unsigned long mapsize, void *buffer, unsigned long bufsiz);\n@@ -1244,23 +1210,6 @@ extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned l\n \n extern int finalize_object_file(const char *tmpfile, const char *filename);\n \n-/*\n- * Convenience for sha1_object_info_extended() with a NULL struct\n- * object_info. OBJECT_INFO_SKIP_CACHED is automatically set; pass\n- * nonzero flags to also set other flags.\n- */\n-extern int has_sha1_file_with_flags(const unsigned char *sha1, int flags);\n-static inline int has_sha1_file(const unsigned char *sha1)\n-{\n-\treturn has_sha1_file_with_flags(sha1, 0);\n-}\n-\n-/* Same as the above, except for struct object_id. */\n-extern int has_object_file(const struct object_id *oid);\n-extern int has_object_file_with_flags(const struct object_id *oid, int flags);\n-\n-extern void assert_sha1_type(const unsigned char *sha1, enum object_type expect);\n-\n /* Helper to check and \"touch\" a file */\n extern int check_and_freshen_file(const char *fn, int freshen);\n \n@@ -1566,57 +1515,6 @@ extern int odb_pack_keep(const char *name);\n  */\n #define FOR_EACH_OBJECT_LOCAL_ONLY 0x1\n \n-struct object_info {\n-\t/* Request */\n-\tenum object_type *typep;\n-\tunsigned long *sizep;\n-\toff_t *disk_sizep;\n-\tunsigned char *delta_base_sha1;\n-\tstruct strbuf *typename;\n-\tvoid **contentp;\n-\n-\t/* Response */\n-\tenum {\n-\t\tOI_CACHED,\n-\t\tOI_LOOSE,\n-\t\tOI_PACKED,\n-\t\tOI_DBCACHED\n-\t} whence;\n-\tunion {\n-\t\t/*\n-\t\t * struct {\n-\t\t * \t... Nothing to expose in this case\n-\t\t * } cached;\n-\t\t * struct {\n-\t\t * \t... Nothing to expose in this case\n-\t\t * } loose;\n-\t\t */\n-\t\tstruct {\n-\t\t\tstruct packed_git *pack;\n-\t\t\toff_t offset;\n-\t\t\tunsigned int is_delta;\n-\t\t} packed;\n-\t} u;\n-};\n-\n-/*\n- * Initializer for a \"struct object_info\" that wants no items. You may\n- * also memset() the memory to all-zeroes.\n- */\n-#define OBJECT_INFO_INIT {NULL}\n-\n-/* Invoke lookup_replace_object() on the given hash */\n-#define OBJECT_INFO_LOOKUP_REPLACE 1\n-/* Allow reading from a loose object file of unknown/bogus type */\n-#define OBJECT_INFO_ALLOW_UNKNOWN_TYPE 2\n-/* Do not check cached storage */\n-#define OBJECT_INFO_SKIP_CACHED 4\n-/* Do not retry packed storage after checking packed and loose storage */\n-#define OBJECT_INFO_QUICK 8\n-#define sha1_object_info_extended(r, s, oi, f) \\\n-\t\tsha1_object_info_extended_##r(s, oi, f)\n-extern int sha1_object_info_extended_the_repository(const unsigned char *, struct object_info *, unsigned flags);\n-\n /* Dumb servers support */\n extern int update_server_info(int);\n \ndiff --git a/combine-diff.c b/combine-diff.c\nindex 2505de119a..f45ab6f57c 100644\n--- a/combine-diff.c\n+++ b/combine-diff.c\n@@ -1,4 +1,5 @@\n #include \"cache.h\"\n+#include \"object-store.h\"\n #include \"commit.h\"\n #include \"blob.h\"\n #include \"diff.h\"\ndiff --git a/commit.c b/commit.c\nindex cab8d4455b..b60906d3f9 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -1,6 +1,7 @@\n #include \"cache.h\"\n #include \"tag.h\"\n #include \"commit.h\"\n+#include \"object-store.h\"\n #include \"pkt-line.h\"\n #include \"utf8.h\"\n #include \"diff.h\"\ndiff --git a/convert.c b/convert.c\nindex 1a41a48e15..a090ed805f 100644\n--- a/convert.c\n+++ b/convert.c\n@@ -1,6 +1,7 @@\n #define NO_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"config.h\"\n+#include \"object-store.h\"\n #include \"attr.h\"\n #include \"run-command.h\"\n #include \"quote.h\"\ndiff --git a/diff.c b/diff.c\nindex fb22b19f09..e89c7d9919 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -13,6 +13,7 @@\n #include \"attr.h\"\n #include \"run-command.h\"\n #include \"utf8.h\"\n+#include \"object-store.h\"\n #include \"userdiff.h\"\n #include \"submodule-config.h\"\n #include \"submodule.h\"\ndiff --git a/diffcore-rename.c b/diffcore-rename.c\nindex 245e999fe5..266b9ff03f 100644\n--- a/diffcore-rename.c\n+++ b/diffcore-rename.c\n@@ -4,6 +4,7 @@\n #include \"cache.h\"\n #include \"diff.h\"\n #include \"diffcore.h\"\n+#include \"object-store.h\"\n #include \"hashmap.h\"\n #include \"progress.h\"\n \ndiff --git a/dir.c b/dir.c\nindex 7c4b45e30e..4a7981abc4 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -11,6 +11,7 @@\n #include \"cache.h\"\n #include \"config.h\"\n #include \"dir.h\"\n+#include \"object-store.h\"\n #include \"attr.h\"\n #include \"refs.h\"\n #include \"wildmatch.h\"\ndiff --git a/entry.c b/entry.c\nindex 30211447ac..02aa09bc83 100644\n--- a/entry.c\n+++ b/entry.c\n@@ -1,5 +1,6 @@\n #include \"cache.h\"\n #include \"blob.h\"\n+#include \"object-store.h\"\n #include \"dir.h\"\n #include \"streaming.h\"\n #include \"submodule.h\"\ndiff --git a/fsck.c b/fsck.c\nindex 032699e9ac..d106714bf5 100644\n--- a/fsck.c\n+++ b/fsck.c\n@@ -1,4 +1,5 @@\n #include \"cache.h\"\n+#include \"object-store.h\"\n #include \"object.h\"\n #include \"blob.h\"\n #include \"tree.h\"\ndiff --git a/grep.c b/grep.c\nindex 3d7cd0e96f..6bccd7c7ea 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -1,6 +1,7 @@\n #include \"cache.h\"\n #include \"config.h\"\n #include \"grep.h\"\n+#include \"object-store.h\"\n #include \"userdiff.h\"\n #include \"xdiff-interface.h\"\n #include \"diff.h\"\ndiff --git a/log-tree.c b/log-tree.c\nindex fca29d4799..b2fff6b5f6 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -1,6 +1,7 @@\n #include \"cache.h\"\n #include \"config.h\"\n #include \"diff.h\"\n+#include \"object-store.h\"\n #include \"commit.h\"\n #include \"tag.h\"\n #include \"graph.h\"\ndiff --git a/mailmap.c b/mailmap.c\nindex cb921b4db6..6afa9cc56d 100644\n--- a/mailmap.c\n+++ b/mailmap.c\n@@ -1,6 +1,7 @@\n #include \"cache.h\"\n #include \"string-list.h\"\n #include \"mailmap.h\"\n+#include \"object-store.h\"\n \n #define DEBUG_MAILMAP 0\n #if DEBUG_MAILMAP\ndiff --git a/match-trees.c b/match-trees.c\nindex 396b7338df..bdfdfcaaab 100644\n--- a/match-trees.c\n+++ b/match-trees.c\n@@ -1,6 +1,7 @@\n #include \"cache.h\"\n #include \"tree.h\"\n #include \"tree-walk.h\"\n+#include \"object-store.h\"\n \n static int score_missing(unsigned mode, const char *path)\n {\ndiff --git a/merge-blobs.c b/merge-blobs.c\nindex 9b6eac22e4..f5e71bcd9b 100644\n--- a/merge-blobs.c\n+++ b/merge-blobs.c\n@@ -4,6 +4,7 @@\n #include \"ll-merge.h\"\n #include \"blob.h\"\n #include \"merge-blobs.h\"\n+#include \"object-store.h\"\n \n static int fill_mmfile_blob(mmfile_t *f, struct blob *obj)\n {\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 0fc580d8ca..620e4f653c 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -8,6 +8,7 @@\n #include \"advice.h\"\n #include \"lockfile.h\"\n #include \"cache-tree.h\"\n+#include \"object-store.h\"\n #include \"commit.h\"\n #include \"blob.h\"\n #include \"builtin.h\"\ndiff --git a/notes-cache.c b/notes-cache.c\nindex 17ee8602b3..ee513e87a9 100644\n--- a/notes-cache.c\n+++ b/notes-cache.c\n@@ -1,5 +1,6 @@\n #include \"cache.h\"\n #include \"notes-cache.h\"\n+#include \"object-store.h\"\n #include \"commit.h\"\n #include \"refs.h\"\n \ndiff --git a/notes-merge.c b/notes-merge.c\nindex 0f6573cb17..1053c65e83 100644\n--- a/notes-merge.c\n+++ b/notes-merge.c\n@@ -1,6 +1,7 @@\n #include \"cache.h\"\n #include \"commit.h\"\n #include \"refs.h\"\n+#include \"object-store.h\"\n #include \"diff.h\"\n #include \"diffcore.h\"\n #include \"xdiff-interface.h\"\ndiff --git a/notes.c b/notes.c\nindex c7f21fae44..b1478a8dca 100644\n--- a/notes.c\n+++ b/notes.c\n@@ -1,6 +1,7 @@\n #include \"cache.h\"\n #include \"config.h\"\n #include \"notes.h\"\n+#include \"object-store.h\"\n #include \"blob.h\"\n #include \"tree.h\"\n #include \"utf8.h\"\ndiff --git a/object-store.h b/object-store.h\nindex 3475e22021..31628c49dc 100644\n--- a/object-store.h\n+++ b/object-store.h\n@@ -1,11 +1,17 @@\n #ifndef OBJECT_STORE_H\n #define OBJECT_STORE_H\n \n-#include \"cache.h\"\n+#include \"strbuf.h\"\n #include \"mru.h\"\n #include \"replace-object.h\"\n #include \"alternates.h\"\n-#include \"packfile.h\"\n+\n+/* in packfile.h */\n+struct pack_window;\n+\n+/* in cache.h */\n+enum object_type;\n+extern int check_replace_refs;\n \n struct object_store {\n \tstruct packed_git *packed_git;\n@@ -67,6 +73,108 @@ struct packed_git {\n \tchar pack_name[FLEX_ARRAY]; /* more */\n };\n \n+extern void *read_sha1_file_extended(const unsigned char *sha1,\n+\t\t\t\t     enum object_type *type,\n+\t\t\t\t     unsigned long *size, int lookup_replace);\n+static inline void *read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size)\n+{\n+\treturn read_sha1_file_extended(sha1, type, size, 1);\n+}\n+\n+/*\n+ * This internal function is only declared here for the benefit of\n+ * lookup_replace_object().  Please do not call it directly.\n+ */\n+extern const unsigned char *do_lookup_replace_object(const unsigned char *sha1);\n+\n+/*\n+ * If object sha1 should be replaced, return the replacement object's\n+ * name (replaced recursively, if necessary).  The return value is\n+ * either sha1 or a pointer to a permanently-allocated value.  When\n+ * object replacement is suppressed, always return sha1.\n+ */\n+static inline const unsigned char *lookup_replace_object(const unsigned char *sha1)\n+{\n+\tif (!check_replace_refs)\n+\t\treturn sha1;\n+\treturn do_lookup_replace_object(sha1);\n+}\n+\n+/* Read and unpack a sha1 file into memory, write memory to a sha1 file */\n+extern int sha1_object_info(const unsigned char *, unsigned long *);\n+extern int hash_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *sha1);\n+extern int write_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *return_sha1);\n+extern int hash_sha1_file_literally(const void *buf, unsigned long len, const char *type, struct object_id *oid, unsigned flags);\n+extern int pretend_sha1_file(void *, unsigned long, enum object_type, unsigned char *);\n+extern int force_object_loose(const unsigned char *sha1, time_t mtime);\n extern void *map_sha1_file(struct repository *r, const unsigned char *sha1, unsigned long *size);\n \n+/*\n+ * Convenience for sha1_object_info_extended() with a NULL struct\n+ * object_info. OBJECT_INFO_SKIP_CACHED is automatically set; pass\n+ * nonzero flags to also set other flags.\n+ */\n+extern int has_sha1_file_with_flags(const unsigned char *sha1, int flags);\n+static inline int has_sha1_file(const unsigned char *sha1)\n+{\n+\treturn has_sha1_file_with_flags(sha1, 0);\n+}\n+\n+/* Same as the above, except for struct object_id. */\n+extern int has_object_file(const struct object_id *oid);\n+extern int has_object_file_with_flags(const struct object_id *oid, int flags);\n+\n+extern void assert_sha1_type(const unsigned char *sha1, enum object_type expect);\n+\n+struct object_info {\n+\t/* Request */\n+\tenum object_type *typep;\n+\tunsigned long *sizep;\n+\toff_t *disk_sizep;\n+\tunsigned char *delta_base_sha1;\n+\tstruct strbuf *typename;\n+\tvoid **contentp;\n+\n+\t/* Response */\n+\tenum {\n+\t\tOI_CACHED,\n+\t\tOI_LOOSE,\n+\t\tOI_PACKED,\n+\t\tOI_DBCACHED\n+\t} whence;\n+\tunion {\n+\t\t/*\n+\t\t * struct {\n+\t\t * \t... Nothing to expose in this case\n+\t\t * } cached;\n+\t\t * struct {\n+\t\t * \t... Nothing to expose in this case\n+\t\t * } loose;\n+\t\t */\n+\t\tstruct {\n+\t\t\tstruct packed_git *pack;\n+\t\t\toff_t offset;\n+\t\t\tunsigned int is_delta;\n+\t\t} packed;\n+\t} u;\n+};\n+\n+/*\n+ * Initializer for a \"struct object_info\" that wants no items. You may\n+ * also memset() the memory to all-zeroes.\n+ */\n+#define OBJECT_INFO_INIT {NULL}\n+\n+/* Invoke lookup_replace_object() on the given hash */\n+#define OBJECT_INFO_LOOKUP_REPLACE 1\n+/* Allow reading from a loose object file of unknown/bogus type */\n+#define OBJECT_INFO_ALLOW_UNKNOWN_TYPE 2\n+/* Do not check cached storage */\n+#define OBJECT_INFO_SKIP_CACHED 4\n+/* Do not retry packed storage after checking packed and loose storage */\n+#define OBJECT_INFO_QUICK 8\n+#define sha1_object_info_extended(r, s, oi, f) \\\n+\t\tsha1_object_info_extended_##r(s, oi, f)\n+extern int sha1_object_info_extended_the_repository(const unsigned char *, struct object_info *, unsigned flags);\n+\n #endif /* OBJECT_STORE_H */\ndiff --git a/object.c b/object.c\nindex b9a4a0e501..4d2ae6851c 100644\n--- a/object.c\n+++ b/object.c\n@@ -1,5 +1,6 @@\n #include \"cache.h\"\n #include \"object.h\"\n+#include \"object-store.h\"\n #include \"blob.h\"\n #include \"tree.h\"\n #include \"commit.h\"\ndiff --git a/pack-bitmap-write.c b/pack-bitmap-write.c\nindex a8df5ce2ab..6a656104af 100644\n--- a/pack-bitmap-write.c\n+++ b/pack-bitmap-write.c\n@@ -1,4 +1,5 @@\n #include \"cache.h\"\n+#include \"object-store.h\"\n #include \"commit.h\"\n #include \"tag.h\"\n #include \"diff.h\"\ndiff --git a/packfile.h b/packfile.h\nindex 1163fc7bb4..0c314eea93 100644\n--- a/packfile.h\n+++ b/packfile.h\n@@ -5,6 +5,9 @@\n enum object_type;\n struct object_info;\n \n+/* in object-store.h */\n+struct packed_git;\n+\n struct pack_window {\n \tstruct pack_window *next;\n \tunsigned char *base;\ndiff --git a/read-cache.c b/read-cache.c\nindex 2eb81a66b9..45cad9272a 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -11,6 +11,7 @@\n #include \"cache-tree.h\"\n #include \"refs.h\"\n #include \"dir.h\"\n+#include \"object-store.h\"\n #include \"tree.h\"\n #include \"commit.h\"\n #include \"blob.h\"\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 3f9161707e..0a106b888d 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -3,6 +3,7 @@\n #include \"parse-options.h\"\n #include \"refs.h\"\n #include \"wildmatch.h\"\n+#include \"object-store.h\"\n #include \"commit.h\"\n #include \"remote.h\"\n #include \"color.h\"\ndiff --git a/refs.c b/refs.c\nindex 20ba82b434..968d33ac11 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -9,6 +9,7 @@\n #include \"iterator.h\"\n #include \"refs.h\"\n #include \"refs/refs-internal.h\"\n+#include \"object-store.h\"\n #include \"object.h\"\n #include \"tag.h\"\n #include \"submodule.h\"\ndiff --git a/remote-testsvn.c b/remote-testsvn.c\nindex bcebb4c789..387d4ae935 100644\n--- a/remote-testsvn.c\n+++ b/remote-testsvn.c\n@@ -1,6 +1,7 @@\n #include \"cache.h\"\n #include \"refs.h\"\n #include \"remote.h\"\n+#include \"object-store.h\"\n #include \"strbuf.h\"\n #include \"url.h\"\n #include \"exec_cmd.h\"\ndiff --git a/remote.c b/remote.c\nindex 4e93753e19..5112f370c3 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -2,6 +2,7 @@\n #include \"config.h\"\n #include \"remote.h\"\n #include \"refs.h\"\n+#include \"object-store.h\"\n #include \"commit.h\"\n #include \"diff.h\"\n #include \"revision.h\"\ndiff --git a/rerere.c b/rerere.c\nindex 1ce440f4bb..ab64d3f48e 100644\n--- a/rerere.c\n+++ b/rerere.c\n@@ -9,6 +9,7 @@\n #include \"ll-merge.h\"\n #include \"attr.h\"\n #include \"pathspec.h\"\n+#include \"object-store.h\"\n #include \"sha1-lookup.h\"\n \n #define RESOLVED 0\ndiff --git a/revision.c b/revision.c\nindex 72f2b4572e..9ede92c09e 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -1,4 +1,5 @@\n #include \"cache.h\"\n+#include \"object-store.h\"\n #include \"tag.h\"\n #include \"blob.h\"\n #include \"tree.h\"\ndiff --git a/send-pack.c b/send-pack.c\nindex 2112d3b27a..c2856dcfd5 100644\n--- a/send-pack.c\n+++ b/send-pack.c\n@@ -2,6 +2,7 @@\n #include \"config.h\"\n #include \"commit.h\"\n #include \"refs.h\"\n+#include \"object-store.h\"\n #include \"pkt-line.h\"\n #include \"sideband.h\"\n #include \"run-command.h\"\ndiff --git a/sequencer.c b/sequencer.c\nindex 4d3f60594c..234addd4e7 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -3,6 +3,7 @@\n #include \"lockfile.h\"\n #include \"sequencer.h\"\n #include \"dir.h\"\n+#include \"object-store.h\"\n #include \"object.h\"\n #include \"commit.h\"\n #include \"tag.h\"\ndiff --git a/shallow.c b/shallow.c\nindex df4d44ea7a..c2f81a5a5a 100644\n--- a/shallow.c\n+++ b/shallow.c\n@@ -1,6 +1,7 @@\n #include \"cache.h\"\n #include \"tempfile.h\"\n #include \"lockfile.h\"\n+#include \"object-store.h\"\n #include \"commit.h\"\n #include \"tag.h\"\n #include \"pkt-line.h\"\ndiff --git a/tag.c b/tag.c\nindex fcbe012f7a..30798abf1f 100644\n--- a/tag.c\n+++ b/tag.c\n@@ -1,5 +1,6 @@\n #include \"cache.h\"\n #include \"tag.h\"\n+#include \"object-store.h\"\n #include \"commit.h\"\n #include \"tree.h\"\n #include \"blob.h\"\ndiff --git a/tree-walk.c b/tree-walk.c\nindex 63a87ed666..8bd56eddd5 100644\n--- a/tree-walk.c\n+++ b/tree-walk.c\n@@ -2,6 +2,7 @@\n #include \"tree-walk.h\"\n #include \"unpack-trees.h\"\n #include \"dir.h\"\n+#include \"object-store.h\"\n #include \"tree.h\"\n #include \"pathspec.h\"\n \ndiff --git a/tree.c b/tree.c\nindex b224115e0f..653339db03 100644\n--- a/tree.c\n+++ b/tree.c\n@@ -2,6 +2,7 @@\n #include \"cache.h\"\n #include \"cache-tree.h\"\n #include \"tree.h\"\n+#include \"object-store.h\"\n #include \"blob.h\"\n #include \"commit.h\"\n #include \"tag.h\"\ndiff --git a/upload-pack.c b/upload-pack.c\nindex d5de18127c..6db85ecdc4 100644\n--- a/upload-pack.c\n+++ b/upload-pack.c\n@@ -3,6 +3,7 @@\n #include \"refs.h\"\n #include \"pkt-line.h\"\n #include \"sideband.h\"\n+#include \"object-store.h\"\n #include \"tag.h\"\n #include \"object.h\"\n #include \"commit.h\"\ndiff --git a/walker.c b/walker.c\nindex 5d4d3733f7..49b6a96e6e 100644\n--- a/walker.c\n+++ b/walker.c\n@@ -1,5 +1,6 @@\n #include \"cache.h\"\n #include \"walker.h\"\n+#include \"object-store.h\"\n #include \"commit.h\"\n #include \"tree.h\"\n #include \"tree-walk.h\"\ndiff --git a/xdiff-interface.c b/xdiff-interface.c\nindex 770e1f7f81..a2d0e05edd 100644\n--- a/xdiff-interface.c\n+++ b/xdiff-interface.c\n@@ -1,5 +1,6 @@\n #include \"cache.h\"\n #include \"config.h\"\n+#include \"object-store.h\"\n #include \"xdiff-interface.h\"\n #include \"xdiff/xtypes.h\"\n #include \"xdiff/xdiffi.h\"\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338312","messageId":"20180205235735.216710-27-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 047/194] object-store: move lookup_replace_object to replace-object.h","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:08Z","receivedAt":"2018-02-06T00:04:08Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nlookup_replace_object is a low-level function that most users of the\nobject store do not need to use directly.\n\nMove it to replace-object.h to avoid a dependency loop in an upcoming\nchange to its inline definition that will make use of repository.h.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n builtin/mktag.c  |  1 +\n object-store.h   | 19 -------------------\n object.c         |  1 +\n replace-object.h | 22 ++++++++++++++++++++++\n sha1_file.c      |  1 +\n streaming.c      |  1 +\n 6 files changed, 26 insertions(+), 19 deletions(-)\n\ndiff --git a/builtin/mktag.c b/builtin/mktag.c\nindex 04eadc7b24..93934e8e4b 100644\n--- a/builtin/mktag.c\n+++ b/builtin/mktag.c\n@@ -1,6 +1,7 @@\n #include \"builtin.h\"\n #include \"tag.h\"\n #include \"object-store.h\"\n+#include \"replace-object.h\"\n \n /*\n  * A signature file has a very simple fixed format: four lines\ndiff --git a/object-store.h b/object-store.h\nindex cf06a54782..4ac0ffdb98 100644\n--- a/object-store.h\n+++ b/object-store.h\n@@ -88,25 +88,6 @@ static inline void *read_sha1_file(const unsigned char *sha1, enum object_type *\n \treturn read_sha1_file_extended(sha1, type, size, 1);\n }\n \n-/*\n- * This internal function is only declared here for the benefit of\n- * lookup_replace_object().  Please do not call it directly.\n- */\n-extern const unsigned char *do_lookup_replace_object(const unsigned char *sha1);\n-\n-/*\n- * If object sha1 should be replaced, return the replacement object's\n- * name (replaced recursively, if necessary).  The return value is\n- * either sha1 or a pointer to a permanently-allocated value.  When\n- * object replacement is suppressed, always return sha1.\n- */\n-static inline const unsigned char *lookup_replace_object(const unsigned char *sha1)\n-{\n-\tif (!check_replace_refs)\n-\t\treturn sha1;\n-\treturn do_lookup_replace_object(sha1);\n-}\n-\n /* Read and unpack a sha1 file into memory, write memory to a sha1 file */\n extern int sha1_object_info(const unsigned char *, unsigned long *);\n extern int hash_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *sha1);\ndiff --git a/object.c b/object.c\nindex 4d2ae6851c..fc0ccbefef 100644\n--- a/object.c\n+++ b/object.c\n@@ -1,6 +1,7 @@\n #include \"cache.h\"\n #include \"object.h\"\n #include \"object-store.h\"\n+#include \"replace-object.h\"\n #include \"blob.h\"\n #include \"tree.h\"\n #include \"commit.h\"\ndiff --git a/replace-object.h b/replace-object.h\nindex e05713b951..668bbed1da 100644\n--- a/replace-object.h\n+++ b/replace-object.h\n@@ -1,9 +1,31 @@\n #ifndef REPLACE_OBJECT_H\n #define REPLACE_OBJECT_H\n \n+#include \"cache.h\"\n+#include \"repository.h\"\n+\n struct replace_object {\n \tunsigned char original[20];\n \tunsigned char replacement[20];\n };\n \n+/*\n+ * This internal function is only declared here for the benefit of\n+ * lookup_replace_object().  Please do not call it directly.\n+ */\n+extern const unsigned char *do_lookup_replace_object(const unsigned char *sha1);\n+\n+/*\n+ * If object sha1 should be replaced, return the replacement object's\n+ * name (replaced recursively, if necessary).  The return value is\n+ * either sha1 or a pointer to a permanently-allocated value.  When\n+ * object replacement is suppressed, always return sha1.\n+ */\n+static inline const unsigned char *lookup_replace_object(const unsigned char *sha1)\n+{\n+\tif (!check_replace_refs)\n+\t\treturn sha1;\n+\treturn do_lookup_replace_object(sha1);\n+}\n+\n #endif /* REPLACE_OBJECT_H */\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 2584465e9c..8ee86f8ede 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -25,6 +25,7 @@\n #include \"bulk-checkin.h\"\n #include \"repository.h\"\n #include \"object-store.h\"\n+#include \"replace-object.h\"\n #include \"loose-object.h\"\n #include \"streaming.h\"\n #include \"path.h\"\ndiff --git a/streaming.c b/streaming.c\nindex 47fca9aba0..c47600e719 100644\n--- a/streaming.c\n+++ b/streaming.c\n@@ -5,6 +5,7 @@\n #include \"streaming.h\"\n #include \"repository.h\"\n #include \"object-store.h\"\n+#include \"replace-object.h\"\n #include \"packfile.h\"\n \n enum input_source {\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338313","messageId":"20180205235735.216710-26-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 046/194] object-store: move replace_objects back to object-store","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:07Z","receivedAt":"2018-02-06T00:04:09Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nThis way, object-store.h does not need to #include replace-object.h,\navoiding a header dependency loop in an upcoming change to the inline\ndefinition of the lookup_replace_object function.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n object-store.h   | 13 ++++++++++---\n replace-object.h | 11 -----------\n 2 files changed, 10 insertions(+), 14 deletions(-)\n\ndiff --git a/object-store.h b/object-store.h\nindex 31628c49dc..cf06a54782 100644\n--- a/object-store.h\n+++ b/object-store.h\n@@ -3,7 +3,6 @@\n \n #include \"strbuf.h\"\n #include \"mru.h\"\n-#include \"replace-object.h\"\n #include \"alternates.h\"\n \n /* in packfile.h */\n@@ -32,7 +31,15 @@ struct object_store {\n \t * Objects that should be substituted by other objects\n \t * (see git-replace(1)).\n \t */\n-\tstruct replace_objects replacements;\n+\tstruct replace_objects {\n+\t\t/*\n+\t\t * An array of replacements.  The array is kept sorted by the original\n+\t\t * sha1.\n+\t\t */\n+\t\tstruct replace_object **items;\n+\n+\t\tint alloc, nr;\n+\t} replacements;\n \n \t/*\n \t * A fast, rough count of the number of objects in the repository.\n@@ -49,7 +56,7 @@ struct object_store {\n \tunsigned packed_git_initialized : 1;\n };\n #define OBJECT_STORE_INIT \\\n-\t{ NULL, MRU_INIT, ALTERNATES_INIT, REPLACE_OBJECTS_INIT, 0, 0, 0 }\n+\t{ NULL, MRU_INIT, ALTERNATES_INIT, { NULL, 0, 0 }, 0, 0, 0 }\n \n struct packed_git {\n \tstruct packed_git *next;\ndiff --git a/replace-object.h b/replace-object.h\nindex 483335ffcc..e05713b951 100644\n--- a/replace-object.h\n+++ b/replace-object.h\n@@ -1,17 +1,6 @@\n #ifndef REPLACE_OBJECT_H\n #define REPLACE_OBJECT_H\n \n-struct replace_objects {\n-\t/*\n-\t * An array of replacements.  The array is kept sorted by the original\n-\t * sha1.\n-\t */\n-\tstruct replace_object **items;\n-\n-\tint alloc, nr;\n-};\n-#define REPLACE_OBJECTS_INIT { NULL, 0, 0 }\n-\n struct replace_object {\n \tunsigned char original[20];\n \tunsigned char replacement[20];\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338314","messageId":"20180205235735.216710-28-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 048/194] replace-object: add repository argument to do_lookup_replace_object","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:09Z","receivedAt":"2018-02-06T00:04:11Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow the do_lookup_replace_object caller\nto be more specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n replace-object.c | 2 +-\n replace-object.h | 5 +++--\n 2 files changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/replace-object.c b/replace-object.c\nindex d26e180639..cf38c3df00 100644\n--- a/replace-object.c\n+++ b/replace-object.c\n@@ -94,7 +94,7 @@ static void prepare_replace_object(void)\n  * permanently-allocated value.  This function always respects replace\n  * references, regardless of the value of check_replace_refs.\n  */\n-const unsigned char *do_lookup_replace_object(const unsigned char *sha1)\n+const unsigned char *do_lookup_replace_object_the_repository(const unsigned char *sha1)\n {\n \tint pos, depth = MAXREPLACEDEPTH;\n \tconst unsigned char *cur = sha1;\ndiff --git a/replace-object.h b/replace-object.h\nindex 668bbed1da..702020a3a0 100644\n--- a/replace-object.h\n+++ b/replace-object.h\n@@ -13,7 +13,8 @@ struct replace_object {\n  * This internal function is only declared here for the benefit of\n  * lookup_replace_object().  Please do not call it directly.\n  */\n-extern const unsigned char *do_lookup_replace_object(const unsigned char *sha1);\n+#define do_lookup_replace_object(r, s) do_lookup_replace_object_##r(s)\n+extern const unsigned char *do_lookup_replace_object_the_repository(const unsigned char *sha1);\n \n /*\n  * If object sha1 should be replaced, return the replacement object's\n@@ -25,7 +26,7 @@ static inline const unsigned char *lookup_replace_object(const unsigned char *sh\n {\n \tif (!check_replace_refs)\n \t\treturn sha1;\n-\treturn do_lookup_replace_object(sha1);\n+\treturn do_lookup_replace_object(the_repository, sha1);\n }\n \n #endif /* REPLACE_OBJECT_H */\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338315","messageId":"20180205235735.216710-29-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 049/194] replace-object: move replace objects prepared flag to object store","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:10Z","receivedAt":"2018-02-06T00:04:19Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Remove another global variable on the way.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n object-store.h   | 4 +++-\n replace-object.c | 6 ++----\n 2 files changed, 5 insertions(+), 5 deletions(-)\n\ndiff --git a/object-store.h b/object-store.h\nindex 4ac0ffdb98..e1e592bdd5 100644\n--- a/object-store.h\n+++ b/object-store.h\n@@ -39,6 +39,8 @@ struct object_store {\n \t\tstruct replace_object **items;\n \n \t\tint alloc, nr;\n+\n+\t\tunsigned prepared : 1;\n \t} replacements;\n \n \t/*\n@@ -56,7 +58,7 @@ struct object_store {\n \tunsigned packed_git_initialized : 1;\n };\n #define OBJECT_STORE_INIT \\\n-\t{ NULL, MRU_INIT, ALTERNATES_INIT, { NULL, 0, 0 }, 0, 0, 0 }\n+\t{ NULL, MRU_INIT, ALTERNATES_INIT, { NULL, 0, 0, 0 }, 0, 0, 0 }\n \n struct packed_git {\n \tstruct packed_git *next;\ndiff --git a/replace-object.c b/replace-object.c\nindex cf38c3df00..c865eff0ba 100644\n--- a/replace-object.c\n+++ b/replace-object.c\n@@ -73,13 +73,11 @@ static int register_replace_ref(const char *refname,\n \n static void prepare_replace_object(void)\n {\n-\tstatic int replace_object_prepared;\n-\n-\tif (replace_object_prepared)\n+\tif (the_repository->objects.replacements.prepared)\n \t\treturn;\n \n \tfor_each_replace_ref(register_replace_ref, NULL);\n-\treplace_object_prepared = 1;\n+\tthe_repository->objects.replacements.prepared = 1;\n \tif (!the_repository->objects.replacements.nr)\n \t\tcheck_replace_refs = 0;\n }\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338316","messageId":"20180205235735.216710-30-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 050/194] replace-object: check_replace_refs is safe in multi repo environment","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:11Z","receivedAt":"2018-02-06T00:04:22Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"In e1111cef23 (inline lookup_replace_object() calls, 2011-05-15) a shortcut\nfor checking the object replacement was added by setting check_replace_refs\nto 0 once the replacements were evaluated to not exist. This works fine in\nwith the assumption of only one repository in existence.\n\nThe assumption won't hold true any more when we work on multiple instances\nof a repository structs (e.g. one struct per submodule), as the first\nrepository to be inspected may have no replacements and would set the\nglobal variable. Other repositories would then completely omit their\nevaluation of replacements.\n\nThis reverts back the meaning of the flag `check_replace_refs` of\n\"Do we need to check with the lookup table?\" to \"Do we need read the\nreplacement definition?\", adding the bypassing logic to\nlookup_replace_object after the replacement definition was read.\nAs with the original patch, delay the renaming of the global variable\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n environment.c    | 2 +-\n replace-object.c | 2 --\n replace-object.h | 4 +++-\n 3 files changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/environment.c b/environment.c\nindex 63ac38a46f..249516cf6b 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -46,7 +46,7 @@ const char *editor_program;\n const char *askpass_program;\n const char *excludes_file;\n enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;\n-int check_replace_refs = 1;\n+int check_replace_refs = 1; /* NEEDSWORK: rename to read_replace_refs */\n char *git_replace_ref_base;\n enum eol core_eol = EOL_UNSET;\n enum safe_crlf safe_crlf = SAFE_CRLF_WARN;\ndiff --git a/replace-object.c b/replace-object.c\nindex c865eff0ba..91fedd9447 100644\n--- a/replace-object.c\n+++ b/replace-object.c\n@@ -78,8 +78,6 @@ static void prepare_replace_object(void)\n \n \tfor_each_replace_ref(register_replace_ref, NULL);\n \tthe_repository->objects.replacements.prepared = 1;\n-\tif (!the_repository->objects.replacements.nr)\n-\t\tcheck_replace_refs = 0;\n }\n \n /* We allow \"recursive\" replacement. Only within reason, though */\ndiff --git a/replace-object.h b/replace-object.h\nindex 702020a3a0..8af730f5e3 100644\n--- a/replace-object.h\n+++ b/replace-object.h\n@@ -24,7 +24,9 @@ extern const unsigned char *do_lookup_replace_object_the_repository(const unsign\n  */\n static inline const unsigned char *lookup_replace_object(const unsigned char *sha1)\n {\n-\tif (!check_replace_refs)\n+\tif (!check_replace_refs ||\n+\t    (the_repository->objects.replacements.prepared &&\n+\t     the_repository->objects.replacements.nr == 0))\n \t\treturn sha1;\n \treturn do_lookup_replace_object(the_repository, sha1);\n }\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338317","messageId":"20180205235735.216710-31-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 051/194] refs: add repository argument to for_each_replace_ref","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:12Z","receivedAt":"2018-02-06T00:04:47Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow for_each_replace_ref callers to be\nmore specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n builtin/replace.c | 3 ++-\n refs.c            | 2 +-\n refs.h            | 4 +++-\n replace-object.c  | 2 +-\n 4 files changed, 7 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/replace.c b/builtin/replace.c\nindex ccde160228..6d27dd73f0 100644\n--- a/builtin/replace.c\n+++ b/builtin/replace.c\n@@ -15,6 +15,7 @@\n #include \"parse-options.h\"\n #include \"run-command.h\"\n #include \"object-store.h\"\n+#include \"repository.h\"\n #include \"tag.h\"\n \n static const char * const git_replace_usage[] = {\n@@ -84,7 +85,7 @@ static int list_replace_refs(const char *pattern, const char *format)\n \t\t    \"valid formats are 'short', 'medium' and 'long'\\n\",\n \t\t    format);\n \n-\tfor_each_replace_ref(show_reference, (void *)&data);\n+\tfor_each_replace_ref(the_repository, show_reference, (void *)&data);\n \n \treturn 0;\n }\ndiff --git a/refs.c b/refs.c\nindex 968d33ac11..5c26532cbd 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -1415,7 +1415,7 @@ int refs_for_each_fullref_in(struct ref_store *refs, const char *prefix,\n \treturn do_for_each_ref(refs, prefix, fn, 0, flag, cb_data);\n }\n \n-int for_each_replace_ref(each_ref_fn fn, void *cb_data)\n+int for_each_replace_ref_the_repository(each_ref_fn fn, void *cb_data)\n {\n \treturn do_for_each_ref(get_main_ref_store(),\n \t\t\t       git_replace_ref_base, fn,\ndiff --git a/refs.h b/refs.h\nindex 01be5ae32f..546fa9e65a 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -300,7 +300,9 @@ int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data,\n int for_each_tag_ref(each_ref_fn fn, void *cb_data);\n int for_each_branch_ref(each_ref_fn fn, void *cb_data);\n int for_each_remote_ref(each_ref_fn fn, void *cb_data);\n-int for_each_replace_ref(each_ref_fn fn, void *cb_data);\n+#define for_each_replace_ref(r, fn, cb) \\\n+\tfor_each_replace_ref_##r(fn, cb)\n+int for_each_replace_ref_the_repository(each_ref_fn fn, void *cb_data);\n int for_each_glob_ref(each_ref_fn fn, const char *pattern, void *cb_data);\n int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,\n \t\t\t const char *prefix, void *cb_data);\ndiff --git a/replace-object.c b/replace-object.c\nindex 91fedd9447..102e009927 100644\n--- a/replace-object.c\n+++ b/replace-object.c\n@@ -76,7 +76,7 @@ static void prepare_replace_object(void)\n \tif (the_repository->objects.replacements.prepared)\n \t\treturn;\n \n-\tfor_each_replace_ref(register_replace_ref, NULL);\n+\tfor_each_replace_ref(the_repository, register_replace_ref, NULL);\n \tthe_repository->objects.replacements.prepared = 1;\n }\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338318","messageId":"20180205235735.216710-32-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 052/194] refs: add repository argument to get_main_ref_store","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:13Z","receivedAt":"2018-02-06T00:04:50Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow the get_main_ref_store caller\nto be more specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n builtin/pack-refs.c       |  3 ++-\n refs.c                    | 67 ++++++++++++++++++++++++-----------------------\n refs.h                    |  4 ++-\n revision.c                |  5 ++--\n t/helper/test-ref-store.c |  3 ++-\n 5 files changed, 44 insertions(+), 38 deletions(-)\n\ndiff --git a/builtin/pack-refs.c b/builtin/pack-refs.c\nindex b106a392a4..f3353564f9 100644\n--- a/builtin/pack-refs.c\n+++ b/builtin/pack-refs.c\n@@ -1,6 +1,7 @@\n #include \"builtin.h\"\n #include \"parse-options.h\"\n #include \"refs.h\"\n+#include \"repository.h\"\n \n static char const * const pack_refs_usage[] = {\n \tN_(\"git pack-refs [<options>]\"),\n@@ -17,5 +18,5 @@ int cmd_pack_refs(int argc, const char **argv, const char *prefix)\n \t};\n \tif (parse_options(argc, argv, prefix, opts, pack_refs_usage, 0))\n \t\tusage_with_options(pack_refs_usage, opts);\n-\treturn refs_pack_refs(get_main_ref_store(), flags);\n+\treturn refs_pack_refs(get_main_ref_store(the_repository), flags);\n }\ndiff --git a/refs.c b/refs.c\nindex 5c26532cbd..c2dee7a69a 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -14,6 +14,7 @@\n #include \"tag.h\"\n #include \"submodule.h\"\n #include \"worktree.h\"\n+#include \"repository.h\"\n \n /*\n  * List of all available backends\n@@ -207,7 +208,7 @@ char *refs_resolve_refdup(struct ref_store *refs,\n char *resolve_refdup(const char *refname, int resolve_flags,\n \t\t     struct object_id *oid, int *flags)\n {\n-\treturn refs_resolve_refdup(get_main_ref_store(),\n+\treturn refs_resolve_refdup(get_main_ref_store(the_repository),\n \t\t\t\t   refname, resolve_flags,\n \t\t\t\t   oid, flags);\n }\n@@ -229,7 +230,7 @@ int refs_read_ref_full(struct ref_store *refs, const char *refname,\n \n int read_ref_full(const char *refname, int resolve_flags, struct object_id *oid, int *flags)\n {\n-\treturn refs_read_ref_full(get_main_ref_store(), refname,\n+\treturn refs_read_ref_full(get_main_ref_store(the_repository), refname,\n \t\t\t\t  resolve_flags, oid, flags);\n }\n \n@@ -376,7 +377,7 @@ int refs_for_each_tag_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data)\n \n int for_each_tag_ref(each_ref_fn fn, void *cb_data)\n {\n-\treturn refs_for_each_tag_ref(get_main_ref_store(), fn, cb_data);\n+\treturn refs_for_each_tag_ref(get_main_ref_store(the_repository), fn, cb_data);\n }\n \n int refs_for_each_branch_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data)\n@@ -386,7 +387,7 @@ int refs_for_each_branch_ref(struct ref_store *refs, each_ref_fn fn, void *cb_da\n \n int for_each_branch_ref(each_ref_fn fn, void *cb_data)\n {\n-\treturn refs_for_each_branch_ref(get_main_ref_store(), fn, cb_data);\n+\treturn refs_for_each_branch_ref(get_main_ref_store(the_repository), fn, cb_data);\n }\n \n int refs_for_each_remote_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data)\n@@ -396,7 +397,7 @@ int refs_for_each_remote_ref(struct ref_store *refs, each_ref_fn fn, void *cb_da\n \n int for_each_remote_ref(each_ref_fn fn, void *cb_data)\n {\n-\treturn refs_for_each_remote_ref(get_main_ref_store(), fn, cb_data);\n+\treturn refs_for_each_remote_ref(get_main_ref_store(the_repository), fn, cb_data);\n }\n \n int head_ref_namespaced(each_ref_fn fn, void *cb_data)\n@@ -731,7 +732,7 @@ int refs_delete_ref(struct ref_store *refs, const char *msg,\n \tstruct strbuf err = STRBUF_INIT;\n \n \tif (ref_type(refname) == REF_TYPE_PSEUDOREF) {\n-\t\tassert(refs == get_main_ref_store());\n+\t\tassert(refs == get_main_ref_store(the_repository));\n \t\treturn delete_pseudoref(refname, old_oid);\n \t}\n \n@@ -753,7 +754,7 @@ int refs_delete_ref(struct ref_store *refs, const char *msg,\n int delete_ref(const char *msg, const char *refname,\n \t       const struct object_id *old_oid, unsigned int flags)\n {\n-\treturn refs_delete_ref(get_main_ref_store(), msg, refname,\n+\treturn refs_delete_ref(get_main_ref_store(the_repository), msg, refname,\n \t\t\t       old_oid, flags);\n }\n \n@@ -929,7 +930,7 @@ struct ref_transaction *ref_store_transaction_begin(struct ref_store *refs,\n \n struct ref_transaction *ref_transaction_begin(struct strbuf *err)\n {\n-\treturn ref_store_transaction_begin(get_main_ref_store(), err);\n+\treturn ref_store_transaction_begin(get_main_ref_store(the_repository), err);\n }\n \n void ref_transaction_free(struct ref_transaction *transaction)\n@@ -1061,7 +1062,7 @@ int refs_update_ref(struct ref_store *refs, const char *msg,\n \tint ret = 0;\n \n \tif (ref_type(refname) == REF_TYPE_PSEUDOREF) {\n-\t\tassert(refs == get_main_ref_store());\n+\t\tassert(refs == get_main_ref_store(the_repository));\n \t\tret = write_pseudoref(refname, new_oid, old_oid, &err);\n \t} else {\n \t\tt = ref_store_transaction_begin(refs, &err);\n@@ -1100,7 +1101,7 @@ int update_ref(const char *msg, const char *refname,\n \t       const struct object_id *old_oid,\n \t       unsigned int flags, enum action_on_err onerr)\n {\n-\treturn refs_update_ref(get_main_ref_store(), msg, refname, new_oid,\n+\treturn refs_update_ref(get_main_ref_store(the_repository), msg, refname, new_oid,\n \t\t\t       old_oid, flags, onerr);\n }\n \n@@ -1321,7 +1322,7 @@ int refs_head_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data)\n \n int head_ref(each_ref_fn fn, void *cb_data)\n {\n-\treturn refs_head_ref(get_main_ref_store(), fn, cb_data);\n+\treturn refs_head_ref(get_main_ref_store(the_repository), fn, cb_data);\n }\n \n struct ref_iterator *refs_ref_iterator_begin(\n@@ -1380,7 +1381,7 @@ int refs_for_each_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data)\n \n int for_each_ref(each_ref_fn fn, void *cb_data)\n {\n-\treturn refs_for_each_ref(get_main_ref_store(), fn, cb_data);\n+\treturn refs_for_each_ref(get_main_ref_store(the_repository), fn, cb_data);\n }\n \n int refs_for_each_ref_in(struct ref_store *refs, const char *prefix,\n@@ -1391,7 +1392,7 @@ int refs_for_each_ref_in(struct ref_store *refs, const char *prefix,\n \n int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data)\n {\n-\treturn refs_for_each_ref_in(get_main_ref_store(), prefix, fn, cb_data);\n+\treturn refs_for_each_ref_in(get_main_ref_store(the_repository), prefix, fn, cb_data);\n }\n \n int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data, unsigned int broken)\n@@ -1400,7 +1401,7 @@ int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data, unsig\n \n \tif (broken)\n \t\tflag = DO_FOR_EACH_INCLUDE_BROKEN;\n-\treturn do_for_each_ref(get_main_ref_store(),\n+\treturn do_for_each_ref(get_main_ref_store(the_repository),\n \t\t\t       prefix, fn, 0, flag, cb_data);\n }\n \n@@ -1417,7 +1418,7 @@ int refs_for_each_fullref_in(struct ref_store *refs, const char *prefix,\n \n int for_each_replace_ref_the_repository(each_ref_fn fn, void *cb_data)\n {\n-\treturn do_for_each_ref(get_main_ref_store(),\n+\treturn do_for_each_ref(get_main_ref_store(the_repository),\n \t\t\t       git_replace_ref_base, fn,\n \t\t\t       strlen(git_replace_ref_base),\n \t\t\t       DO_FOR_EACH_INCLUDE_BROKEN, cb_data);\n@@ -1428,7 +1429,7 @@ int for_each_namespaced_ref(each_ref_fn fn, void *cb_data)\n \tstruct strbuf buf = STRBUF_INIT;\n \tint ret;\n \tstrbuf_addf(&buf, \"%srefs/\", get_git_namespace());\n-\tret = do_for_each_ref(get_main_ref_store(),\n+\tret = do_for_each_ref(get_main_ref_store(the_repository),\n \t\t\t      buf.buf, fn, 0, 0, cb_data);\n \tstrbuf_release(&buf);\n \treturn ret;\n@@ -1442,7 +1443,7 @@ int refs_for_each_rawref(struct ref_store *refs, each_ref_fn fn, void *cb_data)\n \n int for_each_rawref(each_ref_fn fn, void *cb_data)\n {\n-\treturn refs_for_each_rawref(get_main_ref_store(), fn, cb_data);\n+\treturn refs_for_each_rawref(get_main_ref_store(the_repository), fn, cb_data);\n }\n \n int refs_read_raw_ref(struct ref_store *ref_store,\n@@ -1548,7 +1549,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,\n /* backend functions */\n int refs_init_db(struct strbuf *err)\n {\n-\tstruct ref_store *refs = get_main_ref_store();\n+\tstruct ref_store *refs = get_main_ref_store(the_repository);\n \n \treturn refs->be->init_db(refs, err);\n }\n@@ -1556,7 +1557,7 @@ int refs_init_db(struct strbuf *err)\n const char *resolve_ref_unsafe(const char *refname, int resolve_flags,\n \t\t\t       struct object_id *oid, int *flags)\n {\n-\treturn refs_resolve_ref_unsafe(get_main_ref_store(), refname,\n+\treturn refs_resolve_ref_unsafe(get_main_ref_store(the_repository), refname,\n \t\t\t\t       resolve_flags, oid, flags);\n }\n \n@@ -1652,7 +1653,7 @@ static struct ref_store *ref_store_init(const char *gitdir,\n \treturn refs;\n }\n \n-struct ref_store *get_main_ref_store(void)\n+struct ref_store *get_main_ref_store_the_repository(void)\n {\n \tif (main_ref_store)\n \t\treturn main_ref_store;\n@@ -1727,7 +1728,7 @@ struct ref_store *get_worktree_ref_store(const struct worktree *wt)\n \tconst char *id;\n \n \tif (wt->is_current)\n-\t\treturn get_main_ref_store();\n+\t\treturn get_main_ref_store(the_repository);\n \n \tid = wt->id ? wt->id : \"/\";\n \trefs = lookup_ref_store_map(&worktree_ref_stores, id);\n@@ -1783,7 +1784,7 @@ int refs_peel_ref(struct ref_store *refs, const char *refname,\n \n int peel_ref(const char *refname, struct object_id *oid)\n {\n-\treturn refs_peel_ref(get_main_ref_store(), refname, oid);\n+\treturn refs_peel_ref(get_main_ref_store(the_repository), refname, oid);\n }\n \n int refs_create_symref(struct ref_store *refs,\n@@ -1799,7 +1800,7 @@ int refs_create_symref(struct ref_store *refs,\n int create_symref(const char *ref_target, const char *refs_heads_master,\n \t\t  const char *logmsg)\n {\n-\treturn refs_create_symref(get_main_ref_store(), ref_target,\n+\treturn refs_create_symref(get_main_ref_store(the_repository), ref_target,\n \t\t\t\t  refs_heads_master, logmsg);\n }\n \n@@ -2007,7 +2008,7 @@ int refs_for_each_reflog(struct ref_store *refs, each_ref_fn fn, void *cb_data)\n \n int for_each_reflog(each_ref_fn fn, void *cb_data)\n {\n-\treturn refs_for_each_reflog(get_main_ref_store(), fn, cb_data);\n+\treturn refs_for_each_reflog(get_main_ref_store(the_repository), fn, cb_data);\n }\n \n int refs_for_each_reflog_ent_reverse(struct ref_store *refs,\n@@ -2022,7 +2023,7 @@ int refs_for_each_reflog_ent_reverse(struct ref_store *refs,\n int for_each_reflog_ent_reverse(const char *refname, each_reflog_ent_fn fn,\n \t\t\t\tvoid *cb_data)\n {\n-\treturn refs_for_each_reflog_ent_reverse(get_main_ref_store(),\n+\treturn refs_for_each_reflog_ent_reverse(get_main_ref_store(the_repository),\n \t\t\t\t\t\trefname, fn, cb_data);\n }\n \n@@ -2035,7 +2036,7 @@ int refs_for_each_reflog_ent(struct ref_store *refs, const char *refname,\n int for_each_reflog_ent(const char *refname, each_reflog_ent_fn fn,\n \t\t\tvoid *cb_data)\n {\n-\treturn refs_for_each_reflog_ent(get_main_ref_store(), refname,\n+\treturn refs_for_each_reflog_ent(get_main_ref_store(the_repository), refname,\n \t\t\t\t\tfn, cb_data);\n }\n \n@@ -2046,7 +2047,7 @@ int refs_reflog_exists(struct ref_store *refs, const char *refname)\n \n int reflog_exists(const char *refname)\n {\n-\treturn refs_reflog_exists(get_main_ref_store(), refname);\n+\treturn refs_reflog_exists(get_main_ref_store(the_repository), refname);\n }\n \n int refs_create_reflog(struct ref_store *refs, const char *refname,\n@@ -2058,7 +2059,7 @@ int refs_create_reflog(struct ref_store *refs, const char *refname,\n int safe_create_reflog(const char *refname, int force_create,\n \t\t       struct strbuf *err)\n {\n-\treturn refs_create_reflog(get_main_ref_store(), refname,\n+\treturn refs_create_reflog(get_main_ref_store(the_repository), refname,\n \t\t\t\t  force_create, err);\n }\n \n@@ -2069,7 +2070,7 @@ int refs_delete_reflog(struct ref_store *refs, const char *refname)\n \n int delete_reflog(const char *refname)\n {\n-\treturn refs_delete_reflog(get_main_ref_store(), refname);\n+\treturn refs_delete_reflog(get_main_ref_store(the_repository), refname);\n }\n \n int refs_reflog_expire(struct ref_store *refs,\n@@ -2092,7 +2093,7 @@ int reflog_expire(const char *refname, const struct object_id *oid,\n \t\t  reflog_expiry_cleanup_fn cleanup_fn,\n \t\t  void *policy_cb_data)\n {\n-\treturn refs_reflog_expire(get_main_ref_store(),\n+\treturn refs_reflog_expire(get_main_ref_store(the_repository),\n \t\t\t\t  refname, oid, flags,\n \t\t\t\t  prepare_fn, should_prune_fn,\n \t\t\t\t  cleanup_fn, policy_cb_data);\n@@ -2115,7 +2116,7 @@ int refs_delete_refs(struct ref_store *refs, const char *msg,\n int delete_refs(const char *msg, struct string_list *refnames,\n \t\tunsigned int flags)\n {\n-\treturn refs_delete_refs(get_main_ref_store(), msg, refnames, flags);\n+\treturn refs_delete_refs(get_main_ref_store(the_repository), msg, refnames, flags);\n }\n \n int refs_rename_ref(struct ref_store *refs, const char *oldref,\n@@ -2126,7 +2127,7 @@ int refs_rename_ref(struct ref_store *refs, const char *oldref,\n \n int rename_ref(const char *oldref, const char *newref, const char *logmsg)\n {\n-\treturn refs_rename_ref(get_main_ref_store(), oldref, newref, logmsg);\n+\treturn refs_rename_ref(get_main_ref_store(the_repository), oldref, newref, logmsg);\n }\n \n int refs_copy_existing_ref(struct ref_store *refs, const char *oldref,\n@@ -2137,5 +2138,5 @@ int refs_copy_existing_ref(struct ref_store *refs, const char *oldref,\n \n int copy_existing_ref(const char *oldref, const char *newref, const char *logmsg)\n {\n-\treturn refs_copy_existing_ref(get_main_ref_store(), oldref, newref, logmsg);\n+\treturn refs_copy_existing_ref(get_main_ref_store(the_repository), oldref, newref, logmsg);\n }\ndiff --git a/refs.h b/refs.h\nindex 546fa9e65a..ab3d2bec2f 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -760,7 +760,9 @@ int reflog_expire(const char *refname, const struct object_id *oid,\n \n int ref_storage_backend_exists(const char *name);\n \n-struct ref_store *get_main_ref_store(void);\n+#define get_main_ref_store(r) \\\n+\tget_main_ref_store_##r()\n+struct ref_store *get_main_ref_store_the_repository(void);\n /*\n  * Return the ref_store instance for the specified submodule. For the\n  * main repository, use submodule==NULL; such a call cannot fail. For\ndiff --git a/revision.c b/revision.c\nindex 9ede92c09e..e98bdf2ac7 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -7,6 +7,7 @@\n #include \"diff.h\"\n #include \"refs.h\"\n #include \"revision.h\"\n+#include \"repository.h\"\n #include \"graph.h\"\n #include \"grep.h\"\n #include \"reflog-walk.h\"\n@@ -1280,7 +1281,7 @@ void add_reflogs_to_pending(struct rev_info *revs, unsigned flags)\n \n \tcb.all_revs = revs;\n \tcb.all_flags = flags;\n-\tcb.refs = get_main_ref_store();\n+\tcb.refs = get_main_ref_store(the_repository);\n \tfor_each_reflog(handle_one_reflog, &cb);\n \n \tif (!revs->single_worktree)\n@@ -2168,7 +2169,7 @@ static int handle_revision_pseudo_opt(const char *submodule,\n \t\t\tdie(\"BUG: --single-worktree cannot be used together with submodule\");\n \t\trefs = get_submodule_ref_store(submodule);\n \t} else\n-\t\trefs = get_main_ref_store();\n+\t\trefs = get_main_ref_store(the_repository);\n \n \t/*\n \t * NOTE!\ndiff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c\nindex 4b96dfe12f..93ea6f781e 100644\n--- a/t/helper/test-ref-store.c\n+++ b/t/helper/test-ref-store.c\n@@ -2,6 +2,7 @@\n #include \"alternates.h\"\n #include \"refs.h\"\n #include \"worktree.h\"\n+#include \"repository.h\"\n \n static const char *notnull(const char *arg, const char *name)\n {\n@@ -22,7 +23,7 @@ static const char **get_store(const char **argv, struct ref_store **refs)\n \tif (!argv[0]) {\n \t\tdie(\"ref store required\");\n \t} else if (!strcmp(argv[0], \"main\")) {\n-\t\t*refs = get_main_ref_store();\n+\t\t*refs = get_main_ref_store(the_repository);\n \t} else if (skip_prefix(argv[0], \"submodule:\", &gitdir)) {\n \t\tstruct strbuf sb = STRBUF_INIT;\n \t\tint ret;\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338319","messageId":"20180205235735.216710-33-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 053/194] replace-object: add repository argument to register_replace_object","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:14Z","receivedAt":"2018-02-06T00:05:15Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow the register_replace_object caller\nto be more specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n replace-object.c | 8 +++++---\n 1 file changed, 5 insertions(+), 3 deletions(-)\n\ndiff --git a/replace-object.c b/replace-object.c\nindex 102e009927..1479530d34 100644\n--- a/replace-object.c\n+++ b/replace-object.c\n@@ -18,8 +18,10 @@ static int replace_object_pos(const unsigned char *sha1)\n \t\t\treplace_sha1_access);\n }\n \n-static int register_replace_object(struct replace_object *replace,\n-\t\t\t\t   int ignore_dups)\n+#define register_replace_object(r, rp, i) \\\n+\tregister_replace_object_##r(rp, i)\n+static int register_replace_object_the_repository(struct replace_object *replace,\n+\t\t\t\t\t\t  int ignore_dups)\n {\n \tint pos = replace_object_pos(replace->original);\n \n@@ -65,7 +67,7 @@ static int register_replace_ref(const char *refname,\n \thashcpy(repl_obj->replacement, oid->hash);\n \n \t/* Register new object */\n-\tif (register_replace_object(repl_obj, 1))\n+\tif (register_replace_object(the_repository, repl_obj, 1))\n \t\tdie(\"duplicate replace ref: %s\", refname);\n \n \treturn 0;\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338320","messageId":"20180205235735.216710-34-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 054/194] replace-object: add repository argument to register_replace_ref","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:15Z","receivedAt":"2018-02-06T00:05:17Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Unlike the other conversions this just takes the repository as the cb_data.\n\nNEEDSWORK: callback interface doesn't supply a repository argument, so\nwe have to supply it ourselves as cb_data. It would be nicer to update\nthe callback interface in for_each_replace_ref to pass on the\nrepository at the same time as it gets a repository argument.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n replace-object.c | 5 ++++-\n 1 file changed, 4 insertions(+), 1 deletion(-)\n\ndiff --git a/replace-object.c b/replace-object.c\nindex 1479530d34..8d3e0a30fb 100644\n--- a/replace-object.c\n+++ b/replace-object.c\n@@ -52,6 +52,8 @@ static int register_replace_ref(const char *refname,\n \t\t\t\tconst struct object_id *oid,\n \t\t\t\tint flag, void *cb_data)\n {\n+\tstruct repository *r = cb_data;\n+\n \t/* Get sha1 from refname */\n \tconst char *slash = strrchr(refname, '/');\n \tconst char *hash = slash ? slash + 1 : refname;\n@@ -67,6 +69,7 @@ static int register_replace_ref(const char *refname,\n \thashcpy(repl_obj->replacement, oid->hash);\n \n \t/* Register new object */\n+\t(void)r;\n \tif (register_replace_object(the_repository, repl_obj, 1))\n \t\tdie(\"duplicate replace ref: %s\", refname);\n \n@@ -78,7 +81,7 @@ static void prepare_replace_object(void)\n \tif (the_repository->objects.replacements.prepared)\n \t\treturn;\n \n-\tfor_each_replace_ref(the_repository, register_replace_ref, NULL);\n+\tfor_each_replace_ref(the_repository, register_replace_ref, the_repository);\n \tthe_repository->objects.replacements.prepared = 1;\n }\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338321","messageId":"20180205235735.216710-35-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 055/194] replace-object: add repository argument to replace_object_pos","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:16Z","receivedAt":"2018-02-06T00:05:47Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow the replace_object_pos caller\nto be more specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n replace-object.c | 8 +++++---\n 1 file changed, 5 insertions(+), 3 deletions(-)\n\ndiff --git a/replace-object.c b/replace-object.c\nindex 8d3e0a30fb..4a07f82aa0 100644\n--- a/replace-object.c\n+++ b/replace-object.c\n@@ -11,7 +11,9 @@ static const unsigned char *replace_sha1_access(size_t index, void *table)\n \treturn replace[index]->original;\n }\n \n-static int replace_object_pos(const unsigned char *sha1)\n+#define replace_object_pos(r, s) \\\n+\treplace_object_pos_##r(s)\n+static int replace_object_pos_the_repository(const unsigned char *sha1)\n {\n \treturn sha1_pos(sha1, the_repository->objects.replacements.items,\n \t\t\tthe_repository->objects.replacements.nr,\n@@ -23,7 +25,7 @@ static int replace_object_pos(const unsigned char *sha1)\n static int register_replace_object_the_repository(struct replace_object *replace,\n \t\t\t\t\t\t  int ignore_dups)\n {\n-\tint pos = replace_object_pos(replace->original);\n+\tint pos = replace_object_pos(the_repository, replace->original);\n \n \tif (0 <= pos) {\n \t\tif (ignore_dups)\n@@ -108,7 +110,7 @@ const unsigned char *do_lookup_replace_object_the_repository(const unsigned char\n \t\t\tdie(\"replace depth too high for object %s\",\n \t\t\t    sha1_to_hex(sha1));\n \n-\t\tpos = replace_object_pos(cur);\n+\t\tpos = replace_object_pos(the_repository, cur);\n \t\tif (0 <= pos)\n \t\t\tcur = the_repository->objects.replacements.items[pos]->replacement;\n \t} while (0 <= pos);\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338322","messageId":"20180205235735.216710-36-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 056/194] replace-object: allow replace_object_pos to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:17Z","receivedAt":"2018-02-06T00:05:53Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n replace-object.c | 8 +++-----\n 1 file changed, 3 insertions(+), 5 deletions(-)\n\ndiff --git a/replace-object.c b/replace-object.c\nindex 4a07f82aa0..c30bee2e69 100644\n--- a/replace-object.c\n+++ b/replace-object.c\n@@ -11,12 +11,10 @@ static const unsigned char *replace_sha1_access(size_t index, void *table)\n \treturn replace[index]->original;\n }\n \n-#define replace_object_pos(r, s) \\\n-\treplace_object_pos_##r(s)\n-static int replace_object_pos_the_repository(const unsigned char *sha1)\n+static int replace_object_pos(struct repository *r, const unsigned char *sha1)\n {\n-\treturn sha1_pos(sha1, the_repository->objects.replacements.items,\n-\t\t\tthe_repository->objects.replacements.nr,\n+\treturn sha1_pos(sha1, r->objects.replacements.items,\n+\t\t\tr->objects.replacements.nr,\n \t\t\treplace_sha1_access);\n }\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338323","messageId":"20180205235735.216710-37-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 057/194] replace-object: allow register_replace_object to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:18Z","receivedAt":"2018-02-06T00:06:14Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n replace-object.c | 33 ++++++++++++++++-----------------\n 1 file changed, 16 insertions(+), 17 deletions(-)\n\ndiff --git a/replace-object.c b/replace-object.c\nindex c30bee2e69..31b6b3044e 100644\n--- a/replace-object.c\n+++ b/replace-object.c\n@@ -18,33 +18,32 @@ static int replace_object_pos(struct repository *r, const unsigned char *sha1)\n \t\t\treplace_sha1_access);\n }\n \n-#define register_replace_object(r, rp, i) \\\n-\tregister_replace_object_##r(rp, i)\n-static int register_replace_object_the_repository(struct replace_object *replace,\n-\t\t\t\t\t\t  int ignore_dups)\n+static int register_replace_object(struct repository *r,\n+\t\t\t\t   struct replace_object *replace,\n+\t\t\t\t   int ignore_dups)\n {\n-\tint pos = replace_object_pos(the_repository, replace->original);\n+\tint pos = replace_object_pos(r, replace->original);\n \n \tif (0 <= pos) {\n \t\tif (ignore_dups)\n \t\t\tfree(replace);\n \t\telse {\n-\t\t\tfree(the_repository->objects.replacements.items[pos]);\n-\t\t\tthe_repository->objects.replacements.items[pos] = replace;\n+\t\t\tfree(r->objects.replacements.items[pos]);\n+\t\t\tr->objects.replacements.items[pos] = replace;\n \t\t}\n \t\treturn 1;\n \t}\n \tpos = -pos - 1;\n-\tALLOC_GROW(the_repository->objects.replacements.items,\n-\t\t   the_repository->objects.replacements.nr + 1,\n-\t\t   the_repository->objects.replacements.alloc);\n-\tthe_repository->objects.replacements.nr++;\n-\tif (pos < the_repository->objects.replacements.nr)\n-\t\tmemmove(the_repository->objects.replacements.items + pos + 1,\n-\t\t\tthe_repository->objects.replacements.items + pos,\n-\t\t\t(the_repository->objects.replacements.nr - pos - 1) *\n-\t\t\tsizeof(*the_repository->objects.replacements.items));\n-\tthe_repository->objects.replacements.items[pos] = replace;\n+\tALLOC_GROW(r->objects.replacements.items,\n+\t\t   r->objects.replacements.nr + 1,\n+\t\t   r->objects.replacements.alloc);\n+\tr->objects.replacements.nr++;\n+\tif (pos < r->objects.replacements.nr)\n+\t\tmemmove(r->objects.replacements.items + pos + 1,\n+\t\t\tr->objects.replacements.items + pos,\n+\t\t\t(r->objects.replacements.nr - pos - 1) *\n+\t\t\tsizeof(*r->objects.replacements.items));\n+\tr->objects.replacements.items[pos] = replace;\n \treturn 0;\n }\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338324","messageId":"20180205235735.216710-38-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 058/194] replace-object: add repository argument to prepare_replace_object","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:19Z","receivedAt":"2018-02-06T00:06:19Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow the prepare_replace_object caller\nto be more specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n replace-object.c | 6 ++++--\n 1 file changed, 4 insertions(+), 2 deletions(-)\n\ndiff --git a/replace-object.c b/replace-object.c\nindex 31b6b3044e..cba88f50e3 100644\n--- a/replace-object.c\n+++ b/replace-object.c\n@@ -75,7 +75,9 @@ static int register_replace_ref(const char *refname,\n \treturn 0;\n }\n \n-static void prepare_replace_object(void)\n+#define prepare_replace_object(r) \\\n+\tprepare_replace_object_##r()\n+static void prepare_replace_object_the_repository(void)\n {\n \tif (the_repository->objects.replacements.prepared)\n \t\treturn;\n@@ -99,7 +101,7 @@ const unsigned char *do_lookup_replace_object_the_repository(const unsigned char\n \tint pos, depth = MAXREPLACEDEPTH;\n \tconst unsigned char *cur = sha1;\n \n-\tprepare_replace_object();\n+\tprepare_replace_object(the_repository);\n \n \t/* Try to recursively replace the object */\n \tdo {\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338325","messageId":"20180205235735.216710-39-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 059/194] refs: store the main ref store inside the repository struct","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:20Z","receivedAt":"2018-02-06T00:06:43Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n refs.c       | 13 +++++--------\n refs.h       |  4 +---\n repository.c |  2 +-\n repository.h |  5 +++++\n 4 files changed, 12 insertions(+), 12 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex c2dee7a69a..f079d65030 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -1609,9 +1609,6 @@ static struct ref_store_hash_entry *alloc_ref_store_hash_entry(\n \treturn entry;\n }\n \n-/* A pointer to the ref_store for the main repository: */\n-static struct ref_store *main_ref_store;\n-\n /* A hashmap of ref_stores, stored by submodule name: */\n static struct hashmap submodule_ref_stores;\n \n@@ -1653,13 +1650,13 @@ static struct ref_store *ref_store_init(const char *gitdir,\n \treturn refs;\n }\n \n-struct ref_store *get_main_ref_store_the_repository(void)\n+struct ref_store *get_main_ref_store(struct repository *r)\n {\n-\tif (main_ref_store)\n-\t\treturn main_ref_store;\n+\tif (r->main_ref_store)\n+\t\treturn r->main_ref_store;\n \n-\tmain_ref_store = ref_store_init(get_git_dir(), REF_STORE_ALL_CAPS);\n-\treturn main_ref_store;\n+\tr->main_ref_store = ref_store_init(r->gitdir, REF_STORE_ALL_CAPS);\n+\treturn r->main_ref_store;\n }\n \n /*\ndiff --git a/refs.h b/refs.h\nindex ab3d2bec2f..f5ab68c0ed 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -760,9 +760,7 @@ int reflog_expire(const char *refname, const struct object_id *oid,\n \n int ref_storage_backend_exists(const char *name);\n \n-#define get_main_ref_store(r) \\\n-\tget_main_ref_store_##r()\n-struct ref_store *get_main_ref_store_the_repository(void);\n+struct ref_store *get_main_ref_store(struct repository *r);\n /*\n  * Return the ref_store instance for the specified submodule. For the\n  * main repository, use submodule==NULL; such a call cannot fail. For\ndiff --git a/repository.c b/repository.c\nindex 0ec9648f53..6f85fade82 100644\n--- a/repository.c\n+++ b/repository.c\n@@ -6,7 +6,7 @@\n \n /* The main repository */\n static struct repository the_repo = {\n-\tNULL, NULL, NULL, OBJECT_STORE_INIT,\n+\tNULL, NULL, NULL, OBJECT_STORE_INIT, NULL,\n \tNULL, NULL, NULL, NULL, NULL, NULL, &the_index, NULL, 0, 0\n };\n struct repository *the_repository = &the_repo;\ndiff --git a/repository.h b/repository.h\nindex ba7b3b7cb9..727ddcea5b 100644\n--- a/repository.h\n+++ b/repository.h\n@@ -33,6 +33,11 @@ struct repository {\n \t */\n \tstruct object_store objects;\n \n+\t/*\n+\t * The store in which the refs are hold.\n+\t */\n+\tstruct ref_store *main_ref_store;\n+\n \t/*\n \t * Path to the repository's graft file.\n \t * Cannot be NULL after initialization.\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338326","messageId":"20180205235735.216710-40-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 060/194] refs: allow for_each_replace_ref to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:21Z","receivedAt":"2018-02-06T00:06:45Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n refs.c | 4 ++--\n refs.h | 4 +---\n 2 files changed, 3 insertions(+), 5 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex f079d65030..e534ff4256 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -1416,9 +1416,9 @@ int refs_for_each_fullref_in(struct ref_store *refs, const char *prefix,\n \treturn do_for_each_ref(refs, prefix, fn, 0, flag, cb_data);\n }\n \n-int for_each_replace_ref_the_repository(each_ref_fn fn, void *cb_data)\n+int for_each_replace_ref(struct repository *r, each_ref_fn fn, void *cb_data)\n {\n-\treturn do_for_each_ref(get_main_ref_store(the_repository),\n+\treturn do_for_each_ref(get_main_ref_store(r),\n \t\t\t       git_replace_ref_base, fn,\n \t\t\t       strlen(git_replace_ref_base),\n \t\t\t       DO_FOR_EACH_INCLUDE_BROKEN, cb_data);\ndiff --git a/refs.h b/refs.h\nindex f5ab68c0ed..15f3a91cc4 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -300,9 +300,7 @@ int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data,\n int for_each_tag_ref(each_ref_fn fn, void *cb_data);\n int for_each_branch_ref(each_ref_fn fn, void *cb_data);\n int for_each_remote_ref(each_ref_fn fn, void *cb_data);\n-#define for_each_replace_ref(r, fn, cb) \\\n-\tfor_each_replace_ref_##r(fn, cb)\n-int for_each_replace_ref_the_repository(each_ref_fn fn, void *cb_data);\n+int for_each_replace_ref(struct repository *r, each_ref_fn fn, void *cb_data);\n int for_each_glob_ref(each_ref_fn fn, const char *pattern, void *cb_data);\n int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,\n \t\t\t const char *prefix, void *cb_data);\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338327","messageId":"20180205235735.216710-41-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 061/194] replace-object: allow prepare_replace_object to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:22Z","receivedAt":"2018-02-06T00:07:05Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n replace-object.c | 10 ++++------\n 1 file changed, 4 insertions(+), 6 deletions(-)\n\ndiff --git a/replace-object.c b/replace-object.c\nindex cba88f50e3..d9250a7cf8 100644\n--- a/replace-object.c\n+++ b/replace-object.c\n@@ -75,15 +75,13 @@ static int register_replace_ref(const char *refname,\n \treturn 0;\n }\n \n-#define prepare_replace_object(r) \\\n-\tprepare_replace_object_##r()\n-static void prepare_replace_object_the_repository(void)\n+static void prepare_replace_object(struct repository *r)\n {\n-\tif (the_repository->objects.replacements.prepared)\n+\tif (r->objects.replacements.prepared)\n \t\treturn;\n \n-\tfor_each_replace_ref(the_repository, register_replace_ref, the_repository);\n-\tthe_repository->objects.replacements.prepared = 1;\n+\tfor_each_replace_ref(r, register_replace_ref, r);\n+\tr->objects.replacements.prepared = 1;\n }\n \n /* We allow \"recursive\" replacement. Only within reason, though */\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338328","messageId":"20180205235735.216710-43-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 063/194] replace-object: add repository argument to lookup_replace_object","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:24Z","receivedAt":"2018-02-06T00:07:37Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow callers of lookup_replace_object\nto be more specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n builtin/mktag.c  | 2 +-\n object.c         | 2 +-\n replace-object.h | 3 ++-\n sha1_file.c      | 6 +++---\n streaming.c      | 2 +-\n 5 files changed, 8 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin/mktag.c b/builtin/mktag.c\nindex 93934e8e4b..ab41735f2a 100644\n--- a/builtin/mktag.c\n+++ b/builtin/mktag.c\n@@ -26,7 +26,7 @@ static int verify_object(const unsigned char *sha1, const char *expected_type)\n \tenum object_type type;\n \tunsigned long size;\n \tvoid *buffer = read_sha1_file(sha1, &type, &size);\n-\tconst unsigned char *repl = lookup_replace_object(sha1);\n+\tconst unsigned char *repl = lookup_replace_object(the_repository, sha1);\n \n \tif (buffer) {\n \t\tif (type == type_from_string(expected_type))\ndiff --git a/object.c b/object.c\nindex fc0ccbefef..a5cafb10e7 100644\n--- a/object.c\n+++ b/object.c\n@@ -246,7 +246,7 @@ struct object *parse_object(const struct object_id *oid)\n \tunsigned long size;\n \tenum object_type type;\n \tint eaten;\n-\tconst unsigned char *repl = lookup_replace_object(oid->hash);\n+\tconst unsigned char *repl = lookup_replace_object(the_repository, oid->hash);\n \tvoid *buffer;\n \tstruct object *obj;\n \ndiff --git a/replace-object.h b/replace-object.h\nindex 67a433d5a5..c61ee66e95 100644\n--- a/replace-object.h\n+++ b/replace-object.h\n@@ -21,7 +21,8 @@ extern const unsigned char *do_lookup_replace_object(struct repository *r, const\n  * either sha1 or a pointer to a permanently-allocated value.  When\n  * object replacement is suppressed, always return sha1.\n  */\n-static inline const unsigned char *lookup_replace_object(const unsigned char *sha1)\n+#define lookup_replace_object(r, s) lookup_replace_object_##r(s)\n+static inline const unsigned char *lookup_replace_object_the_repository(const unsigned char *sha1)\n {\n \tif (!check_replace_refs ||\n \t    (the_repository->objects.replacements.prepared &&\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 8ee86f8ede..a6df4b61c7 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -1243,7 +1243,7 @@ int sha1_object_info_extended_the_repository(const unsigned char *sha1, struct o\n \tstruct pack_entry e;\n \tint rtype;\n \tconst unsigned char *real = (flags & OBJECT_INFO_LOOKUP_REPLACE) ?\n-\t\t\t\t    lookup_replace_object(sha1) :\n+\t\t\t\t    lookup_replace_object(the_repository, sha1) :\n \t\t\t\t    sha1;\n \n \tif (is_null_sha1(real))\n@@ -1369,8 +1369,8 @@ void *read_sha1_file_extended(const unsigned char *sha1,\n \tconst struct packed_git *p;\n \tconst char *path;\n \tstruct stat st;\n-\tconst unsigned char *repl = lookup_replace ? lookup_replace_object(sha1)\n-\t\t\t\t\t\t   : sha1;\n+\tconst unsigned char *repl = lookup_replace ?\n+\t\tlookup_replace_object(the_repository, sha1) : sha1;\n \n \terrno = 0;\n \tdata = read_object(repl, type, size);\ndiff --git a/streaming.c b/streaming.c\nindex c47600e719..bc3c4811ca 100644\n--- a/streaming.c\n+++ b/streaming.c\n@@ -140,7 +140,7 @@ struct git_istream *open_istream(const unsigned char *sha1,\n {\n \tstruct git_istream *st;\n \tstruct object_info oi = OBJECT_INFO_INIT;\n-\tconst unsigned char *real = lookup_replace_object(sha1);\n+\tconst unsigned char *real = lookup_replace_object(the_repository, sha1);\n \tenum input_source src = istream_source(real, type, &oi);\n \n \tif (src < 0)\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338329","messageId":"20180205235735.216710-42-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 062/194] replace_object: allow do_lookup_replace_object to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:23Z","receivedAt":"2018-02-06T00:07:41Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n replace-object.c | 9 +++++----\n replace-object.h | 3 +--\n 2 files changed, 6 insertions(+), 6 deletions(-)\n\ndiff --git a/replace-object.c b/replace-object.c\nindex d9250a7cf8..a6a34217d8 100644\n--- a/replace-object.c\n+++ b/replace-object.c\n@@ -94,12 +94,13 @@ static void prepare_replace_object(struct repository *r)\n  * permanently-allocated value.  This function always respects replace\n  * references, regardless of the value of check_replace_refs.\n  */\n-const unsigned char *do_lookup_replace_object_the_repository(const unsigned char *sha1)\n+const unsigned char *do_lookup_replace_object(struct repository *r,\n+\t\t\t\t\t      const unsigned char *sha1)\n {\n \tint pos, depth = MAXREPLACEDEPTH;\n \tconst unsigned char *cur = sha1;\n \n-\tprepare_replace_object(the_repository);\n+\tprepare_replace_object(r);\n \n \t/* Try to recursively replace the object */\n \tdo {\n@@ -107,9 +108,9 @@ const unsigned char *do_lookup_replace_object_the_repository(const unsigned char\n \t\t\tdie(\"replace depth too high for object %s\",\n \t\t\t    sha1_to_hex(sha1));\n \n-\t\tpos = replace_object_pos(the_repository, cur);\n+\t\tpos = replace_object_pos(r, cur);\n \t\tif (0 <= pos)\n-\t\t\tcur = the_repository->objects.replacements.items[pos]->replacement;\n+\t\t\tcur = r->objects.replacements.items[pos]->replacement;\n \t} while (0 <= pos);\n \n \treturn cur;\ndiff --git a/replace-object.h b/replace-object.h\nindex 8af730f5e3..67a433d5a5 100644\n--- a/replace-object.h\n+++ b/replace-object.h\n@@ -13,8 +13,7 @@ struct replace_object {\n  * This internal function is only declared here for the benefit of\n  * lookup_replace_object().  Please do not call it directly.\n  */\n-#define do_lookup_replace_object(r, s) do_lookup_replace_object_##r(s)\n-extern const unsigned char *do_lookup_replace_object_the_repository(const unsigned char *sha1);\n+extern const unsigned char *do_lookup_replace_object(struct repository *r, const unsigned char *sha1);\n \n /*\n  * If object sha1 should be replaced, return the replacement object's\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338330","messageId":"20180205235735.216710-44-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 064/194] repository: allow lookup_replace_object to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:25Z","receivedAt":"2018-02-06T00:07:43Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n replace-object.h | 10 +++++-----\n 1 file changed, 5 insertions(+), 5 deletions(-)\n\ndiff --git a/replace-object.h b/replace-object.h\nindex c61ee66e95..f4666afc2a 100644\n--- a/replace-object.h\n+++ b/replace-object.h\n@@ -21,14 +21,14 @@ extern const unsigned char *do_lookup_replace_object(struct repository *r, const\n  * either sha1 or a pointer to a permanently-allocated value.  When\n  * object replacement is suppressed, always return sha1.\n  */\n-#define lookup_replace_object(r, s) lookup_replace_object_##r(s)\n-static inline const unsigned char *lookup_replace_object_the_repository(const unsigned char *sha1)\n+static inline const unsigned char *lookup_replace_object(struct repository *r,\n+\t\t\t\t\t\t\t const unsigned char *sha1)\n {\n \tif (!check_replace_refs ||\n-\t    (the_repository->objects.replacements.prepared &&\n-\t     the_repository->objects.replacements.nr == 0))\n+\t    (r->objects.replacements.prepared &&\n+\t     r->objects.replacements.nr == 0))\n \t\treturn sha1;\n-\treturn do_lookup_replace_object(the_repository, sha1);\n+\treturn do_lookup_replace_object(r, sha1);\n }\n \n #endif /* REPLACE_OBJECT_H */\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338332","messageId":"20180205235735.216710-45-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 065/194] object-store: add repository argument to sha1_object_info","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:26Z","receivedAt":"2018-02-06T00:08:03Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow the callers of sha1_object_info\nto be more specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nIn the expanded macro the identifier `the_repository` is not actually used,\nso the compiler does not catch if the repository.h header is not included\nat the call site. call sites needing that #include were identified by\nchanging the macro to definition to\n\n  #define sha1_object_info(r, sha1, size) \\\n      (r, sha1_object_info_##r(sha1, size)).\n\nThis produces a compiler warning about the left hand side of the comma\noperator being unused, which can be suppressed using -Wno-unused-value.\n\nTo avoid breaking bisection, do not include this trick in the patch.\n\nThere is a large number of callers. The included coccinelle semantic patch\nwill adapt any new callers in the diff produced by `make coccicheck`.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n archive-tar.c                             |  3 ++-\n archive-zip.c                             |  4 +++-\n blame.c                                   |  5 +++--\n builtin/cat-file.c                        |  6 +++---\n builtin/fast-export.c                     |  3 ++-\n builtin/fetch.c                           |  3 ++-\n builtin/fsck.c                            |  3 ++-\n builtin/index-pack.c                      |  7 +++++--\n builtin/ls-tree.c                         |  3 ++-\n builtin/mktree.c                          |  3 ++-\n builtin/pack-objects.c                    |  9 ++++++---\n builtin/prune.c                           |  3 ++-\n builtin/replace.c                         | 12 +++++++-----\n builtin/tag.c                             |  5 +++--\n builtin/unpack-objects.c                  |  4 +++-\n contrib/coccinelle/sha1_object_info.cocci |  7 +++++++\n diff.c                                    |  4 +++-\n fast-import.c                             | 16 +++++++++++-----\n list-objects-filter.c                     |  2 +-\n object-store.h                            |  5 ++++-\n object.c                                  |  2 +-\n pack-bitmap-write.c                       |  4 +++-\n packfile.c                                |  2 +-\n reachable.c                               |  2 +-\n refs.c                                    |  2 +-\n remote.c                                  |  3 ++-\n sequencer.c                               |  5 ++++-\n sha1_file.c                               |  4 ++--\n sha1_name.c                               | 12 ++++++------\n submodule.c                               |  2 +-\n tag.c                                     |  3 ++-\n 31 files changed, 97 insertions(+), 51 deletions(-)\n create mode 100644 contrib/coccinelle/sha1_object_info.cocci\n\ndiff --git a/archive-tar.c b/archive-tar.c\nindex 909347c108..b10c9b8911 100644\n--- a/archive-tar.c\n+++ b/archive-tar.c\n@@ -5,6 +5,7 @@\n #include \"config.h\"\n #include \"tar.h\"\n #include \"archive.h\"\n+#include \"repository.h\"\n #include \"object-store.h\"\n #include \"streaming.h\"\n #include \"run-command.h\"\n@@ -277,7 +278,7 @@ static int write_tar_entry(struct archiver_args *args,\n \t\tmemcpy(header.name, path, pathlen);\n \n \tif (S_ISREG(mode) && !args->convert &&\n-\t    sha1_object_info(sha1, &size) == OBJ_BLOB &&\n+\t    sha1_object_info(the_repository, sha1, &size) == OBJ_BLOB &&\n \t    size > big_file_threshold)\n \t\tbuffer = NULL;\n \telse if (S_ISLNK(mode) || S_ISREG(mode)) {\ndiff --git a/archive-zip.c b/archive-zip.c\nindex 233fed3a61..03321b9777 100644\n--- a/archive-zip.c\n+++ b/archive-zip.c\n@@ -6,6 +6,7 @@\n #include \"archive.h\"\n #include \"streaming.h\"\n #include \"utf8.h\"\n+#include \"repository.h\"\n #include \"object-store.h\"\n #include \"userdiff.h\"\n #include \"xdiff-interface.h\"\n@@ -326,7 +327,8 @@ static int write_zip_entry(struct archiver_args *args,\n \t\tcompressed_size = 0;\n \t\tbuffer = NULL;\n \t} else if (S_ISREG(mode) || S_ISLNK(mode)) {\n-\t\tenum object_type type = sha1_object_info(sha1, &size);\n+\t\tenum object_type type = sha1_object_info(the_repository, sha1,\n+\t\t\t\t\t\t\t &size);\n \n \t\tmethod = 0;\n \t\tattr2 = S_ISLNK(mode) ? ((mode | 0777) << 16) :\ndiff --git a/blame.c b/blame.c\nindex 61f0f6bb40..f95a53898d 100644\n--- a/blame.c\n+++ b/blame.c\n@@ -1,5 +1,6 @@\n #include \"cache.h\"\n #include \"refs.h\"\n+#include \"repository.h\"\n #include \"object-store.h\"\n #include \"cache-tree.h\"\n #include \"mergesort.h\"\n@@ -82,7 +83,7 @@ static void verify_working_tree_path(struct commit *work_tree, const char *path)\n \t\tunsigned mode;\n \n \t\tif (!get_tree_entry(commit_oid->hash, path, blob_oid.hash, &mode) &&\n-\t\t    sha1_object_info(blob_oid.hash, NULL) == OBJ_BLOB)\n+\t\t    sha1_object_info(the_repository, blob_oid.hash, NULL) == OBJ_BLOB)\n \t\t\treturn;\n \t}\n \n@@ -507,7 +508,7 @@ static int fill_blob_sha1_and_mode(struct blame_origin *origin)\n \t\t\t   origin->path,\n \t\t\t   origin->blob_oid.hash, &origin->mode))\n \t\tgoto error_out;\n-\tif (sha1_object_info(origin->blob_oid.hash, NULL) != OBJ_BLOB)\n+\tif (sha1_object_info(the_repository, origin->blob_oid.hash, NULL) != OBJ_BLOB)\n \t\tgoto error_out;\n \treturn 0;\n  error_out:\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex fdc70aa419..96c834b8f4 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -117,7 +117,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,\n \t\t/* else fallthrough */\n \n \tcase 'p':\n-\t\ttype = sha1_object_info(oid.hash, NULL);\n+\t\ttype = sha1_object_info(the_repository, oid.hash, NULL);\n \t\tif (type < 0)\n \t\t\tdie(\"Not a valid object name %s\", obj_name);\n \n@@ -141,7 +141,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,\n \tcase 0:\n \t\tif (type_from_string(exp_type) == OBJ_BLOB) {\n \t\t\tstruct object_id blob_oid;\n-\t\t\tif (sha1_object_info(oid.hash, NULL) == OBJ_TAG) {\n+\t\t\tif (sha1_object_info(the_repository, oid.hash, NULL) == OBJ_TAG) {\n \t\t\t\tchar *buffer = read_sha1_file(oid.hash, &type, &size);\n \t\t\t\tconst char *target;\n \t\t\t\tif (!skip_prefix(buffer, \"object \", &target) ||\n@@ -151,7 +151,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,\n \t\t\t} else\n \t\t\t\toidcpy(&blob_oid, &oid);\n \n-\t\t\tif (sha1_object_info(blob_oid.hash, NULL) == OBJ_BLOB)\n+\t\t\tif (sha1_object_info(the_repository, blob_oid.hash, NULL) == OBJ_BLOB)\n \t\t\t\treturn stream_blob_to_fd(1, &blob_oid, NULL, 0);\n \t\t\t/*\n \t\t\t * we attempted to dereference a tag to a blob\ndiff --git a/builtin/fast-export.c b/builtin/fast-export.c\nindex f76b7bda79..d4e53908c6 100644\n--- a/builtin/fast-export.c\n+++ b/builtin/fast-export.c\n@@ -7,6 +7,7 @@\n #include \"cache.h\"\n #include \"config.h\"\n #include \"refs.h\"\n+#include \"repository.h\"\n #include \"object-store.h\"\n #include \"commit.h\"\n #include \"object.h\"\n@@ -948,7 +949,7 @@ static void import_marks(char *input_file)\n \t\tif (last_idnum < mark)\n \t\t\tlast_idnum = mark;\n \n-\t\ttype = sha1_object_info(oid.hash, NULL);\n+\t\ttype = sha1_object_info(the_repository, oid.hash, NULL);\n \t\tif (type < 0)\n \t\t\tdie(\"object not found: %s\", oid_to_hex(&oid));\n \ndiff --git a/builtin/fetch.c b/builtin/fetch.c\nindex 9b7202953b..276beebbb1 100644\n--- a/builtin/fetch.c\n+++ b/builtin/fetch.c\n@@ -5,6 +5,7 @@\n #include \"config.h\"\n #include \"repository.h\"\n #include \"refs.h\"\n+#include \"repository.h\"\n #include \"object-store.h\"\n #include \"commit.h\"\n #include \"builtin.h\"\n@@ -624,7 +625,7 @@ static int update_local_ref(struct ref *ref,\n \tstruct branch *current_branch = branch_get(NULL);\n \tconst char *pretty_ref = prettify_refname(ref->name);\n \n-\ttype = sha1_object_info(ref->new_oid.hash, NULL);\n+\ttype = sha1_object_info(the_repository, ref->new_oid.hash, NULL);\n \tif (type < 0)\n \t\tdie(_(\"object %s not found\"), oid_to_hex(&ref->new_oid));\n \ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex 920cc50923..f5e3c51077 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -69,7 +69,8 @@ static const char *printable_type(struct object *obj)\n \tconst char *ret;\n \n \tif (obj->type == OBJ_NONE) {\n-\t\tenum object_type type = sha1_object_info(obj->oid.hash, NULL);\n+\t\tenum object_type type = sha1_object_info(the_repository,\n+\t\t\t\t\t\t\t obj->oid.hash, NULL);\n \t\tif (type > 0)\n \t\t\tobject_as_type(obj, type, 0);\n \t}\ndiff --git a/builtin/index-pack.c b/builtin/index-pack.c\nindex 1902d4e096..b9851ad69d 100644\n--- a/builtin/index-pack.c\n+++ b/builtin/index-pack.c\n@@ -12,6 +12,7 @@\n #include \"exec_cmd.h\"\n #include \"streaming.h\"\n #include \"thread-utils.h\"\n+#include \"repository.h\"\n #include \"object-store.h\"\n #include \"packfile.h\"\n \n@@ -222,7 +223,8 @@ static unsigned check_object(struct object *obj)\n \n \tif (!(obj->flags & FLAG_CHECKED)) {\n \t\tunsigned long size;\n-\t\tint type = sha1_object_info(obj->oid.hash, &size);\n+\t\tint type = sha1_object_info(the_repository, obj->oid.hash,\n+\t\t\t\t\t    &size);\n \t\tif (type <= 0)\n \t\t\tdie(_(\"did not receive expected object %s\"),\n \t\t\t      oid_to_hex(&obj->oid));\n@@ -811,7 +813,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,\n \t\tenum object_type has_type;\n \t\tunsigned long has_size;\n \t\tread_lock();\n-\t\thas_type = sha1_object_info(oid->hash, &has_size);\n+\t\thas_type = sha1_object_info(the_repository, oid->hash,\n+\t\t\t\t\t    &has_size);\n \t\tif (has_type < 0)\n \t\t\tdie(_(\"cannot read existing object info %s\"), oid_to_hex(oid));\n \t\tif (has_type != type || has_size != size)\ndiff --git a/builtin/ls-tree.c b/builtin/ls-tree.c\nindex 78fcced566..d929da03b4 100644\n--- a/builtin/ls-tree.c\n+++ b/builtin/ls-tree.c\n@@ -5,6 +5,7 @@\n  */\n #include \"cache.h\"\n #include \"config.h\"\n+#include \"repository.h\"\n #include \"object-store.h\"\n #include \"blob.h\"\n #include \"tree.h\"\n@@ -95,7 +96,7 @@ static int show_tree(const unsigned char *sha1, struct strbuf *base,\n \t\t\tchar size_text[24];\n \t\t\tif (!strcmp(type, blob_type)) {\n \t\t\t\tunsigned long size;\n-\t\t\t\tif (sha1_object_info(sha1, &size) == OBJ_BAD)\n+\t\t\t\tif (sha1_object_info(the_repository, sha1, &size) == OBJ_BAD)\n \t\t\t\t\txsnprintf(size_text, sizeof(size_text),\n \t\t\t\t\t\t  \"BAD\");\n \t\t\t\telse\ndiff --git a/builtin/mktree.c b/builtin/mktree.c\nindex 0f66946618..ccb3a7a897 100644\n--- a/builtin/mktree.c\n+++ b/builtin/mktree.c\n@@ -7,6 +7,7 @@\n #include \"quote.h\"\n #include \"tree.h\"\n #include \"parse-options.h\"\n+#include \"repository.h\"\n #include \"object-store.h\"\n \n static struct treeent {\n@@ -117,7 +118,7 @@ static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_miss\n \t}\n \n \t/* Check the type of object identified by sha1 */\n-\tobj_type = sha1_object_info(sha1, NULL);\n+\tobj_type = sha1_object_info(the_repository, sha1, NULL);\n \tif (obj_type < 0) {\n \t\tif (allow_missing) {\n \t\t\t; /* no problem - missing objects are presumed to be of the right type */\ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex 7cb73c29ac..79ec5c6842 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -1519,7 +1519,8 @@ static void check_object(struct object_entry *entry)\n \t\tunuse_pack(&w_curs);\n \t}\n \n-\tentry->type = sha1_object_info(entry->idx.oid.hash, &entry->size);\n+\tentry->type = sha1_object_info(the_repository, entry->idx.oid.hash,\n+\t\t\t\t       &entry->size);\n \t/*\n \t * The error condition is checked in prepare_pack().  This is\n \t * to permit a missing preferred base object to be ignored\n@@ -1581,7 +1582,8 @@ static void drop_reused_delta(struct object_entry *entry)\n \t\t * And if that fails, the error will be recorded in entry->type\n \t\t * and dealt with in prepare_pack().\n \t\t */\n-\t\tentry->type = sha1_object_info(entry->idx.oid.hash,\n+\t\tentry->type = sha1_object_info(the_repository,\n+\t\t\t\t\t       entry->idx.oid.hash,\n \t\t\t\t\t       &entry->size);\n \t}\n }\n@@ -2689,7 +2691,8 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs)\n static int add_loose_object(const struct object_id *oid, const char *path,\n \t\t\t    void *data)\n {\n-\tenum object_type type = sha1_object_info(oid->hash, NULL);\n+\tenum object_type type = sha1_object_info(the_repository, oid->hash,\n+\t\t\t\t\t\t NULL);\n \n \tif (type < 0) {\n \t\twarning(\"loose object at %s could not be examined\", path);\ndiff --git a/builtin/prune.c b/builtin/prune.c\nindex 52091f299e..7891048b35 100644\n--- a/builtin/prune.c\n+++ b/builtin/prune.c\n@@ -51,7 +51,8 @@ static int prune_object(const struct object_id *oid, const char *fullpath,\n \tif (st.st_mtime > expire)\n \t\treturn 0;\n \tif (show_only || verbose) {\n-\t\tenum object_type type = sha1_object_info(oid->hash, NULL);\n+\t\tenum object_type type = sha1_object_info(the_repository,\n+\t\t\t\t\t\t\t oid->hash, NULL);\n \t\tprintf(\"%s %s\\n\", oid_to_hex(oid),\n \t\t       (type > 0) ? typename(type) : \"unknown\");\n \t}\ndiff --git a/builtin/replace.c b/builtin/replace.c\nindex 6d27dd73f0..25322d2f73 100644\n--- a/builtin/replace.c\n+++ b/builtin/replace.c\n@@ -55,8 +55,10 @@ static int show_reference(const char *refname, const struct object_id *oid,\n \t\t\tif (get_oid(refname, &object))\n \t\t\t\treturn error(\"Failed to resolve '%s' as a valid ref.\", refname);\n \n-\t\t\tobj_type = sha1_object_info(object.hash, NULL);\n-\t\t\trepl_type = sha1_object_info(oid->hash, NULL);\n+\t\t\tobj_type = sha1_object_info(the_repository,\n+\t\t\t\t\t\t    object.hash, NULL);\n+\t\t\trepl_type = sha1_object_info(the_repository,\n+\t\t\t\t\t\t     oid->hash, NULL);\n \n \t\t\tprintf(\"%s (%s) -> %s (%s)\\n\", refname, typename(obj_type),\n \t\t\t       oid_to_hex(oid), typename(repl_type));\n@@ -164,8 +166,8 @@ static int replace_object_oid(const char *object_ref,\n \tstruct ref_transaction *transaction;\n \tstruct strbuf err = STRBUF_INIT;\n \n-\tobj_type = sha1_object_info(object->hash, NULL);\n-\trepl_type = sha1_object_info(repl->hash, NULL);\n+\tobj_type = sha1_object_info(the_repository, object->hash, NULL);\n+\trepl_type = sha1_object_info(the_repository, repl->hash, NULL);\n \tif (!force && obj_type != repl_type)\n \t\tdie(\"Objects must be of the same type.\\n\"\n \t\t    \"'%s' points to a replaced object of type '%s'\\n\"\n@@ -292,7 +294,7 @@ static int edit_and_replace(const char *object_ref, int force, int raw)\n \tif (get_oid(object_ref, &old) < 0)\n \t\tdie(\"Not a valid object name: '%s'\", object_ref);\n \n-\ttype = sha1_object_info(old.hash, NULL);\n+\ttype = sha1_object_info(the_repository, old.hash, NULL);\n \tif (type < 0)\n \t\tdie(\"unable to get object type for %s\", oid_to_hex(&old));\n \ndiff --git a/builtin/tag.c b/builtin/tag.c\nindex 7ed3506fff..014d7c9e9b 100644\n--- a/builtin/tag.c\n+++ b/builtin/tag.c\n@@ -10,6 +10,7 @@\n #include \"config.h\"\n #include \"builtin.h\"\n #include \"refs.h\"\n+#include \"repository.h\"\n #include \"object-store.h\"\n #include \"tag.h\"\n #include \"run-command.h\"\n@@ -211,7 +212,7 @@ static void create_tag(const struct object_id *object, const char *tag,\n \tstruct strbuf header = STRBUF_INIT;\n \tchar *path = NULL;\n \n-\ttype = sha1_object_info(object->hash, NULL);\n+\ttype = sha1_object_info(the_repository, object->hash, NULL);\n \tif (type <= OBJ_NONE)\n \t    die(_(\"bad object type.\"));\n \n@@ -294,7 +295,7 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb)\n \t}\n \n \tstrbuf_addstr(sb, \" (\");\n-\ttype = sha1_object_info(oid->hash, NULL);\n+\ttype = sha1_object_info(the_repository, oid->hash, NULL);\n \tswitch (type) {\n \tdefault:\n \t\tstrbuf_addstr(sb, \"object of unknown type\");\ndiff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c\nindex 6d03ea2670..ee707068b3 100644\n--- a/builtin/unpack-objects.c\n+++ b/builtin/unpack-objects.c\n@@ -1,6 +1,7 @@\n #include \"builtin.h\"\n #include \"cache.h\"\n #include \"config.h\"\n+#include \"repository.h\"\n #include \"object-store.h\"\n #include \"object.h\"\n #include \"delta.h\"\n@@ -198,7 +199,8 @@ static int check_object(struct object *obj, int type, void *data, struct fsck_op\n \n \tif (!(obj->flags & FLAG_OPEN)) {\n \t\tunsigned long size;\n-\t\tint type = sha1_object_info(obj->oid.hash, &size);\n+\t\tint type = sha1_object_info(the_repository, obj->oid.hash,\n+\t\t\t\t\t    &size);\n \t\tif (type != obj->type || type <= 0)\n \t\t\tdie(\"object of unexpected type\");\n \t\tobj->flags |= FLAG_WRITTEN;\ndiff --git a/contrib/coccinelle/sha1_object_info.cocci b/contrib/coccinelle/sha1_object_info.cocci\nnew file mode 100644\nindex 0000000000..800e0581e5\n--- /dev/null\n+++ b/contrib/coccinelle/sha1_object_info.cocci\n@@ -0,0 +1,7 @@\n+@@\n+expression E;\n+expression F;\n+@@\n+ sha1_object_info(\n++the_repository,\n+ E, F)\ndiff --git a/diff.c b/diff.c\nindex e89c7d9919..08bff6e720 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -13,6 +13,7 @@\n #include \"attr.h\"\n #include \"run-command.h\"\n #include \"utf8.h\"\n+#include \"repository.h\"\n #include \"object-store.h\"\n #include \"userdiff.h\"\n #include \"submodule-config.h\"\n@@ -3616,7 +3617,8 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)\n \telse {\n \t\tenum object_type type;\n \t\tif (size_only || (flags & CHECK_BINARY)) {\n-\t\t\ttype = sha1_object_info(s->oid.hash, &s->size);\n+\t\t\ttype = sha1_object_info(the_repository, s->oid.hash,\n+\t\t\t\t\t\t&s->size);\n \t\t\tif (type < 0)\n \t\t\t\tdie(\"unable to read %s\",\n \t\t\t\t    oid_to_hex(&s->oid));\ndiff --git a/fast-import.c b/fast-import.c\nindex 39cd0b7540..2542f600ef 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -1913,7 +1913,9 @@ static void read_marks(void)\n \t\t\tdie(\"corrupt mark line: %s\", line);\n \t\te = find_object(&oid);\n \t\tif (!e) {\n-\t\t\tenum object_type type = sha1_object_info(oid.hash, NULL);\n+\t\t\tenum object_type type = sha1_object_info(the_repository,\n+\t\t\t\t\t\t\t\t oid.hash,\n+\t\t\t\t\t\t\t\t NULL);\n \t\t\tif (type < 0)\n \t\t\t\tdie(\"object not found: %s\", oid_to_hex(&oid));\n \t\t\te = insert_object(&oid);\n@@ -2443,7 +2445,8 @@ static void file_change_m(const char *p, struct branch *b)\n \t\tenum object_type expected = S_ISDIR(mode) ?\n \t\t\t\t\t\tOBJ_TREE: OBJ_BLOB;\n \t\tenum object_type type = oe ? oe->type :\n-\t\t\t\t\tsha1_object_info(oid.hash, NULL);\n+\t\t\t\t\tsha1_object_info(the_repository,\n+\t\t\t\t\t\t\t oid.hash, NULL);\n \t\tif (type < 0)\n \t\t\tdie(\"%s not found: %s\",\n \t\t\t\t\tS_ISDIR(mode) ?  \"Tree\" : \"Blob\",\n@@ -2603,7 +2606,8 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa\n \t\t\tdie(\"Not a blob (actually a %s): %s\",\n \t\t\t\ttypename(oe->type), command_buf.buf);\n \t} else if (!is_null_oid(&oid)) {\n-\t\tenum object_type type = sha1_object_info(oid.hash, NULL);\n+\t\tenum object_type type = sha1_object_info(the_repository,\n+\t\t\t\t\t\t\t oid.hash, NULL);\n \t\tif (type < 0)\n \t\t\tdie(\"Blob not found: %s\", command_buf.buf);\n \t\tif (type != OBJ_BLOB)\n@@ -2890,7 +2894,8 @@ static void parse_new_tag(const char *arg)\n \t} else if (!get_oid(from, &oid)) {\n \t\tstruct object_entry *oe = find_object(&oid);\n \t\tif (!oe) {\n-\t\t\ttype = sha1_object_info(oid.hash, NULL);\n+\t\t\ttype = sha1_object_info(the_repository, oid.hash,\n+\t\t\t\t\t\tNULL);\n \t\t\tif (type < 0)\n \t\t\t\tdie(\"Not a valid object: %s\", from);\n \t\t} else\n@@ -3048,7 +3053,8 @@ static struct object_entry *dereference(struct object_entry *oe,\n \tunsigned long size;\n \tchar *buf = NULL;\n \tif (!oe) {\n-\t\tenum object_type type = sha1_object_info(oid->hash, NULL);\n+\t\tenum object_type type = sha1_object_info(the_repository,\n+\t\t\t\t\t\t\t oid->hash, NULL);\n \t\tif (type < 0)\n \t\t\tdie(\"object not found: %s\", oid_to_hex(oid));\n \t\t/* cache it! */\ndiff --git a/list-objects-filter.c b/list-objects-filter.c\nindex 4356c45368..180d8729d9 100644\n--- a/list-objects-filter.c\n+++ b/list-objects-filter.c\n@@ -117,7 +117,7 @@ static enum list_objects_filter_result filter_blobs_limit(\n \t\tassert(obj->type == OBJ_BLOB);\n \t\tassert((obj->flags & SEEN) == 0);\n \n-\t\tt = sha1_object_info(obj->oid.hash, &object_length);\n+\t\tt = sha1_object_info(the_repository, obj->oid.hash, &object_length);\n \t\tif (t != OBJ_BLOB) { /* probably OBJ_NONE */\n \t\t\t/*\n \t\t\t * We DO NOT have the blob locally, so we cannot\ndiff --git a/object-store.h b/object-store.h\nindex e1e592bdd5..4ff60e3be0 100644\n--- a/object-store.h\n+++ b/object-store.h\n@@ -91,7 +91,10 @@ static inline void *read_sha1_file(const unsigned char *sha1, enum object_type *\n }\n \n /* Read and unpack a sha1 file into memory, write memory to a sha1 file */\n-extern int sha1_object_info(const unsigned char *, unsigned long *);\n+\n+#define sha1_object_info(r, sha1, size) \\\n+\tsha1_object_info_##r(sha1, size)\n+extern int sha1_object_info_the_repository(const unsigned char *, unsigned long *);\n extern int hash_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *sha1);\n extern int write_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *return_sha1);\n extern int hash_sha1_file_literally(const void *buf, unsigned long len, const char *type, struct object_id *oid, unsigned flags);\ndiff --git a/object.c b/object.c\nindex a5cafb10e7..40f7c7bdab 100644\n--- a/object.c\n+++ b/object.c\n@@ -256,7 +256,7 @@ struct object *parse_object(const struct object_id *oid)\n \n \tif ((obj && obj->type == OBJ_BLOB) ||\n \t    (!obj && has_object_file(oid) &&\n-\t     sha1_object_info(oid->hash, NULL) == OBJ_BLOB)) {\n+\t     sha1_object_info(the_repository, oid->hash, NULL) == OBJ_BLOB)) {\n \t\tif (check_sha1_signature(repl, NULL, 0, NULL) < 0) {\n \t\t\terror(\"sha1 mismatch %s\", oid_to_hex(oid));\n \t\t\treturn NULL;\ndiff --git a/pack-bitmap-write.c b/pack-bitmap-write.c\nindex 6a656104af..f684ed5ea2 100644\n--- a/pack-bitmap-write.c\n+++ b/pack-bitmap-write.c\n@@ -1,4 +1,5 @@\n #include \"cache.h\"\n+#include \"repository.h\"\n #include \"object-store.h\"\n #include \"commit.h\"\n #include \"tag.h\"\n@@ -74,7 +75,8 @@ void bitmap_writer_build_type_index(struct pack_idx_entry **index,\n \t\t\tbreak;\n \n \t\tdefault:\n-\t\t\treal_type = sha1_object_info(entry->idx.oid.hash,\n+\t\t\treal_type = sha1_object_info(the_repository,\n+\t\t\t\t\t\t     entry->idx.oid.hash,\n \t\t\t\t\t\t     NULL);\n \t\t\tbreak;\n \t\t}\ndiff --git a/packfile.c b/packfile.c\nindex b73814f2ce..a1c1b1a42e 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -1092,7 +1092,7 @@ static int retry_bad_packed_offset(struct packed_git *p, off_t obj_offset)\n \t\treturn OBJ_BAD;\n \tsha1 = nth_packed_object_sha1(p, revidx->nr);\n \tmark_bad_packed_object(p, sha1);\n-\ttype = sha1_object_info(sha1, NULL);\n+\ttype = sha1_object_info(the_repository, sha1, NULL);\n \tif (type <= OBJ_NONE)\n \t\treturn OBJ_BAD;\n \treturn type;\ndiff --git a/reachable.c b/reachable.c\nindex ac5224b9a5..7e7b9525c0 100644\n--- a/reachable.c\n+++ b/reachable.c\n@@ -79,7 +79,7 @@ static void add_recent_object(const struct object_id *oid,\n \t * later processing, and the revision machinery expects\n \t * commits and tags to have been parsed.\n \t */\n-\ttype = sha1_object_info(oid->hash, NULL);\n+\ttype = sha1_object_info(the_repository, oid->hash, NULL);\n \tif (type < 0)\n \t\tdie(\"unable to get object info for %s\", oid_to_hex(oid));\n \ndiff --git a/refs.c b/refs.c\nindex e534ff4256..ddcb4a908f 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -303,7 +303,7 @@ enum peel_status peel_object(const struct object_id *name, struct object_id *oid\n \tstruct object *o = lookup_unknown_object(name->hash);\n \n \tif (o->type == OBJ_NONE) {\n-\t\tint type = sha1_object_info(name->hash, NULL);\n+\t\tint type = sha1_object_info(the_repository, name->hash, NULL);\n \t\tif (type < 0 || !object_as_type(o, type, 0))\n \t\t\treturn PEEL_INVALID;\n \t}\ndiff --git a/remote.c b/remote.c\nindex 5112f370c3..fd8cd8ce77 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -2,6 +2,7 @@\n #include \"config.h\"\n #include \"remote.h\"\n #include \"refs.h\"\n+#include \"repository.h\"\n #include \"object-store.h\"\n #include \"commit.h\"\n #include \"diff.h\"\n@@ -1362,7 +1363,7 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds\n \t\t\tcontinue; /* not a tag */\n \t\tif (string_list_has_string(&dst_tag, ref->name))\n \t\t\tcontinue; /* they already have it */\n-\t\tif (sha1_object_info(ref->new_oid.hash, NULL) != OBJ_TAG)\n+\t\tif (sha1_object_info(the_repository, ref->new_oid.hash, NULL) != OBJ_TAG)\n \t\t\tcontinue; /* be conservative */\n \t\titem = string_list_append(&src_tag, ref->name);\n \t\titem->util = ref;\ndiff --git a/sequencer.c b/sequencer.c\nindex 234addd4e7..311f00acda 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -3,6 +3,7 @@\n #include \"lockfile.h\"\n #include \"sequencer.h\"\n #include \"dir.h\"\n+#include \"repository.h\"\n #include \"object-store.h\"\n #include \"object.h\"\n #include \"commit.h\"\n@@ -2347,7 +2348,9 @@ int sequencer_pick_revisions(struct replay_opts *opts)\n \n \t\tif (!get_oid(name, &oid)) {\n \t\t\tif (!lookup_commit_reference_gently(&oid, 1)) {\n-\t\t\t\tenum object_type type = sha1_object_info(oid.hash, NULL);\n+\t\t\t\tenum object_type type = sha1_object_info(the_repository,\n+\t\t\t\t\t\t\t\t\t oid.hash,\n+\t\t\t\t\t\t\t\t\t NULL);\n \t\t\t\treturn error(_(\"%s: can't cherry-pick a %s\"),\n \t\t\t\t\tname, typename(type));\n \t\t\t}\ndiff --git a/sha1_file.c b/sha1_file.c\nindex a6df4b61c7..01bdb3cd7a 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -1310,7 +1310,7 @@ int sha1_object_info_extended_the_repository(const unsigned char *sha1, struct o\n }\n \n /* returns enum object_type or negative */\n-int sha1_object_info(const unsigned char *sha1, unsigned long *sizep)\n+int sha1_object_info_the_repository(const unsigned char *sha1, unsigned long *sizep)\n {\n \tenum object_type type;\n \tstruct object_info oi = OBJECT_INFO_INIT;\n@@ -1962,7 +1962,7 @@ int read_pack_header(int fd, struct pack_header *header)\n \n void assert_sha1_type(const unsigned char *sha1, enum object_type expect)\n {\n-\tenum object_type type = sha1_object_info(sha1, NULL);\n+\tenum object_type type = sha1_object_info(the_repository, sha1, NULL);\n \tif (type < 0)\n \t\tdie(\"%s is not a valid object\", sha1_to_hex(sha1));\n \tif (type != expect)\ndiff --git a/sha1_name.c b/sha1_name.c\nindex 03ce2ff7f2..190710c638 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -243,7 +243,7 @@ static int finish_object_disambiguation(struct disambiguate_state *ds,\n \n static int disambiguate_commit_only(const struct object_id *oid, void *cb_data_unused)\n {\n-\tint kind = sha1_object_info(oid->hash, NULL);\n+\tint kind = sha1_object_info(the_repository, oid->hash, NULL);\n \treturn kind == OBJ_COMMIT;\n }\n \n@@ -252,7 +252,7 @@ static int disambiguate_committish_only(const struct object_id *oid, void *cb_da\n \tstruct object *obj;\n \tint kind;\n \n-\tkind = sha1_object_info(oid->hash, NULL);\n+\tkind = sha1_object_info(the_repository, oid->hash, NULL);\n \tif (kind == OBJ_COMMIT)\n \t\treturn 1;\n \tif (kind != OBJ_TAG)\n@@ -267,7 +267,7 @@ static int disambiguate_committish_only(const struct object_id *oid, void *cb_da\n \n static int disambiguate_tree_only(const struct object_id *oid, void *cb_data_unused)\n {\n-\tint kind = sha1_object_info(oid->hash, NULL);\n+\tint kind = sha1_object_info(the_repository, oid->hash, NULL);\n \treturn kind == OBJ_TREE;\n }\n \n@@ -276,7 +276,7 @@ static int disambiguate_treeish_only(const struct object_id *oid, void *cb_data_\n \tstruct object *obj;\n \tint kind;\n \n-\tkind = sha1_object_info(oid->hash, NULL);\n+\tkind = sha1_object_info(the_repository, oid->hash, NULL);\n \tif (kind == OBJ_TREE || kind == OBJ_COMMIT)\n \t\treturn 1;\n \tif (kind != OBJ_TAG)\n@@ -291,7 +291,7 @@ static int disambiguate_treeish_only(const struct object_id *oid, void *cb_data_\n \n static int disambiguate_blob_only(const struct object_id *oid, void *cb_data_unused)\n {\n-\tint kind = sha1_object_info(oid->hash, NULL);\n+\tint kind = sha1_object_info(the_repository, oid->hash, NULL);\n \treturn kind == OBJ_BLOB;\n }\n \n@@ -370,7 +370,7 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)\n \tif (ds->fn && !ds->fn(oid, ds->cb_data))\n \t\treturn 0;\n \n-\ttype = sha1_object_info(oid->hash, NULL);\n+\ttype = sha1_object_info(the_repository, oid->hash, NULL);\n \tif (type == OBJ_COMMIT) {\n \t\tstruct commit *commit = lookup_commit(oid);\n \t\tif (commit) {\ndiff --git a/submodule.c b/submodule.c\nindex f7736ec4b5..dc57c176e8 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -818,7 +818,7 @@ static int check_has_commit(const struct object_id *oid, void *data)\n {\n \tstruct has_commit_data *cb = data;\n \n-\tenum object_type type = sha1_object_info(oid->hash, NULL);\n+\tenum object_type type = sha1_object_info(the_repository, oid->hash, NULL);\n \n \tswitch (type) {\n \tcase OBJ_COMMIT:\ndiff --git a/tag.c b/tag.c\nindex 30798abf1f..7b32afd123 100644\n--- a/tag.c\n+++ b/tag.c\n@@ -1,5 +1,6 @@\n #include \"cache.h\"\n #include \"tag.h\"\n+#include \"repository.h\"\n #include \"object-store.h\"\n #include \"commit.h\"\n #include \"tree.h\"\n@@ -42,7 +43,7 @@ int gpg_verify_tag(const struct object_id *oid, const char *name_to_report,\n \tunsigned long size;\n \tint ret;\n \n-\ttype = sha1_object_info(oid->hash, NULL);\n+\ttype = sha1_object_info(the_repository, oid->hash, NULL);\n \tif (type != OBJ_TAG)\n \t\treturn error(\"%s: cannot verify a non-tag object of type %s.\",\n \t\t\t\tname_to_report ?\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338333","messageId":"20180205235735.216710-46-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 066/194] pack: add repository argument to retry_bad_packed_offset","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:27Z","receivedAt":"2018-02-06T00:08:04Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow the callers of retry_bad_packed_offset\nto be more specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n packfile.c | 8 +++++---\n 1 file changed, 5 insertions(+), 3 deletions(-)\n\ndiff --git a/packfile.c b/packfile.c\nindex a1c1b1a42e..66391b8a6f 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -1082,7 +1082,9 @@ static const unsigned char *get_delta_base_sha1(struct packed_git *p,\n \t\treturn NULL;\n }\n \n-static int retry_bad_packed_offset(struct packed_git *p, off_t obj_offset)\n+#define retry_bad_packed_offset(r, p, o) \\\n+\tretry_bad_packed_offset_##r(p, o)\n+static int retry_bad_packed_offset_the_repository(struct packed_git *p, off_t obj_offset)\n {\n \tint type;\n \tstruct revindex_entry *revidx;\n@@ -1131,7 +1133,7 @@ static enum object_type packed_to_object_type(struct packed_git *p,\n \t\tif (type <= OBJ_NONE) {\n \t\t\t/* If getting the base itself fails, we first\n \t\t\t * retry the base, otherwise unwind */\n-\t\t\ttype = retry_bad_packed_offset(p, base_offset);\n+\t\t\ttype = retry_bad_packed_offset(the_repository, p, base_offset);\n \t\t\tif (type > OBJ_NONE)\n \t\t\t\tgoto out;\n \t\t\tgoto unwind;\n@@ -1159,7 +1161,7 @@ static enum object_type packed_to_object_type(struct packed_git *p,\n unwind:\n \twhile (poi_stack_nr) {\n \t\tobj_offset = poi_stack[--poi_stack_nr];\n-\t\ttype = retry_bad_packed_offset(p, obj_offset);\n+\t\ttype = retry_bad_packed_offset(the_repository, p, obj_offset);\n \t\tif (type > OBJ_NONE)\n \t\t\tgoto out;\n \t}\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338334","messageId":"20180205235735.216710-47-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 067/194] pack: add repository argument to packed_to_object_type","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:28Z","receivedAt":"2018-02-06T00:08:31Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow the callers of packed_to_object_type\nto be more specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n packfile.c | 16 +++++++++-------\n 1 file changed, 9 insertions(+), 7 deletions(-)\n\ndiff --git a/packfile.c b/packfile.c\nindex 66391b8a6f..250c9af1a7 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -1102,11 +1102,13 @@ static int retry_bad_packed_offset_the_repository(struct packed_git *p, off_t ob\n \n #define POI_STACK_PREALLOC 64\n \n-static enum object_type packed_to_object_type(struct packed_git *p,\n-\t\t\t\t\t      off_t obj_offset,\n-\t\t\t\t\t      enum object_type type,\n-\t\t\t\t\t      struct pack_window **w_curs,\n-\t\t\t\t\t      off_t curpos)\n+#define packed_to_object_type(r, p, o, t, w, c) \\\n+\tpacked_to_object_type_##r(p, o, t, w, c)\n+static enum object_type packed_to_object_type_the_repository(struct packed_git *p,\n+\t\t\t\t\t\t\t     off_t obj_offset,\n+\t\t\t\t\t\t\t     enum object_type type,\n+\t\t\t\t\t\t\t     struct pack_window **w_curs,\n+\t\t\t\t\t\t\t     off_t curpos)\n {\n \toff_t small_poi_stack[POI_STACK_PREALLOC];\n \toff_t *poi_stack = small_poi_stack;\n@@ -1356,8 +1358,8 @@ int packed_object_info(struct packed_git *p, off_t obj_offset,\n \n \tif (oi->typep || oi->typename) {\n \t\tenum object_type ptot;\n-\t\tptot = packed_to_object_type(p, obj_offset, type, &w_curs,\n-\t\t\t\t\t     curpos);\n+\t\tptot = packed_to_object_type(the_repository, p, obj_offset,\n+\t\t\t\t\t     type, &w_curs, curpos);\n \t\tif (oi->typep)\n \t\t\t*oi->typep = ptot;\n \t\tif (oi->typename) {\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338335","messageId":"20180205235735.216710-48-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 068/194] pack: add repository argument to packed_object_info","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:29Z","receivedAt":"2018-02-06T00:08:32Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nAdd a repository argument to allow callers of packed_object_info to be\nmore specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n builtin/pack-objects.c | 3 ++-\n packfile.c             | 4 ++--\n packfile.h             | 3 ++-\n sha1_file.c            | 2 +-\n 4 files changed, 7 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex 79ec5c6842..4e59e496dc 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -1575,7 +1575,8 @@ static void drop_reused_delta(struct object_entry *entry)\n \n \toi.sizep = &entry->size;\n \toi.typep = &entry->type;\n-\tif (packed_object_info(entry->in_pack, entry->in_pack_offset, &oi) < 0) {\n+\tif (packed_object_info(the_repository, entry->in_pack,\n+\t\t\t       entry->in_pack_offset, &oi) < 0) {\n \t\t/*\n \t\t * We failed to get the info from this pack for some reason;\n \t\t * fall back to sha1_object_info, which may find another copy.\ndiff --git a/packfile.c b/packfile.c\nindex 250c9af1a7..61e84a789c 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -1311,8 +1311,8 @@ static void add_delta_base_cache(struct packed_git *p, off_t base_offset,\n \thashmap_add(&delta_base_cache, ent);\n }\n \n-int packed_object_info(struct packed_git *p, off_t obj_offset,\n-\t\t       struct object_info *oi)\n+int packed_object_info_the_repository(struct packed_git *p, off_t obj_offset,\n+\t\t\t\t      struct object_info *oi)\n {\n \tstruct pack_window *w_curs = NULL;\n \tunsigned long size;\ndiff --git a/packfile.h b/packfile.h\nindex 0c314eea93..bb1d92b849 100644\n--- a/packfile.h\n+++ b/packfile.h\n@@ -135,7 +135,8 @@ extern void release_pack_memory(size_t);\n /* global flag to enable extra checks when accessing packed objects */\n extern int do_check_packed_object_crc;\n \n-extern int packed_object_info(struct packed_git *pack, off_t offset, struct object_info *);\n+#define packed_object_info(r, p, o, oi) packed_object_info_##r(p, o, oi)\n+extern int packed_object_info_the_repository(struct packed_git *pack, off_t offset, struct object_info *);\n \n extern void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1);\n extern const struct packed_git *has_packed_and_bad(const unsigned char *sha1);\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 01bdb3cd7a..299e8be72c 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -1294,7 +1294,7 @@ int sha1_object_info_extended_the_repository(const unsigned char *sha1, struct o\n \t\t */\n \t\treturn 0;\n \n-\trtype = packed_object_info(e.p, e.offset, oi);\n+\trtype = packed_object_info(the_repository, e.p, e.offset, oi);\n \tif (rtype < 0) {\n \t\tmark_bad_packed_object(e.p, real);\n \t\treturn sha1_object_info_extended(the_repository, real, oi,\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338336","messageId":"20180205235735.216710-49-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 069/194] pack: add repository argument to find_pack_entry","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:30Z","receivedAt":"2018-02-06T00:08:56Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nAdd a repository argument to allow callers of find_pack_entry to be\nmore specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n packfile.c  | 4 ++--\n packfile.h  | 3 ++-\n sha1_file.c | 6 +++---\n 3 files changed, 7 insertions(+), 6 deletions(-)\n\ndiff --git a/packfile.c b/packfile.c\nindex 61e84a789c..f641f6329a 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -1835,7 +1835,7 @@ static int fill_pack_entry(const unsigned char *sha1,\n  * Iff a pack file contains the object named by sha1, return true and\n  * store its location to e.\n  */\n-int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)\n+int find_pack_entry_the_repository(const unsigned char *sha1, struct pack_entry *e)\n {\n \tstruct mru_entry *p;\n \n@@ -1855,7 +1855,7 @@ int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)\n int has_sha1_pack(const unsigned char *sha1)\n {\n \tstruct pack_entry e;\n-\treturn find_pack_entry(sha1, &e);\n+\treturn find_pack_entry(the_repository, sha1, &e);\n }\n \n int has_pack_index(const unsigned char *sha1)\ndiff --git a/packfile.h b/packfile.h\nindex bb1d92b849..b42e5c2db1 100644\n--- a/packfile.h\n+++ b/packfile.h\n@@ -141,7 +141,8 @@ extern int packed_object_info_the_repository(struct packed_git *pack, off_t offs\n extern void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1);\n extern const struct packed_git *has_packed_and_bad(const unsigned char *sha1);\n \n-extern int find_pack_entry(const unsigned char *sha1, struct pack_entry *e);\n+#define find_pack_entry(r, s, e) find_pack_entry_##r(s, e)\n+extern int find_pack_entry_the_repository(const unsigned char *sha1, struct pack_entry *e);\n \n extern int has_sha1_pack(const unsigned char *sha1);\n \ndiff --git a/sha1_file.c b/sha1_file.c\nindex 299e8be72c..7e06ece5f3 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -1272,7 +1272,7 @@ int sha1_object_info_extended_the_repository(const unsigned char *sha1, struct o\n \t\t}\n \t}\n \n-\tif (!find_pack_entry(real, &e)) {\n+\tif (!find_pack_entry(the_repository, real, &e)) {\n \t\t/* Most likely it's a loose object. */\n \t\tif (!sha1_loose_object_info(the_repository, real, oi, flags))\n \t\t\treturn 0;\n@@ -1282,7 +1282,7 @@ int sha1_object_info_extended_the_repository(const unsigned char *sha1, struct o\n \t\t\treturn -1;\n \t\t} else {\n \t\t\treprepare_packed_git(the_repository);\n-\t\t\tif (!find_pack_entry(real, &e))\n+\t\t\tif (!find_pack_entry(the_repository, real, &e))\n \t\t\t\treturn -1;\n \t\t}\n \t}\n@@ -1648,7 +1648,7 @@ static int freshen_loose_object(const unsigned char *sha1)\n static int freshen_packed_object(const unsigned char *sha1)\n {\n \tstruct pack_entry e;\n-\tif (!find_pack_entry(sha1, &e))\n+\tif (!find_pack_entry(the_repository, sha1, &e))\n \t\treturn 0;\n \tif (e.p->freshened)\n \t\treturn 1;\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338337","messageId":"20180205235735.216710-50-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 070/194] packfile: add repository argument to read_object","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:31Z","receivedAt":"2018-02-06T00:08:59Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow the callers of read_object\nto be more specific about which repository to act on. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n packfile.c | 8 +++++---\n 1 file changed, 5 insertions(+), 3 deletions(-)\n\ndiff --git a/packfile.c b/packfile.c\nindex f641f6329a..56b2db8b06 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -1447,8 +1447,10 @@ struct unpack_entry_stack_ent {\n \tunsigned long size;\n };\n \n-static void *read_object(const unsigned char *sha1, enum object_type *type,\n-\t\t\t unsigned long *size)\n+#define read_object(r, s, t, sz) read_object_##r(s, t, sz)\n+static void *read_object_the_repository(const unsigned char *sha1,\n+\t\t\t\t\tenum object_type *type,\n+\t\t\t\t\tunsigned long *size)\n {\n \tstruct object_info oi = OBJECT_INFO_INIT;\n \tvoid *content;\n@@ -1592,7 +1594,7 @@ void *unpack_entry(struct packed_git *p, off_t obj_offset,\n \t\t\t\t      sha1_to_hex(base_sha1), (uintmax_t)obj_offset,\n \t\t\t\t      p->pack_name);\n \t\t\t\tmark_bad_packed_object(p, base_sha1);\n-\t\t\t\tbase = read_object(base_sha1, &type, &base_size);\n+\t\t\t\tbase = read_object(the_repository, base_sha1, &type, &base_size);\n \t\t\t\texternal_base = base;\n \t\t\t}\n \t\t}\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338338","messageId":"20180205235735.216710-51-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 071/194] packfile: add repository argument to unpack_entry","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:32Z","receivedAt":"2018-02-06T00:09:24Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow the callers of unpack_entry\nto be more specific about which repository to act on. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n fast-import.c | 2 +-\n pack-check.c  | 3 ++-\n packfile.c    | 7 ++++---\n packfile.h    | 3 ++-\n 4 files changed, 9 insertions(+), 6 deletions(-)\n\ndiff --git a/fast-import.c b/fast-import.c\nindex 2542f600ef..5618087015 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -1372,7 +1372,7 @@ static void *gfi_unpack_entry(\n \t\t */\n \t\tp->pack_size = pack_size + 20;\n \t}\n-\treturn unpack_entry(p, oe->idx.offset, &type, sizep);\n+\treturn unpack_entry(the_repository, p, oe->idx.offset, &type, sizep);\n }\n \n static const char *get_mode(const char *str, uint16_t *modep)\ndiff --git a/pack-check.c b/pack-check.c\nindex c80c3ed8fd..25afd59c7d 100644\n--- a/pack-check.c\n+++ b/pack-check.c\n@@ -1,4 +1,5 @@\n #include \"cache.h\"\n+#include \"repository.h\"\n #include \"pack.h\"\n #include \"object-store.h\"\n #include \"pack-revindex.h\"\n@@ -134,7 +135,7 @@ static int verify_packfile(struct packed_git *p,\n \t\t\tdata = NULL;\n \t\t\tdata_valid = 0;\n \t\t} else {\n-\t\t\tdata = unpack_entry(p, entries[i].offset, &type, &size);\n+\t\t\tdata = unpack_entry(the_repository, p, entries[i].offset, &type, &size);\n \t\t\tdata_valid = 1;\n \t\t}\n \ndiff --git a/packfile.c b/packfile.c\nindex 56b2db8b06..69a1cedbe1 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -1257,7 +1257,7 @@ static void *cache_or_unpack_entry(struct packed_git *p, off_t base_offset,\n \n \tent = get_delta_base_cache_entry(p, base_offset);\n \tif (!ent)\n-\t\treturn unpack_entry(p, base_offset, type, base_size);\n+\t\treturn unpack_entry(the_repository, p, base_offset, type, base_size);\n \n \tif (type)\n \t\t*type = ent->type;\n@@ -1463,8 +1463,9 @@ static void *read_object_the_repository(const unsigned char *sha1,\n \treturn content;\n }\n \n-void *unpack_entry(struct packed_git *p, off_t obj_offset,\n-\t\t   enum object_type *final_type, unsigned long *final_size)\n+void *unpack_entry_the_repository(struct packed_git *p, off_t obj_offset,\n+\t\t\t\t  enum object_type *final_type,\n+\t\t\t\t  unsigned long *final_size)\n {\n \tstruct pack_window *w_curs = NULL;\n \toff_t curpos = obj_offset;\ndiff --git a/packfile.h b/packfile.h\nindex b42e5c2db1..615c58cbac 100644\n--- a/packfile.h\n+++ b/packfile.h\n@@ -125,7 +125,8 @@ extern off_t nth_packed_object_offset(const struct packed_git *, uint32_t n);\n extern off_t find_pack_entry_one(const unsigned char *sha1, struct packed_git *);\n \n extern int is_pack_valid(struct packed_git *);\n-extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsigned long *);\n+#define unpack_entry(r, p, of, ot, s) unpack_entry_##r(p, of, ot, s)\n+extern void *unpack_entry_the_repository(struct packed_git *, off_t, enum object_type *, unsigned long *);\n extern unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep);\n extern unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t);\n extern int unpack_object_header(struct packed_git *, struct pack_window **, off_t *, unsigned long *);\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338339","messageId":"20180205235735.216710-52-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 072/194] packfile: add repository argument to cache_or_unpack_entry","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:33Z","receivedAt":"2018-02-06T00:09:26Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow the callers of cache_or_unpack_entry\nto be more specific about which repository to act on. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n packfile.c | 5 +++--\n 1 file changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/packfile.c b/packfile.c\nindex 69a1cedbe1..9f7ca8f211 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -1250,7 +1250,8 @@ static void detach_delta_base_cache_entry(struct delta_base_cache_entry *ent)\n \tfree(ent);\n }\n \n-static void *cache_or_unpack_entry(struct packed_git *p, off_t base_offset,\n+#define cache_or_unpack_entry(r, p, bo, bs, t) cache_or_unpack_entry_##r(p, bo, bs, t)\n+static void *cache_or_unpack_entry_the_repository(struct packed_git *p, off_t base_offset,\n \tunsigned long *base_size, enum object_type *type)\n {\n \tstruct delta_base_cache_entry *ent;\n@@ -1324,7 +1325,7 @@ int packed_object_info_the_repository(struct packed_git *p, off_t obj_offset,\n \t * a \"real\" type later if the caller is interested.\n \t */\n \tif (oi->contentp) {\n-\t\t*oi->contentp = cache_or_unpack_entry(p, obj_offset, oi->sizep,\n+\t\t*oi->contentp = cache_or_unpack_entry(the_repository, p, obj_offset, oi->sizep,\n \t\t\t\t\t\t      &type);\n \t\tif (!*oi->contentp)\n \t\t\ttype = OBJ_BAD;\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338340","messageId":"20180205235735.216710-53-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 073/194] pack: allow find_pack_entry to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:34Z","receivedAt":"2018-02-06T00:09:51Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n packfile.c | 12 +++++++-----\n packfile.h |  5 +++--\n 2 files changed, 10 insertions(+), 7 deletions(-)\n\ndiff --git a/packfile.c b/packfile.c\nindex 9f7ca8f211..178d2e0ddd 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -1839,17 +1839,19 @@ static int fill_pack_entry(const unsigned char *sha1,\n  * Iff a pack file contains the object named by sha1, return true and\n  * store its location to e.\n  */\n-int find_pack_entry_the_repository(const unsigned char *sha1, struct pack_entry *e)\n+int find_pack_entry(struct repository *r,\n+\t\t    const unsigned char *sha1,\n+\t\t    struct pack_entry *e)\n {\n \tstruct mru_entry *p;\n \n-\tprepare_packed_git(the_repository);\n-\tif (!the_repository->objects.packed_git)\n+\tprepare_packed_git(r);\n+\tif (!r->objects.packed_git)\n \t\treturn 0;\n \n-\tfor (p = the_repository->objects.packed_git_mru.head; p; p = p->next) {\n+\tfor (p = r->objects.packed_git_mru.head; p; p = p->next) {\n \t\tif (fill_pack_entry(sha1, e, p->item)) {\n-\t\t\tmru_mark(&the_repository->objects.packed_git_mru, p);\n+\t\t\tmru_mark(&r->objects.packed_git_mru, p);\n \t\t\treturn 1;\n \t\t}\n \t}\ndiff --git a/packfile.h b/packfile.h\nindex 615c58cbac..6d10871d25 100644\n--- a/packfile.h\n+++ b/packfile.h\n@@ -142,8 +142,9 @@ extern int packed_object_info_the_repository(struct packed_git *pack, off_t offs\n extern void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1);\n extern const struct packed_git *has_packed_and_bad(const unsigned char *sha1);\n \n-#define find_pack_entry(r, s, e) find_pack_entry_##r(s, e)\n-extern int find_pack_entry_the_repository(const unsigned char *sha1, struct pack_entry *e);\n+extern int find_pack_entry(struct repository *r,\n+\t\t\t   const unsigned char *sha1,\n+\t\t\t   struct pack_entry *e);\n \n extern int has_sha1_pack(const unsigned char *sha1);\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338341","messageId":"20180205235735.216710-54-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 074/194] object-store: allow sha1_object_info to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:35Z","receivedAt":"2018-02-06T00:09:55Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"This involves also adapting sha1_object_info_extended and a some\ninternal functions that are used to implement these. It all has to\nhappen in one patch, because of a single recursive chain of calls visits\nall these functions.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n object-store.h | 13 ++++++-------\n packfile.c     | 58 ++++++++++++++++++++++++++++------------------------------\n packfile.h     |  8 ++++----\n sha1_file.c    | 24 +++++++++++++-----------\n 4 files changed, 51 insertions(+), 52 deletions(-)\n\ndiff --git a/object-store.h b/object-store.h\nindex 4ff60e3be0..6930cfef82 100644\n--- a/object-store.h\n+++ b/object-store.h\n@@ -91,10 +91,7 @@ static inline void *read_sha1_file(const unsigned char *sha1, enum object_type *\n }\n \n /* Read and unpack a sha1 file into memory, write memory to a sha1 file */\n-\n-#define sha1_object_info(r, sha1, size) \\\n-\tsha1_object_info_##r(sha1, size)\n-extern int sha1_object_info_the_repository(const unsigned char *, unsigned long *);\n+extern int sha1_object_info(struct repository *r, const unsigned char *sha1, unsigned long *sizep);\n extern int hash_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *sha1);\n extern int write_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *return_sha1);\n extern int hash_sha1_file_literally(const void *buf, unsigned long len, const char *type, struct object_id *oid, unsigned flags);\n@@ -166,8 +163,10 @@ struct object_info {\n #define OBJECT_INFO_SKIP_CACHED 4\n /* Do not retry packed storage after checking packed and loose storage */\n #define OBJECT_INFO_QUICK 8\n-#define sha1_object_info_extended(r, s, oi, f) \\\n-\t\tsha1_object_info_extended_##r(s, oi, f)\n-extern int sha1_object_info_extended_the_repository(const unsigned char *, struct object_info *, unsigned flags);\n+\n+extern int sha1_object_info_extended(struct repository *r,\n+\t\t\t\t     const unsigned char *sha1,\n+\t\t\t\t     struct object_info *oi,\n+\t\t\t\t     unsigned flags);\n \n #endif /* OBJECT_STORE_H */\ndiff --git a/packfile.c b/packfile.c\nindex 178d2e0ddd..6a8d5edf6d 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -1082,9 +1082,9 @@ static const unsigned char *get_delta_base_sha1(struct packed_git *p,\n \t\treturn NULL;\n }\n \n-#define retry_bad_packed_offset(r, p, o) \\\n-\tretry_bad_packed_offset_##r(p, o)\n-static int retry_bad_packed_offset_the_repository(struct packed_git *p, off_t obj_offset)\n+static int retry_bad_packed_offset(struct repository *r,\n+\t\t\t\t   struct packed_git *p,\n+\t\t\t\t   off_t obj_offset)\n {\n \tint type;\n \tstruct revindex_entry *revidx;\n@@ -1094,7 +1094,7 @@ static int retry_bad_packed_offset_the_repository(struct packed_git *p, off_t ob\n \t\treturn OBJ_BAD;\n \tsha1 = nth_packed_object_sha1(p, revidx->nr);\n \tmark_bad_packed_object(p, sha1);\n-\ttype = sha1_object_info(the_repository, sha1, NULL);\n+\ttype = sha1_object_info(r, sha1, NULL);\n \tif (type <= OBJ_NONE)\n \t\treturn OBJ_BAD;\n \treturn type;\n@@ -1102,13 +1102,12 @@ static int retry_bad_packed_offset_the_repository(struct packed_git *p, off_t ob\n \n #define POI_STACK_PREALLOC 64\n \n-#define packed_to_object_type(r, p, o, t, w, c) \\\n-\tpacked_to_object_type_##r(p, o, t, w, c)\n-static enum object_type packed_to_object_type_the_repository(struct packed_git *p,\n-\t\t\t\t\t\t\t     off_t obj_offset,\n-\t\t\t\t\t\t\t     enum object_type type,\n-\t\t\t\t\t\t\t     struct pack_window **w_curs,\n-\t\t\t\t\t\t\t     off_t curpos)\n+static enum object_type packed_to_object_type(struct repository *r,\n+\t\t\t\t\t      struct packed_git *p,\n+\t\t\t\t\t      off_t obj_offset,\n+\t\t\t\t\t      enum object_type type,\n+\t\t\t\t\t      struct pack_window **w_curs,\n+\t\t\t\t\t      off_t curpos)\n {\n \toff_t small_poi_stack[POI_STACK_PREALLOC];\n \toff_t *poi_stack = small_poi_stack;\n@@ -1135,7 +1134,7 @@ static enum object_type packed_to_object_type_the_repository(struct packed_git *\n \t\tif (type <= OBJ_NONE) {\n \t\t\t/* If getting the base itself fails, we first\n \t\t\t * retry the base, otherwise unwind */\n-\t\t\ttype = retry_bad_packed_offset(the_repository, p, base_offset);\n+\t\t\ttype = retry_bad_packed_offset(r, p, base_offset);\n \t\t\tif (type > OBJ_NONE)\n \t\t\t\tgoto out;\n \t\t\tgoto unwind;\n@@ -1163,7 +1162,7 @@ static enum object_type packed_to_object_type_the_repository(struct packed_git *\n unwind:\n \twhile (poi_stack_nr) {\n \t\tobj_offset = poi_stack[--poi_stack_nr];\n-\t\ttype = retry_bad_packed_offset(the_repository, p, obj_offset);\n+\t\ttype = retry_bad_packed_offset(r, p, obj_offset);\n \t\tif (type > OBJ_NONE)\n \t\t\tgoto out;\n \t}\n@@ -1250,15 +1249,15 @@ static void detach_delta_base_cache_entry(struct delta_base_cache_entry *ent)\n \tfree(ent);\n }\n \n-#define cache_or_unpack_entry(r, p, bo, bs, t) cache_or_unpack_entry_##r(p, bo, bs, t)\n-static void *cache_or_unpack_entry_the_repository(struct packed_git *p, off_t base_offset,\n-\tunsigned long *base_size, enum object_type *type)\n+static void *cache_or_unpack_entry(struct repository *r, struct packed_git *p,\n+\t\t\t\t   off_t base_offset, unsigned long *base_size,\n+\t\t\t\t   enum object_type *type)\n {\n \tstruct delta_base_cache_entry *ent;\n \n \tent = get_delta_base_cache_entry(p, base_offset);\n \tif (!ent)\n-\t\treturn unpack_entry(the_repository, p, base_offset, type, base_size);\n+\t\treturn unpack_entry(r, p, base_offset, type, base_size);\n \n \tif (type)\n \t\t*type = ent->type;\n@@ -1312,8 +1311,8 @@ static void add_delta_base_cache(struct packed_git *p, off_t base_offset,\n \thashmap_add(&delta_base_cache, ent);\n }\n \n-int packed_object_info_the_repository(struct packed_git *p, off_t obj_offset,\n-\t\t\t\t      struct object_info *oi)\n+int packed_object_info(struct repository *r, struct packed_git *p,\n+\t\t       off_t obj_offset, struct object_info *oi)\n {\n \tstruct pack_window *w_curs = NULL;\n \tunsigned long size;\n@@ -1325,7 +1324,7 @@ int packed_object_info_the_repository(struct packed_git *p, off_t obj_offset,\n \t * a \"real\" type later if the caller is interested.\n \t */\n \tif (oi->contentp) {\n-\t\t*oi->contentp = cache_or_unpack_entry(the_repository, p, obj_offset, oi->sizep,\n+\t\t*oi->contentp = cache_or_unpack_entry(r, p, obj_offset, oi->sizep,\n \t\t\t\t\t\t      &type);\n \t\tif (!*oi->contentp)\n \t\t\ttype = OBJ_BAD;\n@@ -1359,7 +1358,7 @@ int packed_object_info_the_repository(struct packed_git *p, off_t obj_offset,\n \n \tif (oi->typep || oi->typename) {\n \t\tenum object_type ptot;\n-\t\tptot = packed_to_object_type(the_repository, p, obj_offset,\n+\t\tptot = packed_to_object_type(r, p, obj_offset,\n \t\t\t\t\t     type, &w_curs, curpos);\n \t\tif (oi->typep)\n \t\t\t*oi->typep = ptot;\n@@ -1448,10 +1447,10 @@ struct unpack_entry_stack_ent {\n \tunsigned long size;\n };\n \n-#define read_object(r, s, t, sz) read_object_##r(s, t, sz)\n-static void *read_object_the_repository(const unsigned char *sha1,\n-\t\t\t\t\tenum object_type *type,\n-\t\t\t\t\tunsigned long *size)\n+static void *read_object(struct repository *r,\n+\t\t\t const unsigned char *sha1,\n+\t\t\t enum object_type *type,\n+\t\t\t unsigned long *size)\n {\n \tstruct object_info oi = OBJECT_INFO_INIT;\n \tvoid *content;\n@@ -1459,14 +1458,13 @@ static void *read_object_the_repository(const unsigned char *sha1,\n \toi.sizep = size;\n \toi.contentp = &content;\n \n-\tif (sha1_object_info_extended(the_repository, sha1, &oi, 0) < 0)\n+\tif (sha1_object_info_extended(r, sha1, &oi, 0) < 0)\n \t\treturn NULL;\n \treturn content;\n }\n \n-void *unpack_entry_the_repository(struct packed_git *p, off_t obj_offset,\n-\t\t\t\t  enum object_type *final_type,\n-\t\t\t\t  unsigned long *final_size)\n+void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset,\n+\t\t   enum object_type *final_type, unsigned long *final_size)\n {\n \tstruct pack_window *w_curs = NULL;\n \toff_t curpos = obj_offset;\n@@ -1596,7 +1594,7 @@ void *unpack_entry_the_repository(struct packed_git *p, off_t obj_offset,\n \t\t\t\t      sha1_to_hex(base_sha1), (uintmax_t)obj_offset,\n \t\t\t\t      p->pack_name);\n \t\t\t\tmark_bad_packed_object(p, base_sha1);\n-\t\t\t\tbase = read_object(the_repository, base_sha1, &type, &base_size);\n+\t\t\t\tbase = read_object(r, base_sha1, &type, &base_size);\n \t\t\t\texternal_base = base;\n \t\t\t}\n \t\t}\ndiff --git a/packfile.h b/packfile.h\nindex 6d10871d25..f8d2825cce 100644\n--- a/packfile.h\n+++ b/packfile.h\n@@ -125,8 +125,7 @@ extern off_t nth_packed_object_offset(const struct packed_git *, uint32_t n);\n extern off_t find_pack_entry_one(const unsigned char *sha1, struct packed_git *);\n \n extern int is_pack_valid(struct packed_git *);\n-#define unpack_entry(r, p, of, ot, s) unpack_entry_##r(p, of, ot, s)\n-extern void *unpack_entry_the_repository(struct packed_git *, off_t, enum object_type *, unsigned long *);\n+extern void *unpack_entry(struct repository *r, struct packed_git *, off_t, enum object_type *, unsigned long *);\n extern unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep);\n extern unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t);\n extern int unpack_object_header(struct packed_git *, struct pack_window **, off_t *, unsigned long *);\n@@ -136,8 +135,9 @@ extern void release_pack_memory(size_t);\n /* global flag to enable extra checks when accessing packed objects */\n extern int do_check_packed_object_crc;\n \n-#define packed_object_info(r, p, o, oi) packed_object_info_##r(p, o, oi)\n-extern int packed_object_info_the_repository(struct packed_git *pack, off_t offset, struct object_info *);\n+extern int packed_object_info(struct repository *r,\n+\t\t\t      struct packed_git *pack,\n+\t\t\t      off_t offset, struct object_info *);\n \n extern void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1);\n extern const struct packed_git *has_packed_and_bad(const unsigned char *sha1);\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 7e06ece5f3..c296b76329 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -1237,13 +1237,14 @@ static int sha1_loose_object_info(struct repository *r,\n \treturn (status < 0) ? status : 0;\n }\n \n-int sha1_object_info_extended_the_repository(const unsigned char *sha1, struct object_info *oi, unsigned flags)\n+int sha1_object_info_extended(struct repository *r, const unsigned char *sha1,\n+\t\t\t      struct object_info *oi, unsigned flags)\n {\n \tstatic struct object_info blank_oi = OBJECT_INFO_INIT;\n \tstruct pack_entry e;\n \tint rtype;\n \tconst unsigned char *real = (flags & OBJECT_INFO_LOOKUP_REPLACE) ?\n-\t\t\t\t    lookup_replace_object(the_repository, sha1) :\n+\t\t\t\t    lookup_replace_object(r, sha1) :\n \t\t\t\t    sha1;\n \n \tif (is_null_sha1(real))\n@@ -1272,17 +1273,17 @@ int sha1_object_info_extended_the_repository(const unsigned char *sha1, struct o\n \t\t}\n \t}\n \n-\tif (!find_pack_entry(the_repository, real, &e)) {\n+\tif (!find_pack_entry(r, real, &e)) {\n \t\t/* Most likely it's a loose object. */\n-\t\tif (!sha1_loose_object_info(the_repository, real, oi, flags))\n+\t\tif (!sha1_loose_object_info(r, real, oi, flags))\n \t\t\treturn 0;\n \n \t\t/* Not a loose object; someone else may have just packed it. */\n \t\tif (flags & OBJECT_INFO_QUICK) {\n \t\t\treturn -1;\n \t\t} else {\n-\t\t\treprepare_packed_git(the_repository);\n-\t\t\tif (!find_pack_entry(the_repository, real, &e))\n+\t\t\treprepare_packed_git(r);\n+\t\t\tif (!find_pack_entry(r, real, &e))\n \t\t\t\treturn -1;\n \t\t}\n \t}\n@@ -1294,11 +1295,10 @@ int sha1_object_info_extended_the_repository(const unsigned char *sha1, struct o\n \t\t */\n \t\treturn 0;\n \n-\trtype = packed_object_info(the_repository, e.p, e.offset, oi);\n+\trtype = packed_object_info(r, e.p, e.offset, oi);\n \tif (rtype < 0) {\n \t\tmark_bad_packed_object(e.p, real);\n-\t\treturn sha1_object_info_extended(the_repository, real, oi,\n-\t\t\t\t\t\t 0);\n+\t\treturn sha1_object_info_extended(r, real, oi, 0);\n \t} else if (oi->whence == OI_PACKED) {\n \t\toi->u.packed.offset = e.offset;\n \t\toi->u.packed.pack = e.p;\n@@ -1310,14 +1310,16 @@ int sha1_object_info_extended_the_repository(const unsigned char *sha1, struct o\n }\n \n /* returns enum object_type or negative */\n-int sha1_object_info_the_repository(const unsigned char *sha1, unsigned long *sizep)\n+int sha1_object_info(struct repository *r,\n+\t\t     const unsigned char *sha1,\n+\t\t     unsigned long *sizep)\n {\n \tenum object_type type;\n \tstruct object_info oi = OBJECT_INFO_INIT;\n \n \toi.typep = &type;\n \toi.sizep = sizep;\n-\tif (sha1_object_info_extended(the_repository, sha1, &oi,\n+\tif (sha1_object_info_extended(r, sha1, &oi,\n \t\t\t\t      OBJECT_INFO_LOOKUP_REPLACE) < 0)\n \t\treturn -1;\n \treturn type;\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338342","messageId":"20180205235735.216710-55-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 075/194] fetch, push: do not use submodule as alternate in has_commits check","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:36Z","receivedAt":"2018-02-06T00:10:21Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Both fetch and push still use alternates to access submodules in some\nother code paths, but this is progress towards eliminating the alternates\nhack that conflates access to the_repository and other repositories.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n submodule.c | 52 ++++++++++++++++++++++++++++++++++++++--------------\n 1 file changed, 38 insertions(+), 14 deletions(-)\n\ndiff --git a/submodule.c b/submodule.c\nindex dc57c176e8..1504812842 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -811,14 +811,15 @@ static int append_oid_to_argv(const struct object_id *oid, void *data)\n \n struct has_commit_data {\n \tint result;\n-\tconst char *path;\n+\tstruct repository *repo;\n };\n \n static int check_has_commit(const struct object_id *oid, void *data)\n {\n \tstruct has_commit_data *cb = data;\n+\tstruct repository *r = cb->repo;\n \n-\tenum object_type type = sha1_object_info(the_repository, oid->hash, NULL);\n+\tenum object_type type = sha1_object_info(r, oid->hash, NULL);\n \n \tswitch (type) {\n \tcase OBJ_COMMIT:\n@@ -832,24 +833,43 @@ static int check_has_commit(const struct object_id *oid, void *data)\n \t\treturn 0;\n \tdefault:\n \t\tdie(_(\"submodule entry '%s' (%s) is a %s, not a commit\"),\n-\t\t    cb->path, oid_to_hex(oid), typename(type));\n+\t\t    r->submodule_prefix, oid_to_hex(oid), typename(type));\n \t}\n }\n \n+/*\n+ * Initialize 'out' based on the provided submodule path.\n+ *\n+ * Unlike repo_submodule_init, this tolerates submodules not present\n+ * in .gitmodules. NEEDSWORK: The repo_submodule_init behavior is\n+ * preferrable. This function exists only to preserve historical behavior.\n+ *\n+ * Returns 0 on success, -1 when the submodule is not present.\n+ */\n+static int open_submodule(struct repository *out, const char *path)\n+{\n+\tstruct strbuf sb = STRBUF_INIT;\n+\n+\tif (submodule_to_gitdir(&sb, path))\n+\t\treturn -1;\n+\n+\tif (repo_init(out, sb.buf, NULL)) {\n+\t\tstrbuf_release(&sb);\n+\t\treturn -1;\n+\t}\n+\n+\tout->submodule_prefix = xstrdup(path);\n+\n+\tstrbuf_release(&sb);\n+\treturn 0;\n+}\n+\n static int submodule_has_commits(const char *path, struct oid_array *commits)\n {\n-\tstruct has_commit_data has_commit = { 1, path };\n+\tstruct repository sub;\n+\tstruct has_commit_data has_commit = { 1, &sub };\n \n-\t/*\n-\t * Perform a cheap, but incorrect check for the existence of 'commits'.\n-\t * This is done by adding the submodule's object store to the in-core\n-\t * object store, and then querying for each commit's existence.  If we\n-\t * do not have the commit object anywhere, there is no chance we have\n-\t * it in the object store of the correct submodule and have it\n-\t * reachable from a ref, so we can fail early without spawning rev-list\n-\t * which is expensive.\n-\t */\n-\tif (add_submodule_odb(path))\n+\tif (open_submodule(&sub, path))\n \t\treturn 0;\n \n \toid_array_for_each_unique(commits, check_has_commit, &has_commit);\n@@ -878,6 +898,7 @@ static int submodule_has_commits(const char *path, struct oid_array *commits)\n \t\tstrbuf_release(&out);\n \t}\n \n+\trepo_clear(&sub);\n \treturn has_commit.result;\n }\n \n@@ -897,6 +918,9 @@ static int submodule_needs_pushing(const char *path, struct oid_array *commits)\n \t\t */\n \t\treturn 0;\n \n+\t/* The submodule odb is needed for access to its refs. */\n+\tif (add_submodule_odb(path))\n+\t\tBUG(\"submodule '%s' is both present and absent\", path);\n \tif (for_each_remote_ref_submodule(path, has_remote, NULL) > 0) {\n \t\tstruct child_process cp = CHILD_PROCESS_INIT;\n \t\tstruct strbuf buf = STRBUF_INIT;\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338343","messageId":"20180205235735.216710-56-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 076/194] push: add test showing bad interaction of replace refs and submodules","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:37Z","receivedAt":"2018-02-06T00:10:23Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"The ref subsystem has not been migrated yet to access the object store\nvia passed in repository objects. As a result replace when the object store\ntries to access replace refs in a repository other than the_repository\nit produces errors:\n\n  error: refs/replace/3afabef75c627b894cccc3bcae86837abc7c32fe does not point to a valid object!\n\nAdd a test demonstrating this failure.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n\nsquash! push: add test showing bad interaction of replace refs and submodules\n\nreplace-objects: evaluate replacement refs without using the object store\n\nPass DO_FOR_EACH_INCLUDE_BROKEN when iterating over replacement refs\nso that the iteration does not require opening the named objects from\nthe object store. This avoids a dependency cycle between object access\nand replace ref iteration.\n\nMoreover the ref subsystem has not been migrated yet to access the object\nstore via passed in repository objects.  As a result, without this patch\nwhen the object store tries to access replace refs in a repository other\nthan the_repository it produces errors:\n\n   error: refs/replace/3afabef75c627b894cccc3bcae86837abc7c32fe does not point to a valid object!\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n t/t5531-deep-submodule-push.sh | 16 ++++++++++++++++\n 1 file changed, 16 insertions(+)\n\ndiff --git a/t/t5531-deep-submodule-push.sh b/t/t5531-deep-submodule-push.sh\nindex 39cb2c1c34..8b2aa5a0f4 100755\n--- a/t/t5531-deep-submodule-push.sh\n+++ b/t/t5531-deep-submodule-push.sh\n@@ -308,6 +308,22 @@ test_expect_success 'submodule entry pointing at a tag is error' '\n \ttest_i18ngrep \"is a tag, not a commit\" err\n '\n \n+test_expect_success 'replace ref does not interfere with submodule access' '\n+\ttest_commit -C work/gar/bage one &&\n+\ttest_commit -C work/gar/bage two &&\n+\tgit -C work/gar/bage reset HEAD^^ &&\n+\tgit -C work/gar/bage replace two one &&\n+\ttest_when_finished \"git -C work/gar/bage replace -d two\" &&\n+\n+\ttest_commit -C work/gar/bage three &&\n+\tgit -C work add gar/bage &&\n+\tgit -C work commit -m \"advance submodule\" &&\n+\n+\tgit -C work push --recurse-submodules=on-demand ../pub.git master 2>err &&\n+\t! grep error err &&\n+\t! grep fatal err\n+'\n+\n test_expect_success 'push fails if recurse submodules option passed as yes' '\n \t(\n \t\tcd work/gar/bage &&\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338344","messageId":"20180205235735.216710-57-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 077/194] replace_object: allow register_replace_ref to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:38Z","receivedAt":"2018-02-06T00:10:48Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n replace-object.c | 3 +--\n 1 file changed, 1 insertion(+), 2 deletions(-)\n\ndiff --git a/replace-object.c b/replace-object.c\nindex a6a34217d8..96d339729a 100644\n--- a/replace-object.c\n+++ b/replace-object.c\n@@ -68,8 +68,7 @@ static int register_replace_ref(const char *refname,\n \thashcpy(repl_obj->replacement, oid->hash);\n \n \t/* Register new object */\n-\t(void)r;\n-\tif (register_replace_object(the_repository, repl_obj, 1))\n+\tif (register_replace_object(r, repl_obj, 1))\n \t\tdie(\"duplicate replace ref: %s\", refname);\n \n \treturn 0;\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338345","messageId":"20180205235735.216710-58-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 078/194] cache.h: migrate the definition of object_id to object.h","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:39Z","receivedAt":"2018-02-06T00:10:51Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"In the following patch we'll need the struct object completely accessible\nin object.h, which includes an object_id. Move the definition of the\nobject_id there, to enable this.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n cache.h  | 13 +------------\n object.h | 12 ++++++++++++\n 2 files changed, 13 insertions(+), 12 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 22404de92b..634172cec4 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -15,6 +15,7 @@\n #include \"path.h\"\n #include \"sha1-array.h\"\n #include \"repository.h\"\n+#include \"object.h\"\n \n #ifndef platform_SHA_CTX\n /*\n@@ -66,18 +67,6 @@ int git_deflate_end_gently(git_zstream *);\n int git_deflate(git_zstream *, int flush);\n unsigned long git_deflate_bound(git_zstream *, unsigned long);\n \n-/* The length in bytes and in hex digits of an object name (SHA-1 value). */\n-#define GIT_SHA1_RAWSZ 20\n-#define GIT_SHA1_HEXSZ (2 * GIT_SHA1_RAWSZ)\n-\n-/* The length in byte and in hex digits of the largest possible hash value. */\n-#define GIT_MAX_RAWSZ GIT_SHA1_RAWSZ\n-#define GIT_MAX_HEXSZ GIT_SHA1_HEXSZ\n-\n-struct object_id {\n-\tunsigned char hash[GIT_MAX_RAWSZ];\n-};\n-\n #define the_hash_algo the_repository->hash_algo\n \n #if defined(DT_UNKNOWN) && !defined(NO_D_TYPE_IN_DIRENT)\ndiff --git a/object.h b/object.h\nindex f34461d4af..fbccb09257 100644\n--- a/object.h\n+++ b/object.h\n@@ -43,6 +43,18 @@ struct object_array {\n  */\n #define FLAG_BITS  27\n \n+/* The length in bytes and in hex digits of an object name (SHA-1 value). */\n+#define GIT_SHA1_RAWSZ 20\n+#define GIT_SHA1_HEXSZ (2 * GIT_SHA1_RAWSZ)\n+\n+/* The length in byte and in hex digits of the largest possible hash value. */\n+#define GIT_MAX_RAWSZ GIT_SHA1_RAWSZ\n+#define GIT_MAX_HEXSZ GIT_SHA1_HEXSZ\n+\n+struct object_id {\n+\tunsigned char hash[GIT_MAX_RAWSZ];\n+};\n+\n /*\n  * The object type is stored in 3 bits.\n  */\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338346","messageId":"20180205235735.216710-59-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 079/194] repository: introduce object parser field","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:40Z","receivedAt":"2018-02-06T00:11:16Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Git's object access code can be thought of as containing two layers:\nthe raw object store provides access to raw object content, while the\nhigher level obj_hash code parses raw objects and keeps track of\nparenthood and other object relationships using 'struct object'.\nKeeping these layers separate should make it easier to find relevant\nfunctions and to change the implementation of one without having to\ntouch the other.\n\nAdd an object_parser field to 'struct repository' to prepare obj_hash\nto be handled per repository.  Callers still only use the_repository\nfor now --- later patches will adapt them to handle arbitrary\nrepositories.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n object-store.h |  4 ++--\n object.c       | 42 +++++++++++++++++++++---------------------\n object.h       |  7 +++++++\n repository.c   |  2 +-\n repository.h   | 14 ++++++++++++--\n 5 files changed, 43 insertions(+), 26 deletions(-)\n\ndiff --git a/object-store.h b/object-store.h\nindex 6930cfef82..d009f952f8 100644\n--- a/object-store.h\n+++ b/object-store.h\n@@ -12,7 +12,7 @@ struct pack_window;\n enum object_type;\n extern int check_replace_refs;\n \n-struct object_store {\n+struct raw_object_store {\n \tstruct packed_git *packed_git;\n \n \t/*\n@@ -57,7 +57,7 @@ struct object_store {\n \t */\n \tunsigned packed_git_initialized : 1;\n };\n-#define OBJECT_STORE_INIT \\\n+#define RAW_OBJECT_STORE_INIT \\\n \t{ NULL, MRU_INIT, ALTERNATES_INIT, { NULL, 0, 0, 0 }, 0, 0, 0 }\n \n struct packed_git {\ndiff --git a/object.c b/object.c\nindex 40f7c7bdab..18ea8cf574 100644\n--- a/object.c\n+++ b/object.c\n@@ -7,17 +7,14 @@\n #include \"commit.h\"\n #include \"tag.h\"\n \n-static struct object **obj_hash;\n-static int nr_objs, obj_hash_size;\n-\n unsigned int get_max_object_index(void)\n {\n-\treturn obj_hash_size;\n+\treturn the_repository->parsed_objects.obj_hash_size;\n }\n \n struct object *get_indexed_object(unsigned int idx)\n {\n-\treturn obj_hash[idx];\n+\treturn the_repository->parsed_objects.obj_hash[idx];\n }\n \n static const char *object_type_strings[] = {\n@@ -89,15 +86,16 @@ struct object *lookup_object(const unsigned char *sha1)\n \tunsigned int i, first;\n \tstruct object *obj;\n \n-\tif (!obj_hash)\n+\tif (!the_repository->parsed_objects.obj_hash)\n \t\treturn NULL;\n \n-\tfirst = i = hash_obj(sha1, obj_hash_size);\n-\twhile ((obj = obj_hash[i]) != NULL) {\n+\tfirst = i = hash_obj(sha1,\n+\t\t\t     the_repository->parsed_objects.obj_hash_size);\n+\twhile ((obj = the_repository->parsed_objects.obj_hash[i]) != NULL) {\n \t\tif (!hashcmp(sha1, obj->oid.hash))\n \t\t\tbreak;\n \t\ti++;\n-\t\tif (i == obj_hash_size)\n+\t\tif (i == the_repository->parsed_objects.obj_hash_size)\n \t\t\ti = 0;\n \t}\n \tif (obj && i != first) {\n@@ -106,7 +104,8 @@ struct object *lookup_object(const unsigned char *sha1)\n \t\t * that we do not need to walk the hash table the next\n \t\t * time we look for it.\n \t\t */\n-\t\tSWAP(obj_hash[i], obj_hash[first]);\n+\t\tSWAP(the_repository->parsed_objects.obj_hash[i],\n+\t\t     the_repository->parsed_objects.obj_hash[first]);\n \t}\n \treturn obj;\n }\n@@ -123,19 +122,19 @@ static void grow_object_hash(void)\n \t * Note that this size must always be power-of-2 to match hash_obj\n \t * above.\n \t */\n-\tint new_hash_size = obj_hash_size < 32 ? 32 : 2 * obj_hash_size;\n+\tint new_hash_size = the_repository->parsed_objects.obj_hash_size < 32 ? 32 : 2 * the_repository->parsed_objects.obj_hash_size;\n \tstruct object **new_hash;\n \n \tnew_hash = xcalloc(new_hash_size, sizeof(struct object *));\n-\tfor (i = 0; i < obj_hash_size; i++) {\n-\t\tstruct object *obj = obj_hash[i];\n+\tfor (i = 0; i < the_repository->parsed_objects.obj_hash_size; i++) {\n+\t\tstruct object *obj = the_repository->parsed_objects.obj_hash[i];\n \t\tif (!obj)\n \t\t\tcontinue;\n \t\tinsert_obj_hash(obj, new_hash, new_hash_size);\n \t}\n-\tfree(obj_hash);\n-\tobj_hash = new_hash;\n-\tobj_hash_size = new_hash_size;\n+\tfree(the_repository->parsed_objects.obj_hash);\n+\tthe_repository->parsed_objects.obj_hash = new_hash;\n+\tthe_repository->parsed_objects.obj_hash_size = new_hash_size;\n }\n \n void *create_object(const unsigned char *sha1, void *o)\n@@ -146,11 +145,12 @@ void *create_object(const unsigned char *sha1, void *o)\n \tobj->flags = 0;\n \thashcpy(obj->oid.hash, sha1);\n \n-\tif (obj_hash_size - 1 <= nr_objs * 2)\n+\tif (the_repository->parsed_objects.obj_hash_size - 1 <= the_repository->parsed_objects.nr_objs * 2)\n \t\tgrow_object_hash();\n \n-\tinsert_obj_hash(obj, obj_hash, obj_hash_size);\n-\tnr_objs++;\n+\tinsert_obj_hash(obj, the_repository->parsed_objects.obj_hash,\n+\t\t\tthe_repository->parsed_objects.obj_hash_size);\n+\tthe_repository->parsed_objects.nr_objs++;\n \treturn obj;\n }\n \n@@ -430,8 +430,8 @@ void clear_object_flags(unsigned flags)\n {\n \tint i;\n \n-\tfor (i=0; i < obj_hash_size; i++) {\n-\t\tstruct object *obj = obj_hash[i];\n+\tfor (i=0; i < the_repository->parsed_objects.obj_hash_size; i++) {\n+\t\tstruct object *obj = the_repository->parsed_objects.obj_hash[i];\n \t\tif (obj)\n \t\t\tobj->flags &= ~flags;\n \t}\ndiff --git a/object.h b/object.h\nindex fbccb09257..2cff106ff7 100644\n--- a/object.h\n+++ b/object.h\n@@ -1,6 +1,13 @@\n #ifndef OBJECT_H\n #define OBJECT_H\n \n+struct object_parser {\n+\tstruct object **obj_hash;\n+\tint nr_objs, obj_hash_size;\n+};\n+\n+#define OBJECT_PARSER_INIT { NULL, 0, 0 }\n+\n struct object_list {\n \tstruct object *item;\n \tstruct object_list *next;\ndiff --git a/repository.c b/repository.c\nindex 6f85fade82..af62dfdc09 100644\n--- a/repository.c\n+++ b/repository.c\n@@ -6,7 +6,7 @@\n \n /* The main repository */\n static struct repository the_repo = {\n-\tNULL, NULL, NULL, OBJECT_STORE_INIT, NULL,\n+\tNULL, NULL, NULL, RAW_OBJECT_STORE_INIT, OBJECT_PARSER_INIT, NULL,\n \tNULL, NULL, NULL, NULL, NULL, NULL, &the_index, NULL, 0, 0\n };\n struct repository *the_repository = &the_repo;\ndiff --git a/repository.h b/repository.h\nindex 727ddcea5b..c8a34d1ac9 100644\n--- a/repository.h\n+++ b/repository.h\n@@ -2,6 +2,7 @@\n #define REPOSITORY_H\n \n #include \"object-store.h\"\n+#include \"object.h\"\n \n struct config_set;\n struct index_state;\n@@ -29,9 +30,18 @@ struct repository {\n \tchar *objectdir;\n \n \t/*\n-\t * Holds any information related to the object store.\n+\t * Holds any information needed to retrieve the raw content\n+\t * of objects. The object_parser uses this to get object\n+\t * content which it then parses.\n \t */\n-\tstruct object_store objects;\n+\tstruct raw_object_store objects;\n+\n+\t/*\n+\t * State for the object parser. This owns all parsed objects\n+\t * (struct object) so callers do not have to manage their\n+\t * lifetime.\n+\t */\n+\tstruct object_parser parsed_objects;\n \n \t/*\n \t * The store in which the refs are hold.\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338347","messageId":"20180205235735.216710-60-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 080/194] object: add repository argument to parse_object","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:41Z","receivedAt":"2018-02-06T00:11:20Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow the callers of parse_object\nto be more specific about which repository to act on. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nAdd the cocci patch that converted the callers.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n builtin/diff-tree.c                    |  3 ++-\n builtin/diff.c                         |  2 +-\n builtin/fast-export.c                  |  2 +-\n builtin/fmt-merge-msg.c                |  6 ++++--\n builtin/fsck.c                         |  4 ++--\n builtin/log.c                          |  3 ++-\n builtin/name-rev.c                     |  7 ++++---\n builtin/receive-pack.c                 |  6 +++---\n builtin/reflog.c                       |  3 ++-\n builtin/rev-list.c                     |  2 +-\n bundle.c                               |  3 ++-\n commit.c                               |  5 +++--\n contrib/coccinelle/object_parser.cocci |  6 ++++++\n fetch-pack.c                           | 16 +++++++++-------\n fsck.c                                 |  3 ++-\n http-backend.c                         |  2 +-\n http-push.c                            |  6 ++++--\n log-tree.c                             |  7 ++++---\n merge-recursive.c                      |  4 +++-\n object.c                               |  4 ++--\n object.h                               |  3 ++-\n pretty.c                               |  2 +-\n ref-filter.c                           |  3 ++-\n reflog-walk.c                          |  3 ++-\n refs/files-backend.c                   |  2 +-\n remote.c                               |  4 ++--\n revision.c                             | 12 ++++++------\n server-info.c                          |  2 +-\n sha1_name.c                            | 14 +++++++-------\n tag.c                                  |  5 +++--\n tree.c                                 |  5 +++--\n upload-pack.c                          |  9 +++++----\n walker.c                               |  3 ++-\n 33 files changed, 95 insertions(+), 66 deletions(-)\n create mode 100644 contrib/coccinelle/object_parser.cocci\n\ndiff --git a/builtin/diff-tree.c b/builtin/diff-tree.c\nindex b775a75647..1f78308e33 100644\n--- a/builtin/diff-tree.c\n+++ b/builtin/diff-tree.c\n@@ -5,6 +5,7 @@\n #include \"log-tree.h\"\n #include \"builtin.h\"\n #include \"submodule.h\"\n+#include \"repository.h\"\n \n static struct rev_info log_tree_opt;\n \n@@ -68,7 +69,7 @@ static int diff_tree_stdin(char *line)\n \tline[len-1] = 0;\n \tif (parse_oid_hex(line, &oid, &p))\n \t\treturn -1;\n-\tobj = parse_object(&oid);\n+\tobj = parse_object(the_repository, &oid);\n \tif (!obj)\n \t\treturn -1;\n \tif (obj->type == OBJ_COMMIT)\ndiff --git a/builtin/diff.c b/builtin/diff.c\nindex 16bfb22f73..ed6092ef1a 100644\n--- a/builtin/diff.c\n+++ b/builtin/diff.c\n@@ -393,7 +393,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)\n \t\tconst char *name = entry->name;\n \t\tint flags = (obj->flags & UNINTERESTING);\n \t\tif (!obj->parsed)\n-\t\t\tobj = parse_object(&obj->oid);\n+\t\t\tobj = parse_object(the_repository, &obj->oid);\n \t\tobj = deref_tag(obj, NULL, 0);\n \t\tif (!obj)\n \t\t\tdie(_(\"invalid object '%s' given.\"), name);\ndiff --git a/builtin/fast-export.c b/builtin/fast-export.c\nindex d4e53908c6..6140caf8d8 100644\n--- a/builtin/fast-export.c\n+++ b/builtin/fast-export.c\n@@ -798,7 +798,7 @@ static struct commit *get_commit(struct rev_cmdline_entry *e, char *full_name)\n \n \t\t/* handle nested tags */\n \t\twhile (tag && tag->object.type == OBJ_TAG) {\n-\t\t\tparse_object(&tag->object.oid);\n+\t\t\tparse_object(the_repository, &tag->object.oid);\n \t\t\tstring_list_append(&extra_refs, full_name)->util = tag;\n \t\t\ttag = (struct tag *)tag->tagged;\n \t\t}\ndiff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c\nindex 9dd5c85831..dd74251690 100644\n--- a/builtin/fmt-merge-msg.c\n+++ b/builtin/fmt-merge-msg.c\n@@ -11,6 +11,7 @@\n #include \"branch.h\"\n #include \"fmt-merge-msg.h\"\n #include \"gpg-interface.h\"\n+#include \"repository.h\"\n \n static const char * const fmt_merge_msg_usage[] = {\n \tN_(\"git fmt-merge-msg [-m <message>] [--log[=<n>] | --no-log] [--file <file>]\"),\n@@ -343,7 +344,8 @@ static void shortlog(const char *name,\n \tconst struct object_id *oid = &origin_data->oid;\n \tint limit = opts->shortlog_len;\n \n-\tbranch = deref_tag(parse_object(oid), oid_to_hex(oid), GIT_SHA1_HEXSZ);\n+\tbranch = deref_tag(parse_object(the_repository, oid), oid_to_hex(oid),\n+\t\t\t   GIT_SHA1_HEXSZ);\n \tif (!branch || branch->type != OBJ_COMMIT)\n \t\treturn;\n \n@@ -563,7 +565,7 @@ static void find_merge_parents(struct merge_parents *result,\n \t\t * \"name\" here and we do not want to contaminate its\n \t\t * util field yet.\n \t\t */\n-\t\tobj = parse_object(&oid);\n+\t\tobj = parse_object(the_repository, &oid);\n \t\tparent = (struct commit *)peel_to_type(NULL, 0, obj, OBJ_COMMIT);\n \t\tif (!parent)\n \t\t\tcontinue;\ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex f5e3c51077..9408ae5cc6 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -437,7 +437,7 @@ static int fsck_handle_ref(const char *refname, const struct object_id *oid,\n {\n \tstruct object *obj;\n \n-\tobj = parse_object(oid);\n+\tobj = parse_object(the_repository, oid);\n \tif (!obj) {\n \t\terror(\"%s: invalid sha1 pointer %s\", refname, oid_to_hex(oid));\n \t\terrors_found |= ERROR_REACHABLE;\n@@ -593,7 +593,7 @@ static int fsck_cache_tree(struct cache_tree *it)\n \t\tfprintf(stderr, \"Checking cache tree\\n\");\n \n \tif (0 <= it->entry_count) {\n-\t\tstruct object *obj = parse_object(&it->oid);\n+\t\tstruct object *obj = parse_object(the_repository, &it->oid);\n \t\tif (!obj) {\n \t\t\terror(\"%s: invalid sha1 pointer in cache-tree\",\n \t\t\t      oid_to_hex(&it->oid));\ndiff --git a/builtin/log.c b/builtin/log.c\nindex de723fffc6..2c3579b1f7 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -29,6 +29,7 @@\n #include \"mailmap.h\"\n #include \"gpg-interface.h\"\n #include \"progress.h\"\n+#include \"repository.h\"\n \n /* Set a default date-time format for git log (\"log.date\" config variable) */\n static const char *default_date_mode = NULL;\n@@ -613,7 +614,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)\n \t\t\trev.shown_one = 1;\n \t\t\tif (ret)\n \t\t\t\tbreak;\n-\t\t\to = parse_object(&t->tagged->oid);\n+\t\t\to = parse_object(the_repository, &t->tagged->oid);\n \t\t\tif (!o)\n \t\t\t\tret = error(_(\"Could not read object %s\"),\n \t\t\t\t\t    oid_to_hex(&t->tagged->oid));\ndiff --git a/builtin/name-rev.c b/builtin/name-rev.c\nindex 9e088ebd11..c6b253eefb 100644\n--- a/builtin/name-rev.c\n+++ b/builtin/name-rev.c\n@@ -1,5 +1,6 @@\n #include \"builtin.h\"\n #include \"cache.h\"\n+#include \"repository.h\"\n #include \"config.h\"\n #include \"commit.h\"\n #include \"tag.h\"\n@@ -187,7 +188,7 @@ static int tipcmp(const void *a_, const void *b_)\n \n static int name_ref(const char *path, const struct object_id *oid, int flags, void *cb_data)\n {\n-\tstruct object *o = parse_object(oid);\n+\tstruct object *o = parse_object(the_repository, oid);\n \tstruct name_ref_data *data = cb_data;\n \tint can_abbreviate_output = data->tags_only && data->name_only;\n \tint deref = 0;\n@@ -245,7 +246,7 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo\n \t\tstruct tag *t = (struct tag *) o;\n \t\tif (!t->tagged)\n \t\t\tbreak; /* broken repository */\n-\t\to = parse_object(&t->tagged->oid);\n+\t\to = parse_object(the_repository, &t->tagged->oid);\n \t\tderef = 1;\n \t\ttaggerdate = t->date;\n \t}\n@@ -434,7 +435,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)\n \t\t}\n \n \t\tcommit = NULL;\n-\t\tobject = parse_object(&oid);\n+\t\tobject = parse_object(the_repository, &oid);\n \t\tif (object) {\n \t\t\tstruct object *peeled = deref_tag(object, *argv, 0);\n \t\t\tif (peeled && peeled->type == OBJ_COMMIT)\ndiff --git a/builtin/receive-pack.c b/builtin/receive-pack.c\nindex 744fe29366..22d805a8ff 100644\n--- a/builtin/receive-pack.c\n+++ b/builtin/receive-pack.c\n@@ -1107,8 +1107,8 @@ static const char *update(struct command *cmd, struct shallow_info *si)\n \t\tstruct object *old_object, *new_object;\n \t\tstruct commit *old_commit, *new_commit;\n \n-\t\told_object = parse_object(old_oid);\n-\t\tnew_object = parse_object(new_oid);\n+\t\told_object = parse_object(the_repository, old_oid);\n+\t\tnew_object = parse_object(the_repository, new_oid);\n \n \t\tif (!old_object || !new_object ||\n \t\t    old_object->type != OBJ_COMMIT ||\n@@ -1131,7 +1131,7 @@ static const char *update(struct command *cmd, struct shallow_info *si)\n \n \tif (is_null_oid(new_oid)) {\n \t\tstruct strbuf err = STRBUF_INIT;\n-\t\tif (!parse_object(old_oid)) {\n+\t\tif (!parse_object(the_repository, old_oid)) {\n \t\t\told_oid = NULL;\n \t\t\tif (ref_exists(name)) {\n \t\t\t\trp_warning(\"Allowing deletion of corrupt ref.\");\ndiff --git a/builtin/reflog.c b/builtin/reflog.c\nindex 4b525c4448..18145d5494 100644\n--- a/builtin/reflog.c\n+++ b/builtin/reflog.c\n@@ -2,6 +2,7 @@\n #include \"config.h\"\n #include \"lockfile.h\"\n #include \"object-store.h\"\n+#include \"repository.h\"\n #include \"commit.h\"\n #include \"refs.h\"\n #include \"dir.h\"\n@@ -128,7 +129,7 @@ static int commit_is_complete(struct commit *commit)\n \t\tstruct commit_list *parent;\n \n \t\tc = (struct commit *)object_array_pop(&study);\n-\t\tif (!c->object.parsed && !parse_object(&c->object.oid))\n+\t\tif (!c->object.parsed && !parse_object(the_repository, &c->object.oid))\n \t\t\tc->object.flags |= INCOMPLETE;\n \n \t\tif (c->object.flags & INCOMPLETE) {\ndiff --git a/builtin/rev-list.c b/builtin/rev-list.c\nindex 969efde30c..3c2ae454ea 100644\n--- a/builtin/rev-list.c\n+++ b/builtin/rev-list.c\n@@ -222,7 +222,7 @@ static void finish_object(struct object *obj, const char *name, void *cb_data)\n \tif (obj->type == OBJ_BLOB && !has_object_file(&obj->oid))\n \t\tfinish_object__ma(obj);\n \tif (info->revs->verify_objects && !obj->parsed && obj->type != OBJ_COMMIT)\n-\t\tparse_object(&obj->oid);\n+\t\tparse_object(the_repository, &obj->oid);\n }\n \n static void show_object(struct object *obj, const char *name, void *cb_data)\ndiff --git a/bundle.c b/bundle.c\nindex d9376b7c77..1b5f1beb3b 100644\n--- a/bundle.c\n+++ b/bundle.c\n@@ -2,6 +2,7 @@\n #include \"lockfile.h\"\n #include \"bundle.h\"\n #include \"object-store.h\"\n+#include \"repository.h\"\n #include \"object.h\"\n #include \"commit.h\"\n #include \"diff.h\"\n@@ -143,7 +144,7 @@ int verify_bundle(struct bundle_header *header, int verbose)\n \tinit_revisions(&revs, NULL);\n \tfor (i = 0; i < p->nr; i++) {\n \t\tstruct ref_list_entry *e = p->list + i;\n-\t\tstruct object *o = parse_object(&e->oid);\n+\t\tstruct object *o = parse_object(the_repository, &e->oid);\n \t\tif (o) {\n \t\t\to->flags |= PREREQ_MARK;\n \t\t\tadd_pending_object(&revs, o, e->name);\ndiff --git a/commit.c b/commit.c\nindex b60906d3f9..742d710c86 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -23,7 +23,8 @@ const char *commit_type = \"commit\";\n struct commit *lookup_commit_reference_gently(const struct object_id *oid,\n \t\t\t\t\t      int quiet)\n {\n-\tstruct object *obj = deref_tag(parse_object(oid), NULL, 0);\n+\tstruct object *obj = deref_tag(parse_object(the_repository, oid),\n+\t\t\t\t       NULL, 0);\n \n \tif (!obj)\n \t\treturn NULL;\n@@ -1606,7 +1607,7 @@ struct commit *get_merge_parent(const char *name)\n \tstruct object_id oid;\n \tif (get_oid(name, &oid))\n \t\treturn NULL;\n-\tobj = parse_object(&oid);\n+\tobj = parse_object(the_repository, &oid);\n \tcommit = (struct commit *)peel_to_type(name, 0, obj, OBJ_COMMIT);\n \tif (commit && !commit->util)\n \t\tset_merge_remote_desc(commit, name, obj);\ndiff --git a/contrib/coccinelle/object_parser.cocci b/contrib/coccinelle/object_parser.cocci\nnew file mode 100644\nindex 0000000000..a9afe4bf7a\n--- /dev/null\n+++ b/contrib/coccinelle/object_parser.cocci\n@@ -0,0 +1,6 @@\n+@@\n+expression E;\n+@@\n+ parse_object(\n++ the_repository,\n+ E)\ndiff --git a/fetch-pack.c b/fetch-pack.c\nindex 9c189ff3ec..0f7aeabb64 100644\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -82,7 +82,7 @@ static void cache_one_alternate(const char *refname,\n \t\t\t\tvoid *vcache)\n {\n \tstruct alternate_object_cache *cache = vcache;\n-\tstruct object *obj = parse_object(oid);\n+\tstruct object *obj = parse_object(the_repository, oid);\n \n \tif (!obj || (obj->flags & ALTERNATE))\n \t\treturn;\n@@ -124,7 +124,8 @@ static void rev_list_push(struct commit *commit, int mark)\n \n static int rev_list_insert_ref(const char *refname, const struct object_id *oid)\n {\n-\tstruct object *o = deref_tag(parse_object(oid), refname, 0);\n+\tstruct object *o = deref_tag(parse_object(the_repository, oid),\n+\t\t\t\t     refname, 0);\n \n \tif (o && o->type == OBJ_COMMIT)\n \t\trev_list_push((struct commit *)o, SEEN);\n@@ -141,7 +142,8 @@ static int rev_list_insert_ref_oid(const char *refname, const struct object_id *\n static int clear_marks(const char *refname, const struct object_id *oid,\n \t\t       int flag, void *cb_data)\n {\n-\tstruct object *o = deref_tag(parse_object(oid), refname, 0);\n+\tstruct object *o = deref_tag(parse_object(the_repository, oid),\n+\t\t\t\t     refname, 0);\n \n \tif (o && o->type == OBJ_COMMIT)\n \t\tclear_commit_marks((struct commit *)o,\n@@ -430,7 +432,7 @@ static int find_common(struct fetch_pack_args *args,\n \t\t\t\tif (!lookup_object(oid.hash))\n \t\t\t\t\tdie(_(\"object not found: %s\"), line);\n \t\t\t\t/* make sure that it is parsed as shallow */\n-\t\t\t\tif (!parse_object(&oid))\n+\t\t\t\tif (!parse_object(the_repository, &oid))\n \t\t\t\t\tdie(_(\"error in object: %s\"), line);\n \t\t\t\tif (unregister_shallow(&oid))\n \t\t\t\t\tdie(_(\"no shallow found: %s\"), line);\n@@ -561,14 +563,14 @@ static struct commit_list *complete;\n \n static int mark_complete(const struct object_id *oid)\n {\n-\tstruct object *o = parse_object(oid);\n+\tstruct object *o = parse_object(the_repository, oid);\n \n \twhile (o && o->type == OBJ_TAG) {\n \t\tstruct tag *t = (struct tag *) o;\n \t\tif (!t->tagged)\n \t\t\tbreak; /* broken repository */\n \t\to->flags |= COMPLETE;\n-\t\to = parse_object(&t->tagged->oid);\n+\t\to = parse_object(the_repository, &t->tagged->oid);\n \t}\n \tif (o && o->type == OBJ_COMMIT) {\n \t\tstruct commit *commit = (struct commit *)o;\n@@ -721,7 +723,7 @@ static int everything_local(struct fetch_pack_args *args,\n \t\t\t\t\t\tOBJECT_INFO_QUICK))\n \t\t\tcontinue;\n \n-\t\to = parse_object(&ref->old_oid);\n+\t\to = parse_object(the_repository, &ref->old_oid);\n \t\tif (!o)\n \t\t\tcontinue;\n \ndiff --git a/fsck.c b/fsck.c\nindex d106714bf5..843ddc1035 100644\n--- a/fsck.c\n+++ b/fsck.c\n@@ -1,5 +1,6 @@\n #include \"cache.h\"\n #include \"object-store.h\"\n+#include \"repository.h\"\n #include \"object.h\"\n #include \"blob.h\"\n #include \"tree.h\"\n@@ -462,7 +463,7 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options)\n \t\treturn -1;\n \n \tif (obj->type == OBJ_NONE)\n-\t\tparse_object(&obj->oid);\n+\t\tparse_object(the_repository, &obj->oid);\n \n \tswitch (obj->type) {\n \tcase OBJ_BLOB:\ndiff --git a/http-backend.c b/http-backend.c\nindex 4950078c93..b76c8c4f3d 100644\n--- a/http-backend.c\n+++ b/http-backend.c\n@@ -435,7 +435,7 @@ static int show_text_ref(const char *name, const struct object_id *oid,\n {\n \tconst char *name_nons = strip_namespace(name);\n \tstruct strbuf *buf = cb_data;\n-\tstruct object *o = parse_object(oid);\n+\tstruct object *o = parse_object(the_repository, oid);\n \tif (!o)\n \t\treturn 0;\n \ndiff --git a/http-push.c b/http-push.c\nindex 34c5d030b7..b4c3cd1cd7 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -1,4 +1,5 @@\n #include \"cache.h\"\n+#include \"repository.h\"\n #include \"object-store.h\"\n #include \"commit.h\"\n #include \"tag.h\"\n@@ -14,6 +15,7 @@\n #include \"argv-array.h\"\n #include \"packfile.h\"\n \n+\n #ifdef EXPAT_NEEDS_XMLPARSE_H\n #include <xmlparse.h>\n #else\n@@ -722,7 +724,7 @@ static void one_remote_object(const struct object_id *oid)\n \n \tobj = lookup_object(oid->hash);\n \tif (!obj)\n-\t\tobj = parse_object(oid);\n+\t\tobj = parse_object(the_repository, oid);\n \n \t/* Ignore remote objects that don't exist locally */\n \tif (!obj)\n@@ -1455,7 +1457,7 @@ static void add_remote_info_ref(struct remote_ls_ctx *ls)\n \t\treturn;\n \t}\n \n-\to = parse_object(&ref->old_oid);\n+\to = parse_object(the_repository, &ref->old_oid);\n \tif (!o) {\n \t\tfprintf(stderr,\n \t\t\t\"Unable to parse object %s for remote ref %s\\n\",\ndiff --git a/log-tree.c b/log-tree.c\nindex b2fff6b5f6..57d5e5f56d 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -2,6 +2,7 @@\n #include \"config.h\"\n #include \"diff.h\"\n #include \"object-store.h\"\n+#include \"repository.h\"\n #include \"commit.h\"\n #include \"tag.h\"\n #include \"graph.h\"\n@@ -111,13 +112,13 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid,\n \t\t\twarning(\"invalid replace ref %s\", refname);\n \t\t\treturn 0;\n \t\t}\n-\t\tobj = parse_object(&original_oid);\n+\t\tobj = parse_object(the_repository, &original_oid);\n \t\tif (obj)\n \t\t\tadd_name_decoration(DECORATION_GRAFTED, \"replaced\", obj);\n \t\treturn 0;\n \t}\n \n-\tobj = parse_object(oid);\n+\tobj = parse_object(the_repository, oid);\n \tif (!obj)\n \t\treturn 0;\n \n@@ -138,7 +139,7 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid,\n \t\tif (!obj)\n \t\t\tbreak;\n \t\tif (!obj->parsed)\n-\t\t\tparse_object(&obj->oid);\n+\t\t\tparse_object(the_repository, &obj->oid);\n \t\tadd_name_decoration(DECORATION_REF_TAG, refname, obj);\n \t}\n \treturn 0;\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 620e4f653c..e2c434c305 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -9,6 +9,7 @@\n #include \"lockfile.h\"\n #include \"cache-tree.h\"\n #include \"object-store.h\"\n+#include \"repository.h\"\n #include \"commit.h\"\n #include \"blob.h\"\n #include \"builtin.h\"\n@@ -2151,7 +2152,8 @@ static struct commit *get_ref(const struct object_id *oid, const char *name)\n {\n \tstruct object *object;\n \n-\tobject = deref_tag(parse_object(oid), name, strlen(name));\n+\tobject = deref_tag(parse_object(the_repository, oid), name,\n+\t\t\t   strlen(name));\n \tif (!object)\n \t\treturn NULL;\n \tif (object->type == OBJ_TREE)\ndiff --git a/object.c b/object.c\nindex 18ea8cf574..c1154039df 100644\n--- a/object.c\n+++ b/object.c\n@@ -234,14 +234,14 @@ struct object *parse_object_buffer(const struct object_id *oid, enum object_type\n struct object *parse_object_or_die(const struct object_id *oid,\n \t\t\t\t   const char *name)\n {\n-\tstruct object *o = parse_object(oid);\n+\tstruct object *o = parse_object(the_repository, oid);\n \tif (o)\n \t\treturn o;\n \n \tdie(_(\"unable to parse object: %s\"), name ? name : oid_to_hex(oid));\n }\n \n-struct object *parse_object(const struct object_id *oid)\n+struct object *parse_object_the_repository(const struct object_id *oid)\n {\n \tunsigned long size;\n \tenum object_type type;\ndiff --git a/object.h b/object.h\nindex 2cff106ff7..e5cad09fad 100644\n--- a/object.h\n+++ b/object.h\n@@ -109,7 +109,8 @@ void *object_as_type(struct object *obj, enum object_type type, int quiet);\n  *\n  * Returns NULL if the object is missing or corrupt.\n  */\n-struct object *parse_object(const struct object_id *oid);\n+#define parse_object(r, oid) parse_object_##r(oid)\n+struct object *parse_object_the_repository(const struct object_id *oid);\n \n /*\n  * Like parse_object, but will die() instead of returning NULL. If the\ndiff --git a/pretty.c b/pretty.c\nindex f7ce490230..478af1a860 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -1146,7 +1146,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */\n \n \t/* these depend on the commit */\n \tif (!commit->object.parsed)\n-\t\tparse_object(&commit->object.oid);\n+\t\tparse_object(the_repository, &commit->object.oid);\n \n \tswitch (placeholder[0]) {\n \tcase 'H':\t\t/* commit hash */\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 0a106b888d..1d0bad5e36 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -4,6 +4,7 @@\n #include \"refs.h\"\n #include \"wildmatch.h\"\n #include \"object-store.h\"\n+#include \"repository.h\"\n #include \"commit.h\"\n #include \"remote.h\"\n #include \"color.h\"\n@@ -1818,7 +1819,7 @@ static const struct object_id *match_points_at(struct oid_array *points_at,\n \n \tif (oid_array_lookup(points_at, oid) >= 0)\n \t\treturn oid;\n-\tobj = parse_object(oid);\n+\tobj = parse_object(the_repository, oid);\n \tif (!obj)\n \t\tdie(_(\"malformed object at '%s'\"), refname);\n \tif (obj->type == OBJ_TAG)\ndiff --git a/reflog-walk.c b/reflog-walk.c\nindex 5008bbf6ad..3561a8b955 100644\n--- a/reflog-walk.c\n+++ b/reflog-walk.c\n@@ -305,7 +305,8 @@ static struct commit *next_reflog_commit(struct commit_reflog *log)\n {\n \tfor (; log->recno >= 0; log->recno--) {\n \t\tstruct reflog_info *entry = &log->reflogs->items[log->recno];\n-\t\tstruct object *obj = parse_object(&entry->noid);\n+\t\tstruct object *obj = parse_object(the_repository,\n+\t\t\t\t\t\t  &entry->noid);\n \n \t\tif (obj && obj->type == OBJ_COMMIT)\n \t\t\treturn (struct commit *)obj;\ndiff --git a/refs/files-backend.c b/refs/files-backend.c\nindex f75d960e19..932fdc1f0b 100644\n--- a/refs/files-backend.c\n+++ b/refs/files-backend.c\n@@ -1658,7 +1658,7 @@ static int write_ref_to_lockfile(struct ref_lock *lock,\n \tstruct object *o;\n \tint fd;\n \n-\to = parse_object(oid);\n+\to = parse_object(the_repository, oid);\n \tif (!o) {\n \t\tstrbuf_addf(err,\n \t\t\t    \"trying to write ref '%s' with nonexistent object %s\",\ndiff --git a/remote.c b/remote.c\nindex fd8cd8ce77..2abc6baf84 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -1980,12 +1980,12 @@ int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid)\n \t * Both new and old must be commit-ish and new is descendant of\n \t * old.  Otherwise we require --force.\n \t */\n-\to = deref_tag(parse_object(old_oid), NULL, 0);\n+\to = deref_tag(parse_object(the_repository, old_oid), NULL, 0);\n \tif (!o || o->type != OBJ_COMMIT)\n \t\treturn 0;\n \told = (struct commit *) o;\n \n-\to = deref_tag(parse_object(new_oid), NULL, 0);\n+\to = deref_tag(parse_object(the_repository, new_oid), NULL, 0);\n \tif (!o || o->type != OBJ_COMMIT)\n \t\treturn 0;\n \tnew = (struct commit *) o;\ndiff --git a/revision.c b/revision.c\nindex e98bdf2ac7..5ccfc50447 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -184,7 +184,7 @@ void add_head_to_pending(struct rev_info *revs)\n \tstruct object *obj;\n \tif (get_oid(\"HEAD\", &oid))\n \t\treturn;\n-\tobj = parse_object(&oid);\n+\tobj = parse_object(the_repository, &oid);\n \tif (!obj)\n \t\treturn;\n \tadd_pending_object(revs, obj, \"HEAD\");\n@@ -196,7 +196,7 @@ static struct object *get_reference(struct rev_info *revs, const char *name,\n {\n \tstruct object *object;\n \n-\tobject = parse_object(oid);\n+\tobject = parse_object(the_repository, oid);\n \tif (!object) {\n \t\tif (revs->ignore_missing)\n \t\t\treturn object;\n@@ -231,7 +231,7 @@ static struct commit *handle_commit(struct rev_info *revs,\n \t\t\tadd_pending_object(revs, object, tag->tag);\n \t\tif (!tag->tagged)\n \t\t\tdie(\"bad tag\");\n-\t\tobject = parse_object(&tag->tagged->oid);\n+\t\tobject = parse_object(the_repository, &tag->tagged->oid);\n \t\tif (!object) {\n \t\t\tif (revs->ignore_missing_links || (flags & UNINTERESTING))\n \t\t\t\treturn NULL;\n@@ -1222,7 +1222,7 @@ static void handle_one_reflog_commit(struct object_id *oid, void *cb_data)\n {\n \tstruct all_refs_cb *cb = cb_data;\n \tif (!is_null_oid(oid)) {\n-\t\tstruct object *o = parse_object(oid);\n+\t\tstruct object *o = parse_object(the_repository, oid);\n \t\tif (o) {\n \t\t\to->flags |= cb->all_flags;\n \t\t\t/* ??? CMDLINEFLAGS ??? */\n@@ -1549,8 +1549,8 @@ static int handle_dotdot_1(const char *arg, char *dotdot,\n \t\t*dotdot = '\\0';\n \t}\n \n-\ta_obj = parse_object(&a_oid);\n-\tb_obj = parse_object(&b_oid);\n+\ta_obj = parse_object(the_repository, &a_oid);\n+\tb_obj = parse_object(the_repository, &b_oid);\n \tif (!a_obj || !b_obj)\n \t\treturn dotdot_missing(arg, dotdot, revs, symmetric);\n \ndiff --git a/server-info.c b/server-info.c\nindex 6cd1506e5e..fd7ed2a383 100644\n--- a/server-info.c\n+++ b/server-info.c\n@@ -56,7 +56,7 @@ static int add_info_ref(const char *path, const struct object_id *oid,\n \t\t\tint flag, void *cb_data)\n {\n \tFILE *fp = cb_data;\n-\tstruct object *o = parse_object(oid);\n+\tstruct object *o = parse_object(the_repository, oid);\n \tif (!o)\n \t\treturn -1;\n \ndiff --git a/sha1_name.c b/sha1_name.c\nindex 190710c638..0139b480a3 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -259,7 +259,7 @@ static int disambiguate_committish_only(const struct object_id *oid, void *cb_da\n \t\treturn 0;\n \n \t/* We need to do this the hard way... */\n-\tobj = deref_tag(parse_object(oid), NULL, 0);\n+\tobj = deref_tag(parse_object(the_repository, oid), NULL, 0);\n \tif (obj && obj->type == OBJ_COMMIT)\n \t\treturn 1;\n \treturn 0;\n@@ -283,7 +283,7 @@ static int disambiguate_treeish_only(const struct object_id *oid, void *cb_data_\n \t\treturn 0;\n \n \t/* We need to do this the hard way... */\n-\tobj = deref_tag(parse_object(oid), NULL, 0);\n+\tobj = deref_tag(parse_object(the_repository, oid), NULL, 0);\n \tif (obj && (obj->type == OBJ_TREE || obj->type == OBJ_COMMIT))\n \t\treturn 1;\n \treturn 0;\n@@ -894,7 +894,7 @@ struct object *peel_to_type(const char *name, int namelen,\n \tif (name && !namelen)\n \t\tnamelen = strlen(name);\n \twhile (1) {\n-\t\tif (!o || (!o->parsed && !parse_object(&o->oid)))\n+\t\tif (!o || (!o->parsed && !parse_object(the_repository, &o->oid)))\n \t\t\treturn NULL;\n \t\tif (expected_type == OBJ_ANY || o->type == expected_type)\n \t\t\treturn o;\n@@ -967,12 +967,12 @@ static int peel_onion(const char *name, int len, struct object_id *oid,\n \tif (get_oid_1(name, sp - name - 2, &outer, lookup_flags))\n \t\treturn -1;\n \n-\to = parse_object(&outer);\n+\to = parse_object(the_repository, &outer);\n \tif (!o)\n \t\treturn -1;\n \tif (!expected_type) {\n \t\to = deref_tag(o, name, sp - name - 2);\n-\t\tif (!o || (!o->parsed && !parse_object(&o->oid)))\n+\t\tif (!o || (!o->parsed && !parse_object(the_repository, &o->oid)))\n \t\t\treturn -1;\n \t\toidcpy(oid, &o->oid);\n \t\treturn 0;\n@@ -1099,7 +1099,7 @@ static int handle_one_ref(const char *path, const struct object_id *oid,\n \t\t\t  int flag, void *cb_data)\n {\n \tstruct commit_list **list = cb_data;\n-\tstruct object *object = parse_object(oid);\n+\tstruct object *object = parse_object(the_repository, oid);\n \tif (!object)\n \t\treturn 0;\n \tif (object->type == OBJ_TAG) {\n@@ -1145,7 +1145,7 @@ static int get_oid_oneline(const char *prefix, struct object_id *oid,\n \t\tint matches;\n \n \t\tcommit = pop_most_recent_commit(&list, ONELINE_SEEN);\n-\t\tif (!parse_object(&commit->object.oid))\n+\t\tif (!parse_object(the_repository, &commit->object.oid))\n \t\t\tcontinue;\n \t\tbuf = get_commit_buffer(commit, NULL);\n \t\tp = strstr(buf, \"\\n\\n\");\ndiff --git a/tag.c b/tag.c\nindex 7b32afd123..5207f70885 100644\n--- a/tag.c\n+++ b/tag.c\n@@ -68,7 +68,8 @@ struct object *deref_tag(struct object *o, const char *warn, int warnlen)\n {\n \twhile (o && o->type == OBJ_TAG)\n \t\tif (((struct tag *)o)->tagged)\n-\t\t\to = parse_object(&((struct tag *)o)->tagged->oid);\n+\t\t\to = parse_object(the_repository,\n+\t\t\t\t\t &((struct tag *)o)->tagged->oid);\n \t\telse\n \t\t\to = NULL;\n \tif (!o && warn) {\n@@ -82,7 +83,7 @@ struct object *deref_tag(struct object *o, const char *warn, int warnlen)\n struct object *deref_tag_noverify(struct object *o)\n {\n \twhile (o && o->type == OBJ_TAG) {\n-\t\to = parse_object(&o->oid);\n+\t\to = parse_object(the_repository, &o->oid);\n \t\tif (o && o->type == OBJ_TAG && ((struct tag *)o)->tagged)\n \t\t\to = ((struct tag *)o)->tagged;\n \t\telse\ndiff --git a/tree.c b/tree.c\nindex 653339db03..62d78fb4ba 100644\n--- a/tree.c\n+++ b/tree.c\n@@ -7,6 +7,7 @@\n #include \"commit.h\"\n #include \"tag.h\"\n #include \"tree-walk.h\"\n+#include \"repository.h\"\n \n const char *tree_type = \"tree\";\n \n@@ -242,7 +243,7 @@ void free_tree_buffer(struct tree *tree)\n \n struct tree *parse_tree_indirect(const struct object_id *oid)\n {\n-\tstruct object *obj = parse_object(oid);\n+\tstruct object *obj = parse_object(the_repository, oid);\n \tdo {\n \t\tif (!obj)\n \t\t\treturn NULL;\n@@ -255,6 +256,6 @@ struct tree *parse_tree_indirect(const struct object_id *oid)\n \t\telse\n \t\t\treturn NULL;\n \t\tif (!obj->parsed)\n-\t\t\tparse_object(&obj->oid);\n+\t\t\tparse_object(the_repository, &obj->oid);\n \t} while (1);\n }\ndiff --git a/upload-pack.c b/upload-pack.c\nindex 6db85ecdc4..b076cbc5f7 100644\n--- a/upload-pack.c\n+++ b/upload-pack.c\n@@ -3,6 +3,7 @@\n #include \"refs.h\"\n #include \"pkt-line.h\"\n #include \"sideband.h\"\n+#include \"repository.h\"\n #include \"object-store.h\"\n #include \"tag.h\"\n #include \"object.h\"\n@@ -299,7 +300,7 @@ static int got_oid(const char *hex, struct object_id *oid)\n \tif (!has_object_file(oid))\n \t\treturn -1;\n \n-\to = parse_object(oid);\n+\to = parse_object(the_repository, oid);\n \tif (!o)\n \t\tdie(\"oops (%s)\", oid_to_hex(oid));\n \tif (o->type == OBJ_COMMIT) {\n@@ -337,7 +338,7 @@ static int reachable(struct commit *want)\n \t\t\tbreak;\n \t\t}\n \t\tif (!commit->object.parsed)\n-\t\t\tparse_object(&commit->object.oid);\n+\t\t\tparse_object(the_repository, &commit->object.oid);\n \t\tif (commit->object.flags & REACHABLE)\n \t\t\tcontinue;\n \t\tcommit->object.flags |= REACHABLE;\n@@ -758,7 +759,7 @@ static void receive_needs(void)\n \t\t\tstruct object *object;\n \t\t\tif (get_oid_hex(arg, &oid))\n \t\t\t\tdie(\"invalid shallow line: %s\", line);\n-\t\t\tobject = parse_object(&oid);\n+\t\t\tobject = parse_object(the_repository, &oid);\n \t\t\tif (!object)\n \t\t\t\tcontinue;\n \t\t\tif (object->type != OBJ_COMMIT)\n@@ -824,7 +825,7 @@ static void receive_needs(void)\n \t\tif (parse_feature_request(features, \"include-tag\"))\n \t\t\tuse_include_tag = 1;\n \n-\t\to = parse_object(&oid_buf);\n+\t\to = parse_object(the_repository, &oid_buf);\n \t\tif (!o) {\n \t\t\tpacket_write_fmt(1,\n \t\t\t\t\t \"ERR upload-pack: not our ref %s\",\ndiff --git a/walker.c b/walker.c\nindex 49b6a96e6e..492aea906f 100644\n--- a/walker.c\n+++ b/walker.c\n@@ -1,5 +1,6 @@\n #include \"cache.h\"\n #include \"walker.h\"\n+#include \"repository.h\"\n #include \"object-store.h\"\n #include \"commit.h\"\n #include \"tree.h\"\n@@ -181,7 +182,7 @@ static int loop(struct walker *walker)\n \t\t\t}\n \t\t}\n \t\tif (!obj->type)\n-\t\t\tparse_object(&obj->oid);\n+\t\t\tparse_object(the_repository, &obj->oid);\n \t\tif (process_object(walker, obj))\n \t\t\treturn -1;\n \t}\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338348","messageId":"20180205235735.216710-61-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 081/194] object: add repository argument to create_object","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:42Z","receivedAt":"2018-02-06T00:11:44Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow the callers of create_object\nto be more specific about which repository to act on. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nAdd the cocci patch that converted the callers.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n blob.c                                 | 4 +++-\n commit.c                               | 3 ++-\n contrib/coccinelle/object_parser.cocci | 8 ++++++++\n object.c                               | 5 +++--\n object.h                               | 3 ++-\n tag.c                                  | 3 ++-\n tree.c                                 | 3 ++-\n 7 files changed, 22 insertions(+), 7 deletions(-)\n\ndiff --git a/blob.c b/blob.c\nindex fa2ab4f7a7..85c2143f29 100644\n--- a/blob.c\n+++ b/blob.c\n@@ -1,5 +1,6 @@\n #include \"cache.h\"\n #include \"blob.h\"\n+#include \"repository.h\"\n \n const char *blob_type = \"blob\";\n \n@@ -7,7 +8,8 @@ struct blob *lookup_blob(const struct object_id *oid)\n {\n \tstruct object *obj = lookup_object(oid->hash);\n \tif (!obj)\n-\t\treturn create_object(oid->hash, alloc_blob_node());\n+\t\treturn create_object(the_repository, oid->hash,\n+\t\t\t\t     alloc_blob_node());\n \treturn object_as_type(obj, OBJ_BLOB, 0);\n }\n \ndiff --git a/commit.c b/commit.c\nindex 742d710c86..e315d5435b 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -52,7 +52,8 @@ struct commit *lookup_commit(const struct object_id *oid)\n {\n \tstruct object *obj = lookup_object(oid->hash);\n \tif (!obj)\n-\t\treturn create_object(oid->hash, alloc_commit_node());\n+\t\treturn create_object(the_repository, oid->hash,\n+\t\t\t\t     alloc_commit_node());\n \treturn object_as_type(obj, OBJ_COMMIT, 0);\n }\n \ndiff --git a/contrib/coccinelle/object_parser.cocci b/contrib/coccinelle/object_parser.cocci\nindex a9afe4bf7a..2a554084d1 100644\n--- a/contrib/coccinelle/object_parser.cocci\n+++ b/contrib/coccinelle/object_parser.cocci\n@@ -4,3 +4,11 @@ expression E;\n  parse_object(\n + the_repository,\n  E)\n+\n+@@\n+expression E;\n+expression F;\n+@@\n+ create_object(\n++ the_repository,\n+ E, F)\ndiff --git a/object.c b/object.c\nindex c1154039df..1126c7e278 100644\n--- a/object.c\n+++ b/object.c\n@@ -137,7 +137,7 @@ static void grow_object_hash(void)\n \tthe_repository->parsed_objects.obj_hash_size = new_hash_size;\n }\n \n-void *create_object(const unsigned char *sha1, void *o)\n+void *create_object_the_repository(const unsigned char *sha1, void *o)\n {\n \tstruct object *obj = o;\n \n@@ -177,7 +177,8 @@ struct object *lookup_unknown_object(const unsigned char *sha1)\n {\n \tstruct object *obj = lookup_object(sha1);\n \tif (!obj)\n-\t\tobj = create_object(sha1, alloc_object_node());\n+\t\tobj = create_object(the_repository, sha1,\n+\t\t\t\t    alloc_object_node());\n \treturn obj;\n }\n \ndiff --git a/object.h b/object.h\nindex e5cad09fad..ac12dc3629 100644\n--- a/object.h\n+++ b/object.h\n@@ -100,7 +100,8 @@ extern struct object *get_indexed_object(unsigned int);\n  */\n struct object *lookup_object(const unsigned char *sha1);\n \n-extern void *create_object(const unsigned char *sha1, void *obj);\n+#define create_object(r, s, o) create_object_##r(s, o)\n+extern void *create_object_the_repository(const unsigned char *sha1, void *obj);\n \n void *object_as_type(struct object *obj, enum object_type type, int quiet);\n \ndiff --git a/tag.c b/tag.c\nindex 5207f70885..a9e5af4294 100644\n--- a/tag.c\n+++ b/tag.c\n@@ -96,7 +96,8 @@ struct tag *lookup_tag(const struct object_id *oid)\n {\n \tstruct object *obj = lookup_object(oid->hash);\n \tif (!obj)\n-\t\treturn create_object(oid->hash, alloc_tag_node());\n+\t\treturn create_object(the_repository, oid->hash,\n+\t\t\t\t     alloc_tag_node());\n \treturn object_as_type(obj, OBJ_TAG, 0);\n }\n \ndiff --git a/tree.c b/tree.c\nindex 62d78fb4ba..f8e1e6d63d 100644\n--- a/tree.c\n+++ b/tree.c\n@@ -198,7 +198,8 @@ struct tree *lookup_tree(const struct object_id *oid)\n {\n \tstruct object *obj = lookup_object(oid->hash);\n \tif (!obj)\n-\t\treturn create_object(oid->hash, alloc_tree_node());\n+\t\treturn create_object(the_repository, oid->hash,\n+\t\t\t\t     alloc_tree_node());\n \treturn object_as_type(obj, OBJ_TREE, 0);\n }\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338349","messageId":"20180205235735.216710-62-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 082/194] object: add repository argument to lookup_object","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:43Z","receivedAt":"2018-02-06T00:11:47Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nAdd a repository argument to allow callers of lookup_object to be more\nspecific about which repository to handle. This is a small mechanical\nchange; it doesn't change the implementation to handle repositories\nother than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nThe included coccinelle semantic patch will adapt any new callers in\nthe diff produced by `make coccicheck`.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n blob.c                                 | 2 +-\n builtin/fast-export.c                  | 5 +++--\n builtin/fsck.c                         | 5 +++--\n builtin/name-rev.c                     | 3 ++-\n builtin/prune.c                        | 2 +-\n builtin/unpack-objects.c               | 2 +-\n commit.c                               | 2 +-\n contrib/coccinelle/object_parser.cocci | 7 +++++++\n fetch-pack.c                           | 8 ++++----\n http-push.c                            | 2 +-\n object.c                               | 8 ++++----\n object.h                               | 3 ++-\n reachable.c                            | 4 ++--\n tag.c                                  | 2 +-\n tree.c                                 | 2 +-\n upload-pack.c                          | 2 +-\n 16 files changed, 35 insertions(+), 24 deletions(-)\n\ndiff --git a/blob.c b/blob.c\nindex 85c2143f29..a9f3aa2ec8 100644\n--- a/blob.c\n+++ b/blob.c\n@@ -6,7 +6,7 @@ const char *blob_type = \"blob\";\n \n struct blob *lookup_blob(const struct object_id *oid)\n {\n-\tstruct object *obj = lookup_object(oid->hash);\n+\tstruct object *obj = lookup_object(the_repository, oid->hash);\n \tif (!obj)\n \t\treturn create_object(the_repository, oid->hash,\n \t\t\t\t     alloc_blob_node());\ndiff --git a/builtin/fast-export.c b/builtin/fast-export.c\nindex 6140caf8d8..642bafdd30 100644\n--- a/builtin/fast-export.c\n+++ b/builtin/fast-export.c\n@@ -230,7 +230,7 @@ static void export_blob(const struct object_id *oid)\n \tif (is_null_oid(oid))\n \t\treturn;\n \n-\tobject = lookup_object(oid->hash);\n+\tobject = lookup_object(the_repository, oid->hash);\n \tif (object && object->flags & SHOWN)\n \t\treturn;\n \n@@ -402,7 +402,8 @@ static void show_filemodify(struct diff_queue_struct *q,\n \t\t\t\t\t\t   anonymize_sha1(&spec->oid) :\n \t\t\t\t\t\t   spec->oid.hash));\n \t\t\telse {\n-\t\t\t\tstruct object *object = lookup_object(spec->oid.hash);\n+\t\t\t\tstruct object *object = lookup_object(the_repository,\n+\t\t\t\t\t\t\t\t      spec->oid.hash);\n \t\t\t\tprintf(\"M %06o :%d \", spec->mode,\n \t\t\t\t       get_object_mark(object));\n \t\t\t}\ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex 9408ae5cc6..7645418821 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -395,7 +395,7 @@ static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid,\n \tstruct object *obj;\n \n \tif (!is_null_oid(oid)) {\n-\t\tobj = lookup_object(oid->hash);\n+\t\tobj = lookup_object(the_repository, oid->hash);\n \t\tif (obj && (obj->flags & HAS_OBJ)) {\n \t\t\tif (timestamp && name_objects)\n \t\t\t\tadd_decoration(fsck_walk_options.object_names,\n@@ -736,7 +736,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)\n \t\tconst char *arg = argv[i];\n \t\tstruct object_id oid;\n \t\tif (!get_oid(arg, &oid)) {\n-\t\t\tstruct object *obj = lookup_object(oid.hash);\n+\t\t\tstruct object *obj = lookup_object(the_repository,\n+\t\t\t\t\t\t\t   oid.hash);\n \n \t\t\tif (!obj || !(obj->flags & HAS_OBJ)) {\n \t\t\t\terror(\"%s: object missing\", oid_to_hex(&oid));\ndiff --git a/builtin/name-rev.c b/builtin/name-rev.c\nindex c6b253eefb..45ec5515cc 100644\n--- a/builtin/name-rev.c\n+++ b/builtin/name-rev.c\n@@ -363,7 +363,8 @@ static void name_rev_line(char *p, struct name_ref_data *data)\n \t\t\t*(p+1) = 0;\n \t\t\tif (!get_oid(p - (GIT_SHA1_HEXSZ - 1), &oid)) {\n \t\t\t\tstruct object *o =\n-\t\t\t\t\tlookup_object(oid.hash);\n+\t\t\t\t\tlookup_object(the_repository,\n+\t\t\t\t\t\t      oid.hash);\n \t\t\t\tif (o)\n \t\t\t\t\tname = get_rev_name(o, &buf);\n \t\t\t}\ndiff --git a/builtin/prune.c b/builtin/prune.c\nindex 7891048b35..06e6de45b5 100644\n--- a/builtin/prune.c\n+++ b/builtin/prune.c\n@@ -40,7 +40,7 @@ static int prune_object(const struct object_id *oid, const char *fullpath,\n \t * Do we know about this object?\n \t * It must have been reachable\n \t */\n-\tif (lookup_object(oid->hash))\n+\tif (lookup_object(the_repository, oid->hash))\n \t\treturn 0;\n \n \tif (lstat(fullpath, &st)) {\ndiff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c\nindex ee707068b3..e26f673a15 100644\n--- a/builtin/unpack-objects.c\n+++ b/builtin/unpack-objects.c\n@@ -329,7 +329,7 @@ static int resolve_against_held(unsigned nr, const struct object_id *base,\n {\n \tstruct object *obj;\n \tstruct obj_buffer *obj_buffer;\n-\tobj = lookup_object(base->hash);\n+\tobj = lookup_object(the_repository, base->hash);\n \tif (!obj)\n \t\treturn 0;\n \tobj_buffer = lookup_object_buffer(obj);\ndiff --git a/commit.c b/commit.c\nindex e315d5435b..68967e6c59 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -50,7 +50,7 @@ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref\n \n struct commit *lookup_commit(const struct object_id *oid)\n {\n-\tstruct object *obj = lookup_object(oid->hash);\n+\tstruct object *obj = lookup_object(the_repository, oid->hash);\n \tif (!obj)\n \t\treturn create_object(the_repository, oid->hash,\n \t\t\t\t     alloc_commit_node());\ndiff --git a/contrib/coccinelle/object_parser.cocci b/contrib/coccinelle/object_parser.cocci\nindex 2a554084d1..d57b0f16d4 100644\n--- a/contrib/coccinelle/object_parser.cocci\n+++ b/contrib/coccinelle/object_parser.cocci\n@@ -12,3 +12,10 @@ expression F;\n  create_object(\n + the_repository,\n  E, F)\n+\n+@@\n+expression E;\n+@@\n+ lookup_object(\n++the_repository,\n+ E)\ndiff --git a/fetch-pack.c b/fetch-pack.c\nindex 0f7aeabb64..02ac850967 100644\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -360,7 +360,7 @@ static int find_common(struct fetch_pack_args *args,\n \t\t * interested in the case we *know* the object is\n \t\t * reachable and we have already scanned it.\n \t\t */\n-\t\tif (((o = lookup_object(remote->hash)) != NULL) &&\n+\t\tif (((o = lookup_object(the_repository, remote->hash)) != NULL) &&\n \t\t\t\t(o->flags & COMPLETE)) {\n \t\t\tcontinue;\n \t\t}\n@@ -429,7 +429,7 @@ static int find_common(struct fetch_pack_args *args,\n \t\t\tif (skip_prefix(line, \"unshallow \", &arg)) {\n \t\t\t\tif (get_oid_hex(arg, &oid))\n \t\t\t\t\tdie(_(\"invalid unshallow line: %s\"), line);\n-\t\t\t\tif (!lookup_object(oid.hash))\n+\t\t\t\tif (!lookup_object(the_repository, oid.hash))\n \t\t\t\t\tdie(_(\"object not found: %s\"), line);\n \t\t\t\t/* make sure that it is parsed as shallow */\n \t\t\t\tif (!parse_object(the_repository, &oid))\n@@ -751,7 +751,7 @@ static int everything_local(struct fetch_pack_args *args,\n \t * Don't mark them common yet; the server has to be told so first.\n \t */\n \tfor (ref = *refs; ref; ref = ref->next) {\n-\t\tstruct object *o = deref_tag(lookup_object(ref->old_oid.hash),\n+\t\tstruct object *o = deref_tag(lookup_object(the_repository, ref->old_oid.hash),\n \t\t\t\t\t     NULL, 0);\n \n \t\tif (!o || o->type != OBJ_COMMIT || !(o->flags & COMPLETE))\n@@ -770,7 +770,7 @@ static int everything_local(struct fetch_pack_args *args,\n \t\tconst struct object_id *remote = &ref->old_oid;\n \t\tstruct object *o;\n \n-\t\to = lookup_object(remote->hash);\n+\t\to = lookup_object(the_repository, remote->hash);\n \t\tif (!o || !(o->flags & COMPLETE)) {\n \t\t\tretval = 0;\n \t\t\tprint_verbose(args, \"want %s (%s)\", oid_to_hex(remote),\ndiff --git a/http-push.c b/http-push.c\nindex b4c3cd1cd7..5149c1b425 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -722,7 +722,7 @@ static void one_remote_object(const struct object_id *oid)\n {\n \tstruct object *obj;\n \n-\tobj = lookup_object(oid->hash);\n+\tobj = lookup_object(the_repository, oid->hash);\n \tif (!obj)\n \t\tobj = parse_object(the_repository, oid);\n \ndiff --git a/object.c b/object.c\nindex 1126c7e278..681fa40eb1 100644\n--- a/object.c\n+++ b/object.c\n@@ -81,7 +81,7 @@ static void insert_obj_hash(struct object *obj, struct object **hash, unsigned i\n  * Look up the record for the given sha1 in the hash map stored in\n  * obj_hash.  Return NULL if it was not found.\n  */\n-struct object *lookup_object(const unsigned char *sha1)\n+struct object *lookup_object_the_repository(const unsigned char *sha1)\n {\n \tunsigned int i, first;\n \tstruct object *obj;\n@@ -175,7 +175,7 @@ void *object_as_type(struct object *obj, enum object_type type, int quiet)\n \n struct object *lookup_unknown_object(const unsigned char *sha1)\n {\n-\tstruct object *obj = lookup_object(sha1);\n+\tstruct object *obj = lookup_object(the_repository, sha1);\n \tif (!obj)\n \t\tobj = create_object(the_repository, sha1,\n \t\t\t\t    alloc_object_node());\n@@ -251,7 +251,7 @@ struct object *parse_object_the_repository(const struct object_id *oid)\n \tvoid *buffer;\n \tstruct object *obj;\n \n-\tobj = lookup_object(oid->hash);\n+\tobj = lookup_object(the_repository, oid->hash);\n \tif (obj && obj->parsed)\n \t\treturn obj;\n \n@@ -263,7 +263,7 @@ struct object *parse_object_the_repository(const struct object_id *oid)\n \t\t\treturn NULL;\n \t\t}\n \t\tparse_blob_buffer(lookup_blob(oid), NULL, 0);\n-\t\treturn lookup_object(oid->hash);\n+\t\treturn lookup_object(the_repository, oid->hash);\n \t}\n \n \tbuffer = read_sha1_file(oid->hash, &type, &size);\ndiff --git a/object.h b/object.h\nindex ac12dc3629..727a03ebd6 100644\n--- a/object.h\n+++ b/object.h\n@@ -98,7 +98,8 @@ extern struct object *get_indexed_object(unsigned int);\n  * half-initialised objects, the caller is expected to initialize them\n  * by calling parse_object() on them.\n  */\n-struct object *lookup_object(const unsigned char *sha1);\n+#define lookup_object(r, s) lookup_object_##r(s)\n+struct object *lookup_object_the_repository(const unsigned char *sha1);\n \n #define create_object(r, s, o) create_object_##r(s, o)\n extern void *create_object_the_repository(const unsigned char *sha1, void *obj);\ndiff --git a/reachable.c b/reachable.c\nindex 7e7b9525c0..4007c6428b 100644\n--- a/reachable.c\n+++ b/reachable.c\n@@ -109,7 +109,7 @@ static int add_recent_loose(const struct object_id *oid,\n \t\t\t    const char *path, void *data)\n {\n \tstruct stat st;\n-\tstruct object *obj = lookup_object(oid->hash);\n+\tstruct object *obj = lookup_object(the_repository, oid->hash);\n \n \tif (obj && obj->flags & SEEN)\n \t\treturn 0;\n@@ -134,7 +134,7 @@ static int add_recent_packed(const struct object_id *oid,\n \t\t\t     struct packed_git *p, uint32_t pos,\n \t\t\t     void *data)\n {\n-\tstruct object *obj = lookup_object(oid->hash);\n+\tstruct object *obj = lookup_object(the_repository, oid->hash);\n \n \tif (obj && obj->flags & SEEN)\n \t\treturn 0;\ndiff --git a/tag.c b/tag.c\nindex a9e5af4294..3712ef7867 100644\n--- a/tag.c\n+++ b/tag.c\n@@ -94,7 +94,7 @@ struct object *deref_tag_noverify(struct object *o)\n \n struct tag *lookup_tag(const struct object_id *oid)\n {\n-\tstruct object *obj = lookup_object(oid->hash);\n+\tstruct object *obj = lookup_object(the_repository, oid->hash);\n \tif (!obj)\n \t\treturn create_object(the_repository, oid->hash,\n \t\t\t\t     alloc_tag_node());\ndiff --git a/tree.c b/tree.c\nindex f8e1e6d63d..8f0ee6c8c0 100644\n--- a/tree.c\n+++ b/tree.c\n@@ -196,7 +196,7 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match,\n \n struct tree *lookup_tree(const struct object_id *oid)\n {\n-\tstruct object *obj = lookup_object(oid->hash);\n+\tstruct object *obj = lookup_object(the_repository, oid->hash);\n \tif (!obj)\n \t\treturn create_object(the_repository, oid->hash,\n \t\t\t\t     alloc_tree_node());\ndiff --git a/upload-pack.c b/upload-pack.c\nindex b076cbc5f7..8716e28d4f 100644\n--- a/upload-pack.c\n+++ b/upload-pack.c\n@@ -556,7 +556,7 @@ static int get_reachable_list(struct object_array *src,\n \t\tif (namebuf[40] != '\\n' || get_oid_hex(namebuf, &sha1))\n \t\t\tbreak;\n \n-\t\to = lookup_object(sha1.hash);\n+\t\to = lookup_object(the_repository, sha1.hash);\n \t\tif (o && o->type == OBJ_COMMIT) {\n \t\t\to->flags &= ~TMP_MARK;\n \t\t}\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338350","messageId":"20180205235735.216710-63-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 083/194] object: add repository argument to grow_object_hash","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:44Z","receivedAt":"2018-02-06T00:12:11Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nAdd a repository argument to allow the caller of grow_object_hash to\nbe more specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n object.c | 5 +++--\n 1 file changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/object.c b/object.c\nindex 681fa40eb1..225679188b 100644\n--- a/object.c\n+++ b/object.c\n@@ -115,7 +115,8 @@ struct object *lookup_object_the_repository(const unsigned char *sha1)\n  * power of 2 (but at least 32).  Copy the existing values to the new\n  * hash map.\n  */\n-static void grow_object_hash(void)\n+#define grow_object_hash(r) grow_object_hash_##r()\n+static void grow_object_hash_the_repository(void)\n {\n \tint i;\n \t/*\n@@ -146,7 +147,7 @@ void *create_object_the_repository(const unsigned char *sha1, void *o)\n \thashcpy(obj->oid.hash, sha1);\n \n \tif (the_repository->parsed_objects.obj_hash_size - 1 <= the_repository->parsed_objects.nr_objs * 2)\n-\t\tgrow_object_hash();\n+\t\tgrow_object_hash(the_repository);\n \n \tinsert_obj_hash(obj, the_repository->parsed_objects.obj_hash,\n \t\t\tthe_repository->parsed_objects.obj_hash_size);\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338351","messageId":"20180205235735.216710-64-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 084/194] blob: add repository argument to lookup_blob","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:45Z","receivedAt":"2018-02-06T00:12:15Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow the callers of lookup_blob\nto be more specific about which repository to act on. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nAdd the cocci patch that converted the callers.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n blob.c                                 | 2 +-\n blob.h                                 | 3 ++-\n builtin/describe.c                     | 2 +-\n builtin/fast-export.c                  | 2 +-\n builtin/fsck.c                         | 3 ++-\n builtin/index-pack.c                   | 2 +-\n builtin/merge-tree.c                   | 3 ++-\n builtin/unpack-objects.c               | 2 +-\n contrib/coccinelle/object_parser.cocci | 7 +++++++\n fsck.c                                 | 2 +-\n http-push.c                            | 3 ++-\n list-objects.c                         | 2 +-\n object.c                               | 4 ++--\n reachable.c                            | 2 +-\n revision.c                             | 4 ++--\n tag.c                                  | 2 +-\n walker.c                               | 3 ++-\n 17 files changed, 30 insertions(+), 18 deletions(-)\n\ndiff --git a/blob.c b/blob.c\nindex a9f3aa2ec8..25faf3e692 100644\n--- a/blob.c\n+++ b/blob.c\n@@ -4,7 +4,7 @@\n \n const char *blob_type = \"blob\";\n \n-struct blob *lookup_blob(const struct object_id *oid)\n+struct blob *lookup_blob_the_repository(const struct object_id *oid)\n {\n \tstruct object *obj = lookup_object(the_repository, oid->hash);\n \tif (!obj)\ndiff --git a/blob.h b/blob.h\nindex 4460616831..08bc34487a 100644\n--- a/blob.h\n+++ b/blob.h\n@@ -9,7 +9,8 @@ struct blob {\n \tstruct object object;\n };\n \n-struct blob *lookup_blob(const struct object_id *oid);\n+#define lookup_blob(r, o) lookup_blob_##r(o)\n+struct blob *lookup_blob_the_repository(const struct object_id *oid);\n \n int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size);\n \ndiff --git a/builtin/describe.c b/builtin/describe.c\nindex 3b0b204b1e..2add1e8d83 100644\n--- a/builtin/describe.c\n+++ b/builtin/describe.c\n@@ -499,7 +499,7 @@ static void describe(const char *arg, int last_one)\n \n \tif (cmit)\n \t\tdescribe_commit(&oid, &sb);\n-\telse if (lookup_blob(&oid))\n+\telse if (lookup_blob(the_repository, &oid))\n \t\tdescribe_blob(oid, &sb);\n \telse\n \t\tdie(_(\"%s is neither a commit nor blob\"), arg);\ndiff --git a/builtin/fast-export.c b/builtin/fast-export.c\nindex 642bafdd30..14a27d539f 100644\n--- a/builtin/fast-export.c\n+++ b/builtin/fast-export.c\n@@ -236,7 +236,7 @@ static void export_blob(const struct object_id *oid)\n \n \tif (anonymize) {\n \t\tbuf = anonymize_blob(&size);\n-\t\tobject = (struct object *)lookup_blob(oid);\n+\t\tobject = (struct object *)lookup_blob(the_repository, oid);\n \t\teaten = 0;\n \t} else {\n \t\tbuf = read_sha1_file(oid->hash, &type, &size);\ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex 7645418821..79da01d338 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -778,7 +778,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)\n \t\t\tmode = active_cache[i]->ce_mode;\n \t\t\tif (S_ISGITLINK(mode))\n \t\t\t\tcontinue;\n-\t\t\tblob = lookup_blob(&active_cache[i]->oid);\n+\t\t\tblob = lookup_blob(the_repository,\n+\t\t\t\t\t   &active_cache[i]->oid);\n \t\t\tif (!blob)\n \t\t\t\tcontinue;\n \t\t\tobj = &blob->object;\ndiff --git a/builtin/index-pack.c b/builtin/index-pack.c\nindex b9851ad69d..67db12fc43 100644\n--- a/builtin/index-pack.c\n+++ b/builtin/index-pack.c\n@@ -834,7 +834,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,\n \tif (strict) {\n \t\tread_lock();\n \t\tif (type == OBJ_BLOB) {\n-\t\t\tstruct blob *blob = lookup_blob(oid);\n+\t\t\tstruct blob *blob = lookup_blob(the_repository, oid);\n \t\t\tif (blob)\n \t\t\t\tblob->object.flags |= FLAG_CHECKED;\n \t\t\telse\ndiff --git a/builtin/merge-tree.c b/builtin/merge-tree.c\nindex ba51ad55a8..41f1ae30cc 100644\n--- a/builtin/merge-tree.c\n+++ b/builtin/merge-tree.c\n@@ -2,6 +2,7 @@\n #include \"tree-walk.h\"\n #include \"xdiff-interface.h\"\n #include \"object-store.h\"\n+#include \"repository.h\"\n #include \"blob.h\"\n #include \"exec_cmd.h\"\n #include \"merge-blobs.h\"\n@@ -169,7 +170,7 @@ static struct merge_list *create_entry(unsigned stage, unsigned mode, const stru\n \tres->stage = stage;\n \tres->path = path;\n \tres->mode = mode;\n-\tres->blob = lookup_blob(oid);\n+\tres->blob = lookup_blob(the_repository, oid);\n \treturn res;\n }\n \ndiff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c\nindex e26f673a15..8d13c5145c 100644\n--- a/builtin/unpack-objects.c\n+++ b/builtin/unpack-objects.c\n@@ -252,7 +252,7 @@ static void write_object(unsigned nr, enum object_type type,\n \t\tadded_object(nr, type, buf, size);\n \t\tfree(buf);\n \n-\t\tblob = lookup_blob(&obj_list[nr].oid);\n+\t\tblob = lookup_blob(the_repository, &obj_list[nr].oid);\n \t\tif (blob)\n \t\t\tblob->object.flags |= FLAG_WRITTEN;\n \t\telse\ndiff --git a/contrib/coccinelle/object_parser.cocci b/contrib/coccinelle/object_parser.cocci\nindex d57b0f16d4..3bc38d2faa 100644\n--- a/contrib/coccinelle/object_parser.cocci\n+++ b/contrib/coccinelle/object_parser.cocci\n@@ -1,3 +1,10 @@\n+@@\n+expression E;\n+@@\n+ lookup_blob(\n++the_repository,\n+ E)\n+\n @@\n expression E;\n @@\ndiff --git a/fsck.c b/fsck.c\nindex 843ddc1035..6d04981735 100644\n--- a/fsck.c\n+++ b/fsck.c\n@@ -367,7 +367,7 @@ static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *op\n \t\t\tresult = options->walk(obj, OBJ_TREE, data, options);\n \t\t}\n \t\telse if (S_ISREG(entry.mode) || S_ISLNK(entry.mode)) {\n-\t\t\tobj = (struct object *)lookup_blob(entry.oid);\n+\t\t\tobj = (struct object *)lookup_blob(the_repository, entry.oid);\n \t\t\tif (name && obj)\n \t\t\t\tput_object_name(options, obj, \"%s%s\", name,\n \t\t\t\t\tentry.path);\ndiff --git a/http-push.c b/http-push.c\nindex 5149c1b425..6c60b12ad1 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -1310,7 +1310,8 @@ static struct object_list **process_tree(struct tree *tree,\n \t\t\tp = process_tree(lookup_tree(entry.oid), p);\n \t\t\tbreak;\n \t\tcase OBJ_BLOB:\n-\t\t\tp = process_blob(lookup_blob(entry.oid), p);\n+\t\t\tp = process_blob(lookup_blob(the_repository, entry.oid),\n+\t\t\t\t\t p);\n \t\t\tbreak;\n \t\tdefault:\n \t\t\t/* Subproject commit - not in this repository */\ndiff --git a/list-objects.c b/list-objects.c\nindex 0966cdc9fa..c11dc1281b 100644\n--- a/list-objects.c\n+++ b/list-objects.c\n@@ -139,7 +139,7 @@ static void process_tree(struct rev_info *revs,\n \t\t\t\t\tcb_data);\n \t\telse\n \t\t\tprocess_blob(revs,\n-\t\t\t\t     lookup_blob(entry.oid),\n+\t\t\t\t     lookup_blob(the_repository, entry.oid),\n \t\t\t\t     show, base, entry.path,\n \t\t\t\t     cb_data, filter_fn, filter_data);\n \t}\ndiff --git a/object.c b/object.c\nindex 225679188b..e0dac087c8 100644\n--- a/object.c\n+++ b/object.c\n@@ -190,7 +190,7 @@ struct object *parse_object_buffer(const struct object_id *oid, enum object_type\n \n \tobj = NULL;\n \tif (type == OBJ_BLOB) {\n-\t\tstruct blob *blob = lookup_blob(oid);\n+\t\tstruct blob *blob = lookup_blob(the_repository, oid);\n \t\tif (blob) {\n \t\t\tif (parse_blob_buffer(blob, buffer, size))\n \t\t\t\treturn NULL;\n@@ -263,7 +263,7 @@ struct object *parse_object_the_repository(const struct object_id *oid)\n \t\t\terror(\"sha1 mismatch %s\", oid_to_hex(oid));\n \t\t\treturn NULL;\n \t\t}\n-\t\tparse_blob_buffer(lookup_blob(oid), NULL, 0);\n+\t\tparse_blob_buffer(lookup_blob(the_repository, oid), NULL, 0);\n \t\treturn lookup_object(the_repository, oid->hash);\n \t}\n \ndiff --git a/reachable.c b/reachable.c\nindex 4007c6428b..943e4518c2 100644\n--- a/reachable.c\n+++ b/reachable.c\n@@ -92,7 +92,7 @@ static void add_recent_object(const struct object_id *oid,\n \t\tobj = (struct object *)lookup_tree(oid);\n \t\tbreak;\n \tcase OBJ_BLOB:\n-\t\tobj = (struct object *)lookup_blob(oid);\n+\t\tobj = (struct object *)lookup_blob(the_repository, oid);\n \t\tbreak;\n \tdefault:\n \t\tdie(\"unknown object type for %s: %s\",\ndiff --git a/revision.c b/revision.c\nindex 5ccfc50447..a7b57e3452 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -67,7 +67,7 @@ static void mark_tree_contents_uninteresting(struct tree *tree)\n \t\t\tmark_tree_uninteresting(lookup_tree(entry.oid));\n \t\t\tbreak;\n \t\tcase OBJ_BLOB:\n-\t\t\tmark_blob_uninteresting(lookup_blob(entry.oid));\n+\t\t\tmark_blob_uninteresting(lookup_blob(the_repository, entry.oid));\n \t\t\tbreak;\n \t\tdefault:\n \t\t\t/* Subproject commit - not in this repository */\n@@ -1321,7 +1321,7 @@ static void do_add_index_objects_to_pending(struct rev_info *revs,\n \t\tif (S_ISGITLINK(ce->ce_mode))\n \t\t\tcontinue;\n \n-\t\tblob = lookup_blob(&ce->oid);\n+\t\tblob = lookup_blob(the_repository, &ce->oid);\n \t\tif (!blob)\n \t\t\tdie(\"unable to add index blob to traversal\");\n \t\tadd_pending_object_with_path(revs, &blob->object, \"\",\ndiff --git a/tag.c b/tag.c\nindex 3712ef7867..4cf449303b 100644\n--- a/tag.c\n+++ b/tag.c\n@@ -146,7 +146,7 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)\n \tbufptr = nl + 1;\n \n \tif (!strcmp(type, blob_type)) {\n-\t\titem->tagged = (struct object *)lookup_blob(&oid);\n+\t\titem->tagged = (struct object *)lookup_blob(the_repository, &oid);\n \t} else if (!strcmp(type, tree_type)) {\n \t\titem->tagged = (struct object *)lookup_tree(&oid);\n \t} else if (!strcmp(type, commit_type)) {\ndiff --git a/walker.c b/walker.c\nindex 492aea906f..f5a221d48e 100644\n--- a/walker.c\n+++ b/walker.c\n@@ -54,7 +54,8 @@ static int process_tree(struct walker *walker, struct tree *tree)\n \t\t\t\tobj = &tree->object;\n \t\t}\n \t\telse {\n-\t\t\tstruct blob *blob = lookup_blob(entry.oid);\n+\t\t\tstruct blob *blob = lookup_blob(the_repository,\n+\t\t\t\t\t\t\tentry.oid);\n \t\t\tif (blob)\n \t\t\t\tobj = &blob->object;\n \t\t}\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338352","messageId":"20180205235735.216710-65-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 085/194] tree: add repository argument to lookup_tree","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:46Z","receivedAt":"2018-02-06T00:12:39Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow the callers of lookup_tree\nto be more specific about which repository to act on. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nAdd the cocci patch that converted the callers.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n builtin/am.c                           | 6 ++++--\n builtin/diff-tree.c                    | 2 +-\n builtin/diff.c                         | 3 ++-\n builtin/reflog.c                       | 2 +-\n cache-tree.c                           | 3 ++-\n commit.c                               | 2 +-\n contrib/coccinelle/object_parser.cocci | 8 ++++++++\n fsck.c                                 | 2 +-\n http-push.c                            | 3 ++-\n list-objects.c                         | 2 +-\n merge-recursive.c                      | 6 +++---\n object.c                               | 2 +-\n reachable.c                            | 2 +-\n revision.c                             | 4 ++--\n sequencer.c                            | 2 +-\n tag.c                                  | 2 +-\n tree.c                                 | 4 ++--\n tree.h                                 | 3 ++-\n walker.c                               | 3 ++-\n 19 files changed, 38 insertions(+), 23 deletions(-)\n\ndiff --git a/builtin/am.c b/builtin/am.c\nindex acfe9d3c8c..32002a8661 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -32,6 +32,7 @@\n #include \"apply.h\"\n #include \"string-list.h\"\n #include \"packfile.h\"\n+#include \"repository.h\"\n \n /**\n  * Returns 1 if the file is empty or does not exist, 0 otherwise.\n@@ -1398,9 +1399,10 @@ static void write_index_patch(const struct am_state *state)\n \tFILE *fp;\n \n \tif (!get_oid_tree(\"HEAD\", &head))\n-\t\ttree = lookup_tree(&head);\n+\t\ttree = lookup_tree(the_repository, &head);\n \telse\n-\t\ttree = lookup_tree(the_hash_algo->empty_tree);\n+\t\ttree = lookup_tree(the_repository,\n+\t\t\t\t   the_repository->hash_algo->empty_tree);\n \n \tfp = xfopen(am_path(state, \"patch\"), \"w\");\n \tinit_revisions(&rev_info, NULL);\ndiff --git a/builtin/diff-tree.c b/builtin/diff-tree.c\nindex 1f78308e33..ab491efa9e 100644\n--- a/builtin/diff-tree.c\n+++ b/builtin/diff-tree.c\n@@ -46,7 +46,7 @@ static int stdin_diff_trees(struct tree *tree1, const char *p)\n \tstruct tree *tree2;\n \tif (!isspace(*p++) || parse_oid_hex(p, &oid, &p) || *p)\n \t\treturn error(\"Need exactly two trees, separated by a space\");\n-\ttree2 = lookup_tree(&oid);\n+\ttree2 = lookup_tree(the_repository, &oid);\n \tif (!tree2 || parse_tree(tree2))\n \t\treturn -1;\n \tprintf(\"%s %s\\n\", oid_to_hex(&tree1->object.oid),\ndiff --git a/builtin/diff.c b/builtin/diff.c\nindex ed6092ef1a..0b7d0d612d 100644\n--- a/builtin/diff.c\n+++ b/builtin/diff.c\n@@ -379,7 +379,8 @@ int cmd_diff(int argc, const char **argv, const char *prefix)\n \t\t\t\tadd_head_to_pending(&rev);\n \t\t\t\tif (!rev.pending.nr) {\n \t\t\t\t\tstruct tree *tree;\n-\t\t\t\t\ttree = lookup_tree(the_hash_algo->empty_tree);\n+\t\t\t\t\ttree = lookup_tree(the_repository,\n+\t\t\t\t\t\t\t   the_repository->hash_algo->empty_tree);\n \t\t\t\t\tadd_pending_object(&rev, &tree->object, \"HEAD\");\n \t\t\t\t}\n \t\t\t\tbreak;\ndiff --git a/builtin/reflog.c b/builtin/reflog.c\nindex 18145d5494..335525bb15 100644\n--- a/builtin/reflog.c\n+++ b/builtin/reflog.c\n@@ -65,7 +65,7 @@ static int tree_is_complete(const struct object_id *oid)\n \tint complete;\n \tstruct tree *tree;\n \n-\ttree = lookup_tree(oid);\n+\ttree = lookup_tree(the_repository, oid);\n \tif (!tree)\n \t\treturn 0;\n \tif (tree->object.flags & SEEN)\ndiff --git a/cache-tree.c b/cache-tree.c\nindex 2a98b15b92..75ff93abc7 100644\n--- a/cache-tree.c\n+++ b/cache-tree.c\n@@ -671,7 +671,8 @@ static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)\n \t\t\tcnt++;\n \t\telse {\n \t\t\tstruct cache_tree_sub *sub;\n-\t\t\tstruct tree *subtree = lookup_tree(entry.oid);\n+\t\t\tstruct tree *subtree = lookup_tree(the_repository,\n+\t\t\t\t\t\t\t   entry.oid);\n \t\t\tif (!subtree->object.parsed)\n \t\t\t\tparse_tree(subtree);\n \t\t\tsub = cache_tree_sub(it, entry.path);\ndiff --git a/commit.c b/commit.c\nindex 68967e6c59..253a906124 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -339,7 +339,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s\n \tif (get_sha1_hex(bufptr + 5, parent.hash) < 0)\n \t\treturn error(\"bad tree pointer in commit %s\",\n \t\t\t     oid_to_hex(&item->object.oid));\n-\titem->tree = lookup_tree(&parent);\n+\titem->tree = lookup_tree(the_repository, &parent);\n \tbufptr += tree_entry_len + 1; /* \"tree \" + \"hex sha1\" + \"\\n\" */\n \tpptr = &item->parents;\n \ndiff --git a/contrib/coccinelle/object_parser.cocci b/contrib/coccinelle/object_parser.cocci\nindex 3bc38d2faa..e5ce73fe13 100644\n--- a/contrib/coccinelle/object_parser.cocci\n+++ b/contrib/coccinelle/object_parser.cocci\n@@ -5,6 +5,14 @@ expression E;\n +the_repository,\n  E)\n \n+@@\n+expression E;\n+@@\n+ lookup_tree(\n++the_repository,\n+ E)\n+\n+\n @@\n expression E;\n @@\ndiff --git a/fsck.c b/fsck.c\nindex 6d04981735..54943b7dee 100644\n--- a/fsck.c\n+++ b/fsck.c\n@@ -360,7 +360,7 @@ static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *op\n \t\t\tcontinue;\n \n \t\tif (S_ISDIR(entry.mode)) {\n-\t\t\tobj = (struct object *)lookup_tree(entry.oid);\n+\t\t\tobj = (struct object *)lookup_tree(the_repository, entry.oid);\n \t\t\tif (name && obj)\n \t\t\t\tput_object_name(options, obj, \"%s%s/\", name,\n \t\t\t\t\tentry.path);\ndiff --git a/http-push.c b/http-push.c\nindex 6c60b12ad1..83117770a3 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -1307,7 +1307,8 @@ static struct object_list **process_tree(struct tree *tree,\n \twhile (tree_entry(&desc, &entry))\n \t\tswitch (object_type(entry.mode)) {\n \t\tcase OBJ_TREE:\n-\t\t\tp = process_tree(lookup_tree(entry.oid), p);\n+\t\t\tp = process_tree(lookup_tree(the_repository, entry.oid),\n+\t\t\t\t\t p);\n \t\t\tbreak;\n \t\tcase OBJ_BLOB:\n \t\t\tp = process_blob(lookup_blob(the_repository, entry.oid),\ndiff --git a/list-objects.c b/list-objects.c\nindex c11dc1281b..0db8fc15c2 100644\n--- a/list-objects.c\n+++ b/list-objects.c\n@@ -130,7 +130,7 @@ static void process_tree(struct rev_info *revs,\n \n \t\tif (S_ISDIR(entry.mode))\n \t\t\tprocess_tree(revs,\n-\t\t\t\t     lookup_tree(entry.oid),\n+\t\t\t\t     lookup_tree(the_repository, entry.oid),\n \t\t\t\t     show, base, entry.path,\n \t\t\t\t     cb_data, filter_fn, filter_data);\n \t\telse if (S_ISGITLINK(entry.mode))\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex e2c434c305..181ab36c36 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -95,7 +95,7 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two,\n \t}\n \tif (!oidcmp(&two->object.oid, &shifted))\n \t\treturn two;\n-\treturn lookup_tree(&shifted);\n+\treturn lookup_tree(the_repository, &shifted);\n }\n \n static struct commit *make_virtual_commit(struct tree *tree, const char *comment)\n@@ -332,7 +332,7 @@ struct tree *write_tree_from_memory(struct merge_options *o)\n \t\treturn NULL;\n \t}\n \n-\tresult = lookup_tree(&active_cache_tree->oid);\n+\tresult = lookup_tree(the_repository, &active_cache_tree->oid);\n \n \treturn result;\n }\n@@ -2091,7 +2091,7 @@ int merge_recursive(struct merge_options *o,\n \t\t/* if there is no common ancestor, use an empty tree */\n \t\tstruct tree *tree;\n \n-\t\ttree = lookup_tree(the_hash_algo->empty_tree);\n+\t\ttree = lookup_tree(the_repository, the_repository->hash_algo->empty_tree);\n \t\tmerged_common_ancestors = make_virtual_commit(tree, \"ancestor\");\n \t}\n \ndiff --git a/object.c b/object.c\nindex e0dac087c8..5ddbe91a38 100644\n--- a/object.c\n+++ b/object.c\n@@ -197,7 +197,7 @@ struct object *parse_object_buffer(const struct object_id *oid, enum object_type\n \t\t\tobj = &blob->object;\n \t\t}\n \t} else if (type == OBJ_TREE) {\n-\t\tstruct tree *tree = lookup_tree(oid);\n+\t\tstruct tree *tree = lookup_tree(the_repository, oid);\n \t\tif (tree) {\n \t\t\tobj = &tree->object;\n \t\t\tif (!tree->buffer)\ndiff --git a/reachable.c b/reachable.c\nindex 943e4518c2..44a9328c0e 100644\n--- a/reachable.c\n+++ b/reachable.c\n@@ -89,7 +89,7 @@ static void add_recent_object(const struct object_id *oid,\n \t\tobj = parse_object_or_die(oid, NULL);\n \t\tbreak;\n \tcase OBJ_TREE:\n-\t\tobj = (struct object *)lookup_tree(oid);\n+\t\tobj = (struct object *)lookup_tree(the_repository, oid);\n \t\tbreak;\n \tcase OBJ_BLOB:\n \t\tobj = (struct object *)lookup_blob(the_repository, oid);\ndiff --git a/revision.c b/revision.c\nindex a7b57e3452..629af0dca5 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -64,7 +64,7 @@ static void mark_tree_contents_uninteresting(struct tree *tree)\n \twhile (tree_entry(&desc, &entry)) {\n \t\tswitch (object_type(entry.mode)) {\n \t\tcase OBJ_TREE:\n-\t\t\tmark_tree_uninteresting(lookup_tree(entry.oid));\n+\t\t\tmark_tree_uninteresting(lookup_tree(the_repository, entry.oid));\n \t\t\tbreak;\n \t\tcase OBJ_BLOB:\n \t\t\tmark_blob_uninteresting(lookup_blob(the_repository, entry.oid));\n@@ -1295,7 +1295,7 @@ static void add_cache_tree(struct cache_tree *it, struct rev_info *revs,\n \tint i;\n \n \tif (it->entry_count >= 0) {\n-\t\tstruct tree *tree = lookup_tree(&it->oid);\n+\t\tstruct tree *tree = lookup_tree(the_repository, &it->oid);\n \t\tadd_pending_object_with_path(revs, &tree->object, \"\",\n \t\t\t\t\t     040000, path->buf);\n \t}\ndiff --git a/sequencer.c b/sequencer.c\nindex 311f00acda..6533b97138 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -349,7 +349,7 @@ static int read_oneliner(struct strbuf *buf,\n \n static struct tree *empty_tree(void)\n {\n-\treturn lookup_tree(the_hash_algo->empty_tree);\n+\treturn lookup_tree(the_repository, the_repository->hash_algo->empty_tree);\n }\n \n static int error_dirty_index(struct replay_opts *opts)\ndiff --git a/tag.c b/tag.c\nindex 4cf449303b..ba1df1c695 100644\n--- a/tag.c\n+++ b/tag.c\n@@ -148,7 +148,7 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)\n \tif (!strcmp(type, blob_type)) {\n \t\titem->tagged = (struct object *)lookup_blob(the_repository, &oid);\n \t} else if (!strcmp(type, tree_type)) {\n-\t\titem->tagged = (struct object *)lookup_tree(&oid);\n+\t\titem->tagged = (struct object *)lookup_tree(the_repository, &oid);\n \t} else if (!strcmp(type, commit_type)) {\n \t\titem->tagged = (struct object *)lookup_commit(&oid);\n \t} else if (!strcmp(type, tag_type)) {\ndiff --git a/tree.c b/tree.c\nindex 8f0ee6c8c0..b0d8610c41 100644\n--- a/tree.c\n+++ b/tree.c\n@@ -119,7 +119,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,\n \t\tlen = tree_entry_len(&entry);\n \t\tstrbuf_add(base, entry.path, len);\n \t\tstrbuf_addch(base, '/');\n-\t\tretval = read_tree_1(lookup_tree(&oid),\n+\t\tretval = read_tree_1(lookup_tree(the_repository, &oid),\n \t\t\t\t     base, stage, pathspec,\n \t\t\t\t     fn, context);\n \t\tstrbuf_setlen(base, oldlen);\n@@ -194,7 +194,7 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match,\n \treturn 0;\n }\n \n-struct tree *lookup_tree(const struct object_id *oid)\n+struct tree *lookup_tree_the_repository(const struct object_id *oid)\n {\n \tstruct object *obj = lookup_object(the_repository, oid->hash);\n \tif (!obj)\ndiff --git a/tree.h b/tree.h\nindex 744e6dc2ac..8195db473f 100644\n--- a/tree.h\n+++ b/tree.h\n@@ -12,7 +12,8 @@ struct tree {\n \tunsigned long size;\n };\n \n-struct tree *lookup_tree(const struct object_id *oid);\n+#define lookup_tree(r, oid) lookup_tree_##r(oid)\n+struct tree *lookup_tree_the_repository(const struct object_id *oid);\n \n int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size);\n \ndiff --git a/walker.c b/walker.c\nindex f5a221d48e..5cfd2316a8 100644\n--- a/walker.c\n+++ b/walker.c\n@@ -49,7 +49,8 @@ static int process_tree(struct walker *walker, struct tree *tree)\n \t\tif (S_ISGITLINK(entry.mode))\n \t\t\tcontinue;\n \t\tif (S_ISDIR(entry.mode)) {\n-\t\t\tstruct tree *tree = lookup_tree(entry.oid);\n+\t\t\tstruct tree *tree = lookup_tree(the_repository,\n+\t\t\t\t\t\t\tentry.oid);\n \t\t\tif (tree)\n \t\t\t\tobj = &tree->object;\n \t\t}\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338353","messageId":"20180205235735.216710-66-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 086/194] tag: add repository argument to lookup_tag","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:47Z","receivedAt":"2018-02-06T00:12:43Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow the callers of lookup_tag\nto be more specific about which repository to act on. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nAdd the cocci patch that converted the callers.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n builtin/describe.c                     | 6 +++---\n builtin/pack-objects.c                 | 2 +-\n builtin/replace.c                      | 2 +-\n contrib/coccinelle/object_parser.cocci | 7 +++++++\n log-tree.c                             | 2 +-\n object.c                               | 2 +-\n sha1_name.c                            | 2 +-\n tag.c                                  | 4 ++--\n tag.h                                  | 4 ++--\n 9 files changed, 19 insertions(+), 12 deletions(-)\n\ndiff --git a/builtin/describe.c b/builtin/describe.c\nindex 2add1e8d83..2589872322 100644\n--- a/builtin/describe.c\n+++ b/builtin/describe.c\n@@ -88,13 +88,13 @@ static int replace_name(struct commit_name *e,\n \t\tstruct tag *t;\n \n \t\tif (!e->tag) {\n-\t\t\tt = lookup_tag(&e->oid);\n+\t\t\tt = lookup_tag(the_repository, &e->oid);\n \t\t\tif (!t || parse_tag(t))\n \t\t\t\treturn 1;\n \t\t\te->tag = t;\n \t\t}\n \n-\t\tt = lookup_tag(oid);\n+\t\tt = lookup_tag(the_repository, oid);\n \t\tif (!t || parse_tag(t))\n \t\t\treturn 0;\n \t\t*tag = t;\n@@ -262,7 +262,7 @@ static unsigned long finish_depth_computation(\n static void append_name(struct commit_name *n, struct strbuf *dst)\n {\n \tif (n->prio == 2 && !n->tag) {\n-\t\tn->tag = lookup_tag(&n->oid);\n+\t\tn->tag = lookup_tag(the_repository, &n->oid);\n \t\tif (!n->tag || parse_tag(n->tag))\n \t\t\tdie(_(\"annotated tag %s not available\"), n->path);\n \t}\ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex 4e59e496dc..6348a5e721 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -2371,7 +2371,7 @@ static void add_tag_chain(const struct object_id *oid)\n \tif (packlist_find(&to_pack, oid->hash, NULL))\n \t\treturn;\n \n-\ttag = lookup_tag(oid);\n+\ttag = lookup_tag(the_repository, oid);\n \twhile (1) {\n \t\tif (!tag || parse_tag(tag) || !tag->tagged)\n \t\t\tdie(\"unable to pack objects reachable from tag %s\",\ndiff --git a/builtin/replace.c b/builtin/replace.c\nindex 25322d2f73..b79dd15fdb 100644\n--- a/builtin/replace.c\n+++ b/builtin/replace.c\n@@ -360,7 +360,7 @@ static void check_one_mergetag(struct commit *commit,\n \tint i;\n \n \thash_sha1_file(extra->value, extra->len, typename(OBJ_TAG), tag_oid.hash);\n-\ttag = lookup_tag(&tag_oid);\n+\ttag = lookup_tag(the_repository, &tag_oid);\n \tif (!tag)\n \t\tdie(_(\"bad mergetag in commit '%s'\"), ref);\n \tif (parse_tag_buffer(tag, extra->value, extra->len))\ndiff --git a/contrib/coccinelle/object_parser.cocci b/contrib/coccinelle/object_parser.cocci\nindex e5ce73fe13..8b9b1c717a 100644\n--- a/contrib/coccinelle/object_parser.cocci\n+++ b/contrib/coccinelle/object_parser.cocci\n@@ -13,6 +13,13 @@ expression E;\n  E)\n \n \n+@@\n+expression E;\n+@@\n+ lookup_tag(\n++the_repository,\n+ E)\n+\n @@\n expression E;\n @@\ndiff --git a/log-tree.c b/log-tree.c\nindex 57d5e5f56d..ff64a61e57 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -502,7 +502,7 @@ static void show_one_mergetag(struct commit *commit,\n \tsize_t payload_size, gpg_message_offset;\n \n \thash_sha1_file(extra->value, extra->len, typename(OBJ_TAG), oid.hash);\n-\ttag = lookup_tag(&oid);\n+\ttag = lookup_tag(the_repository, &oid);\n \tif (!tag)\n \t\treturn; /* error message already given */\n \ndiff --git a/object.c b/object.c\nindex 5ddbe91a38..5ebbb32a92 100644\n--- a/object.c\n+++ b/object.c\n@@ -220,7 +220,7 @@ struct object *parse_object_buffer(const struct object_id *oid, enum object_type\n \t\t\tobj = &commit->object;\n \t\t}\n \t} else if (type == OBJ_TAG) {\n-\t\tstruct tag *tag = lookup_tag(oid);\n+\t\tstruct tag *tag = lookup_tag(the_repository, oid);\n \t\tif (tag) {\n \t\t\tif (parse_tag_buffer(tag, buffer, size))\n \t\t\t       return NULL;\ndiff --git a/sha1_name.c b/sha1_name.c\nindex 0139b480a3..717b31359a 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -379,7 +379,7 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)\n \t\t\tformat_commit_message(commit, \" %ad - %s\", &desc, &pp);\n \t\t}\n \t} else if (type == OBJ_TAG) {\n-\t\tstruct tag *tag = lookup_tag(oid);\n+\t\tstruct tag *tag = lookup_tag(the_repository, oid);\n \t\tif (!parse_tag(tag) && tag->tag)\n \t\t\tstrbuf_addf(&desc, \" %s\", tag->tag);\n \t}\ndiff --git a/tag.c b/tag.c\nindex ba1df1c695..8935f3c8c9 100644\n--- a/tag.c\n+++ b/tag.c\n@@ -92,7 +92,7 @@ struct object *deref_tag_noverify(struct object *o)\n \treturn o;\n }\n \n-struct tag *lookup_tag(const struct object_id *oid)\n+struct tag *lookup_tag_the_repository(const struct object_id *oid)\n {\n \tstruct object *obj = lookup_object(the_repository, oid->hash);\n \tif (!obj)\n@@ -152,7 +152,7 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)\n \t} else if (!strcmp(type, commit_type)) {\n \t\titem->tagged = (struct object *)lookup_commit(&oid);\n \t} else if (!strcmp(type, tag_type)) {\n-\t\titem->tagged = (struct object *)lookup_tag(&oid);\n+\t\titem->tagged = (struct object *)lookup_tag(the_repository, &oid);\n \t} else {\n \t\terror(\"Unknown type %s\", type);\n \t\titem->tagged = NULL;\ndiff --git a/tag.h b/tag.h\nindex d469534e82..97d58ebf7b 100644\n--- a/tag.h\n+++ b/tag.h\n@@ -11,8 +11,8 @@ struct tag {\n \tchar *tag;\n \ttimestamp_t date;\n };\n-\n-extern struct tag *lookup_tag(const struct object_id *oid);\n+#define lookup_tag(r, o) lookup_tag_##r(o)\n+extern struct tag *lookup_tag_the_repository(const struct object_id *oid);\n extern int parse_tag_buffer(struct tag *item, const void *data, unsigned long size);\n extern int parse_tag(struct tag *item);\n extern struct object *deref_tag(struct object *, const char *, int);\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338354","messageId":"20180205235735.216710-67-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 087/194] tag: add repository argument to parse_tag_buffer","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:48Z","receivedAt":"2018-02-06T00:13:07Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow the callers of parse_tag_buffer\nto be more specific about which repository to act on. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nAdd the cocci patch that converted the callers.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n builtin/replace.c                      | 2 +-\n contrib/coccinelle/object_parser.cocci | 9 +++++++++\n log-tree.c                             | 2 +-\n object.c                               | 2 +-\n sha1_file.c                            | 2 +-\n tag.c                                  | 4 ++--\n tag.h                                  | 3 ++-\n 7 files changed, 17 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin/replace.c b/builtin/replace.c\nindex b79dd15fdb..d1a939c17b 100644\n--- a/builtin/replace.c\n+++ b/builtin/replace.c\n@@ -363,7 +363,7 @@ static void check_one_mergetag(struct commit *commit,\n \ttag = lookup_tag(the_repository, &tag_oid);\n \tif (!tag)\n \t\tdie(_(\"bad mergetag in commit '%s'\"), ref);\n-\tif (parse_tag_buffer(tag, extra->value, extra->len))\n+\tif (parse_tag_buffer(the_repository, tag, extra->value, extra->len))\n \t\tdie(_(\"malformed mergetag in commit '%s'\"), ref);\n \n \t/* iterate over new parents */\ndiff --git a/contrib/coccinelle/object_parser.cocci b/contrib/coccinelle/object_parser.cocci\nindex 8b9b1c717a..0e2ebdfccb 100644\n--- a/contrib/coccinelle/object_parser.cocci\n+++ b/contrib/coccinelle/object_parser.cocci\n@@ -20,6 +20,15 @@ expression E;\n +the_repository,\n  E)\n \n+@@\n+expression E;\n+expression F;\n+expression G;\n+@@\n+ parse_tag_buffer(\n++the_repository,\n+ E, F, G)\n+\n @@\n expression E;\n @@\ndiff --git a/log-tree.c b/log-tree.c\nindex ff64a61e57..1137506884 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -507,7 +507,7 @@ static void show_one_mergetag(struct commit *commit,\n \t\treturn; /* error message already given */\n \n \tstrbuf_init(&verify_message, 256);\n-\tif (parse_tag_buffer(tag, extra->value, extra->len))\n+\tif (parse_tag_buffer(the_repository, tag, extra->value, extra->len))\n \t\tstrbuf_addstr(&verify_message, \"malformed mergetag\\n\");\n \telse if (is_common_merge(commit) &&\n \t\t !oidcmp(&tag->tagged->oid,\ndiff --git a/object.c b/object.c\nindex 5ebbb32a92..c9ce89cf37 100644\n--- a/object.c\n+++ b/object.c\n@@ -222,7 +222,7 @@ struct object *parse_object_buffer(const struct object_id *oid, enum object_type\n \t} else if (type == OBJ_TAG) {\n \t\tstruct tag *tag = lookup_tag(the_repository, oid);\n \t\tif (tag) {\n-\t\t\tif (parse_tag_buffer(tag, buffer, size))\n+\t\t\tif (parse_tag_buffer(the_repository, tag, buffer, size))\n \t\t\t       return NULL;\n \t\t\tobj = &tag->object;\n \t\t}\ndiff --git a/sha1_file.c b/sha1_file.c\nindex c296b76329..df8bd4c260 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -1759,7 +1759,7 @@ static void check_tag(const void *buf, size_t size)\n {\n \tstruct tag t;\n \tmemset(&t, 0, sizeof(t));\n-\tif (parse_tag_buffer(&t, buf, size))\n+\tif (parse_tag_buffer(the_repository, &t, buf, size))\n \t\tdie(\"corrupt tag\");\n }\n \ndiff --git a/tag.c b/tag.c\nindex 8935f3c8c9..7ff9943847 100644\n--- a/tag.c\n+++ b/tag.c\n@@ -118,7 +118,7 @@ static timestamp_t parse_tag_date(const char *buf, const char *tail)\n \treturn parse_timestamp(dateptr, NULL, 10);\n }\n \n-int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)\n+int parse_tag_buffer_the_repository(struct tag *item, const void *data, unsigned long size)\n {\n \tstruct object_id oid;\n \tchar type[20];\n@@ -195,7 +195,7 @@ int parse_tag(struct tag *item)\n \t\treturn error(\"Object %s not a tag\",\n \t\t\t     oid_to_hex(&item->object.oid));\n \t}\n-\tret = parse_tag_buffer(item, data, size);\n+\tret = parse_tag_buffer(the_repository, item, data, size);\n \tfree(data);\n \treturn ret;\n }\ndiff --git a/tag.h b/tag.h\nindex 97d58ebf7b..31498e788a 100644\n--- a/tag.h\n+++ b/tag.h\n@@ -13,7 +13,8 @@ struct tag {\n };\n #define lookup_tag(r, o) lookup_tag_##r(o)\n extern struct tag *lookup_tag_the_repository(const struct object_id *oid);\n-extern int parse_tag_buffer(struct tag *item, const void *data, unsigned long size);\n+#define parse_tag_buffer(r, i, d, s) parse_tag_buffer_##r(i, d, s)\n+extern int parse_tag_buffer_the_repository(struct tag *item, const void *data, unsigned long size);\n extern int parse_tag(struct tag *item);\n extern struct object *deref_tag(struct object *, const char *, int);\n extern struct object *deref_tag_noverify(struct object *);\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338355","messageId":"20180205235735.216710-68-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 088/194] tag: add repository argument to deref_tag","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:49Z","receivedAt":"2018-02-06T00:13:09Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow the callers of deref_tag\nto be more specific about which repository to act on. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nAdd the cocci patch that converted the callers.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n blame.c                                |  6 +++---\n builtin/diff.c                         |  2 +-\n builtin/fmt-merge-msg.c                |  3 ++-\n builtin/grep.c                         |  3 ++-\n builtin/name-rev.c                     |  3 ++-\n commit.c                               |  3 ++-\n contrib/coccinelle/object_parser.cocci |  9 +++++++++\n fetch-pack.c                           |  9 ++++++---\n http-backend.c                         |  2 +-\n http-push.c                            |  2 +-\n line-log.c                             |  2 +-\n merge-recursive.c                      |  3 ++-\n remote.c                               |  6 ++++--\n server-info.c                          |  2 +-\n sha1_name.c                            | 11 +++++++----\n shallow.c                              |  4 +++-\n tag.c                                  |  2 +-\n tag.h                                  |  3 ++-\n upload-pack.c                          |  2 +-\n 19 files changed, 51 insertions(+), 26 deletions(-)\n\ndiff --git a/blame.c b/blame.c\nindex f95a53898d..02cd0ba498 100644\n--- a/blame.c\n+++ b/blame.c\n@@ -1655,7 +1655,7 @@ static struct commit *find_single_final(struct rev_info *revs,\n \t\tstruct object *obj = revs->pending.objects[i].item;\n \t\tif (obj->flags & UNINTERESTING)\n \t\t\tcontinue;\n-\t\tobj = deref_tag(obj, NULL, 0);\n+\t\tobj = deref_tag(the_repository, obj, NULL, 0);\n \t\tif (obj->type != OBJ_COMMIT)\n \t\t\tdie(\"Non commit %s?\", revs->pending.objects[i].name);\n \t\tif (found)\n@@ -1686,7 +1686,7 @@ static struct commit *dwim_reverse_initial(struct rev_info *revs,\n \n \t/* Is that sole rev a committish? */\n \tobj = revs->pending.objects[0].item;\n-\tobj = deref_tag(obj, NULL, 0);\n+\tobj = deref_tag(the_repository, obj, NULL, 0);\n \tif (obj->type != OBJ_COMMIT)\n \t\treturn NULL;\n \n@@ -1721,7 +1721,7 @@ static struct commit *find_single_initial(struct rev_info *revs,\n \t\tstruct object *obj = revs->pending.objects[i].item;\n \t\tif (!(obj->flags & UNINTERESTING))\n \t\t\tcontinue;\n-\t\tobj = deref_tag(obj, NULL, 0);\n+\t\tobj = deref_tag(the_repository, obj, NULL, 0);\n \t\tif (obj->type != OBJ_COMMIT)\n \t\t\tdie(\"Non commit %s?\", revs->pending.objects[i].name);\n \t\tif (found)\ndiff --git a/builtin/diff.c b/builtin/diff.c\nindex 0b7d0d612d..1dd7dd4a26 100644\n--- a/builtin/diff.c\n+++ b/builtin/diff.c\n@@ -395,7 +395,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)\n \t\tint flags = (obj->flags & UNINTERESTING);\n \t\tif (!obj->parsed)\n \t\t\tobj = parse_object(the_repository, &obj->oid);\n-\t\tobj = deref_tag(obj, NULL, 0);\n+\t\tobj = deref_tag(the_repository, obj, NULL, 0);\n \t\tif (!obj)\n \t\t\tdie(_(\"invalid object '%s' given.\"), name);\n \t\tif (obj->type == OBJ_COMMIT)\ndiff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c\nindex dd74251690..49fd7ea1d2 100644\n--- a/builtin/fmt-merge-msg.c\n+++ b/builtin/fmt-merge-msg.c\n@@ -344,7 +344,8 @@ static void shortlog(const char *name,\n \tconst struct object_id *oid = &origin_data->oid;\n \tint limit = opts->shortlog_len;\n \n-\tbranch = deref_tag(parse_object(the_repository, oid), oid_to_hex(oid),\n+\tbranch = deref_tag(the_repository, parse_object(the_repository, oid),\n+\t\t\t   oid_to_hex(oid),\n \t\t\t   GIT_SHA1_HEXSZ);\n \tif (!branch || branch->type != OBJ_COMMIT)\n \t\treturn;\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex 1c71dff341..2c43307f02 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -641,7 +641,8 @@ static int grep_objects(struct grep_opt *opt, const struct pathspec *pathspec,\n \n \tfor (i = 0; i < nr; i++) {\n \t\tstruct object *real_obj;\n-\t\treal_obj = deref_tag(list->objects[i].item, NULL, 0);\n+\t\treal_obj = deref_tag(the_repository, list->objects[i].item,\n+\t\t\t\t     NULL, 0);\n \n \t\t/* load the gitmodules file for this rev */\n \t\tif (recurse_submodules) {\ndiff --git a/builtin/name-rev.c b/builtin/name-rev.c\nindex 45ec5515cc..2cbb702c2c 100644\n--- a/builtin/name-rev.c\n+++ b/builtin/name-rev.c\n@@ -438,7 +438,8 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)\n \t\tcommit = NULL;\n \t\tobject = parse_object(the_repository, &oid);\n \t\tif (object) {\n-\t\t\tstruct object *peeled = deref_tag(object, *argv, 0);\n+\t\t\tstruct object *peeled = deref_tag(the_repository,\n+\t\t\t\t\t\t\t  object, *argv, 0);\n \t\t\tif (peeled && peeled->type == OBJ_COMMIT)\n \t\t\t\tcommit = (struct commit *)peeled;\n \t\t}\ndiff --git a/commit.c b/commit.c\nindex 253a906124..1b0e37f6f0 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -23,7 +23,8 @@ const char *commit_type = \"commit\";\n struct commit *lookup_commit_reference_gently(const struct object_id *oid,\n \t\t\t\t\t      int quiet)\n {\n-\tstruct object *obj = deref_tag(parse_object(the_repository, oid),\n+\tstruct object *obj = deref_tag(the_repository,\n+\t\t\t\t       parse_object(the_repository, oid),\n \t\t\t\t       NULL, 0);\n \n \tif (!obj)\ndiff --git a/contrib/coccinelle/object_parser.cocci b/contrib/coccinelle/object_parser.cocci\nindex 0e2ebdfccb..7ddd9f11ce 100644\n--- a/contrib/coccinelle/object_parser.cocci\n+++ b/contrib/coccinelle/object_parser.cocci\n@@ -29,6 +29,15 @@ expression G;\n +the_repository,\n  E, F, G)\n \n+@@\n+expression E;\n+expression F;\n+expression G;\n+@@\n+ deref_tag(\n++the_repository,\n+ E, F, G)\n+\n @@\n expression E;\n @@\ndiff --git a/fetch-pack.c b/fetch-pack.c\nindex 02ac850967..ee1e65688a 100644\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -124,7 +124,8 @@ static void rev_list_push(struct commit *commit, int mark)\n \n static int rev_list_insert_ref(const char *refname, const struct object_id *oid)\n {\n-\tstruct object *o = deref_tag(parse_object(the_repository, oid),\n+\tstruct object *o = deref_tag(the_repository,\n+\t\t\t\t     parse_object(the_repository, oid),\n \t\t\t\t     refname, 0);\n \n \tif (o && o->type == OBJ_COMMIT)\n@@ -142,7 +143,8 @@ static int rev_list_insert_ref_oid(const char *refname, const struct object_id *\n static int clear_marks(const char *refname, const struct object_id *oid,\n \t\t       int flag, void *cb_data)\n {\n-\tstruct object *o = deref_tag(parse_object(the_repository, oid),\n+\tstruct object *o = deref_tag(the_repository,\n+\t\t\t\t     parse_object(the_repository, oid),\n \t\t\t\t     refname, 0);\n \n \tif (o && o->type == OBJ_COMMIT)\n@@ -751,7 +753,8 @@ static int everything_local(struct fetch_pack_args *args,\n \t * Don't mark them common yet; the server has to be told so first.\n \t */\n \tfor (ref = *refs; ref; ref = ref->next) {\n-\t\tstruct object *o = deref_tag(lookup_object(the_repository, ref->old_oid.hash),\n+\t\tstruct object *o = deref_tag(the_repository,\n+\t\t\t\t\t     lookup_object(the_repository, ref->old_oid.hash),\n \t\t\t\t\t     NULL, 0);\n \n \t\tif (!o || o->type != OBJ_COMMIT || !(o->flags & COMPLETE))\ndiff --git a/http-backend.c b/http-backend.c\nindex b76c8c4f3d..609faf93d4 100644\n--- a/http-backend.c\n+++ b/http-backend.c\n@@ -441,7 +441,7 @@ static int show_text_ref(const char *name, const struct object_id *oid,\n \n \tstrbuf_addf(buf, \"%s\\t%s\\n\", oid_to_hex(oid), name_nons);\n \tif (o->type == OBJ_TAG) {\n-\t\to = deref_tag(o, name, 0);\n+\t\to = deref_tag(the_repository, o, name, 0);\n \t\tif (!o)\n \t\t\treturn 0;\n \t\tstrbuf_addf(buf, \"%s\\t%s^{}\\n\", oid_to_hex(&o->oid),\ndiff --git a/http-push.c b/http-push.c\nindex 83117770a3..de5e70ea7b 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -1473,7 +1473,7 @@ static void add_remote_info_ref(struct remote_ls_ctx *ls)\n \t\t    oid_to_hex(&ref->old_oid), ls->dentry_name);\n \n \tif (o->type == OBJ_TAG) {\n-\t\to = deref_tag(o, ls->dentry_name, 0);\n+\t\to = deref_tag(the_repository, o, ls->dentry_name, 0);\n \t\tif (o)\n \t\t\tstrbuf_addf(buf, \"%s\\t%s^{}\\n\",\n \t\t\t\t    oid_to_hex(&o->oid), ls->dentry_name);\ndiff --git a/line-log.c b/line-log.c\nindex 545ad0f28b..653c7279f3 100644\n--- a/line-log.c\n+++ b/line-log.c\n@@ -479,7 +479,7 @@ static struct commit *check_single_commit(struct rev_info *revs)\n \t\tstruct object *obj = revs->pending.objects[i].item;\n \t\tif (obj->flags & UNINTERESTING)\n \t\t\tcontinue;\n-\t\tobj = deref_tag(obj, NULL, 0);\n+\t\tobj = deref_tag(the_repository, obj, NULL, 0);\n \t\tif (obj->type != OBJ_COMMIT)\n \t\t\tdie(\"Non commit %s?\", revs->pending.objects[i].name);\n \t\tif (commit)\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 181ab36c36..8b6984cdd7 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -2152,7 +2152,8 @@ static struct commit *get_ref(const struct object_id *oid, const char *name)\n {\n \tstruct object *object;\n \n-\tobject = deref_tag(parse_object(the_repository, oid), name,\n+\tobject = deref_tag(the_repository, parse_object(the_repository, oid),\n+\t\t\t   name,\n \t\t\t   strlen(name));\n \tif (!object)\n \t\treturn NULL;\ndiff --git a/remote.c b/remote.c\nindex 2abc6baf84..8d84e26dd4 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -1980,12 +1980,14 @@ int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid)\n \t * Both new and old must be commit-ish and new is descendant of\n \t * old.  Otherwise we require --force.\n \t */\n-\to = deref_tag(parse_object(the_repository, old_oid), NULL, 0);\n+\to = deref_tag(the_repository, parse_object(the_repository, old_oid),\n+\t\t      NULL, 0);\n \tif (!o || o->type != OBJ_COMMIT)\n \t\treturn 0;\n \told = (struct commit *) o;\n \n-\to = deref_tag(parse_object(the_repository, new_oid), NULL, 0);\n+\to = deref_tag(the_repository, parse_object(the_repository, new_oid),\n+\t\t      NULL, 0);\n \tif (!o || o->type != OBJ_COMMIT)\n \t\treturn 0;\n \tnew = (struct commit *) o;\ndiff --git a/server-info.c b/server-info.c\nindex fd7ed2a383..ee4491b73a 100644\n--- a/server-info.c\n+++ b/server-info.c\n@@ -64,7 +64,7 @@ static int add_info_ref(const char *path, const struct object_id *oid,\n \t\treturn -1;\n \n \tif (o->type == OBJ_TAG) {\n-\t\to = deref_tag(o, path, 0);\n+\t\to = deref_tag(the_repository, o, path, 0);\n \t\tif (o)\n \t\t\tif (fprintf(fp, \"%s\t%s^{}\\n\",\n \t\t\t\toid_to_hex(&o->oid), path) < 0)\ndiff --git a/sha1_name.c b/sha1_name.c\nindex 717b31359a..117c080fd4 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -259,7 +259,8 @@ static int disambiguate_committish_only(const struct object_id *oid, void *cb_da\n \t\treturn 0;\n \n \t/* We need to do this the hard way... */\n-\tobj = deref_tag(parse_object(the_repository, oid), NULL, 0);\n+\tobj = deref_tag(the_repository, parse_object(the_repository, oid),\n+\t\t\tNULL, 0);\n \tif (obj && obj->type == OBJ_COMMIT)\n \t\treturn 1;\n \treturn 0;\n@@ -283,7 +284,8 @@ static int disambiguate_treeish_only(const struct object_id *oid, void *cb_data_\n \t\treturn 0;\n \n \t/* We need to do this the hard way... */\n-\tobj = deref_tag(parse_object(the_repository, oid), NULL, 0);\n+\tobj = deref_tag(the_repository, parse_object(the_repository, oid),\n+\t\t\tNULL, 0);\n \tif (obj && (obj->type == OBJ_TREE || obj->type == OBJ_COMMIT))\n \t\treturn 1;\n \treturn 0;\n@@ -971,7 +973,7 @@ static int peel_onion(const char *name, int len, struct object_id *oid,\n \tif (!o)\n \t\treturn -1;\n \tif (!expected_type) {\n-\t\to = deref_tag(o, name, sp - name - 2);\n+\t\to = deref_tag(the_repository, o, name, sp - name - 2);\n \t\tif (!o || (!o->parsed && !parse_object(the_repository, &o->oid)))\n \t\t\treturn -1;\n \t\toidcpy(oid, &o->oid);\n@@ -1103,7 +1105,8 @@ static int handle_one_ref(const char *path, const struct object_id *oid,\n \tif (!object)\n \t\treturn 0;\n \tif (object->type == OBJ_TAG) {\n-\t\tobject = deref_tag(object, path, strlen(path));\n+\t\tobject = deref_tag(the_repository, object, path,\n+\t\t\t\t   strlen(path));\n \t\tif (!object)\n \t\t\treturn 0;\n \t}\ndiff --git a/shallow.c b/shallow.c\nindex c2f81a5a5a..aa6d04992c 100644\n--- a/shallow.c\n+++ b/shallow.c\n@@ -89,7 +89,9 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth,\n \t\tif (!commit) {\n \t\t\tif (i < heads->nr) {\n \t\t\t\tcommit = (struct commit *)\n-\t\t\t\t\tderef_tag(heads->objects[i++].item, NULL, 0);\n+\t\t\t\t\tderef_tag(the_repository,\n+\t\t\t\t\t\t  heads->objects[i++].item,\n+\t\t\t\t\t\t  NULL, 0);\n \t\t\t\tif (!commit || commit->object.type != OBJ_COMMIT) {\n \t\t\t\t\tcommit = NULL;\n \t\t\t\t\tcontinue;\ndiff --git a/tag.c b/tag.c\nindex 7ff9943847..d8174e0405 100644\n--- a/tag.c\n+++ b/tag.c\n@@ -64,7 +64,7 @@ int gpg_verify_tag(const struct object_id *oid, const char *name_to_report,\n \treturn ret;\n }\n \n-struct object *deref_tag(struct object *o, const char *warn, int warnlen)\n+struct object *deref_tag_the_repository(struct object *o, const char *warn, int warnlen)\n {\n \twhile (o && o->type == OBJ_TAG)\n \t\tif (((struct tag *)o)->tagged)\ndiff --git a/tag.h b/tag.h\nindex 31498e788a..4f45695e1e 100644\n--- a/tag.h\n+++ b/tag.h\n@@ -16,7 +16,8 @@ extern struct tag *lookup_tag_the_repository(const struct object_id *oid);\n #define parse_tag_buffer(r, i, d, s) parse_tag_buffer_##r(i, d, s)\n extern int parse_tag_buffer_the_repository(struct tag *item, const void *data, unsigned long size);\n extern int parse_tag(struct tag *item);\n-extern struct object *deref_tag(struct object *, const char *, int);\n+#define deref_tag(r, o, w, l) deref_tag_##r(o, w, l)\n+extern struct object *deref_tag_the_repository(struct object *, const char *, int);\n extern struct object *deref_tag_noverify(struct object *);\n extern int gpg_verify_tag(const struct object_id *oid,\n \t\tconst char *name_to_report, unsigned flags);\ndiff --git a/upload-pack.c b/upload-pack.c\nindex 8716e28d4f..469a843669 100644\n--- a/upload-pack.c\n+++ b/upload-pack.c\n@@ -368,7 +368,7 @@ static int ok_to_give_up(void)\n \n \t\tif (want->flags & COMMON_KNOWN)\n \t\t\tcontinue;\n-\t\twant = deref_tag(want, \"a want line\", 0);\n+\t\twant = deref_tag(the_repository, want, \"a want line\", 0);\n \t\tif (!want || want->type != OBJ_COMMIT) {\n \t\t\t/* no way to tell if this is reachable by\n \t\t\t * looking at the ancestry chain alone, so\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338356","messageId":"20180205235735.216710-69-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 089/194] object: add repository argument to lookup_commit_reference_gently","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:50Z","receivedAt":"2018-02-06T00:13:46Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nAdd a repository argument to allow callers of\nlookup_commit_reference_gently to be more specific about which\nrepository to handle. This is a small mechanical change; it doesn't\nchange the implementation to handle repositories other than\nthe_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nThe included coccinelle semantic patch will adapt any new callers in\nthe diff produced by `make coccicheck`.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n archive.c                              |  2 +-\n blame.c                                |  3 ++-\n builtin/checkout.c                     |  7 ++++---\n builtin/describe.c                     |  5 +++--\n builtin/fetch.c                        |  9 ++++++---\n builtin/reflog.c                       | 10 ++++++----\n builtin/show-branch.c                  |  3 ++-\n commit.c                               |  9 +++++----\n commit.h                               |  5 ++++-\n contrib/coccinelle/object_parser.cocci |  8 ++++++++\n fast-import.c                          |  6 ++++--\n notes-cache.c                          |  3 ++-\n ref-filter.c                           |  6 ++++--\n remote.c                               |  9 +++++----\n sequencer.c                            |  2 +-\n sha1_name.c                            |  4 ++--\n shallow.c                              |  9 ++++++---\n walker.c                               |  3 ++-\n wt-status.c                            |  2 +-\n 19 files changed, 68 insertions(+), 37 deletions(-)\n\ndiff --git a/archive.c b/archive.c\nindex 9b47041a6c..2aeafe647d 100644\n--- a/archive.c\n+++ b/archive.c\n@@ -380,7 +380,7 @@ static void parse_treeish_arg(const char **argv,\n \tif (get_oid(name, &oid))\n \t\tdie(\"Not a valid object name\");\n \n-\tcommit = lookup_commit_reference_gently(&oid, 1);\n+\tcommit = lookup_commit_reference_gently(the_repository, &oid, 1);\n \tif (commit) {\n \t\tcommit_sha1 = commit->object.oid.hash;\n \t\tarchive_time = commit->date;\ndiff --git a/blame.c b/blame.c\nindex 02cd0ba498..98761c32d5 100644\n--- a/blame.c\n+++ b/blame.c\n@@ -1693,7 +1693,8 @@ static struct commit *dwim_reverse_initial(struct rev_info *revs,\n \t/* Do we have HEAD? */\n \tif (!resolve_ref_unsafe(\"HEAD\", RESOLVE_REF_READING, &head_oid, NULL))\n \t\treturn NULL;\n-\thead_commit = lookup_commit_reference_gently(&head_oid, 1);\n+\thead_commit = lookup_commit_reference_gently(the_repository,\n+\t\t\t\t\t\t     &head_oid, 1);\n \tif (!head_commit)\n \t\treturn NULL;\n \ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex c7271ed43f..cef2b4f2ad 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -380,7 +380,7 @@ static int checkout_paths(const struct checkout_opts *opts,\n \t\tdie(_(\"unable to write new index file\"));\n \n \tread_ref_full(\"HEAD\", 0, &rev, NULL);\n-\thead = lookup_commit_reference_gently(&rev, 1);\n+\thead = lookup_commit_reference_gently(the_repository, &rev, 1);\n \n \terrs |= post_checkout_hook(head, head, 0);\n \treturn errs;\n@@ -835,7 +835,8 @@ static int switch_branches(const struct checkout_opts *opts,\n \tmemset(&old, 0, sizeof(old));\n \told.path = path_to_free = resolve_refdup(\"HEAD\", 0, &rev, &flag);\n \tif (old.path)\n-\t\told.commit = lookup_commit_reference_gently(&rev, 1);\n+\t\told.commit = lookup_commit_reference_gently(the_repository,\n+\t\t\t\t\t\t\t    &rev, 1);\n \tif (!(flag & REF_ISSYMREF))\n \t\told.path = NULL;\n \n@@ -1009,7 +1010,7 @@ static int parse_branchname_arg(int argc, const char **argv,\n \telse\n \t\tnew->path = NULL; /* not an existing branch */\n \n-\tnew->commit = lookup_commit_reference_gently(rev, 1);\n+\tnew->commit = lookup_commit_reference_gently(the_repository, rev, 1);\n \tif (!new->commit) {\n \t\t/* not a commit */\n \t\t*source_tree = parse_tree_indirect(rev);\ndiff --git a/builtin/describe.c b/builtin/describe.c\nindex 2589872322..f1172a8bf0 100644\n--- a/builtin/describe.c\n+++ b/builtin/describe.c\n@@ -320,7 +320,8 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst)\n \t\tstruct commit *c;\n \t\tstruct commit_name *n = hashmap_iter_first(&names, &iter);\n \t\tfor (; n; n = hashmap_iter_next(&iter)) {\n-\t\t\tc = lookup_commit_reference_gently(&n->peeled, 1);\n+\t\t\tc = lookup_commit_reference_gently(the_repository,\n+\t\t\t\t\t\t\t   &n->peeled, 1);\n \t\t\tif (c)\n \t\t\t\tc->util = n;\n \t\t}\n@@ -495,7 +496,7 @@ static void describe(const char *arg, int last_one)\n \n \tif (get_oid(arg, &oid))\n \t\tdie(_(\"Not a valid object name %s\"), arg);\n-\tcmit = lookup_commit_reference_gently(&oid, 1);\n+\tcmit = lookup_commit_reference_gently(the_repository, &oid, 1);\n \n \tif (cmit)\n \t\tdescribe_commit(&oid, &sb);\ndiff --git a/builtin/fetch.c b/builtin/fetch.c\nindex 276beebbb1..904496fa33 100644\n--- a/builtin/fetch.c\n+++ b/builtin/fetch.c\n@@ -660,8 +660,10 @@ static int update_local_ref(struct ref *ref,\n \t\treturn r;\n \t}\n \n-\tcurrent = lookup_commit_reference_gently(&ref->old_oid, 1);\n-\tupdated = lookup_commit_reference_gently(&ref->new_oid, 1);\n+\tcurrent = lookup_commit_reference_gently(the_repository,\n+\t\t\t\t\t\t &ref->old_oid, 1);\n+\tupdated = lookup_commit_reference_gently(the_repository,\n+\t\t\t\t\t\t &ref->new_oid, 1);\n \tif (!current || !updated) {\n \t\tconst char *msg;\n \t\tconst char *what;\n@@ -794,7 +796,8 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,\n \t\t\t\tcontinue;\n \t\t\t}\n \n-\t\t\tcommit = lookup_commit_reference_gently(&rm->old_oid,\n+\t\t\tcommit = lookup_commit_reference_gently(the_repository,\n+\t\t\t\t\t\t\t\t&rm->old_oid,\n \t\t\t\t\t\t\t\t1);\n \t\t\tif (!commit)\n \t\t\t\trm->fetch_head_status = FETCH_HEAD_NOT_FOR_MERGE;\ndiff --git a/builtin/reflog.c b/builtin/reflog.c\nindex 335525bb15..e12b99e9cb 100644\n--- a/builtin/reflog.c\n+++ b/builtin/reflog.c\n@@ -195,7 +195,7 @@ static int keep_entry(struct commit **it, struct object_id *oid)\n \n \tif (is_null_oid(oid))\n \t\treturn 1;\n-\tcommit = lookup_commit_reference_gently(oid, 1);\n+\tcommit = lookup_commit_reference_gently(the_repository, oid, 1);\n \tif (!commit)\n \t\treturn 0;\n \n@@ -264,7 +264,8 @@ static int unreachable(struct expire_reflog_policy_cb *cb, struct commit *commit\n \t\tif (is_null_oid(oid))\n \t\t\treturn 0;\n \n-\t\tcommit = lookup_commit_reference_gently(oid, 1);\n+\t\tcommit = lookup_commit_reference_gently(the_repository, oid,\n+\t\t\t\t\t\t\t1);\n \n \t\t/* Not a commit -- keep it */\n \t\tif (!commit)\n@@ -321,7 +322,7 @@ static int push_tip_to_list(const char *refname, const struct object_id *oid,\n \tstruct commit *tip_commit;\n \tif (flags & REF_ISSYMREF)\n \t\treturn 0;\n-\ttip_commit = lookup_commit_reference_gently(oid, 1);\n+\ttip_commit = lookup_commit_reference_gently(the_repository, oid, 1);\n \tif (!tip_commit)\n \t\treturn 0;\n \tcommit_list_insert(tip_commit, list);\n@@ -338,7 +339,8 @@ static void reflog_expiry_prepare(const char *refname,\n \t\tcb->tip_commit = NULL;\n \t\tcb->unreachable_expire_kind = UE_HEAD;\n \t} else {\n-\t\tcb->tip_commit = lookup_commit_reference_gently(oid, 1);\n+\t\tcb->tip_commit = lookup_commit_reference_gently(the_repository,\n+\t\t\t\t\t\t\t\toid, 1);\n \t\tif (!cb->tip_commit)\n \t\t\tcb->unreachable_expire_kind = UE_ALWAYS;\n \t\telse\ndiff --git a/builtin/show-branch.c b/builtin/show-branch.c\nindex e8a4aa40cb..fb90c9ab3e 100644\n--- a/builtin/show-branch.c\n+++ b/builtin/show-branch.c\n@@ -360,7 +360,8 @@ static void sort_ref_range(int bottom, int top)\n static int append_ref(const char *refname, const struct object_id *oid,\n \t\t      int allow_dups)\n {\n-\tstruct commit *commit = lookup_commit_reference_gently(oid, 1);\n+\tstruct commit *commit = lookup_commit_reference_gently(the_repository,\n+\t\t\t\t\t\t\t       oid, 1);\n \tint i;\n \n \tif (!commit)\ndiff --git a/commit.c b/commit.c\nindex 1b0e37f6f0..b6e253f1af 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -20,8 +20,8 @@ int save_commit_buffer = 1;\n \n const char *commit_type = \"commit\";\n \n-struct commit *lookup_commit_reference_gently(const struct object_id *oid,\n-\t\t\t\t\t      int quiet)\n+struct commit *lookup_commit_reference_gently_the_repository(\n+\t\tconst struct object_id *oid, int quiet)\n {\n \tstruct object *obj = deref_tag(the_repository,\n \t\t\t\t       parse_object(the_repository, oid),\n@@ -34,7 +34,7 @@ struct commit *lookup_commit_reference_gently(const struct object_id *oid,\n \n struct commit *lookup_commit_reference(const struct object_id *oid)\n {\n-\treturn lookup_commit_reference_gently(oid, 0);\n+\treturn lookup_commit_reference_gently(the_repository, oid, 0);\n }\n \n struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref_name)\n@@ -571,7 +571,8 @@ void clear_commit_marks_for_object_array(struct object_array *a, unsigned mark)\n \n \tfor (i = 0; i < a->nr; i++) {\n \t\tobject = a->objects[i].item;\n-\t\tcommit = lookup_commit_reference_gently(&object->oid, 1);\n+\t\tcommit = lookup_commit_reference_gently(the_repository,\n+\t\t\t\t\t\t\t&object->oid, 1);\n \t\tif (commit)\n \t\t\tclear_commit_marks(commit, mark);\n \t}\ndiff --git a/commit.h b/commit.h\nindex 8c68ca1a5a..2ce5597066 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -48,7 +48,10 @@ const struct name_decoration *get_name_decoration(const struct object *obj);\n \n struct commit *lookup_commit(const struct object_id *oid);\n struct commit *lookup_commit_reference(const struct object_id *oid);\n-struct commit *lookup_commit_reference_gently(const struct object_id *oid,\n+#define lookup_commit_reference_gently(r, o, q) \\\n+\t\tlookup_commit_reference_gently_##r(o, q)\n+struct commit *lookup_commit_reference_gently_the_repository(\n+\t\t\t\t\t      const struct object_id *oid,\n \t\t\t\t\t      int quiet);\n struct commit *lookup_commit_reference_by_name(const char *name);\n \ndiff --git a/contrib/coccinelle/object_parser.cocci b/contrib/coccinelle/object_parser.cocci\nindex 7ddd9f11ce..7c1ef62e6d 100644\n--- a/contrib/coccinelle/object_parser.cocci\n+++ b/contrib/coccinelle/object_parser.cocci\n@@ -59,3 +59,11 @@ expression E;\n  lookup_object(\n +the_repository,\n  E)\n+\n+@@\n+expression E;\n+expression F;\n+@@\n+ lookup_commit_reference_gently(\n++the_repository,\n+ E, F)\ndiff --git a/fast-import.c b/fast-import.c\nindex 5618087015..54c2e10656 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -1765,8 +1765,10 @@ static int update_branch(struct branch *b)\n \tif (!force_update && !is_null_oid(&old_oid)) {\n \t\tstruct commit *old_cmit, *new_cmit;\n \n-\t\told_cmit = lookup_commit_reference_gently(&old_oid, 0);\n-\t\tnew_cmit = lookup_commit_reference_gently(&b->oid, 0);\n+\t\told_cmit = lookup_commit_reference_gently(the_repository,\n+\t\t\t\t\t\t\t  &old_oid, 0);\n+\t\tnew_cmit = lookup_commit_reference_gently(the_repository,\n+\t\t\t\t\t\t\t  &b->oid, 0);\n \t\tif (!old_cmit || !new_cmit)\n \t\t\treturn error(\"Branch %s is missing commits.\", b->name);\n \ndiff --git a/notes-cache.c b/notes-cache.c\nindex ee513e87a9..6348baeb07 100644\n--- a/notes-cache.c\n+++ b/notes-cache.c\n@@ -1,6 +1,7 @@\n #include \"cache.h\"\n #include \"notes-cache.h\"\n #include \"object-store.h\"\n+#include \"repository.h\"\n #include \"commit.h\"\n #include \"refs.h\"\n \n@@ -15,7 +16,7 @@ static int notes_cache_match_validity(const char *ref, const char *validity)\n \tif (read_ref(ref, &oid) < 0)\n \t\treturn 0;\n \n-\tcommit = lookup_commit_reference_gently(&oid, 1);\n+\tcommit = lookup_commit_reference_gently(the_repository, &oid, 1);\n \tif (!commit)\n \t\treturn 0;\n \ndiff --git a/ref-filter.c b/ref-filter.c\nindex 1d0bad5e36..b4b6f8801c 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -1914,7 +1914,8 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,\n \t * non-commits early. The actual filtering is done later.\n \t */\n \tif (filter->merge_commit || filter->with_commit || filter->no_commit || filter->verbose) {\n-\t\tcommit = lookup_commit_reference_gently(oid, 1);\n+\t\tcommit = lookup_commit_reference_gently(the_repository, oid,\n+\t\t\t\t\t\t\t1);\n \t\tif (!commit)\n \t\t\treturn 0;\n \t\t/* We perform the filtering for the '--contains' option... */\n@@ -2251,7 +2252,8 @@ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset)\n \tif (get_oid(arg, &oid))\n \t\tdie(_(\"malformed object name %s\"), arg);\n \n-\trf->merge_commit = lookup_commit_reference_gently(&oid, 0);\n+\trf->merge_commit = lookup_commit_reference_gently(the_repository,\n+\t\t\t\t\t\t\t  &oid, 0);\n \tif (!rf->merge_commit)\n \t\treturn opterror(opt, \"must point to a commit\", 0);\n \ndiff --git a/remote.c b/remote.c\nindex 8d84e26dd4..a9386476fe 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -1323,7 +1323,7 @@ static void add_to_tips(struct tips *tips, const struct object_id *oid)\n \n \tif (is_null_oid(oid))\n \t\treturn;\n-\tcommit = lookup_commit_reference_gently(oid, 1);\n+\tcommit = lookup_commit_reference_gently(the_repository, oid, 1);\n \tif (!commit || (commit->object.flags & TMP_MARK))\n \t\treturn;\n \tcommit->object.flags |= TMP_MARK;\n@@ -1385,7 +1385,8 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds\n \n \t\t\tif (is_null_oid(&ref->new_oid))\n \t\t\t\tcontinue;\n-\t\t\tcommit = lookup_commit_reference_gently(&ref->new_oid,\n+\t\t\tcommit = lookup_commit_reference_gently(the_repository,\n+\t\t\t\t\t\t\t\t&ref->new_oid,\n \t\t\t\t\t\t\t\t1);\n \t\t\tif (!commit)\n \t\t\t\t/* not pushing a commit, which is not an error */\n@@ -1613,8 +1614,8 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,\n \t\t\t\treject_reason = REF_STATUS_REJECT_ALREADY_EXISTS;\n \t\t\telse if (!has_object_file(&ref->old_oid))\n \t\t\t\treject_reason = REF_STATUS_REJECT_FETCH_FIRST;\n-\t\t\telse if (!lookup_commit_reference_gently(&ref->old_oid, 1) ||\n-\t\t\t\t !lookup_commit_reference_gently(&ref->new_oid, 1))\n+\t\t\telse if (!lookup_commit_reference_gently(the_repository, &ref->old_oid, 1) ||\n+\t\t\t\t !lookup_commit_reference_gently(the_repository, &ref->new_oid, 1))\n \t\t\t\treject_reason = REF_STATUS_REJECT_NEEDS_FORCE;\n \t\t\telse if (!ref_newer(&ref->new_oid, &ref->old_oid))\n \t\t\t\treject_reason = REF_STATUS_REJECT_NONFASTFORWARD;\ndiff --git a/sequencer.c b/sequencer.c\nindex 6533b97138..d0c3c808aa 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -2347,7 +2347,7 @@ int sequencer_pick_revisions(struct replay_opts *opts)\n \t\t\tcontinue;\n \n \t\tif (!get_oid(name, &oid)) {\n-\t\t\tif (!lookup_commit_reference_gently(&oid, 1)) {\n+\t\t\tif (!lookup_commit_reference_gently(the_repository, &oid, 1)) {\n \t\t\t\tenum object_type type = sha1_object_info(the_repository,\n \t\t\t\t\t\t\t\t\t oid.hash,\n \t\t\t\t\t\t\t\t\t NULL);\ndiff --git a/sha1_name.c b/sha1_name.c\nindex 117c080fd4..160fec7062 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -1257,13 +1257,13 @@ int get_oid_mb(const char *name, struct object_id *oid)\n \t}\n \tif (st)\n \t\treturn st;\n-\tone = lookup_commit_reference_gently(&oid_tmp, 0);\n+\tone = lookup_commit_reference_gently(the_repository, &oid_tmp, 0);\n \tif (!one)\n \t\treturn -1;\n \n \tif (get_oid_committish(dots[3] ? (dots + 3) : \"HEAD\", &oid_tmp))\n \t\treturn -1;\n-\ttwo = lookup_commit_reference_gently(&oid_tmp, 0);\n+\ttwo = lookup_commit_reference_gently(the_repository, &oid_tmp, 0);\n \tif (!two)\n \t\treturn -1;\n \tmbs = get_merge_bases(one, two);\ndiff --git a/shallow.c b/shallow.c\nindex aa6d04992c..b62dd2c5fb 100644\n--- a/shallow.c\n+++ b/shallow.c\n@@ -474,7 +474,8 @@ static void paint_down(struct paint_info *info, const struct object_id *oid,\n \tstruct commit_list *head = NULL;\n \tint bitmap_nr = DIV_ROUND_UP(info->nr_bits, 32);\n \tsize_t bitmap_size = st_mult(sizeof(uint32_t), bitmap_nr);\n-\tstruct commit *c = lookup_commit_reference_gently(oid, 1);\n+\tstruct commit *c = lookup_commit_reference_gently(the_repository, oid,\n+\t\t\t\t\t\t\t  1);\n \tuint32_t *tmp; /* to be freed before return */\n \tuint32_t *bitmap;\n \n@@ -536,7 +537,8 @@ static void paint_down(struct paint_info *info, const struct object_id *oid,\n static int mark_uninteresting(const char *refname, const struct object_id *oid,\n \t\t\t      int flags, void *cb_data)\n {\n-\tstruct commit *commit = lookup_commit_reference_gently(oid, 1);\n+\tstruct commit *commit = lookup_commit_reference_gently(the_repository,\n+\t\t\t\t\t\t\t       oid, 1);\n \tif (!commit)\n \t\treturn 0;\n \tcommit->object.flags |= UNINTERESTING;\n@@ -646,7 +648,8 @@ static int add_ref(const char *refname, const struct object_id *oid,\n {\n \tstruct commit_array *ca = cb_data;\n \tALLOC_GROW(ca->commits, ca->nr + 1, ca->alloc);\n-\tca->commits[ca->nr] = lookup_commit_reference_gently(oid, 1);\n+\tca->commits[ca->nr] = lookup_commit_reference_gently(the_repository,\n+\t\t\t\t\t\t\t     oid, 1);\n \tif (ca->commits[ca->nr])\n \t\tca->nr++;\n \treturn 0;\ndiff --git a/walker.c b/walker.c\nindex 5cfd2316a8..2b6bd9da81 100644\n--- a/walker.c\n+++ b/walker.c\n@@ -210,7 +210,8 @@ static int interpret_target(struct walker *walker, char *target, struct object_i\n static int mark_complete(const char *path, const struct object_id *oid,\n \t\t\t int flag, void *cb_data)\n {\n-\tstruct commit *commit = lookup_commit_reference_gently(oid, 1);\n+\tstruct commit *commit = lookup_commit_reference_gently(the_repository,\n+\t\t\t\t\t\t\t       oid, 1);\n \n \tif (commit) {\n \t\tcommit->object.flags |= COMPLETE;\ndiff --git a/wt-status.c b/wt-status.c\nindex ef26f07446..6655bc6f67 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -1458,7 +1458,7 @@ static void wt_status_get_detached_from(struct wt_status_state *state)\n \t    /* sha1 is a commit? match without further lookup */\n \t    (!oidcmp(&cb.noid, &oid) ||\n \t     /* perhaps sha1 is a tag, try to dereference to a commit */\n-\t     ((commit = lookup_commit_reference_gently(&oid, 1)) != NULL &&\n+\t     ((commit = lookup_commit_reference_gently(the_repository, &oid, 1)) != NULL &&\n \t      !oidcmp(&cb.noid, &commit->object.oid)))) {\n \t\tconst char *from = ref;\n \t\tif (!skip_prefix(from, \"refs/tags/\", &from))\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338357","messageId":"20180205235735.216710-70-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 090/194] object: add repository argument to lookup_commit_reference","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:51Z","receivedAt":"2018-02-06T00:13:50Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow callers of lookup_commit_reference\nto be more specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nThe included coccinelle semantic patch will adapt any new callers in\nthe diff produced by `make coccicheck`.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n bisect.c                               |  2 +-\n blame.c                                |  2 +-\n branch.c                               |  2 +-\n builtin/branch.c                       |  7 ++++---\n builtin/clone.c                        |  3 ++-\n builtin/describe.c                     |  2 +-\n builtin/diff-tree.c                    |  2 +-\n builtin/log.c                          |  7 ++++---\n builtin/merge-base.c                   |  5 +++--\n builtin/notes.c                        |  3 ++-\n builtin/pull.c                         | 15 ++++++++++-----\n builtin/reset.c                        |  4 ++--\n builtin/rev-parse.c                    |  6 +++---\n builtin/show-branch.c                  |  2 +-\n builtin/tag.c                          |  2 +-\n bundle.c                               |  3 ++-\n commit.c                               |  6 +++---\n commit.h                               |  4 +++-\n contrib/coccinelle/object_parser.cocci |  7 +++++++\n notes-merge.c                          |  5 +++--\n parse-options-cb.c                     |  2 +-\n remote.c                               |  4 ++--\n revision.c                             |  4 ++--\n sequencer.c                            |  4 ++--\n sha1_name.c                            |  4 ++--\n submodule.c                            | 10 +++++-----\n 26 files changed, 69 insertions(+), 48 deletions(-)\n\ndiff --git a/bisect.c b/bisect.c\nindex 2f3008b078..c3066bd972 100644\n--- a/bisect.c\n+++ b/bisect.c\n@@ -717,7 +717,7 @@ static int bisect_checkout(const struct object_id *bisect_rev, int no_checkout)\n \n static struct commit *get_commit_reference(const struct object_id *oid)\n {\n-\tstruct commit *r = lookup_commit_reference(oid);\n+\tstruct commit *r = lookup_commit_reference(the_repository, oid);\n \tif (!r)\n \t\tdie(_(\"Not a valid commit name %s\"), oid_to_hex(oid));\n \treturn r;\ndiff --git a/blame.c b/blame.c\nindex 98761c32d5..1aab6228cc 100644\n--- a/blame.c\n+++ b/blame.c\n@@ -101,7 +101,7 @@ static struct commit_list **append_parent(struct commit_list **tail, const struc\n {\n \tstruct commit *parent;\n \n-\tparent = lookup_commit_reference(oid);\n+\tparent = lookup_commit_reference(the_repository, oid);\n \tif (!parent)\n \t\tdie(\"no such commit %s\", oid_to_hex(oid));\n \treturn &commit_list_insert(parent, tail)->next;\ndiff --git a/branch.c b/branch.c\nindex 2672054f0b..0b7aaa1aca 100644\n--- a/branch.c\n+++ b/branch.c\n@@ -301,7 +301,7 @@ void create_branch(const char *name, const char *start_name,\n \t\tbreak;\n \t}\n \n-\tif ((commit = lookup_commit_reference(&oid)) == NULL)\n+\tif ((commit = lookup_commit_reference(the_repository, &oid)) == NULL)\n \t\tdie(_(\"Not a valid branch point: '%s'.\"), start_name);\n \toidcpy(&oid, &commit->object.oid);\n \ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex 8dcc2ed058..2d752c6614 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -126,7 +126,8 @@ static int branch_merged(int kind, const char *name,\n \t\t    (reference_name = reference_name_to_free =\n \t\t     resolve_refdup(upstream, RESOLVE_REF_READING,\n \t\t\t\t    &oid, NULL)) != NULL)\n-\t\t\treference_rev = lookup_commit_reference(&oid);\n+\t\t\treference_rev = lookup_commit_reference(the_repository,\n+\t\t\t\t\t\t\t\t&oid);\n \t}\n \tif (!reference_rev)\n \t\treference_rev = head_rev;\n@@ -159,7 +160,7 @@ static int check_branch_commit(const char *branchname, const char *refname,\n \t\t\t       const struct object_id *oid, struct commit *head_rev,\n \t\t\t       int kinds, int force)\n {\n-\tstruct commit *rev = lookup_commit_reference(oid);\n+\tstruct commit *rev = lookup_commit_reference(the_repository, oid);\n \tif (!rev) {\n \t\terror(_(\"Couldn't look up commit object for '%s'\"), refname);\n \t\treturn -1;\n@@ -213,7 +214,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,\n \t}\n \n \tif (!force) {\n-\t\thead_rev = lookup_commit_reference(&head_oid);\n+\t\thead_rev = lookup_commit_reference(the_repository, &head_oid);\n \t\tif (!head_rev)\n \t\t\tdie(_(\"Couldn't look up commit object for HEAD\"));\n \t}\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex ecd71b9444..6efe189846 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -690,7 +690,8 @@ static void update_head(const struct ref *our, const struct ref *remote,\n \t\t\tinstall_branch_config(0, head, option_origin, our->name);\n \t\t}\n \t} else if (our) {\n-\t\tstruct commit *c = lookup_commit_reference(&our->old_oid);\n+\t\tstruct commit *c = lookup_commit_reference(the_repository,\n+\t\t\t\t\t\t\t   &our->old_oid);\n \t\t/* --branch specifies a non-branch (i.e. tags), detach HEAD */\n \t\tupdate_ref(msg, \"HEAD\", &c->object.oid, NULL, REF_NO_DEREF,\n \t\t\t   UPDATE_REFS_DIE_ON_ERR);\ndiff --git a/builtin/describe.c b/builtin/describe.c\nindex f1172a8bf0..5bd0920ebd 100644\n--- a/builtin/describe.c\n+++ b/builtin/describe.c\n@@ -295,7 +295,7 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst)\n \tunsigned long seen_commits = 0;\n \tunsigned int unannotated_cnt = 0;\n \n-\tcmit = lookup_commit_reference(oid);\n+\tcmit = lookup_commit_reference(the_repository, oid);\n \n \tn = find_commit_name(&cmit->object.oid);\n \tif (n && (tags || all || n->prio == 2)) {\ndiff --git a/builtin/diff-tree.c b/builtin/diff-tree.c\nindex ab491efa9e..603f619532 100644\n--- a/builtin/diff-tree.c\n+++ b/builtin/diff-tree.c\n@@ -11,7 +11,7 @@ static struct rev_info log_tree_opt;\n \n static int diff_tree_commit_oid(const struct object_id *oid)\n {\n-\tstruct commit *commit = lookup_commit_reference(oid);\n+\tstruct commit *commit = lookup_commit_reference(the_repository, oid);\n \tif (!commit)\n \t\treturn -1;\n \treturn log_tree_commit(&log_tree_opt, commit);\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 2c3579b1f7..529e19ce6f 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -901,8 +901,8 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids)\n \to2 = rev->pending.objects[1].item;\n \tflags1 = o1->flags;\n \tflags2 = o2->flags;\n-\tc1 = lookup_commit_reference(&o1->oid);\n-\tc2 = lookup_commit_reference(&o2->oid);\n+\tc1 = lookup_commit_reference(the_repository, &o1->oid);\n+\tc2 = lookup_commit_reference(the_repository, &o2->oid);\n \n \tif ((flags1 & UNINTERESTING) == (flags2 & UNINTERESTING))\n \t\tdie(_(\"Not a range.\"));\n@@ -1850,7 +1850,8 @@ static int add_pending_commit(const char *arg, struct rev_info *revs, int flags)\n {\n \tstruct object_id oid;\n \tif (get_oid(arg, &oid) == 0) {\n-\t\tstruct commit *commit = lookup_commit_reference(&oid);\n+\t\tstruct commit *commit = lookup_commit_reference(the_repository,\n+\t\t\t\t\t\t\t\t&oid);\n \t\tif (commit) {\n \t\t\tcommit->object.flags |= flags;\n \t\t\tadd_pending_object(revs, &commit->object, arg);\ndiff --git a/builtin/merge-base.c b/builtin/merge-base.c\nindex 3b7600150b..bbead6f33e 100644\n--- a/builtin/merge-base.c\n+++ b/builtin/merge-base.c\n@@ -6,6 +6,7 @@\n #include \"diff.h\"\n #include \"revision.h\"\n #include \"parse-options.h\"\n+#include \"repository.h\"\n \n static int show_merge_base(struct commit **rev, int rev_nr, int show_all)\n {\n@@ -42,7 +43,7 @@ static struct commit *get_commit_reference(const char *arg)\n \n \tif (get_oid(arg, &revkey))\n \t\tdie(\"Not a valid object name %s\", arg);\n-\tr = lookup_commit_reference(&revkey);\n+\tr = lookup_commit_reference(the_repository, &revkey);\n \tif (!r)\n \t\tdie(\"Not a valid commit name %s\", arg);\n \n@@ -171,7 +172,7 @@ static int handle_fork_point(int argc, const char **argv)\n \tif (get_oid(commitname, &oid))\n \t\tdie(\"Not a valid object name: '%s'\", commitname);\n \n-\tderived = lookup_commit_reference(&oid);\n+\tderived = lookup_commit_reference(the_repository, &oid);\n \tmemset(&revs, 0, sizeof(revs));\n \trevs.initial = 1;\n \tfor_each_reflog_ent(refname, collect_one_reflog_ent, &revs);\ndiff --git a/builtin/notes.c b/builtin/notes.c\nindex 1bd3994caa..18128eb439 100644\n--- a/builtin/notes.c\n+++ b/builtin/notes.c\n@@ -12,6 +12,7 @@\n #include \"builtin.h\"\n #include \"notes.h\"\n #include \"object-store.h\"\n+#include \"repository.h\"\n #include \"blob.h\"\n #include \"pretty.h\"\n #include \"refs.h\"\n@@ -711,7 +712,7 @@ static int merge_commit(struct notes_merge_options *o)\n \n \tif (get_oid(\"NOTES_MERGE_PARTIAL\", &oid))\n \t\tdie(_(\"failed to read ref NOTES_MERGE_PARTIAL\"));\n-\telse if (!(partial = lookup_commit_reference(&oid)))\n+\telse if (!(partial = lookup_commit_reference(the_repository, &oid)))\n \t\tdie(_(\"could not find commit from NOTES_MERGE_PARTIAL.\"));\n \telse if (parse_commit(partial))\n \t\tdie(_(\"could not parse commit from NOTES_MERGE_PARTIAL.\"));\ndiff --git a/builtin/pull.c b/builtin/pull.c\nindex 511dbbe0f6..90aa922260 100644\n--- a/builtin/pull.c\n+++ b/builtin/pull.c\n@@ -758,10 +758,13 @@ static int get_octopus_merge_base(struct object_id *merge_base,\n {\n \tstruct commit_list *revs = NULL, *result;\n \n-\tcommit_list_insert(lookup_commit_reference(curr_head), &revs);\n-\tcommit_list_insert(lookup_commit_reference(merge_head), &revs);\n+\tcommit_list_insert(lookup_commit_reference(the_repository, curr_head),\n+\t\t\t   &revs);\n+\tcommit_list_insert(lookup_commit_reference(the_repository, merge_head),\n+\t\t\t   &revs);\n \tif (!is_null_oid(fork_point))\n-\t\tcommit_list_insert(lookup_commit_reference(fork_point), &revs);\n+\t\tcommit_list_insert(lookup_commit_reference(the_repository, fork_point),\n+\t\t\t\t   &revs);\n \n \tresult = get_octopus_merge_bases(revs);\n \tfree_commit_list(revs);\n@@ -935,9 +938,11 @@ int cmd_pull(int argc, const char **argv, const char *prefix)\n \t\t\tstruct commit_list *list = NULL;\n \t\t\tstruct commit *merge_head, *head;\n \n-\t\t\thead = lookup_commit_reference(&orig_head);\n+\t\t\thead = lookup_commit_reference(the_repository,\n+\t\t\t\t\t\t       &orig_head);\n \t\t\tcommit_list_insert(head, &list);\n-\t\t\tmerge_head = lookup_commit_reference(&merge_heads.oid[0]);\n+\t\t\tmerge_head = lookup_commit_reference(the_repository,\n+\t\t\t\t\t\t\t     &merge_heads.oid[0]);\n \t\t\tif (is_descendant_of(merge_head, list)) {\n \t\t\t\t/* we can fast-forward this without invoking rebase */\n \t\t\t\topt_ff = \"--ff-only\";\ndiff --git a/builtin/reset.c b/builtin/reset.c\nindex e15f595799..ea600bc62a 100644\n--- a/builtin/reset.c\n+++ b/builtin/reset.c\n@@ -327,7 +327,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)\n \t\tstruct commit *commit;\n \t\tif (get_oid_committish(rev, &oid))\n \t\t\tdie(_(\"Failed to resolve '%s' as a valid revision.\"), rev);\n-\t\tcommit = lookup_commit_reference(&oid);\n+\t\tcommit = lookup_commit_reference(the_repository, &oid);\n \t\tif (!commit)\n \t\t\tdie(_(\"Could not parse object '%s'.\"), rev);\n \t\toidcpy(&oid, &commit->object.oid);\n@@ -404,7 +404,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)\n \t\tupdate_ref_status = reset_refs(rev, &oid);\n \n \t\tif (reset_type == HARD && !update_ref_status && !quiet)\n-\t\t\tprint_new_head_line(lookup_commit_reference(&oid));\n+\t\t\tprint_new_head_line(lookup_commit_reference(the_repository, &oid));\n \t}\n \tif (!pathspec.nr)\n \t\tremove_branch_state();\ndiff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\nindex 74aa644cbb..b5515df1ae 100644\n--- a/builtin/rev-parse.c\n+++ b/builtin/rev-parse.c\n@@ -280,8 +280,8 @@ static int try_difference(const char *arg)\n \t\tif (symmetric) {\n \t\t\tstruct commit_list *exclude;\n \t\t\tstruct commit *a, *b;\n-\t\t\ta = lookup_commit_reference(&oid);\n-\t\t\tb = lookup_commit_reference(&end);\n+\t\t\ta = lookup_commit_reference(the_repository, &oid);\n+\t\t\tb = lookup_commit_reference(the_repository, &end);\n \t\t\texclude = get_merge_bases(a, b);\n \t\t\twhile (exclude) {\n \t\t\t\tstruct commit *commit = pop_commit(&exclude);\n@@ -333,7 +333,7 @@ static int try_parent_shorthands(const char *arg)\n \t\treturn 0;\n \t}\n \n-\tcommit = lookup_commit_reference(&oid);\n+\tcommit = lookup_commit_reference(the_repository, &oid);\n \tif (exclude_parent &&\n \t    exclude_parent > commit_list_count(commit->parents)) {\n \t\t*dotdot = '^';\ndiff --git a/builtin/show-branch.c b/builtin/show-branch.c\nindex fb90c9ab3e..03c98efbe5 100644\n--- a/builtin/show-branch.c\n+++ b/builtin/show-branch.c\n@@ -811,7 +811,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \t\t\t       MAX_REVS), MAX_REVS);\n \t\tif (get_oid(ref_name[num_rev], &revkey))\n \t\t\tdie(_(\"'%s' is not a valid ref.\"), ref_name[num_rev]);\n-\t\tcommit = lookup_commit_reference(&revkey);\n+\t\tcommit = lookup_commit_reference(the_repository, &revkey);\n \t\tif (!commit)\n \t\t\tdie(_(\"cannot find commit %s (%s)\"),\n \t\t\t    ref_name[num_rev], oid_to_hex(&revkey));\ndiff --git a/builtin/tag.c b/builtin/tag.c\nindex 014d7c9e9b..1fad1e6733 100644\n--- a/builtin/tag.c\n+++ b/builtin/tag.c\n@@ -309,7 +309,7 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb)\n \t\t}\n \t\tfree(buf);\n \n-\t\tif ((c = lookup_commit_reference(oid)) != NULL)\n+\t\tif ((c = lookup_commit_reference(the_repository, oid)) != NULL)\n \t\t\tstrbuf_addf(sb, \", %s\", show_date(c->date, 0, DATE_MODE(SHORT)));\n \t\tbreak;\n \tcase OBJ_TREE:\ndiff --git a/bundle.c b/bundle.c\nindex 1b5f1beb3b..d9579f851e 100644\n--- a/bundle.c\n+++ b/bundle.c\n@@ -378,7 +378,8 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)\n \t\t\t * in terms of a tag (e.g. v2.0 from the range\n \t\t\t * \"v1.0..v2.0\")?\n \t\t\t */\n-\t\t\tstruct commit *one = lookup_commit_reference(&oid);\n+\t\t\tstruct commit *one = lookup_commit_reference(the_repository,\n+\t\t\t\t\t\t\t\t     &oid);\n \t\t\tstruct object *obj;\n \n \t\t\tif (e->item == &(one->object)) {\ndiff --git a/commit.c b/commit.c\nindex b6e253f1af..b943b97aee 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -32,14 +32,14 @@ struct commit *lookup_commit_reference_gently_the_repository(\n \treturn object_as_type(obj, OBJ_COMMIT, quiet);\n }\n \n-struct commit *lookup_commit_reference(const struct object_id *oid)\n+struct commit *lookup_commit_reference_the_repository(const struct object_id *oid)\n {\n \treturn lookup_commit_reference_gently(the_repository, oid, 0);\n }\n \n struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref_name)\n {\n-\tstruct commit *c = lookup_commit_reference(oid);\n+\tstruct commit *c = lookup_commit_reference(the_repository, oid);\n \tif (!c)\n \t\tdie(_(\"could not parse %s\"), ref_name);\n \tif (oidcmp(oid, &c->object.oid)) {\n@@ -65,7 +65,7 @@ struct commit *lookup_commit_reference_by_name(const char *name)\n \n \tif (get_oid_committish(name, &oid))\n \t\treturn NULL;\n-\tcommit = lookup_commit_reference(&oid);\n+\tcommit = lookup_commit_reference(the_repository, &oid);\n \tif (parse_commit(commit))\n \t\treturn NULL;\n \treturn commit;\ndiff --git a/commit.h b/commit.h\nindex 2ce5597066..9159165fde 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -47,7 +47,9 @@ void add_name_decoration(enum decoration_type type, const char *name, struct obj\n const struct name_decoration *get_name_decoration(const struct object *obj);\n \n struct commit *lookup_commit(const struct object_id *oid);\n-struct commit *lookup_commit_reference(const struct object_id *oid);\n+#define lookup_commit_reference(r, o) \\\n+\t\tlookup_commit_reference_##r(o)\n+struct commit *lookup_commit_reference_the_repository(const struct object_id *oid);\n #define lookup_commit_reference_gently(r, o, q) \\\n \t\tlookup_commit_reference_gently_##r(o, q)\n struct commit *lookup_commit_reference_gently_the_repository(\ndiff --git a/contrib/coccinelle/object_parser.cocci b/contrib/coccinelle/object_parser.cocci\nindex 7c1ef62e6d..bc00029f8c 100644\n--- a/contrib/coccinelle/object_parser.cocci\n+++ b/contrib/coccinelle/object_parser.cocci\n@@ -67,3 +67,10 @@ expression F;\n  lookup_commit_reference_gently(\n +the_repository,\n  E, F)\n+\n+@@\n+expression E;\n+@@\n+ lookup_commit_reference(\n++the_repository,\n+ E)\ndiff --git a/notes-merge.c b/notes-merge.c\nindex 1053c65e83..ea701827ba 100644\n--- a/notes-merge.c\n+++ b/notes-merge.c\n@@ -2,6 +2,7 @@\n #include \"commit.h\"\n #include \"refs.h\"\n #include \"object-store.h\"\n+#include \"repository.h\"\n #include \"diff.h\"\n #include \"diffcore.h\"\n #include \"xdiff-interface.h\"\n@@ -553,7 +554,7 @@ int notes_merge(struct notes_merge_options *o,\n \telse if (!check_refname_format(o->local_ref, 0) &&\n \t\tis_null_oid(&local_oid))\n \t\tlocal = NULL; /* local_oid == null_oid indicates unborn ref */\n-\telse if (!(local = lookup_commit_reference(&local_oid)))\n+\telse if (!(local = lookup_commit_reference(the_repository, &local_oid)))\n \t\tdie(\"Could not parse local commit %s (%s)\",\n \t\t    oid_to_hex(&local_oid), o->local_ref);\n \ttrace_printf(\"\\tlocal commit: %.7s\\n\", oid_to_hex(&local_oid));\n@@ -571,7 +572,7 @@ int notes_merge(struct notes_merge_options *o,\n \t\t\tdie(\"Failed to resolve remote notes ref '%s'\",\n \t\t\t    o->remote_ref);\n \t\t}\n-\t} else if (!(remote = lookup_commit_reference(&remote_oid))) {\n+\t} else if (!(remote = lookup_commit_reference(the_repository, &remote_oid))) {\n \t\tdie(\"Could not parse remote commit %s (%s)\",\n \t\t    oid_to_hex(&remote_oid), o->remote_ref);\n \t}\ndiff --git a/parse-options-cb.c b/parse-options-cb.c\nindex c6679cb2cd..624fcee6f4 100644\n--- a/parse-options-cb.c\n+++ b/parse-options-cb.c\n@@ -87,7 +87,7 @@ int parse_opt_commits(const struct option *opt, const char *arg, int unset)\n \t\treturn -1;\n \tif (get_oid(arg, &oid))\n \t\treturn error(\"malformed object name %s\", arg);\n-\tcommit = lookup_commit_reference(&oid);\n+\tcommit = lookup_commit_reference(the_repository, &oid);\n \tif (!commit)\n \t\treturn error(\"no such commit %s\", arg);\n \tcommit_list_insert(commit, opt->value);\ndiff --git a/remote.c b/remote.c\nindex a9386476fe..ecfa60a975 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -2039,13 +2039,13 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,\n \t/* Cannot stat if what we used to build on no longer exists */\n \tif (read_ref(base, &oid))\n \t\treturn -1;\n-\ttheirs = lookup_commit_reference(&oid);\n+\ttheirs = lookup_commit_reference(the_repository, &oid);\n \tif (!theirs)\n \t\treturn -1;\n \n \tif (read_ref(branch->refname, &oid))\n \t\treturn -1;\n-\tours = lookup_commit_reference(&oid);\n+\tours = lookup_commit_reference(the_repository, &oid);\n \tif (!ours)\n \t\treturn -1;\n \ndiff --git a/revision.c b/revision.c\nindex 629af0dca5..5c5375ac54 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -1563,8 +1563,8 @@ static int handle_dotdot_1(const char *arg, char *dotdot,\n \t\tstruct commit *a, *b;\n \t\tstruct commit_list *exclude;\n \n-\t\ta = lookup_commit_reference(&a_obj->oid);\n-\t\tb = lookup_commit_reference(&b_obj->oid);\n+\t\ta = lookup_commit_reference(the_repository, &a_obj->oid);\n+\t\tb = lookup_commit_reference(the_repository, &b_obj->oid);\n \t\tif (!a || !b)\n \t\t\treturn dotdot_missing(arg, dotdot, revs, symmetric);\n \ndiff --git a/sequencer.c b/sequencer.c\nindex d0c3c808aa..d24586bc6f 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -857,7 +857,7 @@ static int update_squash_messages(enum todo_command command,\n \n \t\tif (get_oid(\"HEAD\", &head))\n \t\t\treturn error(_(\"need a HEAD to fixup\"));\n-\t\tif (!(head_commit = lookup_commit_reference(&head)))\n+\t\tif (!(head_commit = lookup_commit_reference(the_repository, &head)))\n \t\t\treturn error(_(\"could not read HEAD\"));\n \t\tif (!(head_message = get_commit_buffer(head_commit, NULL)))\n \t\t\treturn error(_(\"could not read HEAD's commit message\"));\n@@ -1300,7 +1300,7 @@ static int parse_insn_line(struct todo_item *item, const char *bol, char *eol)\n \tif (status < 0)\n \t\treturn -1;\n \n-\titem->commit = lookup_commit_reference(&commit_oid);\n+\titem->commit = lookup_commit_reference(the_repository, &commit_oid);\n \treturn !item->commit;\n }\n \ndiff --git a/sha1_name.c b/sha1_name.c\nindex 160fec7062..ea169a28c1 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -849,7 +849,7 @@ static int get_parent(const char *name, int len,\n \n \tif (ret)\n \t\treturn ret;\n-\tcommit = lookup_commit_reference(&oid);\n+\tcommit = lookup_commit_reference(the_repository, &oid);\n \tif (parse_commit(commit))\n \t\treturn -1;\n \tif (!idx) {\n@@ -877,7 +877,7 @@ static int get_nth_ancestor(const char *name, int len,\n \tret = get_oid_1(name, len, &oid, GET_OID_COMMITTISH);\n \tif (ret)\n \t\treturn ret;\n-\tcommit = lookup_commit_reference(&oid);\n+\tcommit = lookup_commit_reference(the_repository, &oid);\n \tif (!commit)\n \t\treturn -1;\n \ndiff --git a/submodule.c b/submodule.c\nindex 1504812842..aec62e6c7d 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -515,8 +515,8 @@ static void show_submodule_header(struct diff_options *o, const char *path,\n \t * Attempt to lookup the commit references, and determine if this is\n \t * a fast forward or fast backwards update.\n \t */\n-\t*left = lookup_commit_reference(one);\n-\t*right = lookup_commit_reference(two);\n+\t*left = lookup_commit_reference(the_repository, one);\n+\t*right = lookup_commit_reference(the_repository, two);\n \n \t/*\n \t * Warn about missing commits in the submodule project, but only if\n@@ -1820,9 +1820,9 @@ int merge_submodule(struct object_id *result, const char *path,\n \t\treturn 0;\n \t}\n \n-\tif (!(commit_base = lookup_commit_reference(base)) ||\n-\t    !(commit_a = lookup_commit_reference(a)) ||\n-\t    !(commit_b = lookup_commit_reference(b))) {\n+\tif (!(commit_base = lookup_commit_reference(the_repository, base)) ||\n+\t    !(commit_a = lookup_commit_reference(the_repository, a)) ||\n+\t    !(commit_b = lookup_commit_reference(the_repository, b))) {\n \t\tMERGE_WARNING(path, \"commits not present\");\n \t\treturn 0;\n \t}\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338358","messageId":"20180205235735.216710-71-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 091/194] object: add repository argument to lookup_commit","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:52Z","receivedAt":"2018-02-06T00:14:04Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nAdd a repository argument to allow callers of lookup_commit to be more\nspecific about which repository to handle. This is a small mechanical\nchange; it doesn't change the implementation to handle repositories\nother than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nThe included coccinelle semantic patch will adapt any new callers in\nthe diff produced by `make coccicheck`.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n builtin/am.c                           |  3 ++-\n builtin/commit-tree.c                  |  4 +++-\n builtin/commit.c                       |  2 +-\n builtin/diff-tree.c                    |  2 +-\n builtin/fast-export.c                  |  2 +-\n builtin/fmt-merge-msg.c                |  2 +-\n builtin/merge-base.c                   |  2 +-\n builtin/verify-commit.c                |  4 +++-\n commit.c                               |  7 ++++---\n commit.h                               |  3 ++-\n contrib/coccinelle/object_parser.cocci |  7 +++++++\n fetch-pack.c                           |  3 ++-\n log-tree.c                             |  2 +-\n notes-utils.c                          |  4 +++-\n object.c                               |  2 +-\n sequencer.c                            |  2 +-\n sha1_name.c                            |  2 +-\n shallow.c                              | 17 ++++++++++-------\n tag.c                                  |  2 +-\n tree.c                                 |  2 +-\n 20 files changed, 47 insertions(+), 27 deletions(-)\n\ndiff --git a/builtin/am.c b/builtin/am.c\nindex 32002a8661..83bc22649e 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -1629,7 +1629,8 @@ static void do_commit(const struct am_state *state)\n \n \tif (!get_oid_commit(\"HEAD\", &parent)) {\n \t\told_oid = &parent;\n-\t\tcommit_list_insert(lookup_commit(&parent), &parents);\n+\t\tcommit_list_insert(lookup_commit(the_repository, &parent),\n+\t\t\t\t   &parents);\n \t} else {\n \t\told_oid = NULL;\n \t\tsay(state, stderr, _(\"applying to an empty history\"));\ndiff --git a/builtin/commit-tree.c b/builtin/commit-tree.c\nindex a54fb362ce..4f4fcace3b 100644\n--- a/builtin/commit-tree.c\n+++ b/builtin/commit-tree.c\n@@ -6,6 +6,7 @@\n #include \"cache.h\"\n #include \"config.h\"\n #include \"object-store.h\"\n+#include \"repository.h\"\n #include \"commit.h\"\n #include \"tree.h\"\n #include \"builtin.h\"\n@@ -60,7 +61,8 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)\n \t\t\tif (get_oid_commit(argv[i], &oid))\n \t\t\t\tdie(\"Not a valid object name %s\", argv[i]);\n \t\t\tassert_sha1_type(oid.hash, OBJ_COMMIT);\n-\t\t\tnew_parent(lookup_commit(&oid), &parents);\n+\t\t\tnew_parent(lookup_commit(the_repository, &oid),\n+\t\t\t\t   &parents);\n \t\t\tcontinue;\n \t\t}\n \ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 8a87701414..cd3144f9f4 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -1464,7 +1464,7 @@ static void print_summary(const char *prefix, const struct object_id *oid,\n \tstruct strbuf author_ident = STRBUF_INIT;\n \tstruct strbuf committer_ident = STRBUF_INIT;\n \n-\tcommit = lookup_commit(oid);\n+\tcommit = lookup_commit(the_repository, oid);\n \tif (!commit)\n \t\tdie(_(\"couldn't look up newly created commit\"));\n \tif (parse_commit(commit))\ndiff --git a/builtin/diff-tree.c b/builtin/diff-tree.c\nindex 603f619532..62c435a65f 100644\n--- a/builtin/diff-tree.c\n+++ b/builtin/diff-tree.c\n@@ -25,7 +25,7 @@ static int stdin_diff_commit(struct commit *commit, const char *p)\n \n \t/* Graft the fake parents locally to the commit */\n \twhile (isspace(*p++) && !parse_oid_hex(p, &oid, &p)) {\n-\t\tstruct commit *parent = lookup_commit(&oid);\n+\t\tstruct commit *parent = lookup_commit(the_repository, &oid);\n \t\tif (!pptr) {\n \t\t\t/* Free the real parent list */\n \t\t\tfree_commit_list(commit->parents);\ndiff --git a/builtin/fast-export.c b/builtin/fast-export.c\nindex 14a27d539f..322adfd408 100644\n--- a/builtin/fast-export.c\n+++ b/builtin/fast-export.c\n@@ -958,7 +958,7 @@ static void import_marks(char *input_file)\n \t\t\t/* only commits */\n \t\t\tcontinue;\n \n-\t\tcommit = lookup_commit(&oid);\n+\t\tcommit = lookup_commit(the_repository, &oid);\n \t\tif (!commit)\n \t\t\tdie(\"not a commit? can't happen: %s\", oid_to_hex(&oid));\n \ndiff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c\nindex 49fd7ea1d2..3e99d10218 100644\n--- a/builtin/fmt-merge-msg.c\n+++ b/builtin/fmt-merge-msg.c\n@@ -573,7 +573,7 @@ static void find_merge_parents(struct merge_parents *result,\n \t\tcommit_list_insert(parent, &parents);\n \t\tadd_merge_parent(result, &obj->oid, &parent->object.oid);\n \t}\n-\thead_commit = lookup_commit(head);\n+\thead_commit = lookup_commit(the_repository, head);\n \tif (head_commit)\n \t\tcommit_list_insert(head_commit, &parents);\n \treduce_heads_replace(&parents);\ndiff --git a/builtin/merge-base.c b/builtin/merge-base.c\nindex bbead6f33e..08d91b1f0c 100644\n--- a/builtin/merge-base.c\n+++ b/builtin/merge-base.c\n@@ -124,7 +124,7 @@ static void add_one_commit(struct object_id *oid, struct rev_collect *revs)\n \tif (is_null_oid(oid))\n \t\treturn;\n \n-\tcommit = lookup_commit(oid);\n+\tcommit = lookup_commit(the_repository, oid);\n \tif (!commit ||\n \t    (commit->object.flags & TMP_MARK) ||\n \t    parse_commit(commit))\ndiff --git a/builtin/verify-commit.c b/builtin/verify-commit.c\nindex 29f5e5507c..b0ae18ec33 100644\n--- a/builtin/verify-commit.c\n+++ b/builtin/verify-commit.c\n@@ -9,6 +9,7 @@\n #include \"config.h\"\n #include \"builtin.h\"\n #include \"object-store.h\"\n+#include \"repository.h\"\n #include \"commit.h\"\n #include \"run-command.h\"\n #include <signal.h>\n@@ -27,7 +28,8 @@ static int run_gpg_verify(const struct object_id *oid, const char *buf, unsigned\n \n \tmemset(&signature_check, 0, sizeof(signature_check));\n \n-\tret = check_commit_signature(lookup_commit(oid), &signature_check);\n+\tret = check_commit_signature(lookup_commit(the_repository, oid),\n+\t\t\t\t     &signature_check);\n \tprint_signature_buffer(&signature_check, flags);\n \n \tsignature_check_clear(&signature_check);\ndiff --git a/commit.c b/commit.c\nindex b943b97aee..2137a0b9c6 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -49,7 +49,7 @@ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref\n \treturn c;\n }\n \n-struct commit *lookup_commit(const struct object_id *oid)\n+struct commit *lookup_commit_the_repository(const struct object_id *oid)\n {\n \tstruct object *obj = lookup_object(the_repository, oid->hash);\n \tif (!obj)\n@@ -359,7 +359,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s\n \t\t */\n \t\tif (graft && (graft->nr_parent < 0 || grafts_replace_parents))\n \t\t\tcontinue;\n-\t\tnew_parent = lookup_commit(&parent);\n+\t\tnew_parent = lookup_commit(the_repository, &parent);\n \t\tif (new_parent)\n \t\t\tpptr = &commit_list_insert(new_parent, pptr)->next;\n \t}\n@@ -367,7 +367,8 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s\n \t\tint i;\n \t\tstruct commit *new_parent;\n \t\tfor (i = 0; i < graft->nr_parent; i++) {\n-\t\t\tnew_parent = lookup_commit(&graft->parent[i]);\n+\t\t\tnew_parent = lookup_commit(the_repository,\n+\t\t\t\t\t\t   &graft->parent[i]);\n \t\t\tif (!new_parent)\n \t\t\t\tcontinue;\n \t\t\tpptr = &commit_list_insert(new_parent, pptr)->next;\ndiff --git a/commit.h b/commit.h\nindex 9159165fde..61e01112eb 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -46,7 +46,8 @@ enum decoration_type {\n void add_name_decoration(enum decoration_type type, const char *name, struct object *obj);\n const struct name_decoration *get_name_decoration(const struct object *obj);\n \n-struct commit *lookup_commit(const struct object_id *oid);\n+#define lookup_commit(r, o) lookup_commit_##r(o)\n+struct commit *lookup_commit_the_repository(const struct object_id *oid);\n #define lookup_commit_reference(r, o) \\\n \t\tlookup_commit_reference_##r(o)\n struct commit *lookup_commit_reference_the_repository(const struct object_id *oid);\ndiff --git a/contrib/coccinelle/object_parser.cocci b/contrib/coccinelle/object_parser.cocci\nindex bc00029f8c..c3cc4dfc9e 100644\n--- a/contrib/coccinelle/object_parser.cocci\n+++ b/contrib/coccinelle/object_parser.cocci\n@@ -74,3 +74,10 @@ expression E;\n  lookup_commit_reference(\n +the_repository,\n  E)\n+\n+@@\n+expression E;\n+@@\n+ lookup_commit(\n++the_repository,\n+ E)\ndiff --git a/fetch-pack.c b/fetch-pack.c\nindex ee1e65688a..f38beea6a3 100644\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -491,7 +491,8 @@ static int find_common(struct fetch_pack_args *args,\n \t\t\t\tcase ACK_ready:\n \t\t\t\tcase ACK_continue: {\n \t\t\t\t\tstruct commit *commit =\n-\t\t\t\t\t\tlookup_commit(result_oid);\n+\t\t\t\t\t\tlookup_commit(the_repository,\n+\t\t\t\t\t\t\t      result_oid);\n \t\t\t\t\tif (!commit)\n \t\t\t\t\t\tdie(_(\"invalid commit %s\"), oid_to_hex(result_oid));\n \t\t\t\t\tif (args->stateless_rpc\ndiff --git a/log-tree.c b/log-tree.c\nindex 1137506884..9fb333605b 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -147,7 +147,7 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid,\n \n static int add_graft_decoration(const struct commit_graft *graft, void *cb_data)\n {\n-\tstruct commit *commit = lookup_commit(&graft->oid);\n+\tstruct commit *commit = lookup_commit(the_repository, &graft->oid);\n \tif (!commit)\n \t\treturn 0;\n \tadd_name_decoration(DECORATION_GRAFTED, \"grafted\", &commit->object);\ndiff --git a/notes-utils.c b/notes-utils.c\nindex 5c8e70c98f..3ef5340c6e 100644\n--- a/notes-utils.c\n+++ b/notes-utils.c\n@@ -3,6 +3,7 @@\n #include \"commit.h\"\n #include \"refs.h\"\n #include \"notes-utils.h\"\n+#include \"repository.h\"\n \n void create_notes_commit(struct notes_tree *t, struct commit_list *parents,\n \t\t\t const char *msg, size_t msg_len,\n@@ -19,7 +20,8 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,\n \t\t/* Deduce parent commit from t->ref */\n \t\tstruct object_id parent_oid;\n \t\tif (!read_ref(t->ref, &parent_oid)) {\n-\t\t\tstruct commit *parent = lookup_commit(&parent_oid);\n+\t\t\tstruct commit *parent = lookup_commit(the_repository,\n+\t\t\t\t\t\t\t      &parent_oid);\n \t\t\tif (parse_commit(parent))\n \t\t\t\tdie(\"Failed to find/parse commit %s\", t->ref);\n \t\t\tcommit_list_insert(parent, &parents);\ndiff --git a/object.c b/object.c\nindex c9ce89cf37..6676887315 100644\n--- a/object.c\n+++ b/object.c\n@@ -209,7 +209,7 @@ struct object *parse_object_buffer(const struct object_id *oid, enum object_type\n \t\t\t}\n \t\t}\n \t} else if (type == OBJ_COMMIT) {\n-\t\tstruct commit *commit = lookup_commit(oid);\n+\t\tstruct commit *commit = lookup_commit(the_repository, oid);\n \t\tif (commit) {\n \t\t\tif (parse_commit_buffer(commit, buffer, size))\n \t\t\t\treturn NULL;\ndiff --git a/sequencer.c b/sequencer.c\nindex d24586bc6f..4d259d9ae4 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -497,7 +497,7 @@ static int is_index_unchanged(void)\n \tif (!resolve_ref_unsafe(\"HEAD\", RESOLVE_REF_READING, &head_oid, NULL))\n \t\treturn error(_(\"could not resolve HEAD commit\"));\n \n-\thead_commit = lookup_commit(&head_oid);\n+\thead_commit = lookup_commit(the_repository, &head_oid);\n \n \t/*\n \t * If head_commit is NULL, check_commit, called from\ndiff --git a/sha1_name.c b/sha1_name.c\nindex ea169a28c1..45b7d6be91 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -374,7 +374,7 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)\n \n \ttype = sha1_object_info(the_repository, oid->hash, NULL);\n \tif (type == OBJ_COMMIT) {\n-\t\tstruct commit *commit = lookup_commit(oid);\n+\t\tstruct commit *commit = lookup_commit(the_repository, oid);\n \t\tif (commit) {\n \t\t\tstruct pretty_print_context pp = {0};\n \t\t\tpp.date_mode.type = DATE_SHORT;\ndiff --git a/shallow.c b/shallow.c\nindex b62dd2c5fb..97c483239a 100644\n--- a/shallow.c\n+++ b/shallow.c\n@@ -32,7 +32,7 @@ int register_shallow(const struct object_id *oid)\n {\n \tstruct commit_graft *graft =\n \t\txmalloc(sizeof(struct commit_graft));\n-\tstruct commit *commit = lookup_commit(oid);\n+\tstruct commit *commit = lookup_commit(the_repository, oid);\n \n \toidcpy(&graft->oid, oid);\n \tgraft->nr_parent = -1;\n@@ -244,7 +244,7 @@ static int write_one_shallow(const struct commit_graft *graft, void *cb_data)\n \tif (graft->nr_parent != -1)\n \t\treturn 0;\n \tif (data->flags & SEEN_ONLY) {\n-\t\tstruct commit *c = lookup_commit(&graft->oid);\n+\t\tstruct commit *c = lookup_commit(the_repository, &graft->oid);\n \t\tif (!c || !(c->object.flags & SEEN)) {\n \t\t\tif (data->flags & VERBOSE)\n \t\t\t\tprintf(\"Removing %s from .git/shallow\\n\",\n@@ -606,7 +606,8 @@ void assign_shallow_commits_to_refs(struct shallow_info *info,\n \n \t/* Mark potential bottoms so we won't go out of bound */\n \tfor (i = 0; i < nr_shallow; i++) {\n-\t\tstruct commit *c = lookup_commit(&oid[shallow[i]]);\n+\t\tstruct commit *c = lookup_commit(the_repository,\n+\t\t\t\t\t\t &oid[shallow[i]]);\n \t\tc->object.flags |= BOTTOM;\n \t}\n \n@@ -617,7 +618,8 @@ void assign_shallow_commits_to_refs(struct shallow_info *info,\n \t\tint bitmap_size = DIV_ROUND_UP(pi.nr_bits, 32) * sizeof(uint32_t);\n \t\tmemset(used, 0, sizeof(*used) * info->shallow->nr);\n \t\tfor (i = 0; i < nr_shallow; i++) {\n-\t\t\tconst struct commit *c = lookup_commit(&oid[shallow[i]]);\n+\t\t\tconst struct commit *c = lookup_commit(the_repository,\n+\t\t\t\t\t\t\t       &oid[shallow[i]]);\n \t\t\tuint32_t **map = ref_bitmap_at(&pi.ref_bitmap, c);\n \t\t\tif (*map)\n \t\t\t\tused[shallow[i]] = xmemdupz(*map, bitmap_size);\n@@ -687,7 +689,7 @@ static void post_assign_shallow(struct shallow_info *info,\n \tfor (i = dst = 0; i < info->nr_theirs; i++) {\n \t\tif (i != dst)\n \t\t\tinfo->theirs[dst] = info->theirs[i];\n-\t\tc = lookup_commit(&oid[info->theirs[i]]);\n+\t\tc = lookup_commit(the_repository, &oid[info->theirs[i]]);\n \t\tbitmap = ref_bitmap_at(ref_bitmap, c);\n \t\tif (!*bitmap)\n \t\t\tcontinue;\n@@ -708,7 +710,7 @@ static void post_assign_shallow(struct shallow_info *info,\n \tfor (i = dst = 0; i < info->nr_ours; i++) {\n \t\tif (i != dst)\n \t\t\tinfo->ours[dst] = info->ours[i];\n-\t\tc = lookup_commit(&oid[info->ours[i]]);\n+\t\tc = lookup_commit(the_repository, &oid[info->ours[i]]);\n \t\tbitmap = ref_bitmap_at(ref_bitmap, c);\n \t\tif (!*bitmap)\n \t\t\tcontinue;\n@@ -730,7 +732,8 @@ static void post_assign_shallow(struct shallow_info *info,\n int delayed_reachability_test(struct shallow_info *si, int c)\n {\n \tif (si->need_reachability_test[c]) {\n-\t\tstruct commit *commit = lookup_commit(&si->shallow->oid[c]);\n+\t\tstruct commit *commit = lookup_commit(the_repository,\n+\t\t\t\t\t\t      &si->shallow->oid[c]);\n \n \t\tif (!si->commits) {\n \t\t\tstruct commit_array ca;\ndiff --git a/tag.c b/tag.c\nindex d8174e0405..da2fe4f2ee 100644\n--- a/tag.c\n+++ b/tag.c\n@@ -150,7 +150,7 @@ int parse_tag_buffer_the_repository(struct tag *item, const void *data, unsigned\n \t} else if (!strcmp(type, tree_type)) {\n \t\titem->tagged = (struct object *)lookup_tree(the_repository, &oid);\n \t} else if (!strcmp(type, commit_type)) {\n-\t\titem->tagged = (struct object *)lookup_commit(&oid);\n+\t\titem->tagged = (struct object *)lookup_commit(the_repository, &oid);\n \t} else if (!strcmp(type, tag_type)) {\n \t\titem->tagged = (struct object *)lookup_tag(the_repository, &oid);\n \t} else {\ndiff --git a/tree.c b/tree.c\nindex b0d8610c41..6e0aafa805 100644\n--- a/tree.c\n+++ b/tree.c\n@@ -100,7 +100,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,\n \t\telse if (S_ISGITLINK(entry.mode)) {\n \t\t\tstruct commit *commit;\n \n-\t\t\tcommit = lookup_commit(entry.oid);\n+\t\t\tcommit = lookup_commit(the_repository, entry.oid);\n \t\t\tif (!commit)\n \t\t\t\tdie(\"Commit %s in submodule path %s%s not found\",\n \t\t\t\t    oid_to_hex(entry.oid),\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338359","messageId":"20180205235735.216710-72-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 092/194] object: move grafts to object parser","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:53Z","receivedAt":"2018-02-06T00:14:07Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nGrafts are only meaningful in the context of a single repository.\nTherefore they cannot be global.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n commit.c | 44 +++++++++++++++++++++++---------------------\n object.h |  6 +++++-\n 2 files changed, 28 insertions(+), 22 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex 2137a0b9c6..2ad5537ed7 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -1,6 +1,7 @@\n #include \"cache.h\"\n #include \"tag.h\"\n #include \"commit.h\"\n+#include \"repository.h\"\n #include \"object-store.h\"\n #include \"pkt-line.h\"\n #include \"utf8.h\"\n@@ -98,9 +99,6 @@ static timestamp_t parse_commit_date(const char *buf, const char *tail)\n \treturn parse_timestamp(dateptr, NULL, 10);\n }\n \n-static struct commit_graft **commit_graft;\n-static int commit_graft_alloc, commit_graft_nr;\n-\n static const unsigned char *commit_graft_sha1_access(size_t index, void *table)\n {\n \tstruct commit_graft **commit_graft_table = table;\n@@ -109,7 +107,8 @@ static const unsigned char *commit_graft_sha1_access(size_t index, void *table)\n \n static int commit_graft_pos(const unsigned char *sha1)\n {\n-\treturn sha1_pos(sha1, commit_graft, commit_graft_nr,\n+\treturn sha1_pos(sha1, the_repository->parsed_objects.grafts,\n+\t\t\tthe_repository->parsed_objects.grafts_nr,\n \t\t\tcommit_graft_sha1_access);\n }\n \n@@ -121,20 +120,22 @@ int register_commit_graft(struct commit_graft *graft, int ignore_dups)\n \t\tif (ignore_dups)\n \t\t\tfree(graft);\n \t\telse {\n-\t\t\tfree(commit_graft[pos]);\n-\t\t\tcommit_graft[pos] = graft;\n+\t\t\tfree(the_repository->parsed_objects.grafts[pos]);\n+\t\t\tthe_repository->parsed_objects.grafts[pos] = graft;\n \t\t}\n \t\treturn 1;\n \t}\n \tpos = -pos - 1;\n-\tALLOC_GROW(commit_graft, commit_graft_nr + 1, commit_graft_alloc);\n-\tcommit_graft_nr++;\n-\tif (pos < commit_graft_nr)\n-\t\tmemmove(commit_graft + pos + 1,\n-\t\t\tcommit_graft + pos,\n-\t\t\t(commit_graft_nr - pos - 1) *\n-\t\t\tsizeof(*commit_graft));\n-\tcommit_graft[pos] = graft;\n+\tALLOC_GROW(the_repository->parsed_objects.grafts,\n+\t\t   the_repository->parsed_objects.grafts_nr + 1,\n+\t\t   the_repository->parsed_objects.grafts_alloc);\n+\tthe_repository->parsed_objects.grafts_nr++;\n+\tif (pos < the_repository->parsed_objects.grafts_nr)\n+\t\tmemmove(the_repository->parsed_objects.grafts + pos + 1,\n+\t\t\tthe_repository->parsed_objects.grafts + pos,\n+\t\t\t(the_repository->parsed_objects.grafts_nr - pos - 1) *\n+\t\t\tsizeof(*the_repository->parsed_objects.grafts));\n+\tthe_repository->parsed_objects.grafts[pos] = graft;\n \treturn 0;\n }\n \n@@ -216,14 +217,14 @@ struct commit_graft *lookup_commit_graft(const struct object_id *oid)\n \tpos = commit_graft_pos(oid->hash);\n \tif (pos < 0)\n \t\treturn NULL;\n-\treturn commit_graft[pos];\n+\treturn the_repository->parsed_objects.grafts[pos];\n }\n \n int for_each_commit_graft(each_commit_graft_fn fn, void *cb_data)\n {\n \tint i, ret;\n-\tfor (i = ret = 0; i < commit_graft_nr && !ret; i++)\n-\t\tret = fn(commit_graft[i], cb_data);\n+\tfor (i = ret = 0; i < the_repository->parsed_objects.grafts_nr && !ret; i++)\n+\t\tret = fn(the_repository->parsed_objects.grafts[i], cb_data);\n \treturn ret;\n }\n \n@@ -232,10 +233,11 @@ int unregister_shallow(const struct object_id *oid)\n \tint pos = commit_graft_pos(oid->hash);\n \tif (pos < 0)\n \t\treturn -1;\n-\tif (pos + 1 < commit_graft_nr)\n-\t\tMOVE_ARRAY(commit_graft + pos, commit_graft + pos + 1,\n-\t\t\t   commit_graft_nr - pos - 1);\n-\tcommit_graft_nr--;\n+\tif (pos + 1 < the_repository->parsed_objects.grafts_nr)\n+\t\tMOVE_ARRAY(the_repository->parsed_objects.grafts + pos,\n+\t\t\t   the_repository->parsed_objects.grafts + pos + 1,\n+\t\t\t   the_repository->parsed_objects.grafts_nr - pos - 1);\n+\tthe_repository->parsed_objects.grafts_nr--;\n \treturn 0;\n }\n \ndiff --git a/object.h b/object.h\nindex 727a03ebd6..b667404f88 100644\n--- a/object.h\n+++ b/object.h\n@@ -4,9 +4,13 @@\n struct object_parser {\n \tstruct object **obj_hash;\n \tint nr_objs, obj_hash_size;\n+\n+\t/* parent substitutions from .git/info/grafts and .git/shallow */\n+\tstruct commit_graft **grafts;\n+\tint grafts_alloc, grafts_nr;\n };\n \n-#define OBJECT_PARSER_INIT { NULL, 0, 0 }\n+#define OBJECT_PARSER_INIT { NULL, 0, 0, NULL, 0, 0 }\n \n struct object_list {\n \tstruct object *item;\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338360","messageId":"20180205235735.216710-73-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 093/194] object: add repository argument to commit_graft_pos","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:54Z","receivedAt":"2018-02-06T00:14:30Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nAdd a repository argument to allow callers of commit_graft_pos to be\nmore specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n commit.c | 9 +++++----\n 1 file changed, 5 insertions(+), 4 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex 2ad5537ed7..a77c05f51c 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -105,7 +105,8 @@ static const unsigned char *commit_graft_sha1_access(size_t index, void *table)\n \treturn commit_graft_table[index]->oid.hash;\n }\n \n-static int commit_graft_pos(const unsigned char *sha1)\n+#define commit_graft_pos(r, s) commit_graft_pos_##r(s)\n+static int commit_graft_pos_the_repository(const unsigned char *sha1)\n {\n \treturn sha1_pos(sha1, the_repository->parsed_objects.grafts,\n \t\t\tthe_repository->parsed_objects.grafts_nr,\n@@ -114,7 +115,7 @@ static int commit_graft_pos(const unsigned char *sha1)\n \n int register_commit_graft(struct commit_graft *graft, int ignore_dups)\n {\n-\tint pos = commit_graft_pos(graft->oid.hash);\n+\tint pos = commit_graft_pos(the_repository, graft->oid.hash);\n \n \tif (0 <= pos) {\n \t\tif (ignore_dups)\n@@ -214,7 +215,7 @@ struct commit_graft *lookup_commit_graft(const struct object_id *oid)\n {\n \tint pos;\n \tprepare_commit_graft();\n-\tpos = commit_graft_pos(oid->hash);\n+\tpos = commit_graft_pos(the_repository, oid->hash);\n \tif (pos < 0)\n \t\treturn NULL;\n \treturn the_repository->parsed_objects.grafts[pos];\n@@ -230,7 +231,7 @@ int for_each_commit_graft(each_commit_graft_fn fn, void *cb_data)\n \n int unregister_shallow(const struct object_id *oid)\n {\n-\tint pos = commit_graft_pos(oid->hash);\n+\tint pos = commit_graft_pos(the_repository, oid->hash);\n \tif (pos < 0)\n \t\treturn -1;\n \tif (pos + 1 < the_repository->parsed_objects.grafts_nr)\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338361","messageId":"20180205235735.216710-74-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 094/194] commit: add repository argument to parse_commit_buffer","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:55Z","receivedAt":"2018-02-06T00:14:32Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow the callers of parse_commit_buffer\nto be more specific about which repository to act on. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nAdd the cocci patch that converted the callers.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n commit.c                               | 4 ++--\n commit.h                               | 3 ++-\n contrib/coccinelle/object_parser.cocci | 9 +++++++++\n object.c                               | 2 +-\n sha1_file.c                            | 2 +-\n 5 files changed, 15 insertions(+), 5 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex a77c05f51c..f10a882d87 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -323,7 +323,7 @@ const void *detach_commit_buffer(struct commit *commit, unsigned long *sizep)\n \treturn ret;\n }\n \n-int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long size)\n+int parse_commit_buffer_the_repository(struct commit *item, const void *buffer, unsigned long size)\n {\n \tconst char *tail = buffer;\n \tconst char *bufptr = buffer;\n@@ -403,7 +403,7 @@ int parse_commit_gently(struct commit *item, int quiet_on_missing)\n \t\treturn error(\"Object %s not a commit\",\n \t\t\t     oid_to_hex(&item->object.oid));\n \t}\n-\tret = parse_commit_buffer(item, buffer, size);\n+\tret = parse_commit_buffer(the_repository, item, buffer, size);\n \tif (save_commit_buffer && !ret) {\n \t\tset_commit_buffer(item, buffer, size);\n \t\treturn 0;\ndiff --git a/commit.h b/commit.h\nindex 61e01112eb..20ad5acabc 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -65,7 +65,8 @@ struct commit *lookup_commit_reference_by_name(const char *name);\n  */\n struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref_name);\n \n-int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long size);\n+#define parse_commit_buffer(r, i, b, s) parse_commit_buffer_##r(i, b, s)\n+int parse_commit_buffer_the_repository(struct commit *item, const void *buffer, unsigned long size);\n int parse_commit_gently(struct commit *item, int quiet_on_missing);\n static inline int parse_commit(struct commit *item)\n {\ndiff --git a/contrib/coccinelle/object_parser.cocci b/contrib/coccinelle/object_parser.cocci\nindex c3cc4dfc9e..60f93c30c4 100644\n--- a/contrib/coccinelle/object_parser.cocci\n+++ b/contrib/coccinelle/object_parser.cocci\n@@ -45,6 +45,15 @@ expression E;\n + the_repository,\n  E)\n \n+@@\n+expression E;\n+expression F;\n+expression G;\n+@@\n+ parse_commit_buffer(\n++the_repository,\n+ E, F, G)\n+\n @@\n expression E;\n expression F;\ndiff --git a/object.c b/object.c\nindex 6676887315..f518e5703b 100644\n--- a/object.c\n+++ b/object.c\n@@ -211,7 +211,7 @@ struct object *parse_object_buffer(const struct object_id *oid, enum object_type\n \t} else if (type == OBJ_COMMIT) {\n \t\tstruct commit *commit = lookup_commit(the_repository, oid);\n \t\tif (commit) {\n-\t\t\tif (parse_commit_buffer(commit, buffer, size))\n+\t\t\tif (parse_commit_buffer(the_repository, commit, buffer, size))\n \t\t\t\treturn NULL;\n \t\t\tif (!get_cached_commit_buffer(commit, NULL)) {\n \t\t\t\tset_commit_buffer(commit, buffer, size);\ndiff --git a/sha1_file.c b/sha1_file.c\nindex df8bd4c260..0c2e215ae5 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -1751,7 +1751,7 @@ static void check_commit(const void *buf, size_t size)\n {\n \tstruct commit c;\n \tmemset(&c, 0, sizeof(c));\n-\tif (parse_commit_buffer(&c, buf, size))\n+\tif (parse_commit_buffer(the_repository, &c, buf, size))\n \t\tdie(\"corrupt commit\");\n }\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338362","messageId":"20180205235735.216710-75-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 095/194] object: add repository argument to register_commit_graft","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:56Z","receivedAt":"2018-02-06T00:14:58Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nAdd a repository argument to allow callers of register_commit_graft to\nbe more specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n builtin/blame.c                        | 3 ++-\n commit.c                               | 4 ++--\n commit.h                               | 3 ++-\n contrib/coccinelle/object_parser.cocci | 8 ++++++++\n shallow.c                              | 3 ++-\n 5 files changed, 16 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex 005f55aaa2..815b0c75ed 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -8,6 +8,7 @@\n #include \"cache.h\"\n #include \"config.h\"\n #include \"builtin.h\"\n+#include \"repository.h\"\n #include \"commit.h\"\n #include \"diff.h\"\n #include \"revision.h\"\n@@ -490,7 +491,7 @@ static int read_ancestry(const char *graft_file)\n \t\t/* The format is just \"Commit Parent1 Parent2 ...\\n\" */\n \t\tstruct commit_graft *graft = read_graft_line(&buf);\n \t\tif (graft)\n-\t\t\tregister_commit_graft(graft, 0);\n+\t\t\tregister_commit_graft(the_repository, graft, 0);\n \t}\n \tfclose(fp);\n \tstrbuf_release(&buf);\ndiff --git a/commit.c b/commit.c\nindex f10a882d87..ce18e41e33 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -113,7 +113,7 @@ static int commit_graft_pos_the_repository(const unsigned char *sha1)\n \t\t\tcommit_graft_sha1_access);\n }\n \n-int register_commit_graft(struct commit_graft *graft, int ignore_dups)\n+int register_commit_graft_the_repository(struct commit_graft *graft, int ignore_dups)\n {\n \tint pos = commit_graft_pos(the_repository, graft->oid.hash);\n \n@@ -189,7 +189,7 @@ static int read_graft_file(const char *graft_file)\n \t\tstruct commit_graft *graft = read_graft_line(&buf);\n \t\tif (!graft)\n \t\t\tcontinue;\n-\t\tif (register_commit_graft(graft, 1))\n+\t\tif (register_commit_graft(the_repository, graft, 1))\n \t\t\terror(\"duplicate graft data: %s\", buf.buf);\n \t}\n \tfclose(fp);\ndiff --git a/commit.h b/commit.h\nindex 20ad5acabc..c8c5aafcb1 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -176,7 +176,8 @@ struct commit_graft {\n typedef int (*each_commit_graft_fn)(const struct commit_graft *, void *);\n \n struct commit_graft *read_graft_line(struct strbuf *line);\n-int register_commit_graft(struct commit_graft *, int);\n+#define register_commit_graft(r, g, i) register_commit_graft_##r(g, i)\n+int register_commit_graft_the_repository(struct commit_graft *, int);\n struct commit_graft *lookup_commit_graft(const struct object_id *oid);\n \n extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2);\ndiff --git a/contrib/coccinelle/object_parser.cocci b/contrib/coccinelle/object_parser.cocci\nindex 60f93c30c4..fc56a90934 100644\n--- a/contrib/coccinelle/object_parser.cocci\n+++ b/contrib/coccinelle/object_parser.cocci\n@@ -90,3 +90,11 @@ expression E;\n  lookup_commit(\n +the_repository,\n  E)\n+\n+@@\n+expression E;\n+expression F;\n+@@\n+ register_commit_graft(\n++the_repository,\n+ E, F)\ndiff --git a/shallow.c b/shallow.c\nindex 97c483239a..925db794fd 100644\n--- a/shallow.c\n+++ b/shallow.c\n@@ -1,4 +1,5 @@\n #include \"cache.h\"\n+#include \"repository.h\"\n #include \"tempfile.h\"\n #include \"lockfile.h\"\n #include \"object-store.h\"\n@@ -38,7 +39,7 @@ int register_shallow(const struct object_id *oid)\n \tgraft->nr_parent = -1;\n \tif (commit && commit->object.parsed)\n \t\tcommit->parents = NULL;\n-\treturn register_commit_graft(graft, 0);\n+\treturn register_commit_graft(the_repository, graft, 0);\n }\n \n int is_repository_shallow(void)\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338363","messageId":"20180205235735.216710-76-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 096/194] object: add repository argument to read_graft_file","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:57Z","receivedAt":"2018-02-06T00:15:01Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nAdd a repository argument to allow the caller of read_graft_file to be\nmore specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n commit.c | 5 +++--\n 1 file changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex ce18e41e33..d2c6367f85 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -178,7 +178,8 @@ struct commit_graft *read_graft_line(struct strbuf *line)\n \treturn NULL;\n }\n \n-static int read_graft_file(const char *graft_file)\n+#define read_graft_file(r, f) read_graft_file_##r(f)\n+static int read_graft_file_the_repository(const char *graft_file)\n {\n \tFILE *fp = fopen_or_warn(graft_file, \"r\");\n \tstruct strbuf buf = STRBUF_INIT;\n@@ -205,7 +206,7 @@ static void prepare_commit_graft(void)\n \tif (commit_graft_prepared)\n \t\treturn;\n \tgraft_file = get_graft_file();\n-\tread_graft_file(graft_file);\n+\tread_graft_file(the_repository, graft_file);\n \t/* make sure shallows are read */\n \tis_repository_shallow();\n \tcommit_graft_prepared = 1;\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338364","messageId":"20180205235735.216710-77-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 097/194] object: add repository argument to prepare_commit_graft","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:58Z","receivedAt":"2018-02-06T00:15:25Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nAdd a repository argument to allow the caller of prepare_commit_graft\nto be more specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n commit.c | 5 +++--\n 1 file changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex d2c6367f85..fbe27cf436 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -198,7 +198,8 @@ static int read_graft_file_the_repository(const char *graft_file)\n \treturn 0;\n }\n \n-static void prepare_commit_graft(void)\n+#define prepare_commit_graft(r) prepare_commit_graft_##r()\n+static void prepare_commit_graft_the_repository(void)\n {\n \tstatic int commit_graft_prepared;\n \tchar *graft_file;\n@@ -215,7 +216,7 @@ static void prepare_commit_graft(void)\n struct commit_graft *lookup_commit_graft(const struct object_id *oid)\n {\n \tint pos;\n-\tprepare_commit_graft();\n+\tprepare_commit_graft(the_repository);\n \tpos = commit_graft_pos(the_repository, oid->hash);\n \tif (pos < 0)\n \t\treturn NULL;\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338365","messageId":"20180205235735.216710-78-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-1-sbeller@google.com","subject":"[PATCH 098/194] object: add repository argument to lookup_commit_graft","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-05T23:55:59Z","receivedAt":"2018-02-06T00:15:27Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nAdd a repository argument to allow callers of lookup_commit_graft to\nbe more specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nThe included coccinelle semantic patch will adapt any new callers in\nthe diff produced by `make coccicheck`.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n commit.c                               | 4 ++--\n commit.h                               | 3 ++-\n contrib/coccinelle/object_parser.cocci | 7 +++++++\n fsck.c                                 | 2 +-\n shallow.c                              | 5 +++--\n 5 files changed, 15 insertions(+), 6 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex fbe27cf436..8e42af7565 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -213,7 +213,7 @@ static void prepare_commit_graft_the_repository(void)\n \tcommit_graft_prepared = 1;\n }\n \n-struct commit_graft *lookup_commit_graft(const struct object_id *oid)\n+struct commit_graft *lookup_commit_graft_the_repository(const struct object_id *oid)\n {\n \tint pos;\n \tprepare_commit_graft(the_repository);\n@@ -349,7 +349,7 @@ int parse_commit_buffer_the_repository(struct commit *item, const void *buffer,\n \tbufptr += tree_entry_len + 1; /* \"tree \" + \"hex sha1\" + \"\\n\" */\n \tpptr = &item->parents;\n \n-\tgraft = lookup_commit_graft(&item->object.oid);\n+\tgraft = lookup_commit_graft(the_repository, &item->object.oid);\n \twhile (bufptr + parent_entry_len < tail && !memcmp(bufptr, \"parent \", 7)) {\n \t\tstruct commit *new_parent;\n \ndiff --git a/commit.h b/commit.h\nindex c8c5aafcb1..f791a55379 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -178,7 +178,8 @@ typedef int (*each_commit_graft_fn)(const struct commit_graft *, void *);\n struct commit_graft *read_graft_line(struct strbuf *line);\n #define register_commit_graft(r, g, i) register_commit_graft_##r(g, i)\n int register_commit_graft_the_repository(struct commit_graft *, int);\n-struct commit_graft *lookup_commit_graft(const struct object_id *oid);\n+#define lookup_commit_graft(r, o) lookup_commit_graft_##r(o)\n+struct commit_graft *lookup_commit_graft_the_repository(const struct object_id *oid);\n \n extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2);\n extern struct commit_list *get_merge_bases_many(struct commit *one, int n, struct commit **twos);\ndiff --git a/contrib/coccinelle/object_parser.cocci b/contrib/coccinelle/object_parser.cocci\nindex fc56a90934..987630f70f 100644\n--- a/contrib/coccinelle/object_parser.cocci\n+++ b/contrib/coccinelle/object_parser.cocci\n@@ -98,3 +98,10 @@ expression F;\n  register_commit_graft(\n +the_repository,\n  E, F)\n+\n+@@\n+expression E;\n+@@\n+ lookup_commit_graft(\n++the_repository,\n+ E)\ndiff --git a/fsck.c b/fsck.c\nindex 54943b7dee..af0291121d 100644\n--- a/fsck.c\n+++ b/fsck.c\n@@ -739,7 +739,7 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,\n \t\tbuffer += 41;\n \t\tparent_line_count++;\n \t}\n-\tgraft = lookup_commit_graft(&commit->object.oid);\n+\tgraft = lookup_commit_graft(the_repository, &commit->object.oid);\n \tparent_count = commit_list_count(commit->parents);\n \tif (graft) {\n \t\tif (graft->nr_parent == -1 && !parent_count)\ndiff --git a/shallow.c b/shallow.c\nindex 925db794fd..004f99d4e2 100644\n--- a/shallow.c\n+++ b/shallow.c\n@@ -111,7 +111,7 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth,\n \t\tcur_depth++;\n \t\tif ((depth != INFINITE_DEPTH && cur_depth >= depth) ||\n \t\t    (is_repository_shallow() && !commit->parents &&\n-\t\t     (graft = lookup_commit_graft(&commit->object.oid)) != NULL &&\n+\t\t     (graft = lookup_commit_graft(the_repository, &commit->object.oid)) != NULL &&\n \t\t     graft->nr_parent < 0)) {\n \t\t\tcommit_list_insert(commit, &result);\n \t\t\tcommit->object.flags |= shallow_flag;\n@@ -400,7 +400,8 @@ void prepare_shallow_info(struct shallow_info *info, struct oid_array *sa)\n \tfor (i = 0; i < sa->nr; i++) {\n \t\tif (has_object_file(sa->oid + i)) {\n \t\t\tstruct commit_graft *graft;\n-\t\t\tgraft = lookup_commit_graft(&sa->oid[i]);\n+\t\t\tgraft = lookup_commit_graft(the_repository,\n+\t\t\t\t\t\t    &sa->oid[i]);\n \t\t\tif (graft && graft->nr_parent < 0)\n \t\t\t\tcontinue;\n \t\t\tinfo->ours[info->nr_ours++] = i;\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338366","messageId":"20180206001749.218943-1-sbeller@google.com","threadId":"47765","inReplyTo":"20180205235508.216277-1-sbeller@google.com","subject":"[PATCH 099/194] object: allow grow_object_hash to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:14Z","receivedAt":"2018-02-06T00:18:03Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n object.c | 17 +++++++++--------\n 1 file changed, 9 insertions(+), 8 deletions(-)\n\ndiff --git a/object.c b/object.c\nindex f518e5703b..be5d6c0931 100644\n--- a/object.c\n+++ b/object.c\n@@ -115,27 +115,28 @@ struct object *lookup_object_the_repository(const unsigned char *sha1)\n  * power of 2 (but at least 32).  Copy the existing values to the new\n  * hash map.\n  */\n-#define grow_object_hash(r) grow_object_hash_##r()\n-static void grow_object_hash_the_repository(void)\n+static void grow_object_hash(struct repository *r)\n {\n \tint i;\n \t/*\n \t * Note that this size must always be power-of-2 to match hash_obj\n \t * above.\n \t */\n-\tint new_hash_size = the_repository->parsed_objects.obj_hash_size < 32 ? 32 : 2 * the_repository->parsed_objects.obj_hash_size;\n+\tint new_hash_size = r->parsed_objects.obj_hash_size < 32\n+\t\t\t\t? 32\n+\t\t\t\t: 2 * r->parsed_objects.obj_hash_size;\n \tstruct object **new_hash;\n \n \tnew_hash = xcalloc(new_hash_size, sizeof(struct object *));\n-\tfor (i = 0; i < the_repository->parsed_objects.obj_hash_size; i++) {\n-\t\tstruct object *obj = the_repository->parsed_objects.obj_hash[i];\n+\tfor (i = 0; i < r->parsed_objects.obj_hash_size; i++) {\n+\t\tstruct object *obj = r->parsed_objects.obj_hash[i];\n \t\tif (!obj)\n \t\t\tcontinue;\n \t\tinsert_obj_hash(obj, new_hash, new_hash_size);\n \t}\n-\tfree(the_repository->parsed_objects.obj_hash);\n-\tthe_repository->parsed_objects.obj_hash = new_hash;\n-\tthe_repository->parsed_objects.obj_hash_size = new_hash_size;\n+\tfree(r->parsed_objects.obj_hash);\n+\tr->parsed_objects.obj_hash = new_hash;\n+\tr->parsed_objects.obj_hash_size = new_hash_size;\n }\n \n void *create_object_the_repository(const unsigned char *sha1, void *o)\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338367","messageId":"20180206001749.218943-2-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 100/194] object: allow create_object to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:15Z","receivedAt":"2018-02-06T00:18:06Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n object.c | 12 ++++++------\n object.h |  3 +--\n 2 files changed, 7 insertions(+), 8 deletions(-)\n\ndiff --git a/object.c b/object.c\nindex be5d6c0931..de19d814c1 100644\n--- a/object.c\n+++ b/object.c\n@@ -139,7 +139,7 @@ static void grow_object_hash(struct repository *r)\n \tr->parsed_objects.obj_hash_size = new_hash_size;\n }\n \n-void *create_object_the_repository(const unsigned char *sha1, void *o)\n+void *create_object(struct repository *r, const unsigned char *sha1, void *o)\n {\n \tstruct object *obj = o;\n \n@@ -147,12 +147,12 @@ void *create_object_the_repository(const unsigned char *sha1, void *o)\n \tobj->flags = 0;\n \thashcpy(obj->oid.hash, sha1);\n \n-\tif (the_repository->parsed_objects.obj_hash_size - 1 <= the_repository->parsed_objects.nr_objs * 2)\n-\t\tgrow_object_hash(the_repository);\n+\tif (r->parsed_objects.obj_hash_size - 1 <= r->parsed_objects.nr_objs * 2)\n+\t\tgrow_object_hash(r);\n \n-\tinsert_obj_hash(obj, the_repository->parsed_objects.obj_hash,\n-\t\t\tthe_repository->parsed_objects.obj_hash_size);\n-\tthe_repository->parsed_objects.nr_objs++;\n+\tinsert_obj_hash(obj, r->parsed_objects.obj_hash,\n+\t\t\tr->parsed_objects.obj_hash_size);\n+\tr->parsed_objects.nr_objs++;\n \treturn obj;\n }\n \ndiff --git a/object.h b/object.h\nindex b667404f88..699adcf161 100644\n--- a/object.h\n+++ b/object.h\n@@ -105,8 +105,7 @@ extern struct object *get_indexed_object(unsigned int);\n #define lookup_object(r, s) lookup_object_##r(s)\n struct object *lookup_object_the_repository(const unsigned char *sha1);\n \n-#define create_object(r, s, o) create_object_##r(s, o)\n-extern void *create_object_the_repository(const unsigned char *sha1, void *obj);\n+extern void *create_object(struct repository *r, const unsigned char *sha1, void *obj);\n \n void *object_as_type(struct object *obj, enum object_type type, int quiet);\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338368","messageId":"20180206001749.218943-3-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 101/194] object: allow lookup_object to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:16Z","receivedAt":"2018-02-06T00:18:08Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n object.c | 15 +++++++--------\n object.h |  3 +--\n 2 files changed, 8 insertions(+), 10 deletions(-)\n\ndiff --git a/object.c b/object.c\nindex de19d814c1..7cac87aa22 100644\n--- a/object.c\n+++ b/object.c\n@@ -81,21 +81,20 @@ static void insert_obj_hash(struct object *obj, struct object **hash, unsigned i\n  * Look up the record for the given sha1 in the hash map stored in\n  * obj_hash.  Return NULL if it was not found.\n  */\n-struct object *lookup_object_the_repository(const unsigned char *sha1)\n+struct object *lookup_object(struct repository *r, const unsigned char *sha1)\n {\n \tunsigned int i, first;\n \tstruct object *obj;\n \n-\tif (!the_repository->parsed_objects.obj_hash)\n+\tif (!r->parsed_objects.obj_hash)\n \t\treturn NULL;\n \n-\tfirst = i = hash_obj(sha1,\n-\t\t\t     the_repository->parsed_objects.obj_hash_size);\n-\twhile ((obj = the_repository->parsed_objects.obj_hash[i]) != NULL) {\n+\tfirst = i = hash_obj(sha1, r->parsed_objects.obj_hash_size);\n+\twhile ((obj = r->parsed_objects.obj_hash[i]) != NULL) {\n \t\tif (!hashcmp(sha1, obj->oid.hash))\n \t\t\tbreak;\n \t\ti++;\n-\t\tif (i == the_repository->parsed_objects.obj_hash_size)\n+\t\tif (i == r->parsed_objects.obj_hash_size)\n \t\t\ti = 0;\n \t}\n \tif (obj && i != first) {\n@@ -104,8 +103,8 @@ struct object *lookup_object_the_repository(const unsigned char *sha1)\n \t\t * that we do not need to walk the hash table the next\n \t\t * time we look for it.\n \t\t */\n-\t\tSWAP(the_repository->parsed_objects.obj_hash[i],\n-\t\t     the_repository->parsed_objects.obj_hash[first]);\n+\t\tSWAP(r->parsed_objects.obj_hash[i],\n+\t\t     r->parsed_objects.obj_hash[first]);\n \t}\n \treturn obj;\n }\ndiff --git a/object.h b/object.h\nindex 699adcf161..d59edc88af 100644\n--- a/object.h\n+++ b/object.h\n@@ -102,8 +102,7 @@ extern struct object *get_indexed_object(unsigned int);\n  * half-initialised objects, the caller is expected to initialize them\n  * by calling parse_object() on them.\n  */\n-#define lookup_object(r, s) lookup_object_##r(s)\n-struct object *lookup_object_the_repository(const unsigned char *sha1);\n+struct object *lookup_object(struct repository *r, const unsigned char *sha1);\n \n extern void *create_object(struct repository *r, const unsigned char *sha1, void *obj);\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338369","messageId":"20180206001749.218943-4-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 102/194] object: add repository argument to lookup_unknown_object","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:17Z","receivedAt":"2018-02-06T00:18:32Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nAdd a repository argument to allow callers of lookup_unknown_object to\nbe more specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nThe included coccinelle semantic patch will adapt any new callers in\nthe diff produced by `make coccicheck`.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n builtin/fsck.c                         | 2 +-\n builtin/pack-objects.c                 | 2 +-\n contrib/coccinelle/object_parser.cocci | 7 +++++++\n http-push.c                            | 2 +-\n object.c                               | 2 +-\n object.h                               | 3 ++-\n refs.c                                 | 2 +-\n t/helper/test-example-decorate.c       | 6 +++---\n upload-pack.c                          | 2 +-\n walker.c                               | 2 +-\n 10 files changed, 19 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex 79da01d338..78cd8cdc69 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -615,7 +615,7 @@ static int fsck_cache_tree(struct cache_tree *it)\n \n static void mark_object_for_connectivity(const struct object_id *oid)\n {\n-\tstruct object *obj = lookup_unknown_object(oid->hash);\n+\tstruct object *obj = lookup_unknown_object(the_repository, oid->hash);\n \tobj->flags |= HAS_OBJ;\n }\n \ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex 6348a5e721..fae579f12a 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -2672,7 +2672,7 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs)\n \n \t\tfor (i = 0; i < p->num_objects; i++) {\n \t\t\tnth_packed_object_oid(&oid, p, i);\n-\t\t\to = lookup_unknown_object(oid.hash);\n+\t\t\to = lookup_unknown_object(the_repository, oid.hash);\n \t\t\tif (!(o->flags & OBJECT_ADDED))\n \t\t\t\tmark_in_pack_object(o, p, &in_pack);\n \t\t\to->flags |= OBJECT_ADDED;\ndiff --git a/contrib/coccinelle/object_parser.cocci b/contrib/coccinelle/object_parser.cocci\nindex 987630f70f..43a312480f 100644\n--- a/contrib/coccinelle/object_parser.cocci\n+++ b/contrib/coccinelle/object_parser.cocci\n@@ -105,3 +105,10 @@ expression E;\n  lookup_commit_graft(\n +the_repository,\n  E)\n+\n+@@\n+expression E;\n+@@\n+ lookup_unknown_object(\n++the_repository,\n+ E)\ndiff --git a/http-push.c b/http-push.c\nindex de5e70ea7b..7cefc2df76 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -1427,7 +1427,7 @@ static void one_remote_ref(const char *refname)\n \t * may be required for updating server info later.\n \t */\n \tif (repo->can_update_info_refs && !has_object_file(&ref->old_oid)) {\n-\t\tobj = lookup_unknown_object(ref->old_oid.hash);\n+\t\tobj = lookup_unknown_object(the_repository, ref->old_oid.hash);\n \t\tfprintf(stderr,\t\"  fetch %s for %s\\n\",\n \t\t\toid_to_hex(&ref->old_oid), refname);\n \t\tadd_fetch_request(obj);\ndiff --git a/object.c b/object.c\nindex 7cac87aa22..3eb12bec49 100644\n--- a/object.c\n+++ b/object.c\n@@ -174,7 +174,7 @@ void *object_as_type(struct object *obj, enum object_type type, int quiet)\n \t}\n }\n \n-struct object *lookup_unknown_object(const unsigned char *sha1)\n+struct object *lookup_unknown_object_the_repository(const unsigned char *sha1)\n {\n \tstruct object *obj = lookup_object(the_repository, sha1);\n \tif (!obj)\ndiff --git a/object.h b/object.h\nindex d59edc88af..083111d7b7 100644\n--- a/object.h\n+++ b/object.h\n@@ -130,7 +130,8 @@ struct object *parse_object_or_die(const struct object_id *oid, const char *name\n struct object *parse_object_buffer(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p);\n \n /** Returns the object, with potentially excess memory allocated. **/\n-struct object *lookup_unknown_object(const unsigned  char *sha1);\n+#define lookup_unknown_object(r, s) lookup_unknown_object_##r(s)\n+struct object *lookup_unknown_object_the_repository(const unsigned char *sha1);\n \n struct object_list *object_list_insert(struct object *item,\n \t\t\t\t       struct object_list **list_p);\ndiff --git a/refs.c b/refs.c\nindex ddcb4a908f..0ea9b05d03 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -300,7 +300,7 @@ static int filter_refs(const char *refname, const struct object_id *oid,\n \n enum peel_status peel_object(const struct object_id *name, struct object_id *oid)\n {\n-\tstruct object *o = lookup_unknown_object(name->hash);\n+\tstruct object *o = lookup_unknown_object(the_repository, name->hash);\n \n \tif (o->type == OBJ_NONE) {\n \t\tint type = sha1_object_info(the_repository, name->hash, NULL);\ndiff --git a/t/helper/test-example-decorate.c b/t/helper/test-example-decorate.c\nindex 90dc97a9d0..156b72733e 100644\n--- a/t/helper/test-example-decorate.c\n+++ b/t/helper/test-example-decorate.c\n@@ -25,8 +25,8 @@ int cmd_main(int argc, const char **argv)\n \t * Add 2 objects, one with a non-NULL decoration and one with a NULL\n \t * decoration.\n \t */\n-\tone = lookup_unknown_object(one_oid.hash);\n-\ttwo = lookup_unknown_object(two_oid.hash);\n+\tone = lookup_unknown_object(the_repository, one_oid.hash);\n+\ttwo = lookup_unknown_object(the_repository, two_oid.hash);\n \tret = add_decoration(&n, one, &decoration_a);\n \tif (ret)\n \t\tdie(\"BUG: when adding a brand-new object, NULL should be returned\");\n@@ -55,7 +55,7 @@ int cmd_main(int argc, const char **argv)\n \tret = lookup_decoration(&n, two);\n \tif (ret != &decoration_b)\n \t\tdie(\"BUG: lookup should return added declaration\");\n-\tthree = lookup_unknown_object(three_oid.hash);\n+\tthree = lookup_unknown_object(the_repository, three_oid.hash);\n \tret = lookup_decoration(&n, three);\n \tif (ret)\n \t\tdie(\"BUG: lookup for unknown object should return NULL\");\ndiff --git a/upload-pack.c b/upload-pack.c\nindex 469a843669..9c003553f8 100644\n--- a/upload-pack.c\n+++ b/upload-pack.c\n@@ -898,7 +898,7 @@ static void receive_needs(void)\n static int mark_our_ref(const char *refname, const char *refname_full,\n \t\t\tconst struct object_id *oid)\n {\n-\tstruct object *o = lookup_unknown_object(oid->hash);\n+\tstruct object *o = lookup_unknown_object(the_repository, oid->hash);\n \n \tif (ref_is_hidden(refname, refname_full)) {\n \t\to->flags |= HIDDEN_REF;\ndiff --git a/walker.c b/walker.c\nindex 2b6bd9da81..b96e00a8f1 100644\n--- a/walker.c\n+++ b/walker.c\n@@ -288,7 +288,7 @@ int walker_fetch(struct walker *walker, int targets, char **target,\n \t\t\terror(\"Could not interpret response from server '%s' as something to pull\", target[i]);\n \t\t\tgoto done;\n \t\t}\n-\t\tif (process(walker, lookup_unknown_object(oids[i].hash)))\n+\t\tif (process(walker, lookup_unknown_object(the_repository, oids[i].hash)))\n \t\t\tgoto done;\n \t}\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338370","messageId":"20180206001749.218943-5-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 103/194] object: allow lookup_unknown_object to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:18Z","receivedAt":"2018-02-06T00:18:34Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n object.c | 7 ++++---\n object.h | 3 +--\n 2 files changed, 5 insertions(+), 5 deletions(-)\n\ndiff --git a/object.c b/object.c\nindex 3eb12bec49..9edddbe1d4 100644\n--- a/object.c\n+++ b/object.c\n@@ -174,11 +174,12 @@ void *object_as_type(struct object *obj, enum object_type type, int quiet)\n \t}\n }\n \n-struct object *lookup_unknown_object_the_repository(const unsigned char *sha1)\n+struct object *lookup_unknown_object(struct repository *r,\n+\t\t\t\t     const unsigned char *sha1)\n {\n-\tstruct object *obj = lookup_object(the_repository, sha1);\n+\tstruct object *obj = lookup_object(r, sha1);\n \tif (!obj)\n-\t\tobj = create_object(the_repository, sha1,\n+\t\tobj = create_object(r, sha1,\n \t\t\t\t    alloc_object_node());\n \treturn obj;\n }\ndiff --git a/object.h b/object.h\nindex 083111d7b7..dd009a03ec 100644\n--- a/object.h\n+++ b/object.h\n@@ -130,8 +130,7 @@ struct object *parse_object_or_die(const struct object_id *oid, const char *name\n struct object *parse_object_buffer(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p);\n \n /** Returns the object, with potentially excess memory allocated. **/\n-#define lookup_unknown_object(r, s) lookup_unknown_object_##r(s)\n-struct object *lookup_unknown_object_the_repository(const unsigned char *sha1);\n+struct object *lookup_unknown_object(struct repository *r, const unsigned char *sha1);\n \n struct object_list *object_list_insert(struct object *item,\n \t\t\t\t       struct object_list **list_p);\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338371","messageId":"20180206001749.218943-6-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 104/194] object: add repository argument to parse_object_buffer","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:19Z","receivedAt":"2018-02-06T00:18:37Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow the callers of parse_object_buffer\nto be more specific about which repository to act on. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nAdd the cocci patch that converted the callers.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n builtin/fast-export.c                  |  3 ++-\n builtin/fsck.c                         |  6 ++++--\n builtin/index-pack.c                   |  3 ++-\n builtin/unpack-objects.c               |  3 ++-\n contrib/coccinelle/object_parser.cocci | 11 +++++++++++\n object.c                               |  5 +++--\n object.h                               |  3 ++-\n ref-filter.c                           |  3 ++-\n 8 files changed, 28 insertions(+), 9 deletions(-)\n\ndiff --git a/builtin/fast-export.c b/builtin/fast-export.c\nindex 322adfd408..b0f229351d 100644\n--- a/builtin/fast-export.c\n+++ b/builtin/fast-export.c\n@@ -244,7 +244,8 @@ static void export_blob(const struct object_id *oid)\n \t\t\tdie (\"Could not read blob %s\", oid_to_hex(oid));\n \t\tif (check_sha1_signature(oid->hash, buf, size, typename(type)) < 0)\n \t\t\tdie(\"sha1 mismatch in blob %s\", oid_to_hex(oid));\n-\t\tobject = parse_object_buffer(oid, type, size, buf, &eaten);\n+\t\tobject = parse_object_buffer(the_repository, oid, type,\n+\t\t\t\t\t     size, buf, &eaten);\n \t}\n \n \tif (!object)\ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex 78cd8cdc69..527c03eb39 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -377,7 +377,8 @@ static int fsck_obj_buffer(const struct object_id *oid, enum object_type type,\n \t * verify_packfile(), data_valid variable for details.\n \t */\n \tstruct object *obj;\n-\tobj = parse_object_buffer(oid, type, size, buffer, eaten);\n+\tobj = parse_object_buffer(the_repository, oid, type, size, buffer,\n+\t\t\t\t  eaten);\n \tif (!obj) {\n \t\terrors_found |= ERROR_OBJECT;\n \t\treturn error(\"%s: object corrupt or missing\", oid_to_hex(oid));\n@@ -499,7 +500,8 @@ static struct object *parse_loose_object(const struct object_id *oid,\n \tif (!contents && type != OBJ_BLOB)\n \t\tdie(\"BUG: read_loose_object streamed a non-blob\");\n \n-\tobj = parse_object_buffer(oid, type, size, contents, &eaten);\n+\tobj = parse_object_buffer(the_repository, oid, type, size,\n+\t\t\t\t  contents, &eaten);\n \n \tif (!eaten)\n \t\tfree(contents);\ndiff --git a/builtin/index-pack.c b/builtin/index-pack.c\nindex 67db12fc43..f570e16bb6 100644\n--- a/builtin/index-pack.c\n+++ b/builtin/index-pack.c\n@@ -850,7 +850,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,\n \t\t\t * we do not need to free the memory here, as the\n \t\t\t * buf is deleted by the caller.\n \t\t\t */\n-\t\t\tobj = parse_object_buffer(oid, type, size, buf,\n+\t\t\tobj = parse_object_buffer(the_repository, oid, type,\n+\t\t\t\t\t\t  size, buf,\n \t\t\t\t\t\t  &eaten);\n \t\t\tif (!obj)\n \t\t\t\tdie(_(\"invalid %s\"), typename(type));\ndiff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c\nindex 8d13c5145c..6b8fb918b6 100644\n--- a/builtin/unpack-objects.c\n+++ b/builtin/unpack-objects.c\n@@ -263,7 +263,8 @@ static void write_object(unsigned nr, enum object_type type,\n \t\tint eaten;\n \t\thash_sha1_file(buf, size, typename(type), obj_list[nr].oid.hash);\n \t\tadded_object(nr, type, buf, size);\n-\t\tobj = parse_object_buffer(&obj_list[nr].oid, type, size, buf,\n+\t\tobj = parse_object_buffer(the_repository, &obj_list[nr].oid,\n+\t\t\t\t\t  type, size, buf,\n \t\t\t\t\t  &eaten);\n \t\tif (!obj)\n \t\t\tdie(\"invalid %s\", typename(type));\ndiff --git a/contrib/coccinelle/object_parser.cocci b/contrib/coccinelle/object_parser.cocci\nindex 43a312480f..c2886c5e50 100644\n--- a/contrib/coccinelle/object_parser.cocci\n+++ b/contrib/coccinelle/object_parser.cocci\n@@ -45,6 +45,17 @@ expression E;\n + the_repository,\n  E)\n \n+@@\n+expression E;\n+expression F;\n+expression G;\n+expression H;\n+expression I;\n+@@\n+parse_object_buffer(\n++ the_repository,\n+ E, F, G, H, I)\n+\n @@\n expression E;\n expression F;\ndiff --git a/object.c b/object.c\nindex 9edddbe1d4..a10983755c 100644\n--- a/object.c\n+++ b/object.c\n@@ -184,7 +184,7 @@ struct object *lookup_unknown_object(struct repository *r,\n \treturn obj;\n }\n \n-struct object *parse_object_buffer(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p)\n+struct object *parse_object_buffer_the_repository(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p)\n {\n \tstruct object *obj;\n \t*eaten_p = 0;\n@@ -276,7 +276,8 @@ struct object *parse_object_the_repository(const struct object_id *oid)\n \t\t\treturn NULL;\n \t\t}\n \n-\t\tobj = parse_object_buffer(oid, type, size, buffer, &eaten);\n+\t\tobj = parse_object_buffer(the_repository, oid, type, size,\n+\t\t\t\t\t  buffer, &eaten);\n \t\tif (!eaten)\n \t\t\tfree(buffer);\n \t\treturn obj;\ndiff --git a/object.h b/object.h\nindex dd009a03ec..c9ea2285e8 100644\n--- a/object.h\n+++ b/object.h\n@@ -127,7 +127,8 @@ struct object *parse_object_or_die(const struct object_id *oid, const char *name\n  * parsing it.  eaten_p indicates if the object has a borrowed copy\n  * of buffer and the caller should not free() it.\n  */\n-struct object *parse_object_buffer(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p);\n+#define parse_object_buffer(r, o, t, s, b, e) parse_object_buffer_##r(o, t, s, b, e)\n+struct object *parse_object_buffer_the_repository(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p);\n \n /** Returns the object, with potentially excess memory allocated. **/\n struct object *lookup_unknown_object(struct repository *r, const unsigned char *sha1);\ndiff --git a/ref-filter.c b/ref-filter.c\nindex b4b6f8801c..256887b585 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -733,7 +733,8 @@ static void *get_obj(const struct object_id *oid, struct object **obj, unsigned\n \tvoid *buf = read_sha1_file(oid->hash, &type, sz);\n \n \tif (buf)\n-\t\t*obj = parse_object_buffer(oid, type, *sz, buf, eaten);\n+\t\t*obj = parse_object_buffer(the_repository, oid, type, *sz,\n+\t\t\t\t\t   buf, eaten);\n \telse\n \t\t*obj = NULL;\n \treturn buf;\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338372","messageId":"20180206001749.218943-7-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 105/194] repository: keep track of all open repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:20Z","receivedAt":"2018-02-06T00:19:01Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"When Git mmap's packfiles into memory it has to keep track of the\nmemory management itself to not use too much memory. Each repository\nhas its own set of packfiles that it keeps track of. To scan all the\npackfiles that are currently mmap'ed, we need to keep track of all\nrepositories that are currently opened.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n builtin/grep.c     |  2 +-\n builtin/ls-files.c |  2 +-\n packfile.c         |  9 ++++++--\n repository.c       | 66 +++++++++++++++++++++++++++++++++++++-----------------\n repository.h       |  6 ++++-\n submodule.c        |  2 +-\n 6 files changed, 61 insertions(+), 26 deletions(-)\n\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex 2c43307f02..a9a908d92a 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -465,7 +465,7 @@ static int grep_submodule(struct grep_opt *opt, struct repository *superproject,\n \t\thit = grep_cache(opt, &submodule, pathspec, 1);\n \t}\n \n-\trepo_clear(&submodule);\n+\trepo_free(&submodule);\n \treturn hit;\n }\n \ndiff --git a/builtin/ls-files.c b/builtin/ls-files.c\nindex 2fc836e330..a6d824a2ba 100644\n--- a/builtin/ls-files.c\n+++ b/builtin/ls-files.c\n@@ -215,7 +215,7 @@ static void show_submodule(struct repository *superproject,\n \n \tshow_files(&submodule, dir);\n \n-\trepo_clear(&submodule);\n+\trepo_free(&submodule);\n }\n \n static void show_ce(struct repository *repo, struct dir_struct *dir,\ndiff --git a/packfile.c b/packfile.c\nindex 6a8d5edf6d..f7e8a81ded 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -237,13 +237,18 @@ static void scan_windows(struct packed_git *p,\n \n static int unuse_one_window(struct packed_git *current)\n {\n+\tint i = 0;\n \tstruct packed_git *p, *lru_p = NULL;\n \tstruct pack_window *lru_w = NULL, *lru_l = NULL;\n \n \tif (current)\n \t\tscan_windows(current, &lru_p, &lru_w, &lru_l);\n-\tfor (p = the_repository->objects.packed_git; p; p = p->next)\n-\t\tscan_windows(p, &lru_p, &lru_w, &lru_l);\n+\tfor (i = -1; i < open_repos_nr; i++) {\n+\t\tstruct repository *r = i == -1 ? the_repository : open_repos[i];\n+\t\tfor (p = r->objects.packed_git; p; p = p->next)\n+\t\t\tscan_windows(p, &lru_p, &lru_w, &lru_l);\n+\t}\n+\n \tif (lru_p) {\n \t\tmunmap(lru_w->base, lru_w->len);\n \t\tpack_mapped -= lru_w->len;\ndiff --git a/repository.c b/repository.c\nindex af62dfdc09..361e503824 100644\n--- a/repository.c\n+++ b/repository.c\n@@ -126,6 +126,36 @@ static int read_and_verify_repository_format(struct repository_format *format,\n \treturn ret;\n }\n \n+struct repository **open_repos;\n+int open_repos_nr;\n+static int open_repos_alloc;\n+\n+static void repo_clear(struct repository *repo)\n+{\n+\tFREE_AND_NULL(repo->gitdir);\n+\tFREE_AND_NULL(repo->commondir);\n+\tFREE_AND_NULL(repo->objectdir);\n+\tFREE_AND_NULL(repo->graft_file);\n+\tFREE_AND_NULL(repo->index_file);\n+\tFREE_AND_NULL(repo->worktree);\n+\tFREE_AND_NULL(repo->submodule_prefix);\n+\n+\tif (repo->config) {\n+\t\tgit_configset_clear(repo->config);\n+\t\tFREE_AND_NULL(repo->config);\n+\t}\n+\n+\tif (repo->submodule_cache) {\n+\t\tsubmodule_cache_free(repo->submodule_cache);\n+\t\trepo->submodule_cache = NULL;\n+\t}\n+\n+\tif (repo->index) {\n+\t\tdiscard_index(repo->index);\n+\t\tFREE_AND_NULL(repo->index);\n+\t}\n+}\n+\n /*\n  * Initialize 'repo' based on the provided 'gitdir'.\n  * Return 0 upon success and a non-zero value upon failure.\n@@ -148,6 +178,9 @@ int repo_init(struct repository *repo, const char *gitdir, const char *worktree)\n \tif (worktree)\n \t\trepo_set_worktree(repo, worktree);\n \n+\tALLOC_GROW(open_repos, open_repos_nr + 1, open_repos_alloc);\n+\topen_repos[open_repos_nr++] = repo;\n+\n \treturn 0;\n \n error:\n@@ -207,30 +240,23 @@ int repo_submodule_init(struct repository *submodule,\n \treturn ret;\n }\n \n-void repo_clear(struct repository *repo)\n+void repo_free(struct repository *repo)\n {\n-\tFREE_AND_NULL(repo->gitdir);\n-\tFREE_AND_NULL(repo->commondir);\n-\tFREE_AND_NULL(repo->objectdir);\n-\tFREE_AND_NULL(repo->graft_file);\n-\tFREE_AND_NULL(repo->index_file);\n-\tFREE_AND_NULL(repo->worktree);\n-\tFREE_AND_NULL(repo->submodule_prefix);\n-\n-\tif (repo->config) {\n-\t\tgit_configset_clear(repo->config);\n-\t\tFREE_AND_NULL(repo->config);\n+\tint i;\n+\tfor (i = 0; i < open_repos_nr; i++) {\n+\t\tif (open_repos[i] != repo)\n+\t\t\tcontinue;\n+\t\tMOVE_ARRAY(open_repos + i,\n+\t\t\t   open_repos + i + 1,\n+\t\t\t   open_repos_nr - i - 1);\n+\t\tbreak;\n \t}\n \n-\tif (repo->submodule_cache) {\n-\t\tsubmodule_cache_free(repo->submodule_cache);\n-\t\trepo->submodule_cache = NULL;\n-\t}\n+\tif (i == open_repos_nr)\n+\t\tBUG(\"free'ing non-open repo?\");\n \n-\tif (repo->index) {\n-\t\tdiscard_index(repo->index);\n-\t\tFREE_AND_NULL(repo->index);\n-\t}\n+\topen_repos_nr--;\n+\trepo_clear(repo);\n }\n \n int repo_read_index(struct repository *repo)\ndiff --git a/repository.h b/repository.h\nindex c8a34d1ac9..74b2b27986 100644\n--- a/repository.h\n+++ b/repository.h\n@@ -110,6 +110,10 @@ struct repository {\n \n extern struct repository *the_repository;\n \n+/* Any open repo except the_repository */\n+extern struct repository **open_repos;\n+extern int open_repos_nr;\n+\n extern void repo_set_gitdir(struct repository *repo, const char *path);\n extern void repo_set_worktree(struct repository *repo, const char *path);\n extern void repo_set_hash_algo(struct repository *repo, int algo);\n@@ -117,7 +121,7 @@ extern int repo_init(struct repository *repo, const char *gitdir, const char *wo\n extern int repo_submodule_init(struct repository *submodule,\n \t\t\t       struct repository *superproject,\n \t\t\t       const char *path);\n-extern void repo_clear(struct repository *repo);\n+extern void repo_free(struct repository *repo);\n \n /*\n  * Populates the repository's index from its index_file, an index struct will\ndiff --git a/submodule.c b/submodule.c\nindex aec62e6c7d..9c4c01ba73 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -898,7 +898,7 @@ static int submodule_has_commits(const char *path, struct oid_array *commits)\n \t\tstrbuf_release(&out);\n \t}\n \n-\trepo_clear(&sub);\n+\trepo_free(&sub);\n \treturn has_commit.result;\n }\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338373","messageId":"20180206001749.218943-8-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 106/194] Rename sha1_object_info.cocci to object_store.cocci","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:21Z","receivedAt":"2018-02-06T00:19:03Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n contrib/coccinelle/{sha1_object_info.cocci => object_store.cocci} | 0\n 1 file changed, 0 insertions(+), 0 deletions(-)\n rename contrib/coccinelle/{sha1_object_info.cocci => object_store.cocci} (100%)\n\ndiff --git a/contrib/coccinelle/sha1_object_info.cocci b/contrib/coccinelle/object_store.cocci\nsimilarity index 100%\nrename from contrib/coccinelle/sha1_object_info.cocci\nrename to contrib/coccinelle/object_store.cocci\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338374","messageId":"20180206001749.218943-9-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 107/194] alternates: add repository argument to add_to_alternates_file","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:22Z","receivedAt":"2018-02-06T00:19:06Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow callers of add_to_alternates_file\nto be more specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n alternates.h    | 3 ++-\n builtin/clone.c | 9 +++++----\n sha1_file.c     | 2 +-\n 3 files changed, 8 insertions(+), 6 deletions(-)\n\ndiff --git a/alternates.h b/alternates.h\nindex df5dc67e2e..2d06b71e50 100644\n--- a/alternates.h\n+++ b/alternates.h\n@@ -48,7 +48,8 @@ struct alternate_object_database *alloc_alt_odb(const char *dir);\n  * Add the directory to the on-disk alternates file; the new entry will also\n  * take effect in the current process.\n  */\n-extern void add_to_alternates_file(const char *dir);\n+#define add_to_alternates_file(r, d) add_to_alternates_file_##r(d)\n+extern void add_to_alternates_file_the_repository(const char *dir);\n \n /*\n  * Add the directory to the in-memory list of alternates (along with any\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex 6efe189846..548255f955 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -11,6 +11,7 @@\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"lockfile.h\"\n+#include \"repository.h\"\n #include \"alternates.h\"\n #include \"parse-options.h\"\n #include \"fetch-pack.h\"\n@@ -330,7 +331,7 @@ static int add_one_reference(struct string_list_item *item, void *cb_data)\n \t} else {\n \t\tstruct strbuf sb = STRBUF_INIT;\n \t\tstrbuf_addf(&sb, \"%s/objects\", ref_git);\n-\t\tadd_to_alternates_file(sb.buf);\n+\t\tadd_to_alternates_file(the_repository, sb.buf);\n \t\tstrbuf_release(&sb);\n \t}\n \n@@ -372,12 +373,12 @@ static void copy_alternates(struct strbuf *src, struct strbuf *dst,\n \t\tif (!line.len || line.buf[0] == '#')\n \t\t\tcontinue;\n \t\tif (is_absolute_path(line.buf)) {\n-\t\t\tadd_to_alternates_file(line.buf);\n+\t\t\tadd_to_alternates_file(the_repository, line.buf);\n \t\t\tcontinue;\n \t\t}\n \t\tabs_path = mkpathdup(\"%s/objects/%s\", src_repo, line.buf);\n \t\tif (!normalize_path_copy(abs_path, abs_path))\n-\t\t\tadd_to_alternates_file(abs_path);\n+\t\t\tadd_to_alternates_file(the_repository, abs_path);\n \t\telse\n \t\t\twarning(\"skipping invalid relative alternate: %s/%s\",\n \t\t\t\tsrc_repo, line.buf);\n@@ -456,7 +457,7 @@ static void clone_local(const char *src_repo, const char *dest_repo)\n \t\tstruct strbuf alt = STRBUF_INIT;\n \t\tget_common_dir(&alt, src_repo);\n \t\tstrbuf_addstr(&alt, \"/objects\");\n-\t\tadd_to_alternates_file(alt.buf);\n+\t\tadd_to_alternates_file(the_repository, alt.buf);\n \t\tstrbuf_release(&alt);\n \t} else {\n \t\tstruct strbuf src = STRBUF_INIT;\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 0c2e215ae5..066aa187a1 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -538,7 +538,7 @@ struct alternate_object_database *alloc_alt_odb(const char *dir)\n \treturn ent;\n }\n \n-void add_to_alternates_file(const char *reference)\n+void add_to_alternates_file_the_repository(const char *reference)\n {\n \tstruct lock_file lock = LOCK_INIT;\n \tchar *alts = git_pathdup(\"objects/info/alternates\");\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338375","messageId":"20180206001749.218943-10-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 108/194] alternates: add repository argument to add_to_alternates_memory","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:23Z","receivedAt":"2018-02-06T00:19:30Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nAdd a repository argument to allow callers of add_to_alternates_memory\nto be more specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n alternates.h              | 3 ++-\n builtin/grep.c            | 2 +-\n sha1_file.c               | 2 +-\n submodule.c               | 2 +-\n t/helper/test-ref-store.c | 2 +-\n tmp-objdir.c              | 2 +-\n 6 files changed, 7 insertions(+), 6 deletions(-)\n\ndiff --git a/alternates.h b/alternates.h\nindex 2d06b71e50..e4520ae5c7 100644\n--- a/alternates.h\n+++ b/alternates.h\n@@ -56,7 +56,8 @@ extern void add_to_alternates_file_the_repository(const char *dir);\n  * recursive alternates it points to), but do not modify the on-disk alternates\n  * file.\n  */\n-extern void add_to_alternates_memory(const char *dir);\n+#define add_to_alternates_memory(r, d) add_to_alternates_memory_##r(d)\n+extern void add_to_alternates_memory_the_repository(const char *dir);\n \n /*\n  * Returns a scratch strbuf pre-filled with the alternate object directory,\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex a9a908d92a..a83e87a676 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -433,7 +433,7 @@ static int grep_submodule(struct grep_opt *opt, struct repository *superproject,\n \t * object.\n \t */\n \tgrep_read_lock();\n-\tadd_to_alternates_memory(submodule.objectdir);\n+\tadd_to_alternates_memory(the_repository, submodule.objectdir);\n \tgrep_read_unlock();\n \n \tif (oid) {\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 066aa187a1..aa564e3ad4 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -581,7 +581,7 @@ void add_to_alternates_file_the_repository(const char *reference)\n \tfree(alts);\n }\n \n-void add_to_alternates_memory(const char *reference)\n+void add_to_alternates_memory_the_repository(const char *reference)\n {\n \t/*\n \t * Make sure alternates are initialized, or else our entry may be\ndiff --git a/submodule.c b/submodule.c\nindex 9c4c01ba73..f9426beff1 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -165,7 +165,7 @@ static int add_submodule_odb(const char *path)\n \t\tret = -1;\n \t\tgoto done;\n \t}\n-\tadd_to_alternates_memory(objects_directory.buf);\n+\tadd_to_alternates_memory(the_repository, objects_directory.buf);\n done:\n \tstrbuf_release(&objects_directory);\n \treturn ret;\ndiff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c\nindex 93ea6f781e..8442ee8146 100644\n--- a/t/helper/test-ref-store.c\n+++ b/t/helper/test-ref-store.c\n@@ -31,7 +31,7 @@ static const char **get_store(const char **argv, struct ref_store **refs)\n \t\tret = strbuf_git_path_submodule(&sb, gitdir, \"objects/\");\n \t\tif (ret)\n \t\t\tdie(\"strbuf_git_path_submodule failed: %d\", ret);\n-\t\tadd_to_alternates_memory(sb.buf);\n+\t\tadd_to_alternates_memory(the_repository, sb.buf);\n \t\tstrbuf_release(&sb);\n \n \t\t*refs = get_submodule_ref_store(gitdir);\ndiff --git a/tmp-objdir.c b/tmp-objdir.c\nindex bf34315adf..a9334d3fc5 100644\n--- a/tmp-objdir.c\n+++ b/tmp-objdir.c\n@@ -288,5 +288,5 @@ const char **tmp_objdir_env(const struct tmp_objdir *t)\n \n void tmp_objdir_add_as_alternate(const struct tmp_objdir *t)\n {\n-\tadd_to_alternates_memory(t->path.buf);\n+\tadd_to_alternates_memory(the_repository, t->path.buf);\n }\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338376","messageId":"20180206001749.218943-11-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 109/194] object-store: move check_sha1_signature to object-store.h","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:24Z","receivedAt":"2018-02-06T00:19:32Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nWhen map == NULL, check_sha1_signature reads the object from the\nobject store to hash it.  Move the declaration of this function to\nobject-store.h to make it easier to find.\n\nWhile at it, clarify the comment describing its API.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n cache.h        | 2 --\n object-store.h | 9 +++++++++\n sha1_file.c    | 6 ------\n 3 files changed, 9 insertions(+), 8 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 634172cec4..15ba480ac3 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1195,8 +1195,6 @@ extern int git_open_cloexec(const char *name, int flags);\n extern int unpack_sha1_header(git_zstream *stream, unsigned char *map, unsigned long mapsize, void *buffer, unsigned long bufsiz);\n extern int parse_sha1_header(const char *hdr, unsigned long *sizep);\n \n-extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned long size, const char *type);\n-\n extern int finalize_object_file(const char *tmpfile, const char *filename);\n \n /* Helper to check and \"touch\" a file */\ndiff --git a/object-store.h b/object-store.h\nindex d009f952f8..a0e9824406 100644\n--- a/object-store.h\n+++ b/object-store.h\n@@ -99,6 +99,15 @@ extern int pretend_sha1_file(void *, unsigned long, enum object_type, unsigned c\n extern int force_object_loose(const unsigned char *sha1, time_t mtime);\n extern void *map_sha1_file(struct repository *r, const unsigned char *sha1, unsigned long *size);\n \n+/*\n+ * Rehash an object's data to make sure the object name actually matches\n+ * \"sha1\" to detect object corruption.\n+ *\n+ * The in-core object data should be in \"map\". If \"map\" == NULL, reads the\n+ * named object using the streaming interface and rehashes it on the fly.\n+ */\n+extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned long size, const char *type);\n+\n /*\n  * Convenience for sha1_object_info_extended() with a NULL struct\n  * object_info. OBJECT_INFO_SKIP_CACHED is automatically set; pass\ndiff --git a/sha1_file.c b/sha1_file.c\nindex aa564e3ad4..3262075497 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -802,12 +802,6 @@ void *xmmap(void *start, size_t length,\n \treturn ret;\n }\n \n-/*\n- * With an in-core object data in \"map\", rehash it to make sure the\n- * object name actually matches \"sha1\" to detect object corruption.\n- * With \"map\" == NULL, try reading the object named with \"sha1\" using\n- * the streaming interface and rehash it to do the same.\n- */\n int check_sha1_signature(const unsigned char *sha1, void *map,\n \t\t\t unsigned long size, const char *type)\n {\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338377","messageId":"20180206001749.218943-12-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 110/194] object-store: add repository argument to check_sha1_signature","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:25Z","receivedAt":"2018-02-06T00:19:35Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nAdd a repository argument to allow callers of check_sha1_signature to\nbe more specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nThe included coccinelle semantic patch will adapt any new callers in\nthe diff produced by `make coccicheck`.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n builtin/fast-export.c                 |  2 +-\n builtin/index-pack.c                  |  2 +-\n builtin/mktag.c                       |  4 +++-\n contrib/coccinelle/object_store.cocci | 10 ++++++++++\n object-store.h                        |  3 ++-\n object.c                              |  4 ++--\n pack-check.c                          |  2 +-\n sha1_file.c                           |  4 ++--\n 8 files changed, 22 insertions(+), 9 deletions(-)\n\ndiff --git a/builtin/fast-export.c b/builtin/fast-export.c\nindex b0f229351d..5d524e7dd2 100644\n--- a/builtin/fast-export.c\n+++ b/builtin/fast-export.c\n@@ -242,7 +242,7 @@ static void export_blob(const struct object_id *oid)\n \t\tbuf = read_sha1_file(oid->hash, &type, &size);\n \t\tif (!buf)\n \t\t\tdie (\"Could not read blob %s\", oid_to_hex(oid));\n-\t\tif (check_sha1_signature(oid->hash, buf, size, typename(type)) < 0)\n+\t\tif (check_sha1_signature(the_repository, oid->hash, buf, size, typename(type)) < 0)\n \t\t\tdie(\"sha1 mismatch in blob %s\", oid_to_hex(oid));\n \t\tobject = parse_object_buffer(the_repository, oid, type,\n \t\t\t\t\t     size, buf, &eaten);\ndiff --git a/builtin/index-pack.c b/builtin/index-pack.c\nindex f570e16bb6..0928ed8dd5 100644\n--- a/builtin/index-pack.c\n+++ b/builtin/index-pack.c\n@@ -1383,7 +1383,7 @@ static void fix_unresolved_deltas(struct sha1file *f)\n \t\tif (!base_obj->data)\n \t\t\tcontinue;\n \n-\t\tif (check_sha1_signature(d->sha1, base_obj->data,\n+\t\tif (check_sha1_signature(the_repository, d->sha1, base_obj->data,\n \t\t\t\tbase_obj->size, typename(type)))\n \t\t\tdie(_(\"local object %s is corrupt\"), sha1_to_hex(d->sha1));\n \t\tbase_obj->obj = append_obj_to_pack(f, d->sha1,\ndiff --git a/builtin/mktag.c b/builtin/mktag.c\nindex ab41735f2a..d05fdb824a 100644\n--- a/builtin/mktag.c\n+++ b/builtin/mktag.c\n@@ -30,7 +30,9 @@ static int verify_object(const unsigned char *sha1, const char *expected_type)\n \n \tif (buffer) {\n \t\tif (type == type_from_string(expected_type))\n-\t\t\tret = check_sha1_signature(repl, buffer, size, expected_type);\n+\t\t\tret = check_sha1_signature(the_repository, repl,\n+\t\t\t\t\t\t   buffer, size,\n+\t\t\t\t\t\t   expected_type);\n \t\tfree(buffer);\n \t}\n \treturn ret;\ndiff --git a/contrib/coccinelle/object_store.cocci b/contrib/coccinelle/object_store.cocci\nindex 800e0581e5..6e6e5454da 100644\n--- a/contrib/coccinelle/object_store.cocci\n+++ b/contrib/coccinelle/object_store.cocci\n@@ -5,3 +5,13 @@ expression F;\n  sha1_object_info(\n +the_repository,\n  E, F)\n+\n+@@\n+expression E;\n+expression F;\n+expression G;\n+expression H;\n+@@\n+ check_sha1_signature(\n++the_repository,\n+ E, F, G, H)\ndiff --git a/object-store.h b/object-store.h\nindex a0e9824406..178268a048 100644\n--- a/object-store.h\n+++ b/object-store.h\n@@ -106,7 +106,8 @@ extern void *map_sha1_file(struct repository *r, const unsigned char *sha1, unsi\n  * The in-core object data should be in \"map\". If \"map\" == NULL, reads the\n  * named object using the streaming interface and rehashes it on the fly.\n  */\n-extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned long size, const char *type);\n+#define check_sha1_signature(r, s, m, sz, t) check_sha1_signature_##r(s, m, sz, t)\n+extern int check_sha1_signature_the_repository(const unsigned char *sha1, void *buf, unsigned long size, const char *type);\n \n /*\n  * Convenience for sha1_object_info_extended() with a NULL struct\ndiff --git a/object.c b/object.c\nindex a10983755c..85b0360e0a 100644\n--- a/object.c\n+++ b/object.c\n@@ -260,7 +260,7 @@ struct object *parse_object_the_repository(const struct object_id *oid)\n \tif ((obj && obj->type == OBJ_BLOB) ||\n \t    (!obj && has_object_file(oid) &&\n \t     sha1_object_info(the_repository, oid->hash, NULL) == OBJ_BLOB)) {\n-\t\tif (check_sha1_signature(repl, NULL, 0, NULL) < 0) {\n+\t\tif (check_sha1_signature(the_repository, repl, NULL, 0, NULL) < 0) {\n \t\t\terror(\"sha1 mismatch %s\", oid_to_hex(oid));\n \t\t\treturn NULL;\n \t\t}\n@@ -270,7 +270,7 @@ struct object *parse_object_the_repository(const struct object_id *oid)\n \n \tbuffer = read_sha1_file(oid->hash, &type, &size);\n \tif (buffer) {\n-\t\tif (check_sha1_signature(repl, buffer, size, typename(type)) < 0) {\n+\t\tif (check_sha1_signature(the_repository, repl, buffer, size, typename(type)) < 0) {\n \t\t\tfree(buffer);\n \t\t\terror(\"sha1 mismatch %s\", sha1_to_hex(repl));\n \t\t\treturn NULL;\ndiff --git a/pack-check.c b/pack-check.c\nindex 25afd59c7d..2eb07cf596 100644\n--- a/pack-check.c\n+++ b/pack-check.c\n@@ -143,7 +143,7 @@ static int verify_packfile(struct packed_git *p,\n \t\t\terr = error(\"cannot unpack %s from %s at offset %\"PRIuMAX\"\",\n \t\t\t\t    oid_to_hex(entries[i].oid.oid), p->pack_name,\n \t\t\t\t    (uintmax_t)entries[i].offset);\n-\t\telse if (check_sha1_signature(entries[i].oid.hash, data, size, typename(type)))\n+\t\telse if (check_sha1_signature(the_repository, entries[i].oid.hash, data, size, typename(type)))\n \t\t\terr = error(\"packed %s from %s is corrupt\",\n \t\t\t\t    oid_to_hex(entries[i].oid.oid), p->pack_name);\n \t\telse if (fn) {\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 3262075497..9ef25e6154 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -802,7 +802,7 @@ void *xmmap(void *start, size_t length,\n \treturn ret;\n }\n \n-int check_sha1_signature(const unsigned char *sha1, void *map,\n+int check_sha1_signature_the_repository(const unsigned char *sha1, void *map,\n \t\t\t unsigned long size, const char *type)\n {\n \tunsigned char real_sha1[20];\n@@ -2207,7 +2207,7 @@ int read_loose_object(const char *path,\n \t\t\tgit_inflate_end(&stream);\n \t\t\tgoto out;\n \t\t}\n-\t\tif (check_sha1_signature(expected_sha1, *contents,\n+\t\tif (check_sha1_signature(the_repository, expected_sha1, *contents,\n \t\t\t\t\t *size, typename(*type))) {\n \t\t\terror(\"sha1 mismatch for %s (expected %s)\", path,\n \t\t\t      sha1_to_hex(expected_sha1));\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338378","messageId":"20180206001749.218943-13-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 111/194] object-store: add repository argument to read_object","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:26Z","receivedAt":"2018-02-06T00:19:58Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nAdd a repository argument to allow callers of read_object to be more\nspecific about which repository to handle. This is a small mechanical\nchange; it doesn't change the implementation to handle repositories\nother than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n sha1_file.c | 7 ++++---\n 1 file changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 9ef25e6154..e62595e3e2 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -1319,7 +1319,8 @@ int sha1_object_info(struct repository *r,\n \treturn type;\n }\n \n-static void *read_object(const unsigned char *sha1, enum object_type *type,\n+#define read_object(r, s, t, sz) read_object_##r(s, t, sz)\n+static void *read_object_the_repository(const unsigned char *sha1, enum object_type *type,\n \t\t\t unsigned long *size)\n {\n \tstruct object_info oi = OBJECT_INFO_INIT;\n@@ -1369,7 +1370,7 @@ void *read_sha1_file_extended(const unsigned char *sha1,\n \t\tlookup_replace_object(the_repository, sha1) : sha1;\n \n \terrno = 0;\n-\tdata = read_object(repl, type, size);\n+\tdata = read_object(the_repository, repl, type, size);\n \tif (data)\n \t\treturn data;\n \n@@ -1701,7 +1702,7 @@ int force_object_loose(const unsigned char *sha1, time_t mtime)\n \n \tif (has_loose_object(sha1))\n \t\treturn 0;\n-\tbuf = read_object(sha1, &type, &len);\n+\tbuf = read_object(the_repository, sha1, &type, &len);\n \tif (!buf)\n \t\treturn error(\"cannot read sha1_file for %s\", sha1_to_hex(sha1));\n \thdrlen = xsnprintf(hdr, sizeof(hdr), \"%s %lu\", typename(type), len) + 1;\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338379","messageId":"20180206001749.218943-14-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 112/194] object-store: add repository argument to read_sha1_file_extended","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:27Z","receivedAt":"2018-02-06T00:20:01Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nAdd a repository argument to allow callers of read_sha1_file_extended\nto be more specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nThe included coccinelle semantic patch will adapt any new callers in\nthe diff produced by `make coccicheck`.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n contrib/coccinelle/object_store.cocci | 10 ++++++++++\n object-store.h                        |  5 +++--\n sha1_file.c                           |  2 +-\n streaming.c                           |  3 ++-\n 4 files changed, 16 insertions(+), 4 deletions(-)\n\ndiff --git a/contrib/coccinelle/object_store.cocci b/contrib/coccinelle/object_store.cocci\nindex 6e6e5454da..915dd176dd 100644\n--- a/contrib/coccinelle/object_store.cocci\n+++ b/contrib/coccinelle/object_store.cocci\n@@ -15,3 +15,13 @@ expression H;\n  check_sha1_signature(\n +the_repository,\n  E, F, G, H)\n+\n+@@\n+expression E;\n+expression F;\n+expression G;\n+expression H;\n+@@\n+ read_sha1_file_extended(\n++the_repository,\n+ E, F, G, H)\ndiff --git a/object-store.h b/object-store.h\nindex 178268a048..d6462cd9f1 100644\n--- a/object-store.h\n+++ b/object-store.h\n@@ -82,12 +82,13 @@ struct packed_git {\n \tchar pack_name[FLEX_ARRAY]; /* more */\n };\n \n-extern void *read_sha1_file_extended(const unsigned char *sha1,\n+#define read_sha1_file_extended(r, s, t, sz, l) read_sha1_file_extended_##r(s, t, sz, l)\n+extern void *read_sha1_file_extended_the_repository(const unsigned char *sha1,\n \t\t\t\t     enum object_type *type,\n \t\t\t\t     unsigned long *size, int lookup_replace);\n static inline void *read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size)\n {\n-\treturn read_sha1_file_extended(sha1, type, size, 1);\n+\treturn read_sha1_file_extended(the_repository, sha1, type, size, 1);\n }\n \n /* Read and unpack a sha1 file into memory, write memory to a sha1 file */\ndiff --git a/sha1_file.c b/sha1_file.c\nindex e62595e3e2..2d9a794654 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -1357,7 +1357,7 @@ int pretend_sha1_file(void *buf, unsigned long len, enum object_type type,\n  * deal with them should arrange to call read_object() and give error\n  * messages themselves.\n  */\n-void *read_sha1_file_extended(const unsigned char *sha1,\n+void *read_sha1_file_extended_the_repository(const unsigned char *sha1,\n \t\t\t      enum object_type *type,\n \t\t\t      unsigned long *size,\n \t\t\t      int lookup_replace)\ndiff --git a/streaming.c b/streaming.c\nindex bc3c4811ca..f0ff5e7245 100644\n--- a/streaming.c\n+++ b/streaming.c\n@@ -490,7 +490,8 @@ static struct stream_vtbl incore_vtbl = {\n \n static open_method_decl(incore)\n {\n-\tst->u.incore.buf = read_sha1_file_extended(sha1, type, &st->size, 0);\n+\tst->u.incore.buf = read_sha1_file_extended(the_repository, sha1,\n+\t\t\t\t\t\t   type, &st->size, 0);\n \tst->u.incore.read_ptr = 0;\n \tst->vtbl = &incore_vtbl;\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338380","messageId":"20180206001749.218943-15-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 113/194] object-store: add repository argument to read_sha1_file","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:28Z","receivedAt":"2018-02-06T00:20:06Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow callers of read_sha1_file to be\nmore specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nThe included coccinelle semantic patch will adapt any new callers in\nthe diff produced by `make coccicheck`.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n apply.c                               |  7 +++++--\n archive.c                             |  3 ++-\n bisect.c                              |  4 +++-\n blame.c                               |  7 +++++--\n builtin/cat-file.c                    | 15 ++++++++++-----\n builtin/difftool.c                    |  4 +++-\n builtin/fast-export.c                 |  6 ++++--\n builtin/fmt-merge-msg.c               |  3 ++-\n builtin/grep.c                        |  2 +-\n builtin/index-pack.c                  |  6 ++++--\n builtin/log.c                         |  2 +-\n builtin/merge-tree.c                  |  8 ++++++--\n builtin/mktag.c                       |  2 +-\n builtin/notes.c                       |  7 ++++---\n builtin/pack-objects.c                | 17 +++++++++++------\n builtin/reflog.c                      |  3 ++-\n builtin/tag.c                         |  4 ++--\n builtin/unpack-file.c                 |  3 ++-\n builtin/unpack-objects.c              |  3 ++-\n builtin/verify-commit.c               |  2 +-\n bundle.c                              |  2 +-\n combine-diff.c                        |  4 +++-\n commit.c                              |  9 ++++++---\n config.c                              |  2 +-\n contrib/coccinelle/object_store.cocci |  9 +++++++++\n diff.c                                |  3 ++-\n dir.c                                 |  3 ++-\n entry.c                               |  4 +++-\n fast-import.c                         |  9 ++++++---\n fsck.c                                |  3 ++-\n grep.c                                |  4 +++-\n http-push.c                           |  3 ++-\n mailmap.c                             |  3 ++-\n match-trees.c                         |  5 +++--\n merge-blobs.c                         |  7 +++++--\n merge-recursive.c                     |  5 +++--\n notes-cache.c                         |  3 ++-\n notes-merge.c                         |  2 +-\n notes.c                               | 11 +++++++----\n object-store.h                        |  3 ++-\n object.c                              |  2 +-\n read-cache.c                          |  6 ++++--\n ref-filter.c                          |  2 +-\n remote-testsvn.c                      |  5 +++--\n rerere.c                              |  4 +++-\n sha1_file.c                           |  3 ++-\n submodule-config.c                    |  3 ++-\n tag.c                                 |  5 +++--\n tree-walk.c                           |  4 +++-\n tree.c                                |  3 ++-\n xdiff-interface.c                     |  3 ++-\n 51 files changed, 162 insertions(+), 80 deletions(-)\n\ndiff --git a/apply.c b/apply.c\nindex de4440cd2a..fa266f6c27 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -10,6 +10,7 @@\n #include \"cache.h\"\n #include \"config.h\"\n #include \"object-store.h\"\n+#include \"repository.h\"\n #include \"blob.h\"\n #include \"delta.h\"\n #include \"diff.h\"\n@@ -3181,7 +3182,8 @@ static int apply_binary(struct apply_state *state,\n \t\tunsigned long size;\n \t\tchar *result;\n \n-\t\tresult = read_sha1_file(oid.hash, &type, &size);\n+\t\tresult = read_sha1_file(the_repository, oid.hash, &type,\n+\t\t\t\t\t&size);\n \t\tif (!result)\n \t\t\treturn error(_(\"the necessary postimage %s for \"\n \t\t\t\t       \"'%s' cannot be read\"),\n@@ -3243,7 +3245,8 @@ static int read_blob_object(struct strbuf *buf, const struct object_id *oid, uns\n \t\tunsigned long sz;\n \t\tchar *result;\n \n-\t\tresult = read_sha1_file(oid->hash, &type, &sz);\n+\t\tresult = read_sha1_file(the_repository, oid->hash, &type,\n+\t\t\t\t\t&sz);\n \t\tif (!result)\n \t\t\treturn -1;\n \t\t/* XXX read_sha1_file NUL-terminates */\ndiff --git a/archive.c b/archive.c\nindex 2aeafe647d..6f38a5cf55 100644\n--- a/archive.c\n+++ b/archive.c\n@@ -2,6 +2,7 @@\n #include \"config.h\"\n #include \"refs.h\"\n #include \"object-store.h\"\n+#include \"repository.h\"\n #include \"commit.h\"\n #include \"tree-walk.h\"\n #include \"attr.h\"\n@@ -73,7 +74,7 @@ void *sha1_file_to_archive(const struct archiver_args *args,\n \tconst struct commit *commit = args->convert ? args->commit : NULL;\n \n \tpath += args->baselen;\n-\tbuffer = read_sha1_file(sha1, type, sizep);\n+\tbuffer = read_sha1_file(the_repository, sha1, type, sizep);\n \tif (buffer && S_ISREG(mode)) {\n \t\tstruct strbuf buf = STRBUF_INIT;\n \t\tsize_t size = 0;\ndiff --git a/bisect.c b/bisect.c\nindex c3066bd972..2db384ce2d 100644\n--- a/bisect.c\n+++ b/bisect.c\n@@ -132,7 +132,9 @@ static void show_list(const char *debug, int counted, int nr,\n \t\tunsigned flags = commit->object.flags;\n \t\tenum object_type type;\n \t\tunsigned long size;\n-\t\tchar *buf = read_sha1_file(commit->object.sha1, &type, &size);\n+\t\tchar *buf = read_sha1_file(the_repository,\n+\t\t\t\t\t   commit->object.sha1, &type,\n+\t\t\t\t\t   &size);\n \t\tconst char *subject_start;\n \t\tint subject_len;\n \ndiff --git a/blame.c b/blame.c\nindex 1aab6228cc..8648a1ddff 100644\n--- a/blame.c\n+++ b/blame.c\n@@ -299,7 +299,8 @@ static void fill_origin_blob(struct diff_options *opt,\n \t\t    textconv_object(o->path, o->mode, &o->blob_oid, 1, &file->ptr, &file_size))\n \t\t\t;\n \t\telse\n-\t\t\tfile->ptr = read_sha1_file(o->blob_oid.hash, &type,\n+\t\t\tfile->ptr = read_sha1_file(the_repository,\n+\t\t\t\t\t\t   o->blob_oid.hash, &type,\n \t\t\t\t\t\t   &file_size);\n \t\tfile->size = file_size;\n \n@@ -1833,7 +1834,9 @@ void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blam\n \t\t\t\t    &sb->final_buf_size))\n \t\t\t;\n \t\telse\n-\t\t\tsb->final_buf = read_sha1_file(o->blob_oid.hash, &type,\n+\t\t\tsb->final_buf = read_sha1_file(the_repository,\n+\t\t\t\t\t\t       o->blob_oid.hash,\n+\t\t\t\t\t\t       &type,\n \t\t\t\t\t\t       &sb->final_buf_size);\n \n \t\tif (!sb->final_buf)\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 96c834b8f4..2ebed86524 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -33,7 +33,7 @@ static int filter_object(const char *path, unsigned mode,\n {\n \tenum object_type type;\n \n-\t*buf = read_sha1_file(oid->hash, &type, size);\n+\t*buf = read_sha1_file(the_repository, oid->hash, &type, size);\n \tif (!*buf)\n \t\treturn error(_(\"cannot read object %s '%s'\"),\n \t\t\t     oid_to_hex(oid), path);\n@@ -131,7 +131,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,\n \n \t\tif (type == OBJ_BLOB)\n \t\t\treturn stream_blob_to_fd(1, &oid, NULL, 0);\n-\t\tbuf = read_sha1_file(oid.hash, &type, &size);\n+\t\tbuf = read_sha1_file(the_repository, oid.hash, &type, &size);\n \t\tif (!buf)\n \t\t\tdie(\"Cannot read object %s\", obj_name);\n \n@@ -142,7 +142,9 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,\n \t\tif (type_from_string(exp_type) == OBJ_BLOB) {\n \t\t\tstruct object_id blob_oid;\n \t\t\tif (sha1_object_info(the_repository, oid.hash, NULL) == OBJ_TAG) {\n-\t\t\t\tchar *buffer = read_sha1_file(oid.hash, &type, &size);\n+\t\t\t\tchar *buffer = read_sha1_file(the_repository,\n+\t\t\t\t\t\t\t      oid.hash,\n+\t\t\t\t\t\t\t      &type, &size);\n \t\t\t\tconst char *target;\n \t\t\t\tif (!skip_prefix(buffer, \"object \", &target) ||\n \t\t\t\t    get_oid_hex(target, &blob_oid))\n@@ -305,7 +307,9 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d\n \t\t\t\tenum object_type type;\n \t\t\t\tif (!textconv_object(data->rest, 0100644, oid,\n \t\t\t\t\t\t     1, &contents, &size))\n-\t\t\t\t\tcontents = read_sha1_file(oid->hash, &type,\n+\t\t\t\t\tcontents = read_sha1_file(the_repository,\n+\t\t\t\t\t\t\t\t  oid->hash,\n+\t\t\t\t\t\t\t\t  &type,\n \t\t\t\t\t\t\t\t  &size);\n \t\t\t\tif (!contents)\n \t\t\t\t\tdie(\"could not convert '%s' %s\",\n@@ -322,7 +326,8 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d\n \t\tunsigned long size;\n \t\tvoid *contents;\n \n-\t\tcontents = read_sha1_file(oid->hash, &type, &size);\n+\t\tcontents = read_sha1_file(the_repository, oid->hash, &type,\n+\t\t\t\t\t  &size);\n \t\tif (!contents)\n \t\t\tdie(\"object %s disappeared\", oid_to_hex(oid));\n \t\tif (type != data->type)\ndiff --git a/builtin/difftool.c b/builtin/difftool.c\nindex d62094060d..32bebbf358 100644\n--- a/builtin/difftool.c\n+++ b/builtin/difftool.c\n@@ -21,6 +21,7 @@\n #include \"strbuf.h\"\n #include \"lockfile.h\"\n #include \"object-store.h\"\n+#include \"repository.h\"\n #include \"dir.h\"\n \n static char *diff_gui_tool;\n@@ -307,7 +308,8 @@ static char *get_symlink(const struct object_id *oid, const char *path)\n \t} else {\n \t\tenum object_type type;\n \t\tunsigned long size;\n-\t\tdata = read_sha1_file(oid->hash, &type, &size);\n+\t\tdata = read_sha1_file(the_repository, oid->hash, &type,\n+\t\t\t\t      &size);\n \t\tif (!data)\n \t\t\tdie(_(\"could not read object %s for symlink %s\"),\n \t\t\t\toid_to_hex(oid), path);\ndiff --git a/builtin/fast-export.c b/builtin/fast-export.c\nindex 5d524e7dd2..1562ac4927 100644\n--- a/builtin/fast-export.c\n+++ b/builtin/fast-export.c\n@@ -239,7 +239,8 @@ static void export_blob(const struct object_id *oid)\n \t\tobject = (struct object *)lookup_blob(the_repository, oid);\n \t\teaten = 0;\n \t} else {\n-\t\tbuf = read_sha1_file(oid->hash, &type, &size);\n+\t\tbuf = read_sha1_file(the_repository, oid->hash, &type,\n+\t\t\t\t     &size);\n \t\tif (!buf)\n \t\t\tdie (\"Could not read blob %s\", oid_to_hex(oid));\n \t\tif (check_sha1_signature(the_repository, oid->hash, buf, size, typename(type)) < 0)\n@@ -686,7 +687,8 @@ static void handle_tag(const char *name, struct tag *tag)\n \t\treturn;\n \t}\n \n-\tbuf = read_sha1_file(tag->object.oid.hash, &type, &size);\n+\tbuf = read_sha1_file(the_repository, tag->object.oid.hash, &type,\n+\t\t\t     &size);\n \tif (!buf)\n \t\tdie (\"Could not read tag %s\", oid_to_hex(&tag->object.oid));\n \tmessage = memmem(buf, size, \"\\n\\n\", 2);\ndiff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c\nindex 3e99d10218..ac98556a1d 100644\n--- a/builtin/fmt-merge-msg.c\n+++ b/builtin/fmt-merge-msg.c\n@@ -492,7 +492,8 @@ static void fmt_merge_msg_sigs(struct strbuf *out)\n \t\tunsigned char *sha1 = origins.items[i].util;\n \t\tenum object_type type;\n \t\tunsigned long size, len;\n-\t\tchar *buf = read_sha1_file(sha1, &type, &size);\n+\t\tchar *buf = read_sha1_file(the_repository, sha1, &type,\n+\t\t\t\t\t   &size);\n \t\tstruct strbuf sig = STRBUF_INIT;\n \n \t\tif (!buf || type != OBJ_TAG)\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex a83e87a676..de1339bfc6 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -308,7 +308,7 @@ static void *lock_and_read_oid_file(const struct object_id *oid, enum object_typ\n \tvoid *data;\n \n \tgrep_read_lock();\n-\tdata = read_sha1_file(oid->hash, type, size);\n+\tdata = read_sha1_file(the_repository, oid->hash, type, size);\n \tgrep_read_unlock();\n \treturn data;\n }\ndiff --git a/builtin/index-pack.c b/builtin/index-pack.c\nindex 0928ed8dd5..b42bf12f65 100644\n--- a/builtin/index-pack.c\n+++ b/builtin/index-pack.c\n@@ -819,7 +819,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,\n \t\t\tdie(_(\"cannot read existing object info %s\"), oid_to_hex(oid));\n \t\tif (has_type != type || has_size != size)\n \t\t\tdie(_(\"SHA1 COLLISION FOUND WITH %s !\"), oid_to_hex(oid));\n-\t\thas_data = read_sha1_file(oid->hash, &has_type, &has_size);\n+\t\thas_data = read_sha1_file(the_repository, oid->hash,\n+\t\t\t\t\t  &has_type, &has_size);\n \t\tread_unlock();\n \t\tif (!data)\n \t\t\tdata = new_data = get_data_from_pack(obj_entry);\n@@ -1379,7 +1380,8 @@ static void fix_unresolved_deltas(struct sha1file *f)\n \n \t\tif (objects[d->obj_no].real_type != OBJ_REF_DELTA)\n \t\t\tcontinue;\n-\t\tbase_obj->data = read_sha1_file(d->sha1, &type, &base_obj->size);\n+\t\tbase_obj->data = read_sha1_file(the_repository, d->sha1,\n+\t\t\t\t\t\t&type, &base_obj->size);\n \t\tif (!base_obj->data)\n \t\t\tcontinue;\n \ndiff --git a/builtin/log.c b/builtin/log.c\nindex 529e19ce6f..fce7b07df4 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -518,7 +518,7 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev)\n {\n \tunsigned long size;\n \tenum object_type type;\n-\tchar *buf = read_sha1_file(oid->hash, &type, &size);\n+\tchar *buf = read_sha1_file(the_repository, oid->hash, &type, &size);\n \tint offset = 0;\n \n \tif (!buf)\ndiff --git a/builtin/merge-tree.c b/builtin/merge-tree.c\nindex 41f1ae30cc..86a8ea3965 100644\n--- a/builtin/merge-tree.c\n+++ b/builtin/merge-tree.c\n@@ -62,7 +62,9 @@ static void *result(struct merge_list *entry, unsigned long *size)\n \tconst char *path = entry->path;\n \n \tif (!entry->stage)\n-\t\treturn read_sha1_file(entry->blob->object.oid.hash, &type, size);\n+\t\treturn read_sha1_file(the_repository,\n+\t\t\t\t      entry->blob->object.oid.hash, &type,\n+\t\t\t\t      size);\n \tbase = NULL;\n \tif (entry->stage == 1) {\n \t\tbase = entry->blob;\n@@ -84,7 +86,9 @@ static void *origin(struct merge_list *entry, unsigned long *size)\n \tenum object_type type;\n \twhile (entry) {\n \t\tif (entry->stage == 2)\n-\t\t\treturn read_sha1_file(entry->blob->object.oid.hash, &type, size);\n+\t\t\treturn read_sha1_file(the_repository,\n+\t\t\t\t\t      entry->blob->object.oid.hash,\n+\t\t\t\t\t      &type, size);\n \t\tentry = entry->link;\n \t}\n \treturn NULL;\ndiff --git a/builtin/mktag.c b/builtin/mktag.c\nindex d05fdb824a..b6498dbb0e 100644\n--- a/builtin/mktag.c\n+++ b/builtin/mktag.c\n@@ -25,7 +25,7 @@ static int verify_object(const unsigned char *sha1, const char *expected_type)\n \tint ret = -1;\n \tenum object_type type;\n \tunsigned long size;\n-\tvoid *buffer = read_sha1_file(sha1, &type, &size);\n+\tvoid *buffer = read_sha1_file(the_repository, sha1, &type, &size);\n \tconst unsigned char *repl = lookup_replace_object(the_repository, sha1);\n \n \tif (buffer) {\ndiff --git a/builtin/notes.c b/builtin/notes.c\nindex 18128eb439..56d99c2789 100644\n--- a/builtin/notes.c\n+++ b/builtin/notes.c\n@@ -124,7 +124,7 @@ static void copy_obj_to_fd(int fd, const unsigned char *sha1)\n {\n \tunsigned long size;\n \tenum object_type type;\n-\tchar *buf = read_sha1_file(sha1, &type, &size);\n+\tchar *buf = read_sha1_file(the_repository, sha1, &type, &size);\n \tif (buf) {\n \t\tif (size)\n \t\t\twrite_or_die(fd, buf, size);\n@@ -255,7 +255,7 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)\n \n \tif (get_oid(arg, &object))\n \t\tdie(_(\"failed to resolve '%s' as a valid ref.\"), arg);\n-\tif (!(buf = read_sha1_file(object.hash, &type, &len))) {\n+\tif (!(buf = read_sha1_file(the_repository, object.hash, &type, &len))) {\n \t\tfree(buf);\n \t\tdie(_(\"failed to read object '%s'.\"), arg);\n \t}\n@@ -610,7 +610,8 @@ static int append_edit(int argc, const char **argv, const char *prefix)\n \t\t/* Append buf to previous note contents */\n \t\tunsigned long size;\n \t\tenum object_type type;\n-\t\tchar *prev_buf = read_sha1_file(note->hash, &type, &size);\n+\t\tchar *prev_buf = read_sha1_file(the_repository, note->hash,\n+\t\t\t\t\t\t&type, &size);\n \n \t\tstrbuf_grow(&d.buf, size + 1);\n \t\tif (d.buf.len && prev_buf && size)\ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex fae579f12a..128e5e3676 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -123,10 +123,12 @@ static void *get_delta(struct object_entry *entry)\n \tvoid *buf, *base_buf, *delta_buf;\n \tenum object_type type;\n \n-\tbuf = read_sha1_file(entry->idx.oid.hash, &type, &size);\n+\tbuf = read_sha1_file(the_repository, entry->idx.oid.hash, &type,\n+\t\t\t     &size);\n \tif (!buf)\n \t\tdie(\"unable to read %s\", oid_to_hex(&entry->idx.oid));\n-\tbase_buf = read_sha1_file(entry->delta->idx.oid.hash, &type,\n+\tbase_buf = read_sha1_file(the_repository, entry->delta->idx.oid.hash,\n+\t\t\t\t  &type,\n \t\t\t\t  &base_size);\n \tif (!base_buf)\n \t\tdie(\"unable to read %s\",\n@@ -271,7 +273,8 @@ static unsigned long write_no_reuse_object(struct sha1file *f, struct object_ent\n \t\t    (st = open_istream(entry->idx.oid.hash, &type, &size, NULL)) != NULL)\n \t\t\tbuf = NULL;\n \t\telse {\n-\t\t\tbuf = read_sha1_file(entry->idx.oid.hash, &type,\n+\t\t\tbuf = read_sha1_file(the_repository,\n+\t\t\t\t\t     entry->idx.oid.hash, &type,\n \t\t\t\t\t     &size);\n \t\t\tif (!buf)\n \t\t\t\tdie(_(\"unable to read %s\"),\n@@ -1193,7 +1196,7 @@ static struct pbase_tree_cache *pbase_tree_get(const struct object_id *oid)\n \t/* Did not find one.  Either we got a bogus request or\n \t * we need to read and perhaps cache.\n \t */\n-\tdata = read_sha1_file(oid->hash, &type, &size);\n+\tdata = read_sha1_file(the_repository, oid->hash, &type, &size);\n \tif (!data)\n \t\treturn NULL;\n \tif (type != OBJ_TREE) {\n@@ -1877,7 +1880,8 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,\n \t/* Load data if not already done */\n \tif (!trg->data) {\n \t\tread_lock();\n-\t\ttrg->data = read_sha1_file(trg_entry->idx.oid.hash, &type,\n+\t\ttrg->data = read_sha1_file(the_repository,\n+\t\t\t\t\t   trg_entry->idx.oid.hash, &type,\n \t\t\t\t\t   &sz);\n \t\tread_unlock();\n \t\tif (!trg->data)\n@@ -1891,7 +1895,8 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,\n \t}\n \tif (!src->data) {\n \t\tread_lock();\n-\t\tsrc->data = read_sha1_file(src_entry->idx.oid.hash, &type,\n+\t\tsrc->data = read_sha1_file(the_repository,\n+\t\t\t\t\t   src_entry->idx.oid.hash, &type,\n \t\t\t\t\t   &sz);\n \t\tread_unlock();\n \t\tif (!src->data) {\ndiff --git a/builtin/reflog.c b/builtin/reflog.c\nindex e12b99e9cb..3b600966e3 100644\n--- a/builtin/reflog.c\n+++ b/builtin/reflog.c\n@@ -76,7 +76,8 @@ static int tree_is_complete(const struct object_id *oid)\n \tif (!tree->buffer) {\n \t\tenum object_type type;\n \t\tunsigned long size;\n-\t\tvoid *data = read_sha1_file(oid->hash, &type, &size);\n+\t\tvoid *data = read_sha1_file(the_repository, oid->hash, &type,\n+\t\t\t\t\t    &size);\n \t\tif (!data) {\n \t\t\ttree->object.flags |= INCOMPLETE;\n \t\t\treturn 0;\ndiff --git a/builtin/tag.c b/builtin/tag.c\nindex 1fad1e6733..59db44447f 100644\n--- a/builtin/tag.c\n+++ b/builtin/tag.c\n@@ -169,7 +169,7 @@ static void write_tag_body(int fd, const struct object_id *oid)\n \tenum object_type type;\n \tchar *buf, *sp;\n \n-\tbuf = read_sha1_file(oid->hash, &type, &size);\n+\tbuf = read_sha1_file(the_repository, oid->hash, &type, &size);\n \tif (!buf)\n \t\treturn;\n \t/* skip header */\n@@ -301,7 +301,7 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb)\n \t\tstrbuf_addstr(sb, \"object of unknown type\");\n \t\tbreak;\n \tcase OBJ_COMMIT:\n-\t\tif ((buf = read_sha1_file(oid->hash, &type, &size)) != NULL) {\n+\t\tif ((buf = read_sha1_file(the_repository, oid->hash, &type, &size)) != NULL) {\n \t\t\tsubject_len = find_commit_subject(buf, &subject_start);\n \t\t\tstrbuf_insert(sb, sb->len, subject_start, subject_len);\n \t\t} else {\ndiff --git a/builtin/unpack-file.c b/builtin/unpack-file.c\nindex b28e056c74..2e9aeaf0da 100644\n--- a/builtin/unpack-file.c\n+++ b/builtin/unpack-file.c\n@@ -1,6 +1,7 @@\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"object-store.h\"\n+#include \"repository.h\"\n \n static char *create_temp_file(struct object_id *oid)\n {\n@@ -10,7 +11,7 @@ static char *create_temp_file(struct object_id *oid)\n \tunsigned long size;\n \tint fd;\n \n-\tbuf = read_sha1_file(oid->hash, &type, &size);\n+\tbuf = read_sha1_file(the_repository, oid->hash, &type, &size);\n \tif (!buf || type != OBJ_BLOB)\n \t\tdie(\"unable to read blob object %s\", oid_to_hex(oid));\n \ndiff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c\nindex 6b8fb918b6..d8175cecd6 100644\n--- a/builtin/unpack-objects.c\n+++ b/builtin/unpack-objects.c\n@@ -423,7 +423,8 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,\n \tif (resolve_against_held(nr, &base_oid, delta_data, delta_size))\n \t\treturn;\n \n-\tbase = read_sha1_file(base_oid.hash, &type, &base_size);\n+\tbase = read_sha1_file(the_repository, base_oid.hash, &type,\n+\t\t\t      &base_size);\n \tif (!base) {\n \t\terror(\"failed to read delta-pack base object %s\",\n \t\t      oid_to_hex(&base_oid));\ndiff --git a/builtin/verify-commit.c b/builtin/verify-commit.c\nindex b0ae18ec33..17641b6097 100644\n--- a/builtin/verify-commit.c\n+++ b/builtin/verify-commit.c\n@@ -47,7 +47,7 @@ static int verify_commit(const char *name, unsigned flags)\n \tif (get_oid(name, &oid))\n \t\treturn error(\"commit '%s' not found.\", name);\n \n-\tbuf = read_sha1_file(oid.hash, &type, &size);\n+\tbuf = read_sha1_file(the_repository, oid.hash, &type, &size);\n \tif (!buf)\n \t\treturn error(\"%s: unable to read file.\", name);\n \tif (type != OBJ_COMMIT)\ndiff --git a/bundle.c b/bundle.c\nindex d9579f851e..abe158b59c 100644\n--- a/bundle.c\n+++ b/bundle.c\n@@ -227,7 +227,7 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs)\n \tif (revs->max_age == -1 && revs->min_age == -1)\n \t\tgoto out;\n \n-\tbuf = read_sha1_file(tag->oid.hash, &type, &size);\n+\tbuf = read_sha1_file(the_repository, tag->oid.hash, &type, &size);\n \tif (!buf)\n \t\tgoto out;\n \tline = memmem(buf, size, \"\\ntagger \", 8);\ndiff --git a/combine-diff.c b/combine-diff.c\nindex f45ab6f57c..8f6ac31252 100644\n--- a/combine-diff.c\n+++ b/combine-diff.c\n@@ -1,5 +1,6 @@\n #include \"cache.h\"\n #include \"object-store.h\"\n+#include \"repository.h\"\n #include \"commit.h\"\n #include \"blob.h\"\n #include \"diff.h\"\n@@ -307,7 +308,8 @@ static char *grab_blob(const struct object_id *oid, unsigned int mode,\n \t\t*size = fill_textconv(textconv, df, &blob);\n \t\tfree_filespec(df);\n \t} else {\n-\t\tblob = read_sha1_file(oid->hash, &type, size);\n+\t\tblob = read_sha1_file(the_repository, oid->hash, &type,\n+\t\t\t\t      size);\n \t\tif (type != OBJ_BLOB)\n \t\t\tdie(\"object '%s' is not a blob!\", oid_to_hex(oid));\n \t}\ndiff --git a/commit.c b/commit.c\nindex 8e42af7565..2fb702795c 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -277,7 +277,8 @@ const void *get_commit_buffer(const struct commit *commit, unsigned long *sizep)\n \tif (!ret) {\n \t\tenum object_type type;\n \t\tunsigned long size;\n-\t\tret = read_sha1_file(commit->object.oid.hash, &type, &size);\n+\t\tret = read_sha1_file(the_repository, commit->object.oid.hash,\n+\t\t\t\t     &type, &size);\n \t\tif (!ret)\n \t\t\tdie(\"cannot read commit object %s\",\n \t\t\t    oid_to_hex(&commit->object.oid));\n@@ -395,7 +396,8 @@ int parse_commit_gently(struct commit *item, int quiet_on_missing)\n \t\treturn -1;\n \tif (item->object.parsed)\n \t\treturn 0;\n-\tbuffer = read_sha1_file(item->object.oid.hash, &type, &size);\n+\tbuffer = read_sha1_file(the_repository, item->object.oid.hash, &type,\n+\t\t\t\t&size);\n \tif (!buffer)\n \t\treturn quiet_on_missing ? -1 :\n \t\t\terror(\"Could not read %s\",\n@@ -1234,7 +1236,8 @@ static void handle_signed_tag(struct commit *parent, struct commit_extra_header\n \tdesc = merge_remote_util(parent);\n \tif (!desc || !desc->obj)\n \t\treturn;\n-\tbuf = read_sha1_file(desc->obj->oid.hash, &type, &size);\n+\tbuf = read_sha1_file(the_repository, desc->obj->oid.hash, &type,\n+\t\t\t     &size);\n \tif (!buf || type != OBJ_TAG)\n \t\tgoto free_return;\n \tlen = parse_signature(buf, size);\ndiff --git a/config.c b/config.c\nindex e617c2018d..c023740c97 100644\n--- a/config.c\n+++ b/config.c\n@@ -1480,7 +1480,7 @@ int git_config_from_blob_oid(config_fn_t fn,\n \tunsigned long size;\n \tint ret;\n \n-\tbuf = read_sha1_file(oid->hash, &type, &size);\n+\tbuf = read_sha1_file(the_repository, oid->hash, &type, &size);\n \tif (!buf)\n \t\treturn error(\"unable to load config blob object '%s'\", name);\n \tif (type != OBJ_BLOB) {\ndiff --git a/contrib/coccinelle/object_store.cocci b/contrib/coccinelle/object_store.cocci\nindex 915dd176dd..72066e3768 100644\n--- a/contrib/coccinelle/object_store.cocci\n+++ b/contrib/coccinelle/object_store.cocci\n@@ -25,3 +25,12 @@ expression H;\n  read_sha1_file_extended(\n +the_repository,\n  E, F, G, H)\n+\n+@@\n+expression E;\n+expression F;\n+expression G;\n+@@\n+ read_sha1_file(\n++the_repository,\n+ E, F, G)\ndiff --git a/diff.c b/diff.c\nindex 08bff6e720..9ad272b5cb 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -3629,7 +3629,8 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)\n \t\t\t\treturn 0;\n \t\t\t}\n \t\t}\n-\t\ts->data = read_sha1_file(s->oid.hash, &type, &s->size);\n+\t\ts->data = read_sha1_file(the_repository, s->oid.hash, &type,\n+\t\t\t\t\t &s->size);\n \t\tif (!s->data)\n \t\t\tdie(\"unable to read %s\", oid_to_hex(&s->oid));\n \t\ts->should_free = 1;\ndiff --git a/dir.c b/dir.c\nindex 4a7981abc4..e4f49636ca 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -12,6 +12,7 @@\n #include \"config.h\"\n #include \"dir.h\"\n #include \"object-store.h\"\n+#include \"repository.h\"\n #include \"attr.h\"\n #include \"refs.h\"\n #include \"wildmatch.h\"\n@@ -246,7 +247,7 @@ static int do_read_blob(const struct object_id *oid,\n \t*size_out = 0;\n \t*data_out = NULL;\n \n-\tdata = read_sha1_file(oid->hash, &type, &sz);\n+\tdata = read_sha1_file(the_repository, oid->hash, &type, &sz);\n \tif (!data || type != OBJ_BLOB) {\n \t\tfree(data);\n \t\treturn -1;\ndiff --git a/entry.c b/entry.c\nindex 02aa09bc83..4fa34741af 100644\n--- a/entry.c\n+++ b/entry.c\n@@ -1,6 +1,7 @@\n #include \"cache.h\"\n #include \"blob.h\"\n #include \"object-store.h\"\n+#include \"repository.h\"\n #include \"dir.h\"\n #include \"streaming.h\"\n #include \"submodule.h\"\n@@ -86,7 +87,8 @@ static int create_file(const char *path, unsigned int mode)\n static void *read_blob_entry(const struct cache_entry *ce, unsigned long *size)\n {\n \tenum object_type type;\n-\tvoid *new = read_sha1_file(ce->oid.hash, &type, size);\n+\tvoid *new = read_sha1_file(the_repository, ce->oid.hash, &type,\n+\t\t\t\t   size);\n \n \tif (new) {\n \t\tif (type == OBJ_BLOB)\ndiff --git a/fast-import.c b/fast-import.c\nindex 54c2e10656..b1ff3d47df 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -1412,7 +1412,8 @@ static void load_tree(struct tree_entry *root)\n \t\t\tdie(\"Can't load tree %s\", oid_to_hex(oid));\n \t} else {\n \t\tenum object_type type;\n-\t\tbuf = read_sha1_file(oid->hash, &type, &size);\n+\t\tbuf = read_sha1_file(the_repository, oid->hash, &type,\n+\t\t\t\t     &size);\n \t\tif (!buf || type != OBJ_TREE)\n \t\t\tdie(\"Can't load tree %s\", oid_to_hex(oid));\n \t}\n@@ -2973,7 +2974,8 @@ static void cat_blob(struct object_entry *oe, struct object_id *oid)\n \tchar *buf;\n \n \tif (!oe || oe->pack_id == MAX_PACK_ID) {\n-\t\tbuf = read_sha1_file(oid->hash, &type, &size);\n+\t\tbuf = read_sha1_file(the_repository, oid->hash, &type,\n+\t\t\t\t     &size);\n \t} else {\n \t\ttype = oe->type;\n \t\tbuf = gfi_unpack_entry(oe, &size);\n@@ -3079,7 +3081,8 @@ static struct object_entry *dereference(struct object_entry *oe,\n \t\tbuf = gfi_unpack_entry(oe, &size);\n \t} else {\n \t\tenum object_type unused;\n-\t\tbuf = read_sha1_file(oid->hash, &unused, &size);\n+\t\tbuf = read_sha1_file(the_repository, oid->hash, &unused,\n+\t\t\t\t     &size);\n \t}\n \tif (!buf)\n \t\tdie(\"Can't load object %s\", oid_to_hex(oid));\ndiff --git a/fsck.c b/fsck.c\nindex af0291121d..5144ceb8e2 100644\n--- a/fsck.c\n+++ b/fsck.c\n@@ -813,7 +813,8 @@ static int fsck_tag_buffer(struct tag *tag, const char *data,\n \t\tenum object_type type;\n \n \t\tbuffer = to_free =\n-\t\t\tread_sha1_file(tag->object.oid.hash, &type, &size);\n+\t\t\tread_sha1_file(the_repository, tag->object.oid.hash,\n+\t\t\t\t       &type, &size);\n \t\tif (!buffer)\n \t\t\treturn report(options, &tag->object,\n \t\t\t\tFSCK_MSG_MISSING_TAG_OBJECT,\ndiff --git a/grep.c b/grep.c\nindex 6bccd7c7ea..c8e27ec6e2 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -2,6 +2,7 @@\n #include \"config.h\"\n #include \"grep.h\"\n #include \"object-store.h\"\n+#include \"repository.h\"\n #include \"userdiff.h\"\n #include \"xdiff-interface.h\"\n #include \"diff.h\"\n@@ -2011,7 +2012,8 @@ static int grep_source_load_oid(struct grep_source *gs)\n \tenum object_type type;\n \n \tgrep_read_lock();\n-\tgs->buf = read_sha1_file(gs->identifier, &type, &gs->size);\n+\tgs->buf = read_sha1_file(the_repository, gs->identifier, &type,\n+\t\t\t\t &gs->size);\n \tgrep_read_unlock();\n \n \tif (!gs->buf)\ndiff --git a/http-push.c b/http-push.c\nindex 7cefc2df76..c7fa9ee15a 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -364,7 +364,8 @@ static void start_put(struct transfer_request *request)\n \tssize_t size;\n \tgit_zstream stream;\n \n-\tunpacked = read_sha1_file(request->obj->oid.hash, &type, &len);\n+\tunpacked = read_sha1_file(the_repository, request->obj->oid.hash,\n+\t\t\t\t  &type, &len);\n \thdrlen = xsnprintf(hdr, sizeof(hdr), \"%s %lu\", typename(type), len) + 1;\n \n \t/* Set it up */\ndiff --git a/mailmap.c b/mailmap.c\nindex 6afa9cc56d..1830e9d2a3 100644\n--- a/mailmap.c\n+++ b/mailmap.c\n@@ -2,6 +2,7 @@\n #include \"string-list.h\"\n #include \"mailmap.h\"\n #include \"object-store.h\"\n+#include \"repository.h\"\n \n #define DEBUG_MAILMAP 0\n #if DEBUG_MAILMAP\n@@ -225,7 +226,7 @@ static int read_mailmap_blob(struct string_list *map,\n \tif (get_oid(name, &oid) < 0)\n \t\treturn 0;\n \n-\tbuf = read_sha1_file(oid.hash, &type, &size);\n+\tbuf = read_sha1_file(the_repository, oid.hash, &type, &size);\n \tif (!buf)\n \t\treturn error(\"unable to read mailmap object at %s\", name);\n \tif (type != OBJ_BLOB)\ndiff --git a/match-trees.c b/match-trees.c\nindex bdfdfcaaab..af77d78e63 100644\n--- a/match-trees.c\n+++ b/match-trees.c\n@@ -2,6 +2,7 @@\n #include \"tree.h\"\n #include \"tree-walk.h\"\n #include \"object-store.h\"\n+#include \"repository.h\"\n \n static int score_missing(unsigned mode, const char *path)\n {\n@@ -55,7 +56,7 @@ static void *fill_tree_desc_strict(struct tree_desc *desc,\n \tenum object_type type;\n \tunsigned long size;\n \n-\tbuffer = read_sha1_file(hash->hash, &type, &size);\n+\tbuffer = read_sha1_file(the_repository, hash->hash, &type, &size);\n \tif (!buffer)\n \t\tdie(\"unable to read tree (%s)\", oid_to_hex(hash));\n \tif (type != OBJ_TREE)\n@@ -183,7 +184,7 @@ static int splice_tree(const unsigned char *hash1,\n \tif (*subpath)\n \t\tsubpath++;\n \n-\tbuf = read_sha1_file(hash1, &type, &sz);\n+\tbuf = read_sha1_file(the_repository, hash1, &type, &sz);\n \tif (!buf)\n \t\tdie(\"cannot read tree %s\", sha1_to_hex(hash1));\n \tinit_tree_desc(&desc, buf, sz);\ndiff --git a/merge-blobs.c b/merge-blobs.c\nindex f5e71bcd9b..4c69509bf8 100644\n--- a/merge-blobs.c\n+++ b/merge-blobs.c\n@@ -5,6 +5,7 @@\n #include \"blob.h\"\n #include \"merge-blobs.h\"\n #include \"object-store.h\"\n+#include \"repository.h\"\n \n static int fill_mmfile_blob(mmfile_t *f, struct blob *obj)\n {\n@@ -12,7 +13,8 @@ static int fill_mmfile_blob(mmfile_t *f, struct blob *obj)\n \tunsigned long size;\n \tenum object_type type;\n \n-\tbuf = read_sha1_file(obj->object.oid.hash, &type, &size);\n+\tbuf = read_sha1_file(the_repository, obj->object.oid.hash, &type,\n+\t\t\t     &size);\n \tif (!buf)\n \t\treturn -1;\n \tif (type != OBJ_BLOB) {\n@@ -67,7 +69,8 @@ void *merge_blobs(const char *path, struct blob *base, struct blob *our, struct\n \t\t\treturn NULL;\n \t\tif (!our)\n \t\t\tour = their;\n-\t\treturn read_sha1_file(our->object.oid.hash, &type, size);\n+\t\treturn read_sha1_file(the_repository, our->object.oid.hash,\n+\t\t\t\t      &type, size);\n \t}\n \n \tif (fill_mmfile_blob(&f1, our) < 0)\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 8b6984cdd7..0b4cb14773 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -825,7 +825,8 @@ static int update_file_flags(struct merge_options *o,\n \t\t\tgoto update_index;\n \t\t}\n \n-\t\tbuf = read_sha1_file(oid->hash, &type, &size);\n+\t\tbuf = read_sha1_file(the_repository, oid->hash, &type,\n+\t\t\t\t     &size);\n \t\tif (!buf)\n \t\t\treturn err(o, _(\"cannot read object %s '%s'\"), oid_to_hex(oid), path);\n \t\tif (type != OBJ_BLOB) {\n@@ -1629,7 +1630,7 @@ static int read_oid_strbuf(struct merge_options *o,\n \tvoid *buf;\n \tenum object_type type;\n \tunsigned long size;\n-\tbuf = read_sha1_file(oid->hash, &type, &size);\n+\tbuf = read_sha1_file(the_repository, oid->hash, &type, &size);\n \tif (!buf)\n \t\treturn err(o, _(\"cannot read object %s\"), oid_to_hex(oid));\n \tif (type != OBJ_BLOB) {\ndiff --git a/notes-cache.c b/notes-cache.c\nindex 6348baeb07..a4a6ccab97 100644\n--- a/notes-cache.c\n+++ b/notes-cache.c\n@@ -79,7 +79,8 @@ char *notes_cache_get(struct notes_cache *c, struct object_id *key_oid,\n \tvalue_oid = get_note(&c->tree, key_oid);\n \tif (!value_oid)\n \t\treturn NULL;\n-\tvalue = read_sha1_file(value_oid->hash, &type, &size);\n+\tvalue = read_sha1_file(the_repository, value_oid->hash, &type,\n+\t\t\t       &size);\n \n \t*outsize = size;\n \treturn value;\ndiff --git a/notes-merge.c b/notes-merge.c\nindex ea701827ba..02729fc474 100644\n--- a/notes-merge.c\n+++ b/notes-merge.c\n@@ -324,7 +324,7 @@ static void write_note_to_worktree(const struct object_id *obj,\n {\n \tenum object_type type;\n \tunsigned long size;\n-\tvoid *buf = read_sha1_file(note->hash, &type, &size);\n+\tvoid *buf = read_sha1_file(the_repository, note->hash, &type, &size);\n \n \tif (!buf)\n \t\tdie(\"cannot read note %s for object %s\",\ndiff --git a/notes.c b/notes.c\nindex b1478a8dca..369af2ee15 100644\n--- a/notes.c\n+++ b/notes.c\n@@ -2,6 +2,7 @@\n #include \"config.h\"\n #include \"notes.h\"\n #include \"object-store.h\"\n+#include \"repository.h\"\n #include \"blob.h\"\n #include \"tree.h\"\n #include \"utf8.h\"\n@@ -797,13 +798,15 @@ int combine_notes_concatenate(unsigned char *cur_sha1,\n \n \t/* read in both note blob objects */\n \tif (!is_null_sha1(new_sha1))\n-\t\tnew_msg = read_sha1_file(new_sha1, &new_type, &new_len);\n+\t\tnew_msg = read_sha1_file(the_repository, new_sha1, &new_type,\n+\t\t\t\t\t &new_len);\n \tif (!new_msg || !new_len || new_type != OBJ_BLOB) {\n \t\tfree(new_msg);\n \t\treturn 0;\n \t}\n \tif (!is_null_sha1(cur_sha1))\n-\t\tcur_msg = read_sha1_file(cur_sha1, &cur_type, &cur_len);\n+\t\tcur_msg = read_sha1_file(the_repository, cur_sha1, &cur_type,\n+\t\t\t\t\t &cur_len);\n \tif (!cur_msg || !cur_len || cur_type != OBJ_BLOB) {\n \t\tfree(cur_msg);\n \t\tfree(new_msg);\n@@ -859,7 +862,7 @@ static int string_list_add_note_lines(struct string_list *list,\n \t\treturn 0;\n \n \t/* read_sha1_file NUL-terminates */\n-\tdata = read_sha1_file(sha1, &t, &len);\n+\tdata = read_sha1_file(the_repository, sha1, &t, &len);\n \tif (t != OBJ_BLOB || !data || !len) {\n \t\tfree(data);\n \t\treturn t != OBJ_BLOB || !data;\n@@ -1217,7 +1220,7 @@ static void format_note(struct notes_tree *t, const struct object_id *object_oid\n \tif (!oid)\n \t\treturn;\n \n-\tif (!(msg = read_sha1_file(oid->hash, &type, &msglen)) || type != OBJ_BLOB) {\n+\tif (!(msg = read_sha1_file(the_repository, oid->hash, &type, &msglen)) || type != OBJ_BLOB) {\n \t\tfree(msg);\n \t\treturn;\n \t}\ndiff --git a/object-store.h b/object-store.h\nindex d6462cd9f1..974f2de78d 100644\n--- a/object-store.h\n+++ b/object-store.h\n@@ -86,7 +86,8 @@ struct packed_git {\n extern void *read_sha1_file_extended_the_repository(const unsigned char *sha1,\n \t\t\t\t     enum object_type *type,\n \t\t\t\t     unsigned long *size, int lookup_replace);\n-static inline void *read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size)\n+#define read_sha1_file(r, s, t, sz) read_sha1_file_##r(s, t, sz)\n+static inline void *read_sha1_file_the_repository(const unsigned char *sha1, enum object_type *type, unsigned long *size)\n {\n \treturn read_sha1_file_extended(the_repository, sha1, type, size, 1);\n }\ndiff --git a/object.c b/object.c\nindex 85b0360e0a..28f536dcae 100644\n--- a/object.c\n+++ b/object.c\n@@ -268,7 +268,7 @@ struct object *parse_object_the_repository(const struct object_id *oid)\n \t\treturn lookup_object(the_repository, oid->hash);\n \t}\n \n-\tbuffer = read_sha1_file(oid->hash, &type, &size);\n+\tbuffer = read_sha1_file(the_repository, oid->hash, &type, &size);\n \tif (buffer) {\n \t\tif (check_sha1_signature(the_repository, repl, buffer, size, typename(type)) < 0) {\n \t\t\tfree(buffer);\ndiff --git a/read-cache.c b/read-cache.c\nindex 45cad9272a..0df9c2d7b7 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -12,6 +12,7 @@\n #include \"refs.h\"\n #include \"dir.h\"\n #include \"object-store.h\"\n+#include \"repository.h\"\n #include \"tree.h\"\n #include \"commit.h\"\n #include \"blob.h\"\n@@ -185,7 +186,7 @@ static int ce_compare_link(const struct cache_entry *ce, size_t expected_size)\n \tif (strbuf_readlink(&sb, ce->name, expected_size))\n \t\treturn -1;\n \n-\tbuffer = read_sha1_file(ce->oid.hash, &type, &size);\n+\tbuffer = read_sha1_file(the_repository, ce->oid.hash, &type, &size);\n \tif (buffer) {\n \t\tif (size == sb.len)\n \t\t\tmatch = memcmp(buffer, sb.buf, size);\n@@ -2671,7 +2672,8 @@ void *read_blob_data_from_index(const struct index_state *istate,\n \t}\n \tif (pos < 0)\n \t\treturn NULL;\n-\tdata = read_sha1_file(istate->cache[pos]->oid.hash, &type, &sz);\n+\tdata = read_sha1_file(the_repository, istate->cache[pos]->oid.hash,\n+\t\t\t      &type, &sz);\n \tif (!data || type != OBJ_BLOB) {\n \t\tfree(data);\n \t\treturn NULL;\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 256887b585..32e2c1cbfc 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -730,7 +730,7 @@ int verify_ref_format(struct ref_format *format)\n static void *get_obj(const struct object_id *oid, struct object **obj, unsigned long *sz, int *eaten)\n {\n \tenum object_type type;\n-\tvoid *buf = read_sha1_file(oid->hash, &type, sz);\n+\tvoid *buf = read_sha1_file(the_repository, oid->hash, &type, sz);\n \n \tif (buf)\n \t\t*obj = parse_object_buffer(the_repository, oid, type, *sz,\ndiff --git a/remote-testsvn.c b/remote-testsvn.c\nindex 387d4ae935..d27cdce87f 100644\n--- a/remote-testsvn.c\n+++ b/remote-testsvn.c\n@@ -2,6 +2,7 @@\n #include \"refs.h\"\n #include \"remote.h\"\n #include \"object-store.h\"\n+#include \"repository.h\"\n #include \"strbuf.h\"\n #include \"url.h\"\n #include \"exec_cmd.h\"\n@@ -62,7 +63,7 @@ static char *read_ref_note(const struct object_id *oid)\n \tinit_notes(NULL, notes_ref, NULL, 0);\n \tif (!(note_oid = get_note(NULL, oid)))\n \t\treturn NULL;\t/* note tree not found */\n-\tif (!(msg = read_sha1_file(note_oid->hash, &type, &msglen)))\n+\tif (!(msg = read_sha1_file(the_repository, note_oid->hash, &type, &msglen)))\n \t\terror(\"Empty notes tree. %s\", notes_ref);\n \telse if (!msglen || type != OBJ_BLOB) {\n \t\terror(\"Note contains unusable content. \"\n@@ -109,7 +110,7 @@ static int note2mark_cb(const struct object_id *object_oid,\n \tenum object_type type;\n \tstruct rev_note note;\n \n-\tif (!(msg = read_sha1_file(note_oid->hash, &type, &msglen)) ||\n+\tif (!(msg = read_sha1_file(the_repository, note_oid->hash, &type, &msglen)) ||\n \t\t\t!msglen || type != OBJ_BLOB) {\n \t\tfree(msg);\n \t\treturn 1;\ndiff --git a/rerere.c b/rerere.c\nindex ab64d3f48e..30ca5fa56d 100644\n--- a/rerere.c\n+++ b/rerere.c\n@@ -10,6 +10,7 @@\n #include \"attr.h\"\n #include \"pathspec.h\"\n #include \"object-store.h\"\n+#include \"repository.h\"\n #include \"sha1-lookup.h\"\n \n #define RESOLVED 0\n@@ -982,7 +983,8 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu\n \t\t\tbreak;\n \t\ti = ce_stage(ce) - 1;\n \t\tif (!mmfile[i].ptr) {\n-\t\t\tmmfile[i].ptr = read_sha1_file(ce->oid.hash, &type,\n+\t\t\tmmfile[i].ptr = read_sha1_file(the_repository,\n+\t\t\t\t\t\t       ce->oid.hash, &type,\n \t\t\t\t\t\t       &size);\n \t\t\tmmfile[i].size = size;\n \t\t}\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 2d9a794654..ca567b64d6 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -1409,7 +1409,8 @@ void *read_object_with_reference(const unsigned char *sha1,\n \t\tint ref_length = -1;\n \t\tconst char *ref_type = NULL;\n \n-\t\tbuffer = read_sha1_file(actual_sha1, &type, &isize);\n+\t\tbuffer = read_sha1_file(the_repository, actual_sha1, &type,\n+\t\t\t\t\t&isize);\n \t\tif (!buffer)\n \t\t\treturn NULL;\n \t\tif (type == required_type) {\ndiff --git a/submodule-config.c b/submodule-config.c\nindex 2aa8a1747f..cac5f0ac52 100644\n--- a/submodule-config.c\n+++ b/submodule-config.c\n@@ -520,7 +520,8 @@ static const struct submodule *config_from(struct submodule_cache *cache,\n \tif (submodule)\n \t\tgoto out;\n \n-\tconfig = read_sha1_file(oid.hash, &type, &config_size);\n+\tconfig = read_sha1_file(the_repository, oid.hash, &type,\n+\t\t\t\t&config_size);\n \tif (!config || type != OBJ_BLOB)\n \t\tgoto out;\n \ndiff --git a/tag.c b/tag.c\nindex da2fe4f2ee..e2fd31ffc7 100644\n--- a/tag.c\n+++ b/tag.c\n@@ -51,7 +51,7 @@ int gpg_verify_tag(const struct object_id *oid, const char *name_to_report,\n \t\t\t\tfind_unique_abbrev(oid->hash, DEFAULT_ABBREV),\n \t\t\t\ttypename(type));\n \n-\tbuf = read_sha1_file(oid->hash, &type, &size);\n+\tbuf = read_sha1_file(the_repository, oid->hash, &type, &size);\n \tif (!buf)\n \t\treturn error(\"%s: unable to read file.\",\n \t\t\t\tname_to_report ?\n@@ -186,7 +186,8 @@ int parse_tag(struct tag *item)\n \n \tif (item->object.parsed)\n \t\treturn 0;\n-\tdata = read_sha1_file(item->object.oid.hash, &type, &size);\n+\tdata = read_sha1_file(the_repository, item->object.oid.hash, &type,\n+\t\t\t      &size);\n \tif (!data)\n \t\treturn error(\"Could not read %s\",\n \t\t\t     oid_to_hex(&item->object.oid));\ndiff --git a/tree-walk.c b/tree-walk.c\nindex 8bd56eddd5..1fa979d146 100644\n--- a/tree-walk.c\n+++ b/tree-walk.c\n@@ -3,6 +3,7 @@\n #include \"unpack-trees.h\"\n #include \"dir.h\"\n #include \"object-store.h\"\n+#include \"repository.h\"\n #include \"tree.h\"\n #include \"pathspec.h\"\n \n@@ -715,7 +716,8 @@ enum follow_symlinks_result get_tree_entry_follow_symlinks(unsigned char *tree_s\n \t\t\t */\n \t\t\tretval = DANGLING_SYMLINK;\n \n-\t\t\tcontents = read_sha1_file(current_tree_sha1, &type,\n+\t\t\tcontents = read_sha1_file(the_repository,\n+\t\t\t\t\t\t  current_tree_sha1, &type,\n \t\t\t\t\t\t  &link_len);\n \n \t\t\tif (!contents)\ndiff --git a/tree.c b/tree.c\nindex 6e0aafa805..f1c4e937c8 100644\n--- a/tree.c\n+++ b/tree.c\n@@ -222,7 +222,8 @@ int parse_tree_gently(struct tree *item, int quiet_on_missing)\n \n \tif (item->object.parsed)\n \t\treturn 0;\n-\tbuffer = read_sha1_file(item->object.oid.hash, &type, &size);\n+\tbuffer = read_sha1_file(the_repository, item->object.oid.hash, &type,\n+\t\t\t\t&size);\n \tif (!buffer)\n \t\treturn quiet_on_missing ? -1 :\n \t\t\terror(\"Could not read %s\",\ndiff --git a/xdiff-interface.c b/xdiff-interface.c\nindex a2d0e05edd..22bbe92584 100644\n--- a/xdiff-interface.c\n+++ b/xdiff-interface.c\n@@ -1,6 +1,7 @@\n #include \"cache.h\"\n #include \"config.h\"\n #include \"object-store.h\"\n+#include \"repository.h\"\n #include \"xdiff-interface.h\"\n #include \"xdiff/xtypes.h\"\n #include \"xdiff/xdiffi.h\"\n@@ -192,7 +193,7 @@ void read_mmblob(mmfile_t *ptr, const struct object_id *oid)\n \t\treturn;\n \t}\n \n-\tptr->ptr = read_sha1_file(oid->hash, &type, &size);\n+\tptr->ptr = read_sha1_file(the_repository, oid->hash, &type, &size);\n \tif (!ptr->ptr || type != OBJ_BLOB)\n \t\tdie(\"unable to read blob object %s\", oid_to_hex(oid));\n \tptr->size = size;\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338381","messageId":"20180206001749.218943-16-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 114/194] object: move read_object_with_reference to object.h","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:29Z","receivedAt":"2018-02-06T00:20:27Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nThis should make the function easier to find, alongside other\nfunctions that parse and act on the content of objects.\n\nWhile at it, add a comment describing the function's API.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n cache.h  |  5 -----\n object.h | 16 ++++++++++++++++\n 2 files changed, 16 insertions(+), 5 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 15ba480ac3..89422e7976 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1351,11 +1351,6 @@ extern int df_name_compare(const char *name1, int len1, int mode1, const char *n\n extern int name_compare(const char *name1, size_t len1, const char *name2, size_t len2);\n extern int cache_name_stage_compare(const char *name1, int len1, int stage1, const char *name2, int len2, int stage2);\n \n-extern void *read_object_with_reference(const unsigned char *sha1,\n-\t\t\t\t\tconst char *required_type,\n-\t\t\t\t\tunsigned long *size,\n-\t\t\t\t\tunsigned char *sha1_ret);\n-\n extern struct object *peel_to_type(const char *name, int namelen,\n \t\t\t\t   struct object *o, enum object_type);\n \ndiff --git a/object.h b/object.h\nindex c9ea2285e8..d676404f00 100644\n--- a/object.h\n+++ b/object.h\n@@ -108,6 +108,22 @@ extern void *create_object(struct repository *r, const unsigned char *sha1, void\n \n void *object_as_type(struct object *obj, enum object_type type, int quiet);\n \n+/*\n+ * Resolves 'sha1' to an object of the specified type and returns the\n+ * raw content of the resulting object.\n+ *\n+ * For example, with required_type == OBJ_TREE, this can be passed a\n+ * tree, commit, or tag object id to get the raw tree object pointed\n+ * to by the named object.\n+ *\n+ * Returns NULL if 'sha1' can not be peeled to an object of the\n+ * specified type.\n+ */\n+extern void *read_object_with_reference(const unsigned char *sha1,\n+\t\t\t\t\tconst char *required_type,\n+\t\t\t\t\tunsigned long *size,\n+\t\t\t\t\tunsigned char *sha1_ret);\n+\n /*\n  * Returns the object, having parsed it to find out what it is.\n  *\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338382","messageId":"20180206001749.218943-17-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 115/194] packfile: add repository argument to has_packed_and_bad","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:30Z","receivedAt":"2018-02-06T00:20:29Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow the callers of has_packed_and_bad\nto be more specific about which repository to act on. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nAdd the cocci patch that converted the callers.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n packfile.c  | 2 +-\n packfile.h  | 4 +++-\n sha1_file.c | 2 +-\n 3 files changed, 5 insertions(+), 3 deletions(-)\n\ndiff --git a/packfile.c b/packfile.c\nindex f7e8a81ded..28453739b2 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -1004,7 +1004,7 @@ void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1)\n \tp->num_bad_objects++;\n }\n \n-const struct packed_git *has_packed_and_bad(const unsigned char *sha1)\n+const struct packed_git *has_packed_and_bad_the_repository(const unsigned char *sha1)\n {\n \tstruct packed_git *p;\n \tunsigned i;\ndiff --git a/packfile.h b/packfile.h\nindex f8d2825cce..b5122d455e 100644\n--- a/packfile.h\n+++ b/packfile.h\n@@ -140,7 +140,9 @@ extern int packed_object_info(struct repository *r,\n \t\t\t      off_t offset, struct object_info *);\n \n extern void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1);\n-extern const struct packed_git *has_packed_and_bad(const unsigned char *sha1);\n+\n+#define has_packed_and_bad(r, s) has_packed_and_bad_##r(s)\n+extern const struct packed_git *has_packed_and_bad_the_repository(const unsigned char *sha1);\n \n extern int find_pack_entry(struct repository *r,\n \t\t\t   const unsigned char *sha1,\ndiff --git a/sha1_file.c b/sha1_file.c\nindex ca567b64d6..e1427c0982 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -1386,7 +1386,7 @@ void *read_sha1_file_extended_the_repository(const unsigned char *sha1,\n \t\tdie(\"loose object %s (stored in %s) is corrupt\",\n \t\t    sha1_to_hex(repl), path);\n \n-\tif ((p = has_packed_and_bad(repl)) != NULL)\n+\tif ((p = has_packed_and_bad(the_repository, repl)) != NULL)\n \t\tdie(\"packed object %s (stored in %s) is corrupt\",\n \t\t    sha1_to_hex(repl), p->pack_name);\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338383","messageId":"20180206001749.218943-18-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 116/194] packfile: allow has_packed_and_bad to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:31Z","receivedAt":"2018-02-06T00:20:32Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n packfile.c | 4 ++--\n packfile.h | 3 +--\n 2 files changed, 3 insertions(+), 4 deletions(-)\n\ndiff --git a/packfile.c b/packfile.c\nindex 28453739b2..21ca15b1ce 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -1004,12 +1004,12 @@ void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1)\n \tp->num_bad_objects++;\n }\n \n-const struct packed_git *has_packed_and_bad_the_repository(const unsigned char *sha1)\n+const struct packed_git *has_packed_and_bad(struct repository *r, const unsigned char *sha1)\n {\n \tstruct packed_git *p;\n \tunsigned i;\n \n-\tfor (p = the_repository->objects.packed_git; p; p = p->next)\n+\tfor (p = r->objects.packed_git; p; p = p->next)\n \t\tfor (i = 0; i < p->num_bad_objects; i++)\n \t\t\tif (!hashcmp(sha1, p->bad_object_sha1 + 20 * i))\n \t\t\t\treturn p;\ndiff --git a/packfile.h b/packfile.h\nindex b5122d455e..42593940b0 100644\n--- a/packfile.h\n+++ b/packfile.h\n@@ -141,8 +141,7 @@ extern int packed_object_info(struct repository *r,\n \n extern void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1);\n \n-#define has_packed_and_bad(r, s) has_packed_and_bad_##r(s)\n-extern const struct packed_git *has_packed_and_bad_the_repository(const unsigned char *sha1);\n+extern const struct packed_git *has_packed_and_bad(struct repository *r, const unsigned char *sha1);\n \n extern int find_pack_entry(struct repository *r,\n \t\t\t   const unsigned char *sha1,\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338384","messageId":"20180206001749.218943-19-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 117/194] streaming: add repository argument to open_istream_fn","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:32Z","receivedAt":"2018-02-06T00:20:56Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow the callers of open_istream_fn\nto be more specific about which repository to act on. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nUnlike the previous commits, this uses a run time check to make sure\nthe passed repository is the_repository instead of a compile time check.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n streaming.c | 20 ++++++++++++++++----\n 1 file changed, 16 insertions(+), 4 deletions(-)\n\ndiff --git a/streaming.c b/streaming.c\nindex f0ff5e7245..8c1e1a1601 100644\n--- a/streaming.c\n+++ b/streaming.c\n@@ -15,7 +15,8 @@ enum input_source {\n \tpack_non_delta = 2\n };\n \n-typedef int (*open_istream_fn)(struct git_istream *,\n+typedef int (*open_istream_fn)(struct repository *,\n+\t\t\t       struct git_istream *,\n \t\t\t       struct object_info *,\n \t\t\t       const unsigned char *,\n \t\t\t       enum object_type *);\n@@ -29,7 +30,9 @@ struct stream_vtbl {\n \n #define open_method_decl(name) \\\n \tint open_istream_ ##name \\\n-\t(struct git_istream *st, struct object_info *oi, \\\n+\t(struct repository *r, \\\n+\t struct git_istream *st, \\\n+\t struct object_info *oi, \\\n \t const unsigned char *sha1, \\\n \t enum object_type *type)\n \n@@ -147,8 +150,8 @@ struct git_istream *open_istream(const unsigned char *sha1,\n \t\treturn NULL;\n \n \tst = xmalloc(sizeof(*st));\n-\tif (open_istream_tbl[src](st, &oi, real, type)) {\n-\t\tif (open_istream_incore(st, &oi, real, type)) {\n+\tif (open_istream_tbl[src](the_repository, st, &oi, real, type)) {\n+\t\tif (open_istream_incore(the_repository, st, &oi, real, type)) {\n \t\t\tfree(st);\n \t\t\treturn NULL;\n \t\t}\n@@ -338,6 +341,9 @@ static struct stream_vtbl loose_vtbl = {\n \n static open_method_decl(loose)\n {\n+\tif (r != the_repository)\n+\t\tBUG(\"r != the_repository\");\n+\n \tst->u.loose.mapped = map_sha1_file(the_repository,\n \t\t\t\t\t   sha1, &st->u.loose.mapsize);\n \tif (!st->u.loose.mapped)\n@@ -433,6 +439,9 @@ static open_method_decl(pack_non_delta)\n \tstruct pack_window *window;\n \tenum object_type in_pack_type;\n \n+\tif (r != the_repository)\n+\t\tBUG(\"r != the_repository\");\n+\n \tst->u.in_pack.pack = oi->u.packed.pack;\n \tst->u.in_pack.pos = oi->u.packed.offset;\n \twindow = NULL;\n@@ -490,6 +499,9 @@ static struct stream_vtbl incore_vtbl = {\n \n static open_method_decl(incore)\n {\n+\tif (r != the_repository)\n+\t\tBUG(\"r != the_repository\");\n+\n \tst->u.incore.buf = read_sha1_file_extended(the_repository, sha1,\n \t\t\t\t\t\t   type, &st->size, 0);\n \tst->u.incore.read_ptr = 0;\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338385","messageId":"20180206001749.218943-21-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 119/194] streaming: add repository argument to istream_source","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:34Z","receivedAt":"2018-02-06T00:21:00Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow the callers of istream_source\nto be more specific about which repository to act on. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n streaming.c | 5 +++--\n 1 file changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/streaming.c b/streaming.c\nindex 90acf7448f..5d2c24798e 100644\n--- a/streaming.c\n+++ b/streaming.c\n@@ -111,7 +111,8 @@ ssize_t read_istream(struct git_istream *st, void *buf, size_t sz)\n \treturn st->vtbl->read(st, buf, sz);\n }\n \n-static enum input_source istream_source(const unsigned char *sha1,\n+#define istream_source(r, s, t, o) istream_source_##r(s, t, o)\n+static enum input_source istream_source_the_repository(const unsigned char *sha1,\n \t\t\t\t\tenum object_type *type,\n \t\t\t\t\tstruct object_info *oi)\n {\n@@ -144,7 +145,7 @@ struct git_istream *open_istream_the_repository(const unsigned char *sha1,\n \tstruct git_istream *st;\n \tstruct object_info oi = OBJECT_INFO_INIT;\n \tconst unsigned char *real = lookup_replace_object(the_repository, sha1);\n-\tenum input_source src = istream_source(real, type, &oi);\n+\tenum input_source src = istream_source(the_repository, real, type, &oi);\n \n \tif (src < 0)\n \t\treturn NULL;\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338386","messageId":"20180206001749.218943-22-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 120/194] streaming: allow istream_source to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:35Z","receivedAt":"2018-02-06T00:21:25Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n streaming.c | 6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/streaming.c b/streaming.c\nindex 5d2c24798e..cb7f8b2042 100644\n--- a/streaming.c\n+++ b/streaming.c\n@@ -111,8 +111,8 @@ ssize_t read_istream(struct git_istream *st, void *buf, size_t sz)\n \treturn st->vtbl->read(st, buf, sz);\n }\n \n-#define istream_source(r, s, t, o) istream_source_##r(s, t, o)\n-static enum input_source istream_source_the_repository(const unsigned char *sha1,\n+static enum input_source istream_source(struct repository *r,\n+\t\t\t\t\tconst unsigned char *sha1,\n \t\t\t\t\tenum object_type *type,\n \t\t\t\t\tstruct object_info *oi)\n {\n@@ -121,7 +121,7 @@ static enum input_source istream_source_the_repository(const unsigned char *sha1\n \n \toi->typep = type;\n \toi->sizep = &size;\n-\tstatus = sha1_object_info_extended(the_repository, sha1, oi, 0);\n+\tstatus = sha1_object_info_extended(r, sha1, oi, 0);\n \tif (status < 0)\n \t\treturn stream_error;\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338387","messageId":"20180206001749.218943-23-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 121/194] sha1_file: allow read_object to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:36Z","receivedAt":"2018-02-06T00:21:27Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n sha1_file.c | 7 +++----\n 1 file changed, 3 insertions(+), 4 deletions(-)\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex a5ad67143d..6164ba29c5 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -1319,9 +1319,8 @@ int sha1_object_info(struct repository *r,\n \treturn type;\n }\n \n-#define read_object(r, s, t, sz) read_object_##r(s, t, sz)\n-static void *read_object_the_repository(const unsigned char *sha1, enum object_type *type,\n-\t\t\t unsigned long *size)\n+static void *read_object(struct repository *r, const unsigned char *sha1,\n+\t\t\t enum object_type *type, unsigned long *size)\n {\n \tstruct object_info oi = OBJECT_INFO_INIT;\n \tvoid *content;\n@@ -1329,7 +1328,7 @@ static void *read_object_the_repository(const unsigned char *sha1, enum object_t\n \toi.sizep = size;\n \toi.contentp = &content;\n \n-\tif (sha1_object_info_extended(the_repository, sha1, &oi, 0) < 0)\n+\tif (sha1_object_info_extended(r, sha1, &oi, 0) < 0)\n \t\treturn NULL;\n \treturn content;\n }\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338388","messageId":"20180206001749.218943-24-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 122/194] object-store.h: allow read_sha1_file{_extended} to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:37Z","receivedAt":"2018-02-06T00:21:30Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n object-store.h | 10 +++++-----\n sha1_file.c    | 11 ++++++-----\n 2 files changed, 11 insertions(+), 10 deletions(-)\n\ndiff --git a/object-store.h b/object-store.h\nindex 974f2de78d..47c38170e3 100644\n--- a/object-store.h\n+++ b/object-store.h\n@@ -82,14 +82,14 @@ struct packed_git {\n \tchar pack_name[FLEX_ARRAY]; /* more */\n };\n \n-#define read_sha1_file_extended(r, s, t, sz, l) read_sha1_file_extended_##r(s, t, sz, l)\n-extern void *read_sha1_file_extended_the_repository(const unsigned char *sha1,\n+extern void *read_sha1_file_extended(struct repository *r,\n+\t\t\t\t     const unsigned char *sha1,\n \t\t\t\t     enum object_type *type,\n \t\t\t\t     unsigned long *size, int lookup_replace);\n-#define read_sha1_file(r, s, t, sz) read_sha1_file_##r(s, t, sz)\n-static inline void *read_sha1_file_the_repository(const unsigned char *sha1, enum object_type *type, unsigned long *size)\n+\n+static inline void *read_sha1_file(struct repository *r, const unsigned char *sha1, enum object_type *type, unsigned long *size)\n {\n-\treturn read_sha1_file_extended(the_repository, sha1, type, size, 1);\n+\treturn read_sha1_file_extended(r, sha1, type, size, 1);\n }\n \n /* Read and unpack a sha1 file into memory, write memory to a sha1 file */\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 6164ba29c5..743ada360d 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -1356,7 +1356,8 @@ int pretend_sha1_file(void *buf, unsigned long len, enum object_type type,\n  * deal with them should arrange to call read_object() and give error\n  * messages themselves.\n  */\n-void *read_sha1_file_extended_the_repository(const unsigned char *sha1,\n+void *read_sha1_file_extended(struct repository *r,\n+\t\t\t      const unsigned char *sha1,\n \t\t\t      enum object_type *type,\n \t\t\t      unsigned long *size,\n \t\t\t      int lookup_replace)\n@@ -1366,10 +1367,10 @@ void *read_sha1_file_extended_the_repository(const unsigned char *sha1,\n \tconst char *path;\n \tstruct stat st;\n \tconst unsigned char *repl = lookup_replace ?\n-\t\tlookup_replace_object(the_repository, sha1) : sha1;\n+\t\tlookup_replace_object(r, sha1) : sha1;\n \n \terrno = 0;\n-\tdata = read_object(the_repository, repl, type, size);\n+\tdata = read_object(r, repl, type, size);\n \tif (data)\n \t\treturn data;\n \n@@ -1381,11 +1382,11 @@ void *read_sha1_file_extended_the_repository(const unsigned char *sha1,\n \t\tdie(\"replacement %s not found for %s\",\n \t\t    sha1_to_hex(repl), sha1_to_hex(sha1));\n \n-\tif (!stat_sha1_file(the_repository, repl, &st, &path))\n+\tif (!stat_sha1_file(r, repl, &st, &path))\n \t\tdie(\"loose object %s (stored in %s) is corrupt\",\n \t\t    sha1_to_hex(repl), path);\n \n-\tif ((p = has_packed_and_bad(the_repository, repl)) != NULL)\n+\tif ((p = has_packed_and_bad(r, repl)) != NULL)\n \t\tdie(\"packed object %s (stored in %s) is corrupt\",\n \t\t    sha1_to_hex(repl), p->pack_name);\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338389","messageId":"20180206001749.218943-25-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 123/194] streaming: allow open_istream_incore to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:38Z","receivedAt":"2018-02-06T00:21:54Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n streaming.c | 5 +----\n 1 file changed, 1 insertion(+), 4 deletions(-)\n\ndiff --git a/streaming.c b/streaming.c\nindex cb7f8b2042..94651ffbf0 100644\n--- a/streaming.c\n+++ b/streaming.c\n@@ -500,10 +500,7 @@ static struct stream_vtbl incore_vtbl = {\n \n static open_method_decl(incore)\n {\n-\tif (r != the_repository)\n-\t\tBUG(\"r != the_repository\");\n-\n-\tst->u.incore.buf = read_sha1_file_extended(the_repository, sha1,\n+\tst->u.incore.buf = read_sha1_file_extended(r, sha1,\n \t\t\t\t\t\t   type, &st->size, 0);\n \tst->u.incore.read_ptr = 0;\n \tst->vtbl = &incore_vtbl;\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338390","messageId":"20180206001749.218943-26-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 124/194] streaming: allow open_istream_pack_non_delta to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:39Z","receivedAt":"2018-02-06T00:21:56Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n streaming.c | 3 ---\n 1 file changed, 3 deletions(-)\n\ndiff --git a/streaming.c b/streaming.c\nindex 94651ffbf0..21bd069315 100644\n--- a/streaming.c\n+++ b/streaming.c\n@@ -440,9 +440,6 @@ static open_method_decl(pack_non_delta)\n \tstruct pack_window *window;\n \tenum object_type in_pack_type;\n \n-\tif (r != the_repository)\n-\t\tBUG(\"r != the_repository\");\n-\n \tst->u.in_pack.pack = oi->u.packed.pack;\n \tst->u.in_pack.pos = oi->u.packed.offset;\n \twindow = NULL;\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338391","messageId":"20180206001749.218943-27-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 125/194] streaming: allow open_istream_loose to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:40Z","receivedAt":"2018-02-06T00:21:58Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n streaming.c | 6 +-----\n 1 file changed, 1 insertion(+), 5 deletions(-)\n\ndiff --git a/streaming.c b/streaming.c\nindex 21bd069315..cd52f517eb 100644\n--- a/streaming.c\n+++ b/streaming.c\n@@ -342,11 +342,7 @@ static struct stream_vtbl loose_vtbl = {\n \n static open_method_decl(loose)\n {\n-\tif (r != the_repository)\n-\t\tBUG(\"r != the_repository\");\n-\n-\tst->u.loose.mapped = map_sha1_file(the_repository,\n-\t\t\t\t\t   sha1, &st->u.loose.mapsize);\n+\tst->u.loose.mapped = map_sha1_file(r, sha1, &st->u.loose.mapsize);\n \tif (!st->u.loose.mapped)\n \t\treturn -1;\n \tif ((unpack_sha1_header(&st->z,\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338392","messageId":"20180206001749.218943-28-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 126/194] streaming: allow open_istream to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:41Z","receivedAt":"2018-02-06T00:22:22Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n streaming.c | 11 ++++++-----\n streaming.h |  3 +--\n 2 files changed, 7 insertions(+), 7 deletions(-)\n\ndiff --git a/streaming.c b/streaming.c\nindex cd52f517eb..2373395afe 100644\n--- a/streaming.c\n+++ b/streaming.c\n@@ -137,22 +137,23 @@ static enum input_source istream_source(struct repository *r,\n \t}\n }\n \n-struct git_istream *open_istream_the_repository(const unsigned char *sha1,\n+struct git_istream *open_istream(struct repository *r,\n+\t\t\t\t const unsigned char *sha1,\n \t\t\t\t enum object_type *type,\n \t\t\t\t unsigned long *size,\n \t\t\t\t struct stream_filter *filter)\n {\n \tstruct git_istream *st;\n \tstruct object_info oi = OBJECT_INFO_INIT;\n-\tconst unsigned char *real = lookup_replace_object(the_repository, sha1);\n-\tenum input_source src = istream_source(the_repository, real, type, &oi);\n+\tconst unsigned char *real = lookup_replace_object(r, sha1);\n+\tenum input_source src = istream_source(r, real, type, &oi);\n \n \tif (src < 0)\n \t\treturn NULL;\n \n \tst = xmalloc(sizeof(*st));\n-\tif (open_istream_tbl[src](the_repository, st, &oi, real, type)) {\n-\t\tif (open_istream_incore(the_repository, st, &oi, real, type)) {\n+\tif (open_istream_tbl[src](r, st, &oi, real, type)) {\n+\t\tif (open_istream_incore(r, st, &oi, real, type)) {\n \t\t\tfree(st);\n \t\t\treturn NULL;\n \t\t}\ndiff --git a/streaming.h b/streaming.h\nindex 9f4d5aeee2..cb36ce4c02 100644\n--- a/streaming.h\n+++ b/streaming.h\n@@ -8,8 +8,7 @@\n /* opaque */\n struct git_istream;\n \n-#define open_istream(r, s, t, sz, f) open_istream_##r(s, t, sz, f)\n-extern struct git_istream *open_istream_the_repository(const unsigned char *, enum object_type *, unsigned long *, struct stream_filter *);\n+extern struct git_istream *open_istream(struct repository *, const unsigned char *, enum object_type *, unsigned long *, struct stream_filter *);\n extern int close_istream(struct git_istream *);\n extern ssize_t read_istream(struct git_istream *, void *, size_t);\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338393","messageId":"20180206001749.218943-29-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 127/194] alternates: convert add_to_alternates_memory to handle arbitrary repos","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:42Z","receivedAt":"2018-02-06T00:22:25Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n alternates.h | 3 +--\n sha1_file.c  | 7 +++----\n tmp-objdir.c | 1 +\n 3 files changed, 5 insertions(+), 6 deletions(-)\n\ndiff --git a/alternates.h b/alternates.h\nindex e4520ae5c7..b3d8d57ba4 100644\n--- a/alternates.h\n+++ b/alternates.h\n@@ -56,8 +56,7 @@ extern void add_to_alternates_file_the_repository(const char *dir);\n  * recursive alternates it points to), but do not modify the on-disk alternates\n  * file.\n  */\n-#define add_to_alternates_memory(r, d) add_to_alternates_memory_##r(d)\n-extern void add_to_alternates_memory_the_repository(const char *dir);\n+extern void add_to_alternates_memory(struct repository *r, const char *dir);\n \n /*\n  * Returns a scratch strbuf pre-filled with the alternate object directory,\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 743ada360d..3c39e34c72 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -581,16 +581,15 @@ void add_to_alternates_file_the_repository(const char *reference)\n \tfree(alts);\n }\n \n-void add_to_alternates_memory_the_repository(const char *reference)\n+void add_to_alternates_memory(struct repository *r, const char *reference)\n {\n \t/*\n \t * Make sure alternates are initialized, or else our entry may be\n \t * overwritten when they are.\n \t */\n-\tprepare_alt_odb(the_repository);\n+\tprepare_alt_odb(r);\n \n-\tlink_alt_odb_entries(the_repository, reference,\n-\t\t\t     '\\n', NULL, 0);\n+\tlink_alt_odb_entries(r, reference, '\\n', NULL, 0);\n }\n \n /*\ndiff --git a/tmp-objdir.c b/tmp-objdir.c\nindex a9334d3fc5..acd55680c8 100644\n--- a/tmp-objdir.c\n+++ b/tmp-objdir.c\n@@ -1,6 +1,7 @@\n #include \"cache.h\"\n #include \"tmp-objdir.h\"\n #include \"alternates.h\"\n+#include \"repository.h\"\n #include \"dir.h\"\n #include \"sigchain.h\"\n #include \"string-list.h\"\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338394","messageId":"20180206001749.218943-30-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 128/194] object: add repository argument to object_as_type","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:43Z","receivedAt":"2018-02-06T00:22:28Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n blob.c         | 2 +-\n builtin/fsck.c | 2 +-\n commit.c       | 4 ++--\n object.c       | 2 +-\n object.h       | 3 ++-\n refs.c         | 2 +-\n tag.c          | 2 +-\n tree.c         | 2 +-\n 8 files changed, 10 insertions(+), 9 deletions(-)\n\ndiff --git a/blob.c b/blob.c\nindex 25faf3e692..0c53cfce45 100644\n--- a/blob.c\n+++ b/blob.c\n@@ -10,7 +10,7 @@ struct blob *lookup_blob_the_repository(const struct object_id *oid)\n \tif (!obj)\n \t\treturn create_object(the_repository, oid->hash,\n \t\t\t\t     alloc_blob_node());\n-\treturn object_as_type(obj, OBJ_BLOB, 0);\n+\treturn object_as_type(the_repository, obj, OBJ_BLOB, 0);\n }\n \n int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size)\ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex 527c03eb39..2e8b298384 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -72,7 +72,7 @@ static const char *printable_type(struct object *obj)\n \t\tenum object_type type = sha1_object_info(the_repository,\n \t\t\t\t\t\t\t obj->oid.hash, NULL);\n \t\tif (type > 0)\n-\t\t\tobject_as_type(obj, type, 0);\n+\t\t\tobject_as_type(the_repository, obj, type, 0);\n \t}\n \n \tret = typename(obj->type);\ndiff --git a/commit.c b/commit.c\nindex 2fb702795c..953c537059 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -30,7 +30,7 @@ struct commit *lookup_commit_reference_gently_the_repository(\n \n \tif (!obj)\n \t\treturn NULL;\n-\treturn object_as_type(obj, OBJ_COMMIT, quiet);\n+\treturn object_as_type(the_repository, obj, OBJ_COMMIT, quiet);\n }\n \n struct commit *lookup_commit_reference_the_repository(const struct object_id *oid)\n@@ -56,7 +56,7 @@ struct commit *lookup_commit_the_repository(const struct object_id *oid)\n \tif (!obj)\n \t\treturn create_object(the_repository, oid->hash,\n \t\t\t\t     alloc_commit_node());\n-\treturn object_as_type(obj, OBJ_COMMIT, 0);\n+\treturn object_as_type(the_repository, obj, OBJ_COMMIT, 0);\n }\n \n struct commit *lookup_commit_reference_by_name(const char *name)\ndiff --git a/object.c b/object.c\nindex 28f536dcae..156fbae15e 100644\n--- a/object.c\n+++ b/object.c\n@@ -155,7 +155,7 @@ void *create_object(struct repository *r, const unsigned char *sha1, void *o)\n \treturn obj;\n }\n \n-void *object_as_type(struct object *obj, enum object_type type, int quiet)\n+void *object_as_type_the_repository(struct object *obj, enum object_type type, int quiet)\n {\n \tif (obj->type == type)\n \t\treturn obj;\ndiff --git a/object.h b/object.h\nindex d676404f00..a61d965700 100644\n--- a/object.h\n+++ b/object.h\n@@ -106,7 +106,8 @@ struct object *lookup_object(struct repository *r, const unsigned char *sha1);\n \n extern void *create_object(struct repository *r, const unsigned char *sha1, void *obj);\n \n-void *object_as_type(struct object *obj, enum object_type type, int quiet);\n+#define object_as_type(r, o, t, q) object_as_type_##r(o, t, q)\n+void *object_as_type_the_repository(struct object *obj, enum object_type type, int quiet);\n \n /*\n  * Resolves 'sha1' to an object of the specified type and returns the\ndiff --git a/refs.c b/refs.c\nindex 0ea9b05d03..24fa57b0f1 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -304,7 +304,7 @@ enum peel_status peel_object(const struct object_id *name, struct object_id *oid\n \n \tif (o->type == OBJ_NONE) {\n \t\tint type = sha1_object_info(the_repository, name->hash, NULL);\n-\t\tif (type < 0 || !object_as_type(o, type, 0))\n+\t\tif (type < 0 || !object_as_type(the_repository, o, type, 0))\n \t\t\treturn PEEL_INVALID;\n \t}\n \ndiff --git a/tag.c b/tag.c\nindex e2fd31ffc7..abba1b8d88 100644\n--- a/tag.c\n+++ b/tag.c\n@@ -98,7 +98,7 @@ struct tag *lookup_tag_the_repository(const struct object_id *oid)\n \tif (!obj)\n \t\treturn create_object(the_repository, oid->hash,\n \t\t\t\t     alloc_tag_node());\n-\treturn object_as_type(obj, OBJ_TAG, 0);\n+\treturn object_as_type(the_repository, obj, OBJ_TAG, 0);\n }\n \n static timestamp_t parse_tag_date(const char *buf, const char *tail)\ndiff --git a/tree.c b/tree.c\nindex f1c4e937c8..37fec8623b 100644\n--- a/tree.c\n+++ b/tree.c\n@@ -200,7 +200,7 @@ struct tree *lookup_tree_the_repository(const struct object_id *oid)\n \tif (!obj)\n \t\treturn create_object(the_repository, oid->hash,\n \t\t\t\t     alloc_tree_node());\n-\treturn object_as_type(obj, OBJ_TREE, 0);\n+\treturn object_as_type(the_repository, obj, OBJ_TREE, 0);\n }\n \n int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size)\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338395","messageId":"20180206001749.218943-31-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 129/194] alloc: add repository argument to alloc_blob_node","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:44Z","receivedAt":"2018-02-06T00:22:51Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n alloc.c | 2 +-\n blob.c  | 2 +-\n cache.h | 3 ++-\n 3 files changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/alloc.c b/alloc.c\nindex 12afadfacd..6c5c376a25 100644\n--- a/alloc.c\n+++ b/alloc.c\n@@ -49,7 +49,7 @@ static inline void *alloc_node(struct alloc_state *s, size_t node_size)\n }\n \n static struct alloc_state blob_state;\n-void *alloc_blob_node(void)\n+void *alloc_blob_node_the_repository(void)\n {\n \tstruct blob *b = alloc_node(&blob_state, sizeof(struct blob));\n \tb->object.type = OBJ_BLOB;\ndiff --git a/blob.c b/blob.c\nindex 0c53cfce45..7c661f178a 100644\n--- a/blob.c\n+++ b/blob.c\n@@ -9,7 +9,7 @@ struct blob *lookup_blob_the_repository(const struct object_id *oid)\n \tstruct object *obj = lookup_object(the_repository, oid->hash);\n \tif (!obj)\n \t\treturn create_object(the_repository, oid->hash,\n-\t\t\t\t     alloc_blob_node());\n+\t\t\t\t     alloc_blob_node(the_repository));\n \treturn object_as_type(the_repository, obj, OBJ_BLOB, 0);\n }\n \ndiff --git a/cache.h b/cache.h\nindex 89422e7976..6ee415d9f7 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1575,7 +1575,8 @@ int decode_85(char *dst, const char *line, int linelen);\n void encode_85(char *buf, const unsigned char *data, int bytes);\n \n /* alloc.c */\n-extern void *alloc_blob_node(void);\n+#define alloc_blob_node(r) alloc_blob_node_##r()\n+extern void *alloc_blob_node_the_repository(void);\n extern void *alloc_tree_node(void);\n extern void *alloc_commit_node(void);\n extern void *alloc_tag_node(void);\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338396","messageId":"20180206001749.218943-32-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 130/194] alloc: add repository argument to alloc_tree_node","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:45Z","receivedAt":"2018-02-06T00:22:54Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n alloc.c | 2 +-\n cache.h | 3 ++-\n tree.c  | 2 +-\n 3 files changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/alloc.c b/alloc.c\nindex 6c5c376a25..2c8d143075 100644\n--- a/alloc.c\n+++ b/alloc.c\n@@ -57,7 +57,7 @@ void *alloc_blob_node_the_repository(void)\n }\n \n static struct alloc_state tree_state;\n-void *alloc_tree_node(void)\n+void *alloc_tree_node_the_repository(void)\n {\n \tstruct tree *t = alloc_node(&tree_state, sizeof(struct tree));\n \tt->object.type = OBJ_TREE;\ndiff --git a/cache.h b/cache.h\nindex 6ee415d9f7..6a794aa903 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1577,7 +1577,8 @@ void encode_85(char *buf, const unsigned char *data, int bytes);\n /* alloc.c */\n #define alloc_blob_node(r) alloc_blob_node_##r()\n extern void *alloc_blob_node_the_repository(void);\n-extern void *alloc_tree_node(void);\n+#define alloc_tree_node(r) alloc_tree_node_##r()\n+extern void *alloc_tree_node_the_repository(void);\n extern void *alloc_commit_node(void);\n extern void *alloc_tag_node(void);\n extern void *alloc_object_node(void);\ndiff --git a/tree.c b/tree.c\nindex 37fec8623b..07cea88450 100644\n--- a/tree.c\n+++ b/tree.c\n@@ -199,7 +199,7 @@ struct tree *lookup_tree_the_repository(const struct object_id *oid)\n \tstruct object *obj = lookup_object(the_repository, oid->hash);\n \tif (!obj)\n \t\treturn create_object(the_repository, oid->hash,\n-\t\t\t\t     alloc_tree_node());\n+\t\t\t\t     alloc_tree_node(the_repository));\n \treturn object_as_type(the_repository, obj, OBJ_TREE, 0);\n }\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338397","messageId":"20180206001749.218943-33-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 131/194] alloc: add repository argument to alloc_commit_node","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:46Z","receivedAt":"2018-02-06T00:22:57Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n alloc.c           | 2 +-\n blame.c           | 2 +-\n cache.h           | 3 ++-\n commit.c          | 2 +-\n merge-recursive.c | 2 +-\n 5 files changed, 6 insertions(+), 5 deletions(-)\n\ndiff --git a/alloc.c b/alloc.c\nindex 2c8d143075..9e2b897ec1 100644\n--- a/alloc.c\n+++ b/alloc.c\n@@ -88,7 +88,7 @@ unsigned int alloc_commit_index(void)\n \treturn count++;\n }\n \n-void *alloc_commit_node(void)\n+void *alloc_commit_node_the_repository(void)\n {\n \tstruct commit *c = alloc_node(&commit_state, sizeof(struct commit));\n \tc->object.type = OBJ_COMMIT;\ndiff --git a/blame.c b/blame.c\nindex 8648a1ddff..592bedd0e0 100644\n--- a/blame.c\n+++ b/blame.c\n@@ -163,7 +163,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,\n \n \tread_cache();\n \ttime(&now);\n-\tcommit = alloc_commit_node();\n+\tcommit = alloc_commit_node(the_repository);\n \tcommit->object.parsed = 1;\n \tcommit->date = now;\n \tparent_tail = &commit->parents;\ndiff --git a/cache.h b/cache.h\nindex 6a794aa903..cb41e22123 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1579,7 +1579,8 @@ void encode_85(char *buf, const unsigned char *data, int bytes);\n extern void *alloc_blob_node_the_repository(void);\n #define alloc_tree_node(r) alloc_tree_node_##r()\n extern void *alloc_tree_node_the_repository(void);\n-extern void *alloc_commit_node(void);\n+#define alloc_commit_node(r) alloc_commit_node_##r()\n+extern void *alloc_commit_node_the_repository(void);\n extern void *alloc_tag_node(void);\n extern void *alloc_object_node(void);\n extern void alloc_report(void);\ndiff --git a/commit.c b/commit.c\nindex 953c537059..17bdd13e0d 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -55,7 +55,7 @@ struct commit *lookup_commit_the_repository(const struct object_id *oid)\n \tstruct object *obj = lookup_object(the_repository, oid->hash);\n \tif (!obj)\n \t\treturn create_object(the_repository, oid->hash,\n-\t\t\t\t     alloc_commit_node());\n+\t\t\t\t     alloc_commit_node(the_repository));\n \treturn object_as_type(the_repository, obj, OBJ_COMMIT, 0);\n }\n \ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 0b4cb14773..f6d28f0d8f 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -100,7 +100,7 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two,\n \n static struct commit *make_virtual_commit(struct tree *tree, const char *comment)\n {\n-\tstruct commit *commit = alloc_commit_node();\n+\tstruct commit *commit = alloc_commit_node(the_repository);\n \n \tset_merge_remote_desc(commit, comment, (struct object *)commit);\n \tcommit->tree = tree;\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338398","messageId":"20180206001749.218943-34-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 132/194] alloc: add repository argument to alloc_tag_node","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:47Z","receivedAt":"2018-02-06T00:23:20Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n alloc.c | 2 +-\n cache.h | 3 ++-\n tag.c   | 2 +-\n 3 files changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/alloc.c b/alloc.c\nindex 9e2b897ec1..290250e359 100644\n--- a/alloc.c\n+++ b/alloc.c\n@@ -65,7 +65,7 @@ void *alloc_tree_node_the_repository(void)\n }\n \n static struct alloc_state tag_state;\n-void *alloc_tag_node(void)\n+void *alloc_tag_node_the_repository(void)\n {\n \tstruct tag *t = alloc_node(&tag_state, sizeof(struct tag));\n \tt->object.type = OBJ_TAG;\ndiff --git a/cache.h b/cache.h\nindex cb41e22123..36c01bdcf5 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1581,7 +1581,8 @@ extern void *alloc_blob_node_the_repository(void);\n extern void *alloc_tree_node_the_repository(void);\n #define alloc_commit_node(r) alloc_commit_node_##r()\n extern void *alloc_commit_node_the_repository(void);\n-extern void *alloc_tag_node(void);\n+#define alloc_tag_node(r) alloc_tag_node_##r()\n+extern void *alloc_tag_node_the_repository(void);\n extern void *alloc_object_node(void);\n extern void alloc_report(void);\n extern unsigned int alloc_commit_index(void);\ndiff --git a/tag.c b/tag.c\nindex abba1b8d88..e0b695cb60 100644\n--- a/tag.c\n+++ b/tag.c\n@@ -97,7 +97,7 @@ struct tag *lookup_tag_the_repository(const struct object_id *oid)\n \tstruct object *obj = lookup_object(the_repository, oid->hash);\n \tif (!obj)\n \t\treturn create_object(the_repository, oid->hash,\n-\t\t\t\t     alloc_tag_node());\n+\t\t\t\t     alloc_tag_node(the_repository));\n \treturn object_as_type(the_repository, obj, OBJ_TAG, 0);\n }\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338399","messageId":"20180206001749.218943-35-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 133/194] alloc: add repository argument to alloc_object_node","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:48Z","receivedAt":"2018-02-06T00:23:23Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n alloc.c  | 2 +-\n cache.h  | 3 ++-\n object.c | 2 +-\n 3 files changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/alloc.c b/alloc.c\nindex 290250e359..f031ce422d 100644\n--- a/alloc.c\n+++ b/alloc.c\n@@ -73,7 +73,7 @@ void *alloc_tag_node_the_repository(void)\n }\n \n static struct alloc_state object_state;\n-void *alloc_object_node(void)\n+void *alloc_object_node_the_repository(void)\n {\n \tstruct object *obj = alloc_node(&object_state, sizeof(union any_object));\n \tobj->type = OBJ_NONE;\ndiff --git a/cache.h b/cache.h\nindex 36c01bdcf5..e0916d1a73 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1583,7 +1583,8 @@ extern void *alloc_tree_node_the_repository(void);\n extern void *alloc_commit_node_the_repository(void);\n #define alloc_tag_node(r) alloc_tag_node_##r()\n extern void *alloc_tag_node_the_repository(void);\n-extern void *alloc_object_node(void);\n+#define alloc_object_node(r) alloc_object_node_##r()\n+extern void *alloc_object_node_the_repository(void);\n extern void alloc_report(void);\n extern unsigned int alloc_commit_index(void);\n \ndiff --git a/object.c b/object.c\nindex 156fbae15e..cd73d41d87 100644\n--- a/object.c\n+++ b/object.c\n@@ -180,7 +180,7 @@ struct object *lookup_unknown_object(struct repository *r,\n \tstruct object *obj = lookup_object(r, sha1);\n \tif (!obj)\n \t\tobj = create_object(r, sha1,\n-\t\t\t\t    alloc_object_node());\n+\t\t\t\t    alloc_object_node(the_repository));\n \treturn obj;\n }\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338400","messageId":"20180206001749.218943-36-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 134/194] alloc: add repository argument to alloc_report","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:49Z","receivedAt":"2018-02-06T00:23:25Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n alloc.c | 2 +-\n cache.h | 3 ++-\n 2 files changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/alloc.c b/alloc.c\nindex f031ce422d..28b85b2214 100644\n--- a/alloc.c\n+++ b/alloc.c\n@@ -105,7 +105,7 @@ static void report(const char *name, unsigned int count, size_t size)\n #define REPORT(name, type)\t\\\n     report(#name, name##_state.count, name##_state.count * sizeof(type) >> 10)\n \n-void alloc_report(void)\n+void alloc_report_the_repository(void)\n {\n \tREPORT(blob, struct blob);\n \tREPORT(tree, struct tree);\ndiff --git a/cache.h b/cache.h\nindex e0916d1a73..5c9807fa8f 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1585,7 +1585,8 @@ extern void *alloc_commit_node_the_repository(void);\n extern void *alloc_tag_node_the_repository(void);\n #define alloc_object_node(r) alloc_object_node_##r()\n extern void *alloc_object_node_the_repository(void);\n-extern void alloc_report(void);\n+#define alloc_report(r) alloc_report_##r()\n+extern void alloc_report_the_repository(void);\n extern unsigned int alloc_commit_index(void);\n \n /* pkt-line.c */\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338401","messageId":"20180206001749.218943-37-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 135/194] alloc: add repository argument to alloc_commit_index","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:50Z","receivedAt":"2018-02-06T00:23:51Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n alloc.c  | 4 ++--\n cache.h  | 3 ++-\n object.c | 2 +-\n 3 files changed, 5 insertions(+), 4 deletions(-)\n\ndiff --git a/alloc.c b/alloc.c\nindex 28b85b2214..277dadd221 100644\n--- a/alloc.c\n+++ b/alloc.c\n@@ -82,7 +82,7 @@ void *alloc_object_node_the_repository(void)\n \n static struct alloc_state commit_state;\n \n-unsigned int alloc_commit_index(void)\n+unsigned int alloc_commit_index_the_repository(void)\n {\n \tstatic unsigned int count;\n \treturn count++;\n@@ -92,7 +92,7 @@ void *alloc_commit_node_the_repository(void)\n {\n \tstruct commit *c = alloc_node(&commit_state, sizeof(struct commit));\n \tc->object.type = OBJ_COMMIT;\n-\tc->index = alloc_commit_index();\n+\tc->index = alloc_commit_index(the_repository);\n \treturn c;\n }\n \ndiff --git a/cache.h b/cache.h\nindex 5c9807fa8f..40aa3f25aa 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1587,7 +1587,8 @@ extern void *alloc_tag_node_the_repository(void);\n extern void *alloc_object_node_the_repository(void);\n #define alloc_report(r) alloc_report_##r()\n extern void alloc_report_the_repository(void);\n-extern unsigned int alloc_commit_index(void);\n+#define alloc_commit_index(r) alloc_commit_index_##r()\n+extern unsigned int alloc_commit_index_the_repository(void);\n \n /* pkt-line.c */\n void packet_trace_identity(const char *prog);\ndiff --git a/object.c b/object.c\nindex cd73d41d87..e84447f229 100644\n--- a/object.c\n+++ b/object.c\n@@ -161,7 +161,7 @@ void *object_as_type_the_repository(struct object *obj, enum object_type type, i\n \t\treturn obj;\n \telse if (obj->type == OBJ_NONE) {\n \t\tif (type == OBJ_COMMIT)\n-\t\t\t((struct commit *)obj)->index = alloc_commit_index();\n+\t\t\t((struct commit *)obj)->index = alloc_commit_index(the_repository);\n \t\tobj->type = type;\n \t\treturn obj;\n \t}\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338402","messageId":"20180206001749.218943-38-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 136/194] alloc: allow arbitrary repositories for alloc functions","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:51Z","receivedAt":"2018-02-06T00:23:53Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"We have to convert them all at once, because alloc_report uses funky a\nmacro for reporting. It is better for the sake of mechanical conversion\nto convert multiple functions at once rather than changing the structure\nof the reporting function.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n alloc.c      | 48 ++++++++++++++++++++++++++----------------------\n cache.h      | 22 ++++++++--------------\n object.h     | 20 +++++++++++++++++++-\n repository.c |  6 ++++++\n 4 files changed, 59 insertions(+), 37 deletions(-)\n\ndiff --git a/alloc.c b/alloc.c\nindex 277dadd221..0e11c7766a 100644\n--- a/alloc.c\n+++ b/alloc.c\n@@ -32,6 +32,11 @@ struct alloc_state {\n \tvoid *p;   /* first free node in current allocation */\n };\n \n+void *allocate_alloc_state(void)\n+{\n+\treturn xcalloc(1, sizeof(struct alloc_state));\n+}\n+\n static inline void *alloc_node(struct alloc_state *s, size_t node_size)\n {\n \tvoid *ret;\n@@ -48,51 +53,49 @@ static inline void *alloc_node(struct alloc_state *s, size_t node_size)\n \treturn ret;\n }\n \n-static struct alloc_state blob_state;\n-void *alloc_blob_node_the_repository(void)\n+struct alloc_state the_repository_blob_state;\n+void *alloc_blob_node(struct repository *r)\n {\n-\tstruct blob *b = alloc_node(&blob_state, sizeof(struct blob));\n+\tstruct blob *b = alloc_node(r->parsed_objects.blob_state, sizeof(struct blob));\n \tb->object.type = OBJ_BLOB;\n \treturn b;\n }\n \n-static struct alloc_state tree_state;\n-void *alloc_tree_node_the_repository(void)\n+struct alloc_state the_repository_tree_state;\n+void *alloc_tree_node(struct repository *r)\n {\n-\tstruct tree *t = alloc_node(&tree_state, sizeof(struct tree));\n+\tstruct tree *t = alloc_node(r->parsed_objects.tree_state, sizeof(struct tree));\n \tt->object.type = OBJ_TREE;\n \treturn t;\n }\n \n-static struct alloc_state tag_state;\n-void *alloc_tag_node_the_repository(void)\n+struct alloc_state the_repository_tag_state;\n+void *alloc_tag_node(struct repository *r)\n {\n-\tstruct tag *t = alloc_node(&tag_state, sizeof(struct tag));\n+\tstruct tag *t = alloc_node(r->parsed_objects.tag_state, sizeof(struct tag));\n \tt->object.type = OBJ_TAG;\n \treturn t;\n }\n \n-static struct alloc_state object_state;\n-void *alloc_object_node_the_repository(void)\n+struct alloc_state the_repository_object_state;\n+void *alloc_object_node(struct repository *r)\n {\n-\tstruct object *obj = alloc_node(&object_state, sizeof(union any_object));\n+\tstruct object *obj = alloc_node(r->parsed_objects.object_state, sizeof(union any_object));\n \tobj->type = OBJ_NONE;\n \treturn obj;\n }\n \n-static struct alloc_state commit_state;\n-\n-unsigned int alloc_commit_index_the_repository(void)\n+unsigned int alloc_commit_index(struct repository *r)\n {\n-\tstatic unsigned int count;\n-\treturn count++;\n+\treturn r->parsed_objects.commit_count++;\n }\n \n-void *alloc_commit_node_the_repository(void)\n+struct alloc_state the_repository_commit_state;\n+void *alloc_commit_node(struct repository *r)\n {\n-\tstruct commit *c = alloc_node(&commit_state, sizeof(struct commit));\n+\tstruct commit *c = alloc_node(r->parsed_objects.commit_state, sizeof(struct commit));\n \tc->object.type = OBJ_COMMIT;\n-\tc->index = alloc_commit_index(the_repository);\n+\tc->index = alloc_commit_index(r);\n \treturn c;\n }\n \n@@ -103,9 +106,10 @@ static void report(const char *name, unsigned int count, size_t size)\n }\n \n #define REPORT(name, type)\t\\\n-    report(#name, name##_state.count, name##_state.count * sizeof(type) >> 10)\n+    report(#name, r->parsed_objects.name##_state->count, \\\n+\t\t  r->parsed_objects.name##_state->count * sizeof(type) >> 10)\n \n-void alloc_report_the_repository(void)\n+void alloc_report(struct repository *r)\n {\n \tREPORT(blob, struct blob);\n \tREPORT(tree, struct tree);\ndiff --git a/cache.h b/cache.h\nindex 40aa3f25aa..ee01daf130 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1575,20 +1575,14 @@ int decode_85(char *dst, const char *line, int linelen);\n void encode_85(char *buf, const unsigned char *data, int bytes);\n \n /* alloc.c */\n-#define alloc_blob_node(r) alloc_blob_node_##r()\n-extern void *alloc_blob_node_the_repository(void);\n-#define alloc_tree_node(r) alloc_tree_node_##r()\n-extern void *alloc_tree_node_the_repository(void);\n-#define alloc_commit_node(r) alloc_commit_node_##r()\n-extern void *alloc_commit_node_the_repository(void);\n-#define alloc_tag_node(r) alloc_tag_node_##r()\n-extern void *alloc_tag_node_the_repository(void);\n-#define alloc_object_node(r) alloc_object_node_##r()\n-extern void *alloc_object_node_the_repository(void);\n-#define alloc_report(r) alloc_report_##r()\n-extern void alloc_report_the_repository(void);\n-#define alloc_commit_index(r) alloc_commit_index_##r()\n-extern unsigned int alloc_commit_index_the_repository(void);\n+extern void *alloc_blob_node(struct repository *r);\n+extern void *alloc_tree_node(struct repository *r);\n+extern void *alloc_commit_node(struct repository *r);\n+extern void *alloc_tag_node(struct repository *r);\n+extern void *alloc_object_node(struct repository *r);\n+extern void alloc_report(struct repository *r);\n+extern unsigned int alloc_commit_index(struct repository *r);\n+void *allocate_alloc_state(void);\n \n /* pkt-line.c */\n void packet_trace_identity(const char *prog);\ndiff --git a/object.h b/object.h\nindex a61d965700..587db55dfe 100644\n--- a/object.h\n+++ b/object.h\n@@ -8,9 +8,27 @@ struct object_parser {\n \t/* parent substitutions from .git/info/grafts and .git/shallow */\n \tstruct commit_graft **grafts;\n \tint grafts_alloc, grafts_nr;\n+\n+\tstruct alloc_state *blob_state;\n+\tstruct alloc_state *tree_state;\n+\tstruct alloc_state *commit_state;\n+\tstruct alloc_state *tag_state;\n+\tstruct alloc_state *object_state;\n+\tunsigned commit_count;\n };\n \n-#define OBJECT_PARSER_INIT { NULL, 0, 0, NULL, 0, 0 }\n+extern struct alloc_state the_repository_blob_state;\n+extern struct alloc_state the_repository_tree_state;\n+extern struct alloc_state the_repository_commit_state;\n+extern struct alloc_state the_repository_tag_state;\n+extern struct alloc_state the_repository_object_state;\n+#define OBJECT_PARSER_INIT { NULL, 0, 0, NULL, 0, 0, \\\n+\t&the_repository_blob_state, \\\n+\t&the_repository_tree_state, \\\n+\t&the_repository_commit_state, \\\n+\t&the_repository_tag_state, \\\n+\t&the_repository_object_state, \\\n+\t0 }\n \n struct object_list {\n \tstruct object *item;\ndiff --git a/repository.c b/repository.c\nindex 361e503824..f76f0ddd37 100644\n--- a/repository.c\n+++ b/repository.c\n@@ -175,6 +175,12 @@ int repo_init(struct repository *repo, const char *gitdir, const char *worktree)\n \n \trepo_set_hash_algo(repo, format.hash_algo);\n \n+\trepo->parsed_objects.blob_state = allocate_alloc_state();\n+\trepo->parsed_objects.tree_state = allocate_alloc_state();\n+\trepo->parsed_objects.commit_state = allocate_alloc_state();\n+\trepo->parsed_objects.tag_state = allocate_alloc_state();\n+\trepo->parsed_objects.object_state = allocate_alloc_state();\n+\n \tif (worktree)\n \t\trepo_set_worktree(repo, worktree);\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338403","messageId":"20180206001749.218943-39-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 137/194] object: allow object_as_type to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:52Z","receivedAt":"2018-02-06T00:23:55Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n object.c | 4 ++--\n object.h | 3 +--\n 2 files changed, 3 insertions(+), 4 deletions(-)\n\ndiff --git a/object.c b/object.c\nindex e84447f229..db15de6623 100644\n--- a/object.c\n+++ b/object.c\n@@ -155,13 +155,13 @@ void *create_object(struct repository *r, const unsigned char *sha1, void *o)\n \treturn obj;\n }\n \n-void *object_as_type_the_repository(struct object *obj, enum object_type type, int quiet)\n+void *object_as_type(struct repository *r, struct object *obj, enum object_type type, int quiet)\n {\n \tif (obj->type == type)\n \t\treturn obj;\n \telse if (obj->type == OBJ_NONE) {\n \t\tif (type == OBJ_COMMIT)\n-\t\t\t((struct commit *)obj)->index = alloc_commit_index(the_repository);\n+\t\t\t((struct commit *)obj)->index = alloc_commit_index(r);\n \t\tobj->type = type;\n \t\treturn obj;\n \t}\ndiff --git a/object.h b/object.h\nindex 587db55dfe..513f5eaef4 100644\n--- a/object.h\n+++ b/object.h\n@@ -124,8 +124,7 @@ struct object *lookup_object(struct repository *r, const unsigned char *sha1);\n \n extern void *create_object(struct repository *r, const unsigned char *sha1, void *obj);\n \n-#define object_as_type(r, o, t, q) object_as_type_##r(o, t, q)\n-void *object_as_type_the_repository(struct object *obj, enum object_type type, int quiet);\n+void *object_as_type(struct repository *r, struct object *obj, enum object_type type, int quiet);\n \n /*\n  * Resolves 'sha1' to an object of the specified type and returns the\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338404","messageId":"20180206001749.218943-40-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 138/194] commit: allow lookup_commit to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:53Z","receivedAt":"2018-02-06T00:24:19Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n commit.c | 10 +++++-----\n commit.h |  3 +--\n 2 files changed, 6 insertions(+), 7 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex 17bdd13e0d..435735ed2c 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -50,13 +50,13 @@ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref\n \treturn c;\n }\n \n-struct commit *lookup_commit_the_repository(const struct object_id *oid)\n+struct commit *lookup_commit(struct repository *r, const struct object_id *oid)\n {\n-\tstruct object *obj = lookup_object(the_repository, oid->hash);\n+\tstruct object *obj = lookup_object(r, oid->hash);\n \tif (!obj)\n-\t\treturn create_object(the_repository, oid->hash,\n-\t\t\t\t     alloc_commit_node(the_repository));\n-\treturn object_as_type(the_repository, obj, OBJ_COMMIT, 0);\n+\t\treturn create_object(r, oid->hash,\n+\t\t\t\t     alloc_commit_node(r));\n+\treturn object_as_type(r, obj, OBJ_COMMIT, 0);\n }\n \n struct commit *lookup_commit_reference_by_name(const char *name)\ndiff --git a/commit.h b/commit.h\nindex f791a55379..41a8947b33 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -46,8 +46,7 @@ enum decoration_type {\n void add_name_decoration(enum decoration_type type, const char *name, struct object *obj);\n const struct name_decoration *get_name_decoration(const struct object *obj);\n \n-#define lookup_commit(r, o) lookup_commit_##r(o)\n-struct commit *lookup_commit_the_repository(const struct object_id *oid);\n+struct commit *lookup_commit(struct repository *r, const struct object_id *oid);\n #define lookup_commit_reference(r, o) \\\n \t\tlookup_commit_reference_##r(o)\n struct commit *lookup_commit_reference_the_repository(const struct object_id *oid);\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338405","messageId":"20180206001749.218943-41-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 139/194] sha1_file: allow add_to_alternates_file to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:54Z","receivedAt":"2018-02-06T00:24:22Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Brandon Williams <bmwill@google.com>\n\nSigned-off-by: Brandon Williams <bmwill@google.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n alternates.h | 3 +--\n sha1_file.c  | 8 ++++----\n 2 files changed, 5 insertions(+), 6 deletions(-)\n\ndiff --git a/alternates.h b/alternates.h\nindex b3d8d57ba4..4d5296c83f 100644\n--- a/alternates.h\n+++ b/alternates.h\n@@ -48,8 +48,7 @@ struct alternate_object_database *alloc_alt_odb(const char *dir);\n  * Add the directory to the on-disk alternates file; the new entry will also\n  * take effect in the current process.\n  */\n-#define add_to_alternates_file(r, d) add_to_alternates_file_##r(d)\n-extern void add_to_alternates_file_the_repository(const char *dir);\n+extern void add_to_alternates_file(struct repository *r, const char *dir);\n \n /*\n  * Add the directory to the in-memory list of alternates (along with any\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 3c39e34c72..8638fae9c4 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -538,10 +538,10 @@ struct alternate_object_database *alloc_alt_odb(const char *dir)\n \treturn ent;\n }\n \n-void add_to_alternates_file_the_repository(const char *reference)\n+void add_to_alternates_file(struct repository *r, const char *reference)\n {\n \tstruct lock_file lock = LOCK_INIT;\n-\tchar *alts = git_pathdup(\"objects/info/alternates\");\n+\tchar *alts = repo_git_path(r, \"objects/info/alternates\");\n \tFILE *in, *out;\n \tint found = 0;\n \n@@ -574,8 +574,8 @@ void add_to_alternates_file_the_repository(const char *reference)\n \t\tfprintf_or_die(out, \"%s\\n\", reference);\n \t\tif (commit_lock_file(&lock))\n \t\t\tdie_errno(\"unable to move new alternates file into place\");\n-\t\tif (the_repository->objects.alt_odb.tail)\n-\t\t\tlink_alt_odb_entries(the_repository, reference,\n+\t\tif (r->objects.alt_odb.tail)\n+\t\t\tlink_alt_odb_entries(r, reference,\n \t\t\t\t\t     '\\n', NULL, 0);\n \t}\n \tfree(alts);\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338406","messageId":"20180206001749.218943-42-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 140/194] commit: convert commit_graft_pos() to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:55Z","receivedAt":"2018-02-06T00:24:25Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Brandon Williams <bmwill@google.com>\n\nSigned-off-by: Brandon Williams <bmwill@google.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n commit.c | 7 +++----\n 1 file changed, 3 insertions(+), 4 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex 435735ed2c..0d006ab1bb 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -105,11 +105,10 @@ static const unsigned char *commit_graft_sha1_access(size_t index, void *table)\n \treturn commit_graft_table[index]->oid.hash;\n }\n \n-#define commit_graft_pos(r, s) commit_graft_pos_##r(s)\n-static int commit_graft_pos_the_repository(const unsigned char *sha1)\n+static int commit_graft_pos(struct repository *r, const unsigned char *sha1)\n {\n-\treturn sha1_pos(sha1, the_repository->parsed_objects.grafts,\n-\t\t\tthe_repository->parsed_objects.grafts_nr,\n+\treturn sha1_pos(sha1, r->parsed_objects.grafts,\n+\t\t\tr->parsed_objects.grafts_nr,\n \t\t\tcommit_graft_sha1_access);\n }\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338407","messageId":"20180206001749.218943-44-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 142/194] commit: convert read_graft_file to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:57Z","receivedAt":"2018-02-06T00:25:00Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Brandon Williams <bmwill@google.com>\n\nSigned-off-by: Brandon Williams <bmwill@google.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n commit.c | 5 ++---\n 1 file changed, 2 insertions(+), 3 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex 43ed3298cc..3a990b7078 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -178,8 +178,7 @@ struct commit_graft *read_graft_line(struct strbuf *line)\n \treturn NULL;\n }\n \n-#define read_graft_file(r, f) read_graft_file_##r(f)\n-static int read_graft_file_the_repository(const char *graft_file)\n+static int read_graft_file(struct repository *r, const char *graft_file)\n {\n \tFILE *fp = fopen_or_warn(graft_file, \"r\");\n \tstruct strbuf buf = STRBUF_INIT;\n@@ -190,7 +189,7 @@ static int read_graft_file_the_repository(const char *graft_file)\n \t\tstruct commit_graft *graft = read_graft_line(&buf);\n \t\tif (!graft)\n \t\t\tcontinue;\n-\t\tif (register_commit_graft(the_repository, graft, 1))\n+\t\tif (register_commit_graft(r, graft, 1))\n \t\t\terror(\"duplicate graft data: %s\", buf.buf);\n \t}\n \tfclose(fp);\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338408","messageId":"20180206001749.218943-43-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 141/194] commit: convert register_commit_graft to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:56Z","receivedAt":"2018-02-06T00:25:04Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"From: Brandon Williams <bmwill@google.com>\n\nSigned-off-by: Brandon Williams <bmwill@google.com>\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n commit.c | 29 +++++++++++++++--------------\n commit.h |  3 +--\n 2 files changed, 16 insertions(+), 16 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex 0d006ab1bb..43ed3298cc 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -112,30 +112,31 @@ static int commit_graft_pos(struct repository *r, const unsigned char *sha1)\n \t\t\tcommit_graft_sha1_access);\n }\n \n-int register_commit_graft_the_repository(struct commit_graft *graft, int ignore_dups)\n+int register_commit_graft(struct repository *r, struct commit_graft *graft,\n+\t\t\t  int ignore_dups)\n {\n-\tint pos = commit_graft_pos(the_repository, graft->oid.hash);\n+\tint pos = commit_graft_pos(r, graft->oid.hash);\n \n \tif (0 <= pos) {\n \t\tif (ignore_dups)\n \t\t\tfree(graft);\n \t\telse {\n-\t\t\tfree(the_repository->parsed_objects.grafts[pos]);\n-\t\t\tthe_repository->parsed_objects.grafts[pos] = graft;\n+\t\t\tfree(r->parsed_objects.grafts[pos]);\n+\t\t\tr->parsed_objects.grafts[pos] = graft;\n \t\t}\n \t\treturn 1;\n \t}\n \tpos = -pos - 1;\n-\tALLOC_GROW(the_repository->parsed_objects.grafts,\n-\t\t   the_repository->parsed_objects.grafts_nr + 1,\n-\t\t   the_repository->parsed_objects.grafts_alloc);\n-\tthe_repository->parsed_objects.grafts_nr++;\n-\tif (pos < the_repository->parsed_objects.grafts_nr)\n-\t\tmemmove(the_repository->parsed_objects.grafts + pos + 1,\n-\t\t\tthe_repository->parsed_objects.grafts + pos,\n-\t\t\t(the_repository->parsed_objects.grafts_nr - pos - 1) *\n-\t\t\tsizeof(*the_repository->parsed_objects.grafts));\n-\tthe_repository->parsed_objects.grafts[pos] = graft;\n+\tALLOC_GROW(r->parsed_objects.grafts,\n+\t\t   r->parsed_objects.grafts_nr + 1,\n+\t\t   r->parsed_objects.grafts_alloc);\n+\tr->parsed_objects.grafts_nr++;\n+\tif (pos < r->parsed_objects.grafts_nr)\n+\t\tmemmove(r->parsed_objects.grafts + pos + 1,\n+\t\t\tr->parsed_objects.grafts + pos,\n+\t\t\t(r->parsed_objects.grafts_nr - pos - 1) *\n+\t\t\tsizeof(*r->parsed_objects.grafts));\n+\tr->parsed_objects.grafts[pos] = graft;\n \treturn 0;\n }\n \ndiff --git a/commit.h b/commit.h\nindex 41a8947b33..870ad525fd 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -175,8 +175,7 @@ struct commit_graft {\n typedef int (*each_commit_graft_fn)(const struct commit_graft *, void *);\n \n struct commit_graft *read_graft_line(struct strbuf *line);\n-#define register_commit_graft(r, g, i) register_commit_graft_##r(g, i)\n-int register_commit_graft_the_repository(struct commit_graft *, int);\n+int register_commit_graft(struct repository *r, struct commit_graft *, int);\n #define lookup_commit_graft(r, o) lookup_commit_graft_##r(o)\n struct commit_graft *lookup_commit_graft_the_repository(const struct object_id *oid);\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338409","messageId":"20180206001749.218943-45-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 143/194] object: add repository argument to parse_commit_gently","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:58Z","receivedAt":"2018-02-06T00:25:08Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow callers of parse_commit_gently to\nbe more specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nThe included coccinelle semantic patch will adapt any new callers in\nthe diff produced by `make coccicheck`.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n commit.c                              | 2 +-\n commit.h                              | 5 +++--\n contrib/coccinelle/object_store.cocci | 9 +++++++++\n revision.c                            | 4 ++--\n 4 files changed, 15 insertions(+), 5 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex 3a990b7078..93a4f70fa4 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -384,7 +384,7 @@ int parse_commit_buffer_the_repository(struct commit *item, const void *buffer,\n \treturn 0;\n }\n \n-int parse_commit_gently(struct commit *item, int quiet_on_missing)\n+int parse_commit_gently_the_repository(struct commit *item, int quiet_on_missing)\n {\n \tenum object_type type;\n \tvoid *buffer;\ndiff --git a/commit.h b/commit.h\nindex 870ad525fd..bb2b1e1e28 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -66,10 +66,11 @@ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref\n \n #define parse_commit_buffer(r, i, b, s) parse_commit_buffer_##r(i, b, s)\n int parse_commit_buffer_the_repository(struct commit *item, const void *buffer, unsigned long size);\n-int parse_commit_gently(struct commit *item, int quiet_on_missing);\n+#define parse_commit_gently(r, i, q) parse_commit_gently_##r(i, q)\n+int parse_commit_gently_the_repository(struct commit *item, int quiet_on_missing);\n static inline int parse_commit(struct commit *item)\n {\n-\treturn parse_commit_gently(item, 0);\n+\treturn parse_commit_gently(the_repository, item, 0);\n }\n void parse_commit_or_die(struct commit *item);\n \ndiff --git a/contrib/coccinelle/object_store.cocci b/contrib/coccinelle/object_store.cocci\nindex 3d29868dbf..93b1d03971 100644\n--- a/contrib/coccinelle/object_store.cocci\n+++ b/contrib/coccinelle/object_store.cocci\n@@ -44,3 +44,12 @@ expression H;\n open_istream(\n + the_repository,\n  E, F, G, H)\n+\n+@@\n+expression E;\n+expression F;\n+@@\n+ parse_commit_gently(\n++ the_repository,\n+  E, F)\n+\ndiff --git a/revision.c b/revision.c\nindex 5c5375ac54..7501ef3160 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -775,7 +775,7 @@ static int add_parents_to_list(struct rev_info *revs, struct commit *commit,\n \t\t\tparent = parent->next;\n \t\t\tif (p)\n \t\t\t\tp->object.flags |= UNINTERESTING;\n-\t\t\tif (parse_commit_gently(p, 1) < 0)\n+\t\t\tif (parse_commit_gently(the_repository, p, 1) < 0)\n \t\t\t\tcontinue;\n \t\t\tif (p->parents)\n \t\t\t\tmark_parents_uninteresting(p);\n@@ -802,7 +802,7 @@ static int add_parents_to_list(struct rev_info *revs, struct commit *commit,\n \tfor (parent = commit->parents; parent; parent = parent->next) {\n \t\tstruct commit *p = parent->item;\n \n-\t\tif (parse_commit_gently(p, revs->ignore_missing_links) < 0)\n+\t\tif (parse_commit_gently(the_repository, p, revs->ignore_missing_links) < 0)\n \t\t\treturn -1;\n \t\tif (revs->show_source && !p->util)\n \t\t\tp->util = commit->util;\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338410","messageId":"20180206001749.218943-46-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 144/194] commit: add repository argument to parse_commit","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:16:59Z","receivedAt":"2018-02-06T00:25:19Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow callers of parse_commit to\nbe more specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nThe included coccinelle semantic patch will adapt any new callers in\nthe diff produced by `make coccicheck`.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n blame.c                               |  4 ++--\n builtin/checkout.c                    |  4 ++--\n builtin/commit.c                      |  4 ++--\n builtin/describe.c                    |  4 ++--\n builtin/merge-base.c                  |  2 +-\n builtin/name-rev.c                    |  2 +-\n builtin/notes.c                       |  2 +-\n builtin/reflog.c                      |  2 +-\n builtin/show-branch.c                 |  4 ++--\n commit.c                              | 18 +++++++++---------\n commit.h                              |  3 ++-\n contrib/coccinelle/object_store.cocci |  7 +++++++\n fetch-pack.c                          |  6 +++---\n fsck.c                                |  2 +-\n merge-recursive.c                     |  4 ++--\n notes-utils.c                         |  2 +-\n remote.c                              |  2 +-\n revision.c                            |  6 +++---\n sequencer.c                           | 12 ++++++------\n sha1_name.c                           |  4 ++--\n shallow.c                             |  4 ++--\n tree.c                                |  2 +-\n walker.c                              |  2 +-\n 23 files changed, 55 insertions(+), 47 deletions(-)\n\ndiff --git a/blame.c b/blame.c\nindex 592bedd0e0..ccd6a5097b 100644\n--- a/blame.c\n+++ b/blame.c\n@@ -1433,7 +1433,7 @@ static void pass_blame(struct blame_scoreboard *sb, struct blame_origin *origin,\n \n \t\t\tif (sg_origin[i])\n \t\t\t\tcontinue;\n-\t\t\tif (parse_commit(p))\n+\t\t\tif (parse_commit(the_repository, p))\n \t\t\t\tcontinue;\n \t\t\tporigin = find(p, origin);\n \t\t\tif (!porigin)\n@@ -1572,7 +1572,7 @@ void assign_blame(struct blame_scoreboard *sb, int opt)\n \t\t * so hold onto it in the meantime.\n \t\t */\n \t\tblame_origin_incref(suspect);\n-\t\tparse_commit(commit);\n+\t\tparse_commit(the_repository, commit);\n \t\tif (sb->reverse ||\n \t\t    (!(commit->object.flags & UNINTERESTING) &&\n \t\t     !(revs->max_age != -1 && commit->date < revs->max_age)))\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex cef2b4f2ad..4428fd5da5 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -403,7 +403,7 @@ static void describe_detached_head(const char *msg, struct commit *commit)\n {\n \tstruct strbuf sb = STRBUF_INIT;\n \n-\tif (!parse_commit(commit))\n+\tif (!parse_commit(the_repository, commit))\n \t\tpp_commit_easy(CMIT_FMT_ONELINE, commit, &sb);\n \tif (print_sha1_ellipsis()) {\n \t\tfprintf(stderr, \"%s %s... %s\\n\", msg,\n@@ -724,7 +724,7 @@ static void describe_one_orphan(struct strbuf *sb, struct commit *commit)\n \tstrbuf_addstr(sb, \"  \");\n \tstrbuf_add_unique_abbrev(sb, commit->object.oid.hash, DEFAULT_ABBREV);\n \tstrbuf_addch(sb, ' ');\n-\tif (!parse_commit(commit))\n+\tif (!parse_commit(the_repository, commit))\n \t\tpp_commit_easy(CMIT_FMT_ONELINE, commit, sb);\n \tstrbuf_addch(sb, '\\n');\n }\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex cd3144f9f4..d15592ad45 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -1467,7 +1467,7 @@ static void print_summary(const char *prefix, const struct object_id *oid,\n \tcommit = lookup_commit(the_repository, oid);\n \tif (!commit)\n \t\tdie(_(\"couldn't look up newly created commit\"));\n-\tif (parse_commit(commit))\n+\tif (parse_commit(the_repository, commit))\n \t\tdie(_(\"could not parse newly created commit\"));\n \n \tstrbuf_addstr(&format, \"format:%h] %s\");\n@@ -1692,7 +1692,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n \t\tcurrent_head = NULL;\n \telse {\n \t\tcurrent_head = lookup_commit_or_die(&oid, \"HEAD\");\n-\t\tif (parse_commit(current_head))\n+\t\tif (parse_commit(the_repository, current_head))\n \t\t\tdie(_(\"could not parse HEAD commit\"));\n \t}\n \tverbose = -1; /* unspecified */\ndiff --git a/builtin/describe.c b/builtin/describe.c\nindex 5bd0920ebd..870a3a780b 100644\n--- a/builtin/describe.c\n+++ b/builtin/describe.c\n@@ -249,7 +249,7 @@ static unsigned long finish_depth_computation(\n \t\t\tbest->depth++;\n \t\twhile (parents) {\n \t\t\tstruct commit *p = parents->item;\n-\t\t\tparse_commit(p);\n+\t\t\tparse_commit(the_repository, p);\n \t\t\tif (!(p->object.flags & SEEN))\n \t\t\t\tcommit_list_insert_by_date(p, list);\n \t\t\tp->object.flags |= c->object.flags;\n@@ -367,7 +367,7 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst)\n \t\t}\n \t\twhile (parents) {\n \t\t\tstruct commit *p = parents->item;\n-\t\t\tparse_commit(p);\n+\t\t\tparse_commit(the_repository, p);\n \t\t\tif (!(p->object.flags & SEEN))\n \t\t\t\tcommit_list_insert_by_date(p, &list);\n \t\t\tp->object.flags |= c->object.flags;\ndiff --git a/builtin/merge-base.c b/builtin/merge-base.c\nindex 08d91b1f0c..426882818c 100644\n--- a/builtin/merge-base.c\n+++ b/builtin/merge-base.c\n@@ -127,7 +127,7 @@ static void add_one_commit(struct object_id *oid, struct rev_collect *revs)\n \tcommit = lookup_commit(the_repository, oid);\n \tif (!commit ||\n \t    (commit->object.flags & TMP_MARK) ||\n-\t    parse_commit(commit))\n+\t    parse_commit(the_repository, commit))\n \t\treturn;\n \n \tALLOC_GROW(revs->commit, revs->nr + 1, revs->alloc);\ndiff --git a/builtin/name-rev.c b/builtin/name-rev.c\nindex 2cbb702c2c..57db381381 100644\n--- a/builtin/name-rev.c\n+++ b/builtin/name-rev.c\n@@ -71,7 +71,7 @@ static void name_rev(struct commit *commit,\n \tint parent_number = 1;\n \tchar *to_free = NULL;\n \n-\tparse_commit(commit);\n+\tparse_commit(the_repository, commit);\n \n \tif (commit->date < cutoff)\n \t\treturn;\ndiff --git a/builtin/notes.c b/builtin/notes.c\nindex 56d99c2789..9100ac5ce0 100644\n--- a/builtin/notes.c\n+++ b/builtin/notes.c\n@@ -715,7 +715,7 @@ static int merge_commit(struct notes_merge_options *o)\n \t\tdie(_(\"failed to read ref NOTES_MERGE_PARTIAL\"));\n \telse if (!(partial = lookup_commit_reference(the_repository, &oid)))\n \t\tdie(_(\"could not find commit from NOTES_MERGE_PARTIAL.\"));\n-\telse if (parse_commit(partial))\n+\telse if (parse_commit(the_repository, partial))\n \t\tdie(_(\"could not parse commit from NOTES_MERGE_PARTIAL.\"));\n \n \tif (partial->parents)\ndiff --git a/builtin/reflog.c b/builtin/reflog.c\nindex 3b600966e3..05eb1baa31 100644\n--- a/builtin/reflog.c\n+++ b/builtin/reflog.c\n@@ -235,7 +235,7 @@ static void mark_reachable(struct expire_reflog_policy_cb *cb)\n \t\tstruct commit *commit = pop_commit(&pending);\n \t\tif (commit->object.flags & REACHABLE)\n \t\t\tcontinue;\n-\t\tif (parse_commit(commit))\n+\t\tif (parse_commit(the_repository, commit))\n \t\t\tcontinue;\n \t\tcommit->object.flags |= REACHABLE;\n \t\tif (commit->date < expire_limit) {\ndiff --git a/builtin/show-branch.c b/builtin/show-branch.c\nindex 03c98efbe5..a3195937d3 100644\n--- a/builtin/show-branch.c\n+++ b/builtin/show-branch.c\n@@ -220,7 +220,7 @@ static void join_revs(struct commit_list **list_p,\n \t\t\tparents = parents->next;\n \t\t\tif ((this_flag & flags) == flags)\n \t\t\t\tcontinue;\n-\t\t\tparse_commit(p);\n+\t\t\tparse_commit(the_repository, p);\n \t\t\tif (mark_seen(p, seen_p) && !still_interesting)\n \t\t\t\textra--;\n \t\t\tp->object.flags |= flags;\n@@ -815,7 +815,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \t\tif (!commit)\n \t\t\tdie(_(\"cannot find commit %s (%s)\"),\n \t\t\t    ref_name[num_rev], oid_to_hex(&revkey));\n-\t\tparse_commit(commit);\n+\t\tparse_commit(the_repository, commit);\n \t\tmark_seen(commit, &seen);\n \n \t\t/* rev#0 uses bit REV_SHIFT, rev#1 uses bit REV_SHIFT+1,\ndiff --git a/commit.c b/commit.c\nindex 93a4f70fa4..49c8f76e41 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -67,7 +67,7 @@ struct commit *lookup_commit_reference_by_name(const char *name)\n \tif (get_oid_committish(name, &oid))\n \t\treturn NULL;\n \tcommit = lookup_commit_reference(the_repository, &oid);\n-\tif (parse_commit(commit))\n+\tif (parse_commit(the_repository, commit))\n \t\treturn NULL;\n \treturn commit;\n }\n@@ -417,7 +417,7 @@ int parse_commit_gently_the_repository(struct commit *item, int quiet_on_missing\n \n void parse_commit_or_die(struct commit *item)\n {\n-\tif (parse_commit(item))\n+\tif (parse_commit(the_repository, item))\n \t\tdie(\"unable to parse commit %s\",\n \t\t    item ? oid_to_hex(&item->object.oid) : \"(null)\");\n }\n@@ -522,7 +522,7 @@ struct commit *pop_most_recent_commit(struct commit_list **list,\n \n \twhile (parents) {\n \t\tstruct commit *commit = parents->item;\n-\t\tif (!parse_commit(commit) && !(commit->object.flags & mark)) {\n+\t\tif (!parse_commit(the_repository, commit) && !(commit->object.flags & mark)) {\n \t\t\tcommit->object.flags |= mark;\n \t\t\tcommit_list_insert_by_date(commit, list);\n \t\t}\n@@ -834,7 +834,7 @@ static struct commit_list *paint_down_to_common(struct commit *one, int n, struc\n \t\t\tparents = parents->next;\n \t\t\tif ((p->object.flags & flags) == flags)\n \t\t\t\tcontinue;\n-\t\t\tif (parse_commit(p))\n+\t\t\tif (parse_commit(the_repository, p))\n \t\t\t\treturn NULL;\n \t\t\tp->object.flags |= flags;\n \t\t\tprio_queue_put(&queue, p);\n@@ -860,10 +860,10 @@ static struct commit_list *merge_bases_many(struct commit *one, int n, struct co\n \t\t\treturn commit_list_insert(one, &result);\n \t}\n \n-\tif (parse_commit(one))\n+\tif (parse_commit(the_repository, one))\n \t\treturn NULL;\n \tfor (i = 0; i < n; i++) {\n-\t\tif (parse_commit(twos[i]))\n+\t\tif (parse_commit(the_repository, twos[i]))\n \t\t\treturn NULL;\n \t}\n \n@@ -922,7 +922,7 @@ static int remove_redundant(struct commit **array, int cnt)\n \tALLOC_ARRAY(filled_index, cnt - 1);\n \n \tfor (i = 0; i < cnt; i++)\n-\t\tparse_commit(array[i]);\n+\t\tparse_commit(the_repository, array[i]);\n \tfor (i = 0; i < cnt; i++) {\n \t\tstruct commit_list *common;\n \n@@ -1046,10 +1046,10 @@ int in_merge_bases_many(struct commit *commit, int nr_reference, struct commit *\n \tstruct commit_list *bases;\n \tint ret = 0, i;\n \n-\tif (parse_commit(commit))\n+\tif (parse_commit(the_repository, commit))\n \t\treturn ret;\n \tfor (i = 0; i < nr_reference; i++)\n-\t\tif (parse_commit(reference[i]))\n+\t\tif (parse_commit(the_repository, reference[i]))\n \t\t\treturn ret;\n \n \tbases = paint_down_to_common(commit, nr_reference, reference);\ndiff --git a/commit.h b/commit.h\nindex bb2b1e1e28..16203fb18c 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -68,7 +68,8 @@ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref\n int parse_commit_buffer_the_repository(struct commit *item, const void *buffer, unsigned long size);\n #define parse_commit_gently(r, i, q) parse_commit_gently_##r(i, q)\n int parse_commit_gently_the_repository(struct commit *item, int quiet_on_missing);\n-static inline int parse_commit(struct commit *item)\n+#define parse_commit(r, i) parse_commit_##r(i)\n+static inline int parse_commit_the_repository(struct commit *item)\n {\n \treturn parse_commit_gently(the_repository, item, 0);\n }\ndiff --git a/contrib/coccinelle/object_store.cocci b/contrib/coccinelle/object_store.cocci\nindex 93b1d03971..3ffb34d5b5 100644\n--- a/contrib/coccinelle/object_store.cocci\n+++ b/contrib/coccinelle/object_store.cocci\n@@ -53,3 +53,10 @@ expression F;\n + the_repository,\n   E, F)\n \n+@@\n+expression E;\n+@@\n+ parse_commit(\n++ the_repository,\n+ E)\n+\ndiff --git a/fetch-pack.c b/fetch-pack.c\nindex f38beea6a3..e8b1fc0d1b 100644\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -112,7 +112,7 @@ static void rev_list_push(struct commit *commit, int mark)\n \tif (!(commit->object.flags & mark)) {\n \t\tcommit->object.flags |= mark;\n \n-\t\tif (parse_commit(commit))\n+\t\tif (parse_commit(the_repository, commit))\n \t\t\treturn;\n \n \t\tprio_queue_put(&rev_list, commit);\n@@ -176,7 +176,7 @@ static void mark_common(struct commit *commit,\n \t\t\tif (!ancestors_only && !(o->flags & POPPED))\n \t\t\t\tnon_common_revs--;\n \t\t\tif (!o->parsed && !dont_parse)\n-\t\t\t\tif (parse_commit(commit))\n+\t\t\t\tif (parse_commit(the_repository, commit))\n \t\t\t\t\treturn;\n \n \t\t\tfor (parents = commit->parents;\n@@ -203,7 +203,7 @@ static const struct object_id *get_rev(void)\n \t\t\treturn NULL;\n \n \t\tcommit = prio_queue_get(&rev_list);\n-\t\tparse_commit(commit);\n+\t\tparse_commit(the_repository, commit);\n \t\tparents = commit->parents;\n \n \t\tcommit->object.flags |= POPPED;\ndiff --git a/fsck.c b/fsck.c\nindex 5144ceb8e2..494b4e3b30 100644\n--- a/fsck.c\n+++ b/fsck.c\n@@ -393,7 +393,7 @@ static int fsck_walk_commit(struct commit *commit, void *data, struct fsck_optio\n \tint result;\n \tconst char *name;\n \n-\tif (parse_commit(commit))\n+\tif (parse_commit(the_repository, commit))\n \t\treturn -1;\n \n \tname = get_object_name(options, &commit->object);\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex f6d28f0d8f..719fa58ab1 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -233,7 +233,7 @@ static void output_commit_title(struct merge_options *o, struct commit *commit)\n \t\tstrbuf_add_unique_abbrev(&o->obuf, commit->object.oid.hash,\n \t\t\t\t\t DEFAULT_ABBREV);\n \t\tstrbuf_addch(&o->obuf, ' ');\n-\t\tif (parse_commit(commit) != 0)\n+\t\tif (parse_commit(the_repository, commit) != 0)\n \t\t\tstrbuf_addstr(&o->obuf, _(\"(bad commit)\\n\"));\n \t\telse {\n \t\t\tconst char *title;\n@@ -2162,7 +2162,7 @@ static struct commit *get_ref(const struct object_id *oid, const char *name)\n \t\treturn make_virtual_commit((struct tree*)object, name);\n \tif (object->type != OBJ_COMMIT)\n \t\treturn NULL;\n-\tif (parse_commit((struct commit *)object))\n+\tif (parse_commit(the_repository, (struct commit *)object))\n \t\treturn NULL;\n \treturn (struct commit *)object;\n }\ndiff --git a/notes-utils.c b/notes-utils.c\nindex 3ef5340c6e..7b0b2a8f8a 100644\n--- a/notes-utils.c\n+++ b/notes-utils.c\n@@ -22,7 +22,7 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,\n \t\tif (!read_ref(t->ref, &parent_oid)) {\n \t\t\tstruct commit *parent = lookup_commit(the_repository,\n \t\t\t\t\t\t\t      &parent_oid);\n-\t\t\tif (parse_commit(parent))\n+\t\t\tif (parse_commit(the_repository, parent))\n \t\t\t\tdie(\"Failed to find/parse commit %s\", t->ref);\n \t\t\tcommit_list_insert(parent, &parents);\n \t\t}\ndiff --git a/remote.c b/remote.c\nindex ecfa60a975..a4cf885012 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -1993,7 +1993,7 @@ int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid)\n \t\treturn 0;\n \tnew = (struct commit *) o;\n \n-\tif (parse_commit(new) < 0)\n+\tif (parse_commit(the_repository, new) < 0)\n \t\treturn 0;\n \n \tused = list = NULL;\ndiff --git a/revision.c b/revision.c\nindex 7501ef3160..56c1a9a78f 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -253,7 +253,7 @@ static struct commit *handle_commit(struct rev_info *revs,\n \t */\n \tif (object->type == OBJ_COMMIT) {\n \t\tstruct commit *commit = (struct commit *)object;\n-\t\tif (parse_commit(commit) < 0)\n+\t\tif (parse_commit(the_repository, commit) < 0)\n \t\t\tdie(\"unable to parse commit %s\", name);\n \t\tif (flags & UNINTERESTING) {\n \t\t\tmark_parents_uninteresting(commit);\n@@ -663,7 +663,7 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)\n \t\t\t\t\tts->treesame[0] = 1;\n \t\t\t}\n \t\t}\n-\t\tif (parse_commit(p) < 0)\n+\t\tif (parse_commit(the_repository, p) < 0)\n \t\t\tdie(\"cannot simplify commit %s (because of %s)\",\n \t\t\t    oid_to_hex(&commit->object.oid),\n \t\t\t    oid_to_hex(&p->object.oid));\n@@ -696,7 +696,7 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)\n \t\t\t\t * IOW, we pretend this parent is a\n \t\t\t\t * \"root\" commit.\n \t\t\t\t */\n-\t\t\t\tif (parse_commit(p) < 0)\n+\t\t\t\tif (parse_commit(the_repository, p) < 0)\n \t\t\t\t\tdie(\"cannot simplify commit %s (invalid %s)\",\n \t\t\t\t\t    oid_to_hex(&commit->object.oid),\n \t\t\t\t\t    oid_to_hex(&p->object.oid));\ndiff --git a/sequencer.c b/sequencer.c\nindex 4d259d9ae4..e94ed30965 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -507,7 +507,7 @@ static int is_index_unchanged(void)\n \t * the commit is invalid, parse_commit() will complain.  So\n \t * there is nothing for us to say here.  Just return failure.\n \t */\n-\tif (parse_commit(head_commit))\n+\tif (parse_commit(the_repository, head_commit))\n \t\treturn -1;\n \n \tif (!active_cache_tree)\n@@ -700,12 +700,12 @@ static int is_original_commit_empty(struct commit *commit)\n {\n \tconst struct object_id *ptree_oid;\n \n-\tif (parse_commit(commit))\n+\tif (parse_commit(the_repository, commit))\n \t\treturn error(_(\"could not parse commit %s\"),\n \t\t\t     oid_to_hex(&commit->object.oid));\n \tif (commit->parents) {\n \t\tstruct commit *parent = commit->parents->item;\n-\t\tif (parse_commit(parent))\n+\t\tif (parse_commit(the_repository, parent))\n \t\t\treturn error(_(\"could not parse parent commit %s\"),\n \t\t\t\toid_to_hex(&parent->object.oid));\n \t\tptree_oid = &parent->tree->object.oid;\n@@ -1019,7 +1019,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,\n \t\tmsg_file = NULL;\n \t\tgoto fast_forward_edit;\n \t}\n-\tif (parent && parse_commit(parent) < 0)\n+\tif (parent && parse_commit(the_repository, parent) < 0)\n \t\t/* TRANSLATORS: The first %s will be a \"todo\" command like\n \t\t   \"revert\" or \"pick\", the second %s a SHA1. */\n \t\treturn error(_(\"%s: cannot parse parent commit %s\"),\n@@ -2774,7 +2774,7 @@ int skip_unnecessary_picks(void)\n \t\t\tcontinue;\n \t\tif (item->command != TODO_PICK)\n \t\t\tbreak;\n-\t\tif (parse_commit(item->commit)) {\n+\t\tif (parse_commit(the_repository, item->commit)) {\n \t\t\ttodo_list_release(&todo_list);\n \t\t\treturn error(_(\"could not parse commit '%s'\"),\n \t\t\t\toid_to_hex(&item->commit->object.oid));\n@@ -2903,7 +2903,7 @@ int rearrange_squash(void)\n \n \t\titem->commit->util = item;\n \n-\t\tparse_commit(item->commit);\n+\t\tparse_commit(the_repository, item->commit);\n \t\tcommit_buffer = get_commit_buffer(item->commit, NULL);\n \t\tfind_commit_subject(commit_buffer, &subject);\n \t\tformat_subject(&buf, subject, \" \");\ndiff --git a/sha1_name.c b/sha1_name.c\nindex 45b7d6be91..43fe20b927 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -850,7 +850,7 @@ static int get_parent(const char *name, int len,\n \tif (ret)\n \t\treturn ret;\n \tcommit = lookup_commit_reference(the_repository, &oid);\n-\tif (parse_commit(commit))\n+\tif (parse_commit(the_repository, commit))\n \t\treturn -1;\n \tif (!idx) {\n \t\toidcpy(result, &commit->object.oid);\n@@ -882,7 +882,7 @@ static int get_nth_ancestor(const char *name, int len,\n \t\treturn -1;\n \n \twhile (generation--) {\n-\t\tif (parse_commit(commit) || !commit->parents)\n+\t\tif (parse_commit(the_repository, commit) || !commit->parents)\n \t\t\treturn -1;\n \t\tcommit = commit->parents->item;\n \t}\ndiff --git a/shallow.c b/shallow.c\nindex 004f99d4e2..254c1a397a 100644\n--- a/shallow.c\n+++ b/shallow.c\n@@ -194,7 +194,7 @@ struct commit_list *get_shallow_commits_by_rev_list(int ac, const char **av,\n \t\tstruct commit *c = p->item;\n \t\tstruct commit_list *parent;\n \n-\t\tif (parse_commit(c))\n+\t\tif (parse_commit(the_repository, c))\n \t\t\tdie(\"unable to parse commit %s\",\n \t\t\t    oid_to_hex(&c->object.oid));\n \n@@ -515,7 +515,7 @@ static void paint_down(struct paint_info *info, const struct object_id *oid,\n \t\tif (c->object.flags & BOTTOM)\n \t\t\tcontinue;\n \n-\t\tif (parse_commit(c))\n+\t\tif (parse_commit(the_repository, c))\n \t\t\tdie(\"unable to parse commit %s\",\n \t\t\t    oid_to_hex(&c->object.oid));\n \ndiff --git a/tree.c b/tree.c\nindex 07cea88450..1635a01794 100644\n--- a/tree.c\n+++ b/tree.c\n@@ -106,7 +106,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,\n \t\t\t\t    oid_to_hex(entry.oid),\n \t\t\t\t    base->buf, entry.path);\n \n-\t\t\tif (parse_commit(commit))\n+\t\t\tif (parse_commit(the_repository, commit))\n \t\t\t\tdie(\"Invalid commit %s in submodule path %s%s\",\n \t\t\t\t    oid_to_hex(entry.oid),\n \t\t\t\t    base->buf, entry.path);\ndiff --git a/walker.c b/walker.c\nindex b96e00a8f1..6efaf087df 100644\n--- a/walker.c\n+++ b/walker.c\n@@ -76,7 +76,7 @@ static struct commit_list *complete = NULL;\n \n static int process_commit(struct walker *walker, struct commit *commit)\n {\n-\tif (parse_commit(commit))\n+\tif (parse_commit(the_repository, commit))\n \t\treturn -1;\n \n \twhile (complete && complete->item->date >= commit->date) {\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338411","messageId":"20180206001749.218943-47-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 145/194] commit: add repository argument to set_commit_buffer","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:00Z","receivedAt":"2018-02-06T00:25:20Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow callers of set_commit_buffer to\nbe more specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nThe included coccinelle semantic patch will adapt any new callers in\nthe diff produced by `make coccicheck`.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n blame.c  | 2 +-\n commit.c | 4 ++--\n commit.h | 3 ++-\n object.c | 2 +-\n 4 files changed, 6 insertions(+), 5 deletions(-)\n\ndiff --git a/blame.c b/blame.c\nindex ccd6a5097b..1cd39e7a17 100644\n--- a/blame.c\n+++ b/blame.c\n@@ -138,7 +138,7 @@ static void set_commit_buffer_from_strbuf(struct commit *c, struct strbuf *sb)\n {\n \tsize_t len;\n \tvoid *buf = strbuf_detach(sb, &len);\n-\tset_commit_buffer(c, buf, len);\n+\tset_commit_buffer(the_repository, c, buf, len);\n }\n \n /*\ndiff --git a/commit.c b/commit.c\nindex 49c8f76e41..5de78c73fd 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -250,7 +250,7 @@ struct commit_buffer {\n define_commit_slab(buffer_slab, struct commit_buffer);\n static struct buffer_slab buffer_slab = COMMIT_SLAB_INIT(1, buffer_slab);\n \n-void set_commit_buffer(struct commit *commit, void *buffer, unsigned long size)\n+void set_commit_buffer_the_repository(struct commit *commit, void *buffer, unsigned long size)\n {\n \tstruct commit_buffer *v = buffer_slab_at(&buffer_slab, commit);\n \tv->buffer = buffer;\n@@ -408,7 +408,7 @@ int parse_commit_gently_the_repository(struct commit *item, int quiet_on_missing\n \t}\n \tret = parse_commit_buffer(the_repository, item, buffer, size);\n \tif (save_commit_buffer && !ret) {\n-\t\tset_commit_buffer(item, buffer, size);\n+\t\tset_commit_buffer(the_repository, item, buffer, size);\n \t\treturn 0;\n \t}\n \tfree(buffer);\ndiff --git a/commit.h b/commit.h\nindex 16203fb18c..d3ec52d1c1 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -79,7 +79,8 @@ void parse_commit_or_die(struct commit *item);\n  * Associate an object buffer with the commit. The ownership of the\n  * memory is handed over to the commit, and must be free()-able.\n  */\n-void set_commit_buffer(struct commit *, void *buffer, unsigned long size);\n+#define set_commit_buffer(r, c, b, s) set_commit_buffer_##r(c, b, s)\n+void set_commit_buffer_the_repository(struct commit *, void *buffer, unsigned long size);\n \n /*\n  * Get any cached object buffer associated with the commit. Returns NULL\ndiff --git a/object.c b/object.c\nindex db15de6623..7d848b5b7a 100644\n--- a/object.c\n+++ b/object.c\n@@ -215,7 +215,7 @@ struct object *parse_object_buffer_the_repository(const struct object_id *oid, e\n \t\t\tif (parse_commit_buffer(the_repository, commit, buffer, size))\n \t\t\t\treturn NULL;\n \t\t\tif (!get_cached_commit_buffer(commit, NULL)) {\n-\t\t\t\tset_commit_buffer(commit, buffer, size);\n+\t\t\t\tset_commit_buffer(the_repository, commit, buffer, size);\n \t\t\t\t*eaten_p = 1;\n \t\t\t}\n \t\t\tobj = &commit->object;\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338412","messageId":"20180206001749.218943-48-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 146/194] commit: add repository argument to get_cached_commit_buffer","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:01Z","receivedAt":"2018-02-06T00:25:24Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow callers of get_cached_commit_buffer to\nbe more specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n builtin/rev-list.c | 2 +-\n commit.c           | 4 ++--\n commit.h           | 3 ++-\n log-tree.c         | 2 +-\n object.c           | 2 +-\n pretty.c           | 2 +-\n 6 files changed, 8 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin/rev-list.c b/builtin/rev-list.c\nindex 3c2ae454ea..e28e7426a5 100644\n--- a/builtin/rev-list.c\n+++ b/builtin/rev-list.c\n@@ -133,7 +133,7 @@ static void show_commit(struct commit *commit, void *data)\n \telse\n \t\tputchar('\\n');\n \n-\tif (revs->verbose_header && get_cached_commit_buffer(commit, NULL)) {\n+\tif (revs->verbose_header && get_cached_commit_buffer(the_repository, commit, NULL)) {\n \t\tstruct strbuf buf = STRBUF_INIT;\n \t\tstruct pretty_print_context ctx = {0};\n \t\tctx.abbrev = revs->abbrev;\ndiff --git a/commit.c b/commit.c\nindex 5de78c73fd..1863900824 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -257,7 +257,7 @@ void set_commit_buffer_the_repository(struct commit *commit, void *buffer, unsig\n \tv->size = size;\n }\n \n-const void *get_cached_commit_buffer(const struct commit *commit, unsigned long *sizep)\n+const void *get_cached_commit_buffer_the_repository(const struct commit *commit, unsigned long *sizep)\n {\n \tstruct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);\n \tif (!v) {\n@@ -272,7 +272,7 @@ const void *get_cached_commit_buffer(const struct commit *commit, unsigned long\n \n const void *get_commit_buffer(const struct commit *commit, unsigned long *sizep)\n {\n-\tconst void *ret = get_cached_commit_buffer(commit, sizep);\n+\tconst void *ret = get_cached_commit_buffer(the_repository, commit, sizep);\n \tif (!ret) {\n \t\tenum object_type type;\n \t\tunsigned long size;\ndiff --git a/commit.h b/commit.h\nindex d3ec52d1c1..bcecb23722 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -86,7 +86,8 @@ void set_commit_buffer_the_repository(struct commit *, void *buffer, unsigned lo\n  * Get any cached object buffer associated with the commit. Returns NULL\n  * if none. The resulting memory should not be freed.\n  */\n-const void *get_cached_commit_buffer(const struct commit *, unsigned long *size);\n+#define get_cached_commit_buffer(r, c, s) get_cached_commit_buffer_##r(c, s)\n+const void *get_cached_commit_buffer_the_repository(const struct commit *, unsigned long *size);\n \n /*\n  * Get the commit's object contents, either from cache or by reading the object\ndiff --git a/log-tree.c b/log-tree.c\nindex 9fb333605b..c6d2883190 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -661,7 +661,7 @@ void show_log(struct rev_info *opt)\n \t\tshow_mergetag(opt, commit);\n \t}\n \n-\tif (!get_cached_commit_buffer(commit, NULL))\n+\tif (!get_cached_commit_buffer(the_repository, commit, NULL))\n \t\treturn;\n \n \tif (opt->show_notes) {\ndiff --git a/object.c b/object.c\nindex 7d848b5b7a..c2268990dd 100644\n--- a/object.c\n+++ b/object.c\n@@ -214,7 +214,7 @@ struct object *parse_object_buffer_the_repository(const struct object_id *oid, e\n \t\tif (commit) {\n \t\t\tif (parse_commit_buffer(the_repository, commit, buffer, size))\n \t\t\t\treturn NULL;\n-\t\t\tif (!get_cached_commit_buffer(commit, NULL)) {\n+\t\t\tif (!get_cached_commit_buffer(the_repository, commit, NULL)) {\n \t\t\t\tset_commit_buffer(the_repository, commit, buffer, size);\n \t\t\t\t*eaten_p = 1;\n \t\t\t}\ndiff --git a/pretty.c b/pretty.c\nindex 478af1a860..f82d30cd97 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -630,7 +630,7 @@ const char *logmsg_reencode(const struct commit *commit,\n \t\t * the cached copy from get_commit_buffer, we need to duplicate it\n \t\t * to avoid munging the cached copy.\n \t\t */\n-\t\tif (msg == get_cached_commit_buffer(commit, NULL))\n+\t\tif (msg == get_cached_commit_buffer(the_repository, commit, NULL))\n \t\t\tout = xstrdup(msg);\n \t\telse\n \t\t\tout = (char *)msg;\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338413","messageId":"20180206001749.218943-49-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 147/194] commit: add repository argument to unuse_commit_buffer","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:02Z","receivedAt":"2018-02-06T00:25:47Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow callers of unuse_commit_buffer to\nbe more specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nThe included coccinelle semantic patch will adapt any new callers in\nthe diff produced by `make coccicheck`.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n builtin/am.c                          |  2 +-\n builtin/blame.c                       |  4 ++--\n builtin/fast-export.c                 |  2 +-\n builtin/fmt-merge-msg.c               |  2 +-\n builtin/log.c                         |  2 +-\n builtin/replace.c                     |  2 +-\n builtin/reset.c                       |  2 +-\n commit.c                              |  8 ++++----\n commit.h                              |  3 ++-\n contrib/coccinelle/object_store.cocci |  7 +++++++\n fsck.c                                |  2 +-\n merge-recursive.c                     |  2 +-\n notes-merge.c                         |  2 +-\n pretty.c                              |  6 +++---\n revision.c                            |  2 +-\n sequencer.c                           | 16 +++++++++-------\n sha1_name.c                           |  2 +-\n 17 files changed, 38 insertions(+), 28 deletions(-)\n\ndiff --git a/builtin/am.c b/builtin/am.c\nindex 83bc22649e..7072ec78cb 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -1358,7 +1358,7 @@ static void get_commit_info(struct am_state *state, struct commit *commit)\n \t\tdie(_(\"unable to parse commit %s\"), oid_to_hex(&commit->object.oid));\n \tstate->msg = xstrdup(msg + 2);\n \tstate->msg_len = strlen(state->msg);\n-\tunuse_commit_buffer(commit, buffer);\n+\tunuse_commit_buffer(the_repository, commit, buffer);\n }\n \n /**\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex 815b0c75ed..956df42c67 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -192,7 +192,7 @@ static void get_commit_info(struct commit *commit,\n \t\t    &ret->author_time, &ret->author_tz);\n \n \tif (!detailed) {\n-\t\tunuse_commit_buffer(commit, message);\n+\t\tunuse_commit_buffer(the_repository, commit, message);\n \t\treturn;\n \t}\n \n@@ -206,7 +206,7 @@ static void get_commit_info(struct commit *commit,\n \telse\n \t\tstrbuf_addf(&ret->summary, \"(%s)\", oid_to_hex(&commit->object.oid));\n \n-\tunuse_commit_buffer(commit, message);\n+\tunuse_commit_buffer(the_repository, commit, message);\n }\n \n /*\ndiff --git a/builtin/fast-export.c b/builtin/fast-export.c\nindex 1562ac4927..80853bb91a 100644\n--- a/builtin/fast-export.c\n+++ b/builtin/fast-export.c\n@@ -618,7 +618,7 @@ static void handle_commit(struct commit *commit, struct rev_info *rev,\n \t\t\t  ? strlen(message) : 0),\n \t       reencoded ? reencoded : message ? message : \"\");\n \tfree(reencoded);\n-\tunuse_commit_buffer(commit, commit_buffer);\n+\tunuse_commit_buffer(the_repository, commit, commit_buffer);\n \n \tfor (i = 0, p = commit->parents; p; p = p->next) {\n \t\tint mark = get_object_mark(&p->item->object);\ndiff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c\nindex ac98556a1d..c54f045ccd 100644\n--- a/builtin/fmt-merge-msg.c\n+++ b/builtin/fmt-merge-msg.c\n@@ -263,7 +263,7 @@ static void record_person(int which, struct string_list *people,\n {\n \tconst char *buffer = get_commit_buffer(commit, NULL);\n \trecord_person_from_buf(which, people, buffer);\n-\tunuse_commit_buffer(commit, buffer);\n+\tunuse_commit_buffer(the_repository, commit, buffer);\n }\n \n static int cmp_string_list_util_as_integral(const void *a_, const void *b_)\ndiff --git a/builtin/log.c b/builtin/log.c\nindex fce7b07df4..7080c5f776 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -1025,7 +1025,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,\n \t\tconst char *buf = get_commit_buffer(list[i], NULL);\n \t\tif (has_non_ascii(buf))\n \t\t\tneed_8bit_cte = 1;\n-\t\tunuse_commit_buffer(list[i], buf);\n+\t\tunuse_commit_buffer(the_repository, list[i], buf);\n \t}\n \n \tif (!branch_name)\ndiff --git a/builtin/replace.c b/builtin/replace.c\nindex d1a939c17b..1a92c0082a 100644\n--- a/builtin/replace.c\n+++ b/builtin/replace.c\n@@ -403,7 +403,7 @@ static int create_graft(int argc, const char **argv, int force)\n \n \tbuffer = get_commit_buffer(commit, &size);\n \tstrbuf_add(&buf, buffer, size);\n-\tunuse_commit_buffer(commit, buffer);\n+\tunuse_commit_buffer(the_repository, commit, buffer);\n \n \treplace_parents(&buf, argc - 1, &argv[1]);\n \ndiff --git a/builtin/reset.c b/builtin/reset.c\nindex ea600bc62a..891dd77a5f 100644\n--- a/builtin/reset.c\n+++ b/builtin/reset.c\n@@ -123,7 +123,7 @@ static void print_new_head_line(struct commit *commit)\n \t}\n \telse\n \t\tprintf(\"\\n\");\n-\tunuse_commit_buffer(commit, msg);\n+\tunuse_commit_buffer(the_repository, commit, msg);\n }\n \n static void update_index_from_diff(struct diff_queue_struct *q,\ndiff --git a/commit.c b/commit.c\nindex 1863900824..fa578a2d22 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -290,7 +290,7 @@ const void *get_commit_buffer(const struct commit *commit, unsigned long *sizep)\n \treturn ret;\n }\n \n-void unuse_commit_buffer(const struct commit *commit, const void *buffer)\n+void unuse_commit_buffer_the_repository(const struct commit *commit, const void *buffer)\n {\n \tstruct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);\n \tif (!(v && v->buffer == buffer))\n@@ -630,7 +630,7 @@ static void record_author_date(struct author_date_slab *author_date,\n \t*(author_date_slab_at(author_date, commit)) = date;\n \n fail_exit:\n-\tunuse_commit_buffer(commit, buffer);\n+\tunuse_commit_buffer(the_repository, commit, buffer);\n }\n \n static int compare_commits_by_author_date(const void *a_, const void *b_,\n@@ -1186,7 +1186,7 @@ int parse_signed_commit(const struct commit *commit,\n \t\t}\n \t\tline = next;\n \t}\n-\tunuse_commit_buffer(commit, buffer);\n+\tunuse_commit_buffer(the_repository, commit, buffer);\n \treturn saw_signature;\n }\n \n@@ -1314,7 +1314,7 @@ struct commit_extra_header *read_commit_extra_headers(struct commit *commit,\n \tunsigned long size;\n \tconst char *buffer = get_commit_buffer(commit, &size);\n \textra = read_commit_extra_header_lines(buffer, size, exclude);\n-\tunuse_commit_buffer(commit, buffer);\n+\tunuse_commit_buffer(the_repository, commit, buffer);\n \treturn extra;\n }\n \ndiff --git a/commit.h b/commit.h\nindex bcecb23722..85dd52d1bf 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -102,7 +102,8 @@ const void *get_commit_buffer(const struct commit *, unsigned long *size);\n  * from an earlier call to get_commit_buffer.  The buffer may or may not be\n  * freed by this call; callers should not access the memory afterwards.\n  */\n-void unuse_commit_buffer(const struct commit *, const void *buffer);\n+#define unuse_commit_buffer(r, c, b) unuse_commit_buffer_##r(c, b)\n+void unuse_commit_buffer_the_repository(const struct commit *, const void *buffer);\n \n /*\n  * Free any cached object buffer associated with the commit.\ndiff --git a/contrib/coccinelle/object_store.cocci b/contrib/coccinelle/object_store.cocci\nindex 3ffb34d5b5..b56ebef884 100644\n--- a/contrib/coccinelle/object_store.cocci\n+++ b/contrib/coccinelle/object_store.cocci\n@@ -60,3 +60,10 @@ expression E;\n + the_repository,\n  E)\n \n+@@\n+expression E;\n+expression F;\n+@@\n+ unuse_commit_buffer(\n++the_repository,\n+ E, F)\ndiff --git a/fsck.c b/fsck.c\nindex 494b4e3b30..3155b77348 100644\n--- a/fsck.c\n+++ b/fsck.c\n@@ -794,7 +794,7 @@ static int fsck_commit(struct commit *commit, const char *data,\n \tconst char *buffer = data ?  data : get_commit_buffer(commit, &size);\n \tint ret = fsck_commit_buffer(commit, buffer, size, options);\n \tif (!data)\n-\t\tunuse_commit_buffer(commit, buffer);\n+\t\tunuse_commit_buffer(the_repository, commit, buffer);\n \treturn ret;\n }\n \ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 719fa58ab1..c749785b0b 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -241,7 +241,7 @@ static void output_commit_title(struct merge_options *o, struct commit *commit)\n \t\t\tint len = find_commit_subject(msg, &title);\n \t\t\tif (len)\n \t\t\t\tstrbuf_addf(&o->obuf, \"%.*s\\n\", len, title);\n-\t\t\tunuse_commit_buffer(commit, msg);\n+\t\t\tunuse_commit_buffer(the_repository, commit, msg);\n \t\t}\n \t}\n \tflush_output(o);\ndiff --git a/notes-merge.c b/notes-merge.c\nindex 02729fc474..df66d96811 100644\n--- a/notes-merge.c\n+++ b/notes-merge.c\n@@ -722,7 +722,7 @@ int notes_merge_commit(struct notes_merge_options *o,\n \n \tcreate_notes_commit(partial_tree, partial_commit->parents,\n \t\t\t    msg, strlen(msg), result_oid->hash);\n-\tunuse_commit_buffer(partial_commit, buffer);\n+\tunuse_commit_buffer(the_repository, partial_commit, buffer);\n \tif (o->verbosity >= 4)\n \t\tprintf(\"Finalized notes merge commit: %s\\n\",\n \t\t\toid_to_hex(result_oid));\ndiff --git a/pretty.c b/pretty.c\nindex f82d30cd97..9a7f19f8c7 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -644,7 +644,7 @@ const char *logmsg_reencode(const struct commit *commit,\n \t\t */\n \t\tout = reencode_string(msg, output_encoding, use_encoding);\n \t\tif (out)\n-\t\t\tunuse_commit_buffer(commit, msg);\n+\t\t\tunuse_commit_buffer(the_repository, commit, msg);\n \t}\n \n \t/*\n@@ -1545,7 +1545,7 @@ void format_commit_message(const struct commit *commit,\n \t}\n \n \tfree(context.commit_encoding);\n-\tunuse_commit_buffer(commit, context.message);\n+\tunuse_commit_buffer(the_repository, commit, context.message);\n }\n \n static void pp_header(struct pretty_print_context *pp,\n@@ -1858,7 +1858,7 @@ void pretty_print_commit(struct pretty_print_context *pp,\n \tif (cmit_fmt_is_mail(pp->fmt) && sb->len <= beginning_of_body)\n \t\tstrbuf_addch(sb, '\\n');\n \n-\tunuse_commit_buffer(commit, reencoded);\n+\tunuse_commit_buffer(the_repository, commit, reencoded);\n }\n \n void pp_commit_easy(enum cmit_fmt fmt, const struct commit *commit,\ndiff --git a/revision.c b/revision.c\nindex 56c1a9a78f..754d7b438e 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -3037,7 +3037,7 @@ static int commit_match(struct commit *commit, struct rev_info *opt)\n \t\tretval = grep_buffer(&opt->grep_filter,\n \t\t\t\t     (char *)message, strlen(message));\n \tstrbuf_release(&buf);\n-\tunuse_commit_buffer(commit, message);\n+\tunuse_commit_buffer(the_repository, commit, message);\n \treturn opt->invert_grep ? !retval : retval;\n }\n \ndiff --git a/sequencer.c b/sequencer.c\nindex e94ed30965..fbbe5267f7 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -260,7 +260,7 @@ static void free_message(struct commit *commit, struct commit_message *msg)\n \tfree(msg->parent_label);\n \tfree(msg->label);\n \tfree(msg->subject);\n-\tunuse_commit_buffer(commit, msg->message);\n+\tunuse_commit_buffer(the_repository, commit, msg->message);\n }\n \n static void print_advice(int show_hint, struct replay_opts *opts)\n@@ -865,7 +865,8 @@ static int update_squash_messages(enum todo_command command,\n \t\tfind_commit_subject(head_message, &body);\n \t\tif (write_message(body, strlen(body),\n \t\t\t\t  rebase_path_fixup_msg(), 0)) {\n-\t\t\tunuse_commit_buffer(head_commit, head_message);\n+\t\t\tunuse_commit_buffer(the_repository, head_commit,\n+\t\t\t\t\t    head_message);\n \t\t\treturn error(_(\"cannot write '%s'\"),\n \t\t\t\t     rebase_path_fixup_msg());\n \t\t}\n@@ -879,7 +880,7 @@ static int update_squash_messages(enum todo_command command,\n \t\tstrbuf_addstr(&buf, \"\\n\\n\");\n \t\tstrbuf_addstr(&buf, body);\n \n-\t\tunuse_commit_buffer(head_commit, head_message);\n+\t\tunuse_commit_buffer(the_repository, head_commit, head_message);\n \t}\n \n \tif (!(message = get_commit_buffer(commit, NULL)))\n@@ -901,7 +902,7 @@ static int update_squash_messages(enum todo_command command,\n \t\tstrbuf_add_commented_lines(&buf, body, strlen(body));\n \t} else\n \t\treturn error(_(\"unknown command: %d\"), command);\n-\tunuse_commit_buffer(commit, message);\n+\tunuse_commit_buffer(the_repository, commit, message);\n \n \tres = write_message(buf.buf, buf.len, rebase_path_squash_msg(), 0);\n \tstrbuf_release(&buf);\n@@ -1560,7 +1561,7 @@ static int walk_revs_populate_todo(struct todo_list *todo_list,\n \t\tsubject_len = find_commit_subject(commit_buffer, &subject);\n \t\tstrbuf_addf(&todo_list->buf, \"%s %s %.*s\\n\", command_string,\n \t\t\tshort_commit_name(commit), subject_len, subject);\n-\t\tunuse_commit_buffer(commit, commit_buffer);\n+\t\tunuse_commit_buffer(the_repository, commit, commit_buffer);\n \t}\n \treturn 0;\n }\n@@ -1818,7 +1819,7 @@ static int make_patch(struct commit *commit, struct replay_opts *opts)\n \t\tconst char *commit_buffer = get_commit_buffer(commit, NULL);\n \t\tfind_commit_subject(commit_buffer, &subject);\n \t\tres |= write_message(subject, strlen(subject), buf.buf, 1);\n-\t\tunuse_commit_buffer(commit, commit_buffer);\n+\t\tunuse_commit_buffer(the_repository, commit, commit_buffer);\n \t}\n \tstrbuf_release(&buf);\n \n@@ -2908,7 +2909,8 @@ int rearrange_squash(void)\n \t\tfind_commit_subject(commit_buffer, &subject);\n \t\tformat_subject(&buf, subject, \" \");\n \t\tsubject = subjects[i] = strbuf_detach(&buf, &subject_len);\n-\t\tunuse_commit_buffer(item->commit, commit_buffer);\n+\t\tunuse_commit_buffer(the_repository, item->commit,\n+\t\t\t\t    commit_buffer);\n \t\tif ((skip_prefix(subject, \"fixup! \", &p) ||\n \t\t     skip_prefix(subject, \"squash! \", &p))) {\n \t\t\tstruct commit *commit2;\ndiff --git a/sha1_name.c b/sha1_name.c\nindex 43fe20b927..a60eaf14d2 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -1153,7 +1153,7 @@ static int get_oid_oneline(const char *prefix, struct object_id *oid,\n \t\tbuf = get_commit_buffer(commit, NULL);\n \t\tp = strstr(buf, \"\\n\\n\");\n \t\tmatches = negative ^ (p && !regexec(&regex, p + 2, 0, NULL, 0));\n-\t\tunuse_commit_buffer(commit, buf);\n+\t\tunuse_commit_buffer(the_repository, commit, buf);\n \n \t\tif (matches) {\n \t\t\toidcpy(oid, &commit->object.oid);\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338414","messageId":"20180206001749.218943-50-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 148/194] commit: add repository argument to free_commit_buffer","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:03Z","receivedAt":"2018-02-06T00:25:49Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Add a repository argument to allow callers of free_commit_buffer to\nbe more specific about which repository to handle. This is a small\nmechanical change; it doesn't change the implementation to handle\nrepositories other than the_repository yet.\n\nAs with the previous commits, use a macro to catch callers passing a\nrepository other than the_repository at compile time.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n builtin/fsck.c     | 2 +-\n builtin/log.c      | 4 ++--\n builtin/rev-list.c | 2 +-\n commit.c           | 2 +-\n commit.h           | 3 ++-\n 5 files changed, 7 insertions(+), 6 deletions(-)\n\ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex 2e8b298384..01c612f75f 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -365,7 +365,7 @@ static int fsck_obj(struct object *obj)\n \tif (obj->type == OBJ_TREE)\n \t\tfree_tree_buffer((struct tree *)obj);\n \tif (obj->type == OBJ_COMMIT)\n-\t\tfree_commit_buffer((struct commit *)obj);\n+\t\tfree_commit_buffer(the_repository, (struct commit *)obj);\n \treturn err;\n }\n \ndiff --git a/builtin/log.c b/builtin/log.c\nindex 7080c5f776..12426e685f 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -386,7 +386,7 @@ static int cmd_log_walk(struct rev_info *rev)\n \t\t\t * We may show a given commit multiple times when\n \t\t\t * walking the reflogs.\n \t\t\t */\n-\t\t\tfree_commit_buffer(commit);\n+\t\t\tfree_commit_buffer(the_repository, commit);\n \t\t\tfree_commit_list(commit->parents);\n \t\t\tcommit->parents = NULL;\n \t\t}\n@@ -1813,7 +1813,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t\t    open_next_file(rev.numbered_files ? NULL : commit, NULL, &rev, quiet))\n \t\t\tdie(_(\"Failed to create output files\"));\n \t\tshown = log_tree_commit(&rev, commit);\n-\t\tfree_commit_buffer(commit);\n+\t\tfree_commit_buffer(the_repository, commit);\n \n \t\t/* We put one extra blank line between formatted\n \t\t * patches and this flag is used by log-tree code\ndiff --git a/builtin/rev-list.c b/builtin/rev-list.c\nindex e28e7426a5..142ba35fdb 100644\n--- a/builtin/rev-list.c\n+++ b/builtin/rev-list.c\n@@ -193,7 +193,7 @@ static void finish_commit(struct commit *commit, void *data)\n \t\tfree_commit_list(commit->parents);\n \t\tcommit->parents = NULL;\n \t}\n-\tfree_commit_buffer(commit);\n+\tfree_commit_buffer(the_repository, commit);\n }\n \n static inline void finish_object__ma(struct object *obj)\ndiff --git a/commit.c b/commit.c\nindex fa578a2d22..8ef8619dec 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -297,7 +297,7 @@ void unuse_commit_buffer_the_repository(const struct commit *commit, const void\n \t\tfree((void *)buffer);\n }\n \n-void free_commit_buffer(struct commit *commit)\n+void free_commit_buffer_the_repository(struct commit *commit)\n {\n \tstruct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);\n \tif (v) {\ndiff --git a/commit.h b/commit.h\nindex 85dd52d1bf..8892989b1d 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -108,7 +108,8 @@ void unuse_commit_buffer_the_repository(const struct commit *, const void *buffe\n /*\n  * Free any cached object buffer associated with the commit.\n  */\n-void free_commit_buffer(struct commit *);\n+#define free_commit_buffer(r, c) free_commit_buffer_##r(c)\n+void free_commit_buffer_the_repository(struct commit *);\n \n /*\n  * Disassociate any cached object buffer from the commit, but do not free it.\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338415","messageId":"20180206001749.218943-51-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 149/194] commit: allow commit buffer functions to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:04Z","receivedAt":"2018-02-06T00:25:53Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n builtin/index-pack.c |  2 +-\n commit.c             | 33 ++++++++++++++++++++++-----------\n commit.h             | 17 ++++++++---------\n object.h             |  6 +++++-\n repository.c         |  6 ++++++\n 5 files changed, 42 insertions(+), 22 deletions(-)\n\ndiff --git a/builtin/index-pack.c b/builtin/index-pack.c\nindex f78e9d2e65..b2b6021ad3 100644\n--- a/builtin/index-pack.c\n+++ b/builtin/index-pack.c\n@@ -870,7 +870,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,\n \t\t\t}\n \t\t\tif (obj->type == OBJ_COMMIT) {\n \t\t\t\tstruct commit *commit = (struct commit *) obj;\n-\t\t\t\tif (detach_commit_buffer(commit, NULL) != data)\n+\t\t\t\tif (detach_commit_buffer(the_repository, commit, NULL) != data)\n \t\t\t\t\tdie(\"BUG: parse_object_buffer transmogrified our buffer\");\n \t\t\t}\n \t\t\tobj->flags |= FLAG_CHECKED;\ndiff --git a/commit.c b/commit.c\nindex 8ef8619dec..a5e570f057 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -248,18 +248,29 @@ struct commit_buffer {\n \tunsigned long size;\n };\n define_commit_slab(buffer_slab, struct commit_buffer);\n-static struct buffer_slab buffer_slab = COMMIT_SLAB_INIT(1, buffer_slab);\n+struct buffer_slab the_repository_buffer_slab = COMMIT_SLAB_INIT(1, the_repository_buffer_slab);\n \n-void set_commit_buffer_the_repository(struct commit *commit, void *buffer, unsigned long size)\n+void alloc_buffer_slab(struct repository *r)\n {\n-\tstruct commit_buffer *v = buffer_slab_at(&buffer_slab, commit);\n+\tr->parsed_objects.buffer_slab = xcalloc(1, sizeof(struct buffer_slab));\n+\tinit_buffer_slab(r->parsed_objects.buffer_slab);\n+}\n+\n+void free_commit_slab(struct repository *r)\n+{\n+\tfree(r->parsed_objects.buffer_slab);\n+}\n+\n+void set_commit_buffer(struct repository *r, struct commit *commit, void *buffer, unsigned long size)\n+{\n+\tstruct commit_buffer *v = buffer_slab_at(r->parsed_objects.buffer_slab, commit);\n \tv->buffer = buffer;\n \tv->size = size;\n }\n \n-const void *get_cached_commit_buffer_the_repository(const struct commit *commit, unsigned long *sizep)\n+const void *get_cached_commit_buffer(struct repository *r, const struct commit *commit, unsigned long *sizep)\n {\n-\tstruct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);\n+\tstruct commit_buffer *v = buffer_slab_peek(r->parsed_objects.buffer_slab, commit);\n \tif (!v) {\n \t\tif (sizep)\n \t\t\t*sizep = 0;\n@@ -290,25 +301,25 @@ const void *get_commit_buffer(const struct commit *commit, unsigned long *sizep)\n \treturn ret;\n }\n \n-void unuse_commit_buffer_the_repository(const struct commit *commit, const void *buffer)\n+void unuse_commit_buffer(struct repository *r, const struct commit *commit, const void *buffer)\n {\n-\tstruct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);\n+\tstruct commit_buffer *v = buffer_slab_peek(r->parsed_objects.buffer_slab, commit);\n \tif (!(v && v->buffer == buffer))\n \t\tfree((void *)buffer);\n }\n \n-void free_commit_buffer_the_repository(struct commit *commit)\n+void free_commit_buffer(struct repository *r, struct commit *commit)\n {\n-\tstruct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);\n+\tstruct commit_buffer *v = buffer_slab_peek(r->parsed_objects.buffer_slab, commit);\n \tif (v) {\n \t\tFREE_AND_NULL(v->buffer);\n \t\tv->size = 0;\n \t}\n }\n \n-const void *detach_commit_buffer(struct commit *commit, unsigned long *sizep)\n+const void *detach_commit_buffer(struct repository *r, struct commit *commit, unsigned long *sizep)\n {\n-\tstruct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);\n+\tstruct commit_buffer *v = buffer_slab_peek(r->parsed_objects.buffer_slab, commit);\n \tvoid *ret;\n \n \tif (!v) {\ndiff --git a/commit.h b/commit.h\nindex 8892989b1d..0d3ccd7279 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -75,19 +75,20 @@ static inline int parse_commit_the_repository(struct commit *item)\n }\n void parse_commit_or_die(struct commit *item);\n \n+extern void alloc_buffer_slab(struct repository *r);\n+extern void free_commit_slab(struct repository *r);\n+\n /*\n  * Associate an object buffer with the commit. The ownership of the\n  * memory is handed over to the commit, and must be free()-able.\n  */\n-#define set_commit_buffer(r, c, b, s) set_commit_buffer_##r(c, b, s)\n-void set_commit_buffer_the_repository(struct commit *, void *buffer, unsigned long size);\n+void set_commit_buffer(struct repository *r, struct commit *, void *buffer, unsigned long size);\n \n /*\n  * Get any cached object buffer associated with the commit. Returns NULL\n  * if none. The resulting memory should not be freed.\n  */\n-#define get_cached_commit_buffer(r, c, s) get_cached_commit_buffer_##r(c, s)\n-const void *get_cached_commit_buffer_the_repository(const struct commit *, unsigned long *size);\n+const void *get_cached_commit_buffer(struct repository *r, const struct commit *, unsigned long *size);\n \n /*\n  * Get the commit's object contents, either from cache or by reading the object\n@@ -102,20 +103,18 @@ const void *get_commit_buffer(const struct commit *, unsigned long *size);\n  * from an earlier call to get_commit_buffer.  The buffer may or may not be\n  * freed by this call; callers should not access the memory afterwards.\n  */\n-#define unuse_commit_buffer(r, c, b) unuse_commit_buffer_##r(c, b)\n-void unuse_commit_buffer_the_repository(const struct commit *, const void *buffer);\n+void unuse_commit_buffer(struct repository *r, const struct commit *, const void *buffer);\n \n /*\n  * Free any cached object buffer associated with the commit.\n  */\n-#define free_commit_buffer(r, c) free_commit_buffer_##r(c)\n-void free_commit_buffer_the_repository(struct commit *);\n+void free_commit_buffer(struct repository *r, struct commit *);\n \n /*\n  * Disassociate any cached object buffer from the commit, but do not free it.\n  * The buffer (or NULL, if none) is returned.\n  */\n-const void *detach_commit_buffer(struct commit *, unsigned long *sizep);\n+const void *detach_commit_buffer(struct repository *r, struct commit *, unsigned long *sizep);\n \n /* Find beginning and length of commit subject. */\n int find_commit_subject(const char *commit_buffer, const char **subject);\ndiff --git a/object.h b/object.h\nindex 513f5eaef4..65b5326e0f 100644\n--- a/object.h\n+++ b/object.h\n@@ -5,6 +5,8 @@ struct object_parser {\n \tstruct object **obj_hash;\n \tint nr_objs, obj_hash_size;\n \n+\tstruct buffer_slab *buffer_slab;\n+\n \t/* parent substitutions from .git/info/grafts and .git/shallow */\n \tstruct commit_graft **grafts;\n \tint grafts_alloc, grafts_nr;\n@@ -17,12 +19,14 @@ struct object_parser {\n \tunsigned commit_count;\n };\n \n+extern struct buffer_slab the_repository_buffer_slab;\n extern struct alloc_state the_repository_blob_state;\n extern struct alloc_state the_repository_tree_state;\n extern struct alloc_state the_repository_commit_state;\n extern struct alloc_state the_repository_tag_state;\n extern struct alloc_state the_repository_object_state;\n-#define OBJECT_PARSER_INIT { NULL, 0, 0, NULL, 0, 0, \\\n+#define OBJECT_PARSER_INIT { NULL, 0, 0, &the_repository_buffer_slab, \\\n+\tNULL, 0, 0, \\\n \t&the_repository_blob_state, \\\n \t&the_repository_tree_state, \\\n \t&the_repository_commit_state, \\\ndiff --git a/repository.c b/repository.c\nindex f76f0ddd37..0cf019bb9b 100644\n--- a/repository.c\n+++ b/repository.c\n@@ -2,6 +2,7 @@\n #include \"repository.h\"\n #include \"object-store.h\"\n #include \"config.h\"\n+#include \"commit.h\"\n #include \"submodule-config.h\"\n \n /* The main repository */\n@@ -187,6 +188,8 @@ int repo_init(struct repository *repo, const char *gitdir, const char *worktree)\n \tALLOC_GROW(open_repos, open_repos_nr + 1, open_repos_alloc);\n \topen_repos[open_repos_nr++] = repo;\n \n+\talloc_buffer_slab(repo);\n+\n \treturn 0;\n \n error:\n@@ -249,6 +252,9 @@ int repo_submodule_init(struct repository *submodule,\n void repo_free(struct repository *repo)\n {\n \tint i;\n+\n+\tfree_commit_slab(repo);\n+\n \tfor (i = 0; i < open_repos_nr; i++) {\n \t\tif (open_repos[i] != repo)\n \t\t\tcontinue;\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338416","messageId":"20180206001749.218943-52-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 150/194] tree: allow lookup_tree to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:05Z","receivedAt":"2018-02-06T00:26:14Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n tree.c | 10 +++++-----\n tree.h |  3 +--\n 2 files changed, 6 insertions(+), 7 deletions(-)\n\ndiff --git a/tree.c b/tree.c\nindex 1635a01794..e8150ba54b 100644\n--- a/tree.c\n+++ b/tree.c\n@@ -194,13 +194,13 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match,\n \treturn 0;\n }\n \n-struct tree *lookup_tree_the_repository(const struct object_id *oid)\n+struct tree *lookup_tree(struct repository *r, const struct object_id *oid)\n {\n-\tstruct object *obj = lookup_object(the_repository, oid->hash);\n+\tstruct object *obj = lookup_object(r, oid->hash);\n \tif (!obj)\n-\t\treturn create_object(the_repository, oid->hash,\n-\t\t\t\t     alloc_tree_node(the_repository));\n-\treturn object_as_type(the_repository, obj, OBJ_TREE, 0);\n+\t\treturn create_object(r, oid->hash,\n+\t\t\t\t     alloc_tree_node(r));\n+\treturn object_as_type(r, obj, OBJ_TREE, 0);\n }\n \n int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size)\ndiff --git a/tree.h b/tree.h\nindex 8195db473f..5e7988d390 100644\n--- a/tree.h\n+++ b/tree.h\n@@ -12,8 +12,7 @@ struct tree {\n \tunsigned long size;\n };\n \n-#define lookup_tree(r, oid) lookup_tree_##r(oid)\n-struct tree *lookup_tree_the_repository(const struct object_id *oid);\n+struct tree *lookup_tree(struct repository *r, const struct object_id *oid);\n \n int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size);\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338417","messageId":"20180206001749.218943-53-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 151/194] cache: convert get_graft_file to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:06Z","receivedAt":"2018-02-06T00:26:17Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n cache.h       | 2 +-\n commit.c      | 2 +-\n environment.c | 6 +++---\n 3 files changed, 5 insertions(+), 5 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex ee01daf130..a74a10fe1f 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -489,7 +489,7 @@ extern const char *get_git_dir(void);\n extern const char *get_git_common_dir(void);\n extern char *get_object_directory(void);\n extern char *get_index_file(void);\n-extern char *get_graft_file(void);\n+extern char *get_graft_file(struct repository *r);\n extern int set_git_dir(const char *path);\n extern int get_common_dir_noenv(struct strbuf *sb, const char *gitdir);\n extern int get_common_dir(struct strbuf *sb, const char *gitdir);\ndiff --git a/commit.c b/commit.c\nindex a5e570f057..32eda5f7c9 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -205,7 +205,7 @@ static void prepare_commit_graft_the_repository(void)\n \n \tif (commit_graft_prepared)\n \t\treturn;\n-\tgraft_file = get_graft_file();\n+\tgraft_file = get_graft_file(the_repository);\n \tread_graft_file(the_repository, graft_file);\n \t/* make sure shallows are read */\n \tis_repository_shallow();\ndiff --git a/environment.c b/environment.c\nindex 249516cf6b..972ade61d8 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -287,11 +287,11 @@ char *get_index_file(void)\n \treturn the_repository->index_file;\n }\n \n-char *get_graft_file(void)\n+char *get_graft_file(struct repository *r)\n {\n-\tif (!the_repository->graft_file)\n+\tif (!r->graft_file)\n \t\tBUG(\"git environment hasn't been setup\");\n-\treturn the_repository->graft_file;\n+\treturn r->graft_file;\n }\n \n int set_git_dir(const char *path)\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338418","messageId":"20180206001749.218943-54-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 152/194] shallow: add repository argument to set_alternate_shallow_file","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:07Z","receivedAt":"2018-02-06T00:26:19Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n commit.h      | 3 ++-\n environment.c | 2 +-\n git.c         | 2 +-\n shallow.c     | 2 +-\n 4 files changed, 5 insertions(+), 4 deletions(-)\n\ndiff --git a/commit.h b/commit.h\nindex 0d3ccd7279..7ef21a0fbf 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -204,7 +204,8 @@ extern struct commit_list *get_shallow_commits(struct object_array *heads,\n \t\tint depth, int shallow_flag, int not_shallow_flag);\n extern struct commit_list *get_shallow_commits_by_rev_list(\n \t\tint ac, const char **av, int shallow_flag, int not_shallow_flag);\n-extern void set_alternate_shallow_file(const char *path, int override);\n+#define set_alternate_shallow_file(r, p, o) set_alternate_shallow_file_##r(p, o)\n+extern void set_alternate_shallow_file_the_repository(const char *path, int override);\n extern int write_shallow_commits(struct strbuf *out, int use_pack_protocol,\n \t\t\t\t const struct oid_array *extra);\n extern void setup_alternate_shallow(struct lock_file *shallow_lock,\ndiff --git a/environment.c b/environment.c\nindex 972ade61d8..d3915a5a0a 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -160,7 +160,7 @@ void setup_git_env(void)\n \tnamespace = expand_namespace(getenv(GIT_NAMESPACE_ENVIRONMENT));\n \tshallow_file = getenv(GIT_SHALLOW_FILE_ENVIRONMENT);\n \tif (shallow_file)\n-\t\tset_alternate_shallow_file(shallow_file, 0);\n+\t\tset_alternate_shallow_file(the_repository, shallow_file, 0);\n }\n \n int is_bare_repository(void)\ndiff --git a/git.c b/git.c\nindex c870b9719c..6c5ef91a0d 100644\n--- a/git.c\n+++ b/git.c\n@@ -189,7 +189,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)\n \t\t} else if (!strcmp(cmd, \"--shallow-file\")) {\n \t\t\t(*argv)++;\n \t\t\t(*argc)--;\n-\t\t\tset_alternate_shallow_file((*argv)[0], 1);\n+\t\t\tset_alternate_shallow_file(the_repository, (*argv)[0], 1);\n \t\t\tif (envchanged)\n \t\t\t\t*envchanged = 1;\n \t\t} else if (!strcmp(cmd, \"-C\")) {\ndiff --git a/shallow.c b/shallow.c\nindex 254c1a397a..c26e99fedd 100644\n--- a/shallow.c\n+++ b/shallow.c\n@@ -19,7 +19,7 @@ static int is_shallow = -1;\n static struct stat_validity shallow_stat;\n static char *alternate_shallow_file;\n \n-void set_alternate_shallow_file(const char *path, int override)\n+void set_alternate_shallow_file_the_repository(const char *path, int override)\n {\n \tif (is_shallow != -1)\n \t\tdie(\"BUG: is_repository_shallow must not be called before set_alternate_shallow_file\");\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338419","messageId":"20180206001749.218943-55-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 153/194] shallow: add repository argument to register_shallow","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:08Z","receivedAt":"2018-02-06T00:26:44Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n builtin/pack-objects.c | 2 +-\n builtin/receive-pack.c | 2 +-\n commit.h               | 3 ++-\n fetch-pack.c           | 2 +-\n shallow.c              | 4 ++--\n upload-pack.c          | 7 ++++---\n 6 files changed, 11 insertions(+), 9 deletions(-)\n\ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex 77275058e4..a16ecc3fe0 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -2864,7 +2864,7 @@ static void get_object_list(int ac, const char **av)\n \t\t\t\tstruct object_id oid;\n \t\t\t\tif (get_oid_hex(line + 10, &oid))\n \t\t\t\t\tdie(\"not an SHA-1 '%s'\", line + 10);\n-\t\t\t\tregister_shallow(&oid);\n+\t\t\t\tregister_shallow(the_repository, &oid);\n \t\t\t\tuse_bitmap_index = 0;\n \t\t\t\tcontinue;\n \t\t\t}\ndiff --git a/builtin/receive-pack.c b/builtin/receive-pack.c\nindex 22d805a8ff..7d00f0bad6 100644\n--- a/builtin/receive-pack.c\n+++ b/builtin/receive-pack.c\n@@ -905,7 +905,7 @@ static int update_shallow_ref(struct command *cmd, struct shallow_info *si)\n \t * not lose these new roots..\n \t */\n \tfor (i = 0; i < extra.nr; i++)\n-\t\tregister_shallow(&extra.oid[i]);\n+\t\tregister_shallow(the_repository, &extra.oid[i]);\n \n \tsi->shallow_ref[cmd->index] = 0;\n \toid_array_clear(&extra);\ndiff --git a/commit.h b/commit.h\nindex 7ef21a0fbf..0c854d3679 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -196,7 +196,8 @@ extern struct commit_list *get_merge_bases_many_dirty(struct commit *one, int n,\n \n struct oid_array;\n struct ref;\n-extern int register_shallow(const struct object_id *oid);\n+#define register_shallow(r, o) register_shallow_##r(o);\n+extern int register_shallow_the_repository(const struct object_id *oid);\n extern int unregister_shallow(const struct object_id *oid);\n extern int for_each_commit_graft(each_commit_graft_fn, void *);\n extern int is_repository_shallow(void);\ndiff --git a/fetch-pack.c b/fetch-pack.c\nindex e8b1fc0d1b..1cd738fd62 100644\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -425,7 +425,7 @@ static int find_common(struct fetch_pack_args *args,\n \t\t\tif (skip_prefix(line, \"shallow \", &arg)) {\n \t\t\t\tif (get_oid_hex(arg, &oid))\n \t\t\t\t\tdie(_(\"invalid shallow line: %s\"), line);\n-\t\t\t\tregister_shallow(&oid);\n+\t\t\t\tregister_shallow(the_repository, &oid);\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (skip_prefix(line, \"unshallow \", &arg)) {\ndiff --git a/shallow.c b/shallow.c\nindex c26e99fedd..67feeb3a4f 100644\n--- a/shallow.c\n+++ b/shallow.c\n@@ -29,7 +29,7 @@ void set_alternate_shallow_file_the_repository(const char *path, int override)\n \talternate_shallow_file = xstrdup_or_null(path);\n }\n \n-int register_shallow(const struct object_id *oid)\n+int register_shallow_the_repository(const struct object_id *oid)\n {\n \tstruct commit_graft *graft =\n \t\txmalloc(sizeof(struct commit_graft));\n@@ -70,7 +70,7 @@ int is_repository_shallow(void)\n \t\tstruct object_id oid;\n \t\tif (get_oid_hex(buf, &oid))\n \t\t\tdie(\"bad shallow line: %s\", buf);\n-\t\tregister_shallow(&oid);\n+\t\tregister_shallow(the_repository, &oid);\n \t}\n \tfclose(fp);\n \treturn is_shallow;\ndiff --git a/upload-pack.c b/upload-pack.c\nindex 9c003553f8..ed2d394ace 100644\n--- a/upload-pack.c\n+++ b/upload-pack.c\n@@ -646,7 +646,7 @@ static void send_shallow(struct commit_list *result)\n \t\tif (!(object->flags & (CLIENT_SHALLOW|NOT_SHALLOW))) {\n \t\t\tpacket_write_fmt(1, \"shallow %s\",\n \t\t\t\t\t oid_to_hex(&object->oid));\n-\t\t\tregister_shallow(&object->oid);\n+\t\t\tregister_shallow(the_repository, &object->oid);\n \t\t\tshallow_nr++;\n \t\t}\n \t\tresult = result->next;\n@@ -683,7 +683,7 @@ static void send_unshallow(const struct object_array *shallows)\n \t\t\tadd_object_array(object, NULL, &extra_edge_obj);\n \t\t}\n \t\t/* make sure commit traversal conforms to client */\n-\t\tregister_shallow(&object->oid);\n+\t\tregister_shallow(the_repository, &object->oid);\n \t}\n }\n \n@@ -887,7 +887,8 @@ static void receive_needs(void)\n \t\tif (shallows.nr > 0) {\n \t\t\tint i;\n \t\t\tfor (i = 0; i < shallows.nr; i++)\n-\t\t\t\tregister_shallow(&shallows.objects[i].item->oid);\n+\t\t\t\tregister_shallow(the_repository,\n+\t\t\t\t\t\t &shallows.objects[i].item->oid);\n \t\t}\n \n \tshallow_nr += shallows.nr;\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338420","messageId":"20180206001749.218943-56-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 154/194] shallow: add repository argument to check_shallow_file_for_update","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:09Z","receivedAt":"2018-02-06T00:26:46Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n shallow.c | 7 ++++---\n 1 file changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/shallow.c b/shallow.c\nindex 67feeb3a4f..2a7685fa7c 100644\n--- a/shallow.c\n+++ b/shallow.c\n@@ -219,7 +219,8 @@ struct commit_list *get_shallow_commits_by_rev_list(int ac, const char **av,\n \treturn result;\n }\n \n-static void check_shallow_file_for_update(void)\n+#define check_shallow_file_for_update(r) check_shallow_file_for_update_##r()\n+static void check_shallow_file_for_update_the_repository(void)\n {\n \tif (is_shallow == -1)\n \t\tdie(\"BUG: shallow must be initialized by now\");\n@@ -321,7 +322,7 @@ void setup_alternate_shallow(struct lock_file *shallow_lock,\n \n \tfd = hold_lock_file_for_update(shallow_lock, git_path_shallow(),\n \t\t\t\t       LOCK_DIE_ON_ERROR);\n-\tcheck_shallow_file_for_update();\n+\tcheck_shallow_file_for_update(the_repository);\n \tif (write_shallow_commits(&sb, 0, extra)) {\n \t\tif (write_in_full(fd, sb.buf, sb.len) < 0)\n \t\t\tdie_errno(\"failed to write to %s\",\n@@ -368,7 +369,7 @@ void prune_shallow(int show_only)\n \t}\n \tfd = hold_lock_file_for_update(&shallow_lock, git_path_shallow(),\n \t\t\t\t       LOCK_DIE_ON_ERROR);\n-\tcheck_shallow_file_for_update();\n+\tcheck_shallow_file_for_update(the_repository);\n \tif (write_shallow_commits_1(&sb, 0, NULL, SEEN_ONLY)) {\n \t\tif (write_in_full(fd, sb.buf, sb.len) < 0)\n \t\t\tdie_errno(\"failed to write to %s\",\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338421","messageId":"20180206001749.218943-57-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 155/194] shallow: add repository argument to is_repository_shallow","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:10Z","receivedAt":"2018-02-06T00:26:50Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n builtin/fetch.c                       | 2 +-\n builtin/pack-objects.c                | 4 ++--\n builtin/prune.c                       | 2 +-\n builtin/rev-parse.c                   | 3 ++-\n commit.c                              | 2 +-\n commit.h                              | 2 ++\n contrib/coccinelle/object_store.cocci | 5 +++++\n fetch-pack.c                          | 4 ++--\n send-pack.c                           | 6 +++---\n shallow.c                             | 8 ++++----\n upload-pack.c                         | 2 +-\n 11 files changed, 24 insertions(+), 16 deletions(-)\n\ndiff --git a/builtin/fetch.c b/builtin/fetch.c\nindex 904496fa33..da99363067 100644\n--- a/builtin/fetch.c\n+++ b/builtin/fetch.c\n@@ -1352,7 +1352,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)\n \tif (unshallow) {\n \t\tif (depth)\n \t\t\tdie(_(\"--depth and --unshallow cannot be used together\"));\n-\t\telse if (!is_repository_shallow())\n+\t\telse if (!is_repository_shallow(the_repository))\n \t\t\tdie(_(\"--unshallow on a complete repository does not make sense\"));\n \t\telse\n \t\t\tdepth = xstrfmt(\"%d\", INFINITE_DEPTH);\ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex a16ecc3fe0..9a98154ec4 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -2846,7 +2846,7 @@ static void get_object_list(int ac, const char **av)\n \tsetup_revisions(ac, av, &revs, NULL);\n \n \t/* make sure shallows are read */\n-\tis_repository_shallow();\n+\tis_repository_shallow(the_repository);\n \n \twhile (fgets(line, sizeof(line), stdin) != NULL) {\n \t\tint len = strlen(line);\n@@ -3123,7 +3123,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)\n \t\tuse_bitmap_index = use_bitmap_index_default;\n \n \t/* \"hard\" reasons not to use bitmaps; these just won't work at all */\n-\tif (!use_internal_rev_list || (!pack_to_stdout && write_bitmap_index) || is_repository_shallow())\n+\tif (!use_internal_rev_list || (!pack_to_stdout && write_bitmap_index) || is_repository_shallow(the_repository))\n \t\tuse_bitmap_index = 0;\n \n \tif (pack_to_stdout || !rev_list_all)\ndiff --git a/builtin/prune.c b/builtin/prune.c\nindex 06e6de45b5..9a5f231b3a 100644\n--- a/builtin/prune.c\n+++ b/builtin/prune.c\n@@ -153,7 +153,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix)\n \tremove_temporary_files(s);\n \tfree(s);\n \n-\tif (is_repository_shallow())\n+\tif (is_repository_shallow(the_repository))\n \t\tprune_shallow(show_only);\n \n \treturn 0;\ndiff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\nindex b5515df1ae..5911714441 100644\n--- a/builtin/rev-parse.c\n+++ b/builtin/rev-parse.c\n@@ -879,7 +879,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (!strcmp(arg, \"--is-shallow-repository\")) {\n-\t\t\t\tprintf(\"%s\\n\", is_repository_shallow() ? \"true\"\n+\t\t\t\tprintf(\"%s\\n\",\n+\t\t\t\t\t\tis_repository_shallow(the_repository) ? \"true\"\n \t\t\t\t\t\t: \"false\");\n \t\t\t\tcontinue;\n \t\t\t}\ndiff --git a/commit.c b/commit.c\nindex 32eda5f7c9..63dac3e601 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -208,7 +208,7 @@ static void prepare_commit_graft_the_repository(void)\n \tgraft_file = get_graft_file(the_repository);\n \tread_graft_file(the_repository, graft_file);\n \t/* make sure shallows are read */\n-\tis_repository_shallow();\n+\tis_repository_shallow(the_repository);\n \tcommit_graft_prepared = 1;\n }\n \ndiff --git a/commit.h b/commit.h\nindex 0c854d3679..06795f0684 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -201,6 +201,8 @@ extern int register_shallow_the_repository(const struct object_id *oid);\n extern int unregister_shallow(const struct object_id *oid);\n extern int for_each_commit_graft(each_commit_graft_fn, void *);\n extern int is_repository_shallow(void);\n+#define is_repository_shallow(r) is_repository_shallow_##r()\n+extern int is_repository_shallow_the_repository(void);\n extern struct commit_list *get_shallow_commits(struct object_array *heads,\n \t\tint depth, int shallow_flag, int not_shallow_flag);\n extern struct commit_list *get_shallow_commits_by_rev_list(\ndiff --git a/contrib/coccinelle/object_store.cocci b/contrib/coccinelle/object_store.cocci\nindex b56ebef884..b22c57ed43 100644\n--- a/contrib/coccinelle/object_store.cocci\n+++ b/contrib/coccinelle/object_store.cocci\n@@ -67,3 +67,8 @@ expression F;\n  unuse_commit_buffer(\n +the_repository,\n  E, F)\n+\n+@@ @@\n+ is_repository_shallow(\n++the_repository\n+ )\ndiff --git a/fetch-pack.c b/fetch-pack.c\nindex 1cd738fd62..01e5b36661 100644\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -397,7 +397,7 @@ static int find_common(struct fetch_pack_args *args,\n \t\treturn 1;\n \t}\n \n-\tif (is_repository_shallow())\n+\tif (is_repository_shallow(the_repository))\n \t\twrite_shallow_commits(&req_buf, 1, NULL);\n \tif (args->depth > 0)\n \t\tpacket_buf_write(&req_buf, \"deepen %d\", args->depth);\n@@ -927,7 +927,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,\n \tsort_ref_list(&ref, ref_compare_name);\n \tQSORT(sought, nr_sought, cmp_ref_by_name);\n \n-\tif ((args->depth > 0 || is_repository_shallow()) && !server_supports(\"shallow\"))\n+\tif ((args->depth > 0 || is_repository_shallow(the_repository)) && !server_supports(\"shallow\"))\n \t\tdie(_(\"Server does not support shallow clients\"));\n \tif (args->depth > 0 || args->deepen_since || args->deepen_not)\n \t\targs->deepen = 1;\ndiff --git a/send-pack.c b/send-pack.c\nindex c2856dcfd5..b6080b9c35 100644\n--- a/send-pack.c\n+++ b/send-pack.c\n@@ -76,7 +76,7 @@ static int pack_objects(int fd, struct ref *refs, struct oid_array *extra, struc\n \t\targv_array_push(&po.args, \"-q\");\n \tif (args->progress)\n \t\targv_array_push(&po.args, \"--progress\");\n-\tif (is_repository_shallow())\n+\tif (is_repository_shallow(the_repository))\n \t\targv_array_push(&po.args, \"--shallow\");\n \tpo.in = -1;\n \tpo.out = args->stateless_rpc ? -1 : fd;\n@@ -219,7 +219,7 @@ static int advertise_shallow_grafts_cb(const struct commit_graft *graft, void *c\n \n static void advertise_shallow_grafts_buf(struct strbuf *sb)\n {\n-\tif (!is_repository_shallow())\n+\tif (!is_repository_shallow(the_repository))\n \t\treturn;\n \tfor_each_commit_graft(advertise_shallow_grafts_cb, sb);\n }\n@@ -536,7 +536,7 @@ int send_pack(struct send_pack_args *args,\n \t}\n \n \tif (args->stateless_rpc) {\n-\t\tif (!args->dry_run && (cmds_sent || is_repository_shallow())) {\n+\t\tif (!args->dry_run && (cmds_sent || is_repository_shallow(the_repository))) {\n \t\t\tpacket_buf_flush(&req_buf);\n \t\t\tsend_sideband(out, -1, req_buf.buf, req_buf.len, LARGE_PACKET_MAX);\n \t\t}\ndiff --git a/shallow.c b/shallow.c\nindex 2a7685fa7c..18c6f063c1 100644\n--- a/shallow.c\n+++ b/shallow.c\n@@ -42,7 +42,7 @@ int register_shallow_the_repository(const struct object_id *oid)\n \treturn register_commit_graft(the_repository, graft, 0);\n }\n \n-int is_repository_shallow(void)\n+int is_repository_shallow_the_repository(void)\n {\n \tFILE *fp;\n \tchar buf[1024];\n@@ -110,7 +110,7 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth,\n \t\tparse_commit_or_die(commit);\n \t\tcur_depth++;\n \t\tif ((depth != INFINITE_DEPTH && cur_depth >= depth) ||\n-\t\t    (is_repository_shallow() && !commit->parents &&\n+\t\t    (is_repository_shallow(the_repository) && !commit->parents &&\n \t\t     (graft = lookup_commit_graft(the_repository, &commit->object.oid)) != NULL &&\n \t\t     graft->nr_parent < 0)) {\n \t\t\tcommit_list_insert(commit, &result);\n@@ -169,7 +169,7 @@ struct commit_list *get_shallow_commits_by_rev_list(int ac, const char **av,\n \t */\n \tclear_object_flags(both_flags);\n \n-\tis_repository_shallow(); /* make sure shallows are read */\n+\tis_repository_shallow(the_repository); /* make sure shallows are read */\n \n \tinit_revisions(&revs, NULL);\n \tsave_commit_buffer = 0;\n@@ -347,7 +347,7 @@ static int advertise_shallow_grafts_cb(const struct commit_graft *graft, void *c\n \n void advertise_shallow_grafts(int fd)\n {\n-\tif (!is_repository_shallow())\n+\tif (!is_repository_shallow(the_repository))\n \t\treturn;\n \tfor_each_commit_graft(advertise_shallow_grafts_cb, &fd);\n }\ndiff --git a/upload-pack.c b/upload-pack.c\nindex ed2d394ace..5bf761518f 100644\n--- a/upload-pack.c\n+++ b/upload-pack.c\n@@ -690,7 +690,7 @@ static void send_unshallow(const struct object_array *shallows)\n static void deepen(int depth, int deepen_relative,\n \t\t   struct object_array *shallows)\n {\n-\tif (depth == INFINITE_DEPTH && !is_repository_shallow()) {\n+\tif (depth == INFINITE_DEPTH && !is_repository_shallow(the_repository)) {\n \t\tint i;\n \n \t\tfor (i = 0; i < shallows->nr; i++) {\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338422","messageId":"20180206001749.218943-58-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 156/194] migrate cached path to use the_repository","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:11Z","receivedAt":"2018-02-06T00:27:14Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n blame.c                              |  8 ++++---\n branch.c                             | 14 ++++++------\n builtin/commit.c                     | 38 +++++++++++++++----------------\n builtin/fetch.c                      |  4 ++--\n builtin/merge.c                      | 37 +++++++++++++++---------------\n builtin/pull.c                       |  4 ++--\n builtin/reset.c                      |  2 +-\n contrib/coccinelle/cached_path.cocci | 44 ++++++++++++++++++++++++++++++++++++\n fetch-pack.c                         |  2 +-\n path.c                               | 18 +++++++--------\n path.h                               | 40 ++++++++++++++++++++++++--------\n repository.c                         |  2 +-\n repository.h                         |  5 ++++\n rerere.c                             |  7 +++---\n sequencer.c                          | 33 ++++++++++++++-------------\n shallow.c                            | 12 ++++++----\n wt-status.c                          |  8 +++----\n 17 files changed, 178 insertions(+), 100 deletions(-)\n create mode 100644 contrib/coccinelle/cached_path.cocci\n\ndiff --git a/blame.c b/blame.c\nindex 1cd39e7a17..6832271319 100644\n--- a/blame.c\n+++ b/blame.c\n@@ -112,17 +112,19 @@ static void append_merge_parents(struct commit_list **tail)\n \tint merge_head;\n \tstruct strbuf line = STRBUF_INIT;\n \n-\tmerge_head = open(git_path_merge_head(), O_RDONLY);\n+\tmerge_head = open(git_path_merge_head(the_repository), O_RDONLY);\n \tif (merge_head < 0) {\n \t\tif (errno == ENOENT)\n \t\t\treturn;\n-\t\tdie(\"cannot open '%s' for reading\", git_path_merge_head());\n+\t\tdie(\"cannot open '%s' for reading\",\n+\t\t    git_path_merge_head(the_repository));\n \t}\n \n \twhile (!strbuf_getwholeline_fd(&line, merge_head, '\\n')) {\n \t\tstruct object_id oid;\n \t\tif (line.len < GIT_SHA1_HEXSZ || get_oid_hex(line.buf, &oid))\n-\t\t\tdie(\"unknown line in '%s': %s\", git_path_merge_head(), line.buf);\n+\t\t\tdie(\"unknown line in '%s': %s\",\n+\t\t\t    git_path_merge_head(the_repository), line.buf);\n \t\ttail = append_parent(tail, &oid);\n \t}\n \tclose(merge_head);\ndiff --git a/branch.c b/branch.c\nindex 0b7aaa1aca..08d4efc1be 100644\n--- a/branch.c\n+++ b/branch.c\n@@ -339,13 +339,13 @@ void create_branch(const char *name, const char *start_name,\n \n void remove_branch_state(void)\n {\n-\tunlink(git_path_cherry_pick_head());\n-\tunlink(git_path_revert_head());\n-\tunlink(git_path_merge_head());\n-\tunlink(git_path_merge_rr());\n-\tunlink(git_path_merge_msg());\n-\tunlink(git_path_merge_mode());\n-\tunlink(git_path_squash_msg());\n+\tunlink(git_path_cherry_pick_head(the_repository));\n+\tunlink(git_path_revert_head(the_repository));\n+\tunlink(git_path_merge_head(the_repository));\n+\tunlink(git_path_merge_rr(the_repository));\n+\tunlink(git_path_merge_msg(the_repository));\n+\tunlink(git_path_merge_mode(the_repository));\n+\tunlink(git_path_squash_msg(the_repository));\n }\n \n void die_if_checked_out(const char *branch, int ignore_current_worktree)\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex d15592ad45..cceb965569 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -179,9 +179,9 @@ static int opt_parse_m(const struct option *opt, const char *arg, int unset)\n \n static void determine_whence(struct wt_status *s)\n {\n-\tif (file_exists(git_path_merge_head()))\n+\tif (file_exists(git_path_merge_head(the_repository)))\n \t\twhence = FROM_MERGE;\n-\telse if (file_exists(git_path_cherry_pick_head())) {\n+\telse if (file_exists(git_path_cherry_pick_head(the_repository))) {\n \t\twhence = FROM_CHERRY_PICK;\n \t\tif (file_exists(git_path_seq_dir()))\n \t\t\tsequencer_in_use = 1;\n@@ -732,21 +732,21 @@ static int prepare_to_commit(const char *index_file, const char *prefix,\n \t\tformat_commit_message(commit, \"fixup! %s\\n\\n\",\n \t\t\t\t      &sb, &ctx);\n \t\thook_arg1 = \"message\";\n-\t} else if (!stat(git_path_merge_msg(), &statbuf)) {\n+\t} else if (!stat(git_path_merge_msg(the_repository), &statbuf)) {\n \t\t/*\n \t\t * prepend SQUASH_MSG here if it exists and a\n \t\t * \"merge --squash\" was originally performed\n \t\t */\n-\t\tif (!stat(git_path_squash_msg(), &statbuf)) {\n-\t\t\tif (strbuf_read_file(&sb, git_path_squash_msg(), 0) < 0)\n+\t\tif (!stat(git_path_squash_msg(the_repository), &statbuf)) {\n+\t\t\tif (strbuf_read_file(&sb, git_path_squash_msg(the_repository), 0) < 0)\n \t\t\t\tdie_errno(_(\"could not read SQUASH_MSG\"));\n \t\t\thook_arg1 = \"squash\";\n \t\t} else\n \t\t\thook_arg1 = \"merge\";\n-\t\tif (strbuf_read_file(&sb, git_path_merge_msg(), 0) < 0)\n+\t\tif (strbuf_read_file(&sb, git_path_merge_msg(the_repository), 0) < 0)\n \t\t\tdie_errno(_(\"could not read MERGE_MSG\"));\n-\t} else if (!stat(git_path_squash_msg(), &statbuf)) {\n-\t\tif (strbuf_read_file(&sb, git_path_squash_msg(), 0) < 0)\n+\t} else if (!stat(git_path_squash_msg(the_repository), &statbuf)) {\n+\t\tif (strbuf_read_file(&sb, git_path_squash_msg(the_repository), 0) < 0)\n \t\t\tdie_errno(_(\"could not read SQUASH_MSG\"));\n \t\thook_arg1 = \"squash\";\n \t} else if (template_file) {\n@@ -827,8 +827,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,\n \t\t\t\t\t\"\t%s\\n\"\n \t\t\t\t\t\"and try again.\\n\"),\n \t\t\t\twhence == FROM_MERGE ?\n-\t\t\t\t\tgit_path_merge_head() :\n-\t\t\t\t\tgit_path_cherry_pick_head());\n+\t\t\t\t\tgit_path_merge_head(the_repository) :\n+\t\t\t\t\tgit_path_cherry_pick_head(the_repository));\n \t\t}\n \n \t\tfprintf(s->fp, \"\\n\");\n@@ -1732,7 +1732,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n \t\tif (!reflog_msg)\n \t\t\treflog_msg = \"commit (merge)\";\n \t\tpptr = commit_list_append(current_head, pptr);\n-\t\tfp = xfopen(git_path_merge_head(), \"r\");\n+\t\tfp = xfopen(git_path_merge_head(the_repository), \"r\");\n \t\twhile (strbuf_getline_lf(&m, fp) != EOF) {\n \t\t\tstruct commit *parent;\n \n@@ -1743,8 +1743,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n \t\t}\n \t\tfclose(fp);\n \t\tstrbuf_release(&m);\n-\t\tif (!stat(git_path_merge_mode(), &statbuf)) {\n-\t\t\tif (strbuf_read_file(&sb, git_path_merge_mode(), 0) < 0)\n+\t\tif (!stat(git_path_merge_mode(the_repository), &statbuf)) {\n+\t\t\tif (strbuf_read_file(&sb, git_path_merge_mode(the_repository), 0) < 0)\n \t\t\t\tdie_errno(_(\"could not read MERGE_MODE\"));\n \t\t\tif (!strcmp(sb.buf, \"no-ff\"))\n \t\t\t\tallow_fast_forward = 0;\n@@ -1820,12 +1820,12 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n \t}\n \tref_transaction_free(transaction);\n \n-\tunlink(git_path_cherry_pick_head());\n-\tunlink(git_path_revert_head());\n-\tunlink(git_path_merge_head());\n-\tunlink(git_path_merge_msg());\n-\tunlink(git_path_merge_mode());\n-\tunlink(git_path_squash_msg());\n+\tunlink(git_path_cherry_pick_head(the_repository));\n+\tunlink(git_path_revert_head(the_repository));\n+\tunlink(git_path_merge_head(the_repository));\n+\tunlink(git_path_merge_msg(the_repository));\n+\tunlink(git_path_merge_mode(the_repository));\n+\tunlink(git_path_squash_msg(the_repository));\n \n \tif (commit_index_files())\n \t\tdie (_(\"Repository has been updated, but unable to write\\n\"\ndiff --git a/builtin/fetch.c b/builtin/fetch.c\nindex da99363067..b516b176f0 100644\n--- a/builtin/fetch.c\n+++ b/builtin/fetch.c\n@@ -756,7 +756,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,\n \tconst char *what, *kind;\n \tstruct ref *rm;\n \tchar *url;\n-\tconst char *filename = dry_run ? \"/dev/null\" : git_path_fetch_head();\n+\tconst char *filename = dry_run ? \"/dev/null\" : git_path_fetch_head(the_repository);\n \tint want_status;\n \tint summary_width = transport_summary_width(ref_map);\n \n@@ -1009,7 +1009,7 @@ static void check_not_current_branch(struct ref *ref_map)\n \n static int truncate_fetch_head(void)\n {\n-\tconst char *filename = git_path_fetch_head();\n+\tconst char *filename = git_path_fetch_head(the_repository);\n \tFILE *fp = fopen_for_writing(filename);\n \n \tif (!fp)\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex 30264cfd7c..4f5c01c41c 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -244,9 +244,9 @@ static struct option builtin_merge_options[] = {\n /* Cleans up metadata that is uninteresting after a succeeded merge. */\n static void drop_save(void)\n {\n-\tunlink(git_path_merge_head());\n-\tunlink(git_path_merge_msg());\n-\tunlink(git_path_merge_mode());\n+\tunlink(git_path_merge_head(the_repository));\n+\tunlink(git_path_merge_msg(the_repository));\n+\tunlink(git_path_merge_mode(the_repository));\n }\n \n static int save_state(struct object_id *stash)\n@@ -379,7 +379,7 @@ static void squash_message(struct commit *commit, struct commit_list *remotehead\n \t\t\toid_to_hex(&commit->object.oid));\n \t\tpretty_print_commit(&ctx, commit, &out);\n \t}\n-\twrite_file_buf(git_path_squash_msg(), out.buf, out.len);\n+\twrite_file_buf(git_path_squash_msg(the_repository), out.buf, out.len);\n \tstrbuf_release(&out);\n }\n \n@@ -742,7 +742,7 @@ static void add_strategies(const char *string, unsigned attr)\n \n static void read_merge_msg(struct strbuf *msg)\n {\n-\tconst char *filename = git_path_merge_msg();\n+\tconst char *filename = git_path_merge_msg(the_repository);\n \tstrbuf_reset(msg);\n \tif (strbuf_read_file(msg, filename, 0) < 0)\n \t\tdie_errno(_(\"Could not read from '%s'\"), filename);\n@@ -779,18 +779,18 @@ static void prepare_to_commit(struct commit_list *remoteheads)\n \tif (signoff)\n \t\tappend_signoff(&msg, ignore_non_trailer(msg.buf, msg.len), 0);\n \twrite_merge_heads(remoteheads);\n-\twrite_file_buf(git_path_merge_msg(), msg.buf, msg.len);\n+\twrite_file_buf(git_path_merge_msg(the_repository), msg.buf, msg.len);\n \tif (run_commit_hook(0 < option_edit, get_index_file(), \"prepare-commit-msg\",\n-\t\t\t    git_path_merge_msg(), \"merge\", NULL))\n+\t\t\t    git_path_merge_msg(the_repository), \"merge\", NULL))\n \t\tabort_commit(remoteheads, NULL);\n \tif (0 < option_edit) {\n-\t\tif (launch_editor(git_path_merge_msg(), NULL, NULL))\n+\t\tif (launch_editor(git_path_merge_msg(the_repository), NULL, NULL))\n \t\t\tabort_commit(remoteheads, NULL);\n \t}\n \n \tif (verify_msg && run_commit_hook(0 < option_edit, get_index_file(),\n \t\t\t\t\t  \"commit-msg\",\n-\t\t\t\t\t  git_path_merge_msg(), NULL))\n+\t\t\t\t\t  git_path_merge_msg(the_repository), NULL))\n \t\tabort_commit(remoteheads, NULL);\n \n \tread_merge_msg(&msg);\n@@ -861,7 +861,7 @@ static int suggest_conflicts(void)\n \tFILE *fp;\n \tstruct strbuf msgbuf = STRBUF_INIT;\n \n-\tfilename = git_path_merge_msg();\n+\tfilename = git_path_merge_msg(the_repository);\n \tfp = xfopen(filename, \"a\");\n \n \tappend_conflicts_hint(&msgbuf);\n@@ -941,12 +941,12 @@ static void write_merge_heads(struct commit_list *remoteheads)\n \t\t}\n \t\tstrbuf_addf(&buf, \"%s\\n\", oid_to_hex(oid));\n \t}\n-\twrite_file_buf(git_path_merge_head(), buf.buf, buf.len);\n+\twrite_file_buf(git_path_merge_head(the_repository), buf.buf, buf.len);\n \n \tstrbuf_reset(&buf);\n \tif (fast_forward == FF_NO)\n \t\tstrbuf_addstr(&buf, \"no-ff\");\n-\twrite_file_buf(git_path_merge_mode(), buf.buf, buf.len);\n+\twrite_file_buf(git_path_merge_mode(the_repository), buf.buf, buf.len);\n \tstrbuf_release(&buf);\n }\n \n@@ -954,7 +954,8 @@ static void write_merge_state(struct commit_list *remoteheads)\n {\n \twrite_merge_heads(remoteheads);\n \tstrbuf_addch(&merge_msg, '\\n');\n-\twrite_file_buf(git_path_merge_msg(), merge_msg.buf, merge_msg.len);\n+\twrite_file_buf(git_path_merge_msg(the_repository), merge_msg.buf,\n+\t\t       merge_msg.len);\n }\n \n static int default_edit_option(void)\n@@ -1037,7 +1038,7 @@ static void handle_fetch_head(struct commit_list **remotes, struct strbuf *merge\n \tif (!merge_names)\n \t\tmerge_names = &fetch_head_file;\n \n-\tfilename = git_path_fetch_head();\n+\tfilename = git_path_fetch_head(the_repository);\n \tfd = open(filename, O_RDONLY);\n \tif (fd < 0)\n \t\tdie_errno(_(\"could not open '%s' for reading\"), filename);\n@@ -1174,7 +1175,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \t\t\tusage_msg_opt(_(\"--abort expects no arguments\"),\n \t\t\t      builtin_merge_usage, builtin_merge_options);\n \n-\t\tif (!file_exists(git_path_merge_head()))\n+\t\tif (!file_exists(git_path_merge_head(the_repository)))\n \t\t\tdie(_(\"There is no merge to abort (MERGE_HEAD missing).\"));\n \n \t\t/* Invoke 'git reset --merge' */\n@@ -1190,7 +1191,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \t\t\tusage_msg_opt(_(\"--continue expects no arguments\"),\n \t\t\t      builtin_merge_usage, builtin_merge_options);\n \n-\t\tif (!file_exists(git_path_merge_head()))\n+\t\tif (!file_exists(git_path_merge_head(the_repository)))\n \t\t\tdie(_(\"There is no merge in progress (MERGE_HEAD missing).\"));\n \n \t\t/* Invoke 'git commit' */\n@@ -1201,7 +1202,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \tif (read_cache_unmerged())\n \t\tdie_resolve_conflict(\"merge\");\n \n-\tif (file_exists(git_path_merge_head())) {\n+\tif (file_exists(git_path_merge_head(the_repository))) {\n \t\t/*\n \t\t * There is no unmerged entry, don't advise 'git\n \t\t * add/rm <file>', just 'git commit'.\n@@ -1212,7 +1213,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \t\telse\n \t\t\tdie(_(\"You have not concluded your merge (MERGE_HEAD exists).\"));\n \t}\n-\tif (file_exists(git_path_cherry_pick_head())) {\n+\tif (file_exists(git_path_cherry_pick_head(the_repository))) {\n \t\tif (advice_resolve_conflict)\n \t\t\tdie(_(\"You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists).\\n\"\n \t\t\t    \"Please, commit your changes before you merge.\"));\ndiff --git a/builtin/pull.c b/builtin/pull.c\nindex 90aa922260..0fb48a33be 100644\n--- a/builtin/pull.c\n+++ b/builtin/pull.c\n@@ -351,7 +351,7 @@ static int git_pull_config(const char *var, const char *value, void *cb)\n  */\n static void get_merge_heads(struct oid_array *merge_heads)\n {\n-\tconst char *filename = git_path_fetch_head();\n+\tconst char *filename = git_path_fetch_head(the_repository);\n \tFILE *fp;\n \tstruct strbuf sb = STRBUF_INIT;\n \tstruct object_id oid;\n@@ -858,7 +858,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)\n \tif (read_cache_unmerged())\n \t\tdie_resolve_conflict(\"pull\");\n \n-\tif (file_exists(git_path_merge_head()))\n+\tif (file_exists(git_path_merge_head(the_repository)))\n \t\tdie_conclude_merge();\n \n \tif (get_oid(\"HEAD\", &orig_head))\ndiff --git a/builtin/reset.c b/builtin/reset.c\nindex 891dd77a5f..7c57309adc 100644\n--- a/builtin/reset.c\n+++ b/builtin/reset.c\n@@ -39,7 +39,7 @@ static const char *reset_type_names[] = {\n \n static inline int is_merge(void)\n {\n-\treturn !access(git_path_merge_head(), F_OK);\n+\treturn !access(git_path_merge_head(the_repository), F_OK);\n }\n \n static int reset_index(const struct object_id *oid, int reset_type, int quiet)\ndiff --git a/contrib/coccinelle/cached_path.cocci b/contrib/coccinelle/cached_path.cocci\nnew file mode 100644\nindex 0000000000..41f38fe922\n--- /dev/null\n+++ b/contrib/coccinelle/cached_path.cocci\n@@ -0,0 +1,44 @@\n+@@ @@\n+ git_path_cherry_pick_head(\n++the_repository\n+ )\n+\n+@@ @@\n+ git_path_revert_head(\n++the_repository\n+ )\n+\n+@@ @@\n+ git_path_squash_msg(\n++the_repository\n+ )\n+\n+@@ @@\n+ git_path_merge_msg(\n++the_repository\n+ )\n+\n+@@ @@\n+ git_path_merge_rr(\n++the_repository\n+ )\n+\n+@@ @@\n+ git_path_merge_mode(\n++the_repository\n+ )\n+\n+@@ @@\n+ git_path_merge_head(\n++the_repository\n+ )\n+\n+@@ @@\n+ git_path_fetch_head(\n++the_repository\n+ )\n+\n+@@ @@\n+ git_path_shallow(\n++the_repository\n+ )\ndiff --git a/fetch-pack.c b/fetch-pack.c\nindex 01e5b36661..74265554c3 100644\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -1070,7 +1070,7 @@ static void update_shallow(struct fetch_pack_args *args,\n \n \tif (args->deepen && alternate_shallow_file) {\n \t\tif (*alternate_shallow_file == '\\0') { /* --unshallow */\n-\t\t\tunlink_or_warn(git_path_shallow());\n+\t\t\tunlink_or_warn(git_path_shallow(the_repository));\n \t\t\trollback_lock_file(&shallow_lock);\n \t\t} else\n \t\t\tcommit_lock_file(&shallow_lock);\ndiff --git a/path.c b/path.c\nindex da8b655730..8a88f145cd 100644\n--- a/path.c\n+++ b/path.c\n@@ -1357,12 +1357,12 @@ char *xdg_cache_home(const char *filename)\n \treturn NULL;\n }\n \n-GIT_PATH_FUNC(git_path_cherry_pick_head, \"CHERRY_PICK_HEAD\")\n-GIT_PATH_FUNC(git_path_revert_head, \"REVERT_HEAD\")\n-GIT_PATH_FUNC(git_path_squash_msg, \"SQUASH_MSG\")\n-GIT_PATH_FUNC(git_path_merge_msg, \"MERGE_MSG\")\n-GIT_PATH_FUNC(git_path_merge_rr, \"MERGE_RR\")\n-GIT_PATH_FUNC(git_path_merge_mode, \"MERGE_MODE\")\n-GIT_PATH_FUNC(git_path_merge_head, \"MERGE_HEAD\")\n-GIT_PATH_FUNC(git_path_fetch_head, \"FETCH_HEAD\")\n-GIT_PATH_FUNC(git_path_shallow, \"shallow\")\n+REPO_GIT_PATH_FUNC(path_cherry_pick_head, \"CHERRY_PICK_HEAD\")\n+REPO_GIT_PATH_FUNC(path_revert_head, \"REVERT_HEAD\")\n+REPO_GIT_PATH_FUNC(path_squash_msg, \"SQUASH_MSG\")\n+REPO_GIT_PATH_FUNC(path_merge_msg, \"MERGE_MSG\")\n+REPO_GIT_PATH_FUNC(path_merge_rr, \"MERGE_RR\")\n+REPO_GIT_PATH_FUNC(path_merge_mode, \"MERGE_MODE\")\n+REPO_GIT_PATH_FUNC(path_merge_head, \"MERGE_HEAD\")\n+REPO_GIT_PATH_FUNC(path_fetch_head, \"FETCH_HEAD\")\n+REPO_GIT_PATH_FUNC(path_shallow, \"shallow\")\ndiff --git a/path.h b/path.h\nindex 1ccd0373c9..0fa6172f96 100644\n--- a/path.h\n+++ b/path.h\n@@ -160,14 +160,36 @@ extern void report_linked_checkout_garbage(void);\n \t\treturn ret; \\\n \t}\n \n-const char *git_path_cherry_pick_head(void);\n-const char *git_path_revert_head(void);\n-const char *git_path_squash_msg(void);\n-const char *git_path_merge_msg(void);\n-const char *git_path_merge_rr(void);\n-const char *git_path_merge_mode(void);\n-const char *git_path_merge_head(void);\n-const char *git_path_fetch_head(void);\n-const char *git_path_shallow(void);\n+#define REPO_GIT_PATH_FUNC(var, filename) \\\n+\tconst char *git_##var(struct repository *r) \\\n+\t{ \\\n+\t\tif (!r->cached_paths.var) \\\n+\t\t\tr->cached_paths.var = git_pathdup(filename); \\\n+\t\treturn r->cached_paths.var; \\\n+\t}\n+\n+struct path_cache {\n+\tconst char *path_cherry_pick_head;\n+\tconst char *path_revert_head;\n+\tconst char *path_squash_msg;\n+\tconst char *path_merge_msg;\n+\tconst char *path_merge_rr;\n+\tconst char *path_merge_mode;\n+\tconst char *path_merge_head;\n+\tconst char *path_fetch_head;\n+\tconst char *path_shallow;\n+};\n+\n+#define PATH_CACHE_INIT { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }\n+\n+const char *git_path_cherry_pick_head(struct repository *r);\n+const char *git_path_revert_head(struct repository *r);\n+const char *git_path_squash_msg(struct repository *r);\n+const char *git_path_merge_msg(struct repository *r);\n+const char *git_path_merge_rr(struct repository *r);\n+const char *git_path_merge_mode(struct repository *r);\n+const char *git_path_merge_head(struct repository *r);\n+const char *git_path_fetch_head(struct repository *r);\n+const char *git_path_shallow(struct repository *r);\n \n #endif /* PATH_H */\ndiff --git a/repository.c b/repository.c\nindex 0cf019bb9b..3ee47b4c5d 100644\n--- a/repository.c\n+++ b/repository.c\n@@ -7,7 +7,7 @@\n \n /* The main repository */\n static struct repository the_repo = {\n-\tNULL, NULL, NULL, RAW_OBJECT_STORE_INIT, OBJECT_PARSER_INIT, NULL,\n+\tNULL, NULL, NULL, RAW_OBJECT_STORE_INIT, OBJECT_PARSER_INIT, PATH_CACHE_INIT, NULL,\n \tNULL, NULL, NULL, NULL, NULL, NULL, &the_index, NULL, 0, 0\n };\n struct repository *the_repository = &the_repo;\ndiff --git a/repository.h b/repository.h\nindex 74b2b27986..8de14137b4 100644\n--- a/repository.h\n+++ b/repository.h\n@@ -43,6 +43,11 @@ struct repository {\n \t */\n \tstruct object_parser parsed_objects;\n \n+\t/*\n+\t * Contains path to often used file names.\n+\t */\n+\tstruct path_cache cached_paths;\n+\n \t/*\n \t * The store in which the refs are hold.\n \t */\ndiff --git a/rerere.c b/rerere.c\nindex 30ca5fa56d..dc79b940c5 100644\n--- a/rerere.c\n+++ b/rerere.c\n@@ -202,7 +202,7 @@ static struct rerere_id *new_rerere_id(unsigned char *sha1)\n static void read_rr(struct string_list *rr)\n {\n \tstruct strbuf buf = STRBUF_INIT;\n-\tFILE *in = fopen_or_warn(git_path_merge_rr(), \"r\");\n+\tFILE *in = fopen_or_warn(git_path_merge_rr(the_repository), \"r\");\n \n \tif (!in)\n \t\treturn;\n@@ -900,7 +900,8 @@ int setup_rerere(struct string_list *merge_rr, int flags)\n \tif (flags & RERERE_READONLY)\n \t\tfd = 0;\n \telse\n-\t\tfd = hold_lock_file_for_update(&write_lock, git_path_merge_rr(),\n+\t\tfd = hold_lock_file_for_update(&write_lock,\n+\t\t\t\t\t       git_path_merge_rr(the_repository),\n \t\t\t\t\t       LOCK_DIE_ON_ERROR);\n \tread_rr(merge_rr);\n \treturn fd;\n@@ -1251,6 +1252,6 @@ void rerere_clear(struct string_list *merge_rr)\n \t\t\trmdir(rerere_path(id, NULL));\n \t\t}\n \t}\n-\tunlink_or_warn(git_path_merge_rr());\n+\tunlink_or_warn(git_path_merge_rr(the_repository));\n \trollback_lock_file(&write_lock);\n }\ndiff --git a/sequencer.c b/sequencer.c\nindex fbbe5267f7..521da238b5 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -274,7 +274,7 @@ static void print_advice(int show_hint, struct replay_opts *opts)\n \t\t * (typically rebase --interactive) wants to take care\n \t\t * of the commit itself so remove CHERRY_PICK_HEAD\n \t\t */\n-\t\tunlink(git_path_cherry_pick_head());\n+\t\tunlink(git_path_cherry_pick_head(the_repository));\n \t\treturn;\n \t}\n \n@@ -951,7 +951,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,\n \t\tstruct replay_opts *opts, int final_fixup)\n {\n \tunsigned int flags = opts->edit ? EDIT_MSG : 0;\n-\tconst char *msg_file = opts->edit ? NULL : git_path_merge_msg();\n+\tconst char *msg_file = opts->edit ? NULL : git_path_merge_msg(the_repository);\n \tstruct object_id head;\n \tstruct commit *base, *next, *parent;\n \tconst char *base_label, *next_label;\n@@ -1083,12 +1083,12 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,\n \t\t\tflags |= CLEANUP_MSG;\n \t\t\tmsg_file = rebase_path_fixup_msg();\n \t\t} else {\n-\t\t\tconst char *dest = git_path_squash_msg();\n+\t\t\tconst char *dest = git_path_squash_msg(the_repository);\n \t\t\tunlink(dest);\n \t\t\tif (copy_file(dest, rebase_path_squash_msg(), 0666))\n \t\t\t\treturn error(_(\"could not rename '%s' to '%s'\"),\n \t\t\t\t\t     rebase_path_squash_msg(), dest);\n-\t\t\tunlink(git_path_merge_msg());\n+\t\t\tunlink(git_path_merge_msg(the_repository));\n \t\t\tmsg_file = dest;\n \t\t\tflags |= EDIT_MSG;\n \t\t}\n@@ -1102,13 +1102,13 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,\n \t\tif (res < 0)\n \t\t\treturn res;\n \t\tres |= write_message(msgbuf.buf, msgbuf.len,\n-\t\t\t\t     git_path_merge_msg(), 0);\n+\t\t\t\t     git_path_merge_msg(the_repository), 0);\n \t} else {\n \t\tstruct commit_list *common = NULL;\n \t\tstruct commit_list *remotes = NULL;\n \n \t\tres = write_message(msgbuf.buf, msgbuf.len,\n-\t\t\t\t    git_path_merge_msg(), 0);\n+\t\t\t\t    git_path_merge_msg(the_repository), 0);\n \n \t\tcommit_list_insert(base, &common);\n \t\tcommit_list_insert(next, &remotes);\n@@ -1644,8 +1644,8 @@ static int rollback_single_pick(void)\n {\n \tstruct object_id head_oid;\n \n-\tif (!file_exists(git_path_cherry_pick_head()) &&\n-\t    !file_exists(git_path_revert_head()))\n+\tif (!file_exists(git_path_cherry_pick_head(the_repository)) &&\n+\t    !file_exists(git_path_revert_head(the_repository)))\n \t\treturn error(_(\"no cherry-pick or revert in progress\"));\n \tif (read_ref_full(\"HEAD\", 0, &head_oid, NULL))\n \t\treturn error(_(\"cannot resolve HEAD\"));\n@@ -1870,10 +1870,11 @@ static int error_failed_squash(struct commit *commit,\n \t\treturn error(_(\"could not rename '%s' to '%s'\"),\n \t\t\trebase_path_squash_msg(), rebase_path_message());\n \tunlink(rebase_path_fixup_msg());\n-\tunlink(git_path_merge_msg());\n-\tif (copy_file(git_path_merge_msg(), rebase_path_message(), 0666))\n+\tunlink(git_path_merge_msg(the_repository));\n+\tif (copy_file(git_path_merge_msg(the_repository), rebase_path_message(), 0666))\n \t\treturn error(_(\"could not copy '%s' to '%s'\"),\n-\t\t\t     rebase_path_message(), git_path_merge_msg());\n+\t\t\t     rebase_path_message(),\n+\t\t\t     git_path_merge_msg(the_repository));\n \treturn error_with_patch(commit, subject, subject_len, opts, 1, 0);\n }\n \n@@ -2228,8 +2229,8 @@ static int continue_single_pick(void)\n {\n \tconst char *argv[] = { \"commit\", NULL };\n \n-\tif (!file_exists(git_path_cherry_pick_head()) &&\n-\t    !file_exists(git_path_revert_head()))\n+\tif (!file_exists(git_path_cherry_pick_head(the_repository)) &&\n+\t    !file_exists(git_path_revert_head(the_repository)))\n \t\treturn error(_(\"no cherry-pick or revert in progress\"));\n \treturn run_command_v_opt(argv, RUN_GIT_CMD);\n }\n@@ -2241,7 +2242,7 @@ static int commit_staged_changes(struct replay_opts *opts)\n \tif (has_unstaged_changes(1))\n \t\treturn error(_(\"cannot rebase: You have unstaged changes.\"));\n \tif (!has_uncommitted_changes(0)) {\n-\t\tconst char *cherry_pick_head = git_path_cherry_pick_head();\n+\t\tconst char *cherry_pick_head = git_path_cherry_pick_head(the_repository);\n \n \t\tif (file_exists(cherry_pick_head) && unlink(cherry_pick_head))\n \t\t\treturn error(_(\"could not remove CHERRY_PICK_HEAD\"));\n@@ -2295,8 +2296,8 @@ int sequencer_continue(struct replay_opts *opts)\n \n \tif (!is_rebase_i(opts)) {\n \t\t/* Verify that the conflict has been resolved */\n-\t\tif (file_exists(git_path_cherry_pick_head()) ||\n-\t\t    file_exists(git_path_revert_head())) {\n+\t\tif (file_exists(git_path_cherry_pick_head(the_repository)) ||\n+\t\t    file_exists(git_path_revert_head(the_repository))) {\n \t\t\tres = continue_single_pick();\n \t\t\tif (res)\n \t\t\t\tgoto release_todo_list;\ndiff --git a/shallow.c b/shallow.c\nindex 18c6f063c1..2849046477 100644\n--- a/shallow.c\n+++ b/shallow.c\n@@ -52,7 +52,7 @@ int is_repository_shallow_the_repository(void)\n \t\treturn is_shallow;\n \n \tif (!path)\n-\t\tpath = git_path_shallow();\n+\t\tpath = git_path_shallow(the_repository);\n \t/*\n \t * fetch-pack sets '--shallow-file \"\"' as an indicator that no\n \t * shallow file should be used. We could just open it and it\n@@ -225,7 +225,7 @@ static void check_shallow_file_for_update_the_repository(void)\n \tif (is_shallow == -1)\n \t\tdie(\"BUG: shallow must be initialized by now\");\n \n-\tif (!stat_validity_check(&shallow_stat, git_path_shallow()))\n+\tif (!stat_validity_check(&shallow_stat, git_path_shallow(the_repository)))\n \t\tdie(\"shallow file has changed since we read it\");\n }\n \n@@ -320,7 +320,8 @@ void setup_alternate_shallow(struct lock_file *shallow_lock,\n \tstruct strbuf sb = STRBUF_INIT;\n \tint fd;\n \n-\tfd = hold_lock_file_for_update(shallow_lock, git_path_shallow(),\n+\tfd = hold_lock_file_for_update(shallow_lock,\n+\t\t\t\t       git_path_shallow(the_repository),\n \t\t\t\t       LOCK_DIE_ON_ERROR);\n \tcheck_shallow_file_for_update(the_repository);\n \tif (write_shallow_commits(&sb, 0, extra)) {\n@@ -367,7 +368,8 @@ void prune_shallow(int show_only)\n \t\tstrbuf_release(&sb);\n \t\treturn;\n \t}\n-\tfd = hold_lock_file_for_update(&shallow_lock, git_path_shallow(),\n+\tfd = hold_lock_file_for_update(&shallow_lock,\n+\t\t\t\t       git_path_shallow(the_repository),\n \t\t\t\t       LOCK_DIE_ON_ERROR);\n \tcheck_shallow_file_for_update(the_repository);\n \tif (write_shallow_commits_1(&sb, 0, NULL, SEEN_ONLY)) {\n@@ -376,7 +378,7 @@ void prune_shallow(int show_only)\n \t\t\t\t  get_lock_file_path(&shallow_lock));\n \t\tcommit_lock_file(&shallow_lock);\n \t} else {\n-\t\tunlink(git_path_shallow());\n+\t\tunlink(git_path_shallow(the_repository));\n \t\trollback_lock_file(&shallow_lock);\n \t}\n \tstrbuf_release(&sb);\ndiff --git a/wt-status.c b/wt-status.c\nindex 6655bc6f67..6b2885a2f1 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -1286,7 +1286,7 @@ static void show_rebase_in_progress(struct wt_status *s,\n \t\t\tstatus_printf_ln(s, color,\n \t\t\t\t_(\"  (use \\\"git rebase --abort\\\" to check out the original branch)\"));\n \t\t}\n-\t} else if (state->rebase_in_progress || !stat(git_path_merge_msg(), &st)) {\n+\t} else if (state->rebase_in_progress || !stat(git_path_merge_msg(the_repository), &st)) {\n \t\tprint_rebase_state(s, state, color);\n \t\tif (s->hints)\n \t\t\tstatus_printf_ln(s, color,\n@@ -1521,17 +1521,17 @@ void wt_status_get_state(struct wt_status_state *state,\n \tstruct stat st;\n \tstruct object_id oid;\n \n-\tif (!stat(git_path_merge_head(), &st)) {\n+\tif (!stat(git_path_merge_head(the_repository), &st)) {\n \t\tstate->merge_in_progress = 1;\n \t} else if (wt_status_check_rebase(NULL, state)) {\n \t\t;\t\t/* all set */\n-\t} else if (!stat(git_path_cherry_pick_head(), &st) &&\n+\t} else if (!stat(git_path_cherry_pick_head(the_repository), &st) &&\n \t\t\t!get_oid(\"CHERRY_PICK_HEAD\", &oid)) {\n \t\tstate->cherry_pick_in_progress = 1;\n \t\thashcpy(state->cherry_pick_head_sha1, oid.hash);\n \t}\n \twt_status_check_bisect(NULL, state);\n-\tif (!stat(git_path_revert_head(), &st) &&\n+\tif (!stat(git_path_revert_head(the_repository), &st) &&\n \t    !get_oid(\"REVERT_HEAD\", &oid)) {\n \t\tstate->revert_in_progress = 1;\n \t\thashcpy(state->revert_head_sha1, oid.hash);\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338423","messageId":"20180206001749.218943-59-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 157/194] shallow: migrate shallow information into the object parser","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:12Z","receivedAt":"2018-02-06T00:27:16Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n commit.h     | 11 ++++-------\n object.h     |  6 ++++++\n repository.c |  4 ++++\n shallow.c    | 52 +++++++++++++++++++++++++---------------------------\n 4 files changed, 39 insertions(+), 34 deletions(-)\n\ndiff --git a/commit.h b/commit.h\nindex 06795f0684..cdd12ad75d 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -196,19 +196,16 @@ extern struct commit_list *get_merge_bases_many_dirty(struct commit *one, int n,\n \n struct oid_array;\n struct ref;\n-#define register_shallow(r, o) register_shallow_##r(o);\n-extern int register_shallow_the_repository(const struct object_id *oid);\n+extern int register_shallow(struct repository *r, const struct object_id *oid);\n extern int unregister_shallow(const struct object_id *oid);\n extern int for_each_commit_graft(each_commit_graft_fn, void *);\n-extern int is_repository_shallow(void);\n-#define is_repository_shallow(r) is_repository_shallow_##r()\n-extern int is_repository_shallow_the_repository(void);\n+extern int is_repository_shallow(struct repository *r);\n+extern int for_each_commit_graft_the_repository(each_commit_graft_fn, void *);\n extern struct commit_list *get_shallow_commits(struct object_array *heads,\n \t\tint depth, int shallow_flag, int not_shallow_flag);\n extern struct commit_list *get_shallow_commits_by_rev_list(\n \t\tint ac, const char **av, int shallow_flag, int not_shallow_flag);\n-#define set_alternate_shallow_file(r, p, o) set_alternate_shallow_file_##r(p, o)\n-extern void set_alternate_shallow_file_the_repository(const char *path, int override);\n+extern void set_alternate_shallow_file(struct repository *r, const char *path, int override);\n extern int write_shallow_commits(struct strbuf *out, int use_pack_protocol,\n \t\t\t\t const struct oid_array *extra);\n extern void setup_alternate_shallow(struct lock_file *shallow_lock,\ndiff --git a/object.h b/object.h\nindex 65b5326e0f..369295c7c1 100644\n--- a/object.h\n+++ b/object.h\n@@ -11,6 +11,10 @@ struct object_parser {\n \tstruct commit_graft **grafts;\n \tint grafts_alloc, grafts_nr;\n \n+\tint is_shallow;\n+\tstruct stat_validity *shallow_stat;\n+\tchar *alternate_shallow_file;\n+\n \tstruct alloc_state *blob_state;\n \tstruct alloc_state *tree_state;\n \tstruct alloc_state *commit_state;\n@@ -20,6 +24,7 @@ struct object_parser {\n };\n \n extern struct buffer_slab the_repository_buffer_slab;\n+extern struct stat_validity the_repository_shallow_stat;\n extern struct alloc_state the_repository_blob_state;\n extern struct alloc_state the_repository_tree_state;\n extern struct alloc_state the_repository_commit_state;\n@@ -27,6 +32,7 @@ extern struct alloc_state the_repository_tag_state;\n extern struct alloc_state the_repository_object_state;\n #define OBJECT_PARSER_INIT { NULL, 0, 0, &the_repository_buffer_slab, \\\n \tNULL, 0, 0, \\\n+\t-1, &the_repository_shallow_stat, NULL, \\\n \t&the_repository_blob_state, \\\n \t&the_repository_tree_state, \\\n \t&the_repository_commit_state, \\\ndiff --git a/repository.c b/repository.c\nindex 3ee47b4c5d..64fb6d8b34 100644\n--- a/repository.c\n+++ b/repository.c\n@@ -185,6 +185,10 @@ int repo_init(struct repository *repo, const char *gitdir, const char *worktree)\n \tif (worktree)\n \t\trepo_set_worktree(repo, worktree);\n \n+\trepo->parsed_objects.is_shallow = -1;\n+\trepo->parsed_objects.shallow_stat = xcalloc(1, sizeof(\n+\t\t*repo->parsed_objects.shallow_stat));\n+\n \tALLOC_GROW(open_repos, open_repos_nr + 1, open_repos_alloc);\n \topen_repos[open_repos_nr++] = repo;\n \ndiff --git a/shallow.c b/shallow.c\nindex 2849046477..64a4fcb57f 100644\n--- a/shallow.c\n+++ b/shallow.c\n@@ -14,66 +14,65 @@\n #include \"commit-slab.h\"\n #include \"revision.h\"\n #include \"list-objects.h\"\n+#include \"repository.h\"\n \n-static int is_shallow = -1;\n-static struct stat_validity shallow_stat;\n-static char *alternate_shallow_file;\n+struct stat_validity the_repository_shallow_stat;\n \n-void set_alternate_shallow_file_the_repository(const char *path, int override)\n+void set_alternate_shallow_file(struct repository *r, const char *path, int override)\n {\n-\tif (is_shallow != -1)\n+\tif (r->parsed_objects.is_shallow != -1)\n \t\tdie(\"BUG: is_repository_shallow must not be called before set_alternate_shallow_file\");\n-\tif (alternate_shallow_file && !override)\n+\tif (r->parsed_objects.alternate_shallow_file && !override)\n \t\treturn;\n-\tfree(alternate_shallow_file);\n-\talternate_shallow_file = xstrdup_or_null(path);\n+\tfree(r->parsed_objects.alternate_shallow_file);\n+\tr->parsed_objects.alternate_shallow_file = xstrdup_or_null(path);\n }\n \n-int register_shallow_the_repository(const struct object_id *oid)\n+int register_shallow(struct repository *r, const struct object_id *oid)\n {\n \tstruct commit_graft *graft =\n \t\txmalloc(sizeof(struct commit_graft));\n-\tstruct commit *commit = lookup_commit(the_repository, oid);\n+\tstruct commit *commit = lookup_commit(r, oid);\n \n \toidcpy(&graft->oid, oid);\n \tgraft->nr_parent = -1;\n \tif (commit && commit->object.parsed)\n \t\tcommit->parents = NULL;\n-\treturn register_commit_graft(the_repository, graft, 0);\n+\treturn register_commit_graft(r, graft, 0);\n }\n \n-int is_repository_shallow_the_repository(void)\n+int is_repository_shallow(struct repository *r)\n {\n \tFILE *fp;\n \tchar buf[1024];\n-\tconst char *path = alternate_shallow_file;\n+\tconst char *path = r->parsed_objects.alternate_shallow_file;\n \n-\tif (is_shallow >= 0)\n-\t\treturn is_shallow;\n+\tif (r->parsed_objects.is_shallow >= 0)\n+\t\treturn r->parsed_objects.is_shallow;\n \n \tif (!path)\n-\t\tpath = git_path_shallow(the_repository);\n+\t\tpath = git_path_shallow(r);\n \t/*\n \t * fetch-pack sets '--shallow-file \"\"' as an indicator that no\n \t * shallow file should be used. We could just open it and it\n \t * will likely fail. But let's do an explicit check instead.\n \t */\n \tif (!*path || (fp = fopen(path, \"r\")) == NULL) {\n-\t\tstat_validity_clear(&shallow_stat);\n-\t\tis_shallow = 0;\n-\t\treturn is_shallow;\n+\t\tstat_validity_clear(r->parsed_objects.shallow_stat);\n+\t\tr->parsed_objects.is_shallow = 0;\n+\t\treturn r->parsed_objects.is_shallow;\n \t}\n-\tstat_validity_update(&shallow_stat, fileno(fp));\n-\tis_shallow = 1;\n+\tstat_validity_update(r->parsed_objects.shallow_stat, fileno(fp));\n+\tr->parsed_objects.is_shallow = 1;\n \n \twhile (fgets(buf, sizeof(buf), fp)) {\n \t\tstruct object_id oid;\n \t\tif (get_oid_hex(buf, &oid))\n \t\t\tdie(\"bad shallow line: %s\", buf);\n-\t\tregister_shallow(the_repository, &oid);\n+\t\tregister_shallow(r, &oid);\n \t}\n \tfclose(fp);\n-\treturn is_shallow;\n+\treturn r->parsed_objects.is_shallow;\n }\n \n struct commit_list *get_shallow_commits(struct object_array *heads, int depth,\n@@ -219,13 +218,12 @@ struct commit_list *get_shallow_commits_by_rev_list(int ac, const char **av,\n \treturn result;\n }\n \n-#define check_shallow_file_for_update(r) check_shallow_file_for_update_##r()\n-static void check_shallow_file_for_update_the_repository(void)\n+static void check_shallow_file_for_update(struct repository *r)\n {\n-\tif (is_shallow == -1)\n+\tif (r->parsed_objects.is_shallow == -1)\n \t\tdie(\"BUG: shallow must be initialized by now\");\n \n-\tif (!stat_validity_check(&shallow_stat, git_path_shallow(the_repository)))\n+\tif (!stat_validity_check(r->parsed_objects.shallow_stat, git_path_shallow(the_repository)))\n \t\tdie(\"shallow file has changed since we read it\");\n }\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338424","messageId":"20180206001749.218943-60-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 158/194] commit: allow prepare_commit_graft to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:13Z","receivedAt":"2018-02-06T00:27:20Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n commit.c | 14 ++++++--------\n object.h |  3 +++\n 2 files changed, 9 insertions(+), 8 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex 63dac3e601..fcda65bee2 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -197,19 +197,17 @@ static int read_graft_file(struct repository *r, const char *graft_file)\n \treturn 0;\n }\n \n-#define prepare_commit_graft(r) prepare_commit_graft_##r()\n-static void prepare_commit_graft_the_repository(void)\n+static void prepare_commit_graft(struct repository *r)\n {\n-\tstatic int commit_graft_prepared;\n \tchar *graft_file;\n \n-\tif (commit_graft_prepared)\n+\tif (r->parsed_objects.commit_graft_prepared)\n \t\treturn;\n-\tgraft_file = get_graft_file(the_repository);\n-\tread_graft_file(the_repository, graft_file);\n+\tgraft_file = get_graft_file(r);\n+\tread_graft_file(r, graft_file);\n \t/* make sure shallows are read */\n-\tis_repository_shallow(the_repository);\n-\tcommit_graft_prepared = 1;\n+\tis_repository_shallow(r);\n+\tr->parsed_objects.commit_graft_prepared = 1;\n }\n \n struct commit_graft *lookup_commit_graft_the_repository(const struct object_id *oid)\ndiff --git a/object.h b/object.h\nindex 369295c7c1..14e0d412bb 100644\n--- a/object.h\n+++ b/object.h\n@@ -11,6 +11,8 @@ struct object_parser {\n \tstruct commit_graft **grafts;\n \tint grafts_alloc, grafts_nr;\n \n+\tint commit_graft_prepared;\n+\n \tint is_shallow;\n \tstruct stat_validity *shallow_stat;\n \tchar *alternate_shallow_file;\n@@ -32,6 +34,7 @@ extern struct alloc_state the_repository_tag_state;\n extern struct alloc_state the_repository_object_state;\n #define OBJECT_PARSER_INIT { NULL, 0, 0, &the_repository_buffer_slab, \\\n \tNULL, 0, 0, \\\n+\t0, \\\n \t-1, &the_repository_shallow_stat, NULL, \\\n \t&the_repository_blob_state, \\\n \t&the_repository_tree_state, \\\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338425","messageId":"20180206001749.218943-61-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 159/194] commit: allow lookup_commit_graft to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:14Z","receivedAt":"2018-02-06T00:27:41Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n commit.c | 8 ++++----\n commit.h | 3 +--\n 2 files changed, 5 insertions(+), 6 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex fcda65bee2..a9660f7401 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -210,14 +210,14 @@ static void prepare_commit_graft(struct repository *r)\n \tr->parsed_objects.commit_graft_prepared = 1;\n }\n \n-struct commit_graft *lookup_commit_graft_the_repository(const struct object_id *oid)\n+struct commit_graft *lookup_commit_graft(struct repository *r, const struct object_id *oid)\n {\n \tint pos;\n-\tprepare_commit_graft(the_repository);\n-\tpos = commit_graft_pos(the_repository, oid->hash);\n+\tprepare_commit_graft(r);\n+\tpos = commit_graft_pos(r, oid->hash);\n \tif (pos < 0)\n \t\treturn NULL;\n-\treturn the_repository->parsed_objects.grafts[pos];\n+\treturn r->parsed_objects.grafts[pos];\n }\n \n int for_each_commit_graft(each_commit_graft_fn fn, void *cb_data)\ndiff --git a/commit.h b/commit.h\nindex cdd12ad75d..b53053400d 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -181,8 +181,7 @@ typedef int (*each_commit_graft_fn)(const struct commit_graft *, void *);\n \n struct commit_graft *read_graft_line(struct strbuf *line);\n int register_commit_graft(struct repository *r, struct commit_graft *, int);\n-#define lookup_commit_graft(r, o) lookup_commit_graft_##r(o)\n-struct commit_graft *lookup_commit_graft_the_repository(const struct object_id *oid);\n+struct commit_graft *lookup_commit_graft(struct repository *r, const struct object_id *oid);\n \n extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2);\n extern struct commit_list *get_merge_bases_many(struct commit *one, int n, struct commit **twos);\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338426","messageId":"20180206001749.218943-62-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 160/194] commit: allow arbitrary repository argument for parse_commit_buffer","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:15Z","receivedAt":"2018-02-06T00:27:44Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n commit.c | 10 +++++-----\n commit.h |  3 +--\n 2 files changed, 6 insertions(+), 7 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex a9660f7401..67d329e13c 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -334,7 +334,7 @@ const void *detach_commit_buffer(struct repository *r, struct commit *commit, un\n \treturn ret;\n }\n \n-int parse_commit_buffer_the_repository(struct commit *item, const void *buffer, unsigned long size)\n+int parse_commit_buffer(struct repository *r, struct commit *item, const void *buffer, unsigned long size)\n {\n \tconst char *tail = buffer;\n \tconst char *bufptr = buffer;\n@@ -354,11 +354,11 @@ int parse_commit_buffer_the_repository(struct commit *item, const void *buffer,\n \tif (get_sha1_hex(bufptr + 5, parent.hash) < 0)\n \t\treturn error(\"bad tree pointer in commit %s\",\n \t\t\t     oid_to_hex(&item->object.oid));\n-\titem->tree = lookup_tree(the_repository, &parent);\n+\titem->tree = lookup_tree(r, &parent);\n \tbufptr += tree_entry_len + 1; /* \"tree \" + \"hex sha1\" + \"\\n\" */\n \tpptr = &item->parents;\n \n-\tgraft = lookup_commit_graft(the_repository, &item->object.oid);\n+\tgraft = lookup_commit_graft(r, &item->object.oid);\n \twhile (bufptr + parent_entry_len < tail && !memcmp(bufptr, \"parent \", 7)) {\n \t\tstruct commit *new_parent;\n \n@@ -373,7 +373,7 @@ int parse_commit_buffer_the_repository(struct commit *item, const void *buffer,\n \t\t */\n \t\tif (graft && (graft->nr_parent < 0 || grafts_replace_parents))\n \t\t\tcontinue;\n-\t\tnew_parent = lookup_commit(the_repository, &parent);\n+\t\tnew_parent = lookup_commit(r, &parent);\n \t\tif (new_parent)\n \t\t\tpptr = &commit_list_insert(new_parent, pptr)->next;\n \t}\n@@ -381,7 +381,7 @@ int parse_commit_buffer_the_repository(struct commit *item, const void *buffer,\n \t\tint i;\n \t\tstruct commit *new_parent;\n \t\tfor (i = 0; i < graft->nr_parent; i++) {\n-\t\t\tnew_parent = lookup_commit(the_repository,\n+\t\t\tnew_parent = lookup_commit(r,\n \t\t\t\t\t\t   &graft->parent[i]);\n \t\t\tif (!new_parent)\n \t\t\t\tcontinue;\ndiff --git a/commit.h b/commit.h\nindex b53053400d..8532ddd69c 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -64,8 +64,7 @@ struct commit *lookup_commit_reference_by_name(const char *name);\n  */\n struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref_name);\n \n-#define parse_commit_buffer(r, i, b, s) parse_commit_buffer_##r(i, b, s)\n-int parse_commit_buffer_the_repository(struct commit *item, const void *buffer, unsigned long size);\n+int parse_commit_buffer(struct repository *r, struct commit *item, const void *buffer, unsigned long size);\n #define parse_commit_gently(r, i, q) parse_commit_gently_##r(i, q)\n int parse_commit_gently_the_repository(struct commit *item, int quiet_on_missing);\n #define parse_commit(r, i) parse_commit_##r(i)\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338427","messageId":"20180206001749.218943-63-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 161/194] commit: allow parse_commit_gently to handle arbitrary repository","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:16Z","receivedAt":"2018-02-06T00:27:47Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n commit.c | 8 ++++----\n commit.h | 3 +--\n 2 files changed, 5 insertions(+), 6 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex 67d329e13c..bd9049a9df 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -393,7 +393,7 @@ int parse_commit_buffer(struct repository *r, struct commit *item, const void *b\n \treturn 0;\n }\n \n-int parse_commit_gently_the_repository(struct commit *item, int quiet_on_missing)\n+int parse_commit_gently(struct repository *r, struct commit *item, int quiet_on_missing)\n {\n \tenum object_type type;\n \tvoid *buffer;\n@@ -404,7 +404,7 @@ int parse_commit_gently_the_repository(struct commit *item, int quiet_on_missing\n \t\treturn -1;\n \tif (item->object.parsed)\n \t\treturn 0;\n-\tbuffer = read_sha1_file(the_repository, item->object.oid.hash, &type,\n+\tbuffer = read_sha1_file(r, item->object.oid.hash, &type,\n \t\t\t\t&size);\n \tif (!buffer)\n \t\treturn quiet_on_missing ? -1 :\n@@ -415,9 +415,9 @@ int parse_commit_gently_the_repository(struct commit *item, int quiet_on_missing\n \t\treturn error(\"Object %s not a commit\",\n \t\t\t     oid_to_hex(&item->object.oid));\n \t}\n-\tret = parse_commit_buffer(the_repository, item, buffer, size);\n+\tret = parse_commit_buffer(r, item, buffer, size);\n \tif (save_commit_buffer && !ret) {\n-\t\tset_commit_buffer(the_repository, item, buffer, size);\n+\t\tset_commit_buffer(r, item, buffer, size);\n \t\treturn 0;\n \t}\n \tfree(buffer);\ndiff --git a/commit.h b/commit.h\nindex 8532ddd69c..153f13600b 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -65,8 +65,7 @@ struct commit *lookup_commit_reference_by_name(const char *name);\n struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref_name);\n \n int parse_commit_buffer(struct repository *r, struct commit *item, const void *buffer, unsigned long size);\n-#define parse_commit_gently(r, i, q) parse_commit_gently_##r(i, q)\n-int parse_commit_gently_the_repository(struct commit *item, int quiet_on_missing);\n+int parse_commit_gently(struct repository *r, struct commit *item, int quiet_on_missing);\n #define parse_commit(r, i) parse_commit_##r(i)\n static inline int parse_commit_the_repository(struct commit *item)\n {\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338428","messageId":"20180206001749.218943-64-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 162/194] commit: add repository argument to get_merge_bases_many_0","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:17Z","receivedAt":"2018-02-06T00:28:09Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n commit.c | 9 +++++----\n 1 file changed, 5 insertions(+), 4 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex bd9049a9df..a4f35cd9fc 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -969,7 +969,8 @@ static int remove_redundant(struct commit **array, int cnt)\n \treturn filled;\n }\n \n-static struct commit_list *get_merge_bases_many_0(struct commit *one,\n+#define get_merge_bases_many_0(r, o, n, t, c) get_merge_bases_many_0_##r(o, n, t, c)\n+static struct commit_list *get_merge_bases_many_0_the_repository(struct commit *one,\n \t\t\t\t\t\t  int n,\n \t\t\t\t\t\t  struct commit **twos,\n \t\t\t\t\t\t  int cleanup)\n@@ -1014,19 +1015,19 @@ struct commit_list *get_merge_bases_many(struct commit *one,\n \t\t\t\t\t int n,\n \t\t\t\t\t struct commit **twos)\n {\n-\treturn get_merge_bases_many_0(one, n, twos, 1);\n+\treturn get_merge_bases_many_0(the_repository, one, n, twos, 1);\n }\n \n struct commit_list *get_merge_bases_many_dirty(struct commit *one,\n \t\t\t\t\t       int n,\n \t\t\t\t\t       struct commit **twos)\n {\n-\treturn get_merge_bases_many_0(one, n, twos, 0);\n+\treturn get_merge_bases_many_0(the_repository, one, n, twos, 0);\n }\n \n struct commit_list *get_merge_bases(struct commit *one, struct commit *two)\n {\n-\treturn get_merge_bases_many_0(one, 1, &two, 1);\n+\treturn get_merge_bases_many_0(the_repository, one, 1, &two, 1);\n }\n \n /*\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338429","messageId":"20180206001749.218943-65-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 163/194] commit: add repository argument to merge_bases_many","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:18Z","receivedAt":"2018-02-06T00:28:12Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n commit.c | 5 +++--\n 1 file changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex a4f35cd9fc..ed7349bbd7 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -854,7 +854,8 @@ static struct commit_list *paint_down_to_common(struct commit *one, int n, struc\n \treturn result;\n }\n \n-static struct commit_list *merge_bases_many(struct commit *one, int n, struct commit **twos)\n+#define merge_bases_many(r, o, n, t) merge_bases_many_##r(o, n, t)\n+static struct commit_list *merge_bases_many_the_repository(struct commit *one, int n, struct commit **twos)\n {\n \tstruct commit_list *list = NULL;\n \tstruct commit_list *result = NULL;\n@@ -980,7 +981,7 @@ static struct commit_list *get_merge_bases_many_0_the_repository(struct commit *\n \tstruct commit_list *result;\n \tint cnt, i;\n \n-\tresult = merge_bases_many(one, n, twos);\n+\tresult = merge_bases_many(the_repository, one, n, twos);\n \tfor (i = 0; i < n; i++) {\n \t\tif (one == twos[i])\n \t\t\treturn result;\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338430","messageId":"20180206001749.218943-66-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 164/194] commit: add repository argument to paint_down_to_common","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:19Z","receivedAt":"2018-02-06T00:28:15Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n commit.c | 9 +++++----\n 1 file changed, 5 insertions(+), 4 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex ed7349bbd7..3886266785 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -805,7 +805,8 @@ static int queue_has_nonstale(struct prio_queue *queue)\n }\n \n /* all input commits in one and twos[] must have been parsed! */\n-static struct commit_list *paint_down_to_common(struct commit *one, int n, struct commit **twos)\n+#define paint_down_to_common(r, o, n, t) paint_down_to_common_##r(o, n, t)\n+static struct commit_list *paint_down_to_common_the_repository(struct commit *one, int n, struct commit **twos)\n {\n \tstruct prio_queue queue = { compare_commits_by_commit_date };\n \tstruct commit_list *result = NULL;\n@@ -877,7 +878,7 @@ static struct commit_list *merge_bases_many_the_repository(struct commit *one, i\n \t\t\treturn NULL;\n \t}\n \n-\tlist = paint_down_to_common(one, n, twos);\n+\tlist = paint_down_to_common(the_repository, one, n, twos);\n \n \twhile (list) {\n \t\tstruct commit *commit = pop_commit(&list);\n@@ -944,7 +945,7 @@ static int remove_redundant(struct commit **array, int cnt)\n \t\t\tfilled_index[filled] = j;\n \t\t\twork[filled++] = array[j];\n \t\t}\n-\t\tcommon = paint_down_to_common(array[i], filled, work);\n+\t\tcommon = paint_down_to_common(the_repository, array[i], filled, work);\n \t\tif (array[i]->object.flags & PARENT2)\n \t\t\tredundant[i] = 1;\n \t\tfor (j = 0; j < filled; j++)\n@@ -1063,7 +1064,7 @@ int in_merge_bases_many(struct commit *commit, int nr_reference, struct commit *\n \t\tif (parse_commit(the_repository, reference[i]))\n \t\t\treturn ret;\n \n-\tbases = paint_down_to_common(commit, nr_reference, reference);\n+\tbases = paint_down_to_common(the_repository, commit, nr_reference, reference);\n \tif (commit->object.flags & PARENT2)\n \t\tret = 1;\n \tclear_commit_marks(commit, all_flags);\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338431","messageId":"20180206001749.218943-67-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 165/194] commit: allow parse_commit to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:20Z","receivedAt":"2018-02-06T00:28:38Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n commit.h | 5 ++---\n 1 file changed, 2 insertions(+), 3 deletions(-)\n\ndiff --git a/commit.h b/commit.h\nindex 153f13600b..b60c287e7d 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -66,10 +66,9 @@ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref\n \n int parse_commit_buffer(struct repository *r, struct commit *item, const void *buffer, unsigned long size);\n int parse_commit_gently(struct repository *r, struct commit *item, int quiet_on_missing);\n-#define parse_commit(r, i) parse_commit_##r(i)\n-static inline int parse_commit_the_repository(struct commit *item)\n+static inline int parse_commit(struct repository *r, struct commit *item)\n {\n-\treturn parse_commit_gently(the_repository, item, 0);\n+\treturn parse_commit_gently(r, item, 0);\n }\n void parse_commit_or_die(struct commit *item);\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338432","messageId":"20180206001749.218943-68-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 166/194] commit: allow paint_down_to_common to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:21Z","receivedAt":"2018-02-06T00:28:41Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n commit.c | 5 ++---\n 1 file changed, 2 insertions(+), 3 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex 3886266785..5454bb5e11 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -805,8 +805,7 @@ static int queue_has_nonstale(struct prio_queue *queue)\n }\n \n /* all input commits in one and twos[] must have been parsed! */\n-#define paint_down_to_common(r, o, n, t) paint_down_to_common_##r(o, n, t)\n-static struct commit_list *paint_down_to_common_the_repository(struct commit *one, int n, struct commit **twos)\n+static struct commit_list *paint_down_to_common(struct repository *r, struct commit *one, int n, struct commit **twos)\n {\n \tstruct prio_queue queue = { compare_commits_by_commit_date };\n \tstruct commit_list *result = NULL;\n@@ -844,7 +843,7 @@ static struct commit_list *paint_down_to_common_the_repository(struct commit *on\n \t\t\tparents = parents->next;\n \t\t\tif ((p->object.flags & flags) == flags)\n \t\t\t\tcontinue;\n-\t\t\tif (parse_commit(the_repository, p))\n+\t\t\tif (parse_commit(r, p))\n \t\t\t\treturn NULL;\n \t\t\tp->object.flags |= flags;\n \t\t\tprio_queue_put(&queue, p);\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338433","messageId":"20180206001749.218943-69-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 167/194] commit: allow merge_bases_many to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:22Z","receivedAt":"2018-02-06T00:28:44Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n commit.c | 9 ++++-----\n 1 file changed, 4 insertions(+), 5 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex 5454bb5e11..b01352f54a 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -854,8 +854,7 @@ static struct commit_list *paint_down_to_common(struct repository *r, struct com\n \treturn result;\n }\n \n-#define merge_bases_many(r, o, n, t) merge_bases_many_##r(o, n, t)\n-static struct commit_list *merge_bases_many_the_repository(struct commit *one, int n, struct commit **twos)\n+static struct commit_list *merge_bases_many(struct repository *r, struct commit *one, int n, struct commit **twos)\n {\n \tstruct commit_list *list = NULL;\n \tstruct commit_list *result = NULL;\n@@ -870,14 +869,14 @@ static struct commit_list *merge_bases_many_the_repository(struct commit *one, i\n \t\t\treturn commit_list_insert(one, &result);\n \t}\n \n-\tif (parse_commit(the_repository, one))\n+\tif (parse_commit(r, one))\n \t\treturn NULL;\n \tfor (i = 0; i < n; i++) {\n-\t\tif (parse_commit(the_repository, twos[i]))\n+\t\tif (parse_commit(r, twos[i]))\n \t\t\treturn NULL;\n \t}\n \n-\tlist = paint_down_to_common(the_repository, one, n, twos);\n+\tlist = paint_down_to_common(r, one, n, twos);\n \n \twhile (list) {\n \t\tstruct commit *commit = pop_commit(&list);\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338434","messageId":"20180206001749.218943-70-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 168/194] commit: add repository argument to remove_redundant","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:23Z","receivedAt":"2018-02-06T00:29:07Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n commit.c | 7 ++++---\n 1 file changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex b01352f54a..3ed46e7372 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -913,7 +913,8 @@ struct commit_list *get_octopus_merge_bases(struct commit_list *in)\n \treturn ret;\n }\n \n-static int remove_redundant(struct commit **array, int cnt)\n+#define remove_redundant(r, a, c) remove_redundant_##r(a, c)\n+static int remove_redundant_the_repository(struct commit **array, int cnt)\n {\n \t/*\n \t * Some commit in the array may be an ancestor of\n@@ -1003,7 +1004,7 @@ static struct commit_list *get_merge_bases_many_0_the_repository(struct commit *\n \tclear_commit_marks(one, all_flags);\n \tclear_commit_marks_many(n, twos, all_flags);\n \n-\tcnt = remove_redundant(rslt, cnt);\n+\tcnt = remove_redundant(the_repository, rslt, cnt);\n \tresult = NULL;\n \tfor (i = 0; i < cnt; i++)\n \t\tcommit_list_insert_by_date(rslt[i], &result);\n@@ -1105,7 +1106,7 @@ struct commit_list *reduce_heads(struct commit_list *heads)\n \t\t\tp->item->object.flags &= ~STALE;\n \t\t}\n \t}\n-\tnum_head = remove_redundant(array, num_head);\n+\tnum_head = remove_redundant(the_repository, array, num_head);\n \tfor (i = 0; i < num_head; i++)\n \t\ttail = &commit_list_insert(array[i], tail)->next;\n \tfree(array);\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338435","messageId":"20180206001749.218943-71-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 169/194] commit: allow remove_redundant to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:24Z","receivedAt":"2018-02-06T00:29:10Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n commit.c | 7 +++----\n 1 file changed, 3 insertions(+), 4 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex 3ed46e7372..a8f964c6f9 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -913,8 +913,7 @@ struct commit_list *get_octopus_merge_bases(struct commit_list *in)\n \treturn ret;\n }\n \n-#define remove_redundant(r, a, c) remove_redundant_##r(a, c)\n-static int remove_redundant_the_repository(struct commit **array, int cnt)\n+static int remove_redundant(struct repository *r, struct commit **array, int cnt)\n {\n \t/*\n \t * Some commit in the array may be an ancestor of\n@@ -932,7 +931,7 @@ static int remove_redundant_the_repository(struct commit **array, int cnt)\n \tALLOC_ARRAY(filled_index, cnt - 1);\n \n \tfor (i = 0; i < cnt; i++)\n-\t\tparse_commit(the_repository, array[i]);\n+\t\tparse_commit(r, array[i]);\n \tfor (i = 0; i < cnt; i++) {\n \t\tstruct commit_list *common;\n \n@@ -944,7 +943,7 @@ static int remove_redundant_the_repository(struct commit **array, int cnt)\n \t\t\tfilled_index[filled] = j;\n \t\t\twork[filled++] = array[j];\n \t\t}\n-\t\tcommon = paint_down_to_common(the_repository, array[i], filled, work);\n+\t\tcommon = paint_down_to_common(r, array[i], filled, work);\n \t\tif (array[i]->object.flags & PARENT2)\n \t\t\tredundant[i] = 1;\n \t\tfor (j = 0; j < filled; j++)\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338436","messageId":"20180206001749.218943-72-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 170/194] commit: allow get_merge_bases_many_0 to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:25Z","receivedAt":"2018-02-06T00:29:12Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n commit.c | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex a8f964c6f9..db03550d70 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -969,8 +969,8 @@ static int remove_redundant(struct repository *r, struct commit **array, int cnt\n \treturn filled;\n }\n \n-#define get_merge_bases_many_0(r, o, n, t, c) get_merge_bases_many_0_##r(o, n, t, c)\n-static struct commit_list *get_merge_bases_many_0_the_repository(struct commit *one,\n+static struct commit_list *get_merge_bases_many_0(struct repository *r,\n+\t\t\t\t\t\t  struct commit *one,\n \t\t\t\t\t\t  int n,\n \t\t\t\t\t\t  struct commit **twos,\n \t\t\t\t\t\t  int cleanup)\n@@ -980,7 +980,7 @@ static struct commit_list *get_merge_bases_many_0_the_repository(struct commit *\n \tstruct commit_list *result;\n \tint cnt, i;\n \n-\tresult = merge_bases_many(the_repository, one, n, twos);\n+\tresult = merge_bases_many(r, one, n, twos);\n \tfor (i = 0; i < n; i++) {\n \t\tif (one == twos[i])\n \t\t\treturn result;\n@@ -1003,7 +1003,7 @@ static struct commit_list *get_merge_bases_many_0_the_repository(struct commit *\n \tclear_commit_marks(one, all_flags);\n \tclear_commit_marks_many(n, twos, all_flags);\n \n-\tcnt = remove_redundant(the_repository, rslt, cnt);\n+\tcnt = remove_redundant(r, rslt, cnt);\n \tresult = NULL;\n \tfor (i = 0; i < cnt; i++)\n \t\tcommit_list_insert_by_date(rslt[i], &result);\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338437","messageId":"20180206001749.218943-73-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 171/194] commit: add repository argument to get_merge_bases","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:26Z","receivedAt":"2018-02-06T00:29:36Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n builtin/log.c       | 2 +-\n builtin/merge.c     | 4 ++--\n builtin/rev-parse.c | 2 +-\n commit.c            | 4 ++--\n commit.h            | 3 ++-\n merge-recursive.c   | 2 +-\n notes-merge.c       | 2 +-\n revision.c          | 4 ++--\n sha1_name.c         | 2 +-\n submodule.c         | 2 +-\n 10 files changed, 14 insertions(+), 13 deletions(-)\n\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 12426e685f..3ccab366e7 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -1312,7 +1312,7 @@ static struct commit *get_base_commit(const char *base_commit,\n \twhile (rev_nr > 1) {\n \t\tfor (i = 0; i < rev_nr / 2; i++) {\n \t\t\tstruct commit_list *merge_base;\n-\t\t\tmerge_base = get_merge_bases(rev[2 * i], rev[2 * i + 1]);\n+\t\t\tmerge_base = get_merge_bases(the_repository, rev[2 * i], rev[2 * i + 1]);\n \t\t\tif (!merge_base || merge_base->next)\n \t\t\t\tdie(_(\"Failed to find exact merge base\"));\n \ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex 4f5c01c41c..93a736ac36 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -1352,7 +1352,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \tif (!remoteheads)\n \t\t; /* already up-to-date */\n \telse if (!remoteheads->next)\n-\t\tcommon = get_merge_bases(head_commit, remoteheads->item);\n+\t\tcommon = get_merge_bases(the_repository, head_commit, remoteheads->item);\n \telse {\n \t\tstruct commit_list *list = remoteheads;\n \t\tcommit_list_insert(head_commit, &list);\n@@ -1451,7 +1451,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \t\t\t * merge_bases again, otherwise \"git merge HEAD^\n \t\t\t * HEAD^^\" would be missed.\n \t\t\t */\n-\t\t\tcommon_one = get_merge_bases(head_commit, j->item);\n+\t\t\tcommon_one = get_merge_bases(the_repository, head_commit, j->item);\n \t\t\tif (oidcmp(&common_one->item->object.oid, &j->item->object.oid)) {\n \t\t\t\tup_to_date = 0;\n \t\t\t\tbreak;\ndiff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\nindex 5911714441..3399176e49 100644\n--- a/builtin/rev-parse.c\n+++ b/builtin/rev-parse.c\n@@ -282,7 +282,7 @@ static int try_difference(const char *arg)\n \t\t\tstruct commit *a, *b;\n \t\t\ta = lookup_commit_reference(the_repository, &oid);\n \t\t\tb = lookup_commit_reference(the_repository, &end);\n-\t\t\texclude = get_merge_bases(a, b);\n+\t\t\texclude = get_merge_bases(the_repository, a, b);\n \t\t\twhile (exclude) {\n \t\t\t\tstruct commit *commit = pop_commit(&exclude);\n \t\t\t\tshow_rev(REVERSED, &commit->object.oid, NULL);\ndiff --git a/commit.c b/commit.c\nindex db03550d70..8b1e35d2a1 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -900,7 +900,7 @@ struct commit_list *get_octopus_merge_bases(struct commit_list *in)\n \n \t\tfor (j = ret; j; j = j->next) {\n \t\t\tstruct commit_list *bases;\n-\t\t\tbases = get_merge_bases(i->item, j->item);\n+\t\t\tbases = get_merge_bases(the_repository, i->item, j->item);\n \t\t\tif (!new)\n \t\t\t\tnew = bases;\n \t\t\telse\n@@ -1025,7 +1025,7 @@ struct commit_list *get_merge_bases_many_dirty(struct commit *one,\n \treturn get_merge_bases_many_0(the_repository, one, n, twos, 0);\n }\n \n-struct commit_list *get_merge_bases(struct commit *one, struct commit *two)\n+struct commit_list *get_merge_bases_the_repository(struct commit *one, struct commit *two)\n {\n \treturn get_merge_bases_many_0(the_repository, one, 1, &two, 1);\n }\ndiff --git a/commit.h b/commit.h\nindex b60c287e7d..e671ce68db 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -180,7 +180,8 @@ struct commit_graft *read_graft_line(struct strbuf *line);\n int register_commit_graft(struct repository *r, struct commit_graft *, int);\n struct commit_graft *lookup_commit_graft(struct repository *r, const struct object_id *oid);\n \n-extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2);\n+#define get_merge_bases(r, r1, r2) get_merge_bases_##r(r1, r2)\n+extern struct commit_list *get_merge_bases_the_repository(struct commit *rev1, struct commit *rev2);\n extern struct commit_list *get_merge_bases_many(struct commit *one, int n, struct commit **twos);\n extern struct commit_list *get_octopus_merge_bases(struct commit_list *in);\n \ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex c749785b0b..6e06634993 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -2074,7 +2074,7 @@ int merge_recursive(struct merge_options *o,\n \t}\n \n \tif (!ca) {\n-\t\tca = get_merge_bases(h1, h2);\n+\t\tca = get_merge_bases(the_repository, h1, h2);\n \t\tca = reverse_commit_list(ca);\n \t}\n \ndiff --git a/notes-merge.c b/notes-merge.c\nindex df66d96811..58b518ae0a 100644\n--- a/notes-merge.c\n+++ b/notes-merge.c\n@@ -594,7 +594,7 @@ int notes_merge(struct notes_merge_options *o,\n \tassert(local && remote);\n \n \t/* Find merge bases */\n-\tbases = get_merge_bases(local, remote);\n+\tbases = get_merge_bases(the_repository, local, remote);\n \tif (!bases) {\n \t\tbase_oid = &null_oid;\n \t\tbase_tree_oid = the_hash_algo->empty_tree;\ndiff --git a/revision.c b/revision.c\nindex 754d7b438e..c5d376ba0a 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -1473,7 +1473,7 @@ static void prepare_show_merge(struct rev_info *revs)\n \tother = lookup_commit_or_die(&oid, \"MERGE_HEAD\");\n \tadd_pending_object(revs, &head->object, \"HEAD\");\n \tadd_pending_object(revs, &other->object, \"MERGE_HEAD\");\n-\tbases = get_merge_bases(head, other);\n+\tbases = get_merge_bases(the_repository, head, other);\n \tadd_rev_cmdline_list(revs, bases, REV_CMD_MERGE_BASE, UNINTERESTING | BOTTOM);\n \tadd_pending_commit_list(revs, bases, UNINTERESTING | BOTTOM);\n \tfree_commit_list(bases);\n@@ -1568,7 +1568,7 @@ static int handle_dotdot_1(const char *arg, char *dotdot,\n \t\tif (!a || !b)\n \t\t\treturn dotdot_missing(arg, dotdot, revs, symmetric);\n \n-\t\texclude = get_merge_bases(a, b);\n+\t\texclude = get_merge_bases(the_repository, a, b);\n \t\tadd_rev_cmdline_list(revs, exclude, REV_CMD_MERGE_BASE,\n \t\t\t\t     flags_exclude);\n \t\tadd_pending_commit_list(revs, exclude, flags_exclude);\ndiff --git a/sha1_name.c b/sha1_name.c\nindex a60eaf14d2..7675ec634f 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -1266,7 +1266,7 @@ int get_oid_mb(const char *name, struct object_id *oid)\n \ttwo = lookup_commit_reference_gently(the_repository, &oid_tmp, 0);\n \tif (!two)\n \t\treturn -1;\n-\tmbs = get_merge_bases(one, two);\n+\tmbs = get_merge_bases(the_repository, one, two);\n \tif (!mbs || mbs->next)\n \t\tst = -1;\n \telse {\ndiff --git a/submodule.c b/submodule.c\nindex f9426beff1..af4a1d2cea 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -526,7 +526,7 @@ static void show_submodule_header(struct diff_options *o, const char *path,\n \t     (!is_null_oid(two) && !*right))\n \t\tmessage = \"(commits not present)\";\n \n-\t*merge_bases = get_merge_bases(*left, *right);\n+\t*merge_bases = get_merge_bases(the_repository, *left, *right);\n \tif (*merge_bases) {\n \t\tif ((*merge_bases)->item == *left)\n \t\t\tfast_forward = 1;\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338438","messageId":"20180206001749.218943-74-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 172/194] commit: allow get_merge_bases to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:27Z","receivedAt":"2018-02-06T00:29:38Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n commit.c | 4 ++--\n commit.h | 3 +--\n 2 files changed, 3 insertions(+), 4 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex 8b1e35d2a1..33f5442dc1 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -1025,9 +1025,9 @@ struct commit_list *get_merge_bases_many_dirty(struct commit *one,\n \treturn get_merge_bases_many_0(the_repository, one, n, twos, 0);\n }\n \n-struct commit_list *get_merge_bases_the_repository(struct commit *one, struct commit *two)\n+struct commit_list *get_merge_bases(struct repository *r, struct commit *one, struct commit *two)\n {\n-\treturn get_merge_bases_many_0(the_repository, one, 1, &two, 1);\n+\treturn get_merge_bases_many_0(r, one, 1, &two, 1);\n }\n \n /*\ndiff --git a/commit.h b/commit.h\nindex e671ce68db..7fe6bb0b22 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -180,8 +180,7 @@ struct commit_graft *read_graft_line(struct strbuf *line);\n int register_commit_graft(struct repository *r, struct commit_graft *, int);\n struct commit_graft *lookup_commit_graft(struct repository *r, const struct object_id *oid);\n \n-#define get_merge_bases(r, r1, r2) get_merge_bases_##r(r1, r2)\n-extern struct commit_list *get_merge_bases_the_repository(struct commit *rev1, struct commit *rev2);\n+extern struct commit_list *get_merge_bases(struct repository *r, struct commit *rev1, struct commit *rev2);\n extern struct commit_list *get_merge_bases_many(struct commit *one, int n, struct commit **twos);\n extern struct commit_list *get_octopus_merge_bases(struct commit_list *in);\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338439","messageId":"20180206001749.218943-75-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 173/194] blob: allow lookup_blob to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:28Z","receivedAt":"2018-02-06T00:29:41Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n blob.c | 10 +++++-----\n blob.h |  3 +--\n 2 files changed, 6 insertions(+), 7 deletions(-)\n\ndiff --git a/blob.c b/blob.c\nindex 7c661f178a..5dcaf63697 100644\n--- a/blob.c\n+++ b/blob.c\n@@ -4,13 +4,13 @@\n \n const char *blob_type = \"blob\";\n \n-struct blob *lookup_blob_the_repository(const struct object_id *oid)\n+struct blob *lookup_blob(struct repository *r, const struct object_id *oid)\n {\n-\tstruct object *obj = lookup_object(the_repository, oid->hash);\n+\tstruct object *obj = lookup_object(r, oid->hash);\n \tif (!obj)\n-\t\treturn create_object(the_repository, oid->hash,\n-\t\t\t\t     alloc_blob_node(the_repository));\n-\treturn object_as_type(the_repository, obj, OBJ_BLOB, 0);\n+\t\treturn create_object(r, oid->hash,\n+\t\t\t\t     alloc_blob_node(r));\n+\treturn object_as_type(r, obj, OBJ_BLOB, 0);\n }\n \n int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size)\ndiff --git a/blob.h b/blob.h\nindex 08bc34487a..1664872055 100644\n--- a/blob.h\n+++ b/blob.h\n@@ -9,8 +9,7 @@ struct blob {\n \tstruct object object;\n };\n \n-#define lookup_blob(r, o) lookup_blob_##r(o)\n-struct blob *lookup_blob_the_repository(const struct object_id *oid);\n+struct blob *lookup_blob(struct repository *r, const struct object_id *oid);\n \n int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size);\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338440","messageId":"20180206001749.218943-76-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 174/194] tag: allow lookup_tag to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:29Z","receivedAt":"2018-02-06T00:30:08Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n tag.c | 10 +++++-----\n tag.h |  3 +--\n 2 files changed, 6 insertions(+), 7 deletions(-)\n\ndiff --git a/tag.c b/tag.c\nindex e0b695cb60..52009bf454 100644\n--- a/tag.c\n+++ b/tag.c\n@@ -92,13 +92,13 @@ struct object *deref_tag_noverify(struct object *o)\n \treturn o;\n }\n \n-struct tag *lookup_tag_the_repository(const struct object_id *oid)\n+struct tag *lookup_tag(struct repository *r, const struct object_id *oid)\n {\n-\tstruct object *obj = lookup_object(the_repository, oid->hash);\n+\tstruct object *obj = lookup_object(r, oid->hash);\n \tif (!obj)\n-\t\treturn create_object(the_repository, oid->hash,\n-\t\t\t\t     alloc_tag_node(the_repository));\n-\treturn object_as_type(the_repository, obj, OBJ_TAG, 0);\n+\t\treturn create_object(r, oid->hash,\n+\t\t\t\t     alloc_tag_node(r));\n+\treturn object_as_type(r, obj, OBJ_TAG, 0);\n }\n \n static timestamp_t parse_tag_date(const char *buf, const char *tail)\ndiff --git a/tag.h b/tag.h\nindex 4f45695e1e..d23af572d8 100644\n--- a/tag.h\n+++ b/tag.h\n@@ -11,8 +11,7 @@ struct tag {\n \tchar *tag;\n \ttimestamp_t date;\n };\n-#define lookup_tag(r, o) lookup_tag_##r(o)\n-extern struct tag *lookup_tag_the_repository(const struct object_id *oid);\n+extern struct tag *lookup_tag(struct repository *r, const struct object_id *oid);\n #define parse_tag_buffer(r, i, d, s) parse_tag_buffer_##r(i, d, s)\n extern int parse_tag_buffer_the_repository(struct tag *item, const void *data, unsigned long size);\n extern int parse_tag(struct tag *item);\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338441","messageId":"20180206001749.218943-78-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 176/194] object: allow parse_object_buffer to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:31Z","receivedAt":"2018-02-06T00:30:21Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n object.c | 18 +++++++++---------\n object.h |  3 +--\n 2 files changed, 10 insertions(+), 11 deletions(-)\n\ndiff --git a/object.c b/object.c\nindex c2268990dd..2a05613c64 100644\n--- a/object.c\n+++ b/object.c\n@@ -184,21 +184,21 @@ struct object *lookup_unknown_object(struct repository *r,\n \treturn obj;\n }\n \n-struct object *parse_object_buffer_the_repository(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p)\n+struct object *parse_object_buffer(struct repository *r, const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p)\n {\n \tstruct object *obj;\n \t*eaten_p = 0;\n \n \tobj = NULL;\n \tif (type == OBJ_BLOB) {\n-\t\tstruct blob *blob = lookup_blob(the_repository, oid);\n+\t\tstruct blob *blob = lookup_blob(r, oid);\n \t\tif (blob) {\n \t\t\tif (parse_blob_buffer(blob, buffer, size))\n \t\t\t\treturn NULL;\n \t\t\tobj = &blob->object;\n \t\t}\n \t} else if (type == OBJ_TREE) {\n-\t\tstruct tree *tree = lookup_tree(the_repository, oid);\n+\t\tstruct tree *tree = lookup_tree(r, oid);\n \t\tif (tree) {\n \t\t\tobj = &tree->object;\n \t\t\tif (!tree->buffer)\n@@ -210,20 +210,20 @@ struct object *parse_object_buffer_the_repository(const struct object_id *oid, e\n \t\t\t}\n \t\t}\n \t} else if (type == OBJ_COMMIT) {\n-\t\tstruct commit *commit = lookup_commit(the_repository, oid);\n+\t\tstruct commit *commit = lookup_commit(r, oid);\n \t\tif (commit) {\n-\t\t\tif (parse_commit_buffer(the_repository, commit, buffer, size))\n+\t\t\tif (parse_commit_buffer(r, commit, buffer, size))\n \t\t\t\treturn NULL;\n-\t\t\tif (!get_cached_commit_buffer(the_repository, commit, NULL)) {\n-\t\t\t\tset_commit_buffer(the_repository, commit, buffer, size);\n+\t\t\tif (!get_cached_commit_buffer(r, commit, NULL)) {\n+\t\t\t\tset_commit_buffer(r, commit, buffer, size);\n \t\t\t\t*eaten_p = 1;\n \t\t\t}\n \t\t\tobj = &commit->object;\n \t\t}\n \t} else if (type == OBJ_TAG) {\n-\t\tstruct tag *tag = lookup_tag(the_repository, oid);\n+\t\tstruct tag *tag = lookup_tag(r, oid);\n \t\tif (tag) {\n-\t\t\tif (parse_tag_buffer(the_repository, tag, buffer, size))\n+\t\t\tif (parse_tag_buffer(r, tag, buffer, size))\n \t\t\t       return NULL;\n \t\t\tobj = &tag->object;\n \t\t}\ndiff --git a/object.h b/object.h\nindex 14e0d412bb..a5456fc2d7 100644\n--- a/object.h\n+++ b/object.h\n@@ -174,8 +174,7 @@ struct object *parse_object_or_die(const struct object_id *oid, const char *name\n  * parsing it.  eaten_p indicates if the object has a borrowed copy\n  * of buffer and the caller should not free() it.\n  */\n-#define parse_object_buffer(r, o, t, s, b, e) parse_object_buffer_##r(o, t, s, b, e)\n-struct object *parse_object_buffer_the_repository(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p);\n+struct object *parse_object_buffer(struct repository *r, const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p);\n \n /** Returns the object, with potentially excess memory allocated. **/\n struct object *lookup_unknown_object(struct repository *r, const unsigned char *sha1);\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338442","messageId":"20180206001749.218943-77-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 175/194] tag: allow parse_tag_buffer to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:30Z","receivedAt":"2018-02-06T00:30:23Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n tag.c | 10 +++++-----\n tag.h |  3 +--\n 2 files changed, 6 insertions(+), 7 deletions(-)\n\ndiff --git a/tag.c b/tag.c\nindex 52009bf454..96757f37dc 100644\n--- a/tag.c\n+++ b/tag.c\n@@ -118,7 +118,7 @@ static timestamp_t parse_tag_date(const char *buf, const char *tail)\n \treturn parse_timestamp(dateptr, NULL, 10);\n }\n \n-int parse_tag_buffer_the_repository(struct tag *item, const void *data, unsigned long size)\n+int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, unsigned long size)\n {\n \tstruct object_id oid;\n \tchar type[20];\n@@ -146,13 +146,13 @@ int parse_tag_buffer_the_repository(struct tag *item, const void *data, unsigned\n \tbufptr = nl + 1;\n \n \tif (!strcmp(type, blob_type)) {\n-\t\titem->tagged = (struct object *)lookup_blob(the_repository, &oid);\n+\t\titem->tagged = (struct object *)lookup_blob(r, &oid);\n \t} else if (!strcmp(type, tree_type)) {\n-\t\titem->tagged = (struct object *)lookup_tree(the_repository, &oid);\n+\t\titem->tagged = (struct object *)lookup_tree(r, &oid);\n \t} else if (!strcmp(type, commit_type)) {\n-\t\titem->tagged = (struct object *)lookup_commit(the_repository, &oid);\n+\t\titem->tagged = (struct object *)lookup_commit(r, &oid);\n \t} else if (!strcmp(type, tag_type)) {\n-\t\titem->tagged = (struct object *)lookup_tag(the_repository, &oid);\n+\t\titem->tagged = (struct object *)lookup_tag(r, &oid);\n \t} else {\n \t\terror(\"Unknown type %s\", type);\n \t\titem->tagged = NULL;\ndiff --git a/tag.h b/tag.h\nindex d23af572d8..91208dd2d6 100644\n--- a/tag.h\n+++ b/tag.h\n@@ -12,8 +12,7 @@ struct tag {\n \ttimestamp_t date;\n };\n extern struct tag *lookup_tag(struct repository *r, const struct object_id *oid);\n-#define parse_tag_buffer(r, i, d, s) parse_tag_buffer_##r(i, d, s)\n-extern int parse_tag_buffer_the_repository(struct tag *item, const void *data, unsigned long size);\n+extern int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, unsigned long size);\n extern int parse_tag(struct tag *item);\n #define deref_tag(r, o, w, l) deref_tag_##r(o, w, l)\n extern struct object *deref_tag_the_repository(struct object *, const char *, int);\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338443","messageId":"20180206001749.218943-79-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 177/194] objects: allow check_sha1_signature to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:32Z","receivedAt":"2018-02-06T00:30:34Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n object-store.h | 3 +--\n sha1_file.c    | 4 ++--\n 2 files changed, 3 insertions(+), 4 deletions(-)\n\ndiff --git a/object-store.h b/object-store.h\nindex 47c38170e3..62763b8412 100644\n--- a/object-store.h\n+++ b/object-store.h\n@@ -108,8 +108,7 @@ extern void *map_sha1_file(struct repository *r, const unsigned char *sha1, unsi\n  * The in-core object data should be in \"map\". If \"map\" == NULL, reads the\n  * named object using the streaming interface and rehashes it on the fly.\n  */\n-#define check_sha1_signature(r, s, m, sz, t) check_sha1_signature_##r(s, m, sz, t)\n-extern int check_sha1_signature_the_repository(const unsigned char *sha1, void *buf, unsigned long size, const char *type);\n+extern int check_sha1_signature(struct repository *r, const unsigned char *sha1, void *buf, unsigned long size, const char *type);\n \n /*\n  * Convenience for sha1_object_info_extended() with a NULL struct\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 8638fae9c4..1cf173da16 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -801,7 +801,7 @@ void *xmmap(void *start, size_t length,\n \treturn ret;\n }\n \n-int check_sha1_signature_the_repository(const unsigned char *sha1, void *map,\n+int check_sha1_signature(struct repository *r, const unsigned char *sha1, void *map,\n \t\t\t unsigned long size, const char *type)\n {\n \tunsigned char real_sha1[20];\n@@ -816,7 +816,7 @@ int check_sha1_signature_the_repository(const unsigned char *sha1, void *map,\n \t\treturn hashcmp(sha1, real_sha1) ? -1 : 0;\n \t}\n \n-\tst = open_istream(the_repository, sha1, &obj_type, &size, NULL);\n+\tst = open_istream(r, sha1, &obj_type, &size, NULL);\n \tif (!st)\n \t\treturn -1;\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338444","messageId":"20180206001749.218943-80-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 178/194] object: allow parse_object to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:33Z","receivedAt":"2018-02-06T00:30:37Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n object.c | 20 ++++++++++----------\n object.h |  3 +--\n 2 files changed, 11 insertions(+), 12 deletions(-)\n\ndiff --git a/object.c b/object.c\nindex 2a05613c64..2fe5fac3ce 100644\n--- a/object.c\n+++ b/object.c\n@@ -244,39 +244,39 @@ struct object *parse_object_or_die(const struct object_id *oid,\n \tdie(_(\"unable to parse object: %s\"), name ? name : oid_to_hex(oid));\n }\n \n-struct object *parse_object_the_repository(const struct object_id *oid)\n+struct object *parse_object(struct repository *r, const struct object_id *oid)\n {\n \tunsigned long size;\n \tenum object_type type;\n \tint eaten;\n-\tconst unsigned char *repl = lookup_replace_object(the_repository, oid->hash);\n+\tconst unsigned char *repl = lookup_replace_object(r, oid->hash);\n \tvoid *buffer;\n \tstruct object *obj;\n \n-\tobj = lookup_object(the_repository, oid->hash);\n+\tobj = lookup_object(r, oid->hash);\n \tif (obj && obj->parsed)\n \t\treturn obj;\n \n \tif ((obj && obj->type == OBJ_BLOB) ||\n \t    (!obj && has_object_file(oid) &&\n-\t     sha1_object_info(the_repository, oid->hash, NULL) == OBJ_BLOB)) {\n-\t\tif (check_sha1_signature(the_repository, repl, NULL, 0, NULL) < 0) {\n+\t     sha1_object_info(r, oid->hash, NULL) == OBJ_BLOB)) {\n+\t\tif (check_sha1_signature(r, repl, NULL, 0, NULL) < 0) {\n \t\t\terror(\"sha1 mismatch %s\", oid_to_hex(oid));\n \t\t\treturn NULL;\n \t\t}\n-\t\tparse_blob_buffer(lookup_blob(the_repository, oid), NULL, 0);\n-\t\treturn lookup_object(the_repository, oid->hash);\n+\t\tparse_blob_buffer(lookup_blob(r, oid), NULL, 0);\n+\t\treturn lookup_object(r, oid->hash);\n \t}\n \n-\tbuffer = read_sha1_file(the_repository, oid->hash, &type, &size);\n+\tbuffer = read_sha1_file(r, oid->hash, &type, &size);\n \tif (buffer) {\n-\t\tif (check_sha1_signature(the_repository, repl, buffer, size, typename(type)) < 0) {\n+\t\tif (check_sha1_signature(r, repl, buffer, size, typename(type)) < 0) {\n \t\t\tfree(buffer);\n \t\t\terror(\"sha1 mismatch %s\", sha1_to_hex(repl));\n \t\t\treturn NULL;\n \t\t}\n \n-\t\tobj = parse_object_buffer(the_repository, oid, type, size,\n+\t\tobj = parse_object_buffer(r, oid, type, size,\n \t\t\t\t\t  buffer, &eaten);\n \t\tif (!eaten)\n \t\t\tfree(buffer);\ndiff --git a/object.h b/object.h\nindex a5456fc2d7..900f1b6611 100644\n--- a/object.h\n+++ b/object.h\n@@ -160,8 +160,7 @@ extern void *read_object_with_reference(const unsigned char *sha1,\n  *\n  * Returns NULL if the object is missing or corrupt.\n  */\n-#define parse_object(r, oid) parse_object_##r(oid)\n-struct object *parse_object_the_repository(const struct object_id *oid);\n+struct object *parse_object(struct repository *r, const struct object_id *oid);\n \n /*\n  * Like parse_object, but will die() instead of returning NULL. If the\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338445","messageId":"20180206001749.218943-81-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 179/194] tag: allow deref_tag to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:34Z","receivedAt":"2018-02-06T00:30:39Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n tag.c | 5 ++---\n tag.h | 3 +--\n 2 files changed, 3 insertions(+), 5 deletions(-)\n\ndiff --git a/tag.c b/tag.c\nindex 96757f37dc..d2b2bbb79c 100644\n--- a/tag.c\n+++ b/tag.c\n@@ -64,12 +64,11 @@ int gpg_verify_tag(const struct object_id *oid, const char *name_to_report,\n \treturn ret;\n }\n \n-struct object *deref_tag_the_repository(struct object *o, const char *warn, int warnlen)\n+struct object *deref_tag(struct repository *r, struct object *o, const char *warn, int warnlen)\n {\n \twhile (o && o->type == OBJ_TAG)\n \t\tif (((struct tag *)o)->tagged)\n-\t\t\to = parse_object(the_repository,\n-\t\t\t\t\t &((struct tag *)o)->tagged->oid);\n+\t\t\to = parse_object(r, &((struct tag *)o)->tagged->oid);\n \t\telse\n \t\t\to = NULL;\n \tif (!o && warn) {\ndiff --git a/tag.h b/tag.h\nindex 91208dd2d6..91bb163e26 100644\n--- a/tag.h\n+++ b/tag.h\n@@ -14,8 +14,7 @@ struct tag {\n extern struct tag *lookup_tag(struct repository *r, const struct object_id *oid);\n extern int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, unsigned long size);\n extern int parse_tag(struct tag *item);\n-#define deref_tag(r, o, w, l) deref_tag_##r(o, w, l)\n-extern struct object *deref_tag_the_repository(struct object *, const char *, int);\n+extern struct object *deref_tag(struct repository *r, struct object *, const char *, int);\n extern struct object *deref_tag_noverify(struct object *);\n extern int gpg_verify_tag(const struct object_id *oid,\n \t\tconst char *name_to_report, unsigned flags);\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338446","messageId":"20180206001749.218943-82-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 180/194] commit: allow lookup_commit_reference_gently to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:35Z","receivedAt":"2018-02-06T00:31:03Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n commit.c | 8 +++-----\n commit.h | 4 +---\n 2 files changed, 4 insertions(+), 8 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex 33f5442dc1..426cbc9b55 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -21,16 +21,14 @@ int save_commit_buffer = 1;\n \n const char *commit_type = \"commit\";\n \n-struct commit *lookup_commit_reference_gently_the_repository(\n+struct commit *lookup_commit_reference_gently(struct repository *r,\n \t\tconst struct object_id *oid, int quiet)\n {\n-\tstruct object *obj = deref_tag(the_repository,\n-\t\t\t\t       parse_object(the_repository, oid),\n+\tstruct object *obj = deref_tag(r, parse_object(r, oid),\n \t\t\t\t       NULL, 0);\n-\n \tif (!obj)\n \t\treturn NULL;\n-\treturn object_as_type(the_repository, obj, OBJ_COMMIT, quiet);\n+\treturn object_as_type(r, obj, OBJ_COMMIT, quiet);\n }\n \n struct commit *lookup_commit_reference_the_repository(const struct object_id *oid)\ndiff --git a/commit.h b/commit.h\nindex 7fe6bb0b22..154c61f111 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -50,9 +50,7 @@ struct commit *lookup_commit(struct repository *r, const struct object_id *oid);\n #define lookup_commit_reference(r, o) \\\n \t\tlookup_commit_reference_##r(o)\n struct commit *lookup_commit_reference_the_repository(const struct object_id *oid);\n-#define lookup_commit_reference_gently(r, o, q) \\\n-\t\tlookup_commit_reference_gently_##r(o, q)\n-struct commit *lookup_commit_reference_gently_the_repository(\n+struct commit *lookup_commit_reference_gently(struct repository *r,\n \t\t\t\t\t      const struct object_id *oid,\n \t\t\t\t\t      int quiet);\n struct commit *lookup_commit_reference_by_name(const char *name);\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338447","messageId":"20180206001749.218943-83-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 181/194] commit: allow lookup_commit_reference to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:36Z","receivedAt":"2018-02-06T00:31:05Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n commit.c | 4 ++--\n commit.h | 4 +---\n 2 files changed, 3 insertions(+), 5 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex 426cbc9b55..ac65c1dbd7 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -31,9 +31,9 @@ struct commit *lookup_commit_reference_gently(struct repository *r,\n \treturn object_as_type(r, obj, OBJ_COMMIT, quiet);\n }\n \n-struct commit *lookup_commit_reference_the_repository(const struct object_id *oid)\n+struct commit *lookup_commit_reference(struct repository *r, const struct object_id *oid)\n {\n-\treturn lookup_commit_reference_gently(the_repository, oid, 0);\n+\treturn lookup_commit_reference_gently(r, oid, 0);\n }\n \n struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref_name)\ndiff --git a/commit.h b/commit.h\nindex 154c61f111..d2d5e66b53 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -47,9 +47,7 @@ void add_name_decoration(enum decoration_type type, const char *name, struct obj\n const struct name_decoration *get_name_decoration(const struct object *obj);\n \n struct commit *lookup_commit(struct repository *r, const struct object_id *oid);\n-#define lookup_commit_reference(r, o) \\\n-\t\tlookup_commit_reference_##r(o)\n-struct commit *lookup_commit_reference_the_repository(const struct object_id *oid);\n+struct commit *lookup_commit_reference(struct repository *r,const struct object_id *oid);\n struct commit *lookup_commit_reference_gently(struct repository *r,\n \t\t\t\t\t      const struct object_id *oid,\n \t\t\t\t\t      int quiet);\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338448","messageId":"20180206001749.218943-84-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 182/194] commit: add repository argument to get_commit_buffer","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:37Z","receivedAt":"2018-02-06T00:31:09Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n builtin/fast-export.c                      |  2 +-\n builtin/fmt-merge-msg.c                    |  2 +-\n builtin/log.c                              |  3 ++-\n builtin/replace.c                          |  2 +-\n commit.c                                   |  8 ++++----\n commit.h                                   |  3 ++-\n contrib/coccinelle/submodule_reading.cocci |  7 +++++++\n fsck.c                                     |  3 ++-\n merge-recursive.c                          |  3 ++-\n notes-merge.c                              |  3 ++-\n pretty.c                                   |  2 +-\n sequencer.c                                | 13 ++++++++-----\n sha1_name.c                                |  2 +-\n 13 files changed, 34 insertions(+), 19 deletions(-)\n create mode 100644 contrib/coccinelle/submodule_reading.cocci\n\ndiff --git a/builtin/fast-export.c b/builtin/fast-export.c\nindex 80853bb91a..bc04e3f0a7 100644\n--- a/builtin/fast-export.c\n+++ b/builtin/fast-export.c\n@@ -561,7 +561,7 @@ static void handle_commit(struct commit *commit, struct rev_info *rev,\n \trev->diffopt.output_format = DIFF_FORMAT_CALLBACK;\n \n \tparse_commit_or_die(commit);\n-\tcommit_buffer = get_commit_buffer(commit, NULL);\n+\tcommit_buffer = get_commit_buffer(the_repository, commit, NULL);\n \tauthor = strstr(commit_buffer, \"\\nauthor \");\n \tif (!author)\n \t\tdie (\"Could not find author in commit %s\",\ndiff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c\nindex c54f045ccd..6dedb92d61 100644\n--- a/builtin/fmt-merge-msg.c\n+++ b/builtin/fmt-merge-msg.c\n@@ -261,7 +261,7 @@ static void record_person_from_buf(int which, struct string_list *people,\n static void record_person(int which, struct string_list *people,\n \t\t\t  struct commit *commit)\n {\n-\tconst char *buffer = get_commit_buffer(commit, NULL);\n+\tconst char *buffer = get_commit_buffer(the_repository, commit, NULL);\n \trecord_person_from_buf(which, people, buffer);\n \tunuse_commit_buffer(the_repository, commit, buffer);\n }\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 3ccab366e7..bb9d909f59 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -1022,7 +1022,8 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,\n \tlog_write_email_headers(rev, head, &pp.after_subject, &need_8bit_cte);\n \n \tfor (i = 0; !need_8bit_cte && i < nr; i++) {\n-\t\tconst char *buf = get_commit_buffer(list[i], NULL);\n+\t\tconst char *buf = get_commit_buffer(the_repository, list[i],\n+\t\t\t\t\t\t    NULL);\n \t\tif (has_non_ascii(buf))\n \t\t\tneed_8bit_cte = 1;\n \t\tunuse_commit_buffer(the_repository, list[i], buf);\ndiff --git a/builtin/replace.c b/builtin/replace.c\nindex 1a92c0082a..46bb7cdfe8 100644\n--- a/builtin/replace.c\n+++ b/builtin/replace.c\n@@ -401,7 +401,7 @@ static int create_graft(int argc, const char **argv, int force)\n \t\tdie(_(\"Not a valid object name: '%s'\"), old_ref);\n \tcommit = lookup_commit_or_die(&old, old_ref);\n \n-\tbuffer = get_commit_buffer(commit, &size);\n+\tbuffer = get_commit_buffer(the_repository, commit, &size);\n \tstrbuf_add(&buf, buffer, size);\n \tunuse_commit_buffer(the_repository, commit, buffer);\n \ndiff --git a/commit.c b/commit.c\nindex ac65c1dbd7..b241cc7979 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -277,7 +277,7 @@ const void *get_cached_commit_buffer(struct repository *r, const struct commit *\n \treturn v->buffer;\n }\n \n-const void *get_commit_buffer(const struct commit *commit, unsigned long *sizep)\n+const void *get_commit_buffer_the_repository(const struct commit *commit, unsigned long *sizep)\n {\n \tconst void *ret = get_cached_commit_buffer(the_repository, commit, sizep);\n \tif (!ret) {\n@@ -617,7 +617,7 @@ define_commit_slab(author_date_slab, unsigned long);\n static void record_author_date(struct author_date_slab *author_date,\n \t\t\t       struct commit *commit)\n {\n-\tconst char *buffer = get_commit_buffer(commit, NULL);\n+\tconst char *buffer = get_commit_buffer(the_repository, commit, NULL);\n \tstruct ident_split ident;\n \tconst char *ident_line;\n \tsize_t ident_len;\n@@ -1163,7 +1163,7 @@ int parse_signed_commit(const struct commit *commit,\n {\n \n \tunsigned long size;\n-\tconst char *buffer = get_commit_buffer(commit, &size);\n+\tconst char *buffer = get_commit_buffer(the_repository, commit, &size);\n \tint in_signature, saw_signature = -1;\n \tconst char *line, *tail;\n \n@@ -1320,7 +1320,7 @@ struct commit_extra_header *read_commit_extra_headers(struct commit *commit,\n {\n \tstruct commit_extra_header *extra = NULL;\n \tunsigned long size;\n-\tconst char *buffer = get_commit_buffer(commit, &size);\n+\tconst char *buffer = get_commit_buffer(the_repository, commit, &size);\n \textra = read_commit_extra_header_lines(buffer, size, exclude);\n \tunuse_commit_buffer(the_repository, commit, buffer);\n \treturn extra;\ndiff --git a/commit.h b/commit.h\nindex d2d5e66b53..b9eb079e21 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -88,7 +88,8 @@ const void *get_cached_commit_buffer(struct repository *r, const struct commit *\n  * from disk. The resulting memory should not be modified, and must be given\n  * to unuse_commit_buffer when the caller is done.\n  */\n-const void *get_commit_buffer(const struct commit *, unsigned long *size);\n+#define get_commit_buffer(r, c, s) get_commit_buffer_##r(c, s)\n+const void *get_commit_buffer_the_repository(const struct commit *, unsigned long *size);\n \n /*\n  * Tell the commit subsytem that we are done with a particular commit buffer.\ndiff --git a/contrib/coccinelle/submodule_reading.cocci b/contrib/coccinelle/submodule_reading.cocci\nnew file mode 100644\nindex 0000000000..17c2e02512\n--- /dev/null\n+++ b/contrib/coccinelle/submodule_reading.cocci\n@@ -0,0 +1,7 @@\n+@@\n+expression E;\n+expression F;\n+@@\n+ get_commit_buffer(\n++the_repository,\n+ E, F)\ndiff --git a/fsck.c b/fsck.c\nindex 3155b77348..7788b60bf4 100644\n--- a/fsck.c\n+++ b/fsck.c\n@@ -791,7 +791,8 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,\n static int fsck_commit(struct commit *commit, const char *data,\n \tunsigned long size, struct fsck_options *options)\n {\n-\tconst char *buffer = data ?  data : get_commit_buffer(commit, &size);\n+\tconst char *buffer = data ?  data : get_commit_buffer(the_repository,\n+\t\t\t\t\t\t\t      commit, &size);\n \tint ret = fsck_commit_buffer(commit, buffer, size, options);\n \tif (!data)\n \t\tunuse_commit_buffer(the_repository, commit, buffer);\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 6e06634993..30ddfcb94e 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -237,7 +237,8 @@ static void output_commit_title(struct merge_options *o, struct commit *commit)\n \t\t\tstrbuf_addstr(&o->obuf, _(\"(bad commit)\\n\"));\n \t\telse {\n \t\t\tconst char *title;\n-\t\t\tconst char *msg = get_commit_buffer(commit, NULL);\n+\t\t\tconst char *msg = get_commit_buffer(the_repository,\n+\t\t\t\t\t\t\t    commit, NULL);\n \t\t\tint len = find_commit_subject(msg, &title);\n \t\t\tif (len)\n \t\t\t\tstrbuf_addf(&o->obuf, \"%.*s\\n\", len, title);\ndiff --git a/notes-merge.c b/notes-merge.c\nindex 58b518ae0a..1cb1c4f8f4 100644\n--- a/notes-merge.c\n+++ b/notes-merge.c\n@@ -672,7 +672,8 @@ int notes_merge_commit(struct notes_merge_options *o,\n \tDIR *dir;\n \tstruct dirent *e;\n \tstruct strbuf path = STRBUF_INIT;\n-\tconst char *buffer = get_commit_buffer(partial_commit, NULL);\n+\tconst char *buffer = get_commit_buffer(the_repository, partial_commit,\n+\t\t\t\t\t       NULL);\n \tconst char *msg = strstr(buffer, \"\\n\\n\");\n \tint baselen;\n \ndiff --git a/pretty.c b/pretty.c\nindex 9a7f19f8c7..c5a2f0b018 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -602,7 +602,7 @@ const char *logmsg_reencode(const struct commit *commit,\n \tstatic const char *utf8 = \"UTF-8\";\n \tconst char *use_encoding;\n \tchar *encoding;\n-\tconst char *msg = get_commit_buffer(commit, NULL);\n+\tconst char *msg = get_commit_buffer(the_repository, commit, NULL);\n \tchar *out;\n \n \tif (!output_encoding || !*output_encoding) {\ndiff --git a/sequencer.c b/sequencer.c\nindex 521da238b5..40ba4b6047 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -859,7 +859,7 @@ static int update_squash_messages(enum todo_command command,\n \t\t\treturn error(_(\"need a HEAD to fixup\"));\n \t\tif (!(head_commit = lookup_commit_reference(the_repository, &head)))\n \t\t\treturn error(_(\"could not read HEAD\"));\n-\t\tif (!(head_message = get_commit_buffer(head_commit, NULL)))\n+\t\tif (!(head_message = get_commit_buffer(the_repository, head_commit, NULL)))\n \t\t\treturn error(_(\"could not read HEAD's commit message\"));\n \n \t\tfind_commit_subject(head_message, &body);\n@@ -883,7 +883,7 @@ static int update_squash_messages(enum todo_command command,\n \t\tunuse_commit_buffer(the_repository, head_commit, head_message);\n \t}\n \n-\tif (!(message = get_commit_buffer(commit, NULL)))\n+\tif (!(message = get_commit_buffer(the_repository, commit, NULL)))\n \t\treturn error(_(\"could not read commit message of %s\"),\n \t\t\t     oid_to_hex(&commit->object.oid));\n \tfind_commit_subject(message, &body);\n@@ -1549,7 +1549,8 @@ static int walk_revs_populate_todo(struct todo_list *todo_list,\n \n \twhile ((commit = get_revision(opts->revs))) {\n \t\tstruct todo_item *item = append_new_todo(todo_list);\n-\t\tconst char *commit_buffer = get_commit_buffer(commit, NULL);\n+\t\tconst char *commit_buffer = get_commit_buffer(the_repository,\n+\t\t\t\t\t\t\t      commit, NULL);\n \t\tconst char *subject;\n \t\tint subject_len;\n \n@@ -1816,7 +1817,8 @@ static int make_patch(struct commit *commit, struct replay_opts *opts)\n \n \tstrbuf_addf(&buf, \"%s/message\", get_dir(opts));\n \tif (!file_exists(buf.buf)) {\n-\t\tconst char *commit_buffer = get_commit_buffer(commit, NULL);\n+\t\tconst char *commit_buffer = get_commit_buffer(the_repository,\n+\t\t\t\t\t\t\t      commit, NULL);\n \t\tfind_commit_subject(commit_buffer, &subject);\n \t\tres |= write_message(subject, strlen(subject), buf.buf, 1);\n \t\tunuse_commit_buffer(the_repository, commit, commit_buffer);\n@@ -2906,7 +2908,8 @@ int rearrange_squash(void)\n \t\titem->commit->util = item;\n \n \t\tparse_commit(the_repository, item->commit);\n-\t\tcommit_buffer = get_commit_buffer(item->commit, NULL);\n+\t\tcommit_buffer = get_commit_buffer(the_repository,\n+\t\t\t\t\t\t  item->commit, NULL);\n \t\tfind_commit_subject(commit_buffer, &subject);\n \t\tformat_subject(&buf, subject, \" \");\n \t\tsubject = subjects[i] = strbuf_detach(&buf, &subject_len);\ndiff --git a/sha1_name.c b/sha1_name.c\nindex 7675ec634f..ee889daead 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -1150,7 +1150,7 @@ static int get_oid_oneline(const char *prefix, struct object_id *oid,\n \t\tcommit = pop_most_recent_commit(&list, ONELINE_SEEN);\n \t\tif (!parse_object(the_repository, &commit->object.oid))\n \t\t\tcontinue;\n-\t\tbuf = get_commit_buffer(commit, NULL);\n+\t\tbuf = get_commit_buffer(the_repository, commit, NULL);\n \t\tp = strstr(buf, \"\\n\\n\");\n \t\tmatches = negative ^ (p && !regexec(&regex, p + 2, 0, NULL, 0));\n \t\tunuse_commit_buffer(the_repository, commit, buf);\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338449","messageId":"20180206001749.218943-85-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 183/194] commit: add repository argument to logmsg_reencode","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:38Z","receivedAt":"2018-02-06T00:31:32Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n builtin/am.c                               | 3 ++-\n builtin/blame.c                            | 2 +-\n builtin/commit.c                           | 2 +-\n builtin/reset.c                            | 3 ++-\n commit.h                                   | 3 ++-\n contrib/coccinelle/submodule_reading.cocci | 9 +++++++++\n pretty.c                                   | 7 ++++---\n revision.c                                 | 2 +-\n sequencer.c                                | 3 ++-\n 9 files changed, 24 insertions(+), 10 deletions(-)\n\ndiff --git a/builtin/am.c b/builtin/am.c\nindex 7072ec78cb..9bbf41912b 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -1328,7 +1328,8 @@ static void get_commit_info(struct am_state *state, struct commit *commit)\n \tsize_t ident_len;\n \tstruct ident_split id;\n \n-\tbuffer = logmsg_reencode(commit, NULL, get_commit_output_encoding());\n+\tbuffer = logmsg_reencode(the_repository, commit, NULL,\n+\t\t\t\t get_commit_output_encoding());\n \n \tident_line = find_commit_header(buffer, \"author\", &ident_len);\n \ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex 956df42c67..f9c18f6413 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -186,7 +186,7 @@ static void get_commit_info(struct commit *commit,\n \tcommit_info_init(ret);\n \n \tencoding = get_log_output_encoding();\n-\tmessage = logmsg_reencode(commit, NULL, encoding);\n+\tmessage = logmsg_reencode(the_repository, commit, NULL, encoding);\n \tget_ac_line(message, \"\\nauthor \",\n \t\t    &ret->author, &ret->author_mail,\n \t\t    &ret->author_time, &ret->author_tz);\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex cceb965569..c903893767 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -1113,7 +1113,7 @@ static const char *read_commit_message(const char *name)\n \tif (!commit)\n \t\tdie(_(\"could not lookup commit %s\"), name);\n \tout_enc = get_commit_output_encoding();\n-\treturn logmsg_reencode(commit, NULL, out_enc);\n+\treturn logmsg_reencode(the_repository, commit, NULL, out_enc);\n }\n \n /*\ndiff --git a/builtin/reset.c b/builtin/reset.c\nindex 7c57309adc..ef16cbea0d 100644\n--- a/builtin/reset.c\n+++ b/builtin/reset.c\n@@ -111,7 +111,8 @@ static void print_new_head_line(struct commit *commit)\n \n \thex = find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV);\n \tprintf(_(\"HEAD is now at %s\"), hex);\n-\tmsg = logmsg_reencode(commit, NULL, get_log_output_encoding());\n+\tmsg = logmsg_reencode(the_repository, commit, NULL,\n+\t\t\t      get_log_output_encoding());\n \tbody = strstr(msg, \"\\n\\n\");\n \tif (body) {\n \t\tconst char *eol;\ndiff --git a/commit.h b/commit.h\nindex b9eb079e21..33f7779602 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -130,7 +130,8 @@ void free_commit_list(struct commit_list *list);\n struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */\n \n extern int has_non_ascii(const char *text);\n-extern const char *logmsg_reencode(const struct commit *commit,\n+#define logmsg_reencode(r, c, e, o) logmsg_reencode_##r(c, e ,o)\n+extern const char *logmsg_reencode_the_repository(const struct commit *commit,\n \t\t\t\t   char **commit_encoding,\n \t\t\t\t   const char *output_encoding);\n extern const char *skip_blank_lines(const char *msg);\ndiff --git a/contrib/coccinelle/submodule_reading.cocci b/contrib/coccinelle/submodule_reading.cocci\nindex 17c2e02512..b3e3d88626 100644\n--- a/contrib/coccinelle/submodule_reading.cocci\n+++ b/contrib/coccinelle/submodule_reading.cocci\n@@ -5,3 +5,12 @@ expression F;\n  get_commit_buffer(\n +the_repository,\n  E, F)\n+\n+@@\n+expression E;\n+expression F;\n+expression G;\n+@@\n+ logmsg_reencode(\n++the_repository,\n+ E, F, G)\ndiff --git a/pretty.c b/pretty.c\nindex c5a2f0b018..a0c95280f6 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -595,7 +595,7 @@ static char *replace_encoding_header(char *buf, const char *encoding)\n \treturn strbuf_detach(&tmp, NULL);\n }\n \n-const char *logmsg_reencode(const struct commit *commit,\n+const char *logmsg_reencode_the_repository(const struct commit *commit,\n \t\t\t    char **commit_encoding,\n \t\t\t    const char *output_encoding)\n {\n@@ -1519,7 +1519,7 @@ void format_commit_message(const struct commit *commit,\n \t * convert a commit message to UTF-8 first\n \t * as far as 'format_commit_item' assumes it in UTF-8\n \t */\n-\tcontext.message = logmsg_reencode(commit,\n+\tcontext.message = logmsg_reencode(the_repository, commit,\n \t\t\t\t\t  &context.commit_encoding,\n \t\t\t\t\t  utf8);\n \n@@ -1801,7 +1801,8 @@ void pretty_print_commit(struct pretty_print_context *pp,\n \t}\n \n \tencoding = get_log_output_encoding();\n-\tmsg = reencoded = logmsg_reencode(commit, NULL, encoding);\n+\tmsg = reencoded = logmsg_reencode(the_repository, commit, NULL,\n+\t\t\t\t\t  encoding);\n \n \tif (pp->fmt == CMIT_FMT_ONELINE || cmit_fmt_is_mail(pp->fmt))\n \t\tindent = 0;\ndiff --git a/revision.c b/revision.c\nindex c5d376ba0a..427ccb1fe1 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -3002,7 +3002,7 @@ static int commit_match(struct commit *commit, struct rev_info *opt)\n \t * in it.\n \t */\n \tencoding = get_log_output_encoding();\n-\tmessage = logmsg_reencode(commit, NULL, encoding);\n+\tmessage = logmsg_reencode(the_repository, commit, NULL, encoding);\n \n \t/* Copy the commit to temporary if we are using \"fake\" headers */\n \tif (buf.len)\ndiff --git a/sequencer.c b/sequencer.c\nindex 40ba4b6047..57b9ddb69b 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -243,7 +243,8 @@ static int get_message(struct commit *commit, struct commit_message *out)\n \tconst char *abbrev, *subject;\n \tint subject_len;\n \n-\tout->message = logmsg_reencode(commit, NULL, get_commit_output_encoding());\n+\tout->message = logmsg_reencode(the_repository, commit, NULL,\n+\t\t\t\t       get_commit_output_encoding());\n \tabbrev = short_commit_name(commit);\n \n \tsubject_len = find_commit_subject(out->message, &subject);\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338450","messageId":"20180206001749.218943-86-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 184/194] pretty: add repository argument to format_commit_message","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:39Z","receivedAt":"2018-02-06T00:31:38Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n archive.c                                  |  3 ++-\n builtin/commit.c                           | 17 +++++++++++------\n builtin/fmt-merge-msg.c                    |  2 +-\n builtin/notes.c                            |  3 ++-\n builtin/shortlog.c                         |  5 +++--\n contrib/coccinelle/submodule_reading.cocci | 10 ++++++++++\n log-tree.c                                 |  2 +-\n notes-cache.c                              |  2 +-\n pretty.c                                   |  5 +++--\n pretty.h                                   |  4 +++-\n sha1_name.c                                |  3 ++-\n submodule.c                                |  5 +++--\n t/helper/test-revision-walking.c           |  2 +-\n 13 files changed, 43 insertions(+), 20 deletions(-)\n\ndiff --git a/archive.c b/archive.c\nindex 6f38a5cf55..cb0b1d595c 100644\n--- a/archive.c\n+++ b/archive.c\n@@ -56,7 +56,8 @@ static void format_subst(const struct commit *commit,\n \t\tstrbuf_add(&fmt, b + 8, c - b - 8);\n \n \t\tstrbuf_add(buf, src, b - src);\n-\t\tformat_commit_message(commit, fmt.buf, buf, &ctx);\n+\t\tformat_commit_message(the_repository, commit, fmt.buf, buf,\n+\t\t\t\t      &ctx);\n \t\tlen -= c + 1 - src;\n \t\tsrc  = c + 1;\n \t}\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex c903893767..a6ddf6dd23 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -696,7 +696,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,\n \t\t\tif (!c)\n \t\t\t\tdie(_(\"could not lookup commit %s\"), squash_message);\n \t\t\tctx.output_encoding = get_commit_output_encoding();\n-\t\t\tformat_commit_message(c, \"squash! %s\\n\\n\", &sb,\n+\t\t\tformat_commit_message(the_repository, c,\n+\t\t\t\t\t      \"squash! %s\\n\\n\", &sb,\n \t\t\t\t\t      &ctx);\n \t\t}\n \t}\n@@ -729,7 +730,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,\n \t\tif (!commit)\n \t\t\tdie(_(\"could not lookup commit %s\"), fixup_message);\n \t\tctx.output_encoding = get_commit_output_encoding();\n-\t\tformat_commit_message(commit, \"fixup! %s\\n\\n\",\n+\t\tformat_commit_message(the_repository, commit, \"fixup! %s\\n\\n\",\n \t\t\t\t      &sb, &ctx);\n \t\thook_arg1 = \"message\";\n \t} else if (!stat(git_path_merge_msg(the_repository), &statbuf)) {\n@@ -1069,7 +1070,8 @@ static const char *find_author_by_nickname(const char *name)\n \t\tstruct pretty_print_context ctx = {0};\n \t\tctx.date_mode.type = DATE_NORMAL;\n \t\tstrbuf_release(&buf);\n-\t\tformat_commit_message(commit, \"%aN <%aE>\", &buf, &ctx);\n+\t\tformat_commit_message(the_repository, commit, \"%aN <%aE>\",\n+\t\t\t\t      &buf, &ctx);\n \t\tclear_mailmap(&mailmap);\n \t\treturn strbuf_detach(&buf, NULL);\n \t}\n@@ -1472,15 +1474,18 @@ static void print_summary(const char *prefix, const struct object_id *oid,\n \n \tstrbuf_addstr(&format, \"format:%h] %s\");\n \n-\tformat_commit_message(commit, \"%an <%ae>\", &author_ident, &pctx);\n-\tformat_commit_message(commit, \"%cn <%ce>\", &committer_ident, &pctx);\n+\tformat_commit_message(the_repository, commit, \"%an <%ae>\",\n+\t\t\t      &author_ident, &pctx);\n+\tformat_commit_message(the_repository, commit, \"%cn <%ce>\",\n+\t\t\t      &committer_ident, &pctx);\n \tif (strbuf_cmp(&author_ident, &committer_ident)) {\n \t\tstrbuf_addstr(&format, \"\\n Author: \");\n \t\tstrbuf_addbuf_percentquote(&format, &author_ident);\n \t}\n \tif (author_date_is_interesting()) {\n \t\tstruct strbuf date = STRBUF_INIT;\n-\t\tformat_commit_message(commit, \"%ad\", &date, &pctx);\n+\t\tformat_commit_message(the_repository, commit, \"%ad\", &date,\n+\t\t\t\t      &pctx);\n \t\tstrbuf_addstr(&format, \"\\n Date: \");\n \t\tstrbuf_addbuf_percentquote(&format, &date);\n \t\tstrbuf_release(&date);\ndiff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c\nindex 6dedb92d61..591cf95346 100644\n--- a/builtin/fmt-merge-msg.c\n+++ b/builtin/fmt-merge-msg.c\n@@ -374,7 +374,7 @@ static void shortlog(const char *name,\n \t\tif (subjects.nr > limit)\n \t\t\tcontinue;\n \n-\t\tformat_commit_message(commit, \"%s\", &sb, &ctx);\n+\t\tformat_commit_message(the_repository, commit, \"%s\", &sb, &ctx);\n \t\tstrbuf_ltrim(&sb);\n \n \t\tif (!sb.len)\ndiff --git a/builtin/notes.c b/builtin/notes.c\nindex 9100ac5ce0..8633da1d5e 100644\n--- a/builtin/notes.c\n+++ b/builtin/notes.c\n@@ -736,7 +736,8 @@ static int merge_commit(struct notes_merge_options *o)\n \n \t/* Reuse existing commit message in reflog message */\n \tmemset(&pretty_ctx, 0, sizeof(pretty_ctx));\n-\tformat_commit_message(partial, \"%s\", &msg, &pretty_ctx);\n+\tformat_commit_message(the_repository, partial, \"%s\", &msg,\n+\t\t\t      &pretty_ctx);\n \tstrbuf_trim(&msg);\n \tstrbuf_insert(&msg, 0, \"notes: \", 7);\n \tupdate_ref(msg.buf, o->local_ref, &oid,\ndiff --git a/builtin/shortlog.c b/builtin/shortlog.c\nindex e29875b843..61a8c9a6e9 100644\n--- a/builtin/shortlog.c\n+++ b/builtin/shortlog.c\n@@ -169,12 +169,13 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)\n \t\t(log->email ? \"%cN <%cE>\" : \"%cN\") :\n \t\t(log->email ? \"%aN <%aE>\" : \"%aN\");\n \n-\tformat_commit_message(commit, fmt, &author, &ctx);\n+\tformat_commit_message(the_repository, commit, fmt, &author, &ctx);\n \tif (!log->summary) {\n \t\tif (log->user_format)\n \t\t\tpretty_print_commit(&ctx, commit, &oneline);\n \t\telse\n-\t\t\tformat_commit_message(commit, \"%s\", &oneline, &ctx);\n+\t\t\tformat_commit_message(the_repository, commit, \"%s\",\n+\t\t\t\t\t      &oneline, &ctx);\n \t}\n \n \tinsert_one_record(log, author.buf, oneline.len ? oneline.buf : \"<none>\");\ndiff --git a/contrib/coccinelle/submodule_reading.cocci b/contrib/coccinelle/submodule_reading.cocci\nindex b3e3d88626..30935ac21d 100644\n--- a/contrib/coccinelle/submodule_reading.cocci\n+++ b/contrib/coccinelle/submodule_reading.cocci\n@@ -14,3 +14,13 @@ expression G;\n  logmsg_reencode(\n +the_repository,\n  E, F, G)\n+\n+@@\n+expression E;\n+expression F;\n+expression G;\n+expression H;\n+@@\n+ format_commit_message(\n++the_repository,\n+ E, F, G, H)\ndiff --git a/log-tree.c b/log-tree.c\nindex c6d2883190..e32a2fe71c 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -341,7 +341,7 @@ void fmt_output_commit(struct strbuf *filename,\n \tstruct pretty_print_context ctx = {0};\n \tstruct strbuf subject = STRBUF_INIT;\n \n-\tformat_commit_message(commit, \"%f\", &subject, &ctx);\n+\tformat_commit_message(the_repository, commit, \"%f\", &subject, &ctx);\n \tfmt_output_subject(filename, subject.buf, info);\n \tstrbuf_release(&subject);\n }\ndiff --git a/notes-cache.c b/notes-cache.c\nindex a4a6ccab97..89c2284192 100644\n--- a/notes-cache.c\n+++ b/notes-cache.c\n@@ -21,7 +21,7 @@ static int notes_cache_match_validity(const char *ref, const char *validity)\n \t\treturn 0;\n \n \tmemset(&pretty_ctx, 0, sizeof(pretty_ctx));\n-\tformat_commit_message(commit, \"%s\", &msg, &pretty_ctx);\n+\tformat_commit_message(the_repository, commit, \"%s\", &msg, &pretty_ctx);\n \tstrbuf_trim(&msg);\n \n \tret = !strcmp(msg.buf, validity);\ndiff --git a/pretty.c b/pretty.c\nindex a0c95280f6..30d53369b5 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -1503,7 +1503,7 @@ void userformat_find_requirements(const char *fmt, struct userformat_want *w)\n \tstrbuf_release(&dummy);\n }\n \n-void format_commit_message(const struct commit *commit,\n+void format_commit_message_the_repository(const struct commit *commit,\n \t\t\t   const char *format, struct strbuf *sb,\n \t\t\t   const struct pretty_print_context *pretty_ctx)\n {\n@@ -1796,7 +1796,8 @@ void pretty_print_commit(struct pretty_print_context *pp,\n \tint need_8bit_cte = pp->need_8bit_cte;\n \n \tif (pp->fmt == CMIT_FMT_USERFORMAT) {\n-\t\tformat_commit_message(commit, user_format, sb, pp);\n+\t\tformat_commit_message(the_repository, commit, user_format, sb,\n+\t\t\t\t      pp);\n \t\treturn;\n \t}\n \ndiff --git a/pretty.h b/pretty.h\nindex 5c85d94e33..14af7df4e8 100644\n--- a/pretty.h\n+++ b/pretty.h\n@@ -99,7 +99,9 @@ void pp_remainder(struct pretty_print_context *pp, const char **msg_p,\n  * Put the result to \"sb\".\n  * Please use this function for custom formats.\n  */\n-void format_commit_message(const struct commit *commit,\n+#define format_commit_message(r, c, f, s, p) \\\n+\tformat_commit_message_##r(c, f, s, p)\n+void format_commit_message_the_repository(const struct commit *commit,\n \t\t\tconst char *format, struct strbuf *sb,\n \t\t\tconst struct pretty_print_context *context);\n \ndiff --git a/sha1_name.c b/sha1_name.c\nindex ee889daead..d6c2cf969f 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -378,7 +378,8 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)\n \t\tif (commit) {\n \t\t\tstruct pretty_print_context pp = {0};\n \t\t\tpp.date_mode.type = DATE_SHORT;\n-\t\t\tformat_commit_message(commit, \" %ad - %s\", &desc, &pp);\n+\t\t\tformat_commit_message(the_repository, commit,\n+\t\t\t\t\t      \" %ad - %s\", &desc, &pp);\n \t\t}\n \t} else if (type == OBJ_TAG) {\n \t\tstruct tag *tag = lookup_tag(the_repository, oid);\ndiff --git a/submodule.c b/submodule.c\nindex af4a1d2cea..b399cf46e4 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -452,7 +452,8 @@ static void print_submodule_summary(struct rev_info *rev, struct diff_options *o\n \t\tctx.date_mode = rev->date_mode;\n \t\tctx.output_encoding = get_log_output_encoding();\n \t\tstrbuf_setlen(&sb, 0);\n-\t\tformat_commit_message(commit, format, &sb, &ctx);\n+\t\tformat_commit_message(the_repository, commit, format, &sb,\n+\t\t\t\t      &ctx);\n \t\tstrbuf_addch(&sb, '\\n');\n \t\tif (commit->object.flags & SYMMETRIC_LEFT)\n \t\t\tdiff_emit_submodule_del(o, sb.buf);\n@@ -1786,7 +1787,7 @@ static void print_commit(struct commit *commit)\n \tstruct strbuf sb = STRBUF_INIT;\n \tstruct pretty_print_context ctx = {0};\n \tctx.date_mode.type = DATE_NORMAL;\n-\tformat_commit_message(commit, \" %h: %m %s\", &sb, &ctx);\n+\tformat_commit_message(the_repository, commit, \" %h: %m %s\", &sb, &ctx);\n \tfprintf(stderr, \"%s\\n\", sb.buf);\n \tstrbuf_release(&sb);\n }\ndiff --git a/t/helper/test-revision-walking.c b/t/helper/test-revision-walking.c\nindex b8e6fe1d00..59599410ce 100644\n--- a/t/helper/test-revision-walking.c\n+++ b/t/helper/test-revision-walking.c\n@@ -18,7 +18,7 @@ static void print_commit(struct commit *commit)\n \tstruct strbuf sb = STRBUF_INIT;\n \tstruct pretty_print_context ctx = {0};\n \tctx.date_mode.type = DATE_NORMAL;\n-\tformat_commit_message(commit, \" %m %s\", &sb, &ctx);\n+\tformat_commit_message(the_repository, commit, \" %m %s\", &sb, &ctx);\n \tprintf(\"%s\\n\", sb.buf);\n \tstrbuf_release(&sb);\n }\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338451","messageId":"20180206001749.218943-87-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 185/194] commit: allow get_commit_buffer to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:40Z","receivedAt":"2018-02-06T00:31:39Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n commit.c | 6 +++---\n commit.h | 3 +--\n 2 files changed, 4 insertions(+), 5 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex b241cc7979..b74086d43d 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -277,13 +277,13 @@ const void *get_cached_commit_buffer(struct repository *r, const struct commit *\n \treturn v->buffer;\n }\n \n-const void *get_commit_buffer_the_repository(const struct commit *commit, unsigned long *sizep)\n+const void *get_commit_buffer(struct repository *r, const struct commit *commit, unsigned long *sizep)\n {\n-\tconst void *ret = get_cached_commit_buffer(the_repository, commit, sizep);\n+\tconst void *ret = get_cached_commit_buffer(r, commit, sizep);\n \tif (!ret) {\n \t\tenum object_type type;\n \t\tunsigned long size;\n-\t\tret = read_sha1_file(the_repository, commit->object.oid.hash,\n+\t\tret = read_sha1_file(r, commit->object.oid.hash,\n \t\t\t\t     &type, &size);\n \t\tif (!ret)\n \t\t\tdie(\"cannot read commit object %s\",\ndiff --git a/commit.h b/commit.h\nindex 33f7779602..77e131d15b 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -88,8 +88,7 @@ const void *get_cached_commit_buffer(struct repository *r, const struct commit *\n  * from disk. The resulting memory should not be modified, and must be given\n  * to unuse_commit_buffer when the caller is done.\n  */\n-#define get_commit_buffer(r, c, s) get_commit_buffer_##r(c, s)\n-const void *get_commit_buffer_the_repository(const struct commit *, unsigned long *size);\n+const void *get_commit_buffer(struct repository *r, const struct commit *, unsigned long *size);\n \n /*\n  * Tell the commit subsytem that we are done with a particular commit buffer.\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338452","messageId":"20180206001749.218943-88-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 186/194] pretty: allow logmsg_reencode to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:41Z","receivedAt":"2018-02-06T00:32:06Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n commit.h | 3 +--\n pretty.c | 8 ++++----\n 2 files changed, 5 insertions(+), 6 deletions(-)\n\ndiff --git a/commit.h b/commit.h\nindex 77e131d15b..7bdc808018 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -129,8 +129,7 @@ void free_commit_list(struct commit_list *list);\n struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */\n \n extern int has_non_ascii(const char *text);\n-#define logmsg_reencode(r, c, e, o) logmsg_reencode_##r(c, e ,o)\n-extern const char *logmsg_reencode_the_repository(const struct commit *commit,\n+extern const char *logmsg_reencode(struct repository *r, const struct commit *commit,\n \t\t\t\t   char **commit_encoding,\n \t\t\t\t   const char *output_encoding);\n extern const char *skip_blank_lines(const char *msg);\ndiff --git a/pretty.c b/pretty.c\nindex 30d53369b5..6dce4bb3c0 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -595,14 +595,14 @@ static char *replace_encoding_header(char *buf, const char *encoding)\n \treturn strbuf_detach(&tmp, NULL);\n }\n \n-const char *logmsg_reencode_the_repository(const struct commit *commit,\n+const char *logmsg_reencode(struct repository *r, const struct commit *commit,\n \t\t\t    char **commit_encoding,\n \t\t\t    const char *output_encoding)\n {\n \tstatic const char *utf8 = \"UTF-8\";\n \tconst char *use_encoding;\n \tchar *encoding;\n-\tconst char *msg = get_commit_buffer(the_repository, commit, NULL);\n+\tconst char *msg = get_commit_buffer(r, commit, NULL);\n \tchar *out;\n \n \tif (!output_encoding || !*output_encoding) {\n@@ -630,7 +630,7 @@ const char *logmsg_reencode_the_repository(const struct commit *commit,\n \t\t * the cached copy from get_commit_buffer, we need to duplicate it\n \t\t * to avoid munging the cached copy.\n \t\t */\n-\t\tif (msg == get_cached_commit_buffer(the_repository, commit, NULL))\n+\t\tif (msg == get_cached_commit_buffer(r, commit, NULL))\n \t\t\tout = xstrdup(msg);\n \t\telse\n \t\t\tout = (char *)msg;\n@@ -644,7 +644,7 @@ const char *logmsg_reencode_the_repository(const struct commit *commit,\n \t\t */\n \t\tout = reencode_string(msg, output_encoding, use_encoding);\n \t\tif (out)\n-\t\t\tunuse_commit_buffer(the_repository, commit, msg);\n+\t\t\tunuse_commit_buffer(r, commit, msg);\n \t}\n \n \t/*\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338453","messageId":"20180206001749.218943-89-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 187/194] commit: add repository argument to in_merge_bases_many","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:42Z","receivedAt":"2018-02-06T00:32:10Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n commit.c  | 4 ++--\n commit.h  | 3 ++-\n remote.c  | 2 +-\n shallow.c | 5 +++--\n 4 files changed, 8 insertions(+), 6 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex b74086d43d..98e04b949f 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -1049,7 +1049,7 @@ int is_descendant_of(struct commit *commit, struct commit_list *with_commit)\n /*\n  * Is \"commit\" an ancestor of one of the \"references\"?\n  */\n-int in_merge_bases_many(struct commit *commit, int nr_reference, struct commit **reference)\n+int in_merge_bases_many_the_repository(struct commit *commit, int nr_reference, struct commit **reference)\n {\n \tstruct commit_list *bases;\n \tint ret = 0, i;\n@@ -1074,7 +1074,7 @@ int in_merge_bases_many(struct commit *commit, int nr_reference, struct commit *\n  */\n int in_merge_bases(struct commit *commit, struct commit *reference)\n {\n-\treturn in_merge_bases_many(commit, 1, &reference);\n+\treturn in_merge_bases_many(the_repository, commit, 1, &reference);\n }\n \n struct commit_list *reduce_heads(struct commit_list *heads)\ndiff --git a/commit.h b/commit.h\nindex 7bdc808018..ea2c5f528c 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -233,7 +233,8 @@ extern struct trace_key trace_shallow;\n \n int is_descendant_of(struct commit *, struct commit_list *);\n int in_merge_bases(struct commit *, struct commit *);\n-int in_merge_bases_many(struct commit *, int, struct commit **);\n+#define in_merge_bases_many(r, c, n, co) in_merge_bases_many_##r(c, n, co)\n+int in_merge_bases_many_the_repository(struct commit *, int, struct commit **);\n \n extern int interactive_add(int argc, const char **argv, const char *prefix, int patch);\n extern int run_add_interactive(const char *revision, const char *patch_mode,\ndiff --git a/remote.c b/remote.c\nindex a4cf885012..0c253b82e8 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -1396,7 +1396,7 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds\n \t\t\t * Is this tag, which they do not have, reachable from\n \t\t\t * any of the commits we are sending?\n \t\t\t */\n-\t\t\tif (!in_merge_bases_many(commit, sent_tips.nr, sent_tips.tip))\n+\t\t\tif (!in_merge_bases_many(the_repository, commit, sent_tips.nr, sent_tips.tip))\n \t\t\t\tcontinue;\n \n \t\t\t/* Add it in */\ndiff --git a/shallow.c b/shallow.c\nindex 64a4fcb57f..f43e94c8e8 100644\n--- a/shallow.c\n+++ b/shallow.c\n@@ -720,7 +720,7 @@ static void post_assign_shallow(struct shallow_info *info,\n \t\tfor (j = 0; j < bitmap_nr; j++)\n \t\t\tif (bitmap[0][j] &&\n \t\t\t    /* Step 7, reachability test at commit level */\n-\t\t\t    !in_merge_bases_many(c, ca.nr, ca.commits)) {\n+\t\t\t    !in_merge_bases_many(the_repository, c, ca.nr, ca.commits)) {\n \t\t\t\tupdate_refstatus(ref_status, info->ref->nr, *bitmap);\n \t\t\t\tdst++;\n \t\t\t\tbreak;\n@@ -748,7 +748,8 @@ int delayed_reachability_test(struct shallow_info *si, int c)\n \t\t\tsi->nr_commits = ca.nr;\n \t\t}\n \n-\t\tsi->reachable[c] = in_merge_bases_many(commit,\n+\t\tsi->reachable[c] = in_merge_bases_many(the_repository,\n+\t\t\t\t\t\t       commit,\n \t\t\t\t\t\t       si->nr_commits,\n \t\t\t\t\t\t       si->commits);\n \t\tsi->need_reachability_test[c] = 0;\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338454","messageId":"20180206001749.218943-90-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 188/194] commit: add repository argument to in_merge_bases","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:43Z","receivedAt":"2018-02-06T00:32:14Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n builtin/branch.c                           |  4 ++--\n builtin/fetch.c                            |  2 +-\n builtin/log.c                              |  2 +-\n builtin/merge-base.c                       |  2 +-\n builtin/receive-pack.c                     |  2 +-\n commit.c                                   |  4 ++--\n commit.h                                   |  3 ++-\n contrib/coccinelle/submodule_reading.cocci |  8 ++++++++\n fast-import.c                              |  2 +-\n http-push.c                                |  2 +-\n pack-bitmap-write.c                        |  2 +-\n submodule.c                                | 12 ++++++------\n 12 files changed, 27 insertions(+), 18 deletions(-)\n\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex 2d752c6614..f525b7e2b5 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -132,7 +132,7 @@ static int branch_merged(int kind, const char *name,\n \tif (!reference_rev)\n \t\treference_rev = head_rev;\n \n-\tmerged = in_merge_bases(rev, reference_rev);\n+\tmerged = in_merge_bases(the_repository, rev, reference_rev);\n \n \t/*\n \t * After the safety valve is fully redefined to \"check with\n@@ -142,7 +142,7 @@ static int branch_merged(int kind, const char *name,\n \t * a gentle reminder is in order.\n \t */\n \tif ((head_rev != reference_rev) &&\n-\t    in_merge_bases(rev, head_rev) != merged) {\n+\t    in_merge_bases(the_repository, rev, head_rev) != merged) {\n \t\tif (merged)\n \t\t\twarning(_(\"deleting branch '%s' that has been merged to\\n\"\n \t\t\t\t\"         '%s', but not yet merged to HEAD.\"),\ndiff --git a/builtin/fetch.c b/builtin/fetch.c\nindex b516b176f0..14eccf3f0d 100644\n--- a/builtin/fetch.c\n+++ b/builtin/fetch.c\n@@ -695,7 +695,7 @@ static int update_local_ref(struct ref *ref,\n \t\treturn r;\n \t}\n \n-\tif (in_merge_bases(current, updated)) {\n+\tif (in_merge_bases(the_repository, current, updated)) {\n \t\tstruct strbuf quickref = STRBUF_INIT;\n \t\tint r;\n \t\tstrbuf_add_unique_abbrev(&quickref, current->object.oid.hash, DEFAULT_ABBREV);\ndiff --git a/builtin/log.c b/builtin/log.c\nindex bb9d909f59..e8bb899e52 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -1325,7 +1325,7 @@ static struct commit *get_base_commit(const char *base_commit,\n \t\trev_nr = DIV_ROUND_UP(rev_nr, 2);\n \t}\n \n-\tif (!in_merge_bases(base, rev[0]))\n+\tif (!in_merge_bases(the_repository, base, rev[0]))\n \t\tdie(_(\"base commit should be the ancestor of revision list\"));\n \n \tfor (i = 0; i < total; i++) {\ndiff --git a/builtin/merge-base.c b/builtin/merge-base.c\nindex 426882818c..00e9f11d92 100644\n--- a/builtin/merge-base.c\n+++ b/builtin/merge-base.c\n@@ -104,7 +104,7 @@ static int handle_is_ancestor(int argc, const char **argv)\n \t\tdie(\"--is-ancestor takes exactly two commits\");\n \tone = get_commit_reference(argv[0]);\n \ttwo = get_commit_reference(argv[1]);\n-\tif (in_merge_bases(one, two))\n+\tif (in_merge_bases(the_repository, one, two))\n \t\treturn 0;\n \telse\n \t\treturn 1;\ndiff --git a/builtin/receive-pack.c b/builtin/receive-pack.c\nindex 7d00f0bad6..2b41affaf5 100644\n--- a/builtin/receive-pack.c\n+++ b/builtin/receive-pack.c\n@@ -1118,7 +1118,7 @@ static const char *update(struct command *cmd, struct shallow_info *si)\n \t\t}\n \t\told_commit = (struct commit *)old_object;\n \t\tnew_commit = (struct commit *)new_object;\n-\t\tif (!in_merge_bases(old_commit, new_commit)) {\n+\t\tif (!in_merge_bases(the_repository, old_commit, new_commit)) {\n \t\t\trp_error(\"denying non-fast-forward %s\"\n \t\t\t\t \" (you should pull first)\", name);\n \t\t\treturn \"non-fast-forward\";\ndiff --git a/commit.c b/commit.c\nindex 98e04b949f..900ecf84b8 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -1040,7 +1040,7 @@ int is_descendant_of(struct commit *commit, struct commit_list *with_commit)\n \n \t\tother = with_commit->item;\n \t\twith_commit = with_commit->next;\n-\t\tif (in_merge_bases(other, commit))\n+\t\tif (in_merge_bases(the_repository, other, commit))\n \t\t\treturn 1;\n \t}\n \treturn 0;\n@@ -1072,7 +1072,7 @@ int in_merge_bases_many_the_repository(struct commit *commit, int nr_reference,\n /*\n  * Is \"commit\" an ancestor of (i.e. reachable from) the \"reference\"?\n  */\n-int in_merge_bases(struct commit *commit, struct commit *reference)\n+int in_merge_bases_the_repository(struct commit *commit, struct commit *reference)\n {\n \treturn in_merge_bases_many(the_repository, commit, 1, &reference);\n }\ndiff --git a/commit.h b/commit.h\nindex ea2c5f528c..0f3cdc6375 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -232,7 +232,8 @@ extern void prune_shallow(int show_only);\n extern struct trace_key trace_shallow;\n \n int is_descendant_of(struct commit *, struct commit_list *);\n-int in_merge_bases(struct commit *, struct commit *);\n+#define in_merge_bases(r, c1, c2) in_merge_bases_##r(c1, c2)\n+int in_merge_bases_the_repository(struct commit *, struct commit *);\n #define in_merge_bases_many(r, c, n, co) in_merge_bases_many_##r(c, n, co)\n int in_merge_bases_many_the_repository(struct commit *, int, struct commit **);\n \ndiff --git a/contrib/coccinelle/submodule_reading.cocci b/contrib/coccinelle/submodule_reading.cocci\nindex 30935ac21d..b9da6a08d3 100644\n--- a/contrib/coccinelle/submodule_reading.cocci\n+++ b/contrib/coccinelle/submodule_reading.cocci\n@@ -24,3 +24,11 @@ expression H;\n  format_commit_message(\n +the_repository,\n  E, F, G, H)\n+\n+@@\n+expression E;\n+expression F;\n+@@\n+ in_merge_bases(\n++the_repository,\n+ E, F)\ndiff --git a/fast-import.c b/fast-import.c\nindex b1ff3d47df..f68d3fbd87 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -1773,7 +1773,7 @@ static int update_branch(struct branch *b)\n \t\tif (!old_cmit || !new_cmit)\n \t\t\treturn error(\"Branch %s is missing commits.\", b->name);\n \n-\t\tif (!in_merge_bases(old_cmit, new_cmit)) {\n+\t\tif (!in_merge_bases(the_repository, old_cmit, new_cmit)) {\n \t\t\twarning(\"Not updating %s\"\n \t\t\t\t\" (new tip %s does not contain %s)\",\n \t\t\t\tb->name, oid_to_hex(&b->oid),\ndiff --git a/http-push.c b/http-push.c\nindex c7fa9ee15a..6af853d245 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -1571,7 +1571,7 @@ static int verify_merge_base(struct object_id *head_oid, struct ref *remote)\n \tstruct commit *branch = lookup_commit_or_die(&remote->old_oid,\n \t\t\t\t\t\t     remote->name);\n \n-\treturn in_merge_bases(branch, head);\n+\treturn in_merge_bases(the_repository, branch, head);\n }\n \n static int delete_remote_branch(const char *pattern, int force)\ndiff --git a/pack-bitmap-write.c b/pack-bitmap-write.c\nindex f684ed5ea2..9ac581920b 100644\n--- a/pack-bitmap-write.c\n+++ b/pack-bitmap-write.c\n@@ -286,7 +286,7 @@ void bitmap_writer_build(struct packing_data *to_pack)\n \t\tif (stored->bitmap == NULL) {\n \t\t\tif (i < writer.selected_nr - 1 &&\n \t\t\t    (need_reset ||\n-\t\t\t     !in_merge_bases(writer.selected[i + 1].commit,\n+\t\t\t     !in_merge_bases(the_repository, writer.selected[i + 1].commit,\n \t\t\t\t\t     stored->commit))) {\n \t\t\t    bitmap_reset(base);\n \t\t\t    reset_all_seen();\ndiff --git a/submodule.c b/submodule.c\nindex b399cf46e4..6125bfbdde 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -1753,7 +1753,7 @@ static int find_first_merges(struct object_array *result, const char *path,\n \t\tdie(\"revision walk setup failed\");\n \twhile ((commit = get_revision(&revs)) != NULL) {\n \t\tstruct object *o = &(commit->object);\n-\t\tif (in_merge_bases(b, commit))\n+\t\tif (in_merge_bases(the_repository, b, commit))\n \t\t\tadd_object_array(o, NULL, &merges);\n \t}\n \treset_revision_walk();\n@@ -1768,7 +1768,7 @@ static int find_first_merges(struct object_array *result, const char *path,\n \t\tcontains_another = 0;\n \t\tfor (j = 0; j < merges.nr; j++) {\n \t\t\tstruct commit *m2 = (struct commit *) merges.objects[j].item;\n-\t\t\tif (i != j && in_merge_bases(m2, m1)) {\n+\t\t\tif (i != j && in_merge_bases(the_repository, m2, m1)) {\n \t\t\t\tcontains_another = 1;\n \t\t\t\tbreak;\n \t\t\t}\n@@ -1829,18 +1829,18 @@ int merge_submodule(struct object_id *result, const char *path,\n \t}\n \n \t/* check whether both changes are forward */\n-\tif (!in_merge_bases(commit_base, commit_a) ||\n-\t    !in_merge_bases(commit_base, commit_b)) {\n+\tif (!in_merge_bases(the_repository, commit_base, commit_a) ||\n+\t    !in_merge_bases(the_repository, commit_base, commit_b)) {\n \t\tMERGE_WARNING(path, \"commits don't follow merge-base\");\n \t\treturn 0;\n \t}\n \n \t/* Case #1: a is contained in b or vice versa */\n-\tif (in_merge_bases(commit_a, commit_b)) {\n+\tif (in_merge_bases(the_repository, commit_a, commit_b)) {\n \t\toidcpy(result, b);\n \t\treturn 1;\n \t}\n-\tif (in_merge_bases(commit_b, commit_a)) {\n+\tif (in_merge_bases(the_repository, commit_b, commit_a)) {\n \t\toidcpy(result, a);\n \t\treturn 1;\n \t}\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338455","messageId":"20180206001749.218943-91-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 189/194] commit: allow in_merge_bases_many to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:44Z","receivedAt":"2018-02-06T00:32:30Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n commit.c | 8 ++++----\n commit.h | 3 +--\n 2 files changed, 5 insertions(+), 6 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex 900ecf84b8..a14933b208 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -1049,18 +1049,18 @@ int is_descendant_of(struct commit *commit, struct commit_list *with_commit)\n /*\n  * Is \"commit\" an ancestor of one of the \"references\"?\n  */\n-int in_merge_bases_many_the_repository(struct commit *commit, int nr_reference, struct commit **reference)\n+int in_merge_bases_many(struct repository *r, struct commit *commit, int nr_reference, struct commit **reference)\n {\n \tstruct commit_list *bases;\n \tint ret = 0, i;\n \n-\tif (parse_commit(the_repository, commit))\n+\tif (parse_commit(r, commit))\n \t\treturn ret;\n \tfor (i = 0; i < nr_reference; i++)\n-\t\tif (parse_commit(the_repository, reference[i]))\n+\t\tif (parse_commit(r, reference[i]))\n \t\t\treturn ret;\n \n-\tbases = paint_down_to_common(the_repository, commit, nr_reference, reference);\n+\tbases = paint_down_to_common(r, commit, nr_reference, reference);\n \tif (commit->object.flags & PARENT2)\n \t\tret = 1;\n \tclear_commit_marks(commit, all_flags);\ndiff --git a/commit.h b/commit.h\nindex 0f3cdc6375..36412a5a9e 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -234,8 +234,7 @@ extern struct trace_key trace_shallow;\n int is_descendant_of(struct commit *, struct commit_list *);\n #define in_merge_bases(r, c1, c2) in_merge_bases_##r(c1, c2)\n int in_merge_bases_the_repository(struct commit *, struct commit *);\n-#define in_merge_bases_many(r, c, n, co) in_merge_bases_many_##r(c, n, co)\n-int in_merge_bases_many_the_repository(struct commit *, int, struct commit **);\n+int in_merge_bases_many(struct repository *r, struct commit *, int, struct commit **);\n \n extern int interactive_add(int argc, const char **argv, const char *prefix, int patch);\n extern int run_add_interactive(const char *revision, const char *patch_mode,\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338456","messageId":"20180206001749.218943-92-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 190/194] commit: allow in_merge_bases to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:45Z","receivedAt":"2018-02-06T00:32:32Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n commit.c | 4 ++--\n commit.h | 3 +--\n 2 files changed, 3 insertions(+), 4 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex a14933b208..cdee8d3917 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -1072,9 +1072,9 @@ int in_merge_bases_many(struct repository *r, struct commit *commit, int nr_refe\n /*\n  * Is \"commit\" an ancestor of (i.e. reachable from) the \"reference\"?\n  */\n-int in_merge_bases_the_repository(struct commit *commit, struct commit *reference)\n+int in_merge_bases(struct repository *r, struct commit *commit, struct commit *reference)\n {\n-\treturn in_merge_bases_many(the_repository, commit, 1, &reference);\n+\treturn in_merge_bases_many(r, commit, 1, &reference);\n }\n \n struct commit_list *reduce_heads(struct commit_list *heads)\ndiff --git a/commit.h b/commit.h\nindex 36412a5a9e..2281948738 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -232,8 +232,7 @@ extern void prune_shallow(int show_only);\n extern struct trace_key trace_shallow;\n \n int is_descendant_of(struct commit *, struct commit_list *);\n-#define in_merge_bases(r, c1, c2) in_merge_bases_##r(c1, c2)\n-int in_merge_bases_the_repository(struct commit *, struct commit *);\n+int in_merge_bases(struct repository *r, struct commit *, struct commit *);\n int in_merge_bases_many(struct repository *r, struct commit *, int, struct commit **);\n \n extern int interactive_add(int argc, const char **argv, const char *prefix, int patch);\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338457","messageId":"20180206001749.218943-93-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 191/194] pretty: allow format_commit_message to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:46Z","receivedAt":"2018-02-06T00:32:35Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n pretty.c | 6 +++---\n pretty.h | 4 +---\n 2 files changed, 4 insertions(+), 6 deletions(-)\n\ndiff --git a/pretty.c b/pretty.c\nindex 6dce4bb3c0..ed1b778c92 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -1503,7 +1503,7 @@ void userformat_find_requirements(const char *fmt, struct userformat_want *w)\n \tstrbuf_release(&dummy);\n }\n \n-void format_commit_message_the_repository(const struct commit *commit,\n+void format_commit_message(struct repository *r, const struct commit *commit,\n \t\t\t   const char *format, struct strbuf *sb,\n \t\t\t   const struct pretty_print_context *pretty_ctx)\n {\n@@ -1519,7 +1519,7 @@ void format_commit_message_the_repository(const struct commit *commit,\n \t * convert a commit message to UTF-8 first\n \t * as far as 'format_commit_item' assumes it in UTF-8\n \t */\n-\tcontext.message = logmsg_reencode(the_repository, commit,\n+\tcontext.message = logmsg_reencode(r, commit,\n \t\t\t\t\t  &context.commit_encoding,\n \t\t\t\t\t  utf8);\n \n@@ -1545,7 +1545,7 @@ void format_commit_message_the_repository(const struct commit *commit,\n \t}\n \n \tfree(context.commit_encoding);\n-\tunuse_commit_buffer(the_repository, commit, context.message);\n+\tunuse_commit_buffer(r, commit, context.message);\n }\n \n static void pp_header(struct pretty_print_context *pp,\ndiff --git a/pretty.h b/pretty.h\nindex 14af7df4e8..c5fc07005f 100644\n--- a/pretty.h\n+++ b/pretty.h\n@@ -99,9 +99,7 @@ void pp_remainder(struct pretty_print_context *pp, const char **msg_p,\n  * Put the result to \"sb\".\n  * Please use this function for custom formats.\n  */\n-#define format_commit_message(r, c, f, s, p) \\\n-\tformat_commit_message_##r(c, f, s, p)\n-void format_commit_message_the_repository(const struct commit *commit,\n+void format_commit_message(struct repository *r, const struct commit *commit,\n \t\t\tconst char *format, struct strbuf *sb,\n \t\t\tconst struct pretty_print_context *context);\n \n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338458","messageId":"20180206001749.218943-94-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 192/194] submodule: add repository argument to print_submodule_summary","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:47Z","receivedAt":"2018-02-06T00:32:58Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Signed-off-by: Stefan Beller <sbeller@google.com>\n---\n submodule.c | 5 +++--\n 1 file changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/submodule.c b/submodule.c\nindex 6125bfbdde..022e366940 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -441,7 +441,8 @@ static int prepare_submodule_summary(struct rev_info *rev, const char *path,\n \treturn prepare_revision_walk(rev);\n }\n \n-static void print_submodule_summary(struct rev_info *rev, struct diff_options *o)\n+#define print_submodule_summary(r, rev, o) print_submodule_summary_##r(rev, o)\n+static void print_submodule_summary_the_repository(struct rev_info *rev, struct diff_options *o)\n {\n \tstatic const char format[] = \"  %m %s\";\n \tstruct strbuf sb = STRBUF_INIT;\n@@ -579,7 +580,7 @@ void show_submodule_summary(struct diff_options *o, const char *path,\n \t\tgoto out;\n \t}\n \n-\tprint_submodule_summary(&rev, o);\n+\tprint_submodule_summary(the_repository, &rev, o);\n \n out:\n \tif (merge_bases)\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338459","messageId":"20180206001749.218943-95-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 193/194] submodule: Reorder open_submodule function","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:48Z","receivedAt":"2018-02-06T00:33:01Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"In the next patch we'll need open_submodule in another function, so\nmove it up.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n submodule.c | 54 +++++++++++++++++++++++++++---------------------------\n 1 file changed, 27 insertions(+), 27 deletions(-)\n\ndiff --git a/submodule.c b/submodule.c\nindex 022e366940..6b6c5a6710 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -481,6 +481,33 @@ void prepare_submodule_repo_env(struct argv_array *out)\n \t\t\t DEFAULT_GIT_DIR_ENVIRONMENT);\n }\n \n+/*\n+ * Initialize 'out' based on the provided submodule path.\n+ *\n+ * Unlike repo_submodule_init, this tolerates submodules not present\n+ * in .gitmodules. NEEDSWORK: The repo_submodule_init behavior is\n+ * preferrable. This function exists only to preserve historical behavior.\n+ *\n+ * Returns 0 on success, -1 when the submodule is not present.\n+ */\n+static int open_submodule(struct repository *out, const char *path)\n+{\n+\tstruct strbuf sb = STRBUF_INIT;\n+\n+\tif (submodule_to_gitdir(&sb, path))\n+\t\treturn -1;\n+\n+\tif (repo_init(out, sb.buf, NULL)) {\n+\t\tstrbuf_release(&sb);\n+\t\treturn -1;\n+\t}\n+\n+\tout->submodule_prefix = xstrdup(path);\n+\n+\tstrbuf_release(&sb);\n+\treturn 0;\n+}\n+\n /* Helper function to display the submodule header line prior to the full\n  * summary output. If it can locate the submodule objects directory it will\n  * attempt to lookup both the left and right commits and put them into the\n@@ -839,33 +866,6 @@ static int check_has_commit(const struct object_id *oid, void *data)\n \t}\n }\n \n-/*\n- * Initialize 'out' based on the provided submodule path.\n- *\n- * Unlike repo_submodule_init, this tolerates submodules not present\n- * in .gitmodules. NEEDSWORK: The repo_submodule_init behavior is\n- * preferrable. This function exists only to preserve historical behavior.\n- *\n- * Returns 0 on success, -1 when the submodule is not present.\n- */\n-static int open_submodule(struct repository *out, const char *path)\n-{\n-\tstruct strbuf sb = STRBUF_INIT;\n-\n-\tif (submodule_to_gitdir(&sb, path))\n-\t\treturn -1;\n-\n-\tif (repo_init(out, sb.buf, NULL)) {\n-\t\tstrbuf_release(&sb);\n-\t\treturn -1;\n-\t}\n-\n-\tout->submodule_prefix = xstrdup(path);\n-\n-\tstrbuf_release(&sb);\n-\treturn 0;\n-}\n-\n static int submodule_has_commits(const char *path, struct oid_array *commits)\n {\n \tstruct repository sub;\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338460","messageId":"20180206001749.218943-96-sbeller@google.com","threadId":"47765","inReplyTo":"20180206001749.218943-1-sbeller@google.com","subject":"[PATCH 194/194] submodule: use submodule repos for object lookup","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:17:49Z","receivedAt":"2018-02-06T00:33:03Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"This converts the 'show_submodule_header' function to use\nthe repository API properly, such that the submodule objects\nare not added to the main object store.\n\nWhen using the inline diff of submodules, the object store is not\npolluted with objects from the submodules. When using the \"log\"\nsummary, we still have to pollute the object store, as the\nrevision walking is not converted yet.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n submodule.c | 25 ++++++++++++++-----------\n 1 file changed, 14 insertions(+), 11 deletions(-)\n\ndiff --git a/submodule.c b/submodule.c\nindex 6b6c5a6710..9bd337ce99 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -441,19 +441,19 @@ static int prepare_submodule_summary(struct rev_info *rev, const char *path,\n \treturn prepare_revision_walk(rev);\n }\n \n-#define print_submodule_summary(r, rev, o) print_submodule_summary_##r(rev, o)\n-static void print_submodule_summary_the_repository(struct rev_info *rev, struct diff_options *o)\n+static void print_submodule_summary(struct repository *r, struct rev_info *rev, struct diff_options *o)\n {\n \tstatic const char format[] = \"  %m %s\";\n \tstruct strbuf sb = STRBUF_INIT;\n \tstruct commit *commit;\n \n+\t/* NEEDSWORK: get_revision is not adapted to repository handling? */\n \twhile ((commit = get_revision(rev))) {\n \t\tstruct pretty_print_context ctx = {0};\n \t\tctx.date_mode = rev->date_mode;\n \t\tctx.output_encoding = get_log_output_encoding();\n \t\tstrbuf_setlen(&sb, 0);\n-\t\tformat_commit_message(the_repository, commit, format, &sb,\n+\t\tformat_commit_message(r, commit, format, &sb,\n \t\t\t\t      &ctx);\n \t\tstrbuf_addch(&sb, '\\n');\n \t\tif (commit->object.flags & SYMMETRIC_LEFT)\n@@ -513,7 +513,8 @@ static int open_submodule(struct repository *out, const char *path)\n  * attempt to lookup both the left and right commits and put them into the\n  * left and right pointers.\n  */\n-static void show_submodule_header(struct diff_options *o, const char *path,\n+static void show_submodule_header(struct diff_options *o, struct repository *sub,\n+\t\tconst char *path,\n \t\tstruct object_id *one, struct object_id *two,\n \t\tunsigned dirty_submodule,\n \t\tstruct commit **left, struct commit **right,\n@@ -534,7 +535,7 @@ static void show_submodule_header(struct diff_options *o, const char *path,\n \telse if (is_null_oid(two))\n \t\tmessage = \"(submodule deleted)\";\n \n-\tif (add_submodule_odb(path)) {\n+\tif (open_submodule(sub, path) < 0) {\n \t\tif (!message)\n \t\t\tmessage = \"(commits not present)\";\n \t\tgoto output_header;\n@@ -544,8 +545,8 @@ static void show_submodule_header(struct diff_options *o, const char *path,\n \t * Attempt to lookup the commit references, and determine if this is\n \t * a fast forward or fast backwards update.\n \t */\n-\t*left = lookup_commit_reference(the_repository, one);\n-\t*right = lookup_commit_reference(the_repository, two);\n+\t*left = lookup_commit_reference(sub, one);\n+\t*right = lookup_commit_reference(sub, two);\n \n \t/*\n \t * Warn about missing commits in the submodule project, but only if\n@@ -555,7 +556,7 @@ static void show_submodule_header(struct diff_options *o, const char *path,\n \t     (!is_null_oid(two) && !*right))\n \t\tmessage = \"(commits not present)\";\n \n-\t*merge_bases = get_merge_bases(the_repository, *left, *right);\n+\t*merge_bases = get_merge_bases(sub, *left, *right);\n \tif (*merge_bases) {\n \t\tif ((*merge_bases)->item == *left)\n \t\t\tfast_forward = 1;\n@@ -589,8 +590,9 @@ void show_submodule_summary(struct diff_options *o, const char *path,\n \tstruct rev_info rev;\n \tstruct commit *left = NULL, *right = NULL;\n \tstruct commit_list *merge_bases = NULL;\n+\tstruct repository sub;\n \n-\tshow_submodule_header(o, path, one, two, dirty_submodule,\n+\tshow_submodule_header(o, &sub, path, one, two, dirty_submodule,\n \t\t\t      &left, &right, &merge_bases);\n \n \t/*\n@@ -607,7 +609,7 @@ void show_submodule_summary(struct diff_options *o, const char *path,\n \t\tgoto out;\n \t}\n \n-\tprint_submodule_summary(the_repository, &rev, o);\n+\tprint_submodule_summary(&sub, &rev, o);\n \n out:\n \tif (merge_bases)\n@@ -625,8 +627,9 @@ void show_submodule_inline_diff(struct diff_options *o, const char *path,\n \tstruct commit_list *merge_bases = NULL;\n \tstruct child_process cp = CHILD_PROCESS_INIT;\n \tstruct strbuf sb = STRBUF_INIT;\n+\tstruct repository sub;\n \n-\tshow_submodule_header(o, path, one, two, dirty_submodule,\n+\tshow_submodule_header(o, &sub, path, one, two, dirty_submodule,\n \t\t\t      &left, &right, &merge_bases);\n \n \t/* We need a valid left and right commit to display a difference */\n-- \n2.15.1.433.g936d1b9894.dirty\n\n"},{"id":"338463","messageId":"CAGZ79kYn6bAH4vVR=Z5nGRC5=R=Ke42Dr21s-MnxE9BZciLfVQ@mail.gmail.com","threadId":"47765","inReplyTo":"20180205235508.216277-1-sbeller@google.com","subject":"Re: [RFC PATCH 000/194] Moving global state into the repository object","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T00:54:53Z","receivedAt":"2018-02-06T00:55:02Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Mon, Feb 5, 2018 at 3:51 PM, Stefan Beller <sbeller@google.com> wrote:\n\n>\n> Any suggestions welcome!\n>\n\nI wouldn't say sending out this many patches is a smooth experience:\n\n* After trying it out internally, it stopped at patch ~80 and the rate\nlimiter kicked in.\n* Okay fine, I'll rate limit myself to be able to send out as many patches!\n* Apparently I did not understand the docs correctly, and after reading the code\n  a patch was made:\n  https://public-inbox.org/git/20180206000743.217503-1-sbeller@google.com/\n  I think the sensible thing would be to error out instead of ignoring the\n  relogin parameter.\n  This is why patches 21/22 ff. have a weird in-reply-to setup, as I hit CTRL-C\n  to stop the unlimited sending and picked up from there using the rate limited\n  --relogin-delay=25 --batch-size=3\n* You'll notice that at patches 99/100 ff the same weird in-reply-to appeared.\n  One patch has had a missing '>' in the signoff, such that the server refused\n  to cc appropriately (\"Stefan\" not a valid recipient)\n  It would be nice if we could check for that before even sending out emails,\n  but I could live with this blamed on the user. (It was my mistake)\n* Patch 118 just bounced. \"Message rejected.\"\n  It is found at\nhttps://github.com/stefanbeller/git/commit/141ba1f82c223636728a476f9acc1229f353a381\n\nStefan\n"},{"id":"338464","messageId":"20180206011940.GD7904@genre.crustytoothpaste.net","threadId":"47765","inReplyTo":"20180205235735.216710-5-sbeller@google.com","subject":"Re: [PATCH 025/194] object-store: allow prepare_alt_odb to handle arbitrary repositories","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-02-06T01:19:40Z","receivedAt":"2018-02-06T01:19:52Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Mon, Feb 05, 2018 at 03:54:46PM -0800, Stefan Beller wrote:\n> @@ -434,12 +433,12 @@ static int link_alt_odb_entry_the_repository(const char *entry,\n>  \tent = alloc_alt_odb(pathbuf.buf);\n>  \n>  \t/* add the alternate entry */\n> -\t*the_repository->objects.alt_odb_tail = ent;\n> -\tthe_repository->objects.alt_odb_tail = &(ent->next);\n> +\t*r->objects.alt_odb_tail = ent;\n> +\tr->objects.alt_odb_tail = &(ent->next);\n>  \tent->next = NULL;\n\nI'm sure I'm missing something obvious, but it's not clear to me that\nthis transformation is correct.  Could you perhaps say a few words about\nwhy it is?\n-- \nbrian m. carlson / brian with sandals: Houston, Texas, US\nhttps://www.crustytoothpaste.net/~bmc | My opinion only\nOpenPGP: https://keybase.io/bk2204\n"},{"id":"338466","messageId":"20180206014457.GE7904@genre.crustytoothpaste.net","threadId":"47765","inReplyTo":"20180205235735.216710-22-sbeller@google.com","subject":"Re: [PATCH 042/194] object-store: move alternates API to new alternates.h","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-02-06T01:44:57Z","receivedAt":"2018-02-06T01:45:08Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Mon, Feb 05, 2018 at 03:55:03PM -0800, Stefan Beller wrote:\n> From: Jonathan Nieder <jrnieder@gmail.com>\n> \n> This should make these functions easier to find and object-store.h\n> less overwhelming to read.\n> \n> Signed-off-by: Stefan Beller <sbeller@google.com>\n> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>\n> ---\n>  alternates.h                | 68 +++++++++++++++++++++++++++++++++++++++++++++\n>  builtin/clone.c             |  1 +\n>  builtin/count-objects.c     |  1 +\n>  builtin/fsck.c              |  3 +-\n>  builtin/grep.c              |  1 +\n>  builtin/submodule--helper.c |  1 +\n>  cache.h                     | 52 ----------------------------------\n>  object-store.h              | 16 +++++------\n>  packfile.c                  |  3 +-\n>  sha1_file.c                 | 23 +++++++--------\n>  sha1_name.c                 |  3 +-\n>  submodule.c                 |  1 +\n>  t/helper/test-ref-store.c   |  1 +\n>  tmp-objdir.c                |  1 +\n>  transport.c                 |  1 +\n>  15 files changed, 102 insertions(+), 74 deletions(-)\n>  create mode 100644 alternates.h\n> \n> diff --git a/alternates.h b/alternates.h\n> new file mode 100644\n> index 0000000000..df5dc67e2e\n> --- /dev/null\n> +++ b/alternates.h\n> @@ -0,0 +1,68 @@\n> +#ifndef ALTERNATES_H\n> +#define ALTERNATES_H\n> +\n> +#include \"strbuf.h\"\n> +#include \"sha1-array.h\"\n> +\n> +struct alternates {\n> +\tstruct alternate_object_database *list;\n> +\tstruct alternate_object_database **tail;\n> +};\n> +#define ALTERNATES_INIT { NULL, NULL }\n\nI was surprised to find that this patch not only moves the alternates\nAPI to a new location, but introduces this struct.  I certainly think\nthe struct is a good idea, but it should probably go in a separate\npatch, or at least get a mention in the commit message.\n-- \nbrian m. carlson / brian with sandals: Houston, Texas, US\nhttps://www.crustytoothpaste.net/~bmc | My opinion only\nOpenPGP: https://keybase.io/bk2204\n"},{"id":"338468","messageId":"20180206015556.GF7904@genre.crustytoothpaste.net","threadId":"47765","inReplyTo":"20180205235735.216710-45-sbeller@google.com","subject":"Re: [PATCH 065/194] object-store: add repository argument to sha1_object_info","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-02-06T01:55:57Z","receivedAt":"2018-02-06T01:56:18Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Mon, Feb 05, 2018 at 03:55:26PM -0800, Stefan Beller wrote:\n> Add a repository argument to allow the callers of sha1_object_info\n> to be more specific about which repository to handle. This is a small\n> mechanical change; it doesn't change the implementation to handle\n> repositories other than the_repository yet.\n> \n> As with the previous commits, use a macro to catch callers passing a\n> repository other than the_repository at compile time.\n> \n> In the expanded macro the identifier `the_repository` is not actually used,\n> so the compiler does not catch if the repository.h header is not included\n> at the call site. call sites needing that #include were identified by\n\n\"Call sites\" (capital at the beginning of the sentence).\n-- \nbrian m. carlson / brian with sandals: Houston, Texas, US\nhttps://www.crustytoothpaste.net/~bmc | My opinion only\nOpenPGP: https://keybase.io/bk2204\n"},{"id":"338470","messageId":"20180206022033.GG7904@genre.crustytoothpaste.net","threadId":"47765","inReplyTo":"20180205235735.216710-56-sbeller@google.com","subject":"Re: [PATCH 076/194] push: add test showing bad interaction of replace refs and submodules","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-02-06T02:20:33Z","receivedAt":"2018-02-06T02:20:47Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Mon, Feb 05, 2018 at 03:55:37PM -0800, Stefan Beller wrote:\n> The ref subsystem has not been migrated yet to access the object store\n> via passed in repository objects. As a result replace when the object store\n> tries to access replace refs in a repository other than the_repository\n> it produces errors:\n> \n>   error: refs/replace/3afabef75c627b894cccc3bcae86837abc7c32fe does not point to a valid object!\n> \n> Add a test demonstrating this failure.\n> \n> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>\n> Signed-off-by: Stefan Beller <sbeller@google.com>\n> \n> squash! push: add test showing bad interaction of replace refs and submodules\n> \n> replace-objects: evaluate replacement refs without using the object store\n> \n> Pass DO_FOR_EACH_INCLUDE_BROKEN when iterating over replacement refs\n> so that the iteration does not require opening the named objects from\n> the object store. This avoids a dependency cycle between object access\n> and replace ref iteration.\n> \n> Moreover the ref subsystem has not been migrated yet to access the object\n> store via passed in repository objects.  As a result, without this patch\n> when the object store tries to access replace refs in a repository other\n> than the_repository it produces errors:\n> \n>    error: refs/replace/3afabef75c627b894cccc3bcae86837abc7c32fe does not point to a valid object!\n> \n> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>\n> Signed-off-by: Stefan Beller <sbeller@google.com>\n\nIt appears you have multiple independent commit messages here.\n-- \nbrian m. carlson / brian with sandals: Houston, Texas, US\nhttps://www.crustytoothpaste.net/~bmc | My opinion only\nOpenPGP: https://keybase.io/bk2204\n"},{"id":"338471","messageId":"20180206033255.GH7904@genre.crustytoothpaste.net","threadId":"47765","inReplyTo":"20180205235508.216277-1-sbeller@google.com","subject":"Re: [RFC PATCH 000/194] Moving global state into the repository object","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-02-06T03:32:55Z","receivedAt":"2018-02-06T03:33:10Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Mon, Feb 05, 2018 at 03:51:54PM -0800, Stefan Beller wrote:\n> This series moves a lot of global state into the repository struct.\n> It applies on top of 2512f15446149235156528dafbe75930c712b29e (2.16.0)\n> It can be found at https://github.com/stefanbeller/git/tree/object-store\n> \n> Motivation for this series:\n> * Easier to reason about code when all state is stored in one place,\n>   for example for multithreading\n> * Easier to move to processing submodules in-process instead of\n>   calling a processes for the submodule handling.\n>   The last patch demonstrates this.\n\nOf course, I like performance improvements (who doesn't?), but I really\nlike the way this series gets rid of various global variables.  I much\nprefer to have fewer globals when possible.\n\n> This is why this series tries to be reviewer friendly by utilizing\n> machine assistance as much as possible. There are 3 types of patches\n> in this series:\n> \n> (A) <area>: add repository argument to <function_foo>\n>   This sort of patch is just adding the repository as an argument to that\n>   function. It assumes the given repository is `the_repository` and has\n>   a compile time check for that assertion using a preprocessor trick.\n>   As did a compile check after each commit of the series, I don't expect\n>   the review burden on these patches to be high. Review on these patches\n>   is mostly checking for formatting errors or if I sneak in malicious\n>   code -- if you're inclined to believe that.\n> \n> (B) <area>: allow <function_foo> to handle arbitrary repositories\n>   This sort of patch is touching code inside the given function only,\n>   usually replacing all occurrences of `the_repository` by the argument\n>   `r`. Here the review is critical: Did I miss any function that relies\n>   on state of `the_repository` ?\n>   This series was developed by converting all functions of\n>   packfile/sha1-file/commit/etc using (A); after the demo patch\n>   was possible, all patches that did (A), but not (B) were deleted.\n>   Therefore I was confident at time of writing that patch that\n>   the conversion of a function which doesn't take a repository argument\n>   is okay.\n> \n> (C) other patches, such as moving code around,\n>     demoing this series in the last patch\n> \n> This approach was chosen as I think it is review friendly, despite the\n> huge number of patches.\n\nI very much appreciate this approach.  It made reviewing things much\nnicer.\n\n> A weakness of this approach is the buildup of a large series, which ignores\n> the ongoing development. Rebasing that series turned out to be ok, but merging\n> it with confidence is an issue.\n\nThat's my concern as well.  This necessarily conflicts with some of the\nobject_id and the_hash_algo work, but rebasing work on top of it\nshouldn't be too awful once it's ready to be picked up.  In fact, long\nterm, it makes that work easier, so I'm all for it.\n\nI'm sure Junio will have thoughts on the size of the series and\npotential conflicts in flight, but I'll let him articulate those.  The\nseries could in theory be split into pieces the way you've done it: it\nwould just be less convenient to work with some of the functions in the\nmean time.\n-- \nbrian m. carlson / brian with sandals: Houston, Texas, US\nhttps://www.crustytoothpaste.net/~bmc | My opinion only\nOpenPGP: https://keybase.io/bk2204\n"},{"id":"338472","messageId":"CAPig+cSE=tXs4R=VrRntjE9ENBCQE3eUvujiVhw+trQ2A+=nLw@mail.gmail.com","threadId":"47765","inReplyTo":"20180206001749.218943-38-sbeller@google.com","subject":"Re: [PATCH 136/194] alloc: allow arbitrary repositories for alloc functions","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-02-06T03:35:40Z","receivedAt":"2018-02-06T03:35:46Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Mon, Feb 5, 2018 at 7:16 PM, Stefan Beller <sbeller@google.com> wrote:\n> We have to convert them all at once, because alloc_report uses funky a\n\ns/funky a/a funky/\n\n> macro for reporting. It is better for the sake of mechanical conversion\n> to convert multiple functions at once rather than changing the structure\n> of the reporting function.\n>\n> Signed-off-by: Stefan Beller <sbeller@google.com>\n"},{"id":"338473","messageId":"CAPig+cT4=WA2PpovtG1M5hsrTxzDYdGjiYgvpp4Pbggc3Qo-Yw@mail.gmail.com","threadId":"47765","inReplyTo":"20180205235735.216710-72-sbeller@google.com","subject":"Re: [PATCH 092/194] object: move grafts to object parser","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-02-06T04:07:10Z","receivedAt":"2018-02-06T04:07:15Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Mon, Feb 5, 2018 at 6:55 PM, Stefan Beller <sbeller@google.com> wrote:\n> Grafts are only meaningful in the context of a single repository.\n> Therefore they cannot be global.\n>\n> Signed-off-by: Stefan Beller <sbeller@google.com>\n> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>\n> ---\n> diff --git a/commit.c b/commit.c\n> @@ -121,20 +120,22 @@ int register_commit_graft(struct commit_graft *graft, int ignore_dups)\n>                 if (ignore_dups)\n>                         free(graft);\n>                 else {\n> -                       free(commit_graft[pos]);\n> -                       commit_graft[pos] = graft;\n> +                       free(the_repository->parsed_objects.grafts[pos]);\n> +                       the_repository->parsed_objects.grafts[pos] = graft;\n> diff --git a/object.h b/object.h\n> @@ -4,9 +4,13 @@\n>  struct object_parser {\n>         struct object **obj_hash;\n>         int nr_objs, obj_hash_size;\n> +\n> +       /* parent substitutions from .git/info/grafts and .git/shallow */\n> +       struct commit_graft **grafts;\n> +       int grafts_alloc, grafts_nr;\n>  };\n\nDo items moved to object_parser need to get freed when object_parser\nitself is freed? Is that happening in some other patch?\n"},{"id":"338474","messageId":"CAPig+cTjUAYRbaF_CLAmtYf56cL2hhvYc4VLrE8DX-MiryCWXA@mail.gmail.com","threadId":"47765","inReplyTo":"20180205235735.216710-55-sbeller@google.com","subject":"Re: [PATCH 075/194] fetch, push: do not use submodule as alternate in has_commits check","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-02-06T04:20:44Z","receivedAt":"2018-02-06T04:20:49Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Mon, Feb 5, 2018 at 6:55 PM, Stefan Beller <sbeller@google.com> wrote:\n> Both fetch and push still use alternates to access submodules in some\n> other code paths, but this is progress towards eliminating the alternates\n> hack that conflates access to the_repository and other repositories.\n>\n> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>\n> Signed-off-by: Stefan Beller <sbeller@google.com>\n> ---\n> diff --git a/submodule.c b/submodule.c\n> @@ -832,24 +833,43 @@ static int check_has_commit(const struct object_id *oid, void *data)\n> +static int open_submodule(struct repository *out, const char *path)\n> +{\n> +       struct strbuf sb = STRBUF_INIT;\n> +\n> +       if (submodule_to_gitdir(&sb, path))\n> +               return -1;\n\nsubmodule_to_gitdir() makes no promise that it has not made\nallocations to 'sb' when it returns -1, so this is potentially\nleaking. Therefore, you should strbuf_release() here.\n\n> +\n> +       if (repo_init(out, sb.buf, NULL)) {\n> +               strbuf_release(&sb);\n> +               return -1;\n> +       }\n\nOr just combine these two error cases:\n\n    if (submodule_to_gitdir(...) || repo_init(...)) {\n        strbuf_release(...);\n        return -1;\n    }\n\n> +       out->submodule_prefix = xstrdup(path);\n> +\n> +       strbuf_release(&sb);\n> +       return 0;\n> +}\n"},{"id":"338475","messageId":"CAPig+cTnucxCf5=24UBKGU5q_n0mwn0eB1pCLdiA77qXn-1n7Q@mail.gmail.com","threadId":"47765","inReplyTo":"20180205235735.216710-39-sbeller@google.com","subject":"Re: [PATCH 059/194] refs: store the main ref store inside the repository struct","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-02-06T04:27:04Z","receivedAt":"2018-02-06T04:27:12Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Mon, Feb 5, 2018 at 6:55 PM, Stefan Beller <sbeller@google.com> wrote:\n> diff --git a/refs.c b/refs.c\n> @@ -1609,9 +1609,6 @@ static struct ref_store_hash_entry *alloc_ref_store_hash_entry(\n> -/* A pointer to the ref_store for the main repository: */\n> -static struct ref_store *main_ref_store;\n> diff --git a/repository.h b/repository.h\n> @@ -33,6 +33,11 @@ struct repository {\n>          */\n>         struct object_store objects;\n>\n> +       /*\n> +        * The store in which the refs are hold.\n> +        */\n> +       struct ref_store *main_ref_store;\n\nDo items moved to the 'repository' structure need to be freed when the\n'repository' itself is freed? Is that being done by a different patch?\nIf so, it would ease review burden for the freeing to happen in the\nsame patch in which the item is moved to the 'repository'.\n"},{"id":"338476","messageId":"CAPig+cRjQVJ5+ae+7Z=J-Sd_YDj1=L9=CYELbriTMYFkdZ+w+w@mail.gmail.com","threadId":"47765","inReplyTo":"20180205235735.216710-30-sbeller@google.com","subject":"Re: [PATCH 050/194] replace-object: check_replace_refs is safe in multi repo environment","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-02-06T04:30:55Z","receivedAt":"2018-02-06T04:31:00Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Mon, Feb 5, 2018 at 6:55 PM, Stefan Beller <sbeller@google.com> wrote:\n> In e1111cef23 (inline lookup_replace_object() calls, 2011-05-15) a shortcut\n> for checking the object replacement was added by setting check_replace_refs\n> to 0 once the replacements were evaluated to not exist. This works fine in\n> with the assumption of only one repository in existence.\n>\n> The assumption won't hold true any more when we work on multiple instances\n> of a repository structs (e.g. one struct per submodule), as the first\n> repository to be inspected may have no replacements and would set the\n> global variable. Other repositories would then completely omit their\n> evaluation of replacements.\n>\n> This reverts back the meaning of the flag `check_replace_refs` of\n> \"Do we need to check with the lookup table?\" to \"Do we need read the\n\ns/need read/need to read/\n\n> replacement definition?\", adding the bypassing logic to\n> lookup_replace_object after the replacement definition was read.\n> As with the original patch, delay the renaming of the global variable\n>\n> Signed-off-by: Stefan Beller <sbeller@google.com>\n"},{"id":"338479","messageId":"CAPig+cT6EmN=PFP9MUQG_J2QFoj8EH3TuXN8w64dYUKYiypX+A@mail.gmail.com","threadId":"47765","inReplyTo":"20180205235735.216710-22-sbeller@google.com","subject":"Re: [PATCH 042/194] object-store: move alternates API to new alternates.h","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-02-06T04:52:41Z","receivedAt":"2018-02-06T04:52:49Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Mon, Feb 5, 2018 at 6:55 PM, Stefan Beller <sbeller@google.com> wrote:\n> This should make these functions easier to find and object-store.h\n> less overwhelming to read.\n\nI think you mean: s/object-store.h/cache.h/\n\n> Signed-off-by: Stefan Beller <sbeller@google.com>\n> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>\n> ---\n>  cache.h                     | 52 ----------------------------------\n>  object-store.h              | 16 +++++------\n"},{"id":"338509","messageId":"38759fdc-64df-113b-9cc9-03e49b5b6cb2@gmail.com","threadId":"47765","inReplyTo":"20180206011940.GD7904@genre.crustytoothpaste.net","subject":"Re: [PATCH 025/194] object-store: allow prepare_alt_odb to handle arbitrary repositories","fromName":"Derrick Stolee","fromEmail":"stolee@gmail.com","sentAt":"2018-02-06T13:44:49Z","receivedAt":"2018-02-06T13:44:58Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 2/5/2018 8:19 PM, brian m. carlson wrote:\n> On Mon, Feb 05, 2018 at 03:54:46PM -0800, Stefan Beller wrote:\n>> @@ -434,12 +433,12 @@ static int link_alt_odb_entry_the_repository(const char *entry,\n>>   \tent = alloc_alt_odb(pathbuf.buf);\n>>   \n>>   \t/* add the alternate entry */\n>> -\t*the_repository->objects.alt_odb_tail = ent;\n>> -\tthe_repository->objects.alt_odb_tail = &(ent->next);\n>> +\t*r->objects.alt_odb_tail = ent;\n>> +\tr->objects.alt_odb_tail = &(ent->next);\n>>   \tent->next = NULL;\n> I'm sure I'm missing something obvious, but it's not clear to me that\n> this transformation is correct.  Could you perhaps say a few words about\n> why it is?\n\nI believe the reason it is correct is due to this change, higher up:\n\n+static void read_info_alternates(struct repository *r,\n+\t\t\t\t const char *relative_base,\n+\t\t\t\t int depth);\n\nNow the method takes a 'struct repository' pointer (which at this moment will always be the_repository) but it allows callers to use a different repository, when they are ready.\n\nThanks,\n-Stolee\n\n"},{"id":"338522","messageId":"CAGZ79kYAjs17RvRyo4rErR+ymkKfyORZ7xBSCDm_q0b-E6BqiA@mail.gmail.com","threadId":"47765","inReplyTo":"20180206011940.GD7904@genre.crustytoothpaste.net","subject":"Re: [PATCH 025/194] object-store: allow prepare_alt_odb to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T17:48:56Z","receivedAt":"2018-02-06T17:49:05Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Mon, Feb 5, 2018 at 5:19 PM, brian m. carlson\n<sandals@crustytoothpaste.net> wrote:\n> On Mon, Feb 05, 2018 at 03:54:46PM -0800, Stefan Beller wrote:\n>> @@ -434,12 +433,12 @@ static int link_alt_odb_entry_the_repository(const char *entry,\n>>       ent = alloc_alt_odb(pathbuf.buf);\n>>\n>>       /* add the alternate entry */\n>> -     *the_repository->objects.alt_odb_tail = ent;\n>> -     the_repository->objects.alt_odb_tail = &(ent->next);\n>> +     *r->objects.alt_odb_tail = ent;\n>> +     r->objects.alt_odb_tail = &(ent->next);\n>>       ent->next = NULL;\n>\n> I'm sure I'm missing something obvious, but it's not clear to me that\n> this transformation is correct.  Could you perhaps say a few words about\n> why it is?\n\nThis is a pretty open ended question, so I'll give it a try:\n\n* ent is a local variable that is newly allocated using `alloc_alt_odb`.\n  `alloc_alt_odb` has no hidden dependencies on a specific repository,\n  it uses FLEX_ALLOC_STR, which is defined in cache.h as a wrapper\n  around xcalloc/memcpy\n\n* Before this patch we always used the_repository->objects.alt_odb_tail,\n  but with this patch there is no reference \"alt_odb.tail\" of the_repository,\n  but only of a given arbitrary repository.\n\n  Usually we convert only one function at a time. (Chose that function,\n  which calls only already converted functions, because then passing in\n  r instead of the_repository still compiles correctly)\n\n  The additional messiness comes from a cycle:\n  read_info_alternates\n    -> link_alt_odb_entries\n      -> link_alt_odb_entry\n        -> read_info_alternates\n\n  That is why we cannot just convert one function, but we have to convert\n  the whole strongly connected component in this graph of functions.\n  This is why this patch is so messy and touches multiple functions at once.\n\n* While I hope this helps, I assume you want me to repeat this or other\n  hints in the commit message, too.\n\nThanks,\nStefan\n"},{"id":"338523","messageId":"CAGZ79kZ8GxrLRWV9HaXkC8fGG+ZFzLwy2gJGjw1t1MdTP=39DQ@mail.gmail.com","threadId":"47765","inReplyTo":"CAPig+cT6EmN=PFP9MUQG_J2QFoj8EH3TuXN8w64dYUKYiypX+A@mail.gmail.com","subject":"Re: [PATCH 042/194] object-store: move alternates API to new alternates.h","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T17:52:49Z","receivedAt":"2018-02-06T17:52:55Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Mon, Feb 5, 2018 at 8:52 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:\n> On Mon, Feb 5, 2018 at 6:55 PM, Stefan Beller <sbeller@google.com> wrote:\n>> This should make these functions easier to find and object-store.h\n>> less overwhelming to read.\n>\n> I think you mean: s/object-store.h/cache.h/\n\nProbably both.\n\nAt the end of the series the object-store.h has grown a bit, such that\nwe'd want to have specific things outside of it. Alternates are a good choice\nas they are coherent on their own.\n\nI have given up on cache.h and its readability, but moving things out of there\nhelps of course. And that is what the patch does.\nSo I'll change that.\n\nThanks,\nStefan\n"},{"id":"338524","messageId":"CAGZ79kbycmoA1DUVEoMAzvmyT3zMtTPFBOV6AGm_-xACDePETA@mail.gmail.com","threadId":"47765","inReplyTo":"20180206014457.GE7904@genre.crustytoothpaste.net","subject":"Re: [PATCH 042/194] object-store: move alternates API to new alternates.h","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T17:53:25Z","receivedAt":"2018-02-06T17:53:31Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Mon, Feb 5, 2018 at 5:44 PM, brian m. carlson\n<sandals@crustytoothpaste.net> wrote:\n> On Mon, Feb 05, 2018 at 03:55:03PM -0800, Stefan Beller wrote:\n>> From: Jonathan Nieder <jrnieder@gmail.com>\n>>\n>> This should make these functions easier to find and object-store.h\n>> less overwhelming to read.\n>>\n>> Signed-off-by: Stefan Beller <sbeller@google.com>\n>> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>\n>> ---\n>>  alternates.h                | 68 +++++++++++++++++++++++++++++++++++++++++++++\n>>  builtin/clone.c             |  1 +\n>>  builtin/count-objects.c     |  1 +\n>>  builtin/fsck.c              |  3 +-\n>>  builtin/grep.c              |  1 +\n>>  builtin/submodule--helper.c |  1 +\n>>  cache.h                     | 52 ----------------------------------\n>>  object-store.h              | 16 +++++------\n>>  packfile.c                  |  3 +-\n>>  sha1_file.c                 | 23 +++++++--------\n>>  sha1_name.c                 |  3 +-\n>>  submodule.c                 |  1 +\n>>  t/helper/test-ref-store.c   |  1 +\n>>  tmp-objdir.c                |  1 +\n>>  transport.c                 |  1 +\n>>  15 files changed, 102 insertions(+), 74 deletions(-)\n>>  create mode 100644 alternates.h\n>>\n>> diff --git a/alternates.h b/alternates.h\n>> new file mode 100644\n>> index 0000000000..df5dc67e2e\n>> --- /dev/null\n>> +++ b/alternates.h\n>> @@ -0,0 +1,68 @@\n>> +#ifndef ALTERNATES_H\n>> +#define ALTERNATES_H\n>> +\n>> +#include \"strbuf.h\"\n>> +#include \"sha1-array.h\"\n>> +\n>> +struct alternates {\n>> +     struct alternate_object_database *list;\n>> +     struct alternate_object_database **tail;\n>> +};\n>> +#define ALTERNATES_INIT { NULL, NULL }\n>\n> I was surprised to find that this patch not only moves the alternates\n> API to a new location, but introduces this struct.  I certainly think\n> the struct is a good idea, but it should probably go in a separate\n> patch, or at least get a mention in the commit message.\n\nok, I'll fix the commit message.\n\nThanks,\nStefan\n"},{"id":"338525","messageId":"CAGZ79kZYZfb1cWX1oeJ6=X6HGs9tCVHik4gs8n7j8WjGKjkK-g@mail.gmail.com","threadId":"47765","inReplyTo":"CAPig+cTnucxCf5=24UBKGU5q_n0mwn0eB1pCLdiA77qXn-1n7Q@mail.gmail.com","subject":"Re: [PATCH 059/194] refs: store the main ref store inside the repository struct","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T18:01:03Z","receivedAt":"2018-02-06T18:01:12Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Mon, Feb 5, 2018 at 8:27 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:\n> On Mon, Feb 5, 2018 at 6:55 PM, Stefan Beller <sbeller@google.com> wrote:\n>> diff --git a/refs.c b/refs.c\n>> @@ -1609,9 +1609,6 @@ static struct ref_store_hash_entry *alloc_ref_store_hash_entry(\n>> -/* A pointer to the ref_store for the main repository: */\n>> -static struct ref_store *main_ref_store;\n>> diff --git a/repository.h b/repository.h\n>> @@ -33,6 +33,11 @@ struct repository {\n>>          */\n>>         struct object_store objects;\n>>\n>> +       /*\n>> +        * The store in which the refs are hold.\n>> +        */\n>> +       struct ref_store *main_ref_store;\n>\n> Do items moved to the 'repository' structure need to be freed when the\n> 'repository' itself is freed? Is that being done by a different patch?\n> If so, it would ease review burden for the freeing to happen in the\n> same patch in which the item is moved to the 'repository'.\n\nThere are two cases:\n\n* the_repository\n  In the_repository we'll mostly have the globals as they exist\n  (the_index, the_hash_algo, the_ref_store) and just as before\n  these globals will not be freed at the end of the program.\n* arbitrary repos:\n  For arbitrary repos, we usually need to allocate memory in repo_init\n  and clear it out in repo_free/clear\n\nThis patch is incomplete and is leaking the main ref store for arbitrary repos.\n\nThanks for spotting the mem leak!\nStefan\n"},{"id":"338526","messageId":"CAGZ79kYKJYemWaaco5wMexf8eiYSDZ06YuReBFykFypSMQNzEQ@mail.gmail.com","threadId":"47765","inReplyTo":"CAPig+cT4=WA2PpovtG1M5hsrTxzDYdGjiYgvpp4Pbggc3Qo-Yw@mail.gmail.com","subject":"Re: [PATCH 092/194] object: move grafts to object parser","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T18:04:24Z","receivedAt":"2018-02-06T18:04:31Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Mon, Feb 5, 2018 at 8:07 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:\n> On Mon, Feb 5, 2018 at 6:55 PM, Stefan Beller <sbeller@google.com> wrote:\n>> Grafts are only meaningful in the context of a single repository.\n>> Therefore they cannot be global.\n>>\n>> Signed-off-by: Stefan Beller <sbeller@google.com>\n>> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>\n>> ---\n>> diff --git a/commit.c b/commit.c\n>> @@ -121,20 +120,22 @@ int register_commit_graft(struct commit_graft *graft, int ignore_dups)\n>>                 if (ignore_dups)\n>>                         free(graft);\n>>                 else {\n>> -                       free(commit_graft[pos]);\n>> -                       commit_graft[pos] = graft;\n>> +                       free(the_repository->parsed_objects.grafts[pos]);\n>> +                       the_repository->parsed_objects.grafts[pos] = graft;\n>> diff --git a/object.h b/object.h\n>> @@ -4,9 +4,13 @@\n>>  struct object_parser {\n>>         struct object **obj_hash;\n>>         int nr_objs, obj_hash_size;\n>> +\n>> +       /* parent substitutions from .git/info/grafts and .git/shallow */\n>> +       struct commit_graft **grafts;\n>> +       int grafts_alloc, grafts_nr;\n>>  };\n>\n> Do items moved to object_parser need to get freed when object_parser\n> itself is freed? Is that happening in some other patch?\n\nNo, this patch supposedly should free the memory via\nrepo_free (which either does it itself or calls some specific free\nfor the grafts)\n\nThanks for finding the mem leak!\nStefan\n"},{"id":"338534","messageId":"CAGZ79kYYZ-dmHA5jZeKTk9TFxn+7_zzxLPR7jNS4X8+K-JU_dg@mail.gmail.com","threadId":"47765","inReplyTo":"20180205235508.216277-1-sbeller@google.com","subject":"Re: [RFC PATCH 000/194] Moving global state into the repository object","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T20:25:51Z","receivedAt":"2018-02-06T20:26:04Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"> Any suggestions welcome!\n\nEric repeatedly points out leaking memory.\n\nAs of today we do not care about memory leaking as it is cleaned\nup at the end of the program anyway, for example the objects\nhash table is never cleared.\n\nIn a resend I will put the infrastructure in place to free the memory via\nadding\n\n  raw_object_store_clear(struct raw_object_store *)\n  object_parser_clear(struct object_parser *)\n  ref_store_clear(struct ref_store *)\n\nand calling these functions on repo destruction. The functions\nitself will be empty code-wise and contain TODO comments listing\nall variables that need care.\n\nFollow up patches can figure out what is best to do, such as closing\nthe memleaks. As repo_clear is not called for the_repository\nwe'd even keep the property of relying on fast cleanup by the OS.\n\nThanks,\nStefan\n"},{"id":"338537","messageId":"CAGZ79kYRg4URASwy5Xf7iZR_CQsGxcVDzfS040Yyc7z1uKKqZw@mail.gmail.com","threadId":"47765","inReplyTo":"CAPig+cTjUAYRbaF_CLAmtYf56cL2hhvYc4VLrE8DX-MiryCWXA@mail.gmail.com","subject":"Re: [PATCH 075/194] fetch, push: do not use submodule as alternate in has_commits check","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T20:33:24Z","receivedAt":"2018-02-06T20:33:47Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Mon, Feb 5, 2018 at 8:20 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:\n\n> Or just combine these two error cases:\n>\n>     if (submodule_to_gitdir(...) || repo_init(...)) {\n>         strbuf_release(...);\n>         return -1;\n>     }\n\nwill fix, thanks!\n"},{"id":"338540","messageId":"CAGZ79kakYV3aeWcEZDnboLyUodDgE2UU9C4ad8kq8_PRE17HHA@mail.gmail.com","threadId":"47765","inReplyTo":"20180206022033.GG7904@genre.crustytoothpaste.net","subject":"Re: [PATCH 076/194] push: add test showing bad interaction of replace refs and submodules","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T22:43:18Z","receivedAt":"2018-02-06T22:43:33Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Mon, Feb 5, 2018 at 6:20 PM, brian m. carlson\n<sandals@crustytoothpaste.net> wrote:\n> On Mon, Feb 05, 2018 at 03:55:37PM -0800, Stefan Beller wrote:\n>> The ref subsystem has not been migrated yet to access the object store\n>> via passed in repository objects. As a result replace when the object store\n>> tries to access replace refs in a repository other than the_repository\n>> it produces errors:\n>>\n>>   error: refs/replace/3afabef75c627b894cccc3bcae86837abc7c32fe does not point to a valid object!\n>>\n>> Add a test demonstrating this failure.\n>>\n>> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>\n>> Signed-off-by: Stefan Beller <sbeller@google.com>\n>>\n>> squash! push: add test showing bad interaction of replace refs and submodules\n>>\n>> replace-objects: evaluate replacement refs without using the object store\n>>\n>> Pass DO_FOR_EACH_INCLUDE_BROKEN when iterating over replacement refs\n>> so that the iteration does not require opening the named objects from\n>> the object store. This avoids a dependency cycle between object access\n>> and replace ref iteration.\n>>\n>> Moreover the ref subsystem has not been migrated yet to access the object\n>> store via passed in repository objects.  As a result, without this patch\n>> when the object store tries to access replace refs in a repository other\n>> than the_repository it produces errors:\n>>\n>>    error: refs/replace/3afabef75c627b894cccc3bcae86837abc7c32fe does not point to a valid object!\n>>\n>> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>\n>> Signed-off-by: Stefan Beller <sbeller@google.com>\n>\n> It appears you have multiple independent commit messages here.\n\nI will drop this patch; it appears as if it was targeted to be part of\n006f3f28af (replace-objects: evaluate replacement refs without\nusing the object store, 2017-09-12), which landed.\n\nWe can revive this test outside of this long series if we feel inclined.\n\nThanks for spotting!\nStefan\n"},{"id":"338548","messageId":"20180206234650.126865-1-sbeller@google.com","threadId":"47765","inReplyTo":"CAGZ79kYYZ-dmHA5jZeKTk9TFxn+7_zzxLPR7jNS4X8+K-JU_dg@mail.gmail.com","subject":"Re: [RFC PATCH 000/194] Moving global state into the repository object","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-06T23:46:50Z","receivedAt":"2018-02-06T23:47:03Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"It took some time to do fixes in such a long series, mostl of my time spent in\nrebasing and being extra careful about selecting the right commit to edit.\nBased on feedback so far I have queued the changes below.\nThe changes are also available at https://github.com/stefanbeller/git/tree/object-store-v2\nI do not plan on sending out this series today, as I would want\nto wait a couple of days between resending for such a large series.\n\nI think I addressed all issues raised, except finishing the memleak\nissues, which I'll continue working on.\n\nStefan\n\ndiff --git c/object-store.h w/object-store.h\nindex 62763b8412..a6051ccb73 100644\n--- c/object-store.h\n+++ w/object-store.h\n@@ -60,6 +60,8 @@ struct raw_object_store {\n #define RAW_OBJECT_STORE_INIT \\\n \t{ NULL, MRU_INIT, ALTERNATES_INIT, { NULL, 0, 0, 0 }, 0, 0, 0 }\n \n+extern void raw_object_store_clear(struct raw_object_store *o);\n+\n struct packed_git {\n \tstruct packed_git *next;\n \tstruct pack_window *windows;\ndiff --git c/object.c w/object.c\nindex 2fe5fac3ce..f13f9d97f4 100644\n--- c/object.c\n+++ w/object.c\n@@ -440,3 +440,20 @@ void clear_object_flags(unsigned flags)\n \t\t\tobj->flags &= ~flags;\n \t}\n }\n+\n+\n+void raw_object_store_clear(struct raw_object_store *o)\n+{\n+\t/* TODO: free alt_odb_list/tail */\n+\t/* TODO: clear packed_git, packed_git_mru */\n+}\n+\n+void object_parser_clear(struct object_parser *o)\n+{\n+\t/*\n+\t * TOOD free objects in o->obj_hash.\n+\t *\n+\t * As objects are allocated in slabs (see alloc.c), we do\n+\t * not need to free each object, but each slab instead.\n+\t */\n+}\ndiff --git c/object.h w/object.h\nindex 900f1b6611..0b42b09322 100644\n--- c/object.h\n+++ w/object.h\n@@ -43,6 +43,8 @@ extern struct alloc_state the_repository_object_state;\n \t&the_repository_object_state, \\\n \t0 }\n \n+extern void object_parser_clear(struct object_parser *o);\n+\n struct object_list {\n \tstruct object *item;\n \tstruct object_list *next;\ndiff --git c/repository.c w/repository.c\nindex 64fb6d8b34..d5ea158b26 100644\n--- c/repository.c\n+++ w/repository.c\n@@ -141,6 +141,9 @@ static void repo_clear(struct repository *repo)\n \tFREE_AND_NULL(repo->worktree);\n \tFREE_AND_NULL(repo->submodule_prefix);\n \n+\traw_object_store_clear(&repo->objects);\n+\tobject_parser_clear(&repo->parsed_objects);\n+\n \tif (repo->config) {\n \t\tgit_configset_clear(repo->config);\n \t\tFREE_AND_NULL(repo->config);\ndiff --git c/submodule.c w/submodule.c\nindex 9bd337ce99..c9634f84ef 100644\n--- c/submodule.c\n+++ w/submodule.c\n@@ -494,10 +494,7 @@ static int open_submodule(struct repository *out, const char *path)\n {\n \tstruct strbuf sb = STRBUF_INIT;\n \n-\tif (submodule_to_gitdir(&sb, path))\n-\t\treturn -1;\n-\n-\tif (repo_init(out, sb.buf, NULL)) {\n+\tif (submodule_to_gitdir(&sb, path) || repo_init(out, sb.buf, NULL)) {\n \t\tstrbuf_release(&sb);\n \t\treturn -1;\n \t}\ndiff --git c/t/t5531-deep-submodule-push.sh w/t/t5531-deep-submodule-push.sh\nindex 8b2aa5a0f4..39cb2c1c34 100755\n--- c/t/t5531-deep-submodule-push.sh\n+++ w/t/t5531-deep-submodule-push.sh\n@@ -308,22 +308,6 @@ test_expect_success 'submodule entry pointing at a tag is error' '\n \ttest_i18ngrep \"is a tag, not a commit\" err\n '\n \n-test_expect_success 'replace ref does not interfere with submodule access' '\n-\ttest_commit -C work/gar/bage one &&\n-\ttest_commit -C work/gar/bage two &&\n-\tgit -C work/gar/bage reset HEAD^^ &&\n-\tgit -C work/gar/bage replace two one &&\n-\ttest_when_finished \"git -C work/gar/bage replace -d two\" &&\n-\n-\ttest_commit -C work/gar/bage three &&\n-\tgit -C work add gar/bage &&\n-\tgit -C work commit -m \"advance submodule\" &&\n-\n-\tgit -C work push --recurse-submodules=on-demand ../pub.git master 2>err &&\n-\t! grep error err &&\n-\t! grep fatal err\n-'\n-\n test_expect_success 'push fails if recurse submodules option passed as yes' '\n \t(\n \t\tcd work/gar/bage &&\n"},{"id":"338600","messageId":"CAPig+cSFcjV8RfWhaZsy2CqYG0JYfn4u0vKkf_XkUAmC12uONA@mail.gmail.com","threadId":"47765","inReplyTo":"CAGZ79kYYZ-dmHA5jZeKTk9TFxn+7_zzxLPR7jNS4X8+K-JU_dg@mail.gmail.com","subject":"Re: [RFC PATCH 000/194] Moving global state into the repository object","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-02-07T09:54:11Z","receivedAt":"2018-02-07T09:54:18Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Tue, Feb 6, 2018 at 3:25 PM, Stefan Beller <sbeller@google.com> wrote:\n>> Any suggestions welcome!\n>\n> Eric repeatedly points out leaking memory.\n>\n> As of today we do not care about memory leaking as it is cleaned\n> up at the end of the program anyway, for example the objects\n> hash table is never cleared.\n\nIs this still true/desirable when multiple 'repos' are involved?\n\n> In a resend I will put the infrastructure in place to free the memory via\n> adding\n>\n>   raw_object_store_clear(struct raw_object_store *)\n>   object_parser_clear(struct object_parser *)\n>   ref_store_clear(struct ref_store *)\n>\n> and calling these functions on repo destruction. The functions\n> itself will be empty code-wise and contain TODO comments listing\n> all variables that need care.\n\nI'm confused. If you go to the effort of inserting TODO's why not go\nall the way and instead insert the actual code?\n\n> Follow up patches can figure out what is best to do, such as closing\n> the memleaks. As repo_clear is not called for the_repository\n> we'd even keep the property of relying on fast cleanup by the OS.\n"},{"id":"338610","messageId":"CACsJy8CGgekpX4cZkyyTSPrj87uQVKZSOL7fyT__P2dh_1LmVQ@mail.gmail.com","threadId":"47765","inReplyTo":"20180205235508.216277-1-sbeller@google.com","subject":"Re: [RFC PATCH 000/194] Moving global state into the repository object","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2018-02-07T11:48:32Z","receivedAt":"2018-02-07T11:49:08Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Tue, Feb 6, 2018 at 6:51 AM, Stefan Beller <sbeller@google.com> wrote:\n> This series moves a lot of global state into the repository struct.\n> It applies on top of 2512f15446149235156528dafbe75930c712b29e (2.16.0)\n> It can be found at https://github.com/stefanbeller/git/tree/object-store\n>\n> Motivation for this series:\n> * Easier to reason about code when all state is stored in one place,\n>   for example for multithreading\n> * Easier to move to processing submodules in-process instead of\n>   calling a processes for the submodule handling.\n>   The last patch demonstrates this.\n\nI have a mixed feeling about this. The end game is to keep\n\"the_repository\" references as minimum as possible, right? Like we\nonly need to mention in in cmd_xxx() and not all over the place. If\nso, yay!!\n\nSomething else.. maybe \"struct repository *\" should not be a universal\nfunction argument to avoid global states. Like sha1_file.c is mostly about the\nobject store, and I see that you added object store struct (nice!).\nThese sha1 related function should take the object_store* (which\nprobably is a combination of both packed and loose stores since they\ndepend on each other), not repository*. This way if a function needs\nboth access to object store and ref store, we can see the two\ndependencies from function arguments.\n\nThe alternate object store, if modeled right, could share the same\nobject store interface. But I don't think we should do anything that\nbig right now, just put alternate object store inside object_store.\n\nSimilarly those functions in blob.c, commit.c, tree.c... should take\nobject_parser* as argument instead of repository*. Maybe there's a\nbetter name for this than object_parser. parsed_object_store I guess.\nOr maybe just object_pool.\n-- \nDuy\n"},{"id":"338631","messageId":"1ba0cc21-aeb3-eeaf-4e1d-c8e1eeca0763@jeffhostetler.com","threadId":"47765","inReplyTo":"20180205235508.216277-1-sbeller@google.com","subject":"Re: [RFC PATCH 000/194] Moving global state into the repository object","fromName":"Jeff Hostetler","fromEmail":"git@jeffhostetler.com","sentAt":"2018-02-07T16:39:57Z","receivedAt":"2018-02-07T16:40:04Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"\n\nOn 2/5/2018 6:51 PM, Stefan Beller wrote:\n> This series moves a lot of global state into the repository struct.\n> It applies on top of 2512f15446149235156528dafbe75930c712b29e (2.16.0)\n> It can be found at https://github.com/stefanbeller/git/tree/object-store\n> \n> Motivation for this series:\n> * Easier to reason about code when all state is stored in one place,\n>    for example for multithreading\n> * Easier to move to processing submodules in-process instead of\n>    calling a processes for the submodule handling.\n>    The last patch demonstrates this.\n[...]\n\nVery nice.  My eyes glazed over a few times, but I like the\ndirection you're heading here.\n\nThanks for tackling this!\nJeff\n\n\n"},{"id":"338641","messageId":"CAGZ79kabQ1WvxxjFV+fgq8b142yNrtGZC_Vqac+5b3CkUpbi2w@mail.gmail.com","threadId":"47765","inReplyTo":"CACsJy8CGgekpX4cZkyyTSPrj87uQVKZSOL7fyT__P2dh_1LmVQ@mail.gmail.com","subject":"Re: [RFC PATCH 000/194] Moving global state into the repository object","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-07T18:06:43Z","receivedAt":"2018-02-07T18:06:50Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Wed, Feb 7, 2018 at 3:48 AM, Duy Nguyen <pclouds@gmail.com> wrote:\n> On Tue, Feb 6, 2018 at 6:51 AM, Stefan Beller <sbeller@google.com> wrote:\n>> This series moves a lot of global state into the repository struct.\n>> It applies on top of 2512f15446149235156528dafbe75930c712b29e (2.16.0)\n>> It can be found at https://github.com/stefanbeller/git/tree/object-store\n>>\n>> Motivation for this series:\n>> * Easier to reason about code when all state is stored in one place,\n>>   for example for multithreading\n>> * Easier to move to processing submodules in-process instead of\n>>   calling a processes for the submodule handling.\n>>   The last patch demonstrates this.\n>\n> I have a mixed feeling about this. The end game is to keep\n> \"the_repository\" references as minimum as possible, right? Like we\n> only need to mention in in cmd_xxx() and not all over the place. If\n> so, yay!!\n\nYes. And the super-end-game long after this series is to have\n    cmd_xxx(struct repository *r, argc, argv)\nor so.\n\n> Something else.. maybe \"struct repository *\" should not be a universal\n> function argument to avoid global states. Like sha1_file.c is mostly about the\n> object store, and I see that you added object store struct (nice!).\n> These sha1 related function should take the object_store* (which\n> probably is a combination of both packed and loose stores since they\n> depend on each other), not repository*. This way if a function needs\n> both access to object store and ref store, we can see the two\n> dependencies from function arguments.\n\nI tried that in the beginning and it blew up a couple of times when I realized\nthat I forgot to pass through one of these dependencies.\nMaybe we can go to the repository and shrink the scope in a follow up?\n\n> The alternate object store, if modeled right, could share the same\n> object store interface. But I don't think we should do anything that\n> big right now, just put alternate object store inside object_store.\n\nyup that is the case, see struct raw_object_store at the end of the series\nhttps://github.com/stefanbeller/git/blob/object-store-v2/object-store.h\n\n> Similarly those functions in blob.c, commit.c, tree.c... should take\n> object_parser* as argument instead of repository*. Maybe there's a\n> better name for this than object_parser. parsed_object_store I guess.\n> Or maybe just object_pool.\n\nNote that the initial few patches are misleading in the name,\nhttps://public-inbox.org/git/20180205235735.216710-59-sbeller@google.com/\nwhich splits up the object handling into two layers, the \"physical\" layer\n(where to get the data from, mmaping pack files, alternates, streams of bytes),\nwhich is \"struct raw_object_store objects;\" in the repository, and the\n\"object\" layer, which is about parsing the objects and making sense of the data\n(which tree belongs to a commit, dereferencing tags)\n\nSo maybe I'll try to make the first layer into its own series, such\nthat we'll have a smaller series.\n\nThanks,\nStefan\n\n> --\n> Duy\n"},{"id":"338672","messageId":"20180207140638.a4ff04513e10e1fc3f2d7c9c@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-5-sbeller@google.com","subject":"Re: [PATCH 025/194] object-store: allow prepare_alt_odb to handle arbitrary repositories","fromName":"Jonathan Tan","fromEmail":"jonathantanmy@google.com","sentAt":"2018-02-07T22:06:38Z","receivedAt":"2018-02-07T22:06:46Z","isPatch":true,"sender":{"key":"jonathantanmy@fastmail.com","avatar":null},"body":"On Mon,  5 Feb 2018 15:54:46 -0800\nStefan Beller <sbeller@google.com> wrote:\n\n> +\t/*\n> +\t * Path to the alternate object database, relative to the\n> +\t * current working directory.\n> +\t */\n>  \tchar path[FLEX_ARRAY];\n\nI would prefer this to be commented:\n\n  Path to the alternative object store. If this is a relative path, it\n  is relative to the current working directory.\n\nto show that it is not necessarily relative, but the current version is\nfine too.\n\n> +\t\t/*\n> +\t\t * Paths in alt are relative to the cwd. We ignore environment\n> +\t\t * settings like this for all repositories except for\n> +\t\t * the_repository, so we don't have to worry about transforming\n> +\t\t * the path to be relative to another repository.\n> +\t\t */\n> +\t\tlink_alt_odb_entries(r, alt, PATH_SEP, NULL, 0);\n\nI find the comment confusing - it makes more sense for the reason for us\nnot worrying about transforming the path is that the paths as stored in\nstruct alternate_object_database are relative to the CWD, not that we\nignore environment variables for certain repositories.\n\nI think it's best to remove this comment, and instead add a comment to\nread_info_alternates() before its call to link_alt_odb_entries(),\nexplaining that paths in the alternates file are relative to\n\"info/alternates\", not to the CWD (since that is the exceptional case).\n\nAll the patches prior to this look good. Thanks especially for the\nconsistent naming convention of the patch titles.\n"},{"id":"338674","messageId":"20180207143300.ce1c39ca07f6a0d64fe0e7ca@google.com","threadId":"47765","inReplyTo":"20180205235735.216710-18-sbeller@google.com","subject":"Re: [PATCH 038/194] pack: allow sha1_loose_object_info to handle arbitrary repositories","fromName":"Jonathan Tan","fromEmail":"jonathantanmy@google.com","sentAt":"2018-02-07T22:33:00Z","receivedAt":"2018-02-07T22:33:07Z","isPatch":true,"sender":{"key":"jonathantanmy@fastmail.com","avatar":null},"body":"On Mon,  5 Feb 2018 15:54:59 -0800\nStefan Beller <sbeller@google.com> wrote:\n\n> From: Jonathan Nieder <jrnieder@gmail.com>\n> \n> Signed-off-by: Stefan Beller <sbeller@google.com>\n> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>\n> ---\n>  sha1_file.c | 11 +++++------\n>  1 file changed, 5 insertions(+), 6 deletions(-)\n\nThanks - I can see that this has been a lot of work, and it brings a lot\nof benefit. Among other things, this will probably allow me to remove\nthe \"fetch_if_missing\" global variable that we need to set and reset in\nthe partial clone series, replacing it with a setting in either the repo\nor the object store (and when fetching a missing object, first cloning\nthe repo/store and then setting that setting, so that objects are not\nrecursively fetched).\n\nIf we're planning to split the series up for merging in batches (which,\nas a reviewer, I'm very much in favor of), I think this is a good\nstopping point for the first batch, so I'll stop my review here for now.\nAfter these 38 patches, the net benefit is a better position of the\npacked object variables (in struct repository) and permitting the\nreading of loose objects in any repository. (Permitting the reading of\nany object in any repository, I see, will only come later in patch 74.)\n"},{"id":"338679","messageId":"CAGZ79kaVBeq_29nyvgLtjLkqZxi02RstE3ZtFOFNvKHpNu=k_w@mail.gmail.com","threadId":"47765","inReplyTo":"20180207143300.ce1c39ca07f6a0d64fe0e7ca@google.com","subject":"Re: [PATCH 038/194] pack: allow sha1_loose_object_info to handle arbitrary repositories","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-07T23:31:14Z","receivedAt":"2018-02-07T23:31:21Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Wed, Feb 7, 2018 at 2:33 PM, Jonathan Tan <jonathantanmy@google.com> wrote:\n> On Mon,  5 Feb 2018 15:54:59 -0800\n> Stefan Beller <sbeller@google.com> wrote:\n>\n>> From: Jonathan Nieder <jrnieder@gmail.com>\n>>\n>> Signed-off-by: Stefan Beller <sbeller@google.com>\n>> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>\n>> ---\n>>  sha1_file.c | 11 +++++------\n>>  1 file changed, 5 insertions(+), 6 deletions(-)\n>\n> Thanks - I can see that this has been a lot of work, and it brings a lot\n> of benefit. Among other things, this will probably allow me to remove\n> the \"fetch_if_missing\" global variable that we need to set and reset in\n> the partial clone series, replacing it with a setting in either the repo\n> or the object store (and when fetching a missing object, first cloning\n> the repo/store and then setting that setting, so that objects are not\n> recursively fetched).\n\nThat sounds intriguing.\n\n> If we're planning to split the series up for merging in batches (which,\n> as a reviewer, I'm very much in favor of), I think this is a good\n> stopping point for the first batch, so I'll stop my review here for now.\n\nThanks for identifying a good spot.\n\nI'll look at this part of the series closer for a reroll, and need to make sure\nthere are no leftovers with the #define trick.\n\n> After these 38 patches, the net benefit is a better position of the\n> packed object variables (in struct repository) and permitting the\n> reading of loose objects in any repository. (Permitting the reading of\n> any object in any repository, I see, will only come later in patch 74.)\n\nwhich would then be a good portion for the next series.\n\nThanks for the review!\n"},{"id":"338686","messageId":"20180208014735.GC785098@genre.crustytoothpaste.net","threadId":"47765","inReplyTo":"CAGZ79kYAjs17RvRyo4rErR+ymkKfyORZ7xBSCDm_q0b-E6BqiA@mail.gmail.com","subject":"Re: [PATCH 025/194] object-store: allow prepare_alt_odb to handle arbitrary repositories","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-02-08T01:47:35Z","receivedAt":"2018-02-08T01:47:46Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Tue, Feb 06, 2018 at 09:48:56AM -0800, Stefan Beller wrote:\n> On Mon, Feb 5, 2018 at 5:19 PM, brian m. carlson\n> <sandals@crustytoothpaste.net> wrote:\n> > On Mon, Feb 05, 2018 at 03:54:46PM -0800, Stefan Beller wrote:\n> >> @@ -434,12 +433,12 @@ static int link_alt_odb_entry_the_repository(const char *entry,\n> >>       ent = alloc_alt_odb(pathbuf.buf);\n> >>\n> >>       /* add the alternate entry */\n> >> -     *the_repository->objects.alt_odb_tail = ent;\n> >> -     the_repository->objects.alt_odb_tail = &(ent->next);\n> >> +     *r->objects.alt_odb_tail = ent;\n> >> +     r->objects.alt_odb_tail = &(ent->next);\n> >>       ent->next = NULL;\n> >\n> > I'm sure I'm missing something obvious, but it's not clear to me that\n> > this transformation is correct.  Could you perhaps say a few words about\n> > why it is?\n> \n> This is a pretty open ended question, so I'll give it a try:\n\nI apologize.  My question was about the use of ent and ent->next, but it\nappears I merely misread the patch as converting from ent to\n&(ent->next), but that's not the case.\n-- \nbrian m. carlson / brian with sandals: Houston, Texas, US\nhttps://www.crustytoothpaste.net/~bmc | My opinion only\nOpenPGP: https://keybase.io/bk2204\n"},{"id":"338706","messageId":"CABPp-BEJniR9H4rN6Ks9bg99qrxJr8vp9pg8YK_+gqhu+oNf=w@mail.gmail.com","threadId":"47765","inReplyTo":"20180205235508.216277-1-sbeller@google.com","subject":"Re: [RFC PATCH 000/194] Moving global state into the repository object","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2018-02-08T15:42:53Z","receivedAt":"2018-02-08T15:43:01Z","isPatch":true,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"On Mon, Feb 5, 2018 at 3:51 PM, Stefan Beller <sbeller@google.com> wrote:\n> This series moves a lot of global state into the repository struct.\n> It applies on top of 2512f15446149235156528dafbe75930c712b29e (2.16.0)\n> It can be found at https://github.com/stefanbeller/git/tree/object-store\n>\n> Motivation for this series:\n> * Easier to reason about code when all state is stored in one place,\n>   for example for multithreading\n> * Easier to move to processing submodules in-process instead of\n>   calling a processes for the submodule handling.\n>   The last patch demonstrates this.\n\nFor what it's worth...I spot checked some random patches, looked\nclosely at the changes to merge-recursive, and looked at what was\nhappening to cache.h\n\nI like how you structured the series, and I like the goals.  Didn't\nfind any problems in the small pieces I looked at.\n"},{"id":"338944","messageId":"xmqqsha9vmqt.fsf@gitster-ct.c.googlers.com","threadId":"47765","inReplyTo":"20180205235508.216277-4-sbeller@google.com","subject":"Re: [PATCH 003/194] object-store: move packed_git and packed_git_mru to object store","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-02-09T22:09:30Z","receivedAt":"2018-02-09T22:09:38Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Stefan Beller <sbeller@google.com> writes:\n\n> Patch generated by\n>\n>  2. Applying the semantic patch contrib/coccinelle/packed_git.cocci\n>     to adjust callers.\n\nAbout this part...\n\n> diff --git a/contrib/coccinelle/packed_git.cocci b/contrib/coccinelle/packed_git.cocci\n> new file mode 100644\n> index 0000000000..da317a51a9\n> --- /dev/null\n> +++ b/contrib/coccinelle/packed_git.cocci\n> @@ -0,0 +1,7 @@\n> +@@ @@\n> +- packed_git\n> ++ the_repository->objects.packed_git\n> +\n> +@@ @@\n> +- packed_git_mru\n> ++ the_repository->objects.packed_git_mru\n\nThe above is correct for one-time transition turning pre-transition\ncode to post the_repository world, but I am not sure if we want to\nhave it in contrib/coccinelle/, where \"make coccicheck\" looks at, as\na way to continuously keep an eye on \"style\" violations like using\nstrbuf_addf() for a constant when strbuf_addstr() suffices.\n\nWouldn't we need a mechanism to ensure that this file will *not* be\nused in \"make coccicheck\" somehow?\n\n\n"},{"id":"338956","messageId":"xmqq4lmpvju5.fsf@gitster-ct.c.googlers.com","threadId":"47765","inReplyTo":"20180206014457.GE7904@genre.crustytoothpaste.net","subject":"Re: [PATCH 042/194] object-store: move alternates API to new alternates.h","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-02-09T23:12:18Z","receivedAt":"2018-02-09T23:12:27Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n\n>> +#include \"strbuf.h\"\n>> +#include \"sha1-array.h\"\n>> +\n>> +struct alternates {\n>> +\tstruct alternate_object_database *list;\n>> +\tstruct alternate_object_database **tail;\n>> +};\n>> +#define ALTERNATES_INIT { NULL, NULL }\n>\n> I was surprised to find that this patch not only moves the alternates\n> API to a new location, but introduces this struct.  I certainly think\n> the struct is a good idea, but it should probably go in a separate\n> patch, or at least get a mention in the commit message.\n\nYeah, I tend to agree that splitting it into two patches may make\nmore sense, especially given that this is already close to 200 patch\nseries ;-)\n\n"},{"id":"338961","messageId":"xmqqzi4hu53x.fsf@gitster-ct.c.googlers.com","threadId":"47765","inReplyTo":"20180205235735.216710-26-sbeller@google.com","subject":"Re: [PATCH 046/194] object-store: move replace_objects back to object-store","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-02-09T23:15:46Z","receivedAt":"2018-02-09T23:15:53Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Stefan Beller <sbeller@google.com> writes:\n\n> @@ -32,7 +31,15 @@ struct object_store {\n>  \t * Objects that should be substituted by other objects\n>  \t * (see git-replace(1)).\n>  \t */\n> -\tstruct replace_objects replacements;\n> +\tstruct replace_objects {\n> +\t\t/*\n> +\t\t * An array of replacements.  The array is kept sorted by the original\n> +\t\t * sha1.\n> +\t\t */\n> +\t\tstruct replace_object **items;\n> +\n> +\t\tint alloc, nr;\n> +\t} replacements;\n>  \n>  \t/*\n>  \t * A fast, rough count of the number of objects in the repository.\n> @@ -49,7 +56,7 @@ struct object_store {\n>  \tunsigned packed_git_initialized : 1;\n>  };\n>  #define OBJECT_STORE_INIT \\\n> -\t{ NULL, MRU_INIT, ALTERNATES_INIT, REPLACE_OBJECTS_INIT, 0, 0, 0 }\n> +\t{ NULL, MRU_INIT, ALTERNATES_INIT, { NULL, 0, 0 }, 0, 0, 0 }\n\nNot the primary thrust of this topic, but we may want to convert\nthese to use designated initializers after this series is done.\n"},{"id":"338981","messageId":"CACsJy8DvkjqL0i7mGbFQmAm0Ncvr4SeRMeZTzUzGdMB0Y86aeA@mail.gmail.com","threadId":"47765","inReplyTo":"CAGZ79kabQ1WvxxjFV+fgq8b142yNrtGZC_Vqac+5b3CkUpbi2w@mail.gmail.com","subject":"Re: [RFC PATCH 000/194] Moving global state into the repository object","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2018-02-10T10:36:25Z","receivedAt":"2018-02-10T10:37:01Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Thu, Feb 8, 2018 at 1:06 AM, Stefan Beller <sbeller@google.com> wrote:\n>> Something else.. maybe \"struct repository *\" should not be a universal\n>> function argument to avoid global states. Like sha1_file.c is mostly about the\n>> object store, and I see that you added object store struct (nice!).\n>> These sha1 related function should take the object_store* (which\n>> probably is a combination of both packed and loose stores since they\n>> depend on each other), not repository*. This way if a function needs\n>> both access to object store and ref store, we can see the two\n>> dependencies from function arguments.\n>\n> I tried that in the beginning and it blew up a couple of times when I realized\n> that I forgot to pass through one of these dependencies.\n> Maybe we can go to the repository and shrink the scope in a follow up?\n\nI think it's a good thing to do. We need to make these implicit\ndependencies explicit sooner or later.\n\nAlso, perhaps at the earlier steps you don't need to add everything to\nthe_respository yet. You can have the_object_store, the_parsed_object\n(and we already have get_main_ref_store()), then use them internally\nwithout touching the API, which helps reduce code change. For example,\nread_sha1_file() could be converted to take \"struct object_store *\"\nall the way\n\nvoid *read_sha1_file_extended(const unsigned char *sha1,\n      enum object_type *type,\n      unsigned long *size,\n      int lookup_replace)\n{\n        struct object_store *store = &the_object_store;\n        ...\n        // more access to \"store\"\n}\n\nWhen every piece is in place, the API change can be made be removing\nthat \"store = &the_object_store\" line and make \"store\" an argument of\nread_sha1_file().\n-- \nDuy\n"},{"id":"339092","messageId":"CAGZ79kacD5Bevw==v3fbyWmz0FiDDM5ypkYuxHxbXJM62FX40w@mail.gmail.com","threadId":"47765","inReplyTo":"xmqqsha9vmqt.fsf@gitster-ct.c.googlers.com","subject":"Re: [PATCH 003/194] object-store: move packed_git and packed_git_mru to object store","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-12T19:00:59Z","receivedAt":"2018-02-12T19:01:05Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Fri, Feb 9, 2018 at 2:09 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Stefan Beller <sbeller@google.com> writes:\n>\n>> Patch generated by\n>>\n>>  2. Applying the semantic patch contrib/coccinelle/packed_git.cocci\n>>     to adjust callers.\n>\n> About this part...\n>\n>> diff --git a/contrib/coccinelle/packed_git.cocci b/contrib/coccinelle/packed_git.cocci\n>> new file mode 100644\n>> index 0000000000..da317a51a9\n>> --- /dev/null\n>> +++ b/contrib/coccinelle/packed_git.cocci\n>> @@ -0,0 +1,7 @@\n>> +@@ @@\n>> +- packed_git\n>> ++ the_repository->objects.packed_git\n>> +\n>> +@@ @@\n>> +- packed_git_mru\n>> ++ the_repository->objects.packed_git_mru\n>\n> The above is correct for one-time transition turning pre-transition\n> code to post the_repository world, but I am not sure if we want to\n> have it in contrib/coccinelle/, where \"make coccicheck\" looks at, as\n> a way to continuously keep an eye on \"style\" violations like using\n> strbuf_addf() for a constant when strbuf_addstr() suffices.\n>\n> Wouldn't we need a mechanism to ensure that this file will *not* be\n> used in \"make coccicheck\" somehow?\n>\n\nI can omit the cocci files from the patches, if that is better for maintenance.\n\nI thought it may be a helpful\nfor merging this series with the rest of the evolved code base which\nmay make use of one of the converted functions. So instead of fixing\nthat new instance manually, cocinelle could do that instead.\n\nStefan\n"},{"id":"339093","messageId":"CAGZ79kbFc6fsajRtUQYtNxPq05cb=U+juHDESGoJMRrZuKVsqQ@mail.gmail.com","threadId":"47765","inReplyTo":"xmqqzi4hu53x.fsf@gitster-ct.c.googlers.com","subject":"Re: [PATCH 046/194] object-store: move replace_objects back to object-store","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-12T19:08:43Z","receivedAt":"2018-02-12T19:08:50Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Fri, Feb 9, 2018 at 3:15 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Stefan Beller <sbeller@google.com> writes:\n>\n>> @@ -32,7 +31,15 @@ struct object_store {\n>>        * Objects that should be substituted by other objects\n>>        * (see git-replace(1)).\n>>        */\n>> -     struct replace_objects replacements;\n>> +     struct replace_objects {\n>> +             /*\n>> +              * An array of replacements.  The array is kept sorted by the original\n>> +              * sha1.\n>> +              */\n>> +             struct replace_object **items;\n>> +\n>> +             int alloc, nr;\n>> +     } replacements;\n>>\n>>       /*\n>>        * A fast, rough count of the number of objects in the repository.\n>> @@ -49,7 +56,7 @@ struct object_store {\n>>       unsigned packed_git_initialized : 1;\n>>  };\n>>  #define OBJECT_STORE_INIT \\\n>> -     { NULL, MRU_INIT, ALTERNATES_INIT, REPLACE_OBJECTS_INIT, 0, 0, 0 }\n>> +     { NULL, MRU_INIT, ALTERNATES_INIT, { NULL, 0, 0 }, 0, 0, 0 }\n\nMaybe we can move the REPLACE_OBJECTS_INIT just before the\ndefinition of OBJECT_STORE_INIT, so we'd not need to touch this line here.\n\n>\n> Not the primary thrust of this topic, but we may want to convert\n> these to use designated initializers after this series is done.\n\nI agree.\n\nI feel cbc0f81d96 (strbuf: use designated initializers in STRBUF_INIT,\n2017-07-10)\nmay need longer cooking until all the interesting architectures have\ntried picking up\nthe latest release, though.\n\nStefan\n"},{"id":"339109","messageId":"xmqqsha5sywh.fsf@gitster-ct.c.googlers.com","threadId":"47765","inReplyTo":"CAGZ79kacD5Bevw==v3fbyWmz0FiDDM5ypkYuxHxbXJM62FX40w@mail.gmail.com","subject":"Re: [PATCH 003/194] object-store: move packed_git and packed_git_mru to object store","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-02-12T21:04:14Z","receivedAt":"2018-02-12T21:04:22Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Stefan Beller <sbeller@google.com> writes:\n\n> I thought it may be a helpful\n> for merging this series with the rest of the evolved code base which\n> may make use of one of the converted functions. So instead of fixing\n> that new instance manually, cocinelle could do that instead.\n\nHaving the .cocci used for the conversion *somewhere* would indeed\nbe helpful, as it allows me to (1) try reproducing this patch by\nsomebody else using the file and following the steps in order to\naudit this patch and (2) catch new places that need to be migrated\nin in-flight topics.\n\nBut placing it in contrib/coccinelle/ has other side effects.\n\nI can think of two precedents in this project, namely:\n\n - fixup-builtins in 36e5e70e (\"Start deprecating \"git-command\" in\n   favor of \"git command\"\", 2007-06-30)\n\n - convert-cache in d98b46f8 (\"Do SHA1 hash _before_ compression.\",\n   2005-04-20)\n\nthat are about tools that is useful during a transition period but\ncan and should be removed after transition is over.  These two were\ndone as one-off and added at the top-level, but perhaps we want a\nnew directory at the top (e.g. devtools/) to add things like this\nand hold them while they are relevant?\n"},{"id":"339116","messageId":"adb2500e-d95d-bbaa-aa22-ee10d9613401@web.de","threadId":"47765","inReplyTo":"CAGZ79kacD5Bevw==v3fbyWmz0FiDDM5ypkYuxHxbXJM62FX40w@mail.gmail.com","subject":"Re: [PATCH 003/194] object-store: move packed_git and packed_git_mru to object store","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2018-02-12T21:40:13Z","receivedAt":"2018-02-12T21:40:27Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"[removed rene.scharfe@lsrfire.ath.cx from cc:; I lost that domain a few\n years ago.  Thanks for the heads-up, Stefan!]\n\nAm 12.02.2018 um 20:00 schrieb Stefan Beller:\n> On Fri, Feb 9, 2018 at 2:09 PM, Junio C Hamano <gitster@pobox.com> wrote:\n>> Stefan Beller <sbeller@google.com> writes:\n>>\n>>> Patch generated by\n>>>\n>>>   2. Applying the semantic patch contrib/coccinelle/packed_git.cocci\n>>>      to adjust callers.\n>>\n>> About this part...\n>>\n>>> diff --git a/contrib/coccinelle/packed_git.cocci b/contrib/coccinelle/packed_git.cocci\n>>> new file mode 100644\n>>> index 0000000000..da317a51a9\n>>> --- /dev/null\n>>> +++ b/contrib/coccinelle/packed_git.cocci\n>>> @@ -0,0 +1,7 @@\n>>> +@@ @@\n>>> +- packed_git\n>>> ++ the_repository->objects.packed_git\n>>> +\n>>> +@@ @@\n>>> +- packed_git_mru\n>>> ++ the_repository->objects.packed_git_mru\n>>\n>> The above is correct for one-time transition turning pre-transition\n>> code to post the_repository world, but I am not sure if we want to\n>> have it in contrib/coccinelle/, where \"make coccicheck\" looks at, as\n>> a way to continuously keep an eye on \"style\" violations like using\n>> strbuf_addf() for a constant when strbuf_addstr() suffices.\n>>\n>> Wouldn't we need a mechanism to ensure that this file will *not* be\n>> used in \"make coccicheck\" somehow?\n\nobject_id.cocci is similar in this regard -- once the conversion is\ndone, we won't need it anymore.\n\n> I can omit the cocci files from the patches, if that is better for maintenance.\n> \n> I thought it may be a helpful\n> for merging this series with the rest of the evolved code base which\n> may make use of one of the converted functions. So instead of fixing\n> that new instance manually, cocinelle could do that instead.\n\nRight, merging should be easier -- instead of fixing conflicts manually,\nCoccinelle could regenerate the patch.\n\nRené\n"},{"id":"339117","messageId":"212094a6-f1bd-c4cd-01f9-e819a701cfac@web.de","threadId":"47765","inReplyTo":"xmqqsha5sywh.fsf@gitster-ct.c.googlers.com","subject":"Re: [PATCH 003/194] object-store: move packed_git and packed_git_mru to object store","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2018-02-12T21:40:20Z","receivedAt":"2018-02-12T21:40:30Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Am 12.02.2018 um 22:04 schrieb Junio C Hamano:\n> Stefan Beller <sbeller@google.com> writes:\n> \n>> I thought it may be a helpful\n>> for merging this series with the rest of the evolved code base which\n>> may make use of one of the converted functions. So instead of fixing\n>> that new instance manually, cocinelle could do that instead.\n> \n> Having the .cocci used for the conversion *somewhere* would indeed\n> be helpful, as it allows me to (1) try reproducing this patch by\n> somebody else using the file and following the steps in order to\n> audit this patch and (2) catch new places that need to be migrated\n> in in-flight topics.\n> \n> But placing it in contrib/coccinelle/ has other side effects.\n\nRunning \"make coccicheck\" takes longer.  What other downsides are\nthere?\n\n> I can think of two precedents in this project, namely:\n> \n>   - fixup-builtins in 36e5e70e (\"Start deprecating \"git-command\" in\n>     favor of \"git command\"\", 2007-06-30)\n> \n>   - convert-cache in d98b46f8 (\"Do SHA1 hash _before_ compression.\",\n>     2005-04-20)\n> \n> that are about tools that is useful during a transition period but\n> can and should be removed after transition is over.  These two were\n> done as one-off and added at the top-level, but perhaps we want a\n> new directory at the top (e.g. devtools/) to add things like this\n> and hold them while they are relevant?\n\nSemantic patches for completed transformations can be removed as\nwell (or archived, e.g. by renaming to .cocci.done or so).\n\nRené\n"},{"id":"339119","messageId":"xmqqbmgtswuq.fsf@gitster-ct.c.googlers.com","threadId":"47765","inReplyTo":"212094a6-f1bd-c4cd-01f9-e819a701cfac@web.de","subject":"Re: [PATCH 003/194] object-store: move packed_git and packed_git_mru to object store","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-02-12T21:48:29Z","receivedAt":"2018-02-12T21:48:37Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"René Scharfe <l.s.r@web.de> writes:\n\n> Am 12.02.2018 um 22:04 schrieb Junio C Hamano:\n>> Stefan Beller <sbeller@google.com> writes:\n>> \n>>> I thought it may be a helpful\n>>> for merging this series with the rest of the evolved code base which\n>>> may make use of one of the converted functions. So instead of fixing\n>>> that new instance manually, cocinelle could do that instead.\n>> \n>> Having the .cocci used for the conversion *somewhere* would indeed\n>> be helpful, as it allows me to (1) try reproducing this patch by\n>> somebody else using the file and following the steps in order to\n>> audit this patch and (2) catch new places that need to be migrated\n>> in in-flight topics.\n>> \n>> But placing it in contrib/coccinelle/ has other side effects.\n>\n> Running \"make coccicheck\" takes longer.  What other downsides are\n> there?\n\nOnce the global variable packed_git has been migrated out of\nexistence, no new code that relies on it would be referring to that\nglobal variable.  If coccicheck finds something, the suggested rewrite \nwould be turning an unrelated packed_git (which may not even be the\nright type) to a reference to a field in a global variable, that\nwould certainly be wrong.\n"},{"id":"339220","messageId":"8b8f6e8c-9077-793b-81d7-8769eee31e66@web.de","threadId":"47765","inReplyTo":"xmqqbmgtswuq.fsf@gitster-ct.c.googlers.com","subject":"Re: [PATCH 003/194] object-store: move packed_git and packed_git_mru to object store","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2018-02-13T18:52:33Z","receivedAt":"2018-02-13T18:52:50Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Am 12.02.2018 um 22:48 schrieb Junio C Hamano:\n> René Scharfe <l.s.r@web.de> writes:\n> \n>> Am 12.02.2018 um 22:04 schrieb Junio C Hamano:\n>>> Stefan Beller <sbeller@google.com> writes:\n>>>\n>>>> I thought it may be a helpful\n>>>> for merging this series with the rest of the evolved code base which\n>>>> may make use of one of the converted functions. So instead of fixing\n>>>> that new instance manually, cocinelle could do that instead.\n>>>\n>>> Having the .cocci used for the conversion *somewhere* would indeed\n>>> be helpful, as it allows me to (1) try reproducing this patch by\n>>> somebody else using the file and following the steps in order to\n>>> audit this patch and (2) catch new places that need to be migrated\n>>> in in-flight topics.\n>>>\n>>> But placing it in contrib/coccinelle/ has other side effects.\n>>\n>> Running \"make coccicheck\" takes longer.  What other downsides are\n>> there?\n> \n> Once the global variable packed_git has been migrated out of\n> existence, no new code that relies on it would be referring to that\n> global variable.  If coccicheck finds something, the suggested rewrite\n> would be turning an unrelated packed_git (which may not even be the\n> right type) to a reference to a field in a global variable, that\n> would certainly be wrong.\n\nUgh, yes.  The semantic patch in question doesn't contain any type\ninformation.  I don't know how to match a variable by name *and* type.\nHere's the closest I can come up with to a safe and complete\ntransformation, but it only handles assignments:\n\n\t@@\n\tstruct packed_git *A;\n\tidentifier B = packed_git;\n\t@@\n\t- A = B\n\t+ A = the_repository->objects.packed_git\n\nSeeing the many for loops, I'm tempted to suggest adding a\nfor_each_packed_git macro to hide the global variable and thus reduce\nthe number of places to change at cutover.  Coccinelle doesn't seem\nto like them, though.\n\nA short semantic patch with a limited time of usefulness and possible\nside-effects can easily be included in a commit message, of course..\n\nRené\n"},{"id":"339227","messageId":"CAGZ79kYCwvs82xyWoxhVD-am0j8NE-6X3rQ=SbiZd1r_3_q4Qw@mail.gmail.com","threadId":"47765","inReplyTo":"8b8f6e8c-9077-793b-81d7-8769eee31e66@web.de","subject":"Re: [PATCH 003/194] object-store: move packed_git and packed_git_mru to object store","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-13T19:45:20Z","receivedAt":"2018-02-13T19:45:26Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Tue, Feb 13, 2018 at 10:52 AM, René Scharfe <l.s.r@web.de> wrote:\n> Am 12.02.2018 um 22:48 schrieb Junio C Hamano:\n>> René Scharfe <l.s.r@web.de> writes:\n>>\n>>> Am 12.02.2018 um 22:04 schrieb Junio C Hamano:\n>>>> Stefan Beller <sbeller@google.com> writes:\n>>>>\n>>>>> I thought it may be a helpful\n>>>>> for merging this series with the rest of the evolved code base which\n>>>>> may make use of one of the converted functions. So instead of fixing\n>>>>> that new instance manually, cocinelle could do that instead.\n>>>>\n>>>> Having the .cocci used for the conversion *somewhere* would indeed\n>>>> be helpful, as it allows me to (1) try reproducing this patch by\n>>>> somebody else using the file and following the steps in order to\n>>>> audit this patch and (2) catch new places that need to be migrated\n>>>> in in-flight topics.\n>>>>\n>>>> But placing it in contrib/coccinelle/ has other side effects.\n>>>\n>>> Running \"make coccicheck\" takes longer.  What other downsides are\n>>> there?\n>>\n>> Once the global variable packed_git has been migrated out of\n>> existence, no new code that relies on it would be referring to that\n>> global variable.  If coccicheck finds something, the suggested rewrite\n>> would be turning an unrelated packed_git (which may not even be the\n>> right type) to a reference to a field in a global variable, that\n>> would certainly be wrong.\n>\n> Ugh, yes.  The semantic patch in question doesn't contain any type\n> information.  I don't know how to match a variable by name *and* type.\n> Here's the closest I can come up with to a safe and complete\n> transformation, but it only handles assignments:\n>\n>         @@\n>         struct packed_git *A;\n>         identifier B = packed_git;\n>         @@\n>         - A = B\n>         + A = the_repository->objects.packed_git\n>\n\nI'll need to play more with coccinelle. :) Thanks for this patch.\n\n> Seeing the many for loops, I'm tempted to suggest adding a\n> for_each_packed_git macro to hide the global variable and thus reduce\n> the number of places to change at cutover.  Coccinelle doesn't seem\n> to like them, though.\n>\n> A short semantic patch with a limited time of usefulness and possible\n> side-effects can easily be included in a commit message, of course..\n\nIn the shorter reroll I moved the semantic patch into a subdir of\ncontrib/coccinelle, but in the next reroll I'll just put it into the\ncommit message.\n\nThanks,\nStefan\n"},{"id":"339251","messageId":"xmqqeflopdia.fsf@gitster-ct.c.googlers.com","threadId":"47765","inReplyTo":"8b8f6e8c-9077-793b-81d7-8769eee31e66@web.de","subject":"Re: [PATCH 003/194] object-store: move packed_git and packed_git_mru to object store","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-02-14T01:26:53Z","receivedAt":"2018-02-14T01:27:01Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"René Scharfe <l.s.r@web.de> writes:\n\n> A short semantic patch with a limited time of usefulness and possible\n> side-effects can easily be included in a commit message, of course..\n\nYeah, I think that is Jonathan's favourite approach as well, and I\ndo not have problem with that.  This transition spatch is unlike the\n\"avoid strbuf_addf when we do not have to use it\" one, in that there\nis a definite cut-over where the old way becomes an invalid C code\nand compilers can help us spot unconverted places (as opposed to a\nvalid but unwanted way that can come into the codebase after one\nround of code cleaning is done, which is a useful thing to catch\nwith the \"make coccicheck\" target).\n\n"}]}