Urgent,

2018-08-26 Thread Juliet Muhammad
i have been trying to contact you


Urgent,

2018-08-26 Thread Juliet Muhammad
i have been trying to contact you


Urgent,

2018-08-26 Thread Juliet Muhammad
i have been trying to contact you


Strange commit count shown by "git describe"

2018-08-26 Thread Daniel Drake
Hi,

Using git 2.17.1 in Ubuntu 18.04 I'm seeing some strange behaviour
when using "git describe" with the repo at
http://github.com/endlessm/linux

First to rewind to a recent commit on the eos3.4 branch and observe:
$ git reset --hard 282b7f72f11f5617947df941a247b0a286faac35

$ git describe
Version_4.15.0-32.35-724859-g282b7f72f11f
$ git describe --match 'Version_*'
Version_4.15.0-32.35-185-g282b7f72f11f

Why is the commit count vastly different when I specify a glob to
match the same (annotated) tag? 724859 vs 185.

185 is what I would have expected.. at least this shows 182 commits:
$ git rev-list Version_4.15.0-32.35..HEAD

Same again with --debug output:

$ git describe --debug
describe HEAD
No exact match on refs or tags, searching to describe
 annotated 724859 Version_4.15.0-32.35
 annotated117 Version_4.15.0-30.32
 annotated124 Ubuntu-4.15.0-29.31
 annotated142 Ubuntu-4.15.0-28.30
 annotated146 Ubuntu-4.15.0-27.29
 annotated149 Ubuntu-4.15.0-26.28
 annotated152 Ubuntu-4.15.0-25.27
 annotated167 Ubuntu-4.15.0-24.26
 annotated919 Release_3.4.6
 annotated926 Release_3.4.4
traversed 728431 commits
more than 10 tags found; listed 10 most recent
gave up search at f30048d13c9ea1763af8c8e448d9e91de116c114
Version_4.15.0-32.35-724859-g282b7f72f11f

$ git describe --debug --match 'Version_*'
describe HEAD
No exact match on refs or tags, searching to describe
finished search at 2261ba7c40893b3659d8b48a77745bfe79e66526
 annotated185 Version_4.15.0-32.35
 annotated289 Version_4.15.0-30.32
 annotated   1100 Version_4.15.0-23.25
 annotated   1234 Version_4.15.0-22.24
 annotated   1274 Version_4.15.0-20.21
 annotated   1813 Version_4.15.0-15.16
 annotated   2949 Version_4.15.0-12.13
 annotated   3564 Version_4.15.0-10.11
 annotated   3607 Version_4.15.0-9.10
 annotated   3754 Version_4.15.0-5.6
traversed 3757 commits
Version_4.15.0-32.35-185-g282b7f72f11f


A similar problem occurs on the current HEAD
(773a8ad2c3b6a54993bc88381b509621aac5be4f) of the eos3.4 branch.
However in that case, even with the --match arg I get a strange commit
count:

$ git describe --match 'Version_*'
Version_4.15.0-33.36-724860-g773a8ad2c3b6

but I would have expected to see a commit count of ~183:
$ git rev-list Version_4.15.0-33.36..HEAD | wc -l
183


Daniel


Urgent,

2018-08-26 Thread Juliet Muhammad
i have been trying to contact you


Urgent,

2018-08-26 Thread Juliet Muhammad
i have been trying to contact you


Possible bug: identical lines added/removed in git diff

2018-08-26 Thread Gabriel Holodak
I think I'm running into a bug with git diff on v2.18.0. When I diff
the attached files, part of the diff ends up looking like:
...
 STARTCHAR U+00F0
 ENCODING 240
 SWIDTH 500 0
-DWIDTH 8 0
-BBX 7 12 1 0
-BITMAP
-12
-0C
-14
-22
-02
-3E
-42
-42
-82
-84
-84
-78
+DWIDTH 8 0
+BBX 8 12 0 0
+BITMAP
+1B
+0E
+1E
+33
+03
+3F
+63
+63
+C3
+C6
+C6
+7C
 ENDCHAR
 STARTCHAR U+00F1
...
where the "DWIDTH 8 0" and "BITMAP" lines are removed and added,
despite being identical. It only seems to be happening around this
section of the file, for the U+00F0 character. This also seems close
to a minimal reproduction of the issue. If I git add --patch and stage
a few hunks, then the duplicated lines seem to disappear.

Steps to reproduce:
git diff --no-index unitera_bold_italic.bdf.old unitera_bold_italic.bdf.new
(It also happens inside a repo, this just seemed the easiest way to
demonstrate.)

Gabriel Holodak


unitera_bold_italic.bdf.new
Description: Binary data


unitera_bold_italic.bdf.old
Description: application/trash


Urgent,

2018-08-26 Thread Juliet Muhammad
i have been trying to contact you


Re: [PATCH 0/9] introducing oideq()

