Re: [PATCH 1/1] Mark messages for translations

2018-02-05 Thread Jeff King
On Tue, Feb 06, 2018 at 02:32:42AM -0500, Eric Sunshine wrote:

> > diff --git a/t/t0002-gitfile.sh b/t/t0002-gitfile.sh
> > @@ -31,7 +31,7 @@ test_expect_success 'bad setup: invalid .git file format' 
> > '
> > echo "git rev-parse accepted an invalid .git file"
> > false
> > fi &&
> > -   if ! grep "Invalid gitfile format" .err
> > +   if ! grep "invalid gitfile format" .err
> 
> Since these strings can now be translated, you'll probably need to use
> 'test_i18ngrep' rather than 'grep'. (See test_i18ngrep in
> t/test-lib.sh.)

Good catch. Looks like there's another in t1506, which you can see with
"make GETTEXT_POISON=1 test".

-Peff


Re: [PATCH 1/1] Mark messages for translations

2018-02-05 Thread Eric Sunshine
On Tue, Feb 6, 2018 at 1:15 AM, Alexander Shopov  wrote:
> Small changes in messages to fit the style and typography of rest
> Reuse already translated messages if possible
> Do not translate messages aimed at developers of git
> Fix unit tests depending on the original string
>
> Signed-off-by: Alexander Shopov 
> ---
> diff --git a/t/t0002-gitfile.sh b/t/t0002-gitfile.sh
> @@ -31,7 +31,7 @@ test_expect_success 'bad setup: invalid .git file format' '
> echo "git rev-parse accepted an invalid .git file"
> false
> fi &&
> -   if ! grep "Invalid gitfile format" .err
> +   if ! grep "invalid gitfile format" .err

Since these strings can now be translated, you'll probably need to use
'test_i18ngrep' rather than 'grep'. (See test_i18ngrep in
t/test-lib.sh.)

> then
> echo "git rev-parse returned wrong error"
> false
> @@ -45,7 +45,7 @@ test_expect_success 'bad setup: invalid .git file path' '
> echo "git rev-parse accepted an invalid .git file path"
> false
> fi &&
> -   if ! grep "Not a git repository" .err
> +   if ! grep "not a git repository" .err
> then
> echo "git rev-parse returned wrong error"
> false
> diff --git a/t/t0008-ignores.sh b/t/t0008-ignores.sh
> index d27f438bf..5743b482f 100755
> --- a/t/t0008-ignores.sh
> +++ b/t/t0008-ignores.sh
> @@ -307,7 +307,7 @@ test_expect_success_multi 'needs work tree' '' '
> cd .git &&
> test_check_ignore "foo" 128
> ) &&
> -   stderr_contains "fatal: This operation must be run in a work tree"
> +   stderr_contains "fatal: this operation must be run in a work tree"
>  '


Re: [GSoC][PATCH] commit: add a commit.signOff config variable

2018-02-05 Thread Chen Jingpiao
On 02/05 01:50, Stefan Beller wrote:
> On Sat, Feb 3, 2018 at 6:03 PM, Chen Jingpiao  wrote:
> > Add the commit.signOff configuration variable to use the -s or --signoff
> > option of git commit by default.
> >
> > Signed-off-by: Chen Jingpiao 
> > ---
> 
> Welcome to the Git community!
> 
> >
> > Though we can configure signoff using format.signOff variable. Someone like 
> > to
> > add Signed-off-by line by the committer.
> 
> There is more discussion about this at
> https://public-inbox.org/git/1482946838-28779-1-git-send-email-ehabk...@redhat.com/
> specifically
> https://public-inbox.org/git/xmqqtw9m5s5m@gitster.mtv.corp.google.com/
> 
> Not sure if there was any other reasons and discussions brought up
> since then, but that discussion seems to not favor patches that
> add .signoff options.

Thank you.

I agree with Johannes Schindelin once said "a signoff _has_ to be a conscious
act, or else  it will lose its meaning."
I think I shouldn't add this configuration variable.

When add configuration variable for sign-off to format-patch have some 
discussion:
https://public-inbox.org/git/20090331204338.ga88...@macbook.lan/

https://public-inbox.org/git/20090401102610.gc26...@coredump.intra.peff.net/
https://public-inbox.org/git/7veiw69p26@gitster.siamese.dyndns.org/

--
Chen Jingpiao


[PATCH 1/1] Mark messages for translations

2018-02-05 Thread Alexander Shopov
Small changes in messages to fit the style and typography of rest
Reuse already translated messages if possible
Do not translate messages aimed at developers of git
Fix unit tests depending on the original string

Signed-off-by: Alexander Shopov 
---
 git.c  | 38 -
 setup.c| 62 +++---
 t/t0002-gitfile.sh |  4 ++--
 t/t0008-ignores.sh |  2 +-
 4 files changed, 53 insertions(+), 53 deletions(-)

diff --git a/git.c b/git.c
index c870b9719..5ddcb75d4 100644
--- a/git.c
+++ b/git.c
@@ -5,11 +5,11 @@
 #include "run-command.h"
 
 const char git_usage_string[] =
-   "git [--version] [--help] [-C ] [-c name=value]\n"
-   "   [--exec-path[=]] [--html-path] [--man-path] 
[--info-path]\n"
-   "   [-p | --paginate | --no-pager] [--no-replace-objects] 
[--bare]\n"
-   "   [--git-dir=] [--work-tree=] 
[--namespace=]\n"
-   "[]";
+   N_("git [--version] [--help] [-C ] [-c =]\n"
+  "   [--exec-path[=]] [--html-path] [--man-path] 
[--info-path]\n"
+  "   [-p | --paginate | --no-pager] [--no-replace-objects] 
[--bare]\n"
+  "   [--git-dir=] [--work-tree=] 
[--namespace=]\n"
+  "[]");
 
 const char git_more_info_string[] =