2018-08-26 Thread brian m. carlson
On Sat, Aug 25, 2018 at 04:00:31AM -0400, Jeff King wrote:
> This is a follow-up to the discussion in:
> 
>   https://public-inbox.org/git/20180822030344.ga14...@sigill.intra.peff.net/
> 
> The general idea is that the majority of callers don't care about actual
> plus/minus ordering from oidcmp() and hashcmp(); they just want to know
> if two oids are equal. The stricter equality check can be optimized
> better by the compiler.
> 
> Due to the simplicity of the current code and our inlining, the compiler
> can usually figure this out for now. So I wouldn't expect this patch to
> actually improve performance right away. But as that discussion shows,
> we are likely to take a performance hit as we move to more runtime
> determination of the_hash_algo parameters. Having these callers use the
> more strict form will potentially help us recover that.
> 
> So in that sense we _could_ simply punt on this series until then (and
> it's certainly post-v2.19 material). But I think it's worth doing now,
> simply from a readability/annotation standpoint. IMHO the resulting code
> is more clear (though I've long since taught myself to read !foocmp() as
> equality).

I would quite like to see this series picked up for v2.20.  If we want
to minimize performance regressions with the SHA-256 work, I think it's
important.

Applying the following patch on top of this series causes gcc to inline
both branches, which is pretty much the best we can expect.  I haven't
benchmarked it, though, so I can't say what the actual performance
consequence is.

As for this series itself, other than the typos people have pointed out,
it looks good to me.

diff --git a/cache.h b/cache.h
index 3bb88ac6d0..1c182c6ef6 100644
--- a/cache.h
+++ b/cache.h
@@ -1033,7 +1033,10 @@ static inline int oidcmp(const struct object_id *oid1, 
const struct object_id *o
 
 static inline int hasheq(const unsigned char *sha1, const unsigned char *sha2)
 {
-   return !hashcmp(sha1, sha2);
+   if (the_hash_algo->rawsz == 32) {
+   return !memcmp(sha1, sha2, 32);
+   }
+   return !memcmp(sha1, sha2, 20);
 }
 
 static inline int oideq(const struct object_id *oid1, const struct object_id 
*oid2)
-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204


signature.asc
Description: PGP signature


Re: [GitHub] Your password was reset

2018-08-26 Thread brian m. carlson
On Sun, Aug 26, 2018 at 11:39:30AM -0400, Randall S. Becker wrote:
> My first reactions were:
> 
> 1. Someone is trying a phishing scam on the distribution list. It has 
> happened before.
> 
> 2. Someone set up the wrong email address for their GitHub account.
> 
> I hope it's not #1.

The emails do appear to be coming from GitHub.  I've reached out to
the security team so that they can investigate what's going on.
-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204


signature.asc
Description: PGP signature


Re: [PATCH 02/11] builtin rebase: support `git rebase --onto A...B`

2018-08-26 Thread Johannes Schindelin
Hi Junio,

On Wed, 8 Aug 2018, Junio C Hamano wrote:

> Pratik Karki  writes:
> 
> > This commit implements support for an --onto argument that is actually a
> > "symmetric range" i.e. `...`.
> >
> > The equivalent shell script version of the code offers two different
> > error messages for the cases where there is no merge base vs more than
> > one merge base. Though following the similar approach would be nice,
> > this would create more complexity than it is of current. Currently, for
> 
> Sorry, but it is unclear what you mean by "than it is of current."
> Do you mean we leave it broken at this step in the series for now
> for expediency, with the intention to later revisit and fix it, or
> do you mean something else?

I suggested to drop the distinction, in favor of simpler code. Not for the
time being, but for good.

I reworded the commit message thusly:

builtin rebase: support `git rebase --onto A...B`

This commit implements support for an --onto argument that is actually a
"symmetric range" i.e. `...`.

The equivalent shell script version of the code offers two different
error messages for the cases where there is no merge base vs more than
one merge base.

Though it would be nice to retain this distinction, dropping it makes it
possible to simply use the `get_oid_mb()` function. Besides, it happens
rarely in real-world scenarios.

Therefore, in the interest of keeping the code less complex, let's just
use that function, and live with an error message that does not
distinguish between those two error conditions.

> > @@ -387,7 +389,11 @@ int cmd_rebase(int argc, const char **argv, const char 
> > *prefix)
> > if (!options.onto_name)
> > options.onto_name = options.upstream_name;
> > if (strstr(options.onto_name, "...")) {
> > -   die("TODO");
> > +   if (get_oid_mb(options.onto_name, _base) < 0)
> > +   die(_("'%s': need exactly one merge base"),
> > +   options.onto_name);
> > +   options.onto = lookup_commit_or_die(_base,
> > +   options.onto_name);
> 
> The original is slightly sloppy in that it will misparse
> 
>   rebase --onto 'master^{/log ... message}'
> 
> and this shares the same, which I think is probably OK.

I did run into this recently, but not with an `--onto` option. I forgot
the details (I meant to write it down, and forgot that, too).

Sorry for musing, back on the topic. Yes, it shares the same, and *that*
makes it okay. Remember: this patch series is not about improving `git
rebase` at all. It is about converting from shell script to builtin.

> When this actually becomes problematic, the original can easily be
> salvaged by making it to fall back to the same peel_committish in its
> else clause; I am not sure if this C rewrite is as easily be fixed the
> same way, though.

I will make a note so that I hopefully won't forget.

Thanks,
Dscho

> 
> > } else {
> > options.onto = peel_committish(options.onto_name);
> > if (!options.onto)
> 


Re: Get "Your branch is ahead of 'origin/master'" message when explicitly passing origin url at push command

2018-08-26 Thread Bryan Turner
On Sun, Aug 26, 2018 at 4:39 AM Bentzy Sagiv  wrote:
>
> git version 2.7.4
> __
>
> First try: NOT passing origin url explicitly
>
> ubuntu@ci-bentzy:/var/lib/jenkins$ sudo git push

Since you didn't specify a remote here, Git assumes origin. It uses
your configured "push.default" behavior ("simple" by default) to
determine which refs to push and pushes your master branch to the
origin's master branch. Since it _knows_ it pushed to origin, it
updates your local "refs/remotes/origin/master" ref with the same
commit it just pushed, resulting in an "up-to-date" message.

>
> ubuntu@ci-bentzy:/var/lib/jenkins$ git status
> On branch master
> Your branch is up-to-date with 'origin/master'.
> nothing to commit, working directory clean
> ubuntu@ci-bentzy:/var/lib/jenkins$
>
> __
>
> Second try: passing origin url explicitily
>
> ubuntu@ci-bentzy:/var/lib/jenkins$ sudo git push 
> https://bitbucket.org/OWNER/jenkinsconf-repo.git

This, on the other hand, _is not pushing to a configured remote_. It's
pushing to an explicit URL, which happens to match the URL of a
configured remote. But it's still not a configured remote. It's using
origin's URL, but you didn't push to origin. As a result,
"refs/remotes/origin/master" is not updated, and you get an "ahead"
message.

>
> ubuntu@ci-bentzy:/var/lib/jenkins$ git status
> On branch master
> Your branch is ahead of 'origin/master' by 1 commit.
>   (use "git push" to publish your local commits)
> nothing to commit, working directory clean
>
> __
>
> An additional " sudo git push" (without explicit origin) solves the issue

Everything here is working as intended. If you want to push to a
_remote_, you either need to:
- Name the remote ("git push origin"), or
- Leave it off, so Git will assume origin ("git push")

Pushing to a URL that matches a remote's URL is _not_ pushing to a
remote. It's pushing to an explicit URL.

Hope this helps,
Bryan Turner
>
>
>


RE: [GitHub] Your password was reset

2018-08-26 Thread Randall S. Becker


On August 26, 2018 11:35 AM, pedro rijo, wrote:
> Subject: Re: [GitHub] Your password was reset
> 
> just wondering if there's something going on? Is there a github account
> associated with the mailing list email? seems odd...
> 
> GitHub  escreveu no dia domingo, 26/08/2018 à(s)
> 10:35:
> >
> > Hello amc2399,
> >


My first reactions were:

1. Someone is trying a phishing scam on the distribution list. It has happened 
before.

2. Someone set up the wrong email address for their GitHub account.

I hope it's not #1.

Cheers,
Randall

-- Brief whoami:
  NonStop developer since approximately NonStop(2112884442)
  UNIX developer since approximately 421664400
-- In my real life, I talk too much.





Re: [GitHub] Your password was reset

2018-08-26 Thread pedro rijo
just wondering if there's something going on? Is there a github
account associated with the mailing list email? seems odd...

GitHub  escreveu no dia domingo, 26/08/2018 à(s) 10:35:
>
> Hello amc2399,
>
> We wanted to let you know that your GitHub password was reset.
>
> If you did not perform this action, you can recover access by entering 
> git@vger.kernel.org into the form at https://github.com/password_reset
>
> To see this and other security events for your account, visit 
> https://github.com/settings/security
>
> If you run into problems, please contact support by visiting 
> https://github.com/contact
>
> Please do not reply to this email with your password. We will never ask for 
> your password, and we strongly discourage you from sharing it with anyone.



-- 
Obrigado,

Pedro Rijo


Get "Your branch is ahead of 'origin/master'" message when explicitly passing origin url at push command

2018-08-26 Thread Bentzy Sagiv
git version 2.7.4
__

First try: NOT passing origin url explicitly

ubuntu@ci-bentzy:/var/lib/jenkins$ git remote -v
origin  https://USER @ bitbucket.org/OWNER/jenkinsconf-repo.git (fetch)
origin  https://USER @ bitbucket.org/OWNER/jenkinsconf-repo.git (push)

ubuntu@ci-bentzy:/var/lib/jenkins$ sudo vim jobs/bentzytest1/config.xml
ubuntu@ci-bentzy:/var/lib/jenkins$ sudo git add .
ubuntu@ci-bentzy:/var/lib/jenkins$ sudo git commit -m'First try' -a
[master b8549c3] First try
 1 file changed, 2 insertions(+), 2 deletions(-)
 
ubuntu@ci-bentzy:/var/lib/jenkins$ sudo git push
Password for 'https://USER @ bitbucket.org':
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (5/5), 399 bytes | 0 bytes/s, done.
Total 5 (delta 3), reused 0 (delta 0)
To https://USER @ bitbucket.org/OWNER/jenkinsconf-repo.git
   d2cc229..b8549c3  master -> master
  
ubuntu@ci-bentzy:/var/lib/jenkins$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
ubuntu@ci-bentzy:/var/lib/jenkins$

__

Second try: passing origin url explicitily

ubuntu@ci-bentzy:/var/lib/jenkins$ git remote -v   
origin  https://USER @ bitbucket.org/OWNER/jenkinsconf-repo.git (fetch)
origin  https://USER @ bitbucket.org/OWNER/jenkinsconf-repo.git (push)

ubuntu@ci-bentzy:/var/lib/jenkins$ sudo vim jobs/bentzytest1/config.xml
ubuntu@ci-bentzy:/var/lib/jenkins$ sudo git add .
ubuntu@ci-bentzy:/var/lib/jenkins$ sudo git commit -m'Second try' -a
[master 331ac84] Second try
 1 file changed, 1 insertion(+), 1 deletion(-)
 
ubuntu@ci-bentzy:/var/lib/jenkins$ sudo git push 
https://bitbucket.org/OWNER/jenkinsconf-repo.git
Username for 'https://bitbucket.org': USER
Password for 'https://USER @ bitbucket.org':
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (5/5), 403 bytes | 0 bytes/s, done.
Total 5 (delta 3), reused 0 (delta 0)
To https://bitbucket.org/OWNER/jenkinsconf-repo.git
   7383066..331ac84  master -> master
  
ubuntu@ci-bentzy:/var/lib/jenkins$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)
nothing to commit, working directory clean

__
  
An additional " sudo git push" (without explicit origin) solves the issue



Bentzy Sagiv
 

   

 


Re: [PATCH 2/2] fsck: use oidset for skiplist

2018-08-26 Thread René Scharfe
Am 14.08.2018 um 03:58 schrieb Jeff King:
> Your suggestion can be implemented using khash (my patch below).
> 
>> Before:
>> Benchmark #1: ./git-cat-file --batch-all-objects --buffer --unordered 
>> --batch-check='%(objectname)'
>>
>>   Time (mean ± σ): 269.5 ms ±  26.7 ms[User: 247.7 ms, System: 21.4 
>> ms]
>>
>>   Range (min … max):   240.3 ms … 339.3 ms
>>
>> After:
>> Benchmark #1: ./git-cat-file --batch-all-objects --buffer --unordered 
>> --batch-check='%(objectname)'
>>
>>   Time (mean ± σ): 224.2 ms ±  18.2 ms[User: 201.7 ms, System: 22.1 
>> ms]
>>
>>   Range (min … max):   205.0 ms … 259.0 ms
> 
> Yeah. My best-of-five dropped from 300ms to 247ms. That 300 was using
> the memory pool, though khash's deletion strategy isn't all that
> different (the wasted memory hangs around until the next hash resize,
> but if you're evenly dropping and adding, you likely won't need to
> resize).

With your khash patch:

Benchmark #1: ./git-cat-file --batch-all-objects --buffer --unordered 
--batch-check='%(objectname)'

  Time (mean ± σ): 159.1 ms ±  20.5 ms[User: 140.3 ms, System: 18.5 ms]

  Range (min … max):   140.0 ms … 214.0 ms

So it seems worth it.

> Anyway, here's the khash patch for reference.
> 
> diff --git a/fetch-pack.c b/fetch-pack.c
> index 5714bcbddd..5a86b10a5e 100644
> --- a/fetch-pack.c
> +++ b/fetch-pack.c
> @@ -534,7 +534,7 @@ static int tip_oids_contain(struct oidset *tip_oids,
>* add to "newlist" between calls, the additions will always be for
>* oids that are already in the set.
>*/
> - if (!tip_oids->map.map.tablesize) {
> + if (!tip_oids->map) {
>   add_refs_to_oidset(tip_oids, unmatched);
>   add_refs_to_oidset(tip_oids, newlist);
>   }

The caller shouldn't look at the private parts of the implementation
like this.  tablesize is the allocation count, which becomes non-zero
if at least one entry was added.  tip_oids is only inserted into, never
deleted from, so a count or size function could be used instead as a
cleaner interface.  (In a separate patch..)

> diff --git a/oidset.c b/oidset.c
> index 454c54f933..2964b43b2d 100644
> --- a/oidset.c
> +++ b/oidset.c
> @@ -3,38 +3,44 @@
>  
>  int oidset_contains(const struct oidset *set, const struct object_id *oid)
>  {
> - if (!set->map.map.tablesize)
> + khiter_t pos;
> +
> + if (!set->map)
>   return 0;
> - return !!oidmap_get(>map, oid);
> +
> + pos = kh_get_oid(set->map, *oid);
> + return pos < kh_end(set->map);
>  }
>  
>  int oidset_insert(struct oidset *set, const struct object_id *oid)
>  {
> - struct oidmap_entry *entry;
> + int hash_ret;
>  
> - if (!set->map.map.tablesize)
> - oidmap_init(>map, 0);
> - else if (oidset_contains(set, oid))
> - return 1;
> + if (!set->map)
> + set->map = kh_init_oid();
>  
> - entry = xmalloc(sizeof(*entry));
> - oidcpy(>oid, oid);
> -
> - oidmap_put(>map, entry);
> - return 0;
> + kh_put_oid(set->map, *oid, _ret);
> + return !hash_ret;
>  }

So initialization is deferred to the first insert, and the empty set
can be represented in two ways -- map == NULL and map->size == 0.

I wondered about the performance impact of all those NULL checks at
insert and lookup and converted it to stack storage, with a dirty
hand-rolled oidset_clear() implementation.  It wasn't any faster.

>  
>  int oidset_remove(struct oidset *set, const struct object_id *oid)
>  {
> - struct oidmap_entry *entry;
> + khiter_t pos;
>  
> - entry = oidmap_remove(>map, oid);
> - free(entry);
> + if (!set->map)
> + return 0;
> +
> + pos = kh_get_oid(set->map, *oid);
> + if (pos < kh_end(set->map)) {
> + kh_del_oid(set->map, pos);
> + return 1;
> + }
>  
> - return (entry != NULL);
> + return 0;
>  }
>  
>  void oidset_clear(struct oidset *set)
>  {
> - oidmap_free(>map, 1);
> + kh_destroy_oid(set->map);
> + set->map = NULL;
>  }
> diff --git a/oidset.h b/oidset.h
> index 40ec5f87fe..4c4c5a42fe 100644
> --- a/oidset.h
> +++ b/oidset.h
> @@ -2,6 +2,7 @@
>  #define OIDSET_H
>  
>  #include "oidmap.h"

This can go.

> +#include "khash.h"
>  
>  /**
>   * This API is similar to sha1-array, in that it maintains a set of object 
> ids
> @@ -15,19 +16,34 @@
>   *  table overhead.
>   */
>  
> +static inline unsigned int oid_hash(const struct object_id oid)
> +{
> + unsigned int hash;
> + memcpy(, oid.hash, sizeof(hash));
> + return hash;
> +}
> +
> +static inline int oid_equal(const struct object_id a,
> + const struct object_id b)
> +{
> + return !oidcmp(, );
> +}

Look, it's oideq() from that other series in disguise! :)

> +
> +KHASH_INIT(oid, struct object_id, int, 0, oid_hash, oid_equal)

Note to self: The 0 is for kh_is_map, which means that no values are
kept and the given value type (int) doesn't 

[PATCH 13/21] sha1-file.c: remove implicit dependency on the_index

2018-08-26 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 builtin/difftool.c |  2 +-
 builtin/hash-object.c  |  2 +-
 builtin/replace.c  |  2 +-
 builtin/update-index.c |  2 +-
 cache.h|  4 ++--
 diff.c | 20 -
 notes-merge.c  |  2 +-
 read-cache.c   | 25 -
 sha1-file.c| 50 --
 9 files changed, 61 insertions(+), 48 deletions(-)

diff --git a/builtin/difftool.c b/builtin/difftool.c
index cdd585ca76..e7023e3adf 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -112,7 +112,7 @@ static int use_wt_file(const char *workdir, const char 
*name,
int fd = open(buf.buf, O_RDONLY);
 
if (fd >= 0 &&
-   !index_fd(_oid, fd, , OBJ_BLOB, name, 0)) {
+   !index_fd(_index, _oid, fd, , OBJ_BLOB, name, 0)) 
{
if (is_null_oid(oid)) {
oidcpy(oid, _oid);
use = 1;
diff --git a/builtin/hash-object.c b/builtin/hash-object.c
index 9ada4f4dfd..d6f06ea32f 100644
--- a/builtin/hash-object.c
+++ b/builtin/hash-object.c
@@ -40,7 +40,7 @@ static void hash_fd(int fd, const char *type, const char 
*path, unsigned flags,
if (fstat(fd, ) < 0 ||
(literally
 ? hash_literally(, fd, type, flags)
-: index_fd(, fd, , type_from_string(type), path, flags)))
+: index_fd(_index, , fd, , type_from_string(type), 
path, flags)))
die((flags & HASH_WRITE_OBJECT)
? "Unable to add %s to database"
: "Unable to hash %s", path);
diff --git a/builtin/replace.c b/builtin/replace.c
index 4f05791f3e..e0b16ad44b 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -295,7 +295,7 @@ static int import_object(struct object_id *oid, enum 
object_type type,
close(fd);
return -1;
}
-   if (index_fd(oid, fd, , type, NULL, flags) < 0)
+   if (index_fd(_index, oid, fd, , type, NULL, flags) < 0)
return error(_("unable to write object to database"));
/* index_fd close()s fd for us */
}
diff --git a/builtin/update-index.c b/builtin/update-index.c
index fe84003b4f..3086212fdb 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -282,7 +282,7 @@ static int add_one_path(const struct cache_entry *old, 
const char *path, int len
fill_stat_cache_info(ce, st);
ce->ce_mode = ce_mode_from_stat(old, st->st_mode);
 
-   if (index_path(>oid, path, st,
+   if (index_path(_index, >oid, path, st,
   info_only ? 0 : HASH_WRITE_OBJECT)) {
discard_cache_entry(ce);
return -1;
diff --git a/cache.h b/cache.h
index 218edaa198..0964611997 100644
--- a/cache.h
+++ b/cache.h
@@ -787,8 +787,8 @@ extern int ie_modified(struct index_state *, const struct 
cache_entry *, struct
 #define HASH_WRITE_OBJECT 1
 #define HASH_FORMAT_CHECK 2
 #define HASH_RENORMALIZE  4
-extern int index_fd(struct object_id *oid, int fd, struct stat *st, enum 
object_type type, const char *path, unsigned flags);
-extern int index_path(struct object_id *oid, const char *path, struct stat 
*st, unsigned flags);
+extern int index_fd(struct index_state *istate, struct object_id *oid, int fd, 
struct stat *st, enum object_type type, const char *path, unsigned flags);
+extern int index_path(struct index_state *istate, struct object_id *oid, const 
char *path, struct stat *st, unsigned flags);
 
 /*
  * Record to sd the data from st that we use to check whether a file
diff --git a/diff.c b/diff.c
index 81582679e0..ec3029df82 100644
--- a/diff.c
+++ b/diff.c
@@ -4252,7 +4252,7 @@ static void run_diff_cmd(const char *pgm,
fprintf(o->file, "* Unmerged path %s\n", name);
 }
 
-static void diff_fill_oid_info(struct diff_filespec *one)
+static void diff_fill_oid_info(struct diff_filespec *one, struct index_state 
*istate)
 {
if (DIFF_FILE_VALID(one)) {
if (!one->oid_valid) {
@@ -4263,7 +4263,7 @@ static void diff_fill_oid_info(struct diff_filespec *one)
}
if (lstat(one->path, ) < 0)
die_errno("stat '%s'", one->path);
-   if (index_path(>oid, one->path, , 0))
+   if (index_path(istate, >oid, one->path, , 0))
die("cannot hash %s", one->path);
}
}
@@ -4311,8 +4311,8 @@ static void run_diff(struct diff_filepair *p, struct 
diff_options *o)
return;
}
 
-   diff_fill_oid_info(one);
-   diff_fill_oid_info(two);
+   diff_fill_oid_info(one, o->repo->index);
+   diff_fill_oid_info(two, o->repo->index);
 
if (!pgm &&
DIFF_FILE_VALID(one) && DIFF_FILE_VALID(two) 

[PATCH 09/21] ll-merge.c: remove implicit dependency on the_index

2018-08-26 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 apply.c|  9 ++---
 builtin/checkout.c |  3 ++-
 diff.c |  2 +-
 ll-merge.c | 17 +
 ll-merge.h |  5 -
 merge-blobs.c  |  3 ++-
 merge-recursive.c  |  3 ++-
 notes-merge.c  |  3 ++-
 rerere.c   | 10 ++
 9 files changed, 34 insertions(+), 21 deletions(-)

diff --git a/apply.c b/apply.c
index e485fbc6bc..ea111ab13f 100644
--- a/apply.c
+++ b/apply.c
@@ -3467,7 +3467,8 @@ static int load_preimage(struct apply_state *state,
return 0;
 }
 
-static int three_way_merge(struct image *image,
+static int three_way_merge(struct apply_state *state,
+  struct image *image,
   char *path,
   const struct object_id *base,
   const struct object_id *ours,
@@ -3483,7 +3484,9 @@ static int three_way_merge(struct image *image,
status = ll_merge(, path,
  _file, "base",
  _file, "ours",
- _file, "theirs", NULL);
+ _file, "theirs",
+ state->repo->index,
+ NULL);
free(base_file.ptr);
free(our_file.ptr);
free(their_file.ptr);
@@ -3595,7 +3598,7 @@ static int try_threeway(struct apply_state *state,
clear_image(_image);
 
/* in-core three-way merge between post and our using pre as base */
-   status = three_way_merge(image, patch->new_name,
+   status = three_way_merge(state, image, patch->new_name,
 _oid, _oid, _oid);
if (status < 0) {
if (state->apply_verbosity > verbosity_silent)
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 29ef50013d..cd9be50161 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -208,7 +208,8 @@ static int checkout_merged(int pos, const struct checkout 
*state)
 * merge.renormalize set, too
 */
status = ll_merge(_buf, path, , "base",
- , "ours", , "theirs", NULL);
+ , "ours", , "theirs",
+ state->istate, NULL);
free(ancestor.ptr);
free(ours.ptr);
free(theirs.ptr);
diff --git a/diff.c b/diff.c
index a702ed98bb..81582679e0 100644
--- a/diff.c
+++ b/diff.c
@@ -3637,7 +3637,7 @@ static void builtin_checkdiff(const char *name_a, const 
char *name_b,
data.lineno = 0;
data.o = o;
data.ws_rule = whitespace_rule(attr_path);
-   data.conflict_marker_size = ll_merge_marker_size(attr_path);
+   data.conflict_marker_size = ll_merge_marker_size(o->repo->index, 
attr_path);
 
if (fill_mmfile(o->repo, , one) < 0 ||
fill_mmfile(o->repo, , two) < 0)
diff --git a/ll-merge.c b/ll-merge.c
index 0e2800f7bb..c339ef8ae8 100644
--- a/ll-merge.c
+++ b/ll-merge.c
@@ -336,10 +336,10 @@ static const struct ll_merge_driver 
*find_ll_merge_driver(const char *merge_attr
return _merge_drv[LL_TEXT_MERGE];
 }
 
-static void normalize_file(mmfile_t *mm, const char *path)
+static void normalize_file(mmfile_t *mm, const char *path, struct index_state 
*istate)
 {
struct strbuf strbuf = STRBUF_INIT;
-   if (renormalize_buffer(_index, path, mm->ptr, mm->size, )) {
+   if (renormalize_buffer(istate, path, mm->ptr, mm->size, )) {
free(mm->ptr);
mm->size = strbuf.len;
mm->ptr = strbuf_detach(, NULL);
@@ -351,6 +351,7 @@ int ll_merge(mmbuffer_t *result_buf,
 mmfile_t *ancestor, const char *ancestor_label,
 mmfile_t *ours, const char *our_label,
 mmfile_t *theirs, const char *their_label,
+struct index_state *istate,
 const struct ll_merge_options *opts)
 {
static struct attr_check *check;
@@ -363,15 +364,15 @@ int ll_merge(mmbuffer_t *result_buf,
opts = _opts;
 
if (opts->renormalize) {
-   normalize_file(ancestor, path);
-   normalize_file(ours, path);
-   normalize_file(theirs, path);
+   normalize_file(ancestor, path, istate);
+   normalize_file(ours, path, istate);
+   normalize_file(theirs, path, istate);
}
 
if (!check)
check = attr_check_initl("merge", "conflict-marker-size", NULL);
 
-   if (!git_check_attr(_index, path, check)) {
+   if (!git_check_attr(istate, path, check)) {
ll_driver_name = check->items[0].value;
if (check->items[1].value) {
marker_size = atoi(check->items[1].value);
@@ -391,14 +392,14 @@ int ll_merge(mmbuffer_t *result_buf,
  opts, marker_size);
 }
 
-int ll_merge_marker_size(const char *path)
+int ll_merge_marker_size(struct index_state *istate, const char *path)
 {
static struct attr_check 

[PATCH 02/21] read-cache.c: remove 'const' from index_has_changes()

2018-08-26 Thread Nguyễn Thái Ngọc Duy
This function calls do_diff_cache() which eventually needs to set this
"istate" to unpack_options->src_index (*). This is an unfornate fact
that unpack_trees() _will_ destroy src_index so we can't really pass a
const index_state there. Just remove 'const'.

(*) Right now diff_cache() in diff-lib.c assigns the_index to
src_index. But the plan is to get rid of the_index, so it should
be 'istate' from here that gets assigned to src_index.

Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 builtin/reset.c   |   1 +
 cache.h   |   2 +-
 diff.c| 174 +++---
 diff.h|   3 +
 diffcore-break.c  |  12 ++--
 diffcore-delta.c  |  12 ++--
 diffcore-rename.c |  35 ++
 diffcore.h|  13 ++--
 line-log.c|  21 +++---
 read-cache.c  |   2 +-
 10 files changed, 162 insertions(+), 113 deletions(-)

diff --git a/builtin/reset.c b/builtin/reset.c
index 11cd0dcb8c..6d37a35e2e 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -159,6 +159,7 @@ static int read_from_tree(const struct pathspec *pathspec,
opt.format_callback = update_index_from_diff;
opt.format_callback_data = _to_add;
opt.flags.override_submodule_config = 1;
+   opt.repo = the_repository;
 
if (do_diff_cache(tree_oid, ))
return 1;
diff --git a/cache.h b/cache.h
index b1fd3d58ab..31013ce8af 100644
--- a/cache.h
+++ b/cache.h
@@ -703,7 +703,7 @@ extern int unmerged_index(const struct index_state *);
  * provided, the space-separated list of files that differ will be appended
  * to it.
  */
-extern int index_has_changes(const struct index_state *istate,
+extern int index_has_changes(struct index_state *istate,
 struct tree *tree,
 struct strbuf *sb);
 
diff --git a/diff.c b/diff.c
index 145cfbae59..8040f8b0f0 100644
--- a/diff.c
+++ b/diff.c
@@ -554,14 +554,15 @@ static int count_lines(const char *data, int size)
return count;
 }
 
-static int fill_mmfile(mmfile_t *mf, struct diff_filespec *one)
+static int fill_mmfile(struct repository *repo, mmfile_t *mf,
+  struct diff_filespec *one)
 {
if (!DIFF_FILE_VALID(one)) {
mf->ptr = (char *)""; /* does not matter */
mf->size = 0;
return 0;
}
-   else if (diff_populate_filespec(one, 0))
+   else if (diff_populate_filespec(repo, one, 0))
return -1;
 
mf->ptr = one->data;
@@ -570,11 +571,12 @@ static int fill_mmfile(mmfile_t *mf, struct diff_filespec 
*one)
 }
 
 /* like fill_mmfile, but only for size, so we can avoid retrieving blob */
-static unsigned long diff_filespec_size(struct diff_filespec *one)
+static unsigned long diff_filespec_size(struct repository *repo,
+   struct diff_filespec *one)
 {
if (!DIFF_FILE_VALID(one))
return 0;
-   diff_populate_filespec(one, CHECK_SIZE_ONLY);
+   diff_populate_filespec(repo, one, CHECK_SIZE_ONLY);
return one->size;
 }
 
@@ -2965,18 +2967,19 @@ static void show_dirstat(struct diff_options *options)
}
 
if (DIFF_FILE_VALID(p->one) && DIFF_FILE_VALID(p->two)) {
-   diff_populate_filespec(p->one, 0);
-   diff_populate_filespec(p->two, 0);
-   diffcore_count_changes(p->one, p->two, NULL, NULL,
+   diff_populate_filespec(options->repo, p->one, 0);
+   diff_populate_filespec(options->repo, p->two, 0);
+   diffcore_count_changes(options->repo,
+  p->one, p->two, NULL, NULL,
   , );
diff_free_filespec_data(p->one);
diff_free_filespec_data(p->two);
} else if (DIFF_FILE_VALID(p->one)) {
-   diff_populate_filespec(p->one, CHECK_SIZE_ONLY);
+   diff_populate_filespec(options->repo, p->one, 
CHECK_SIZE_ONLY);
copied = added = 0;
diff_free_filespec_data(p->one);
} else if (DIFF_FILE_VALID(p->two)) {
-   diff_populate_filespec(p->two, CHECK_SIZE_ONLY);
+   diff_populate_filespec(options->repo, p->two, 
CHECK_SIZE_ONLY);
copied = 0;
added = p->two->size;
diff_free_filespec_data(p->two);
@@ -3250,7 +3253,8 @@ static void emit_binary_diff(struct diff_options *o,
emit_binary_diff_body(o, two, one);
 }
 
-int diff_filespec_is_binary(struct diff_filespec *one)
+int diff_filespec_is_binary(struct repository *repo,
+   struct diff_filespec *one)
 {
if (one->is_binary == -1) {
diff_filespec_load_driver(one);
@@ -3258,7 +3262,7 @@ int 

[PATCH 06/21] diff.c: remove implicit dependency on the_index

2018-08-26 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 blame.c  | 20 +++-
 builtin/diff.c   |  2 +-
 builtin/log.c|  2 +-
 builtin/merge.c  |  2 +-
 builtin/range-diff.c |  2 +-
 diff-no-index.c  |  9 +++--
 diff.c   |  4 ++--
 diff.h   |  4 ++--
 merge-recursive.c|  2 +-
 notes-merge.c|  4 ++--
 patch-ids.c  |  2 +-
 read-cache.c |  2 +-
 revision.c   |  2 +-
 tree-diff.c  |  2 +-
 14 files changed, 33 insertions(+), 26 deletions(-)

diff --git a/blame.c b/blame.c
index 366d8d85e7..90a32938ad 100644
--- a/blame.c
+++ b/blame.c
@@ -543,8 +543,9 @@ static int fill_blob_sha1_and_mode(struct repository *repo,
  * We have an origin -- check if the same path exists in the
  * parent and return an origin structure to represent it.
  */
-static struct blame_origin *find_origin(struct commit *parent,
- struct blame_origin *origin)
+static struct blame_origin *find_origin(struct repository *repo,
+   struct commit *parent,
+   struct blame_origin *origin)
 {
struct blame_origin *porigin;
struct diff_options diff_opts;
@@ -564,7 +565,7 @@ static struct blame_origin *find_origin(struct commit 
*parent,
 * and origin first.  Most of the time they are the
 * same and diff-tree is fairly efficient about this.
 */
-   diff_setup(_opts);
+   diff_setup(_opts, repo);
diff_opts.flags.recursive = 1;
diff_opts.detect_rename = 0;
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
@@ -631,14 +632,15 @@ static struct blame_origin *find_origin(struct commit 
*parent,
  * We have an origin -- find the path that corresponds to it in its
  * parent and return an origin structure to represent it.
  */
-static struct blame_origin *find_rename(struct commit *parent,
- struct blame_origin *origin)
+static struct blame_origin *find_rename(struct repository *repo,
+   struct commit *parent,
+   struct blame_origin *origin)
 {
struct blame_origin *porigin = NULL;
struct diff_options diff_opts;
int i;
 
-   diff_setup(_opts);
+   diff_setup(_opts, repo);
diff_opts.flags.recursive = 1;
diff_opts.detect_rename = DIFF_DETECT_RENAME;
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
@@ -1262,7 +1264,7 @@ static void find_copy_in_parent(struct blame_scoreboard 
*sb,
if (!unblamed)
return; /* nothing remains for this target */
 
-   diff_setup(_opts);
+   diff_setup(_opts, sb->repo);
diff_opts.flags.recursive = 1;
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
 
@@ -1444,7 +1446,7 @@ static void pass_blame(struct blame_scoreboard *sb, 
struct blame_origin *origin,
 * common cases, then we look for renames in the second pass.
 */
for (pass = 0; pass < 2 - sb->no_whole_file_rename; pass++) {
-   struct blame_origin *(*find)(struct commit *, struct 
blame_origin *);
+   struct blame_origin *(*find)(struct repository *, struct commit 
*, struct blame_origin *);
find = pass ? find_rename : find_origin;
 
for (i = 0, sg = first_scapegoat(revs, commit, sb->reverse);
@@ -1457,7 +1459,7 @@ static void pass_blame(struct blame_scoreboard *sb, 
struct blame_origin *origin,
continue;
if (parse_commit(p))
continue;
-   porigin = find(p, origin);
+   porigin = find(sb->repo, p, origin);
if (!porigin)
continue;
if (!oidcmp(>blob_oid, >blob_oid)) {
diff --git a/builtin/diff.c b/builtin/diff.c
index 361a3c3ed3..ab89b06d18 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -339,7 +339,7 @@ int cmd_diff(int argc, const char **argv, const char 
*prefix)
}
if (no_index)
/* If this is a no-index diff, just run it and exit there. */
-   diff_no_index(, argc, argv);
+   diff_no_index(the_repository, , argc, argv);
 
/* Otherwise, we are doing the usual "git" diff */
rev.diffopt.skip_stat_unmatch = !!diff_auto_refresh_index;
diff --git a/builtin/log.c b/builtin/log.c
index b62082472c..33084102e0 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1361,7 +1361,7 @@ static void prepare_bases(struct base_tree_info *bases,
return;
 
init_commit_base(_base);
-   diff_setup();
+   diff_setup(, the_repository);
diffopt.flags.recursive = 1;
diff_setup_done();
 
diff --git a/builtin/merge.c b/builtin/merge.c
index 8f4a5065c2..0a37d5ef2c 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -452,7 

[PATCH 05/21] grep.c: remove implicit dependency on the_index

2018-08-26 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 builtin/grep.c |  4 ++--
 builtin/log.c  |  2 +-
 grep.c | 13 -
 grep.h |  7 +--
 revision.c |  4 ++--
 5 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/builtin/grep.c b/builtin/grep.c
index 601f801158..0667ffde84 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -904,9 +904,9 @@ int cmd_grep(int argc, const char **argv, const char 
*prefix)
OPT_END()
};
 
-   init_grep_defaults();
+   init_grep_defaults(the_repository);
git_config(grep_cmd_config, NULL);
-   grep_init(, prefix);
+   grep_init(, the_repository, prefix);
 
/*
 * If there is no -- then the paths must exist in the working
diff --git a/builtin/log.c b/builtin/log.c
index f32a07f6a9..b62082472c 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -115,7 +115,7 @@ static int log_line_range_callback(const struct option 
*option, const char *arg,
 
 static void init_log_defaults(void)
 {
-   init_grep_defaults();
+   init_grep_defaults(the_repository);
init_diff_ui_defaults();
 
decoration_style = auto_decoration_style();
diff --git a/grep.c b/grep.c
index e146ff20bb..51c8beda43 100644
--- a/grep.c
+++ b/grep.c
@@ -42,7 +42,7 @@ static void color_set(char *dst, const char *color_bytes)
  * We could let the compiler do this, but without C99 initializers
  * the code gets unwieldy and unreadable, so...
  */
-void init_grep_defaults(void)
+void init_grep_defaults(struct repository *repo)
 {
struct grep_opt *opt = _defaults;
static int run_once;
@@ -52,6 +52,7 @@ void init_grep_defaults(void)
run_once++;
 
memset(opt, 0, sizeof(*opt));
+   opt->repo = repo;
opt->relative = 1;
opt->pathname = 1;
opt->max_depth = -1;
@@ -149,12 +150,13 @@ int grep_config(const char *var, const char *value, void 
*cb)
  * default values from the template we read the configuration
  * information in an earlier call to git_config(grep_config).
  */
-void grep_init(struct grep_opt *opt, const char *prefix)
+void grep_init(struct grep_opt *opt, struct repository *repo, const char 
*prefix)
 {
struct grep_opt *def = _defaults;
int i;
 
memset(opt, 0, sizeof(*opt));
+   opt->repo = repo;
opt->prefix = prefix;
opt->prefix_length = (prefix && *prefix) ? strlen(prefix) : 0;
opt->pattern_tail = >pattern_list;
@@ -1708,7 +1710,8 @@ static int look_ahead(struct grep_opt *opt,
return 0;
 }
 
-static int fill_textconv_grep(struct userdiff_driver *driver,
+static int fill_textconv_grep(struct repository *repo,
+ struct userdiff_driver *driver,
  struct grep_source *gs)
 {
struct diff_filespec *df;
@@ -1741,7 +1744,7 @@ static int fill_textconv_grep(struct userdiff_driver 
*driver,
 * structure.
 */
grep_read_lock();
-   size = fill_textconv(the_repository, driver, df, );
+   size = fill_textconv(repo, driver, df, );
grep_read_unlock();
free_filespec(df);
 
@@ -1837,7 +1840,7 @@ static int grep_source_1(struct grep_opt *opt, struct 
grep_source *gs, int colle
 
try_lookahead = should_lookahead(opt);
 
-   if (fill_textconv_grep(textconv, gs) < 0)
+   if (fill_textconv_grep(opt->repo, textconv, gs) < 0)
return 0;
 
bol = gs->buf;
diff --git a/grep.h b/grep.h
index 0ba62a11c5..3651183971 100644
--- a/grep.h
+++ b/grep.h
@@ -36,6 +36,8 @@ typedef int pcre2_jit_stack;
 #include "thread-utils.h"
 #include "userdiff.h"
 
+struct repository;
+
 enum grep_pat_token {
GREP_PATTERN,
GREP_PATTERN_HEAD,
@@ -136,6 +138,7 @@ struct grep_opt {
struct grep_pat *header_list;
struct grep_pat **header_tail;
struct grep_expr *pattern_expression;
+   struct repository *repo;
const char *prefix;
int prefix_length;
regex_t regexp;
@@ -183,9 +186,9 @@ struct grep_opt {
void *output_priv;
 };
 
-extern void init_grep_defaults(void);
+extern void init_grep_defaults(struct repository *);
 extern int grep_config(const char *var, const char *value, void *);
-extern void grep_init(struct grep_opt *, const char *prefix);
+extern void grep_init(struct grep_opt *, struct repository *repo, const char 
*prefix);
 void grep_commit_pattern_type(enum grep_pattern_type, struct grep_opt *opt);
 
 extern void append_grep_pat(struct grep_opt *opt, const char *pat, size_t 
patlen, const char *origin, int no, enum grep_pat_token t);
diff --git a/revision.c b/revision.c
index de4dce600d..3457064ff3 100644
--- a/revision.c
+++ b/revision.c
@@ -1464,8 +1464,8 @@ void init_revisions(struct rev_info *revs, const char 
*prefix)
revs->commit_format = CMIT_FMT_DEFAULT;
revs->expand_tabs_in_log_default = 8;
 
-   init_grep_defaults();
-   grep_init(>grep_filter, prefix);
+   

[PATCH 20/21] wt-status.c: remove implicit dependency on the_index

2018-08-26 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 builtin/commit.c |  2 +-
 builtin/pull.c   |  3 ++-
 sequencer.c  |  6 ++---
 wt-status.c  | 64 
 wt-status.h  | 17 +
 5 files changed, 56 insertions(+), 36 deletions(-)

diff --git a/builtin/commit.c b/builtin/commit.c
index 731e98fd63..64adc078d7 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -183,7 +183,7 @@ static void determine_whence(struct wt_status *s)
 
 static void status_init_config(struct wt_status *s, config_fn_t fn)
 {
-   wt_status_prepare(s);
+   wt_status_prepare(s, the_repository);
init_diff_ui_defaults();
git_config(fn, s);
determine_whence(s);
diff --git a/builtin/pull.c b/builtin/pull.c
index 73e06625c8..ce333ac708 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -887,7 +887,8 @@ int cmd_pull(int argc, const char **argv, const char 
*prefix)
die(_("Updating an unborn branch with changes added to 
the index."));
 
if (!autostash)
-   require_clean_work_tree(N_("pull with rebase"),
+   require_clean_work_tree(the_repository,
+   N_("pull with rebase"),
_("please commit or stash them."), 1, 0);
 
if (get_rebase_fork_point(_fork_point, repo, *refspecs))
diff --git a/sequencer.c b/sequencer.c
index cb7fefde9c..4dbbc7389d 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -2679,7 +2679,7 @@ static int do_exec(const char *command_line)
if (discard_cache() < 0 || read_cache() < 0)
return error(_("could not read index"));
 
-   dirty = require_clean_work_tree("rebase", NULL, 1, 1);
+   dirty = require_clean_work_tree(the_repository, "rebase", NULL, 1, 1);
 
if (status) {
warning(_("execution failed: %s\n%s"
@@ -3550,10 +3550,10 @@ static int commit_staged_changes(struct replay_opts 
*opts,
unsigned int flags = ALLOW_EMPTY | EDIT_MSG;
unsigned int final_fixup = 0, is_clean;
 
-   if (has_unstaged_changes(1))
+   if (has_unstaged_changes(the_repository, 1))
return error(_("cannot rebase: You have unstaged changes."));
 
-   is_clean = !has_uncommitted_changes(0);
+   is_clean = !has_uncommitted_changes(the_repository, 0);
 
if (file_exists(rebase_path_amend())) {
struct strbuf rev = STRBUF_INIT;
diff --git a/wt-status.c b/wt-status.c
index 5ffab61015..57bc2aac0f 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -119,9 +119,11 @@ static void status_printf_more(struct wt_status *s, const 
char *color,
va_end(ap);
 }
 
-void wt_status_prepare(struct wt_status *s)
+void wt_status_prepare(struct wt_status *s,
+  struct repository *repo)
 {
memset(s, 0, sizeof(*s));
+   s->repo = repo;
memcpy(s->color_palette, default_wt_status_colors,
   sizeof(default_wt_status_colors));
s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
@@ -494,19 +496,19 @@ static void wt_status_collect_changed_cb(struct 
diff_queue_struct *q,
}
 }
 
-static int unmerged_mask(const char *path)
+static int unmerged_mask(struct index_state *istate, const char *path)
 {
int pos, mask;
const struct cache_entry *ce;
 
-   pos = cache_name_pos(path, strlen(path));
+   pos = index_name_pos(istate, path, strlen(path));
if (0 <= pos)
return 0;
 
mask = 0;
pos = -pos-1;
-   while (pos < active_nr) {
-   ce = active_cache[pos++];
+   while (pos < istate->cache_nr) {
+   ce = istate->cache[pos++];
if (strcmp(ce->name, path) || !ce_stage(ce))
break;
mask |= (1 << (ce_stage(ce) - 1));
@@ -563,7 +565,8 @@ static void wt_status_collect_updated_cb(struct 
diff_queue_struct *q,
oidcpy(>oid_index, >two->oid);
break;
case DIFF_STATUS_UNMERGED:
-   d->stagemask = unmerged_mask(p->two->path);
+   d->stagemask = unmerged_mask(s->repo->index,
+p->two->path);
/*
 * Don't bother setting {mode,oid}_{head,index} since 
the print
 * code will output the stage values directly and not 
use the
@@ -640,14 +643,15 @@ static void wt_status_collect_changes_index(struct 
wt_status *s)
 
 static void wt_status_collect_changes_initial(struct wt_status *s)
 {
+   struct index_state *istate = s->repo->index;
int i;
 
-   for (i = 0; i < active_nr; i++) {
+   for (i = 0; i < istate->cache_nr; i++) {
struct string_list_item *it;
struct wt_status_change_data *d;
-   const struct cache_entry *ce = active_cache[i];
+   const 

[PATCH 08/21] diff-lib.c: remove implicit dependency on the_index

2018-08-26 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 diff-lib.c | 17 ++---
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/diff-lib.c b/diff-lib.c
index 88a98b1c06..c54773fe12 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -70,7 +70,7 @@ static int match_stat_with_submodule(struct diff_options 
*diffopt,
 struct stat *st, unsigned ce_option,
 unsigned *dirty_submodule)
 {
-   int changed = ce_match_stat(ce, st, ce_option);
+   int changed = ie_match_stat(diffopt->repo->index, ce, st, ce_option);
if (S_ISGITLINK(ce->ce_mode)) {
struct diff_flags orig_flags = diffopt->flags;
if (!diffopt->flags.override_submodule_config)
@@ -93,15 +93,16 @@ int run_diff_files(struct rev_info *revs, unsigned int 
option)
unsigned ce_option = ((option & DIFF_RACY_IS_MODIFIED)
  ? CE_MATCH_RACY_IS_DIRTY : 0);
uint64_t start = getnanotime();
+   struct index_state *istate = revs->diffopt.repo->index;
 
diff_set_mnemonic_prefix(>diffopt, "i/", "w/");
 
if (diff_unmerged_stage < 0)
diff_unmerged_stage = 2;
-   entries = active_nr;
+   entries = istate->cache_nr;
for (i = 0; i < entries; i++) {
unsigned int oldmode, newmode;
-   struct cache_entry *ce = active_cache[i];
+   struct cache_entry *ce = istate->cache[i];
int changed;
unsigned dirty_submodule = 0;
const struct object_id *old_oid, *new_oid;
@@ -109,7 +110,7 @@ int run_diff_files(struct rev_info *revs, unsigned int 
option)
if (diff_can_quit_early(>diffopt))
break;
 
-   if (!ce_path_match(_index, ce, >prune_data, NULL))
+   if (!ce_path_match(istate, ce, >prune_data, NULL))
continue;
 
if (ce_stage(ce)) {
@@ -145,7 +146,7 @@ int run_diff_files(struct rev_info *revs, unsigned int 
option)
dpath->mode = wt_mode;
 
while (i < entries) {
-   struct cache_entry *nce = active_cache[i];
+   struct cache_entry *nce = istate->cache[i];
int stage;
 
if (strcmp(ce->name, nce->name))
@@ -474,7 +475,9 @@ static int oneway_diff(const struct cache_entry * const 
*src,
if (tree == o->df_conflict_entry)
tree = NULL;
 
-   if (ce_path_match(_index, idx ? idx : tree, >prune_data, 
NULL)) {
+   if (ce_path_match(revs->diffopt.repo->index,
+ idx ? idx : tree,
+ >prune_data, NULL)) {
do_oneway_diff(o, idx, tree);
if (diff_can_quit_early(>diffopt)) {
o->exiting_early = 1;
@@ -506,7 +509,7 @@ static int diff_cache(struct rev_info *revs,
opts.merge = 1;
opts.fn = oneway_diff;
opts.unpack_data = revs;
-   opts.src_index = _index;
+   opts.src_index = revs->diffopt.repo->index;
opts.dst_index = NULL;
opts.pathspec = >diffopt.pathspec;
opts.pathspec->recursive = 1;
-- 
2.19.0.rc0.337.ge906d732e7



[PATCH 04/21] diff.c: remove the_index dependency in textconv() functions

2018-08-26 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 blame.c|  7 ---
 builtin/cat-file.c |  6 --
 builtin/log.c  |  3 ++-
 combine-diff.c | 27 ---
 diff.c | 17 +
 diff.h |  9 +++--
 diffcore-pickaxe.c |  4 ++--
 grep.c |  2 +-
 8 files changed, 45 insertions(+), 30 deletions(-)

diff --git a/blame.c b/blame.c
index 08c0c6cf73..366d8d85e7 100644
--- a/blame.c
+++ b/blame.c
@@ -234,7 +234,7 @@ static struct commit *fake_working_tree_commit(struct 
repository *repo,
switch (st.st_mode & S_IFMT) {
case S_IFREG:
if (opt->flags.allow_textconv &&
-   textconv_object(read_from, mode, _oid, 0, 
_ptr, _len))
+   textconv_object(repo, read_from, mode, _oid, 
0, _ptr, _len))
strbuf_attach(, buf_ptr, buf_len, buf_len + 
1);
else if (strbuf_read_file(, read_from, st.st_size) 
!= st.st_size)
die_errno("cannot open or read '%s'", 
read_from);
@@ -318,7 +318,8 @@ static void fill_origin_blob(struct diff_options *opt,
 
(*num_read_blob)++;
if (opt->flags.allow_textconv &&
-   textconv_object(o->path, o->mode, >blob_oid, 1, 
>ptr, _size))
+   textconv_object(opt->repo, o->path, o->mode,
+   >blob_oid, 1, >ptr, _size))
;
else
file->ptr = read_object_file(>blob_oid, ,
@@ -1859,7 +1860,7 @@ void setup_scoreboard(struct blame_scoreboard *sb,
die(_("no such path %s in %s"), path, 
final_commit_name);
 
if (sb->revs->diffopt.flags.allow_textconv &&
-   textconv_object(path, o->mode, >blob_oid, 1, (char **) 
>final_buf,
+   textconv_object(sb->repo, path, o->mode, >blob_oid, 1, 
(char **) >final_buf,
>final_buf_size))
;
else
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 64ec1745ab..8d97c84725 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -113,7 +113,8 @@ static int cat_one_file(int opt, const char *exp_type, 
const char *obj_name,
die("git cat-file --textconv %s:  must be 
",
obj_name);
 
-   if (textconv_object(path, obj_context.mode, , 1, , 
))
+   if (textconv_object(the_repository, path, obj_context.mode,
+   , 1, , ))
break;
/* else fallthrough */
 
@@ -305,7 +306,8 @@ static void print_object_or_die(struct batch_options *opt, 
struct expand_data *d
oid_to_hex(oid), data->rest);
} else if (opt->cmdmode == 'c') {
enum object_type type;
-   if (!textconv_object(data->rest, 0100644, oid,
+   if (!textconv_object(the_repository,
+data->rest, 0100644, oid,
 1, , ))
contents = read_object_file(oid,
,
diff --git a/builtin/log.c b/builtin/log.c
index e094560d9a..f32a07f6a9 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -507,7 +507,8 @@ static int show_blob_object(const struct object_id *oid, 
struct rev_info *rev, c
 , _context))
die(_("Not a valid object name %s"), obj_name);
if (!obj_context.path ||
-   !textconv_object(obj_context.path, obj_context.mode, , 1, 
, )) {
+   !textconv_object(the_repository, obj_context.path,
+obj_context.mode, , 1, , )) {
free(obj_context.path);
return stream_blob_to_fd(1, oid, NULL, 0);
}
diff --git a/combine-diff.c b/combine-diff.c
index 4fa7707b57..ec20fff63b 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -285,7 +285,8 @@ static struct lline *coalesce_lines(struct lline *base, int 
*lenbase,
return base;
 }
 
-static char *grab_blob(const struct object_id *oid, unsigned int mode,
+static char *grab_blob(struct repository *repo,
+  const struct object_id *oid, unsigned int mode,
   unsigned long *size, struct userdiff_driver *textconv,
   const char *path)
 {
@@ -304,7 +305,7 @@ static char *grab_blob(const struct object_id *oid, 
unsigned int mode,
} else if (textconv) {
struct diff_filespec *df = alloc_filespec(path);
fill_filespec(df, oid, 1, mode);
-   *size = fill_textconv(textconv, df, );
+   *size = 

[PATCH 11/21] merge.c: remove implicit dependency on the_index

2018-08-26 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 builtin/merge.c |  8 +---
 builtin/pull.c  |  7 +--
 cache.h |  6 --
 merge.c | 20 +++-
 sequencer.c |  6 +++---
 5 files changed, 28 insertions(+), 19 deletions(-)

diff --git a/builtin/merge.c b/builtin/merge.c
index 0a37d5ef2c..a56754db5c 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -728,8 +728,9 @@ static int try_merge_strategy(const char *strategy, struct 
commit_list *common,
die(_("unable to write %s"), get_index_file());
return clean ? 0 : 1;
} else {
-   return try_merge_command(strategy, xopts_nr, xopts,
-   common, head_arg, remoteheads);
+   return try_merge_command(the_repository,
+strategy, xopts_nr, xopts,
+common, head_arg, remoteheads);
}
 }
 
@@ -1470,7 +1471,8 @@ int cmd_merge(int argc, const char **argv, const char 
*prefix)
goto done;
}
 
-   if (checkout_fast_forward(_commit->object.oid,
+   if (checkout_fast_forward(the_repository,
+ _commit->object.oid,
  >object.oid,
  overwrite_ignore)) {
ret = 1;
diff --git a/builtin/pull.c b/builtin/pull.c
index 53bc5facfd..9b2f76f9d9 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -562,7 +562,9 @@ static int pull_into_void(const struct object_id 
*merge_head,
 * index/worktree changes that the user already made on the unborn
 * branch.
 */
-   if (checkout_fast_forward(the_hash_algo->empty_tree, merge_head, 0))
+   if (checkout_fast_forward(the_repository,
+ the_hash_algo->empty_tree,
+ merge_head, 0))
return 1;
 
if (update_ref("initial pull", "HEAD", merge_head, curr_head, 0, 
UPDATE_REFS_DIE_ON_ERR))
@@ -915,7 +917,8 @@ int cmd_pull(int argc, const char **argv, const char 
*prefix)
"fast-forwarding your working tree from\n"
"commit %s."), oid_to_hex(_head));
 
-   if (checkout_fast_forward(_head, _head, 0))
+   if (checkout_fast_forward(the_repository, _head,
+ _head, 0))
die(_("Cannot fast-forward your working tree.\n"
"After making sure that you saved anything 
precious from\n"
"$ git diff %s\n"
diff --git a/cache.h b/cache.h
index 31013ce8af..218edaa198 100644
--- a/cache.h
+++ b/cache.h
@@ -1706,10 +1706,12 @@ extern struct startup_info *startup_info;
 
 /* merge.c */
 struct commit_list;
-int try_merge_command(const char *strategy, size_t xopts_nr,
+int try_merge_command(struct repository *repo,
+   const char *strategy, size_t xopts_nr,
const char **xopts, struct commit_list *common,
const char *head_arg, struct commit_list *remotes);
-int checkout_fast_forward(const struct object_id *from,
+int checkout_fast_forward(struct repository *repo,
+ const struct object_id *from,
  const struct object_id *to,
  int overwrite_ignore);
 
diff --git a/merge.c b/merge.c
index e30e03fb84..3c8c769e50 100644
--- a/merge.c
+++ b/merge.c
@@ -14,7 +14,8 @@ static const char *merge_argument(struct commit *commit)
return oid_to_hex(commit ? >object.oid : 
the_hash_algo->empty_tree);
 }
 
-int try_merge_command(const char *strategy, size_t xopts_nr,
+int try_merge_command(struct repository *repo,
+ const char *strategy, size_t xopts_nr,
  const char **xopts, struct commit_list *common,
  const char *head_arg, struct commit_list *remotes)
 {
@@ -35,15 +36,16 @@ int try_merge_command(const char *strategy, size_t xopts_nr,
ret = run_command_v_opt(args.argv, RUN_GIT_CMD);
argv_array_clear();
 
-   discard_cache();
-   if (read_cache() < 0)
+   discard_index(repo->index);
+   if (read_index(repo->index) < 0)
die(_("failed to read the cache"));
-   resolve_undo_clear();
+   resolve_undo_clear_index(repo->index);
 
return ret;
 }
 
-int checkout_fast_forward(const struct object_id *head,
+int checkout_fast_forward(struct repository *repo,
+ const struct object_id *head,
  const struct object_id *remote,
  int overwrite_ignore)
 {
@@ -54,7 +56,7 @@ int checkout_fast_forward(const struct object_id *head,
struct dir_struct dir;
struct lock_file lock_file = LOCK_INIT;
 
-   refresh_cache(REFRESH_QUIET);
+   

[PATCH 12/21] patch-ids.c: remove implicit dependency on the_index

2018-08-26 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 builtin/log.c | 2 +-
 patch-ids.c   | 4 ++--
 patch-ids.h   | 3 ++-
 revision.c| 2 +-
 4 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/builtin/log.c b/builtin/log.c
index 33084102e0..2910122d90 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -914,7 +914,7 @@ static void get_patch_ids(struct rev_info *rev, struct 
patch_ids *ids)
if ((flags1 & UNINTERESTING) == (flags2 & UNINTERESTING))
die(_("Not a range."));
 
-   init_patch_ids(ids);
+   init_patch_ids(ids, the_repository);
 
/* given a range a..b get all patch ids for b..a */
init_revisions(_rev, rev->prefix);
diff --git a/patch-ids.c b/patch-ids.c
index 9084604c77..72ef9e4e8a 100644
--- a/patch-ids.c
+++ b/patch-ids.c
@@ -56,10 +56,10 @@ static int patch_id_cmp(const void *cmpfn_data,
return oidcmp(>patch_id, >patch_id);
 }
 
-int init_patch_ids(struct patch_ids *ids)
+int init_patch_ids(struct patch_ids *ids, struct repository *repo)
 {
memset(ids, 0, sizeof(*ids));
-   diff_setup(>diffopts, the_repository);
+   diff_setup(>diffopts, repo);
ids->diffopts.detect_rename = 0;
ids->diffopts.flags.recursive = 1;
diff_setup_done(>diffopts);
diff --git a/patch-ids.h b/patch-ids.h
index 79ac9a8498..1d4cf618f9 100644
--- a/patch-ids.h
+++ b/patch-ids.h
@@ -6,6 +6,7 @@
 
 struct commit;
 struct object_id;
+struct repository;
 
 struct patch_id {
struct hashmap_entry ent;
@@ -20,7 +21,7 @@ struct patch_ids {
 
 int commit_patch_id(struct commit *commit, struct diff_options *options,
struct object_id *oid, int);
-int init_patch_ids(struct patch_ids *);
+int init_patch_ids(struct patch_ids *, struct repository *);
 int free_patch_ids(struct patch_ids *);
 struct patch_id *add_commit_patch_id(struct commit *, struct patch_ids *);
 struct patch_id *has_commit_patch_id(struct commit *, struct patch_ids *);
diff --git a/revision.c b/revision.c
index bfcb0f2a00..d4a539dc69 100644
--- a/revision.c
+++ b/revision.c
@@ -877,7 +877,7 @@ static void cherry_pick_list(struct commit_list *list, 
struct rev_info *revs)
return;
 
left_first = left_count < right_count;
-   init_patch_ids();
+   init_patch_ids(, the_repository);
ids.diffopts.pathspec = revs->diffopt.pathspec;
 
/* Compute patch-ids for one side */
-- 
2.19.0.rc0.337.ge906d732e7



[PATCH 21/21] wt-status.c: remove implicit dependency the_repository

2018-08-26 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 ref-filter.c |  2 +-
 wt-status.c  | 24 +---
 wt-status.h  |  4 +++-
 3 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/ref-filter.c b/ref-filter.c
index 0bccfceff2..1b229b84da 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1409,7 +1409,7 @@ char *get_head_description(void)
struct strbuf desc = STRBUF_INIT;
struct wt_status_state state;
memset(, 0, sizeof(state));
-   wt_status_get_state(, 1);
+   wt_status_get_state(the_repository, , 1);
if (state.rebase_in_progress ||
state.rebase_interactive_in_progress) {
if (state.branch)
diff --git a/wt-status.c b/wt-status.c
index 57bc2aac0f..1d3a5fe267 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -1322,7 +1322,7 @@ static void show_rebase_in_progress(struct wt_status *s,
status_printf_ln(s, color,
_("  (use \"git rebase --abort\" to check out 
the original branch)"));
}
-   } else if (state->rebase_in_progress || 
!stat(git_path_merge_msg(the_repository), )) {
+   } else if (state->rebase_in_progress || 
!stat(git_path_merge_msg(s->repo), )) {
print_rebase_state(s, state, color);
if (s->hints)
status_printf_ln(s, color,
@@ -1477,7 +1477,8 @@ static int grab_1st_switch(struct object_id *ooid, struct 
object_id *noid,
return 1;
 }
 
-static void wt_status_get_detached_from(struct wt_status_state *state)
+static void wt_status_get_detached_from(struct repository *repo,
+   struct wt_status_state *state)
 {
struct grab_1st_switch_cbdata cb;
struct commit *commit;
@@ -1494,7 +1495,7 @@ static void wt_status_get_detached_from(struct 
wt_status_state *state)
/* sha1 is a commit? match without further lookup */
(!oidcmp(, ) ||
 /* perhaps sha1 is a tag, try to dereference to a commit */
-((commit = lookup_commit_reference_gently(the_repository, , 
1)) != NULL &&
+((commit = lookup_commit_reference_gently(repo, , 1)) != NULL 
&&
  !oidcmp(, >object.oid {
const char *from = ref;
if (!skip_prefix(from, "refs/tags/", ))
@@ -1551,30 +1552,31 @@ int wt_status_check_bisect(const struct worktree *wt,
return 0;
 }
 
-void wt_status_get_state(struct wt_status_state *state,
+void wt_status_get_state(struct repository *repo,
+struct wt_status_state *state,
 int get_detached_from)
 {
struct stat st;
struct object_id oid;
 
-   if (!stat(git_path_merge_head(the_repository), )) {
+   if (!stat(git_path_merge_head(repo), )) {
state->merge_in_progress = 1;
} else if (wt_status_check_rebase(NULL, state)) {
;   /* all set */
-   } else if (!stat(git_path_cherry_pick_head(the_repository), ) &&
+   } else if (!stat(git_path_cherry_pick_head(repo), ) &&
!get_oid("CHERRY_PICK_HEAD", )) {
state->cherry_pick_in_progress = 1;
oidcpy(>cherry_pick_head_oid, );
}
wt_status_check_bisect(NULL, state);
-   if (!stat(git_path_revert_head(the_repository), ) &&
+   if (!stat(git_path_revert_head(repo), ) &&
!get_oid("REVERT_HEAD", )) {
state->revert_in_progress = 1;
oidcpy(>revert_head_oid, );
}
 
if (get_detached_from)
-   wt_status_get_detached_from(state);
+   wt_status_get_detached_from(repo, state);
 }
 
 static void wt_longstatus_print_state(struct wt_status *s,
@@ -1602,7 +1604,7 @@ static void wt_longstatus_print(struct wt_status *s)
struct wt_status_state state;
 
memset(, 0, sizeof(state));
-   wt_status_get_state(,
+   wt_status_get_state(s->repo, ,
s->branch && !strcmp(s->branch, "HEAD"));
 
if (s->branch) {
@@ -1947,7 +1949,7 @@ static void wt_porcelain_v2_print_tracking(struct 
wt_status *s)
char eol = s->null_termination ? '\0' : '\n';
 
memset(, 0, sizeof(state));
-   wt_status_get_state(, s->branch && !strcmp(s->branch, "HEAD"));
+   wt_status_get_state(s->repo, , s->branch && !strcmp(s->branch, 
"HEAD"));
 
fprintf(s->fp, "# branch.oid %s%c",
(s->is_initial ? "(initial)" : 
sha1_to_hex(s->sha1_commit)),
@@ -2355,7 +2357,7 @@ int has_uncommitted_changes(struct repository *repo,
 * We have no head (or it's corrupt); use the empty tree,
 * which will complain if the index is non-empty.
 */
-   struct tree *tree = lookup_tree(the_repository, 
the_hash_algo->empty_tree);
+   struct tree *tree = lookup_tree(repo, 
the_hash_algo->empty_tree);

[PATCH 14/21] rerere.c: remove implicit dependency on the_index

2018-08-26 Thread Nguyễn Thái Ngọc Duy
The reason rerere(), rerere_forget() and rerere_remaining() take a
struct repository instead of struct index_state is not obvious from
the patch:

deep in update_paths() and find_conflict(), hold_locked_index() and
read_index() are called. These functions assumes the index path at
$GIT_DIR/index which is not always true when you take an arbitrary
index state. Taking a repository will allow us to point to the right
index path later when we replace them with repo_ versions.

Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 apply.c  |   2 +-
 builtin/am.c |   4 +-
 builtin/commit.c |   2 +-
 builtin/merge.c  |   2 +-
 builtin/rerere.c |   6 +--
 rerere.c | 119 +--
 rerere.h |   9 ++--
 sequencer.c  |   4 +-
 8 files changed, 79 insertions(+), 69 deletions(-)

diff --git a/apply.c b/apply.c
index ea111ab13f..d80b3547c2 100644
--- a/apply.c
+++ b/apply.c
@@ -4630,7 +4630,7 @@ static int write_out_results(struct apply_state *state, 
struct patch *list)
}
string_list_clear(, 0);
 
-   rerere(0);
+   rerere(state->repo, 0);
}
 
return errs;
diff --git a/builtin/am.c b/builtin/am.c
index 9f7ecf6ecb..9b2a2dd0ea 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1603,7 +1603,7 @@ static int fall_back_threeway(const struct am_state 
*state, const char *index_pa
o.verbosity = 0;
 
if (merge_recursive_generic(, _tree, _tree, 1, bases, 
)) {
-   rerere(state->allow_rerere_autoupdate);
+   rerere(the_repository, state->allow_rerere_autoupdate);
free(their_tree_name);
return error(_("Failed to merge in the changes."));
}
@@ -1898,7 +1898,7 @@ static void am_resolve(struct am_state *state)
goto next;
}
 
-   rerere(0);
+   rerere(the_repository, 0);
 
do_commit(state);
 
diff --git a/builtin/commit.c b/builtin/commit.c
index 0d9828e29e..731e98fd63 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1651,7 +1651,7 @@ int cmd_commit(int argc, const char **argv, const char 
*prefix)
  "new_index file. Check that disk is not full and quota 
is\n"
  "not exceeded, and then \"git reset HEAD\" to recover."));
 
-   rerere(0);
+   rerere(the_repository, 0);
run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
run_commit_hook(use_editor, get_index_file(), "post-commit", NULL);
if (amend && !no_post_rewrite) {
diff --git a/builtin/merge.c b/builtin/merge.c
index a56754db5c..432dcbe4cd 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -899,7 +899,7 @@ static int suggest_conflicts(void)
fputs(msgbuf.buf, fp);
strbuf_release();
fclose(fp);
-   rerere(allow_rerere_auto);
+   rerere(the_repository, allow_rerere_auto);
printf(_("Automatic merge failed; "
"fix conflicts and then commit the result.\n"));
return 1;
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 0bc40298c2..d1fc472d13 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -70,7 +70,7 @@ int cmd_rerere(int argc, const char **argv, const char 
*prefix)
flags = RERERE_NOAUTOUPDATE;
 
if (argc < 1)
-   return rerere(flags);
+   return rerere(the_repository, flags);
 
if (!strcmp(argv[0], "forget")) {
struct pathspec pathspec;
@@ -78,7 +78,7 @@ int cmd_rerere(int argc, const char **argv, const char 
*prefix)
warning("'git rerere forget' without paths is 
deprecated");
parse_pathspec(, 0, PATHSPEC_PREFER_CWD,
   prefix, argv + 1);
-   return rerere_forget();
+   return rerere_forget(the_repository, );
}
 
if (!strcmp(argv[0], "clear")) {
@@ -91,7 +91,7 @@ int cmd_rerere(int argc, const char **argv, const char 
*prefix)
for (i = 0; i < merge_rr.nr; i++)
printf("%s\n", merge_rr.items[i].string);
} else if (!strcmp(argv[0], "remaining")) {
-   rerere_remaining(_rr);
+   rerere_remaining(the_repository, _rr);
for (i = 0; i < merge_rr.nr; i++) {
if (merge_rr.items[i].util != RERERE_RESOLVED)
printf("%s\n", merge_rr.items[i].string);
diff --git a/rerere.c b/rerere.c
index e65d8fc06f..4c5b343450 100644
--- a/rerere.c
+++ b/rerere.c
@@ -474,11 +474,12 @@ static int handle_path(unsigned char *sha1, struct 
rerere_io *io, int marker_siz
  * Scan the path for conflicts, do the "handle_path()" thing above, and
  * return the number of conflict hunks found.
  */
-static int handle_file(const char *path, unsigned char *sha1, const char 
*output)
+static int handle_file(struct index_state *istate, const char *path,
+  unsigned char 

[PATCH 16/21] line-range.c: remove implicit dependency on the_index

2018-08-26 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 builtin/blame.c |  2 +-
 line-log.c  |  4 ++--
 line-range.c| 22 ++
 line-range.h|  6 --
 4 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/builtin/blame.c b/builtin/blame.c
index c2da673ac8..97632828db 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -1001,7 +1001,7 @@ int cmd_blame(int argc, const char **argv, const char 
*prefix)
long bottom, top;
if (parse_range_arg(range_list.items[range_i].string,
nth_line_cb, , lno, anchor,
-   , , sb.path))
+   , , sb.path, _index))
usage(blame_usage);
if ((!lno && (top || bottom)) || lno < bottom)
die(Q_("file %s has only %lu line",
diff --git a/line-log.c b/line-log.c
index 7ee9e17d95..b1f3ca6735 100644
--- a/line-log.c
+++ b/line-log.c
@@ -574,7 +574,7 @@ parse_lines(struct repository *repo, struct commit *commit,
long begin = 0, end = 0;
long anchor;
 
-   name_part = skip_range_arg(item->string);
+   name_part = skip_range_arg(item->string, repo->index);
if (!name_part || *name_part != ':' || !name_part[1])
die("-L argument not 'start,end:file' or 
':funcname:file': %s",
item->string);
@@ -599,7 +599,7 @@ parse_lines(struct repository *repo, struct commit *commit,
 
if (parse_range_arg(range_part, nth_line, _data,
lines, anchor, , ,
-   full_name))
+   full_name, repo->index))
die("malformed -L argument '%s'", range_part);
if ((!lines && (begin || end)) || lines < begin)
die("file %s has only %lu lines", name_part, lines);
diff --git a/line-range.c b/line-range.c
index 7fa0d8bba5..9b50583dc0 100644
--- a/line-range.c
+++ b/line-range.c
@@ -163,9 +163,10 @@ static const char 
*find_funcname_matching_regexp(xdemitconf_t *xecfg, const char
}
 }
 
-static const char *parse_range_funcname(const char *arg, nth_line_fn_t 
nth_line_cb,
-   void *cb_data, long lines, long anchor, 
long *begin, long *end,
-   const char *path)
+static const char *parse_range_funcname(
+   const char *arg, nth_line_fn_t nth_line_cb,
+   void *cb_data, long lines, long anchor, long *begin, long *end,
+   const char *path, struct index_state *istate)
 {
char *pattern;
const char *term;
@@ -198,7 +199,7 @@ static const char *parse_range_funcname(const char *arg, 
nth_line_fn_t nth_line_
anchor--; /* input is in human terms */
start = nth_line_cb(cb_data, anchor);
 
-   drv = userdiff_find_by_path(_index, path);
+   drv = userdiff_find_by_path(istate, path);
if (drv && drv->funcname.pattern) {
const struct userdiff_funcname *pe = >funcname;
xecfg = xcalloc(1, sizeof(*xecfg));
@@ -244,7 +245,8 @@ static const char *parse_range_funcname(const char *arg, 
nth_line_fn_t nth_line_
 
 int parse_range_arg(const char *arg, nth_line_fn_t nth_line_cb,
void *cb_data, long lines, long anchor,
-   long *begin, long *end, const char *path)
+   long *begin, long *end,
+   const char *path, struct index_state *istate)
 {
*begin = *end = 0;
 
@@ -254,7 +256,9 @@ int parse_range_arg(const char *arg, nth_line_fn_t 
nth_line_cb,
anchor = lines + 1;
 
if (*arg == ':' || (*arg == '^' && *(arg + 1) == ':')) {
-   arg = parse_range_funcname(arg, nth_line_cb, cb_data, lines, 
anchor, begin, end, path);
+   arg = parse_range_funcname(arg, nth_line_cb, cb_data,
+  lines, anchor, begin, end,
+  path, istate);
if (!arg || *arg)
return -1;
return 0;
@@ -275,10 +279,12 @@ int parse_range_arg(const char *arg, nth_line_fn_t 
nth_line_cb,
return 0;
 }
 
-const char *skip_range_arg(const char *arg)
+const char *skip_range_arg(const char *arg, struct index_state *istate)
 {
if (*arg == ':' || (*arg == '^' && *(arg + 1) == ':'))
-   return parse_range_funcname(arg, NULL, NULL, 0, 0, NULL, NULL, 
NULL);
+   return parse_range_funcname(arg, NULL, NULL,
+   0, 0, NULL, NULL,
+   NULL, istate);
 
arg = parse_loc(arg, NULL, NULL, 0, -1, NULL);
 
diff --git a/line-range.h b/line-range.h
index d3c54e45aa..e69bf7c017 100644
--- a/line-range.h
+++ b/line-range.h
@@ -1,6 +1,8 @@
 #ifndef LINE_RANGE_H
 

[PATCH 15/21] userdiff.c: remove implicit dependency on the_index

2018-08-26 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 archive-zip.c  | 14 +-
 builtin/grep.c |  3 ++-
 combine-diff.c |  2 +-
 diff.c | 40 +++-
 diff.h |  3 ++-
 diffcore-pickaxe.c |  4 ++--
 grep.c | 21 -
 grep.h |  3 ++-
 line-range.c   |  2 +-
 userdiff.c |  5 +++--
 userdiff.h |  3 ++-
 11 files changed, 59 insertions(+), 41 deletions(-)

diff --git a/archive-zip.c b/archive-zip.c
index 5a62351ab1..155ee4a779 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -264,9 +264,10 @@ static int has_only_ascii(const char *s)
}
 }
 
-static int entry_is_binary(const char *path, const void *buffer, size_t size)
+static int entry_is_binary(struct index_state *istate, const char *path,
+  const void *buffer, size_t size)
 {
-   struct userdiff_driver *driver = userdiff_find_by_path(path);
+   struct userdiff_driver *driver = userdiff_find_by_path(istate, path);
if (!driver)
driver = userdiff_find_by_name("default");
if (driver->binary != -1)
@@ -352,7 +353,8 @@ static int write_zip_entry(struct archiver_args *args,
return error(_("cannot read %s"),
 oid_to_hex(oid));
crc = crc32(crc, buffer, size);
-   is_binary = entry_is_binary(path_without_prefix,
+   is_binary = entry_is_binary(args->repo->index,
+   path_without_prefix,
buffer, size);
out = buffer;
}
@@ -428,7 +430,8 @@ static int write_zip_entry(struct archiver_args *args,
break;
crc = crc32(crc, buf, readlen);
if (is_binary == -1)
-   is_binary = entry_is_binary(path_without_prefix,
+   is_binary = entry_is_binary(args->repo->index,
+   path_without_prefix,
buf, readlen);
write_or_die(1, buf, readlen);
}
@@ -460,7 +463,8 @@ static int write_zip_entry(struct archiver_args *args,
break;
crc = crc32(crc, buf, readlen);
if (is_binary == -1)
-   is_binary = entry_is_binary(path_without_prefix,
+   is_binary = entry_is_binary(args->repo->index,
+   path_without_prefix,
buf, readlen);
 
zstream.next_in = buf;
diff --git a/builtin/grep.c b/builtin/grep.c
index 0667ffde84..0c3527242e 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -103,7 +103,8 @@ static void add_work(struct grep_opt *opt, const struct 
grep_source *gs)
 
todo[todo_end].source = *gs;
if (opt->binary != GREP_BINARY_TEXT)
-   grep_source_load_driver([todo_end].source);
+   grep_source_load_driver([todo_end].source,
+   opt->repo->index);
todo[todo_end].done = 0;
strbuf_reset([todo_end].out);
todo_end = (todo_end + 1) % ARRAY_SIZE(todo);
diff --git a/combine-diff.c b/combine-diff.c
index ec20fff63b..67adba1933 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -987,7 +987,7 @@ static void show_patch_diff(struct combine_diff_path *elem, 
int num_parent,
const char *line_prefix = diff_line_prefix(opt);
 
context = opt->context;
-   userdiff = userdiff_find_by_path(elem->path);
+   userdiff = userdiff_find_by_path(opt->repo->index, elem->path);
if (!userdiff)
userdiff = userdiff_find_by_name("default");
if (opt->flags.allow_textconv)
diff --git a/diff.c b/diff.c
index ec3029df82..5a5f91480b 100644
--- a/diff.c
+++ b/diff.c
@@ -2093,23 +2093,25 @@ static void diff_words_flush(struct emit_callback 
*ecbdata)
}
 }
 
-static void diff_filespec_load_driver(struct diff_filespec *one)
+static void diff_filespec_load_driver(struct diff_filespec *one,
+ struct index_state *istate)
 {
/* Use already-loaded driver */
if (one->driver)
return;
 
if (S_ISREG(one->mode))
-   one->driver = userdiff_find_by_path(one->path);
+   one->driver = userdiff_find_by_path(istate, one->path);
 
/* Fallback to default settings */
if (!one->driver)
one->driver = userdiff_find_by_name("default");
 }
 
-static const char *userdiff_word_regex(struct diff_filespec *one)
+static const char 

[PATCH 01/21] archive.c: remove implicit dependency the_repository

2018-08-26 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 archive.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/archive.c b/archive.c
index 0a07b140fe..994495af05 100644
--- a/archive.c
+++ b/archive.c
@@ -391,7 +391,7 @@ static void parse_treeish_arg(const char **argv,
if (get_oid(name, ))
die("Not a valid object name");
 
-   commit = lookup_commit_reference_gently(the_repository, , 1);
+   commit = lookup_commit_reference_gently(ar_args->repo, , 1);
if (commit) {
commit_sha1 = commit->object.oid.hash;
archive_time = commit->date;
-- 
2.19.0.rc0.337.ge906d732e7



[PATCH 03/21] combine-diff.c: remove implicit dependency on the_index

2018-08-26 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 combine-diff.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/combine-diff.c b/combine-diff.c
index de7695e728..4fa7707b57 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -1054,7 +1054,8 @@ static void show_patch_diff(struct combine_diff_path 
*elem, int num_parent,
if (is_file) {
struct strbuf buf = STRBUF_INIT;
 
-   if (convert_to_git(_index, elem->path, 
result, len, , global_conv_flags_eol)) {
+   if (convert_to_git(rev->diffopt.repo->index,
+  elem->path, result, len, 
, global_conv_flags_eol)) {
free(result);
result = strbuf_detach(, );
result_size = len;
-- 
2.19.0.rc0.337.ge906d732e7



[PATCH 07/21] read-cache.c: remove implicit dependency on the_index

2018-08-26 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 read-cache.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/read-cache.c b/read-cache.c
index 8e92b1e21f..b9df81e94e 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -823,7 +823,7 @@ struct cache_entry *make_cache_entry(struct index_state 
*istate,
ce->ce_namelen = len;
ce->ce_mode = create_ce_mode(mode);
 
-   ret = refresh_cache_entry(_index, ce, refresh_options);
+   ret = refresh_cache_entry(istate, ce, refresh_options);
if (ret != ce)
discard_cache_entry(ce);
return ret;
@@ -1493,7 +1493,7 @@ int refresh_index(struct index_state *istate, unsigned 
int flags,
if (ignore_submodules && S_ISGITLINK(ce->ce_mode))
continue;
 
-   if (pathspec && !ce_path_match(_index, ce, pathspec, seen))
+   if (pathspec && !ce_path_match(istate, ce, pathspec, seen))
filtered = 1;
 
if (ce_stage(ce)) {
-- 
2.19.0.rc0.337.ge906d732e7



[PATCH 10/21] merge-blobs.c: remove implicit dependency on the_index

2018-08-26 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 builtin/merge-tree.c |  2 +-
 merge-blobs.c| 15 +++
 merge-blobs.h|  7 +--
 3 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c
index f8023bae1e..f32941fdab 100644
--- a/builtin/merge-tree.c
+++ b/builtin/merge-tree.c
@@ -76,7 +76,7 @@ static void *result(struct merge_list *entry, unsigned long 
*size)
their = NULL;
if (entry)
their = entry->blob;
-   return merge_blobs(path, base, our, their, size);
+   return merge_blobs(_index, path, base, our, their, size);
 }
 
 static void *origin(struct merge_list *entry, unsigned long *size)
diff --git a/merge-blobs.c b/merge-blobs.c
index 668fb2e05d..ee0a0e90c9 100644
--- a/merge-blobs.c
+++ b/merge-blobs.c
@@ -29,7 +29,12 @@ static void free_mmfile(mmfile_t *f)
free(f->ptr);
 }
 
-static void *three_way_filemerge(const char *path, mmfile_t *base, mmfile_t 
*our, mmfile_t *their, unsigned long *size)
+static void *three_way_filemerge(struct index_state *istate,
+const char *path,
+mmfile_t *base,
+mmfile_t *our,
+mmfile_t *their,
+unsigned long *size)
 {
int merge_status;
mmbuffer_t res;
@@ -42,7 +47,7 @@ static void *three_way_filemerge(const char *path, mmfile_t 
*base, mmfile_t *our
 */
merge_status = ll_merge(, path, base, NULL,
our, ".our", their, ".their",
-   _index, NULL);
+   istate, NULL);
if (merge_status < 0)
return NULL;
 
@@ -50,7 +55,9 @@ static void *three_way_filemerge(const char *path, mmfile_t 
*base, mmfile_t *our
return res.ptr;
 }
 
-void *merge_blobs(const char *path, struct blob *base, struct blob *our, 
struct blob *their, unsigned long *size)
+void *merge_blobs(struct index_state *istate, const char *path,
+ struct blob *base, struct blob *our,
+ struct blob *their, unsigned long *size)
 {
void *res = NULL;
mmfile_t f1, f2, common;
@@ -83,7 +90,7 @@ void *merge_blobs(const char *path, struct blob *base, struct 
blob *our, struct
common.ptr = xstrdup("");
common.size = 0;
}
-   res = three_way_filemerge(path, , , , size);
+   res = three_way_filemerge(istate, path, , , , size);
free_mmfile();
 out_free_f2_f1:
free_mmfile();
diff --git a/merge-blobs.h b/merge-blobs.h
index 62b569e472..cc31038b80 100644
--- a/merge-blobs.h
+++ b/merge-blobs.h
@@ -1,8 +1,11 @@
 #ifndef MERGE_BLOBS_H
 #define MERGE_BLOBS_H
 
-#include "blob.h"
+struct blob;
+struct index_state;
 
-extern void *merge_blobs(const char *, struct blob *, struct blob *, struct 
blob *, unsigned long *);
+extern void *merge_blobs(struct index_state *, const char *,
+struct blob *, struct blob *,
+struct blob *, unsigned long *);
 
 #endif /* MERGE_BLOBS_H */
-- 
2.19.0.rc0.337.ge906d732e7



[PATCH 19/21] ws.c: remove implicit dependency on the_index

2018-08-26 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 apply.c | 8 +---
 cache.h | 2 +-
 diff.c  | 6 +++---
 ws.c| 5 ++---
 4 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/apply.c b/apply.c
index d80b3547c2..fc52993548 100644
--- a/apply.c
+++ b/apply.c
@@ -2131,10 +2131,12 @@ static int parse_chunk(struct apply_state *state, char 
*buffer, unsigned long si
 
if (!use_patch(state, patch))
patch->ws_rule = 0;
+   else if (patch->new_name)
+   patch->ws_rule = whitespace_rule(state->repo->index,
+patch->new_name);
else
-   patch->ws_rule = whitespace_rule(patch->new_name
-? patch->new_name
-: patch->old_name);
+   patch->ws_rule = whitespace_rule(state->repo->index,
+patch->old_name);
 
patchsize = parse_single_patch(state,
   buffer + offset + hdrsize,
diff --git a/cache.h b/cache.h
index 0964611997..e697402396 100644
--- a/cache.h
+++ b/cache.h
@@ -1684,7 +1684,7 @@ void shift_tree_by(const struct object_id *, const struct 
object_id *, struct ob
 /* All WS_* -- when extended, adapt diff.c emit_symbol */
 #define WS_RULE_MASK   0
 extern unsigned whitespace_rule_cfg;
-extern unsigned whitespace_rule(const char *);
+extern unsigned whitespace_rule(struct index_state *, const char *);
 extern unsigned parse_whitespace_rule(const char *);
 extern unsigned ws_check(const char *line, int len, unsigned ws_rule);
 extern void ws_check_emit(const char *line, int len, unsigned ws_rule, FILE 
*stream, const char *set, const char *reset, const char *ws);
diff --git a/diff.c b/diff.c
index 5a5f91480b..b28de7a246 100644
--- a/diff.c
+++ b/diff.c
@@ -1705,7 +1705,7 @@ static void emit_rewrite_diff(const char *name_a,
 
memset(, 0, sizeof(ecbdata));
ecbdata.color_diff = want_color(o->use_color);
-   ecbdata.ws_rule = whitespace_rule(name_b);
+   ecbdata.ws_rule = whitespace_rule(o->repo->index, name_b);
ecbdata.opt = o;
if (ecbdata.ws_rule & WS_BLANK_AT_EOF) {
mmfile_t mf1, mf2;
@@ -3480,7 +3480,7 @@ static void builtin_diff(const char *name_a,
lbl[0] = NULL;
ecbdata.label_path = lbl;
ecbdata.color_diff = want_color(o->use_color);
-   ecbdata.ws_rule = whitespace_rule(name_b);
+   ecbdata.ws_rule = whitespace_rule(o->repo->index, name_b);
if (ecbdata.ws_rule & WS_BLANK_AT_EOF)
check_blank_at_eof(, , );
ecbdata.opt = o;
@@ -3640,7 +3640,7 @@ static void builtin_checkdiff(const char *name_a, const 
char *name_b,
data.filename = name_b ? name_b : name_a;
data.lineno = 0;
data.o = o;
-   data.ws_rule = whitespace_rule(attr_path);
+   data.ws_rule = whitespace_rule(o->repo->index, attr_path);
data.conflict_marker_size = ll_merge_marker_size(o->repo->index, 
attr_path);
 
if (fill_mmfile(o->repo, , one) < 0 ||
diff --git a/ws.c b/ws.c
index 5b67b426e7..55349b4c5d 100644
--- a/ws.c
+++ b/ws.c
@@ -3,7 +3,6 @@
  *
  * Copyright (c) 2007 Junio C Hamano
  */
-
 #include "cache.h"
 #include "attr.h"
 
@@ -71,14 +70,14 @@ unsigned parse_whitespace_rule(const char *string)
return rule;
 }
 
-unsigned whitespace_rule(const char *pathname)
+unsigned whitespace_rule(struct index_state *istate, const char *pathname)
 {
static struct attr_check *attr_whitespace_rule;
 
if (!attr_whitespace_rule)
attr_whitespace_rule = attr_check_initl("whitespace", NULL);
 
-   if (!git_check_attr(_index, pathname, attr_whitespace_rule)) {
+   if (!git_check_attr(istate, pathname, attr_whitespace_rule)) {
const char *value;
 
value = attr_whitespace_rule->items[0].value;
-- 
2.19.0.rc0.337.ge906d732e7



[PATCH 18/21] tree-diff.c: remove implicit dependency on the_index

2018-08-26 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 tree-diff.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tree-diff.c b/tree-diff.c
index d29127b029..b5ff14711c 100644
--- a/tree-diff.c
+++ b/tree-diff.c
@@ -607,7 +607,7 @@ static void try_to_follow_renames(const struct object_id 
*old_oid,
choice = q->queue[0];
q->nr = 0;
 
-   diff_setup(_opts, the_repository);
+   diff_setup(_opts, opt->repo);
diff_opts.flags.recursive = 1;
diff_opts.flags.find_copies_harder = 1;
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
-- 
2.19.0.rc0.337.ge906d732e7



[PATCH 17/21] submodule.c: remove implicit dependency on the_index

2018-08-26 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 builtin/pull.c |  2 +-
 submodule.c| 28 +---
 submodule.h|  9 ++---
 transport.c|  9 ++---
 4 files changed, 30 insertions(+), 18 deletions(-)

diff --git a/builtin/pull.c b/builtin/pull.c
index 9b2f76f9d9..73e06625c8 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -944,7 +944,7 @@ int cmd_pull(int argc, const char **argv, const char 
*prefix)
int ret = 0;
if ((recurse_submodules == RECURSE_SUBMODULES_ON ||
 recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND) &&
-   submodule_touches_in_range(_fork_point, _head))
+   submodule_touches_in_range(_index, _fork_point, 
_head))
die(_("cannot rebase with locally recorded submodule 
modifications"));
if (!autostash) {
struct commit_list *list = NULL;
diff --git a/submodule.c b/submodule.c
index 50cbf5f13e..c0c1224760 100644
--- a/submodule.c
+++ b/submodule.c
@@ -766,7 +766,8 @@ static void collect_changed_submodules_cb(struct 
diff_queue_struct *q,
  * have a corresponding 'struct oid_array' (in the 'util' field) which lists
  * what the submodule pointers were updated to during the change.
  */
-static void collect_changed_submodules(struct string_list *changed,
+static void collect_changed_submodules(struct index_state *istate,
+  struct string_list *changed,
   struct argv_array *argv)
 {
struct rev_info rev;
@@ -930,8 +931,10 @@ static int submodule_needs_pushing(const char *path, 
struct oid_array *commits)
return 0;
 }
 
-int find_unpushed_submodules(struct oid_array *commits,
-   const char *remotes_name, struct string_list *needs_pushing)
+int find_unpushed_submodules(struct index_state *istate,
+struct oid_array *commits,
+const char *remotes_name,
+struct string_list *needs_pushing)
 {
struct string_list submodules = STRING_LIST_INIT_DUP;
struct string_list_item *name;
@@ -943,7 +946,7 @@ int find_unpushed_submodules(struct oid_array *commits,
argv_array_push(, "--not");
argv_array_pushf(, "--remotes=%s", remotes_name);
 
-   collect_changed_submodules(, );
+   collect_changed_submodules(istate, , );
 
for_each_string_list_item(name, ) {
struct oid_array *commits = name->util;
@@ -1044,7 +1047,8 @@ static void submodule_push_check(const char *path, const 
char *head,
die("process for submodule '%s' failed", path);
 }
 
-int push_unpushed_submodules(struct oid_array *commits,
+int push_unpushed_submodules(struct index_state *istate,
+struct oid_array *commits,
 const struct remote *remote,
 const struct refspec *rs,
 const struct string_list *push_options,
@@ -1053,7 +1057,8 @@ int push_unpushed_submodules(struct oid_array *commits,
int i, ret = 1;
struct string_list needs_pushing = STRING_LIST_INIT_DUP;
 
-   if (!find_unpushed_submodules(commits, remote->name, _pushing))
+   if (!find_unpushed_submodules(istate, commits,
+ remote->name, _pushing))
return 1;
 
/*
@@ -1110,7 +1115,7 @@ void check_for_new_submodule_commits(struct object_id 
*oid)
oid_array_append(_tips_after_fetch, oid);
 }
 
-static void calculate_changed_submodule_paths(void)
+static void calculate_changed_submodule_paths(struct index_state *istate)
 {
struct argv_array argv = ARGV_ARRAY_INIT;
struct string_list changed_submodules = STRING_LIST_INIT_DUP;
@@ -1131,7 +1136,7 @@ static void calculate_changed_submodule_paths(void)
 * Collect all submodules (whether checked out or not) for which new
 * commits have been recorded upstream in "changed_submodule_names".
 */
-   collect_changed_submodules(_submodules, );
+   collect_changed_submodules(istate, _submodules, );
 
for_each_string_list_item(name, _submodules) {
struct oid_array *commits = name->util;
@@ -1158,7 +1163,8 @@ static void calculate_changed_submodule_paths(void)
initialized_fetch_ref_tips = 0;
 }
 
-int submodule_touches_in_range(struct object_id *excl_oid,
+int submodule_touches_in_range(struct index_state *istate,
+  struct object_id *excl_oid,
   struct object_id *incl_oid)
 {
struct string_list subs = STRING_LIST_INIT_DUP;
@@ -1176,7 +1182,7 @@ int submodule_touches_in_range(struct object_id *excl_oid,
argv_array_push(, oid_to_hex(excl_oid));
}
 
-   collect_changed_submodules(, );
+   collect_changed_submodules(istate, , );
ret = subs.nr;
 
   

[PATCH 00/21] Kill the_index part 4

2018-08-26 Thread Nguyễn Thái Ngọc Duy
This continues the journey of getting rid of the_index at least in
library code. The focus of part 4 is diff code. Since 'struct
repository *' is passed around more (and even more in part 5), I take
this opportunity to remove some the_repository references too.

Besides some small conflicts on 'pu', like the previous part, it also
breaks 'pu' because of API changes. The fix is trivial though, just
prepend the_repository as the first argument for the broken function
calls.

After this and ~20 more patches in part5, the_index is gone from
library code.

Nguyễn Thái Ngọc Duy (21):
  archive.c: remove implicit dependency the_repository
  read-cache.c: remove 'const' from index_has_changes()
  combine-diff.c: remove implicit dependency on the_index
  diff.c: remove the_index dependency in textconv() functions
  grep.c: remove implicit dependency on the_index
  diff.c: remove implicit dependency on the_index
  read-cache.c: remove implicit dependency on the_index
  diff-lib.c: remove implicit dependency on the_index
  ll-merge.c: remove implicit dependency on the_index
  merge-blobs.c: remove implicit dependency on the_index
  merge.c: remove implicit dependency on the_index
  patch-ids.c: remove implicit dependency on the_index
  sha1-file.c: remove implicit dependency on the_index
  rerere.c: remove implicit dependency on the_index
  userdiff.c: remove implicit dependency on the_index
  line-range.c: remove implicit dependency on the_index
  submodule.c: remove implicit dependency on the_index
  tree-diff.c: remove implicit dependency on the_index
  ws.c: remove implicit dependency on the_index
  wt-status.c: remove implicit dependency on the_index
  wt-status.c: remove implicit dependency the_repository

 apply.c|  19 +--
 archive-zip.c  |  14 ++-
 archive.c  |   2 +-
 blame.c|  27 +++--
 builtin/am.c   |   4 +-
 builtin/blame.c|   2 +-
 builtin/cat-file.c |   6 +-
 builtin/checkout.c |   3 +-
 builtin/commit.c   |   4 +-
 builtin/diff.c |   2 +-
 builtin/difftool.c |   2 +-
 builtin/grep.c |   7 +-
 builtin/hash-object.c  |   2 +-
 builtin/log.c  |   9 +-
 builtin/merge-tree.c   |   2 +-
 builtin/merge.c|  12 +-
 builtin/pull.c |  12 +-
 builtin/range-diff.c   |   2 +-
 builtin/replace.c  |   2 +-
 builtin/rerere.c   |   6 +-
 builtin/reset.c|   1 +
 builtin/update-index.c |   2 +-
 cache.h|  14 ++-
 combine-diff.c |  32 ++---
 diff-lib.c |  17 +--
 diff-no-index.c|   9 +-
 diff.c | 259 +++--
 diff.h |  19 ++-
 diffcore-break.c   |  12 +-
 diffcore-delta.c   |  12 +-
 diffcore-pickaxe.c |   8 +-
 diffcore-rename.c  |  35 +++---
 diffcore.h |  13 ++-
 grep.c |  34 +++---
 grep.h |  10 +-
 line-log.c |  25 ++--
 line-range.c   |  22 ++--
 line-range.h   |   6 +-
 ll-merge.c |  17 +--
 ll-merge.h |   5 +-
 merge-blobs.c  |  16 ++-
 merge-blobs.h  |   7 +-
 merge-recursive.c  |   5 +-
 merge.c|  20 ++--
 notes-merge.c  |   9 +-
 patch-ids.c|   4 +-
 patch-ids.h|   3 +-
 read-cache.c   |  33 +++---
 ref-filter.c   |   2 +-
 rerere.c   | 121 ++-
 rerere.h   |   9 +-
 revision.c |   8 +-
 sequencer.c|  16 +--
 sha1-file.c|  50 
 submodule.c|  28 +++--
 submodule.h|   9 +-
 transport.c|   9 +-
 tree-diff.c|   2 +-
 userdiff.c |   5 +-
 userdiff.h |   3 +-
 ws.c   |   5 +-
 wt-status.c|  88 --
 wt-status.h|  21 +++-
 63 files changed, 682 insertions(+), 482 deletions(-)

-- 
2.19.0.rc0.337.ge906d732e7



[GitHub] Your password was reset

2018-08-26 Thread GitHub
Hello amc2399,

We wanted to let you know that your GitHub password was reset.

If you did not perform this action, you can recover access by entering 
git@vger.kernel.org into the form at https://github.com/password_reset

To see this and other security events for your account, visit 
https://github.com/settings/security

If you run into problems, please contact support by visiting 
https://github.com/contact

Please do not reply to this email with your password. We will never ask for 
your password, and we strongly discourage you from sharing it with anyone.


[GitHub] Please reset your password

2018-08-26 Thread GitHub
We heard that you lost your GitHub password. Sorry about that!

But don’t worry! You can use the following link to reset your password:

https://github.com/password_reset/0289e079249d6968ef22556b1ddd0d6f2700c17a8b603a7a92ce5b829e1883a5656d61696cb367697440766765722e6b65726e656c2e6f7267a5666f726365c2b374776f5f666163746f725f7665726966696564c2

If you don’t use this link within 3 hours, it will expire. To get a new 
password reset link, visit https://github.com/password_reset

Thanks,
Your friends at GitHub


[GitHub] Your password was reset

2018-08-26 Thread GitHub
Hello amc2399,

We wanted to let you know that your GitHub password was reset.

If you did not perform this action, you can recover access by entering 
git@vger.kernel.org into the form at https://github.com/password_reset

To see this and other security events for your account, visit 
https://github.com/settings/security

If you run into problems, please contact support by visiting 
https://github.com/contact

Please do not reply to this email with your password. We will never ask for 
your password, and we strongly discourage you from sharing it with anyone.


[GitHub] Please reset your password

2018-08-26 Thread GitHub
We heard that you lost your GitHub password. Sorry about that!

But don’t worry! You can use the following link to reset your password:

https://github.com/password_reset/0289e07960cb65215eefb2f61c23506a55bbfa82268ca3c092ce5b82779283a5656d61696cb367697440766765722e6b65726e656c2e6f7267a5666f726365c2b374776f5f666163746f725f7665726966696564c2

If you don’t use this link within 3 hours, it will expire. To get a new 
password reset link, visit https://github.com/password_reset

Thanks,
Your friends at GitHub


[GitHub] Your password was reset

2018-08-26 Thread GitHub
Hello amc2399,

We wanted to let you know that your GitHub password was reset.

If you did not perform this action, you can recover access by entering 
git@vger.kernel.org into the form at https://github.com/password_reset

To see this and other security events for your account, visit 
https://github.com/settings/security

If you run into problems, please contact support by visiting 
https://github.com/contact

Please do not reply to this email with your password. We will never ask for 
your password, and we strongly discourage you from sharing it with anyone.