N_("'git help -a' and 'git help -g' list available subcommands and 
some\n"
@@ -92,7 +92,7 @@ static int handle_options(const char ***argv, int *argc, int 
*envchanged)
*envchanged = 1;
} else if (!strcmp(cmd, "--git-dir")) {
if (*argc < 2) {
-   fprintf(stderr, "No directory given for 
--git-dir.\n" );
+   fprintf(stderr, _("no directory given for 
--git-dir\n" ));
usage(git_usage_string);
}
setenv(GIT_DIR_ENVIRONMENT, (*argv)[1], 1);
@@ -106,7 +106,7 @@ static int handle_options(const char ***argv, int *argc, 
int *envchanged)
*envchanged = 1;
} else if (!strcmp(cmd, "--namespace")) {
if (*argc < 2) {
-   fprintf(stderr, "No namespace given for 
--namespace.\n" );
+   fprintf(stderr, _("no namespace given for 
--namespace\n" ));
usage(git_usage_string);
}
setenv(GIT_NAMESPACE_ENVIRONMENT, (*argv)[1], 1);
@@ -120,7 +120,7 @@ static int handle_options(const char ***argv, int *argc, 
int *envchanged)
*envchanged = 1;
} else if (!strcmp(cmd, "--work-tree")) {
if (*argc < 2) {
-   fprintf(stderr, "No directory given for 
--work-tree.\n" );
+   fprintf(stderr, _("no directory given for 
--work-tree\n" ));
usage(git_usage_string);
}
setenv(GIT_WORK_TREE_ENVIRONMENT, (*argv)[1], 1);
@@ -134,7 +134,7 @@ static int handle_options(const char ***argv, int *argc, 
int *envchanged)
*envchanged = 1;
} else if (!strcmp(cmd, "--super-prefix")) {
if (*argc < 2) {
-   fprintf(stderr, "No prefix given for 
--super-prefix.\n" );
+   fprintf(stderr, _("no prefix given for 
--super-prefix\n" ));
usage(git_usage_string);
}
setenv(GIT_SUPER_PREFIX_ENVIRONMENT, (*argv)[1], 1);
@@ -156,7 +156,7 @@ static int handle_options(const char ***argv, int *argc, 
int *envchanged)
*envchanged = 1;
} else if (!strcmp(cmd, "-c")) {
if (*argc < 2) {
-   fprintf(stderr, "-c expects a configuration 
string\n" );
+   fprintf(stderr, _("-c expects a configuration 
string\n" ));
usage(git_usage_string);
}
git_config_push_parameter((*argv)[1]);
@@ -194,12 +194,12 @@ static int handle_options(const char ***argv, int *argc, 
int *envchanged)
*envchanged = 1;
} else if (!strcmp(cmd, "-C")) {
if (*argc < 2) {
-   fprintf(stderr, "No directory given for -C.\n" 
);
+   fprintf(stderr, _("no directory given for -C\n" 
));
usage(git_usage_string);
}
if ((*argv)[1][0]) {
if (chdir((*argv)[1]))
-   

[PATCH 0/1] Mark messages for translations

2018-02-05 Thread Alexander Shopov
*** BLURB HERE ***
Hi all,

Again I am marking messages for translations in gui.c and setup.c based
on the feedback I got last time. Now I am fixing unit tests as well,
hopefully no regressions.

Here is a recap:

Johannes Sixt:
  1. Lower-case letters at the beginning of error messages
  2. Past tense to present tense in some cases
Eric Sunshine:
  3. Fix `-cname=value` to say `-c =`
  4. Do not translate "BUG message"
Duy Nguyen:
  5. Fix parentheses on `_` macro

Kind regards:
al_shopov


Alexander Shopov (1):
  Mark messages for translations

 git.c  | 38 -
 setup.c| 62 +++---
 t/t0002-gitfile.sh |  4 ++--
 t/t0008-ignores.sh |  2 +-
 4 files changed, 53 insertions(+), 53 deletions(-)

-- 
2.16.1



Re: [PATCH v2 01/41] parse-options: support --git-completion-helper

2018-02-05 Thread Eric Sunshine
On Mon, Feb 5, 2018 at 4:56 AM, Duy Nguyen  wrote:
> On Thu, Feb 01, 2018 at 02:16:46PM -0500, Eric Sunshine wrote:
>> On Thu, Feb 1, 2018 at 5:21 AM, Duy Nguyen  wrote:
>> > On Thu, Feb 1, 2018 at 4:54 PM, Eric Sunshine  
>> > wrote:
>> >> I don't see that as convincing argument for two classes of "no
>> >> complete". Since git-completion.bash already special-cases
>> >> rebase/am/cherry-pick for --continue|--abort|--skip, it is not far
>> >> fetched that that special-case treatment can be extended slightly to
>> >> also filter out those three options from the list returned by
>> >> --git-completion-helper.
>> >
>> > I agree that is possible, but it's a bit tricky to do the filtering
>> > right in bash (all options are sent back as one line instead of one
>> > per line, which is easier to process by command line tools).
>>
>> Perhaps I'm missing something, but wouldn't filtering out those
>> options directly in Bash require only this?
>>
>> % x='--foo --bar --snoo'
>> % echo ${x/--bar}
>> --foo --snoo
>
> OK how about some thing like this fixup patch? __gitcomp_builtin now
> allows to add extra options as well as remove some.
>
> -- 8< --
>  __gitcomp_builtin ()
>  {
> +   local incl="$2"
> +   local excl="$3"
> +   options="$(__git ${cmd/_/ } --git-completion-helper) $incl "
> +   for i in $excl; do
> +   options="${options/$i /}"

Is 'options' guaranteed to end with a space? If not, then this
expulsion will fail for the very last option. I'd think you can get by
fine with just "${options/$i}".


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

2018-02-05 Thread Eric Sunshine
On Mon, Feb 5, 2018 at 6:55 PM, Stefan Beller  wrote:
> This should make these functions easier to find and object-store.h
> less overwhelming to read.

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

> Signed-off-by: Stefan Beller 
> Signed-off-by: Jonathan Nieder 
> ---
>  cache.h | 52 --
>  object-store.h  | 16 +--


Re: [RFH/PATCH] blame: tighten command line parser

2018-02-05 Thread Eric Sunshine
On Mon, Feb 5, 2018 at 6:37 PM, Junio C Hamano  wrote:
> The command line parser of "git blame" is prepared to take an
> ancient odd argument order "blame  " in addition to the
> usual "blame [] ".  It has at least two negative
> ramifications:
>
>  - In order to tell these two apart, it checks if the last command
>line argument names a path in the working tree, using
>file_exists().  However, "blame  " is a request to
>explalin each and every line in the contents of  stored in

s/explalin/explain/

>revision  and does not need to have a working tree version
>of the file.  A check with file_exists() is simply wrong.
>
>  - To coerce that mistaken file_exists() check to work, the code
>calls setup_work_tree() before doing so, because the path it has
>is relative to the top-level of the project tree.  However,
>"blame  " MUST be usable even in a bare repository,
>and there is no reason for letting setup_work_tree() to complain

s/to complain/complain/

>and die with "This operation must be run in a work tree".
>
> To correct the former, switch to check if the last token is a
> revision (and if so, parse arguments using "blame  "
> rule).  Correct the latter by getting rid of setup_work_tree() and
> file_exists() check--the only case the call to this function matters
> is when we are running "blame " (i.e. no starting revision and
> asking to blame the working tree file at , digging through the
> HEAD revision), but there is a call in setup_scoreboard() just
> before it calls fake_working_tree_commit().
>
> Also attempt to give a bit more sensible error message when "blame
> XYZ" is given and XYZ cannot be a path.
>
>side note: I am not happy with the "only one arg, which is a rev,
>given in a bare repository" condition to give the new error
>message, but this should be a good starting point.
>
> Signed-off-by: Junio C Hamano 


Re: [GSoC][PATCH v2] commit: add a commit.signOff config variable

2018-02-05 Thread Chen Jingpiao
On 02/05 11:22, Junio C Hamano wrote:
> Chen Jingpiao  writes:
> 
> > Add the commit.signOff configuration variable to use the -s or --signoff
> > option of git commit by default.
> 
> This is a rather old topic.  Here is one from 2006:
> 
> 
> https://public-inbox.org/git/pine.lnx.4.63.0611281426311.30...@wbgn013.biozentrum.uni-wuerzburg.de/
> 
> which was referred to in another discussion in late 2008:
> 
> https://public-inbox.org/git/20081227070228.6...@nanako3.lavabit.com/
> https://public-inbox.org/git/7vabaijvxl@gitster.siamese.dyndns.org/
> 
> I am not sure if the reasons why the last effort was retracted still
> apply to this round (the world certainly has changed in the past 10
> years); it would be good to explain why this time it is different
> ;-).
> 
> Assuming that the new configuration variable is a desirable thing to
> add, the change to the code looks OK.  Documentation updates may
> need more thought in the light of past discussions, though.
> 
> Thanks.

I agree with Johannes Schindelin once said "a signoff _has_ to be a
conscious act, or else  it will lose its meaning."
I think I shouldn't add this configuration variable. Thank you.

--
Chen Jingpiao


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

2018-02-05 Thread Eric Sunshine
On Mon, Feb 5, 2018 at 6:55 PM, Stefan Beller  wrote:
> In ecef23 (inline lookup_replace_object() calls, 2011-05-15) a shortcut
> for checking the object replacement was added by setting check_replace_refs
> to 0 once the replacements were evaluated to not exist. This works fine in
> with the assumption of only one repository in existence.
>
> The assumption won't hold true any more when we work on multiple instances
> of a repository structs (e.g. one struct per submodule), as the first
> repository to be inspected may have no replacements and would set the
> global variable. Other repositories would then completely omit their
> evaluation of replacements.
>
> This reverts back the meaning of the flag `check_replace_refs` of
> "Do we need to check with the lookup table?" to "Do we need read the

s/need read/need to read/

> replacement definition?", adding the bypassing logic to
> lookup_replace_object after the replacement definition was read.
> As with the original patch, delay the renaming of the global variable
>
> Signed-off-by: Stefan Beller 


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

2018-02-05 Thread Eric Sunshine
On Mon, Feb 5, 2018 at 6:55 PM, Stefan Beller  wrote:
> diff --git a/refs.c b/refs.c
> @@ -1609,9 +1609,6 @@ static struct ref_store_hash_entry 
> *alloc_ref_store_hash_entry(
> -/* A pointer to the ref_store for the main repository: */
> -static struct ref_store *main_ref_store;
> diff --git a/repository.h b/repository.h
> @@ -33,6 +33,11 @@ struct repository {
>  */
> struct object_store objects;
>
> +   /*
> +* The store in which the refs are hold.
> +*/
> +   struct ref_store *main_ref_store;

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


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

2018-02-05 Thread Eric Sunshine
On Mon, Feb 5, 2018 at 6:55 PM, Stefan Beller  wrote:
> Both fetch and push still use alternates to access submodules in some
> other code paths, but this is progress towards eliminating the alternates
> hack that conflates access to the_repository and other repositories.
>
> Signed-off-by: Jonathan Nieder 
> Signed-off-by: Stefan Beller 
> ---
> diff --git a/submodule.c b/submodule.c
> @@ -832,24 +833,43 @@ static int check_has_commit(const struct object_id 
> *oid, void *data)
> +static int open_submodule(struct repository *out, const char *path)
> +{
> +   struct strbuf sb = STRBUF_INIT;
> +
> +   if (submodule_to_gitdir(, path))
> +   return -1;

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

> +
> +   if (repo_init(out, sb.buf, NULL)) {
> +   strbuf_release();
> +   return -1;
> +   }

Or just combine these two error cases:

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

> +   out->submodule_prefix = xstrdup(path);
> +
> +   strbuf_release();
> +   return 0;
> +}


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

2018-02-05 Thread Eric Sunshine
On Mon, Feb 5, 2018 at 6:55 PM, Stefan Beller  wrote:
> Grafts are only meaningful in the context of a single repository.
> Therefore they cannot be global.
>
> Signed-off-by: Stefan Beller 
> Signed-off-by: Jonathan Nieder 
> ---
> diff --git a/commit.c b/commit.c
> @@ -121,20 +120,22 @@ int register_commit_graft(struct commit_graft *graft, 
> int ignore_dups)
> if (ignore_dups)
> free(graft);
> else {
> -   free(commit_graft[pos]);
> -   commit_graft[pos] = graft;
> +   free(the_repository->parsed_objects.grafts[pos]);
> +   the_repository->parsed_objects.grafts[pos] = graft;
> diff --git a/object.h b/object.h
> @@ -4,9 +4,13 @@
>  struct object_parser {
> struct object **obj_hash;
> int nr_objs, obj_hash_size;
> +
> +   /* parent substitutions from .git/info/grafts and .git/shallow */
> +   struct commit_graft **grafts;
> +   int grafts_alloc, grafts_nr;
>  };

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


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

2018-02-05 Thread Eric Sunshine
On Mon, Feb 5, 2018 at 7:16 PM, Stefan Beller  wrote:
> We have to convert them all at once, because alloc_report uses funky a

s/funky a/a funky/

> macro for reporting. It is better for the sake of mechanical conversion
> to convert multiple functions at once rather than changing the structure
> of the reporting function.
>
> Signed-off-by: Stefan Beller 


Re: [RFC PATCH 000/194] Moving global state into the repository object

2018-02-05 Thread brian m. carlson
On Mon, Feb 05, 2018 at 03:51:54PM -0800, Stefan Beller wrote:
> This series moves a lot of global state into the repository struct.
> It applies on top of 2512f15446149235156528dafbe75930c712b29e (2.16.0)
> It can be found at https://github.com/stefanbeller/git/tree/object-store
> 
> Motivation for this series:
> * Easier to reason about code when all state is stored in one place,
>   for example for multithreading
> * Easier to move to processing submodules in-process instead of
>   calling a processes for the submodule handling.
>   The last patch demonstrates this.

Of course, I like performance improvements (who doesn't?), but I really
like the way this series gets rid of various global variables.  I much
prefer to have fewer globals when possible.

> This is why this series tries to be reviewer friendly by utilizing
> machine assistance as much as possible. There are 3 types of patches
> in this series:
> 
> (A) : add repository argument to 
>   This sort of patch is just adding the repository as an argument to that
>   function. It assumes the given repository is `the_repository` and has
>   a compile time check for that assertion using a preprocessor trick.
>   As did a compile check after each commit of the series, I don't expect
>   the review burden on these patches to be high. Review on these patches
>   is mostly checking for formatting errors or if I sneak in malicious
>   code -- if you're inclined to believe that.
> 
> (B) : allow  to handle arbitrary repositories
>   This sort of patch is touching code inside the given function only,
>   usually replacing all occurrences of `the_repository` by the argument
>   `r`. Here the review is critical: Did I miss any function that relies
>   on state of `the_repository` ?
>   This series was developed by converting all functions of
>   packfile/sha1-file/commit/etc using (A); after the demo patch
>   was possible, all patches that did (A), but not (B) were deleted.
>   Therefore I was confident at time of writing that patch that
>   the conversion of a function which doesn't take a repository argument
>   is okay.
> 
> (C) other patches, such as moving code around,
> demoing this series in the last patch
> 
> This approach was chosen as I think it is review friendly, despite the
> huge number of patches.

I very much appreciate this approach.  It made reviewing things much
nicer.

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

That's my concern as well.  This necessarily conflicts with some of the
object_id and the_hash_algo work, but rebasing work on top of it
shouldn't be too awful once it's ready to be picked up.  In fact, long
term, it makes that work easier, so I'm all for it.

I'm sure Junio will have thoughts on the size of the series and
potential conflicts in flight, but I'll let him articulate those.  The
series could in theory be split into pieces the way you've done it: it
would just be less convenient to work with some of the functions in the
mean time.
-- 
brian m. carlson / brian with sandals: Houston, Texas, US
https://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: https://keybase.io/bk2204


signature.asc
Description: PGP signature


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

2018-02-05 Thread brian m. carlson
On Mon, Feb 05, 2018 at 03:55:37PM -0800, Stefan Beller wrote:
> The ref subsystem has not been migrated yet to access the object store
> via passed in repository objects. As a result replace when the object store
> tries to access replace refs in a repository other than the_repository
> it produces errors:
> 
>   error: refs/replace/3afabef75c627b8943bcae86837abc7c32fe does not point 
> to a valid object!
> 
> Add a test demonstrating this failure.
> 
> Signed-off-by: Jonathan Nieder 
> Signed-off-by: Stefan Beller 
> 
> squash! push: add test showing bad interaction of replace refs and submodules
> 
> replace-objects: evaluate replacement refs without using the object store
> 
> Pass DO_FOR_EACH_INCLUDE_BROKEN when iterating over replacement refs
> so that the iteration does not require opening the named objects from
> the object store. This avoids a dependency cycle between object access
> and replace ref iteration.
> 
> Moreover the ref subsystem has not been migrated yet to access the object
> store via passed in repository objects.  As a result, without this patch
> when the object store tries to access replace refs in a repository other
> than the_repository it produces errors:
> 
>error: refs/replace/3afabef75c627b8943bcae86837abc7c32fe does not 
> point to a valid object!
> 
> Signed-off-by: Jonathan Nieder 
> Signed-off-by: Stefan Beller 

It appears you have multiple independent commit messages here.
-- 
brian m. carlson / brian with sandals: Houston, Texas, US
https://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: https://keybase.io/bk2204


signature.asc
Description: PGP signature


Re: [PATCH 3/7] worktree move: new command

2018-02-05 Thread Jeff King
On Mon, Feb 05, 2018 at 08:28:10PM +0700, Duy Nguyen wrote:

> >> This is still leaking 'worktrees'[1]. You probably want
> >> free_worktrees() immediately after the find_worktree() invocation.
> >
> > Sorry, free_worktrees() after the last use of 'wt' since you still
> > need to access its fields, which would be the end of the function.
> 
> I learned SANITIZE=leak today! It not only catches this but also "dst".
> 
> Jeff is there any ongoing effort to make the test suite pass with
> SANITIZE=leak? My t2038 passed, so I went ahead with the full test
> suite and saw so many failures. I did see in your original mails that
> you focused on t and t0001 only..

Yeah, I did those two scripts to try to prove to myself that the
approach was good. But I haven't really pushed it any further.

Martin Ågren (cc'd) did some follow-up work, but I think we still have a
long way to go. My hope is that people who are interested in
leak-checking their new code can run some specific script they're
interested in, and maybe fix up one or two nearby bits while they're
there (either by fixing a leak, or just annotating via UNLEAK). Then we
can slowly converge on correctness. :)

-Peff


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

2018-02-05 Thread brian m. carlson
On Mon, Feb 05, 2018 at 03:55:26PM -0800, Stefan Beller wrote:
> Add a repository argument to allow the callers of sha1_object_info
> to be more specific about which repository to handle. This is a small
> mechanical change; it doesn't change the implementation to handle
> repositories other than the_repository yet.
> 
> As with the previous commits, use a macro to catch callers passing a
> repository other than the_repository at compile time.
> 
> In the expanded macro the identifier `the_repository` is not actually used,
> so the compiler does not catch if the repository.h header is not included
> at the call site. call sites needing that #include were identified by

"Call sites" (capital at the beginning of the sentence).
-- 
brian m. carlson / brian with sandals: Houston, Texas, US
https://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: https://keybase.io/bk2204


signature.asc
Description: PGP signature


Re: [PATCH v1] dir.c: don't flag the index as dirty for changes to the untracked cache

2018-02-05 Thread Ben Peart



On 2/5/2018 4:58 PM, Brandon Williams wrote:

On 02/05, Ben Peart wrote:

The untracked cache saves its current state in the UNTR index extension.
Currently, _any_ change to that state causes the index to be flagged as dirty
and written out to disk.  Unfortunately, the cost to write out the index can
exceed the savings gained by using the untracked cache.  Since it is a cache
that can be updated from the current state of the working directory, there is
no functional requirement that the index be written out for every change to the
untracked cache.

Update the untracked cache logic so that it no longer forces the index to be
written to disk except in the case where the extension is being turned on or
off.  When some other git command requires the index to be written to disk, the
untracked cache will take advantage of that to save it's updated state as well.
This results in a performance win when looked at over common sequences of git
commands (ie such as a status followed by add, commit, etc).

After this patch, all the logic to track statistics for the untracked cache
could be removed as it is only used by debug tracing used to debug the untracked
cache.


So we don't need to update it every time because its just a cache
and if its inaccurate between status calls that's ok?  So only
operations like add and commit will actually write out the untracked
cache (as a part of writing out the index).  Sounds ok.

What benefit is there to using the untracked cache then?  Sounds like
you should just turn it off instead?
(I'm sure this is a naive question :D )


The parts of the untracked cache that have not changed since the 
extension was updated are still cached and valid.  Only those 
directories that have changes will need to be checked.


With the old behavior, making a change in dir1/, then calling status 
would update the dir1/ untracked cache entry, flag the index as dirty 
and write it out.  On the next status, git would detect that no changes 
have been made and use the cached data for dir1/.


With the new behavior, making a change in dir1/, then calling status 
would update the dir1/ untracked cache entry but not write it out. On 
the next status, git would detect the change in dir1/ again and update 
the untracked cache.  All of the other cached entries are still valid 
and the cache would be used for them.  The updated cache entry for dir1/ 
would not get persisted to disk until something that required the index 
to be written out.


The behavior is correct in both cases.  You just don't get the benefit 
of the updated cache for the dir1/ entry until the index is persisted 
again.  What you gain in exchange is that you don't have to write out 
the index which is (typically) a lot more expensive than checking dir1/ 
for changes.






Signed-off-by: Ben Peart 
---

Notes:
 Base Ref: master
 Web-Diff: https://github.com/benpeart/git/commit/20c2e8d787
 Checkout: git fetch https://github.com/benpeart/git untracked-cache-v1 && 
git checkout 20c2e8d787

  dir.c | 3 ++-
  t/t7063-status-untracked-cache.sh | 3 +++
  2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/dir.c b/dir.c
index 7c4b45e30e..da93374f0c 100644
--- a/dir.c
+++ b/dir.c
@@ -2297,7 +2297,8 @@ int read_directory(struct dir_struct *dir, struct 
index_state *istate,
 dir->untracked->gitignore_invalidated,
 dir->untracked->dir_invalidated,
 dir->untracked->dir_opened);
-   if (dir->untracked == istate->untracked &&
+   if (getenv("GIT_TEST_UNTRACKED_CACHE") &&
+   dir->untracked == istate->untracked &&
(dir->untracked->dir_opened ||
 dir->untracked->gitignore_invalidated ||
 dir->untracked->dir_invalidated))
diff --git a/t/t7063-status-untracked-cache.sh 
b/t/t7063-status-untracked-cache.sh
index e5fb892f95..6ef520e823 100755
--- a/t/t7063-status-untracked-cache.sh
+++ b/t/t7063-status-untracked-cache.sh
@@ -14,6 +14,9 @@ test_description='test untracked cache'
  # See <20160803174522.5571-1-pclo...@gmail.com> if you want to know
  # more.
  
+GIT_TEST_UNTRACKED_CACHE=true

+export GIT_TEST_UNTRACKED_CACHE
+
  sync_mtime () {
find . -type d -ls >/dev/null
  }

base-commit: 5be1f00a9a701532232f57958efab4be8c959a29
--
2.15.0.windows.1





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

2018-02-05 Thread brian m. carlson
On Mon, Feb 05, 2018 at 03:55:03PM -0800, Stefan Beller wrote:
> From: Jonathan Nieder 
> 
> This should make these functions easier to find and object-store.h
> less overwhelming to read.
> 
> Signed-off-by: Stefan Beller 
> Signed-off-by: Jonathan Nieder 
> ---
>  alternates.h| 68 
> +
>  builtin/clone.c |  1 +
>  builtin/count-objects.c |  1 +
>  builtin/fsck.c  |  3 +-
>  builtin/grep.c  |  1 +
>  builtin/submodule--helper.c |  1 +
>  cache.h | 52 --
>  object-store.h  | 16 +--
>  packfile.c  |  3 +-
>  sha1_file.c | 23 +++
>  sha1_name.c |  3 +-
>  submodule.c |  1 +
>  t/helper/test-ref-store.c   |  1 +
>  tmp-objdir.c|  1 +
>  transport.c |  1 +
>  15 files changed, 102 insertions(+), 74 deletions(-)
>  create mode 100644 alternates.h
> 
> diff --git a/alternates.h b/alternates.h
> new file mode 100644
> index 00..df5dc67e2e
> --- /dev/null
> +++ b/alternates.h
> @@ -0,0 +1,68 @@
> +#ifndef ALTERNATES_H
> +#define ALTERNATES_H
> +
> +#include "strbuf.h"
> +#include "sha1-array.h"
> +
> +struct alternates {
> + struct alternate_object_database *list;
> + struct alternate_object_database **tail;
> +};
> +#define ALTERNATES_INIT { NULL, NULL }

I was surprised to find that this patch not only moves the alternates
API to a new location, but introduces this struct.  I certainly think
the struct is a good idea, but it should probably go in a separate
patch, or at least get a mention in the commit message.
-- 
brian m. carlson / brian with sandals: Houston, Texas, US
https://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: https://keybase.io/bk2204


signature.asc
Description: PGP signature


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

2018-02-05 Thread brian m. carlson
On Mon, Feb 05, 2018 at 03:54:46PM -0800, Stefan Beller wrote:
> @@ -434,12 +433,12 @@ static int link_alt_odb_entry_the_repository(const char 
> *entry,
>   ent = alloc_alt_odb(pathbuf.buf);
>  
>   /* add the alternate entry */
> - *the_repository->objects.alt_odb_tail = ent;
> - the_repository->objects.alt_odb_tail = &(ent->next);
> + *r->objects.alt_odb_tail = ent;
> + r->objects.alt_odb_tail = &(ent->next);
>   ent->next = NULL;

I'm sure I'm missing something obvious, but it's not clear to me that
this transformation is correct.  Could you perhaps say a few words about
why it is?
-- 
brian m. carlson / brian with sandals: Houston, Texas, US
https://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: https://keybase.io/bk2204


signature.asc
Description: PGP signature


Re: [RFC PATCH 000/194] Moving global state into the repository object

2018-02-05 Thread Stefan Beller
On Mon, Feb 5, 2018 at 3:51 PM, Stefan Beller  wrote:

>
> Any suggestions welcome!
>

I wouldn't say sending out this many patches is a smooth experience:

* After trying it out internally, it stopped at patch ~80 and the rate
limiter kicked in.
* Okay fine, I'll rate limit myself to be able to send out as many patches!
* Apparently I did not understand the docs correctly, and after reading the code
  a patch was made:
  https://public-inbox.org/git/20180206000743.217503-1-sbel...@google.com/
  I think the sensible thing would be to error out instead of ignoring the
  relogin parameter.
  This is why patches 21/22 ff. have a weird in-reply-to setup, as I hit CTRL-C
  to stop the unlimited sending and picked up from there using the rate limited
  --relogin-delay=25 --batch-size=3
* You'll notice that at patches 99/100 ff the same weird in-reply-to appeared.
  One patch has had a missing '>' in the signoff, such that the server refused
  to cc appropriately ("Stefan" not a valid recipient)
  It would be nice if we could check for that before even sending out emails,
  but I could live with this blamed on the user. (It was my mistake)
* Patch 118 just bounced. "Message rejected."
  It is found at
https://github.com/stefanbeller/git/commit/141ba1f82c223636728a476f9acc1229f353a381

Stefan


Re: Missing git options

2018-02-05 Thread brian m. carlson
On Mon, Feb 05, 2018 at 10:12:05AM +0100, Martin Häcker wrote:
> Hi there,
> 
> I just recently learned that not all command line switches seem to 
> automatically correlate to options in the git configuration.
> 
> This seems something that should be relatively easy to fix.
> 
> What I’m most missing is
> 
> — snip —
> [log]
>   graph = true
>   patch = true
> — snap —
> 
> which would / should correspond to `git log —graph —patch`.
> 
> What do you guys think?

I think this is likely to cause problems.  Many people use git log with
--pretty to format commit hashes or messages into other programs.  I'm
aware of multiple tools that will simply break if --graph or --patch
become the default.  Requiring people to retrofit their tools to use
--no-graph or --no-patch is likely to be a burden.
-- 
brian m. carlson / brian with sandals: Houston, Texas, US
https://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: https://keybase.io/bk2204


signature.asc
Description: PGP signature


Re: [PATCH v2 00/12] object_id part 11 (the_hash_algo)

2018-02-05 Thread brian m. carlson
On Fri, Feb 02, 2018 at 11:46:03AM -0800, Junio C Hamano wrote:
> Thanks for working on this.  All changes looked sensible (even
> though I spotted one nit in the original, which was moved as-is,
> which does not count as a "change" ;-)).

I forgot to ask: do you want a reroll which fixes this, or just a
follow-up patch on top to fix the comment?
-- 
brian m. carlson / brian with sandals: Houston, Texas, US
https://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: https://keybase.io/bk2204


signature.asc
Description: PGP signature


[PATCH 194/194] submodule: use submodule repos for object lookup

2018-02-05 Thread Stefan Beller
This converts the 'show_submodule_header' function to use
the repository API properly, such that the submodule objects
are not added to the main object store.

When using the inline diff of submodules, the object store is not
polluted with objects from the submodules. When using the "log"
summary, we still have to pollute the object store, as the
revision walking is not converted yet.

Signed-off-by: Stefan Beller 
---
 submodule.c | 25 ++---
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/submodule.c b/submodule.c
index 6b6c5a6710..9bd337ce99 100644
--- a/submodule.c
+++ b/submodule.c
@@ -441,19 +441,19 @@ static int prepare_submodule_summary(struct rev_info 
*rev, const char *path,
return prepare_revision_walk(rev);
 }
 
-#define print_submodule_summary(r, rev, o) print_submodule_summary_##r(rev, o)
-static void print_submodule_summary_the_repository(struct rev_info *rev, 
struct diff_options *o)
+static void print_submodule_summary(struct repository *r, struct rev_info 
*rev, struct diff_options *o)
 {
static const char format[] = "  %m %s";
struct strbuf sb = STRBUF_INIT;
struct commit *commit;
 
+   /* NEEDSWORK: get_revision is not adapted to repository handling? */
while ((commit = get_revision(rev))) {
struct pretty_print_context ctx = {0};
ctx.date_mode = rev->date_mode;
ctx.output_encoding = get_log_output_encoding();
strbuf_setlen(, 0);
-   format_commit_message(the_repository, commit, format, ,
+   format_commit_message(r, commit, format, ,
  );
strbuf_addch(, '\n');
if (commit->object.flags & SYMMETRIC_LEFT)
@@ -513,7 +513,8 @@ static int open_submodule(struct repository *out, const 
char *path)
  * attempt to lookup both the left and right commits and put them into the
  * left and right pointers.
  */
-static void show_submodule_header(struct diff_options *o, const char *path,
+static void show_submodule_header(struct diff_options *o, struct repository 
*sub,
+   const char *path,
struct object_id *one, struct object_id *two,
unsigned dirty_submodule,
struct commit **left, struct commit **right,
@@ -534,7 +535,7 @@ static void show_submodule_header(struct diff_options *o, 
const char *path,
else if (is_null_oid(two))
message = "(submodule deleted)";
 
-   if (add_submodule_odb(path)) {
+   if (open_submodule(sub, path) < 0) {
if (!message)
message = "(commits not present)";
goto output_header;
@@ -544,8 +545,8 @@ static void show_submodule_header(struct diff_options *o, 
const char *path,
 * Attempt to lookup the commit references, and determine if this is
 * a fast forward or fast backwards update.
 */
-   *left = lookup_commit_reference(the_repository, one);
-   *right = lookup_commit_reference(the_repository, two);
+   *left = lookup_commit_reference(sub, one);
+   *right = lookup_commit_reference(sub, two);
 
/*
 * Warn about missing commits in the submodule project, but only if
@@ -555,7 +556,7 @@ static void show_submodule_header(struct diff_options *o, 
const char *path,
 (!is_null_oid(two) && !*right))
message = "(commits not present)";
 
-   *merge_bases = get_merge_bases(the_repository, *left, *right);
+   *merge_bases = get_merge_bases(sub, *left, *right);
if (*merge_bases) {
if ((*merge_bases)->item == *left)
fast_forward = 1;
@@ -589,8 +590,9 @@ void show_submodule_summary(struct diff_options *o, const 
char *path,
struct rev_info rev;
struct commit *left = NULL, *right = NULL;
struct commit_list *merge_bases = NULL;
+   struct repository sub;
 
-   show_submodule_header(o, path, one, two, dirty_submodule,
+   show_submodule_header(o, , path, one, two, dirty_submodule,
  , , _bases);
 
/*
@@ -607,7 +609,7 @@ void show_submodule_summary(struct diff_options *o, const 
char *path,
goto out;
}
 
-   print_submodule_summary(the_repository, , o);
+   print_submodule_summary(, , o);
 
 out:
if (merge_bases)
@@ -625,8 +627,9 @@ void show_submodule_inline_diff(struct diff_options *o, 
const char *path,
struct commit_list *merge_bases = NULL;
struct child_process cp = CHILD_PROCESS_INIT;
struct strbuf sb = STRBUF_INIT;
+   struct repository sub;
 
-   show_submodule_header(o, path, one, two, dirty_submodule,
+   show_submodule_header(o, , path, one, two, dirty_submodule,
  , , _bases);
 
/* We need a valid left and right commit to display a difference */
-- 

[PATCH 193/194] submodule: Reorder open_submodule function

2018-02-05 Thread Stefan Beller
In the next patch we'll need open_submodule in another function, so
move it up.

Signed-off-by: Stefan Beller 
---
 submodule.c | 54 +++---
 1 file changed, 27 insertions(+), 27 deletions(-)

diff --git a/submodule.c b/submodule.c
index 022e366940..6b6c5a6710 100644
--- a/submodule.c
+++ b/submodule.c
@@ -481,6 +481,33 @@ void prepare_submodule_repo_env(struct argv_array *out)
 DEFAULT_GIT_DIR_ENVIRONMENT);
 }
 
+/*
+ * Initialize 'out' based on the provided submodule path.
+ *
+ * Unlike repo_submodule_init, this tolerates submodules not present
+ * in .gitmodules. NEEDSWORK: The repo_submodule_init behavior is
+ * preferrable. This function exists only to preserve historical behavior.
+ *
+ * Returns 0 on success, -1 when the submodule is not present.
+ */
+static int open_submodule(struct repository *out, const char *path)
+{
+   struct strbuf sb = STRBUF_INIT;
+
+   if (submodule_to_gitdir(, path))
+   return -1;
+
+   if (repo_init(out, sb.buf, NULL)) {
+   strbuf_release();
+   return -1;
+   }
+
+   out->submodule_prefix = xstrdup(path);
+
+   strbuf_release();
+   return 0;
+}
+
 /* Helper function to display the submodule header line prior to the full
  * summary output. If it can locate the submodule objects directory it will
  * attempt to lookup both the left and right commits and put them into the
@@ -839,33 +866,6 @@ static int check_has_commit(const struct object_id *oid, 
void *data)
}
 }
 
-/*
- * Initialize 'out' based on the provided submodule path.
- *
- * Unlike repo_submodule_init, this tolerates submodules not present
- * in .gitmodules. NEEDSWORK: The repo_submodule_init behavior is
- * preferrable. This function exists only to preserve historical behavior.
- *
- * Returns 0 on success, -1 when the submodule is not present.
- */
-static int open_submodule(struct repository *out, const char *path)
-{
-   struct strbuf sb = STRBUF_INIT;
-
-   if (submodule_to_gitdir(, path))
-   return -1;
-
-   if (repo_init(out, sb.buf, NULL)) {
-   strbuf_release();
-   return -1;
-   }
-
-   out->submodule_prefix = xstrdup(path);
-
-   strbuf_release();
-   return 0;
-}
-
 static int submodule_has_commits(const char *path, struct oid_array *commits)
 {
struct repository sub;
-- 
2.15.1.433.g936d1b9894.dirty



[PATCH 192/194] submodule: add repository argument to print_submodule_summary

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 submodule.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/submodule.c b/submodule.c
index 6125bfbdde..022e366940 100644
--- a/submodule.c
+++ b/submodule.c
@@ -441,7 +441,8 @@ static int prepare_submodule_summary(struct rev_info *rev, 
const char *path,
return prepare_revision_walk(rev);
 }
 
-static void print_submodule_summary(struct rev_info *rev, struct diff_options 
*o)
+#define print_submodule_summary(r, rev, o) print_submodule_summary_##r(rev, o)
+static void print_submodule_summary_the_repository(struct rev_info *rev, 
struct diff_options *o)
 {
static const char format[] = "  %m %s";
struct strbuf sb = STRBUF_INIT;
@@ -579,7 +580,7 @@ void show_submodule_summary(struct diff_options *o, const 
char *path,
goto out;
}
 
-   print_submodule_summary(, o);
+   print_submodule_summary(the_repository, , o);
 
 out:
if (merge_bases)
-- 
2.15.1.433.g936d1b9894.dirty



[PATCH 189/194] commit: allow in_merge_bases_many to handle arbitrary repositories

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 commit.c | 8 
 commit.h | 3 +--
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/commit.c b/commit.c
index 900ecf84b8..a14933b208 100644
--- a/commit.c
+++ b/commit.c
@@ -1049,18 +1049,18 @@ int is_descendant_of(struct commit *commit, struct 
commit_list *with_commit)
 /*
  * Is "commit" an ancestor of one of the "references"?
  */
-int in_merge_bases_many_the_repository(struct commit *commit, int 
nr_reference, struct commit **reference)
+int in_merge_bases_many(struct repository *r, struct commit *commit, int 
nr_reference, struct commit **reference)
 {
struct commit_list *bases;
int ret = 0, i;
 
-   if (parse_commit(the_repository, commit))
+   if (parse_commit(r, commit))
return ret;
for (i = 0; i < nr_reference; i++)
-   if (parse_commit(the_repository, reference[i]))
+   if (parse_commit(r, reference[i]))
return ret;
 
-   bases = paint_down_to_common(the_repository, commit, nr_reference, 
reference);
+   bases = paint_down_to_common(r, commit, nr_reference, reference);
if (commit->object.flags & PARENT2)
ret = 1;
clear_commit_marks(commit, all_flags);
diff --git a/commit.h b/commit.h
index 0f3cdc6375..36412a5a9e 100644
--- a/commit.h
+++ b/commit.h
@@ -234,8 +234,7 @@ extern struct trace_key trace_shallow;
 int is_descendant_of(struct commit *, struct commit_list *);
 #define in_merge_bases(r, c1, c2) in_merge_bases_##r(c1, c2)
 int in_merge_bases_the_repository(struct commit *, struct commit *);
-#define in_merge_bases_many(r, c, n, co) in_merge_bases_many_##r(c, n, co)
-int in_merge_bases_many_the_repository(struct commit *, int, struct commit **);
+int in_merge_bases_many(struct repository *r, struct commit *, int, struct 
commit **);
 
 extern int interactive_add(int argc, const char **argv, const char *prefix, 
int patch);
 extern int run_add_interactive(const char *revision, const char *patch_mode,
-- 
2.15.1.433.g936d1b9894.dirty



[PATCH 191/194] pretty: allow format_commit_message to handle arbitrary repositories

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 pretty.c | 6 +++---
 pretty.h | 4 +---
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/pretty.c b/pretty.c
index 6dce4bb3c0..ed1b778c92 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1503,7 +1503,7 @@ void userformat_find_requirements(const char *fmt, struct 
userformat_want *w)
strbuf_release();
 }
 
-void format_commit_message_the_repository(const struct commit *commit,
+void format_commit_message(struct repository *r, const struct commit *commit,
   const char *format, struct strbuf *sb,
   const struct pretty_print_context *pretty_ctx)
 {
@@ -1519,7 +1519,7 @@ void format_commit_message_the_repository(const struct 
commit *commit,
 * convert a commit message to UTF-8 first
 * as far as 'format_commit_item' assumes it in UTF-8
 */
-   context.message = logmsg_reencode(the_repository, commit,
+   context.message = logmsg_reencode(r, commit,
  _encoding,
  utf8);
 
@@ -1545,7 +1545,7 @@ void format_commit_message_the_repository(const struct 
commit *commit,
}
 
free(context.commit_encoding);
-   unuse_commit_buffer(the_repository, commit, context.message);
+   unuse_commit_buffer(r, commit, context.message);
 }
 
 static void pp_header(struct pretty_print_context *pp,
diff --git a/pretty.h b/pretty.h
index 14af7df4e8..c5fc07005f 100644
--- a/pretty.h
+++ b/pretty.h
@@ -99,9 +99,7 @@ void pp_remainder(struct pretty_print_context *pp, const char 
**msg_p,
  * Put the result to "sb".
  * Please use this function for custom formats.
  */
-#define format_commit_message(r, c, f, s, p) \
-   format_commit_message_##r(c, f, s, p)
-void format_commit_message_the_repository(const struct commit *commit,
+void format_commit_message(struct repository *r, const struct commit *commit,
const char *format, struct strbuf *sb,
const struct pretty_print_context *context);
 
-- 
2.15.1.433.g936d1b9894.dirty



[PATCH 190/194] commit: allow in_merge_bases to handle arbitrary repositories

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 commit.c | 4 ++--
 commit.h | 3 +--
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/commit.c b/commit.c
index a14933b208..cdee8d3917 100644
--- a/commit.c
+++ b/commit.c
@@ -1072,9 +1072,9 @@ int in_merge_bases_many(struct repository *r, struct 
commit *commit, int nr_refe
 /*
  * Is "commit" an ancestor of (i.e. reachable from) the "reference"?
  */
-int in_merge_bases_the_repository(struct commit *commit, struct commit 
*reference)
+int in_merge_bases(struct repository *r, struct commit *commit, struct commit 
*reference)
 {
-   return in_merge_bases_many(the_repository, commit, 1, );
+   return in_merge_bases_many(r, commit, 1, );
 }
 
 struct commit_list *reduce_heads(struct commit_list *heads)
diff --git a/commit.h b/commit.h
index 36412a5a9e..2281948738 100644
--- a/commit.h
+++ b/commit.h
@@ -232,8 +232,7 @@ extern void prune_shallow(int show_only);
 extern struct trace_key trace_shallow;
 
 int is_descendant_of(struct commit *, struct commit_list *);
-#define in_merge_bases(r, c1, c2) in_merge_bases_##r(c1, c2)
-int in_merge_bases_the_repository(struct commit *, struct commit *);
+int in_merge_bases(struct repository *r, struct commit *, struct commit *);
 int in_merge_bases_many(struct repository *r, struct commit *, int, struct 
commit **);
 
 extern int interactive_add(int argc, const char **argv, const char *prefix, 
int patch);
-- 
2.15.1.433.g936d1b9894.dirty



[PATCH 188/194] commit: add repository argument to in_merge_bases

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 builtin/branch.c   |  4 ++--
 builtin/fetch.c|  2 +-
 builtin/log.c  |  2 +-
 builtin/merge-base.c   |  2 +-
 builtin/receive-pack.c |  2 +-
 commit.c   |  4 ++--
 commit.h   |  3 ++-
 contrib/coccinelle/submodule_reading.cocci |  8 
 fast-import.c  |  2 +-
 http-push.c|  2 +-
 pack-bitmap-write.c|  2 +-
 submodule.c| 12 ++--
 12 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/builtin/branch.c b/builtin/branch.c
index 2d752c6614..f525b7e2b5 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -132,7 +132,7 @@ static int branch_merged(int kind, const char *name,
if (!reference_rev)
reference_rev = head_rev;
 
-   merged = in_merge_bases(rev, reference_rev);
+   merged = in_merge_bases(the_repository, rev, reference_rev);
 
/*
 * After the safety valve is fully redefined to "check with
@@ -142,7 +142,7 @@ static int branch_merged(int kind, const char *name,
 * a gentle reminder is in order.
 */
if ((head_rev != reference_rev) &&
-   in_merge_bases(rev, head_rev) != merged) {
+   in_merge_bases(the_repository, rev, head_rev) != merged) {
if (merged)
warning(_("deleting branch '%s' that has been merged 
to\n"
" '%s', but not yet merged to HEAD."),
diff --git a/builtin/fetch.c b/builtin/fetch.c
index b516b176f0..14eccf3f0d 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -695,7 +695,7 @@ static int update_local_ref(struct ref *ref,
return r;
}
 
-   if (in_merge_bases(current, updated)) {
+   if (in_merge_bases(the_repository, current, updated)) {
struct strbuf quickref = STRBUF_INIT;
int r;
strbuf_add_unique_abbrev(, current->object.oid.hash, 
DEFAULT_ABBREV);
diff --git a/builtin/log.c b/builtin/log.c
index bb9d909f59..e8bb899e52 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1325,7 +1325,7 @@ static struct commit *get_base_commit(const char 
*base_commit,
rev_nr = DIV_ROUND_UP(rev_nr, 2);
}
 
-   if (!in_merge_bases(base, rev[0]))
+   if (!in_merge_bases(the_repository, base, rev[0]))
die(_("base commit should be the ancestor of revision list"));
 
for (i = 0; i < total; i++) {
diff --git a/builtin/merge-base.c b/builtin/merge-base.c
index 426882818c..00e9f11d92 100644
--- a/builtin/merge-base.c
+++ b/builtin/merge-base.c
@@ -104,7 +104,7 @@ static int handle_is_ancestor(int argc, const char **argv)
die("--is-ancestor takes exactly two commits");
one = get_commit_reference(argv[0]);
two = get_commit_reference(argv[1]);
-   if (in_merge_bases(one, two))
+   if (in_merge_bases(the_repository, one, two))
return 0;
else
return 1;
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 7d00f0bad6..2b41affaf5 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1118,7 +1118,7 @@ static const char *update(struct command *cmd, struct 
shallow_info *si)
}
old_commit = (struct commit *)old_object;
new_commit = (struct commit *)new_object;
-   if (!in_merge_bases(old_commit, new_commit)) {
+   if (!in_merge_bases(the_repository, old_commit, new_commit)) {
rp_error("denying non-fast-forward %s"
 " (you should pull first)", name);
return "non-fast-forward";
diff --git a/commit.c b/commit.c
index 98e04b949f..900ecf84b8 100644
--- a/commit.c
+++ b/commit.c
@@ -1040,7 +1040,7 @@ int is_descendant_of(struct commit *commit, struct 
commit_list *with_commit)
 
other = with_commit->item;
with_commit = with_commit->next;
-   if (in_merge_bases(other, commit))
+   if (in_merge_bases(the_repository, other, commit))
return 1;
}
return 0;
@@ -1072,7 +1072,7 @@ int in_merge_bases_many_the_repository(struct commit 
*commit, int nr_reference,
 /*
  * Is "commit" an ancestor of (i.e. reachable from) the "reference"?
  */
-int in_merge_bases(struct commit *commit, struct commit *reference)
+int in_merge_bases_the_repository(struct commit *commit, struct commit 
*reference)
 {
return in_merge_bases_many(the_repository, commit, 1, );
 }
diff --git a/commit.h b/commit.h
index ea2c5f528c..0f3cdc6375 100644
--- a/commit.h
+++ b/commit.h
@@ -232,7 +232,8 @@ extern void prune_shallow(int show_only);

[PATCH 187/194] commit: add repository argument to in_merge_bases_many

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 commit.c  | 4 ++--
 commit.h  | 3 ++-
 remote.c  | 2 +-
 shallow.c | 5 +++--
 4 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/commit.c b/commit.c
index b74086d43d..98e04b949f 100644
--- a/commit.c
+++ b/commit.c
@@ -1049,7 +1049,7 @@ int is_descendant_of(struct commit *commit, struct 
commit_list *with_commit)
 /*
  * Is "commit" an ancestor of one of the "references"?
  */
-int in_merge_bases_many(struct commit *commit, int nr_reference, struct commit 
**reference)
+int in_merge_bases_many_the_repository(struct commit *commit, int 
nr_reference, struct commit **reference)
 {
struct commit_list *bases;
int ret = 0, i;
@@ -1074,7 +1074,7 @@ int in_merge_bases_many(struct commit *commit, int 
nr_reference, struct commit *
  */
 int in_merge_bases(struct commit *commit, struct commit *reference)
 {
-   return in_merge_bases_many(commit, 1, );
+   return in_merge_bases_many(the_repository, commit, 1, );
 }
 
 struct commit_list *reduce_heads(struct commit_list *heads)
diff --git a/commit.h b/commit.h
index 7bdc808018..ea2c5f528c 100644
--- a/commit.h
+++ b/commit.h
@@ -233,7 +233,8 @@ extern struct trace_key trace_shallow;
 
 int is_descendant_of(struct commit *, struct commit_list *);
 int in_merge_bases(struct commit *, struct commit *);
-int in_merge_bases_many(struct commit *, int, struct commit **);
+#define in_merge_bases_many(r, c, n, co) in_merge_bases_many_##r(c, n, co)
+int in_merge_bases_many_the_repository(struct commit *, int, struct commit **);
 
 extern int interactive_add(int argc, const char **argv, const char *prefix, 
int patch);
 extern int run_add_interactive(const char *revision, const char *patch_mode,
diff --git a/remote.c b/remote.c
index a4cf885012..0c253b82e8 100644
--- a/remote.c
+++ b/remote.c
@@ -1396,7 +1396,7 @@ static void add_missing_tags(struct ref *src, struct ref 
**dst, struct ref ***ds
 * Is this tag, which they do not have, reachable from
 * any of the commits we are sending?
 */
-   if (!in_merge_bases_many(commit, sent_tips.nr, 
sent_tips.tip))
+   if (!in_merge_bases_many(the_repository, commit, 
sent_tips.nr, sent_tips.tip))
continue;
 
/* Add it in */
diff --git a/shallow.c b/shallow.c
index 64a4fcb57f..f43e94c8e8 100644
--- a/shallow.c
+++ b/shallow.c
@@ -720,7 +720,7 @@ static void post_assign_shallow(struct shallow_info *info,
for (j = 0; j < bitmap_nr; j++)
if (bitmap[0][j] &&
/* Step 7, reachability test at commit level */
-   !in_merge_bases_many(c, ca.nr, ca.commits)) {
+   !in_merge_bases_many(the_repository, c, ca.nr, 
ca.commits)) {
update_refstatus(ref_status, info->ref->nr, 
*bitmap);
dst++;
break;
@@ -748,7 +748,8 @@ int delayed_reachability_test(struct shallow_info *si, int 
c)
si->nr_commits = ca.nr;
}
 
-   si->reachable[c] = in_merge_bases_many(commit,
+   si->reachable[c] = in_merge_bases_many(the_repository,
+  commit,
   si->nr_commits,
   si->commits);
si->need_reachability_test[c] = 0;
-- 
2.15.1.433.g936d1b9894.dirty



[PATCH 186/194] pretty: allow logmsg_reencode to handle arbitrary repositories

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 commit.h | 3 +--
 pretty.c | 8 
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/commit.h b/commit.h
index 77e131d15b..7bdc808018 100644
--- a/commit.h
+++ b/commit.h
@@ -129,8 +129,7 @@ void free_commit_list(struct commit_list *list);
 struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */
 
 extern int has_non_ascii(const char *text);
-#define logmsg_reencode(r, c, e, o) logmsg_reencode_##r(c, e ,o)
-extern const char *logmsg_reencode_the_repository(const struct commit *commit,
+extern const char *logmsg_reencode(struct repository *r, const struct commit 
*commit,
   char **commit_encoding,
   const char *output_encoding);
 extern const char *skip_blank_lines(const char *msg);
diff --git a/pretty.c b/pretty.c
index 30d53369b5..6dce4bb3c0 100644
--- a/pretty.c
+++ b/pretty.c
@@ -595,14 +595,14 @@ static char *replace_encoding_header(char *buf, const 
char *encoding)
return strbuf_detach(, NULL);
 }
 
-const char *logmsg_reencode_the_repository(const struct commit *commit,
+const char *logmsg_reencode(struct repository *r, const struct commit *commit,
char **commit_encoding,
const char *output_encoding)
 {
static const char *utf8 = "UTF-8";
const char *use_encoding;
char *encoding;
-   const char *msg = get_commit_buffer(the_repository, commit, NULL);
+   const char *msg = get_commit_buffer(r, commit, NULL);
char *out;
 
if (!output_encoding || !*output_encoding) {
@@ -630,7 +630,7 @@ const char *logmsg_reencode_the_repository(const struct 
commit *commit,
 * the cached copy from get_commit_buffer, we need to duplicate 
it
 * to avoid munging the cached copy.
 */
-   if (msg == get_cached_commit_buffer(the_repository, commit, 
NULL))
+   if (msg == get_cached_commit_buffer(r, commit, NULL))
out = xstrdup(msg);
else
out = (char *)msg;
@@ -644,7 +644,7 @@ const char *logmsg_reencode_the_repository(const struct 
commit *commit,
 */
out = reencode_string(msg, output_encoding, use_encoding);
if (out)
-   unuse_commit_buffer(the_repository, commit, msg);
+   unuse_commit_buffer(r, commit, msg);
}
 
/*
-- 
2.15.1.433.g936d1b9894.dirty



[PATCH 184/194] pretty: add repository argument to format_commit_message

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 archive.c  |  3 ++-
 builtin/commit.c   | 17 +++--
 builtin/fmt-merge-msg.c|  2 +-
 builtin/notes.c|  3 ++-
 builtin/shortlog.c |  5 +++--
 contrib/coccinelle/submodule_reading.cocci | 10 ++
 log-tree.c |  2 +-
 notes-cache.c  |  2 +-
 pretty.c   |  5 +++--
 pretty.h   |  4 +++-
 sha1_name.c|  3 ++-
 submodule.c|  5 +++--
 t/helper/test-revision-walking.c   |  2 +-
 13 files changed, 43 insertions(+), 20 deletions(-)

diff --git a/archive.c b/archive.c
index 6f38a5cf55..cb0b1d595c 100644
--- a/archive.c
+++ b/archive.c
@@ -56,7 +56,8 @@ static void format_subst(const struct commit *commit,
strbuf_add(, b + 8, c - b - 8);
 
strbuf_add(buf, src, b - src);
-   format_commit_message(commit, fmt.buf, buf, );
+   format_commit_message(the_repository, commit, fmt.buf, buf,
+ );
len -= c + 1 - src;
src  = c + 1;
}
diff --git a/builtin/commit.c b/builtin/commit.c
index c903893767..a6ddf6dd23 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -696,7 +696,8 @@ static int prepare_to_commit(const char *index_file, const 
char *prefix,
if (!c)
die(_("could not lookup commit %s"), 
squash_message);
ctx.output_encoding = get_commit_output_encoding();
-   format_commit_message(c, "squash! %s\n\n", ,
+   format_commit_message(the_repository, c,
+ "squash! %s\n\n", ,
  );
}
}
@@ -729,7 +730,7 @@ static int prepare_to_commit(const char *index_file, const 
char *prefix,
if (!commit)
die(_("could not lookup commit %s"), fixup_message);
ctx.output_encoding = get_commit_output_encoding();
-   format_commit_message(commit, "fixup! %s\n\n",
+   format_commit_message(the_repository, commit, "fixup! %s\n\n",
  , );
hook_arg1 = "message";
} else if (!stat(git_path_merge_msg(the_repository), )) {
@@ -1069,7 +1070,8 @@ static const char *find_author_by_nickname(const char 
*name)
struct pretty_print_context ctx = {0};
ctx.date_mode.type = DATE_NORMAL;
strbuf_release();
-   format_commit_message(commit, "%aN <%aE>", , );
+   format_commit_message(the_repository, commit, "%aN <%aE>",
+ , );
clear_mailmap();
return strbuf_detach(, NULL);
}
@@ -1472,15 +1474,18 @@ static void print_summary(const char *prefix, const 
struct object_id *oid,
 
strbuf_addstr(, "format:%h] %s");
 
-   format_commit_message(commit, "%an <%ae>", _ident, );
-   format_commit_message(commit, "%cn <%ce>", _ident, );
+   format_commit_message(the_repository, commit, "%an <%ae>",
+ _ident, );
+   format_commit_message(the_repository, commit, "%cn <%ce>",
+ _ident, );
if (strbuf_cmp(_ident, _ident)) {
strbuf_addstr(, "\n Author: ");
strbuf_addbuf_percentquote(, _ident);
}
if (author_date_is_interesting()) {
struct strbuf date = STRBUF_INIT;
-   format_commit_message(commit, "%ad", , );
+   format_commit_message(the_repository, commit, "%ad", ,
+ );
strbuf_addstr(, "\n Date: ");
strbuf_addbuf_percentquote(, );
strbuf_release();
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index 6dedb92d61..591cf95346 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -374,7 +374,7 @@ static void shortlog(const char *name,
if (subjects.nr > limit)
continue;
 
-   format_commit_message(commit, "%s", , );
+   format_commit_message(the_repository, commit, "%s", , );
strbuf_ltrim();
 
if (!sb.len)
diff --git a/builtin/notes.c b/builtin/notes.c
index 9100ac5ce0..8633da1d5e 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -736,7 +736,8 @@ static int merge_commit(struct notes_merge_options *o)
 
/* Reuse existing commit message in reflog message */
memset(_ctx, 0, sizeof(pretty_ctx));
-   format_commit_message(partial, "%s", , _ctx);
+   

[PATCH 185/194] commit: allow get_commit_buffer to handle arbitrary repositories

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 commit.c | 6 +++---
 commit.h | 3 +--
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/commit.c b/commit.c
index b241cc7979..b74086d43d 100644
--- a/commit.c
+++ b/commit.c
@@ -277,13 +277,13 @@ const void *get_cached_commit_buffer(struct repository 
*r, const struct commit *
return v->buffer;
 }
 
-const void *get_commit_buffer_the_repository(const struct commit *commit, 
unsigned long *sizep)
+const void *get_commit_buffer(struct repository *r, const struct commit 
*commit, unsigned long *sizep)
 {
-   const void *ret = get_cached_commit_buffer(the_repository, commit, 
sizep);
+   const void *ret = get_cached_commit_buffer(r, commit, sizep);
if (!ret) {
enum object_type type;
unsigned long size;
-   ret = read_sha1_file(the_repository, commit->object.oid.hash,
+   ret = read_sha1_file(r, commit->object.oid.hash,
 , );
if (!ret)
die("cannot read commit object %s",
diff --git a/commit.h b/commit.h
index 33f7779602..77e131d15b 100644
--- a/commit.h
+++ b/commit.h
@@ -88,8 +88,7 @@ const void *get_cached_commit_buffer(struct repository *r, 
const struct commit *
  * from disk. The resulting memory should not be modified, and must be given
  * to unuse_commit_buffer when the caller is done.
  */
-#define get_commit_buffer(r, c, s) get_commit_buffer_##r(c, s)
-const void *get_commit_buffer_the_repository(const struct commit *, unsigned 
long *size);
+const void *get_commit_buffer(struct repository *r, const struct commit *, 
unsigned long *size);
 
 /*
  * Tell the commit subsytem that we are done with a particular commit buffer.
-- 
2.15.1.433.g936d1b9894.dirty



[PATCH 183/194] commit: add repository argument to logmsg_reencode

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 builtin/am.c   | 3 ++-
 builtin/blame.c| 2 +-
 builtin/commit.c   | 2 +-
 builtin/reset.c| 3 ++-
 commit.h   | 3 ++-
 contrib/coccinelle/submodule_reading.cocci | 9 +
 pretty.c   | 7 ---
 revision.c | 2 +-
 sequencer.c| 3 ++-
 9 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/builtin/am.c b/builtin/am.c
index 7072ec78cb..9bbf41912b 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1328,7 +1328,8 @@ static void get_commit_info(struct am_state *state, 
struct commit *commit)
size_t ident_len;
struct ident_split id;
 
-   buffer = logmsg_reencode(commit, NULL, get_commit_output_encoding());
+   buffer = logmsg_reencode(the_repository, commit, NULL,
+get_commit_output_encoding());
 
ident_line = find_commit_header(buffer, "author", _len);
 
diff --git a/builtin/blame.c b/builtin/blame.c
index 956df42c67..f9c18f6413 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -186,7 +186,7 @@ static void get_commit_info(struct commit *commit,
commit_info_init(ret);
 
encoding = get_log_output_encoding();
-   message = logmsg_reencode(commit, NULL, encoding);
+   message = logmsg_reencode(the_repository, commit, NULL, encoding);
get_ac_line(message, "\nauthor ",
>author, >author_mail,
>author_time, >author_tz);
diff --git a/builtin/commit.c b/builtin/commit.c
index cceb965569..c903893767 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1113,7 +1113,7 @@ static const char *read_commit_message(const char *name)
if (!commit)
die(_("could not lookup commit %s"), name);
out_enc = get_commit_output_encoding();
-   return logmsg_reencode(commit, NULL, out_enc);
+   return logmsg_reencode(the_repository, commit, NULL, out_enc);
 }
 
 /*
diff --git a/builtin/reset.c b/builtin/reset.c
index 7c57309adc..ef16cbea0d 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -111,7 +111,8 @@ static void print_new_head_line(struct commit *commit)
 
hex = find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV);
printf(_("HEAD is now at %s"), hex);
-   msg = logmsg_reencode(commit, NULL, get_log_output_encoding());
+   msg = logmsg_reencode(the_repository, commit, NULL,
+ get_log_output_encoding());
body = strstr(msg, "\n\n");
if (body) {
const char *eol;
diff --git a/commit.h b/commit.h
index b9eb079e21..33f7779602 100644
--- a/commit.h
+++ b/commit.h
@@ -130,7 +130,8 @@ void free_commit_list(struct commit_list *list);
 struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */
 
 extern int has_non_ascii(const char *text);
-extern const char *logmsg_reencode(const struct commit *commit,
+#define logmsg_reencode(r, c, e, o) logmsg_reencode_##r(c, e ,o)
+extern const char *logmsg_reencode_the_repository(const struct commit *commit,
   char **commit_encoding,
   const char *output_encoding);
 extern const char *skip_blank_lines(const char *msg);
diff --git a/contrib/coccinelle/submodule_reading.cocci 
b/contrib/coccinelle/submodule_reading.cocci
index 17c2e02512..b3e3d88626 100644
--- a/contrib/coccinelle/submodule_reading.cocci
+++ b/contrib/coccinelle/submodule_reading.cocci
@@ -5,3 +5,12 @@ expression F;
  get_commit_buffer(
 +the_repository,
  E, F)
+
+@@
+expression E;
+expression F;
+expression G;
+@@
+ logmsg_reencode(
++the_repository,
+ E, F, G)
diff --git a/pretty.c b/pretty.c
index c5a2f0b018..a0c95280f6 100644
--- a/pretty.c
+++ b/pretty.c
@@ -595,7 +595,7 @@ static char *replace_encoding_header(char *buf, const char 
*encoding)
return strbuf_detach(, NULL);
 }
 
-const char *logmsg_reencode(const struct commit *commit,
+const char *logmsg_reencode_the_repository(const struct commit *commit,
char **commit_encoding,
const char *output_encoding)
 {
@@ -1519,7 +1519,7 @@ void format_commit_message(const struct commit *commit,
 * convert a commit message to UTF-8 first
 * as far as 'format_commit_item' assumes it in UTF-8
 */
-   context.message = logmsg_reencode(commit,
+   context.message = logmsg_reencode(the_repository, commit,
  _encoding,
  utf8);
 
@@ -1801,7 +1801,8 @@ void pretty_print_commit(struct pretty_print_context *pp,
}
 
encoding = get_log_output_encoding();
-   msg = reencoded = logmsg_reencode(commit, NULL, encoding);
+   msg = reencoded = 

[PATCH 182/194] commit: add repository argument to get_commit_buffer

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 builtin/fast-export.c  |  2 +-
 builtin/fmt-merge-msg.c|  2 +-
 builtin/log.c  |  3 ++-
 builtin/replace.c  |  2 +-
 commit.c   |  8 
 commit.h   |  3 ++-
 contrib/coccinelle/submodule_reading.cocci |  7 +++
 fsck.c |  3 ++-
 merge-recursive.c  |  3 ++-
 notes-merge.c  |  3 ++-
 pretty.c   |  2 +-
 sequencer.c| 13 -
 sha1_name.c|  2 +-
 13 files changed, 34 insertions(+), 19 deletions(-)
 create mode 100644 contrib/coccinelle/submodule_reading.cocci

diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 80853bb91a..bc04e3f0a7 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -561,7 +561,7 @@ static void handle_commit(struct commit *commit, struct 
rev_info *rev,
rev->diffopt.output_format = DIFF_FORMAT_CALLBACK;
 
parse_commit_or_die(commit);
-   commit_buffer = get_commit_buffer(commit, NULL);
+   commit_buffer = get_commit_buffer(the_repository, commit, NULL);
author = strstr(commit_buffer, "\nauthor ");
if (!author)
die ("Could not find author in commit %s",
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index c54f045ccd..6dedb92d61 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -261,7 +261,7 @@ static void record_person_from_buf(int which, struct 
string_list *people,
 static void record_person(int which, struct string_list *people,
  struct commit *commit)
 {
-   const char *buffer = get_commit_buffer(commit, NULL);
+   const char *buffer = get_commit_buffer(the_repository, commit, NULL);
record_person_from_buf(which, people, buffer);
unuse_commit_buffer(the_repository, commit, buffer);
 }
diff --git a/builtin/log.c b/builtin/log.c
index 3ccab366e7..bb9d909f59 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1022,7 +1022,8 @@ static void make_cover_letter(struct rev_info *rev, int 
use_stdout,
log_write_email_headers(rev, head, _subject, _8bit_cte);
 
for (i = 0; !need_8bit_cte && i < nr; i++) {
-   const char *buf = get_commit_buffer(list[i], NULL);
+   const char *buf = get_commit_buffer(the_repository, list[i],
+   NULL);
if (has_non_ascii(buf))
need_8bit_cte = 1;
unuse_commit_buffer(the_repository, list[i], buf);
diff --git a/builtin/replace.c b/builtin/replace.c
index 1a92c0082a..46bb7cdfe8 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -401,7 +401,7 @@ static int create_graft(int argc, const char **argv, int 
force)
die(_("Not a valid object name: '%s'"), old_ref);
commit = lookup_commit_or_die(, old_ref);
 
-   buffer = get_commit_buffer(commit, );
+   buffer = get_commit_buffer(the_repository, commit, );
strbuf_add(, buffer, size);
unuse_commit_buffer(the_repository, commit, buffer);
 
diff --git a/commit.c b/commit.c
index ac65c1dbd7..b241cc7979 100644
--- a/commit.c
+++ b/commit.c
@@ -277,7 +277,7 @@ const void *get_cached_commit_buffer(struct repository *r, 
const struct commit *
return v->buffer;
 }
 
-const void *get_commit_buffer(const struct commit *commit, unsigned long 
*sizep)
+const void *get_commit_buffer_the_repository(const struct commit *commit, 
unsigned long *sizep)
 {
const void *ret = get_cached_commit_buffer(the_repository, commit, 
sizep);
if (!ret) {
@@ -617,7 +617,7 @@ define_commit_slab(author_date_slab, unsigned long);
 static void record_author_date(struct author_date_slab *author_date,
   struct commit *commit)
 {
-   const char *buffer = get_commit_buffer(commit, NULL);
+   const char *buffer = get_commit_buffer(the_repository, commit, NULL);
struct ident_split ident;
const char *ident_line;
size_t ident_len;
@@ -1163,7 +1163,7 @@ int parse_signed_commit(const struct commit *commit,
 {
 
unsigned long size;
-   const char *buffer = get_commit_buffer(commit, );
+   const char *buffer = get_commit_buffer(the_repository, commit, );
int in_signature, saw_signature = -1;
const char *line, *tail;
 
@@ -1320,7 +1320,7 @@ struct commit_extra_header 
*read_commit_extra_headers(struct commit *commit,
 {
struct commit_extra_header *extra = NULL;
unsigned long size;
-   const char *buffer = get_commit_buffer(commit, );
+   const char *buffer = get_commit_buffer(the_repository, commit, );
extra = read_commit_extra_header_lines(buffer, size, exclude);

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

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 tag.c | 5 ++---
 tag.h | 3 +--
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/tag.c b/tag.c
index 96757f37dc..d2b2bbb79c 100644
--- a/tag.c
+++ b/tag.c
@@ -64,12 +64,11 @@ int gpg_verify_tag(const struct object_id *oid, const char 
*name_to_report,
return ret;
 }
 
-struct object *deref_tag_the_repository(struct object *o, const char *warn, 
int warnlen)
+struct object *deref_tag(struct repository *r, struct object *o, const char 
*warn, int warnlen)
 {
while (o && o->type == OBJ_TAG)
if (((struct tag *)o)->tagged)
-   o = parse_object(the_repository,
-&((struct tag *)o)->tagged->oid);
+   o = parse_object(r, &((struct tag *)o)->tagged->oid);
else
o = NULL;
if (!o && warn) {
diff --git a/tag.h b/tag.h
index 91208dd2d6..91bb163e26 100644
--- a/tag.h
+++ b/tag.h
@@ -14,8 +14,7 @@ struct tag {
 extern struct tag *lookup_tag(struct repository *r, const struct object_id 
*oid);
 extern int parse_tag_buffer(struct repository *r, struct tag *item, const void 
*data, unsigned long size);
 extern int parse_tag(struct tag *item);
-#define deref_tag(r, o, w, l) deref_tag_##r(o, w, l)
-extern struct object *deref_tag_the_repository(struct object *, const char *, 
int);
+extern struct object *deref_tag(struct repository *r, struct object *, const 
char *, int);
 extern struct object *deref_tag_noverify(struct object *);
 extern int gpg_verify_tag(const struct object_id *oid,
const char *name_to_report, unsigned flags);
-- 
2.15.1.433.g936d1b9894.dirty



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

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 commit.c | 8 +++-
 commit.h | 4 +---
 2 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/commit.c b/commit.c
index 33f5442dc1..426cbc9b55 100644
--- a/commit.c
+++ b/commit.c
@@ -21,16 +21,14 @@ int save_commit_buffer = 1;
 
 const char *commit_type = "commit";
 
-struct commit *lookup_commit_reference_gently_the_repository(
+struct commit *lookup_commit_reference_gently(struct repository *r,
const struct object_id *oid, int quiet)
 {
-   struct object *obj = deref_tag(the_repository,
-  parse_object(the_repository, oid),
+   struct object *obj = deref_tag(r, parse_object(r, oid),
   NULL, 0);
-
if (!obj)
return NULL;
-   return object_as_type(the_repository, obj, OBJ_COMMIT, quiet);
+   return object_as_type(r, obj, OBJ_COMMIT, quiet);
 }
 
 struct commit *lookup_commit_reference_the_repository(const struct object_id 
*oid)
diff --git a/commit.h b/commit.h
index 7fe6bb0b22..154c61f111 100644
--- a/commit.h
+++ b/commit.h
@@ -50,9 +50,7 @@ struct commit *lookup_commit(struct repository *r, const 
struct object_id *oid);
 #define lookup_commit_reference(r, o) \
lookup_commit_reference_##r(o)
 struct commit *lookup_commit_reference_the_repository(const struct object_id 
*oid);
-#define lookup_commit_reference_gently(r, o, q) \
-   lookup_commit_reference_gently_##r(o, q)
-struct commit *lookup_commit_reference_gently_the_repository(
+struct commit *lookup_commit_reference_gently(struct repository *r,
  const struct object_id *oid,
  int quiet);
 struct commit *lookup_commit_reference_by_name(const char *name);
-- 
2.15.1.433.g936d1b9894.dirty



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

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 commit.c | 4 ++--
 commit.h | 4 +---
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/commit.c b/commit.c
index 426cbc9b55..ac65c1dbd7 100644
--- a/commit.c
+++ b/commit.c
@@ -31,9 +31,9 @@ struct commit *lookup_commit_reference_gently(struct 
repository *r,
return object_as_type(r, obj, OBJ_COMMIT, quiet);
 }
 
-struct commit *lookup_commit_reference_the_repository(const struct object_id 
*oid)
+struct commit *lookup_commit_reference(struct repository *r, const struct 
object_id *oid)
 {
-   return lookup_commit_reference_gently(the_repository, oid, 0);
+   return lookup_commit_reference_gently(r, oid, 0);
 }
 
 struct commit *lookup_commit_or_die(const struct object_id *oid, const char 
*ref_name)
diff --git a/commit.h b/commit.h
index 154c61f111..d2d5e66b53 100644
--- a/commit.h
+++ b/commit.h
@@ -47,9 +47,7 @@ void add_name_decoration(enum decoration_type type, const 
char *name, struct obj
 const struct name_decoration *get_name_decoration(const struct object *obj);
 
 struct commit *lookup_commit(struct repository *r, const struct object_id 
*oid);
-#define lookup_commit_reference(r, o) \
-   lookup_commit_reference_##r(o)
-struct commit *lookup_commit_reference_the_repository(const struct object_id 
*oid);
+struct commit *lookup_commit_reference(struct repository *r,const struct 
object_id *oid);
 struct commit *lookup_commit_reference_gently(struct repository *r,
  const struct object_id *oid,
  int quiet);
-- 
2.15.1.433.g936d1b9894.dirty



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

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 object.c | 20 ++--
 object.h |  3 +--
 2 files changed, 11 insertions(+), 12 deletions(-)

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



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

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 object-store.h | 3 +--
 sha1_file.c| 4 ++--
 2 files changed, 3 insertions(+), 4 deletions(-)

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



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

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 tag.c | 10 +-
 tag.h |  3 +--
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/tag.c b/tag.c
index 52009bf454..96757f37dc 100644
--- a/tag.c
+++ b/tag.c
@@ -118,7 +118,7 @@ static timestamp_t parse_tag_date(const char *buf, const 
char *tail)
return parse_timestamp(dateptr, NULL, 10);
 }
 
-int parse_tag_buffer_the_repository(struct tag *item, const void *data, 
unsigned long size)
+int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, 
unsigned long size)
 {
struct object_id oid;
char type[20];
@@ -146,13 +146,13 @@ int parse_tag_buffer_the_repository(struct tag *item, 
const void *data, unsigned
bufptr = nl + 1;
 
if (!strcmp(type, blob_type)) {
-   item->tagged = (struct object *)lookup_blob(the_repository, 
);
+   item->tagged = (struct object *)lookup_blob(r, );
} else if (!strcmp(type, tree_type)) {
-   item->tagged = (struct object *)lookup_tree(the_repository, 
);
+   item->tagged = (struct object *)lookup_tree(r, );
} else if (!strcmp(type, commit_type)) {
-   item->tagged = (struct object *)lookup_commit(the_repository, 
);
+   item->tagged = (struct object *)lookup_commit(r, );
} else if (!strcmp(type, tag_type)) {
-   item->tagged = (struct object *)lookup_tag(the_repository, 
);
+   item->tagged = (struct object *)lookup_tag(r, );
} else {
error("Unknown type %s", type);
item->tagged = NULL;
diff --git a/tag.h b/tag.h
index d23af572d8..91208dd2d6 100644
--- a/tag.h
+++ b/tag.h
@@ -12,8 +12,7 @@ struct tag {
timestamp_t date;
 };
 extern struct tag *lookup_tag(struct repository *r, const struct object_id 
*oid);
-#define parse_tag_buffer(r, i, d, s) parse_tag_buffer_##r(i, d, s)
-extern int parse_tag_buffer_the_repository(struct tag *item, const void *data, 
unsigned long size);
+extern int parse_tag_buffer(struct repository *r, struct tag *item, const void 
*data, unsigned long size);
 extern int parse_tag(struct tag *item);
 #define deref_tag(r, o, w, l) deref_tag_##r(o, w, l)
 extern struct object *deref_tag_the_repository(struct object *, const char *, 
int);
-- 
2.15.1.433.g936d1b9894.dirty



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

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 object.c | 18 +-
 object.h |  3 +--
 2 files changed, 10 insertions(+), 11 deletions(-)

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



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

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 tag.c | 10 +-
 tag.h |  3 +--
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/tag.c b/tag.c
index e0b695cb60..52009bf454 100644
--- a/tag.c
+++ b/tag.c
@@ -92,13 +92,13 @@ struct object *deref_tag_noverify(struct object *o)
return o;
 }
 
-struct tag *lookup_tag_the_repository(const struct object_id *oid)
+struct tag *lookup_tag(struct repository *r, const struct object_id *oid)
 {
-   struct object *obj = lookup_object(the_repository, oid->hash);
+   struct object *obj = lookup_object(r, oid->hash);
if (!obj)
-   return create_object(the_repository, oid->hash,
-alloc_tag_node(the_repository));
-   return object_as_type(the_repository, obj, OBJ_TAG, 0);
+   return create_object(r, oid->hash,
+alloc_tag_node(r));
+   return object_as_type(r, obj, OBJ_TAG, 0);
 }
 
 static timestamp_t parse_tag_date(const char *buf, const char *tail)
diff --git a/tag.h b/tag.h
index 4f45695e1e..d23af572d8 100644
--- a/tag.h
+++ b/tag.h
@@ -11,8 +11,7 @@ struct tag {
char *tag;
timestamp_t date;
 };
-#define lookup_tag(r, o) lookup_tag_##r(o)
-extern struct tag *lookup_tag_the_repository(const struct object_id *oid);
+extern struct tag *lookup_tag(struct repository *r, const struct object_id 
*oid);
 #define parse_tag_buffer(r, i, d, s) parse_tag_buffer_##r(i, d, s)
 extern int parse_tag_buffer_the_repository(struct tag *item, const void *data, 
unsigned long size);
 extern int parse_tag(struct tag *item);
-- 
2.15.1.433.g936d1b9894.dirty



[PATCH 171/194] commit: add repository argument to get_merge_bases

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 builtin/log.c   | 2 +-
 builtin/merge.c | 4 ++--
 builtin/rev-parse.c | 2 +-
 commit.c| 4 ++--
 commit.h| 3 ++-
 merge-recursive.c   | 2 +-
 notes-merge.c   | 2 +-
 revision.c  | 4 ++--
 sha1_name.c | 2 +-
 submodule.c | 2 +-
 10 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/builtin/log.c b/builtin/log.c
index 12426e685f..3ccab366e7 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1312,7 +1312,7 @@ static struct commit *get_base_commit(const char 
*base_commit,
while (rev_nr > 1) {
for (i = 0; i < rev_nr / 2; i++) {
struct commit_list *merge_base;
-   merge_base = get_merge_bases(rev[2 * i], rev[2 * i + 
1]);
+   merge_base = get_merge_bases(the_repository, rev[2 * 
i], rev[2 * i + 1]);
if (!merge_base || merge_base->next)
die(_("Failed to find exact merge base"));
 
diff --git a/builtin/merge.c b/builtin/merge.c
index 4f5c01c41c..93a736ac36 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -1352,7 +1352,7 @@ int cmd_merge(int argc, const char **argv, const char 
*prefix)
if (!remoteheads)
; /* already up-to-date */
else if (!remoteheads->next)
-   common = get_merge_bases(head_commit, remoteheads->item);
+   common = get_merge_bases(the_repository, head_commit, 
remoteheads->item);
else {
struct commit_list *list = remoteheads;
commit_list_insert(head_commit, );
@@ -1451,7 +1451,7 @@ int cmd_merge(int argc, const char **argv, const char 
*prefix)
 * merge_bases again, otherwise "git merge HEAD^
 * HEAD^^" would be missed.
 */
-   common_one = get_merge_bases(head_commit, j->item);
+   common_one = get_merge_bases(the_repository, 
head_commit, j->item);
if (oidcmp(_one->item->object.oid, 
>item->object.oid)) {
up_to_date = 0;
break;
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 5911714441..3399176e49 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -282,7 +282,7 @@ static int try_difference(const char *arg)
struct commit *a, *b;
a = lookup_commit_reference(the_repository, );
b = lookup_commit_reference(the_repository, );
-   exclude = get_merge_bases(a, b);
+   exclude = get_merge_bases(the_repository, a, b);
while (exclude) {
struct commit *commit = pop_commit();
show_rev(REVERSED, >object.oid, NULL);
diff --git a/commit.c b/commit.c
index db03550d70..8b1e35d2a1 100644
--- a/commit.c
+++ b/commit.c
@@ -900,7 +900,7 @@ struct commit_list *get_octopus_merge_bases(struct 
commit_list *in)
 
for (j = ret; j; j = j->next) {
struct commit_list *bases;
-   bases = get_merge_bases(i->item, j->item);
+   bases = get_merge_bases(the_repository, i->item, 
j->item);
if (!new)
new = bases;
else
@@ -1025,7 +1025,7 @@ struct commit_list *get_merge_bases_many_dirty(struct 
commit *one,
return get_merge_bases_many_0(the_repository, one, n, twos, 0);
 }
 
-struct commit_list *get_merge_bases(struct commit *one, struct commit *two)
+struct commit_list *get_merge_bases_the_repository(struct commit *one, struct 
commit *two)
 {
return get_merge_bases_many_0(the_repository, one, 1, , 1);
 }
diff --git a/commit.h b/commit.h
index b60c287e7d..e671ce68db 100644
--- a/commit.h
+++ b/commit.h
@@ -180,7 +180,8 @@ struct commit_graft *read_graft_line(struct strbuf *line);
 int register_commit_graft(struct repository *r, struct commit_graft *, int);
 struct commit_graft *lookup_commit_graft(struct repository *r, const struct 
object_id *oid);
 
-extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit 
*rev2);
+#define get_merge_bases(r, r1, r2) get_merge_bases_##r(r1, r2)
+extern struct commit_list *get_merge_bases_the_repository(struct commit *rev1, 
struct commit *rev2);
 extern struct commit_list *get_merge_bases_many(struct commit *one, int n, 
struct commit **twos);
 extern struct commit_list *get_octopus_merge_bases(struct commit_list *in);
 
diff --git a/merge-recursive.c b/merge-recursive.c
index c749785b0b..6e06634993 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -2074,7 +2074,7 @@ int merge_recursive(struct merge_options *o,
}
 
if (!ca) {
-   ca = get_merge_bases(h1, h2);
+   ca = 

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

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 blob.c | 10 +-
 blob.h |  3 +--
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/blob.c b/blob.c
index 7c661f178a..5dcaf63697 100644
--- a/blob.c
+++ b/blob.c
@@ -4,13 +4,13 @@
 
 const char *blob_type = "blob";
 
-struct blob *lookup_blob_the_repository(const struct object_id *oid)
+struct blob *lookup_blob(struct repository *r, const struct object_id *oid)
 {
-   struct object *obj = lookup_object(the_repository, oid->hash);
+   struct object *obj = lookup_object(r, oid->hash);
if (!obj)
-   return create_object(the_repository, oid->hash,
-alloc_blob_node(the_repository));
-   return object_as_type(the_repository, obj, OBJ_BLOB, 0);
+   return create_object(r, oid->hash,
+alloc_blob_node(r));
+   return object_as_type(r, obj, OBJ_BLOB, 0);
 }
 
 int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size)
diff --git a/blob.h b/blob.h
index 08bc34487a..1664872055 100644
--- a/blob.h
+++ b/blob.h
@@ -9,8 +9,7 @@ struct blob {
struct object object;
 };
 
-#define lookup_blob(r, o) lookup_blob_##r(o)
-struct blob *lookup_blob_the_repository(const struct object_id *oid);
+struct blob *lookup_blob(struct repository *r, const struct object_id *oid);
 
 int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size);
 
-- 
2.15.1.433.g936d1b9894.dirty



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

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 commit.c | 4 ++--
 commit.h | 3 +--
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/commit.c b/commit.c
index 8b1e35d2a1..33f5442dc1 100644
--- a/commit.c
+++ b/commit.c
@@ -1025,9 +1025,9 @@ struct commit_list *get_merge_bases_many_dirty(struct 
commit *one,
return get_merge_bases_many_0(the_repository, one, n, twos, 0);
 }
 
-struct commit_list *get_merge_bases_the_repository(struct commit *one, struct 
commit *two)
+struct commit_list *get_merge_bases(struct repository *r, struct commit *one, 
struct commit *two)
 {
-   return get_merge_bases_many_0(the_repository, one, 1, , 1);
+   return get_merge_bases_many_0(r, one, 1, , 1);
 }
 
 /*
diff --git a/commit.h b/commit.h
index e671ce68db..7fe6bb0b22 100644
--- a/commit.h
+++ b/commit.h
@@ -180,8 +180,7 @@ struct commit_graft *read_graft_line(struct strbuf *line);
 int register_commit_graft(struct repository *r, struct commit_graft *, int);
 struct commit_graft *lookup_commit_graft(struct repository *r, const struct 
object_id *oid);
 
-#define get_merge_bases(r, r1, r2) get_merge_bases_##r(r1, r2)
-extern struct commit_list *get_merge_bases_the_repository(struct commit *rev1, 
struct commit *rev2);
+extern struct commit_list *get_merge_bases(struct repository *r, struct commit 
*rev1, struct commit *rev2);
 extern struct commit_list *get_merge_bases_many(struct commit *one, int n, 
struct commit **twos);
 extern struct commit_list *get_octopus_merge_bases(struct commit_list *in);
 
-- 
2.15.1.433.g936d1b9894.dirty



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

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 commit.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/commit.c b/commit.c
index a8f964c6f9..db03550d70 100644
--- a/commit.c
+++ b/commit.c
@@ -969,8 +969,8 @@ static int remove_redundant(struct repository *r, struct 
commit **array, int cnt
return filled;
 }
 
-#define get_merge_bases_many_0(r, o, n, t, c) get_merge_bases_many_0_##r(o, n, 
t, c)
-static struct commit_list *get_merge_bases_many_0_the_repository(struct commit 
*one,
+static struct commit_list *get_merge_bases_many_0(struct repository *r,
+ struct commit *one,
  int n,
  struct commit **twos,
  int cleanup)
@@ -980,7 +980,7 @@ static struct commit_list 
*get_merge_bases_many_0_the_repository(struct commit *
struct commit_list *result;
int cnt, i;
 
-   result = merge_bases_many(the_repository, one, n, twos);
+   result = merge_bases_many(r, one, n, twos);
for (i = 0; i < n; i++) {
if (one == twos[i])
return result;
@@ -1003,7 +1003,7 @@ static struct commit_list 
*get_merge_bases_many_0_the_repository(struct commit *
clear_commit_marks(one, all_flags);
clear_commit_marks_many(n, twos, all_flags);
 
-   cnt = remove_redundant(the_repository, rslt, cnt);
+   cnt = remove_redundant(r, rslt, cnt);
result = NULL;
for (i = 0; i < cnt; i++)
commit_list_insert_by_date(rslt[i], );
-- 
2.15.1.433.g936d1b9894.dirty



[PATCH 168/194] commit: add repository argument to remove_redundant

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 commit.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/commit.c b/commit.c
index b01352f54a..3ed46e7372 100644
--- a/commit.c
+++ b/commit.c
@@ -913,7 +913,8 @@ struct commit_list *get_octopus_merge_bases(struct 
commit_list *in)
return ret;
 }
 
-static int remove_redundant(struct commit **array, int cnt)
+#define remove_redundant(r, a, c) remove_redundant_##r(a, c)
+static int remove_redundant_the_repository(struct commit **array, int cnt)
 {
/*
 * Some commit in the array may be an ancestor of
@@ -1003,7 +1004,7 @@ static struct commit_list 
*get_merge_bases_many_0_the_repository(struct commit *
clear_commit_marks(one, all_flags);
clear_commit_marks_many(n, twos, all_flags);
 
-   cnt = remove_redundant(rslt, cnt);
+   cnt = remove_redundant(the_repository, rslt, cnt);
result = NULL;
for (i = 0; i < cnt; i++)
commit_list_insert_by_date(rslt[i], );
@@ -1105,7 +1106,7 @@ struct commit_list *reduce_heads(struct commit_list 
*heads)
p->item->object.flags &= ~STALE;
}
}
-   num_head = remove_redundant(array, num_head);
+   num_head = remove_redundant(the_repository, array, num_head);
for (i = 0; i < num_head; i++)
tail = _list_insert(array[i], tail)->next;
free(array);
-- 
2.15.1.433.g936d1b9894.dirty



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

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 commit.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/commit.c b/commit.c
index 3ed46e7372..a8f964c6f9 100644
--- a/commit.c
+++ b/commit.c
@@ -913,8 +913,7 @@ struct commit_list *get_octopus_merge_bases(struct 
commit_list *in)
return ret;
 }
 
-#define remove_redundant(r, a, c) remove_redundant_##r(a, c)
-static int remove_redundant_the_repository(struct commit **array, int cnt)
+static int remove_redundant(struct repository *r, struct commit **array, int 
cnt)
 {
/*
 * Some commit in the array may be an ancestor of
@@ -932,7 +931,7 @@ static int remove_redundant_the_repository(struct commit 
**array, int cnt)
ALLOC_ARRAY(filled_index, cnt - 1);
 
for (i = 0; i < cnt; i++)
-   parse_commit(the_repository, array[i]);
+   parse_commit(r, array[i]);
for (i = 0; i < cnt; i++) {
struct commit_list *common;
 
@@ -944,7 +943,7 @@ static int remove_redundant_the_repository(struct commit 
**array, int cnt)
filled_index[filled] = j;
work[filled++] = array[j];
}
-   common = paint_down_to_common(the_repository, array[i], filled, 
work);
+   common = paint_down_to_common(r, array[i], filled, work);
if (array[i]->object.flags & PARENT2)
redundant[i] = 1;
for (j = 0; j < filled; j++)
-- 
2.15.1.433.g936d1b9894.dirty



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

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 commit.h | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/commit.h b/commit.h
index 153f13600b..b60c287e7d 100644
--- a/commit.h
+++ b/commit.h
@@ -66,10 +66,9 @@ struct commit *lookup_commit_or_die(const struct object_id 
*oid, const char *ref
 
 int parse_commit_buffer(struct repository *r, struct commit *item, const void 
*buffer, unsigned long size);
 int parse_commit_gently(struct repository *r, struct commit *item, int 
quiet_on_missing);
-#define parse_commit(r, i) parse_commit_##r(i)
-static inline int parse_commit_the_repository(struct commit *item)
+static inline int parse_commit(struct repository *r, struct commit *item)
 {
-   return parse_commit_gently(the_repository, item, 0);
+   return parse_commit_gently(r, item, 0);
 }
 void parse_commit_or_die(struct commit *item);
 
-- 
2.15.1.433.g936d1b9894.dirty



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

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 commit.c | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/commit.c b/commit.c
index 5454bb5e11..b01352f54a 100644
--- a/commit.c
+++ b/commit.c
@@ -854,8 +854,7 @@ static struct commit_list *paint_down_to_common(struct 
repository *r, struct com
return result;
 }
 
-#define merge_bases_many(r, o, n, t) merge_bases_many_##r(o, n, t)
-static struct commit_list *merge_bases_many_the_repository(struct commit *one, 
int n, struct commit **twos)
+static struct commit_list *merge_bases_many(struct repository *r, struct 
commit *one, int n, struct commit **twos)
 {
struct commit_list *list = NULL;
struct commit_list *result = NULL;
@@ -870,14 +869,14 @@ static struct commit_list 
*merge_bases_many_the_repository(struct commit *one, i
return commit_list_insert(one, );
}
 
-   if (parse_commit(the_repository, one))
+   if (parse_commit(r, one))
return NULL;
for (i = 0; i < n; i++) {
-   if (parse_commit(the_repository, twos[i]))
+   if (parse_commit(r, twos[i]))
return NULL;
}
 
-   list = paint_down_to_common(the_repository, one, n, twos);
+   list = paint_down_to_common(r, one, n, twos);
 
while (list) {
struct commit *commit = pop_commit();
-- 
2.15.1.433.g936d1b9894.dirty



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

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 commit.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/commit.c b/commit.c
index 3886266785..5454bb5e11 100644
--- a/commit.c
+++ b/commit.c
@@ -805,8 +805,7 @@ static int queue_has_nonstale(struct prio_queue *queue)
 }
 
 /* all input commits in one and twos[] must have been parsed! */
-#define paint_down_to_common(r, o, n, t) paint_down_to_common_##r(o, n, t)
-static struct commit_list *paint_down_to_common_the_repository(struct commit 
*one, int n, struct commit **twos)
+static struct commit_list *paint_down_to_common(struct repository *r, struct 
commit *one, int n, struct commit **twos)
 {
struct prio_queue queue = { compare_commits_by_commit_date };
struct commit_list *result = NULL;
@@ -844,7 +843,7 @@ static struct commit_list 
*paint_down_to_common_the_repository(struct commit *on
parents = parents->next;
if ((p->object.flags & flags) == flags)
continue;
-   if (parse_commit(the_repository, p))
+   if (parse_commit(r, p))
return NULL;
p->object.flags |= flags;
prio_queue_put(, p);
-- 
2.15.1.433.g936d1b9894.dirty



[PATCH 163/194] commit: add repository argument to merge_bases_many

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 commit.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/commit.c b/commit.c
index a4f35cd9fc..ed7349bbd7 100644
--- a/commit.c
+++ b/commit.c
@@ -854,7 +854,8 @@ static struct commit_list *paint_down_to_common(struct 
commit *one, int n, struc
return result;
 }
 
-static struct commit_list *merge_bases_many(struct commit *one, int n, struct 
commit **twos)
+#define merge_bases_many(r, o, n, t) merge_bases_many_##r(o, n, t)
+static struct commit_list *merge_bases_many_the_repository(struct commit *one, 
int n, struct commit **twos)
 {
struct commit_list *list = NULL;
struct commit_list *result = NULL;
@@ -980,7 +981,7 @@ static struct commit_list 
*get_merge_bases_many_0_the_repository(struct commit *
struct commit_list *result;
int cnt, i;
 
-   result = merge_bases_many(one, n, twos);
+   result = merge_bases_many(the_repository, one, n, twos);
for (i = 0; i < n; i++) {
if (one == twos[i])
return result;
-- 
2.15.1.433.g936d1b9894.dirty



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

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 commit.c | 8 
 commit.h | 3 +--
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/commit.c b/commit.c
index fcda65bee2..a9660f7401 100644
--- a/commit.c
+++ b/commit.c
@@ -210,14 +210,14 @@ static void prepare_commit_graft(struct repository *r)
r->parsed_objects.commit_graft_prepared = 1;
 }
 
-struct commit_graft *lookup_commit_graft_the_repository(const struct object_id 
*oid)
+struct commit_graft *lookup_commit_graft(struct repository *r, const struct 
object_id *oid)
 {
int pos;
-   prepare_commit_graft(the_repository);
-   pos = commit_graft_pos(the_repository, oid->hash);
+   prepare_commit_graft(r);
+   pos = commit_graft_pos(r, oid->hash);
if (pos < 0)
return NULL;
-   return the_repository->parsed_objects.grafts[pos];
+   return r->parsed_objects.grafts[pos];
 }
 
 int for_each_commit_graft(each_commit_graft_fn fn, void *cb_data)
diff --git a/commit.h b/commit.h
index cdd12ad75d..b53053400d 100644
--- a/commit.h
+++ b/commit.h
@@ -181,8 +181,7 @@ typedef int (*each_commit_graft_fn)(const struct 
commit_graft *, void *);
 
 struct commit_graft *read_graft_line(struct strbuf *line);
 int register_commit_graft(struct repository *r, struct commit_graft *, int);
-#define lookup_commit_graft(r, o) lookup_commit_graft_##r(o)
-struct commit_graft *lookup_commit_graft_the_repository(const struct object_id 
*oid);
+struct commit_graft *lookup_commit_graft(struct repository *r, const struct 
object_id *oid);
 
 extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit 
*rev2);
 extern struct commit_list *get_merge_bases_many(struct commit *one, int n, 
struct commit **twos);
-- 
2.15.1.433.g936d1b9894.dirty



[PATCH 162/194] commit: add repository argument to get_merge_bases_many_0

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 commit.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/commit.c b/commit.c
index bd9049a9df..a4f35cd9fc 100644
--- a/commit.c
+++ b/commit.c
@@ -969,7 +969,8 @@ static int remove_redundant(struct commit **array, int cnt)
return filled;
 }
 
-static struct commit_list *get_merge_bases_many_0(struct commit *one,
+#define get_merge_bases_many_0(r, o, n, t, c) get_merge_bases_many_0_##r(o, n, 
t, c)
+static struct commit_list *get_merge_bases_many_0_the_repository(struct commit 
*one,
  int n,
  struct commit **twos,
  int cleanup)
@@ -1014,19 +1015,19 @@ struct commit_list *get_merge_bases_many(struct commit 
*one,
 int n,
 struct commit **twos)
 {
-   return get_merge_bases_many_0(one, n, twos, 1);
+   return get_merge_bases_many_0(the_repository, one, n, twos, 1);
 }
 
 struct commit_list *get_merge_bases_many_dirty(struct commit *one,
   int n,
   struct commit **twos)
 {
-   return get_merge_bases_many_0(one, n, twos, 0);
+   return get_merge_bases_many_0(the_repository, one, n, twos, 0);
 }
 
 struct commit_list *get_merge_bases(struct commit *one, struct commit *two)
 {
-   return get_merge_bases_many_0(one, 1, , 1);
+   return get_merge_bases_many_0(the_repository, one, 1, , 1);
 }
 
 /*
-- 
2.15.1.433.g936d1b9894.dirty



[PATCH 164/194] commit: add repository argument to paint_down_to_common

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 commit.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

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



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

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 commit.c | 10 +-
 commit.h |  3 +--
 2 files changed, 6 insertions(+), 7 deletions(-)

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



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

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 commit.c | 8 
 commit.h | 3 +--
 2 files changed, 5 insertions(+), 6 deletions(-)

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



[PATCH 156/194] migrate cached path to use the_repository

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

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

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

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 commit.c | 14 ++
 object.h |  3 +++
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/commit.c b/commit.c
index 63dac3e601..fcda65bee2 100644
--- a/commit.c
+++ b/commit.c
@@ -197,19 +197,17 @@ static int read_graft_file(struct repository *r, const 
char *graft_file)
return 0;
 }
 
-#define prepare_commit_graft(r) prepare_commit_graft_##r()
-static void prepare_commit_graft_the_repository(void)
+static void prepare_commit_graft(struct repository *r)
 {
-   static int commit_graft_prepared;
char *graft_file;
 
-   if (commit_graft_prepared)
+   if (r->parsed_objects.commit_graft_prepared)
return;
-   graft_file = get_graft_file(the_repository);
-   read_graft_file(the_repository, graft_file);
+   graft_file = get_graft_file(r);
+   read_graft_file(r, graft_file);
/* make sure shallows are read */
-   is_repository_shallow(the_repository);
-   commit_graft_prepared = 1;
+   is_repository_shallow(r);
+   r->parsed_objects.commit_graft_prepared = 1;
 }
 
 struct commit_graft *lookup_commit_graft_the_repository(const struct object_id 
*oid)
diff --git a/object.h b/object.h
index 369295c7c1..14e0d412bb 100644
--- a/object.h
+++ b/object.h
@@ -11,6 +11,8 @@ struct object_parser {
struct commit_graft **grafts;
int grafts_alloc, grafts_nr;
 
+   int commit_graft_prepared;
+
int is_shallow;
struct stat_validity *shallow_stat;
char *alternate_shallow_file;
@@ -32,6 +34,7 @@ extern struct alloc_state the_repository_tag_state;
 extern struct alloc_state the_repository_object_state;
 #define OBJECT_PARSER_INIT { NULL, 0, 0, _repository_buffer_slab, \
NULL, 0, 0, \
+   0, \
-1, _repository_shallow_stat, NULL, \
_repository_blob_state, \
_repository_tree_state, \
-- 
2.15.1.433.g936d1b9894.dirty



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

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 commit.h | 11 ---
 object.h |  6 ++
 repository.c |  4 
 shallow.c| 52 +---
 4 files changed, 39 insertions(+), 34 deletions(-)

diff --git a/commit.h b/commit.h
index 06795f0684..cdd12ad75d 100644
--- a/commit.h
+++ b/commit.h
@@ -196,19 +196,16 @@ extern struct commit_list 
*get_merge_bases_many_dirty(struct commit *one, int n,
 
 struct oid_array;
 struct ref;
-#define register_shallow(r, o) register_shallow_##r(o);
-extern int register_shallow_the_repository(const struct object_id *oid);
+extern int register_shallow(struct repository *r, const struct object_id *oid);
 extern int unregister_shallow(const struct object_id *oid);
 extern int for_each_commit_graft(each_commit_graft_fn, void *);
-extern int is_repository_shallow(void);
-#define is_repository_shallow(r) is_repository_shallow_##r()
-extern int is_repository_shallow_the_repository(void);
+extern int is_repository_shallow(struct repository *r);
+extern int for_each_commit_graft_the_repository(each_commit_graft_fn, void *);
 extern struct commit_list *get_shallow_commits(struct object_array *heads,
int depth, int shallow_flag, int not_shallow_flag);
 extern struct commit_list *get_shallow_commits_by_rev_list(
int ac, const char **av, int shallow_flag, int 
not_shallow_flag);
-#define set_alternate_shallow_file(r, p, o) set_alternate_shallow_file_##r(p, 
o)
-extern void set_alternate_shallow_file_the_repository(const char *path, int 
override);
+extern void set_alternate_shallow_file(struct repository *r, const char *path, 
int override);
 extern int write_shallow_commits(struct strbuf *out, int use_pack_protocol,
 const struct oid_array *extra);
 extern void setup_alternate_shallow(struct lock_file *shallow_lock,
diff --git a/object.h b/object.h
index 65b5326e0f..369295c7c1 100644
--- a/object.h
+++ b/object.h
@@ -11,6 +11,10 @@ struct object_parser {
struct commit_graft **grafts;
int grafts_alloc, grafts_nr;
 
+   int is_shallow;
+   struct stat_validity *shallow_stat;
+   char *alternate_shallow_file;
+
struct alloc_state *blob_state;
struct alloc_state *tree_state;
struct alloc_state *commit_state;
@@ -20,6 +24,7 @@ struct object_parser {
 };
 
 extern struct buffer_slab the_repository_buffer_slab;
+extern struct stat_validity the_repository_shallow_stat;
 extern struct alloc_state the_repository_blob_state;
 extern struct alloc_state the_repository_tree_state;
 extern struct alloc_state the_repository_commit_state;
@@ -27,6 +32,7 @@ extern struct alloc_state the_repository_tag_state;
 extern struct alloc_state the_repository_object_state;
 #define OBJECT_PARSER_INIT { NULL, 0, 0, _repository_buffer_slab, \
NULL, 0, 0, \
+   -1, _repository_shallow_stat, NULL, \
_repository_blob_state, \
_repository_tree_state, \
_repository_commit_state, \
diff --git a/repository.c b/repository.c
index 3ee47b4c5d..64fb6d8b34 100644
--- a/repository.c
+++ b/repository.c
@@ -185,6 +185,10 @@ int repo_init(struct repository *repo, const char *gitdir, 
const char *worktree)
if (worktree)
repo_set_worktree(repo, worktree);
 
+   repo->parsed_objects.is_shallow = -1;
+   repo->parsed_objects.shallow_stat = xcalloc(1, sizeof(
+   *repo->parsed_objects.shallow_stat));
+
ALLOC_GROW(open_repos, open_repos_nr + 1, open_repos_alloc);
open_repos[open_repos_nr++] = repo;
 
diff --git a/shallow.c b/shallow.c
index 2849046477..64a4fcb57f 100644
--- a/shallow.c
+++ b/shallow.c
@@ -14,66 +14,65 @@
 #include "commit-slab.h"
 #include "revision.h"
 #include "list-objects.h"
+#include "repository.h"
 
-static int is_shallow = -1;
-static struct stat_validity shallow_stat;
-static char *alternate_shallow_file;
+struct stat_validity the_repository_shallow_stat;
 
-void set_alternate_shallow_file_the_repository(const char *path, int override)
+void set_alternate_shallow_file(struct repository *r, const char *path, int 
override)
 {
-   if (is_shallow != -1)
+   if (r->parsed_objects.is_shallow != -1)
die("BUG: is_repository_shallow must not be called before 
set_alternate_shallow_file");
-   if (alternate_shallow_file && !override)
+   if (r->parsed_objects.alternate_shallow_file && !override)
return;
-   free(alternate_shallow_file);
-   alternate_shallow_file = xstrdup_or_null(path);
+   free(r->parsed_objects.alternate_shallow_file);
+   r->parsed_objects.alternate_shallow_file = xstrdup_or_null(path);
 }
 
-int register_shallow_the_repository(const struct object_id *oid)
+int register_shallow(struct repository *r, const struct object_id *oid)
 {
struct commit_graft *graft =
xmalloc(sizeof(struct commit_graft));
-   struct commit *commit = 

[PATCH 153/194] shallow: add repository argument to register_shallow

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 builtin/pack-objects.c | 2 +-
 builtin/receive-pack.c | 2 +-
 commit.h   | 3 ++-
 fetch-pack.c   | 2 +-
 shallow.c  | 4 ++--
 upload-pack.c  | 7 ---
 6 files changed, 11 insertions(+), 9 deletions(-)

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



[PATCH 155/194] shallow: add repository argument to is_repository_shallow

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

diff --git a/builtin/fetch.c b/builtin/fetch.c
index 904496fa33..da99363067 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -1352,7 +1352,7 @@ int cmd_fetch(int argc, const char **argv, const char 
*prefix)
if (unshallow) {
if (depth)
die(_("--depth and --unshallow cannot be used 
together"));
-   else if (!is_repository_shallow())
+   else if (!is_repository_shallow(the_repository))
die(_("--unshallow on a complete repository does not 
make sense"));
else
depth = xstrfmt("%d", INFINITE_DEPTH);
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index a16ecc3fe0..9a98154ec4 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -2846,7 +2846,7 @@ static void get_object_list(int ac, const char **av)
setup_revisions(ac, av, , NULL);
 
/* make sure shallows are read */
-   is_repository_shallow();
+   is_repository_shallow(the_repository);
 
while (fgets(line, sizeof(line), stdin) != NULL) {
int len = strlen(line);
@@ -3123,7 +3123,7 @@ int cmd_pack_objects(int argc, const char **argv, const 
char *prefix)
use_bitmap_index = use_bitmap_index_default;
 
/* "hard" reasons not to use bitmaps; these just won't work at all */
-   if (!use_internal_rev_list || (!pack_to_stdout && write_bitmap_index) 
|| is_repository_shallow())
+   if (!use_internal_rev_list || (!pack_to_stdout && write_bitmap_index) 
|| is_repository_shallow(the_repository))
use_bitmap_index = 0;
 
if (pack_to_stdout || !rev_list_all)
diff --git a/builtin/prune.c b/builtin/prune.c
index 06e6de45b5..9a5f231b3a 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -153,7 +153,7 @@ int cmd_prune(int argc, const char **argv, const char 
*prefix)
remove_temporary_files(s);
free(s);
 
-   if (is_repository_shallow())
+   if (is_repository_shallow(the_repository))
prune_shallow(show_only);
 
return 0;
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index b5515df1ae..5911714441 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -879,7 +879,8 @@ int cmd_rev_parse(int argc, const char **argv, const char 
*prefix)
continue;
}
if (!strcmp(arg, "--is-shallow-repository")) {
-   printf("%s\n", is_repository_shallow() ? "true"
+   printf("%s\n",
+   
is_repository_shallow(the_repository) ? "true"
: "false");
continue;
}
diff --git a/commit.c b/commit.c
index 32eda5f7c9..63dac3e601 100644
--- a/commit.c
+++ b/commit.c
@@ -208,7 +208,7 @@ static void prepare_commit_graft_the_repository(void)
graft_file = get_graft_file(the_repository);
read_graft_file(the_repository, graft_file);
/* make sure shallows are read */
-   is_repository_shallow();
+   is_repository_shallow(the_repository);
commit_graft_prepared = 1;
 }
 
diff --git a/commit.h b/commit.h
index 0c854d3679..06795f0684 100644
--- a/commit.h
+++ b/commit.h
@@ -201,6 +201,8 @@ extern int register_shallow_the_repository(const struct 
object_id *oid);
 extern int unregister_shallow(const struct object_id *oid);
 extern int for_each_commit_graft(each_commit_graft_fn, void *);
 extern int is_repository_shallow(void);
+#define is_repository_shallow(r) is_repository_shallow_##r()
+extern int is_repository_shallow_the_repository(void);
 extern struct commit_list *get_shallow_commits(struct object_array *heads,
int depth, int shallow_flag, int not_shallow_flag);
 extern struct commit_list *get_shallow_commits_by_rev_list(
diff --git a/contrib/coccinelle/object_store.cocci 
b/contrib/coccinelle/object_store.cocci
index b56ebef884..b22c57ed43 100644
--- a/contrib/coccinelle/object_store.cocci
+++ b/contrib/coccinelle/object_store.cocci
@@ -67,3 +67,8 @@ expression F;
  unuse_commit_buffer(
 +the_repository,
  E, F)
+
+@@ @@
+ is_repository_shallow(
++the_repository
+ )
diff --git a/fetch-pack.c b/fetch-pack.c
index 1cd738fd62..01e5b36661 

[PATCH 154/194] shallow: add repository argument to check_shallow_file_for_update

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 shallow.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

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



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

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 builtin/index-pack.c |  2 +-
 commit.c | 33 ++---
 commit.h | 17 -
 object.h |  6 +-
 repository.c |  6 ++
 5 files changed, 42 insertions(+), 22 deletions(-)

diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index f78e9d2e65..b2b6021ad3 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -870,7 +870,7 @@ static void sha1_object(const void *data, struct 
object_entry *obj_entry,
}
if (obj->type == OBJ_COMMIT) {
struct commit *commit = (struct commit *) obj;
-   if (detach_commit_buffer(commit, NULL) != data)
+   if (detach_commit_buffer(the_repository, 
commit, NULL) != data)
die("BUG: parse_object_buffer 
transmogrified our buffer");
}
obj->flags |= FLAG_CHECKED;
diff --git a/commit.c b/commit.c
index 8ef8619dec..a5e570f057 100644
--- a/commit.c
+++ b/commit.c
@@ -248,18 +248,29 @@ struct commit_buffer {
unsigned long size;
 };
 define_commit_slab(buffer_slab, struct commit_buffer);
-static struct buffer_slab buffer_slab = COMMIT_SLAB_INIT(1, buffer_slab);
+struct buffer_slab the_repository_buffer_slab = COMMIT_SLAB_INIT(1, 
the_repository_buffer_slab);
 
-void set_commit_buffer_the_repository(struct commit *commit, void *buffer, 
unsigned long size)
+void alloc_buffer_slab(struct repository *r)
 {
-   struct commit_buffer *v = buffer_slab_at(_slab, commit);
+   r->parsed_objects.buffer_slab = xcalloc(1, sizeof(struct buffer_slab));
+   init_buffer_slab(r->parsed_objects.buffer_slab);
+}
+
+void free_commit_slab(struct repository *r)
+{
+   free(r->parsed_objects.buffer_slab);
+}
+
+void set_commit_buffer(struct repository *r, struct commit *commit, void 
*buffer, unsigned long size)
+{
+   struct commit_buffer *v = buffer_slab_at(r->parsed_objects.buffer_slab, 
commit);
v->buffer = buffer;
v->size = size;
 }
 
-const void *get_cached_commit_buffer_the_repository(const struct commit 
*commit, unsigned long *sizep)
+const void *get_cached_commit_buffer(struct repository *r, const struct commit 
*commit, unsigned long *sizep)
 {
-   struct commit_buffer *v = buffer_slab_peek(_slab, commit);
+   struct commit_buffer *v = 
buffer_slab_peek(r->parsed_objects.buffer_slab, commit);
if (!v) {
if (sizep)
*sizep = 0;
@@ -290,25 +301,25 @@ const void *get_commit_buffer(const struct commit 
*commit, unsigned long *sizep)
return ret;
 }
 
-void unuse_commit_buffer_the_repository(const struct commit *commit, const 
void *buffer)
+void unuse_commit_buffer(struct repository *r, const struct commit *commit, 
const void *buffer)
 {
-   struct commit_buffer *v = buffer_slab_peek(_slab, commit);
+   struct commit_buffer *v = 
buffer_slab_peek(r->parsed_objects.buffer_slab, commit);
if (!(v && v->buffer == buffer))
free((void *)buffer);
 }
 
-void free_commit_buffer_the_repository(struct commit *commit)
+void free_commit_buffer(struct repository *r, struct commit *commit)
 {
-   struct commit_buffer *v = buffer_slab_peek(_slab, commit);
+   struct commit_buffer *v = 
buffer_slab_peek(r->parsed_objects.buffer_slab, commit);
if (v) {
FREE_AND_NULL(v->buffer);
v->size = 0;
}
 }
 
-const void *detach_commit_buffer(struct commit *commit, unsigned long *sizep)
+const void *detach_commit_buffer(struct repository *r, struct commit *commit, 
unsigned long *sizep)
 {
-   struct commit_buffer *v = buffer_slab_peek(_slab, commit);
+   struct commit_buffer *v = 
buffer_slab_peek(r->parsed_objects.buffer_slab, commit);
void *ret;
 
if (!v) {
diff --git a/commit.h b/commit.h
index 8892989b1d..0d3ccd7279 100644
--- a/commit.h
+++ b/commit.h
@@ -75,19 +75,20 @@ static inline int parse_commit_the_repository(struct commit 
*item)
 }
 void parse_commit_or_die(struct commit *item);
 
+extern void alloc_buffer_slab(struct repository *r);
+extern void free_commit_slab(struct repository *r);
+
 /*
  * Associate an object buffer with the commit. The ownership of the
  * memory is handed over to the commit, and must be free()-able.
  */
-#define set_commit_buffer(r, c, b, s) set_commit_buffer_##r(c, b, s)
-void set_commit_buffer_the_repository(struct commit *, void *buffer, unsigned 
long size);
+void set_commit_buffer(struct repository *r, struct commit *, void *buffer, 
unsigned long size);
 
 /*
  * Get any cached object buffer associated with the commit. Returns NULL
  * if none. The resulting memory should not be freed.
  */
-#define get_cached_commit_buffer(r, c, s) get_cached_commit_buffer_##r(c, s)
-const void 

[PATCH 152/194] shallow: add repository argument to set_alternate_shallow_file

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 commit.h  | 3 ++-
 environment.c | 2 +-
 git.c | 2 +-
 shallow.c | 2 +-
 4 files changed, 5 insertions(+), 4 deletions(-)

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



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

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 cache.h   | 2 +-
 commit.c  | 2 +-
 environment.c | 6 +++---
 3 files changed, 5 insertions(+), 5 deletions(-)

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



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

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 tree.c | 10 +-
 tree.h |  3 +--
 2 files changed, 6 insertions(+), 7 deletions(-)

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



[PATCH 148/194] commit: add repository argument to free_commit_buffer

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

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

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

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



[PATCH 147/194] commit: add repository argument to unuse_commit_buffer

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

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

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

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

diff --git a/builtin/am.c b/builtin/am.c
index 83bc22649e..7072ec78cb 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1358,7 +1358,7 @@ static void get_commit_info(struct am_state *state, 
struct commit *commit)
die(_("unable to parse commit %s"), 
oid_to_hex(>object.oid));
state->msg = xstrdup(msg + 2);
state->msg_len = strlen(state->msg);
-   unuse_commit_buffer(commit, buffer);
+   unuse_commit_buffer(the_repository, commit, buffer);
 }
 
 /**
diff --git a/builtin/blame.c b/builtin/blame.c
index 815b0c75ed..956df42c67 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -192,7 +192,7 @@ static void get_commit_info(struct commit *commit,
>author_time, >author_tz);
 
if (!detailed) {
-   unuse_commit_buffer(commit, message);
+   unuse_commit_buffer(the_repository, commit, message);
return;
}
 
@@ -206,7 +206,7 @@ static void get_commit_info(struct commit *commit,
else
strbuf_addf(>summary, "(%s)", 
oid_to_hex(>object.oid));
 
-   unuse_commit_buffer(commit, message);
+   unuse_commit_buffer(the_repository, commit, message);
 }
 
 /*
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 1562ac4927..80853bb91a 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -618,7 +618,7 @@ static void handle_commit(struct commit *commit, struct 
rev_info *rev,
  ? strlen(message) : 0),
   reencoded ? reencoded : message ? message : "");
free(reencoded);
-   unuse_commit_buffer(commit, commit_buffer);
+   unuse_commit_buffer(the_repository, commit, commit_buffer);
 
for (i = 0, p = commit->parents; p; p = p->next) {
int mark = get_object_mark(>item->object);
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index ac98556a1d..c54f045ccd 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -263,7 +263,7 @@ static void record_person(int which, struct string_list 
*people,
 {
const char *buffer = get_commit_buffer(commit, NULL);
record_person_from_buf(which, people, buffer);
-   unuse_commit_buffer(commit, buffer);
+   unuse_commit_buffer(the_repository, commit, buffer);
 }
 
 static int cmp_string_list_util_as_integral(const void *a_, const void *b_)
diff --git a/builtin/log.c b/builtin/log.c
index fce7b07df4..7080c5f776 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1025,7 +1025,7 @@ static void make_cover_letter(struct rev_info *rev, int 
use_stdout,
const char *buf = get_commit_buffer(list[i], NULL);
if (has_non_ascii(buf))
need_8bit_cte = 1;
-   unuse_commit_buffer(list[i], buf);
+   unuse_commit_buffer(the_repository, list[i], buf);
}
 
if (!branch_name)
diff --git a/builtin/replace.c b/builtin/replace.c
index d1a939c17b..1a92c0082a 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -403,7 +403,7 @@ static int create_graft(int argc, const char **argv, int 
force)
 
buffer = get_commit_buffer(commit, );
strbuf_add(, buffer, size);
-   unuse_commit_buffer(commit, buffer);
+   unuse_commit_buffer(the_repository, commit, buffer);
 
replace_parents(, argc - 1, [1]);
 
diff --git a/builtin/reset.c b/builtin/reset.c
index ea600bc62a..891dd77a5f 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -123,7 +123,7 @@ static void print_new_head_line(struct commit *commit)
}
else
  

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

2018-02-05 Thread Stefan Beller
From: Brandon Williams 

Signed-off-by: Brandon Williams 
Signed-off-by: Stefan Beller 
---
 commit.c | 29 +++--
 commit.h |  3 +--
 2 files changed, 16 insertions(+), 16 deletions(-)

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



[PATCH 143/194] object: add repository argument to parse_commit_gently

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

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

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

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

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



[PATCH 144/194] commit: add repository argument to parse_commit

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

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

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

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

diff --git a/blame.c b/blame.c
index 592bedd0e0..ccd6a5097b 100644
--- a/blame.c
+++ b/blame.c
@@ -1433,7 +1433,7 @@ static void pass_blame(struct blame_scoreboard *sb, 
struct blame_origin *origin,
 
if (sg_origin[i])
continue;
-   if (parse_commit(p))
+   if (parse_commit(the_repository, p))
continue;
porigin = find(p, origin);
if (!porigin)
@@ -1572,7 +1572,7 @@ void assign_blame(struct blame_scoreboard *sb, int opt)
 * so hold onto it in the meantime.
 */
blame_origin_incref(suspect);
-   parse_commit(commit);
+   parse_commit(the_repository, commit);
if (sb->reverse ||
(!(commit->object.flags & UNINTERESTING) &&
 !(revs->max_age != -1 && commit->date < revs->max_age)))
diff --git a/builtin/checkout.c b/builtin/checkout.c
index cef2b4f2ad..4428fd5da5 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -403,7 +403,7 @@ static void describe_detached_head(const char *msg, struct 
commit *commit)
 {
struct strbuf sb = STRBUF_INIT;
 
-   if (!parse_commit(commit))
+   if (!parse_commit(the_repository, commit))
pp_commit_easy(CMIT_FMT_ONELINE, commit, );
if (print_sha1_ellipsis()) {
fprintf(stderr, "%s %s... %s\n", msg,
@@ -724,7 +724,7 @@ static void describe_one_orphan(struct strbuf *sb, struct 
commit *commit)
strbuf_addstr(sb, "  ");
strbuf_add_unique_abbrev(sb, commit->object.oid.hash, DEFAULT_ABBREV);
strbuf_addch(sb, ' ');
-   if (!parse_commit(commit))
+   if (!parse_commit(the_repository, commit))
pp_commit_easy(CMIT_FMT_ONELINE, commit, sb);
strbuf_addch(sb, '\n');
 }
diff --git a/builtin/commit.c b/builtin/commit.c
index cd3144f9f4..d15592ad45 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1467,7 +1467,7 @@ static void print_summary(const char *prefix, const 
struct object_id *oid,
commit = lookup_commit(the_repository, oid);
if (!commit)
die(_("couldn't look up newly created commit"));
-   if (parse_commit(commit))
+   if (parse_commit(the_repository, commit))
die(_("could not parse newly created commit"));
 
strbuf_addstr(, "format:%h] %s");
@@ -1692,7 +1692,7 @@ int cmd_commit(int argc, const char **argv, const char 
*prefix)
current_head = NULL;
else {
current_head = lookup_commit_or_die(, "HEAD");
-   if (parse_commit(current_head))
+   if (parse_commit(the_repository, current_head))
die(_("could not parse HEAD commit"));
}
verbose = -1; /* unspecified */
diff --git a/builtin/describe.c b/builtin/describe.c
index 5bd0920ebd..870a3a780b 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -249,7 +249,7 @@ static unsigned long finish_depth_computation(
best->depth++;
while (parents) {
struct commit *p = parents->item;
-   

[PATCH 146/194] commit: add repository argument to get_cached_commit_buffer

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

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

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

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



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

2018-02-05 Thread Stefan Beller
From: Brandon Williams 

Signed-off-by: Brandon Williams 
Signed-off-by: Stefan Beller 
---
 commit.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

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



[PATCH 145/194] commit: add repository argument to set_commit_buffer

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

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

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

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

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



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

2018-02-05 Thread Stefan Beller
From: Brandon Williams 

Signed-off-by: Brandon Williams 
Signed-off-by: Stefan Beller 
---
 commit.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

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



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

2018-02-05 Thread Stefan Beller
From: Brandon Williams 

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

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



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

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 commit.c | 10 +-
 commit.h |  3 +--
 2 files changed, 6 insertions(+), 7 deletions(-)

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



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

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 object.c | 4 ++--
 object.h | 3 +--
 2 files changed, 3 insertions(+), 4 deletions(-)

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



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

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

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

diff --git a/alloc.c b/alloc.c
index 277dadd221..0e11c7766a 100644
--- a/alloc.c
+++ b/alloc.c
@@ -32,6 +32,11 @@ struct alloc_state {
void *p;   /* first free node in current allocation */
 };
 
+void *allocate_alloc_state(void)
+{
+   return xcalloc(1, sizeof(struct alloc_state));
+}
+
 static inline void *alloc_node(struct alloc_state *s, size_t node_size)
 {
void *ret;
@@ -48,51 +53,49 @@ static inline void *alloc_node(struct alloc_state *s, 
size_t node_size)
return ret;
 }
 
-static struct alloc_state blob_state;
-void *alloc_blob_node_the_repository(void)
+struct alloc_state the_repository_blob_state;
+void *alloc_blob_node(struct repository *r)
 {
-   struct blob *b = alloc_node(_state, sizeof(struct blob));
+   struct blob *b = alloc_node(r->parsed_objects.blob_state, sizeof(struct 
blob));
b->object.type = OBJ_BLOB;
return b;
 }
 
-static struct alloc_state tree_state;
-void *alloc_tree_node_the_repository(void)
+struct alloc_state the_repository_tree_state;
+void *alloc_tree_node(struct repository *r)
 {
-   struct tree *t = alloc_node(_state, sizeof(struct tree));
+   struct tree *t = alloc_node(r->parsed_objects.tree_state, sizeof(struct 
tree));
t->object.type = OBJ_TREE;
return t;
 }
 
-static struct alloc_state tag_state;
-void *alloc_tag_node_the_repository(void)
+struct alloc_state the_repository_tag_state;
+void *alloc_tag_node(struct repository *r)
 {
-   struct tag *t = alloc_node(_state, sizeof(struct tag));
+   struct tag *t = alloc_node(r->parsed_objects.tag_state, sizeof(struct 
tag));
t->object.type = OBJ_TAG;
return t;
 }
 
-static struct alloc_state object_state;
-void *alloc_object_node_the_repository(void)
+struct alloc_state the_repository_object_state;
+void *alloc_object_node(struct repository *r)
 {
-   struct object *obj = alloc_node(_state, sizeof(union 
any_object));
+   struct object *obj = alloc_node(r->parsed_objects.object_state, 
sizeof(union any_object));
obj->type = OBJ_NONE;
return obj;
 }
 
-static struct alloc_state commit_state;
-
-unsigned int alloc_commit_index_the_repository(void)
+unsigned int alloc_commit_index(struct repository *r)
 {
-   static unsigned int count;
-   return count++;
+   return r->parsed_objects.commit_count++;
 }
 
-void *alloc_commit_node_the_repository(void)
+struct alloc_state the_repository_commit_state;
+void *alloc_commit_node(struct repository *r)
 {
-   struct commit *c = alloc_node(_state, sizeof(struct commit));
+   struct commit *c = alloc_node(r->parsed_objects.commit_state, 
sizeof(struct commit));
c->object.type = OBJ_COMMIT;
-   c->index = alloc_commit_index(the_repository);
+   c->index = alloc_commit_index(r);
return c;
 }
 
@@ -103,9 +106,10 @@ static void report(const char *name, unsigned int count, 
size_t size)
 }
 
 #define REPORT(name, type) \
-report(#name, name##_state.count, name##_state.count * sizeof(type) >> 10)
+report(#name, r->parsed_objects.name##_state->count, \
+ r->parsed_objects.name##_state->count * sizeof(type) >> 10)
 
-void alloc_report_the_repository(void)
+void alloc_report(struct repository *r)
 {
REPORT(blob, struct blob);
REPORT(tree, struct tree);
diff --git a/cache.h b/cache.h
index 40aa3f25aa..ee01daf130 100644
--- a/cache.h
+++ b/cache.h
@@ -1575,20 +1575,14 @@ int decode_85(char *dst, const char *line, int linelen);
 void encode_85(char *buf, const unsigned char *data, int bytes);
 
 /* alloc.c */
-#define alloc_blob_node(r) alloc_blob_node_##r()
-extern void *alloc_blob_node_the_repository(void);
-#define alloc_tree_node(r) alloc_tree_node_##r()
-extern void *alloc_tree_node_the_repository(void);
-#define alloc_commit_node(r) alloc_commit_node_##r()
-extern void *alloc_commit_node_the_repository(void);
-#define alloc_tag_node(r) alloc_tag_node_##r()
-extern void *alloc_tag_node_the_repository(void);
-#define alloc_object_node(r) alloc_object_node_##r()
-extern void *alloc_object_node_the_repository(void);
-#define alloc_report(r) alloc_report_##r()
-extern void alloc_report_the_repository(void);
-#define alloc_commit_index(r) alloc_commit_index_##r()
-extern unsigned int alloc_commit_index_the_repository(void);
+extern void *alloc_blob_node(struct repository *r);
+extern void *alloc_tree_node(struct repository *r);
+extern void *alloc_commit_node(struct 

[PATCH 135/194] alloc: add repository argument to alloc_commit_index

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 alloc.c  | 4 ++--
 cache.h  | 3 ++-
 object.c | 2 +-
 3 files changed, 5 insertions(+), 4 deletions(-)

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



[PATCH 129/194] alloc: add repository argument to alloc_blob_node

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 alloc.c | 2 +-
 blob.c  | 2 +-
 cache.h | 3 ++-
 3 files changed, 4 insertions(+), 3 deletions(-)

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



[PATCH 131/194] alloc: add repository argument to alloc_commit_node

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 alloc.c   | 2 +-
 blame.c   | 2 +-
 cache.h   | 3 ++-
 commit.c  | 2 +-
 merge-recursive.c | 2 +-
 5 files changed, 6 insertions(+), 5 deletions(-)

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



[PATCH 133/194] alloc: add repository argument to alloc_object_node

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 alloc.c  | 2 +-
 cache.h  | 3 ++-
 object.c | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)

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



[PATCH 132/194] alloc: add repository argument to alloc_tag_node

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 alloc.c | 2 +-
 cache.h | 3 ++-
 tag.c   | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)

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



[PATCH 134/194] alloc: add repository argument to alloc_report

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 alloc.c | 2 +-
 cache.h | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

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



[PATCH 130/194] alloc: add repository argument to alloc_tree_node

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 alloc.c | 2 +-
 cache.h | 3 ++-
 tree.c  | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)

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



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

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 alternates.h | 3 +--
 sha1_file.c  | 7 +++
 tmp-objdir.c | 1 +
 3 files changed, 5 insertions(+), 6 deletions(-)

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



[PATCH 128/194] object: add repository argument to object_as_type

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 blob.c | 2 +-
 builtin/fsck.c | 2 +-
 commit.c   | 4 ++--
 object.c   | 2 +-
 object.h   | 3 ++-
 refs.c | 2 +-
 tag.c  | 2 +-
 tree.c | 2 +-
 8 files changed, 10 insertions(+), 9 deletions(-)

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



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

2018-02-05 Thread Stefan Beller
Signed-off-by: Jonathan Nieder 
Signed-off-by: Stefan Beller 
---
 streaming.c | 11 ++-
 streaming.h |  3 +--
 2 files changed, 7 insertions(+), 7 deletions(-)

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



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

2018-02-05 Thread Stefan Beller
Signed-off-by: Jonathan Nieder 
Signed-off-by: Stefan Beller 
---
 streaming.c | 3 ---
 1 file changed, 3 deletions(-)

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



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

2018-02-05 Thread Stefan Beller
Signed-off-by: Jonathan Nieder 
Signed-off-by: Stefan Beller 
---
 streaming.c | 6 +-
 1 file changed, 1 insertion(+), 5 deletions(-)

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



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

2018-02-05 Thread Stefan Beller
Signed-off-by: Jonathan Nieder 
Signed-off-by: Stefan Beller 
---
 streaming.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

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



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

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 object-store.h | 10 +-
 sha1_file.c| 11 ++-
 2 files changed, 11 insertions(+), 10 deletions(-)

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



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

2018-02-05 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 sha1_file.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

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



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

2018-02-05 Thread Stefan Beller
Signed-off-by: Jonathan Nieder 
Signed-off-by: Stefan Beller 
---
 streaming.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

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



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

2018-02-05 Thread Stefan Beller
Signed-off-by: Jonathan Nieder 
Signed-off-by: Stefan Beller 
---
 packfile.c | 4 ++--
 packfile.h | 3 +--
 2 files changed, 3 insertions(+), 4 deletions(-)

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



  1   2   3   4   >