Re: [PATCH v4] http-backend: allow empty CONTENT_LENGTH

2018-09-09 Thread Jonathan Nieder
Max Kirillov wrote:

> Reported-By: Jelmer Vernooij 
> Authored-by: Jeff King 
> Signed-off-by: Max Kirillov 

Nit: for this kind of case of forwarding someone else's patch, we put
a From field at the beginning of the body of the message.  "git
format-patch" can produce a message with that format if you commit
with 'git commit --author="Someone Else "' and run
format-patch with --from="My Name ".  More details are
in the DISCUSSION section of git-format-patch(1).

As with v3, since v2 is already in "next" this should go incremental.

[...]
> --- a/http-backend.c
> +++ b/http-backend.c
> @@ -353,8 +353,28 @@ static ssize_t get_content_length(void)
>   ssize_t val = -1;
>   const char *str = getenv("CONTENT_LENGTH");
>  
> - if (str && !git_parse_ssize_t(str, ))
> - die("failed to parse CONTENT_LENGTH: %s", str);
> + if (!str) {
> + /*
> +  * RFC3875 says this must mean "no body", but in practice we
> +  * receive chunked encodings with no CONTENT_LENGTH. Tell the
> +  * caller to read until EOF.
> +  */
> + val = -1;
> + } else if (!*str) {
> + /*
> +  * An empty length should be treated as "no body" according to
> +  * RFC3875, and this seems to hold in practice.
> +  */
> + val = 0;

Are there example callers that this version fixes?  Where can I read
more, or what can I run to experience it?

For example, v2.19.0-rc0~45^2~2 (http-backend: respect CONTENT_LENGTH
as specified by rfc3875, 2018-06-10) mentions IIS/Windows; does IIS
make use of this distinction?

Thanks,
Jonathan


Re: [PATCH v3] http-backend: allow empty CONTENT_LENGTH

2018-09-09 Thread Jonathan Nieder
From: Max Kirillov 
Subject: http-backend test: make empty CONTENT_LENGTH test more realistic

This is a test of smart HTTP, so it should use the smart HTTP endpoints
(e.g. /info/refs?service=git-receive-pack), not dumb HTTP (HEAD).

Signed-off-by: Max Kirillov 
Signed-off-by: Jonathan Nieder 
---
Max Kirillov wrote:

> Provided more thorough message, also fix test (it did not test
> actually the error before)
>
> There will be more versions later, at least the one which suggested
> by Jeff

v2 is in "next", and I believe that version should already be
sufficient for Git 2.19.  Please correct me if I'm wrong.

Since v2 is in "next", I think any further refinements are supposed to
be incremental patches on top.  Here's an example (representing the
v2->v3 diff).  It's more of an RFC than a serious patch, because:

This version of the test doesn't seem to reproduce the bug.  When I
run the test against the unfixed version of http-backend, it passes.
Ideas?

Not about this patch: could this test share some infrustructure with
t5560-http-backend-noserver.sh?  If there were some common shell
library that they shared, the tests might be easier to read and write.

Thanks,
Jonathan

 t/t5562-http-backend-content-length.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/t5562-http-backend-content-length.sh 
b/t/t5562-http-backend-content-length.sh
index f94d01f69e..fceb3d39c1 100755
--- a/t/t5562-http-backend-content-length.sh
+++ b/t/t5562-http-backend-content-length.sh
@@ -155,8 +155,8 @@ test_expect_success 'CONTENT_LENGTH overflow ssite_t' '
 
 test_expect_success 'empty CONTENT_LENGTH' '
env \
-   QUERY_STRING=/repo.git/HEAD \
-   PATH_TRANSLATED="$PWD"/.git/HEAD \
+   QUERY_STRING="/repo.git/info/refs?service=git-receive-pack" \
+   PATH_TRANSLATED="$PWD"/.git/info/refs \
GIT_HTTP_EXPORT_ALL=TRUE \
REQUEST_METHOD=GET \
CONTENT_LENGTH="" \
-- 
2.19.0.rc2.392.g5ba43deb5a



Re: [PATCH 1/6] t/helper: keep test-tool command list sorted

2018-09-09 Thread brian m. carlson
On Sun, Sep 09, 2018 at 07:36:26PM +0200, Nguyễn Thái Ngọc Duy wrote:
> Signed-off-by: Nguyễn Thái Ngọc Duy 
> ---
>  Makefile | 2 +-
>  t/helper/test-tool.c | 2 +-
>  t/helper/test-tool.h | 2 +-
>  3 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index 5a969f5830..1208584fa1 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -729,8 +729,8 @@ TEST_BUILTINS_OBJS += test-repository.o
>  TEST_BUILTINS_OBJS += test-revision-walking.o
>  TEST_BUILTINS_OBJS += test-run-command.o
>  TEST_BUILTINS_OBJS += test-scrap-cache-tree.o
> -TEST_BUILTINS_OBJS += test-sha1-array.o
>  TEST_BUILTINS_OBJS += test-sha1.o
> +TEST_BUILTINS_OBJS += test-sha1-array.o
>  TEST_BUILTINS_OBJS += test-sigchain.o
>  TEST_BUILTINS_OBJS += test-strcmp-offset.o
>  TEST_BUILTINS_OBJS += test-string-list.o

Thanks for fixing this.
-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204


signature.asc
Description: PGP signature


Re: [Possible GIT Bug]

2018-09-09 Thread Bryan Turner
On Sun, Sep 9, 2018 at 6:31 AM Dylan Young  wrote:
>
> Works:
>
> git show -C --find-copies-harder  055f6c89fa4506037d1621761f13430f469b8029
>
> git show -C --find-copies-harder
> 055f6c89fa4506037d1621761f13430f469b8029 --name-status

Here, because you didn't provide _any_ paths, Git is allowed to
consider all of the paths modified in the commit and, because you
specified --find-copies-harder, it's allowed to consider paths that
_weren't_ modified too. That means it can "see" both the source and
destination for the copy, and it detects the copy as you're expecting.

>
> Doesn’t Work:
>
> git show -C --find-copies-harder
> 055f6c89fa4506037d1621761f13430f469b8029  --  PATH_TO_MY_COPIED_FILE

Here, though, you've _explicitly limited_ Git to only the copied file.
It's not allowed to consider any others, which means it can't "see"
the source path anymore. As a result, the copy is detected as a
straight add. Note that --find-copies-harder means the diff machinery
is allowed to consider files that weren't modified in the commit as
possible sources for copies, but that's still subject to your explicit
filtering. In other words, if PATH_TO_SOURCE_FILE wasn't modified,
running this would _not_ see a copy:

git show -C 055f6c89fa4506037d1621761f13430f469b8029  --
PATH_TO_MY_COPIED_FILE PATH_TO_SOURCE_FILE

But running this would:

git show -C -C 055f6c89fa4506037d1621761f13430f469b8029  --
PATH_TO_MY_COPIED_FILE PATH_TO_SOURCE_FILE

No bugs here. Everything is working as intended, if not, perhaps, as
you expected.

Hope this helps,
Bryan

>
> i.e.
>
> --- /dev/null
>
> +++ b/ PATH_TO_MY_COPIED_FILE
>
> Hope that’s self-explanatory!!!
>
> Best,
> Casey Meijer


Re: [PATCH 0/6] Merge remaining t/helper binaries to test-tool

2018-09-09 Thread Duy Nguyen
On Sun, Sep 9, 2018 at 8:09 PM Ævar Arnfjörð Bjarmason  wrote:
>
>
> On Sun, Sep 09 2018, Nguyễn Thái Ngọc Duy wrote:
>
> > Last time when I added test-tool in 27f25845cf (Merge branch
> > 'nd/combined-test-helper' - 2018-04-11) I left out a few test programs
> > because there were a couple in-flight new tests that used them. All
> > those topics are merged now. So we can merge these to test-tool and
> > call it done.
>
> This is great. Just a small side-note: Am I the only one who misses the
> 2.8.0 days when you could do "git clean -dxff" in the t/ directory to
> clean up various test crap without breaking subsequent tests?

Isn't "make clean" (in t/) enough?

> That went away in e6e7530d10 ("test helpers: move test-* to t/helper/
> subdirectory", 2016-04-13) when we started building stuff in t/helper/.
>
> So now that this is one binary perhaps we can build it in the root
> directory and get that functionality back?

It's still a few binaries. Most of them are now merged to test-tool,
but ones that need separate program name, or have extra deps, stay
separate. Having said that, producing the binaries at root directory
is possible. I'm just not sure if it's worth doing.
-- 
Duy


Re: [PATCH 0/6] Merge remaining t/helper binaries to test-tool

2018-09-09 Thread Ævar Arnfjörð Bjarmason


On Sun, Sep 09 2018, Nguyễn Thái Ngọc Duy wrote:

> Last time when I added test-tool in 27f25845cf (Merge branch
> 'nd/combined-test-helper' - 2018-04-11) I left out a few test programs
> because there were a couple in-flight new tests that used them. All
> those topics are merged now. So we can merge these to test-tool and
> call it done.

This is great. Just a small side-note: Am I the only one who misses the
2.8.0 days when you could do "git clean -dxff" in the t/ directory to
clean up various test crap without breaking subsequent tests?

That went away in e6e7530d10 ("test helpers: move test-* to t/helper/
subdirectory", 2016-04-13) when we started building stuff in t/helper/.

So now that this is one binary perhaps we can build it in the root
directory and get that functionality back?


[PATCH 3/6] t/helper: merge test-pkt-line into test-tool

2018-09-09 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Makefile   |  2 +-
 t/helper/test-pkt-line.c   |  3 ++-
 t/helper/test-tool.c   |  1 +
 t/helper/test-tool.h   |  1 +
 t/t5701-git-serve.sh   | 36 +++---
 t/t5702-protocol-v2.sh |  2 +-
 t/t5703-upload-pack-ref-in-want.sh | 14 ++--
 7 files changed, 31 insertions(+), 28 deletions(-)

diff --git a/Makefile b/Makefile
index fa67d76780..d9a4029895 100644
--- a/Makefile
+++ b/Makefile
@@ -722,6 +722,7 @@ TEST_BUILTINS_OBJS += test-mergesort.o
 TEST_BUILTINS_OBJS += test-mktemp.o
 TEST_BUILTINS_OBJS += test-online-cpus.o
 TEST_BUILTINS_OBJS += test-path-utils.o
+TEST_BUILTINS_OBJS += test-pkt-line.o
 TEST_BUILTINS_OBJS += test-prio-queue.o
 TEST_BUILTINS_OBJS += test-read-cache.o
 TEST_BUILTINS_OBJS += test-ref-store.o
@@ -745,7 +746,6 @@ TEST_PROGRAMS_NEED_X += test-dump-fsmonitor
 TEST_PROGRAMS_NEED_X += test-fake-ssh
 TEST_PROGRAMS_NEED_X += test-line-buffer
 TEST_PROGRAMS_NEED_X += test-parse-options
-TEST_PROGRAMS_NEED_X += test-pkt-line
 TEST_PROGRAMS_NEED_X += test-svn-fe
 TEST_PROGRAMS_NEED_X += test-tool
 
diff --git a/t/helper/test-pkt-line.c b/t/helper/test-pkt-line.c
index 30775f986f..282d536384 100644
--- a/t/helper/test-pkt-line.c
+++ b/t/helper/test-pkt-line.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "test-tool.h"
 #include "pkt-line.h"
 
 static void pack_line(const char *line)
@@ -79,7 +80,7 @@ static void unpack_sideband(void)
}
 }
 
-int cmd_main(int argc, const char **argv)
+int cmd__pkt_line(int argc, const char **argv)
 {
if (argc < 2)
die("too few arguments");
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index 820335704a..0ef53152c4 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -27,6 +27,7 @@ static struct test_cmd cmds[] = {
{ "mktemp", cmd__mktemp },
{ "online-cpus", cmd__online_cpus },
{ "path-utils", cmd__path_utils },
+   { "pkt-line", cmd__pkt_line },
{ "prio-queue", cmd__prio_queue },
{ "read-cache", cmd__read_cache },
{ "ref-store", cmd__ref_store },
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index 118c700c7a..7a0ac22ef7 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -23,6 +23,7 @@ int cmd__mergesort(int argc, const char **argv);
 int cmd__mktemp(int argc, const char **argv);
 int cmd__online_cpus(int argc, const char **argv);
 int cmd__path_utils(int argc, const char **argv);
+int cmd__pkt_line(int argc, const char **argv);
 int cmd__prio_queue(int argc, const char **argv);
 int cmd__read_cache(int argc, const char **argv);
 int cmd__ref_store(int argc, const char **argv);
diff --git a/t/t5701-git-serve.sh b/t/t5701-git-serve.sh
index 75ec79e6cb..29a54fbfff 100755
--- a/t/t5701-git-serve.sh
+++ b/t/t5701-git-serve.sh
@@ -15,13 +15,13 @@ test_expect_success 'test capability advertisement' '
EOF
 
git serve --advertise-capabilities >out &&
-   test-pkt-line unpack actual &&
+   test-tool pkt-line unpack actual &&
test_cmp actual expect
 '
 
 test_expect_success 'stateless-rpc flag does not list capabilities' '
# Empty request
-   test-pkt-line pack >in <<-EOF &&
+   test-tool pkt-line pack >in <<-EOF &&

EOF
git serve --stateless-rpc >out in <<-EOF &&
+   test-tool pkt-line pack >in <<-EOF &&
foobar

EOF
@@ -42,7 +42,7 @@ test_expect_success 'request invalid capability' '
 '
 
 test_expect_success 'request with no command' '
-   test-pkt-line pack >in <<-EOF &&
+   test-tool pkt-line pack >in <<-EOF &&
agent=git/test

EOF
@@ -51,7 +51,7 @@ test_expect_success 'request with no command' '
 '
 
 test_expect_success 'request invalid command' '
-   test-pkt-line pack >in <<-EOF &&
+   test-tool pkt-line pack >in <<-EOF &&
command=foo
agent=git/test

@@ -71,7 +71,7 @@ test_expect_success 'setup some refs and tags' '
 '
 
 test_expect_success 'basics of ls-refs' '
-   test-pkt-line pack >in <<-EOF &&
+   test-tool pkt-line pack >in <<-EOF &&
command=ls-refs

EOF
@@ -88,12 +88,12 @@ test_expect_success 'basics of ls-refs' '
EOF
 
git serve --stateless-rpc out &&
-   test-pkt-line unpack actual &&
+   test-tool pkt-line unpack actual &&
test_cmp actual expect
 '
 
 test_expect_success 'basic ref-prefixes' '
-   test-pkt-line pack >in <<-EOF &&
+   test-tool pkt-line pack >in <<-EOF &&
command=ls-refs
0001
ref-prefix refs/heads/master
@@ -108,12 +108,12 @@ test_expect_success 'basic ref-prefixes' '
EOF
 
git serve --stateless-rpc out &&
-   test-pkt-line unpack actual &&
+   test-tool pkt-line unpack actual &&
test_cmp actual expect
 '
 
 test_expect_success 'refs/heads prefix' '
-  

[PATCH 2/6] t/helper: merge test-dump-untracked-cache into test-tool

2018-09-09 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Makefile |  2 +-
 t/helper/test-dump-untracked-cache.c |  3 +-
 t/helper/test-tool.c |  1 +
 t/helper/test-tool.h |  1 +
 t/t7063-status-untracked-cache.sh| 68 ++--
 t/t7519-status-fsmonitor.sh  |  4 +-
 6 files changed, 41 insertions(+), 38 deletions(-)

diff --git a/Makefile b/Makefile
index 1208584fa1..fa67d76780 100644
--- a/Makefile
+++ b/Makefile
@@ -710,6 +710,7 @@ TEST_BUILTINS_OBJS += test-delta.o
 TEST_BUILTINS_OBJS += test-drop-caches.o
 TEST_BUILTINS_OBJS += test-dump-cache-tree.o
 TEST_BUILTINS_OBJS += test-dump-split-index.o
+TEST_BUILTINS_OBJS += test-dump-untracked-cache.o
 TEST_BUILTINS_OBJS += test-example-decorate.o
 TEST_BUILTINS_OBJS += test-genrandom.o
 TEST_BUILTINS_OBJS += test-hashmap.o
@@ -741,7 +742,6 @@ TEST_BUILTINS_OBJS += test-wildmatch.o
 TEST_BUILTINS_OBJS += test-write-cache.o
 
 TEST_PROGRAMS_NEED_X += test-dump-fsmonitor
-TEST_PROGRAMS_NEED_X += test-dump-untracked-cache
 TEST_PROGRAMS_NEED_X += test-fake-ssh
 TEST_PROGRAMS_NEED_X += test-line-buffer
 TEST_PROGRAMS_NEED_X += test-parse-options
diff --git a/t/helper/test-dump-untracked-cache.c 
b/t/helper/test-dump-untracked-cache.c
index bd92fb305a..52870ebbb3 100644
--- a/t/helper/test-dump-untracked-cache.c
+++ b/t/helper/test-dump-untracked-cache.c
@@ -1,3 +1,4 @@
+#include "test-tool.h"
 #include "cache.h"
 #include "dir.h"
 
@@ -38,7 +39,7 @@ static void dump(struct untracked_cache_dir *ucd, struct 
strbuf *base)
strbuf_setlen(base, len);
 }
 
-int cmd_main(int ac, const char **av)
+int cmd__dump_untracked_cache(int ac, const char **av)
 {
struct untracked_cache *uc;
struct strbuf base = STRBUF_INIT;
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index 79e03eecb5..820335704a 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -15,6 +15,7 @@ static struct test_cmd cmds[] = {
{ "drop-caches", cmd__drop_caches },
{ "dump-cache-tree", cmd__dump_cache_tree },
{ "dump-split-index", cmd__dump_split_index },
+   { "dump-untracked-cache", cmd__dump_untracked_cache },
{ "example-decorate", cmd__example_decorate },
{ "genrandom", cmd__genrandom },
{ "hashmap", cmd__hashmap },
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index 4b7212827a..118c700c7a 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -11,6 +11,7 @@ int cmd__delta(int argc, const char **argv);
 int cmd__drop_caches(int argc, const char **argv);
 int cmd__dump_cache_tree(int argc, const char **argv);
 int cmd__dump_split_index(int argc, const char **argv);
+int cmd__dump_untracked_cache(int argc, const char **argv);
 int cmd__example_decorate(int argc, const char **argv);
 int cmd__genrandom(int argc, const char **argv);
 int cmd__hashmap(int argc, const char **argv);
diff --git a/t/t7063-status-untracked-cache.sh 
b/t/t7063-status-untracked-cache.sh
index 2da57fce7b..190ae149cf 100755
--- a/t/t7063-status-untracked-cache.sh
+++ b/t/t7063-status-untracked-cache.sh
@@ -55,7 +55,7 @@ test_expect_success 'setup' '
 '
 
 test_expect_success 'untracked cache is empty' '
-   test-dump-untracked-cache >../actual &&
+   test-tool dump-untracked-cache >../actual &&
cat >../expect-empty <../actual &&
+   test-tool dump-untracked-cache >../actual &&
test_cmp ../dump.expect ../actual
 '
 
@@ -126,7 +126,7 @@ EOF
 '
 
 test_expect_success 'untracked cache after second status' '
-   test-dump-untracked-cache >../actual &&
+   test-tool dump-untracked-cache >../actual &&
test_cmp ../dump.expect ../actual
 '
 
@@ -157,7 +157,7 @@ EOF
 '
 
 test_expect_success 'verify untracked cache dump' '
-   test-dump-untracked-cache >../actual &&
+   test-tool dump-untracked-cache >../actual &&
cat >../expect <../actual &&
+   test-tool dump-untracked-cache >../actual &&
cat >../expect <../actual &&
+   test-tool dump-untracked-cache >../actual &&
cat >../expect <../actual &&
+   test-tool dump-untracked-cache >../actual &&
cat >../expect <../actual &&
+   test-tool dump-untracked-cache >../actual &&
cat >../expect <../actual &&
+   test-tool dump-untracked-cache >../actual &&
cat >../expect <../actual &&
+   test-tool dump-untracked-cache >../actual &&
cat >../expect <../actual &&
+   test-tool dump-untracked-cache >../actual &&
cat >../expect <../actual &&
+   test-tool dump-untracked-cache >../actual &&
cat >../expect <../actual &&
+   test-tool dump-untracked-cache >../actual &&
cat >../expect-from-test-dump <../actual &&
+   test-tool dump-untracked-cache >../actual &&
echo "no untracked cache" >../expect-no-uc &&
test_cmp ../expect-no-uc ../actual
 '
 
 test_expect_success 'git status does not change anything' '
git status &&
-   

[PATCH 6/6] Makefile: add a hint about TEST_BUILTINS_OBJS

2018-09-09 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Makefile | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Makefile b/Makefile
index ea7454632d..39d39257e0 100644
--- a/Makefile
+++ b/Makefile
@@ -744,6 +744,8 @@ TEST_BUILTINS_OBJS += test-urlmatch-normalization.o
 TEST_BUILTINS_OBJS += test-wildmatch.o
 TEST_BUILTINS_OBJS += test-write-cache.o
 
+# Do not add more tests here unless they have extra dependencies. Add
+# them in TEST_BUILTINS_OBJS above.
 TEST_PROGRAMS_NEED_X += test-fake-ssh
 TEST_PROGRAMS_NEED_X += test-line-buffer
 TEST_PROGRAMS_NEED_X += test-svn-fe
-- 
2.19.0.rc0.337.ge906d732e7



[PATCH 5/6] t/helper: merge test-dump-fsmonitor into test-tool

2018-09-09 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Makefile   |  2 +-
 t/helper/test-dump-fsmonitor.c |  3 ++-
 t/helper/test-tool.c   |  1 +
 t/helper/test-tool.h   |  1 +
 t/t7519-status-fsmonitor.sh| 10 +-
 5 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/Makefile b/Makefile
index 1a8a7cb82d..ea7454632d 100644
--- a/Makefile
+++ b/Makefile
@@ -709,6 +709,7 @@ TEST_BUILTINS_OBJS += test-date.o
 TEST_BUILTINS_OBJS += test-delta.o
 TEST_BUILTINS_OBJS += test-drop-caches.o
 TEST_BUILTINS_OBJS += test-dump-cache-tree.o
+TEST_BUILTINS_OBJS += test-dump-fsmonitor.o
 TEST_BUILTINS_OBJS += test-dump-split-index.o
 TEST_BUILTINS_OBJS += test-dump-untracked-cache.o
 TEST_BUILTINS_OBJS += test-example-decorate.o
@@ -743,7 +744,6 @@ TEST_BUILTINS_OBJS += test-urlmatch-normalization.o
 TEST_BUILTINS_OBJS += test-wildmatch.o
 TEST_BUILTINS_OBJS += test-write-cache.o
 
-TEST_PROGRAMS_NEED_X += test-dump-fsmonitor
 TEST_PROGRAMS_NEED_X += test-fake-ssh
 TEST_PROGRAMS_NEED_X += test-line-buffer
 TEST_PROGRAMS_NEED_X += test-svn-fe
diff --git a/t/helper/test-dump-fsmonitor.c b/t/helper/test-dump-fsmonitor.c
index ad452707e8..08e3684aff 100644
--- a/t/helper/test-dump-fsmonitor.c
+++ b/t/helper/test-dump-fsmonitor.c
@@ -1,6 +1,7 @@
+#include "test-tool.h"
 #include "cache.h"
 
-int cmd_main(int ac, const char **av)
+int cmd__dump_fsmonitor(int ac, const char **av)
 {
struct index_state *istate = _index;
int i;
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index 9cc21024e9..6261c2fda0 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -14,6 +14,7 @@ static struct test_cmd cmds[] = {
{ "delta", cmd__delta },
{ "drop-caches", cmd__drop_caches },
{ "dump-cache-tree", cmd__dump_cache_tree },
+   { "dump-fsmonitor", cmd__dump_fsmonitor },
{ "dump-split-index", cmd__dump_split_index },
{ "dump-untracked-cache", cmd__dump_untracked_cache },
{ "example-decorate", cmd__example_decorate },
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index 527722f4b0..38da025511 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -10,6 +10,7 @@ int cmd__date(int argc, const char **argv);
 int cmd__delta(int argc, const char **argv);
 int cmd__drop_caches(int argc, const char **argv);
 int cmd__dump_cache_tree(int argc, const char **argv);
+int cmd__dump_fsmonitor(int argc, const char **argv);
 int cmd__dump_split_index(int argc, const char **argv);
 int cmd__dump_untracked_cache(int argc, const char **argv);
 int cmd__example_decorate(int argc, const char **argv);
diff --git a/t/t7519-status-fsmonitor.sh b/t/t7519-status-fsmonitor.sh
index 603d27789b..8384ad258c 100755
--- a/t/t7519-status-fsmonitor.sh
+++ b/t/t7519-status-fsmonitor.sh
@@ -84,21 +84,21 @@ test_expect_success 'setup' '
 
 # test that the fsmonitor extension is off by default
 test_expect_success 'fsmonitor extension is off by default' '
-   test-dump-fsmonitor >actual &&
+   test-tool dump-fsmonitor >actual &&
grep "^no fsmonitor" actual
 '
 
 # test that "update-index --fsmonitor" adds the fsmonitor extension
 test_expect_success 'update-index --fsmonitor" adds the fsmonitor extension' '
git update-index --fsmonitor &&
-   test-dump-fsmonitor >actual &&
+   test-tool dump-fsmonitor >actual &&
grep "^fsmonitor last update" actual
 '
 
 # test that "update-index --no-fsmonitor" removes the fsmonitor extension
 test_expect_success 'update-index --no-fsmonitor" removes the fsmonitor 
extension' '
git update-index --no-fsmonitor &&
-   test-dump-fsmonitor >actual &&
+   test-tool dump-fsmonitor >actual &&
grep "^no fsmonitor" actual
 '
 
@@ -307,9 +307,9 @@ test_expect_success 'splitting the index results in the 
same state' '
dirty_repo &&
git update-index --fsmonitor  &&
git ls-files -f >expect &&
-   test-dump-fsmonitor >&2 && echo &&
+   test-tool dump-fsmonitor >&2 && echo &&
git update-index --fsmonitor --split-index &&
-   test-dump-fsmonitor >&2 && echo &&
+   test-tool dump-fsmonitor >&2 && echo &&
git ls-files -f >actual &&
test_cmp expect actual
 '
-- 
2.19.0.rc0.337.ge906d732e7



[PATCH 4/6] t/helper: merge test-parse-options into test-tool

2018-09-09 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Makefile  |  2 +-
 t/helper/test-parse-options.c |  5 ++-
 t/helper/test-tool.c  |  1 +
 t/helper/test-tool.h  |  1 +
 t/t0040-parse-options.sh  | 70 +--
 5 files changed, 41 insertions(+), 38 deletions(-)

diff --git a/Makefile b/Makefile
index d9a4029895..1a8a7cb82d 100644
--- a/Makefile
+++ b/Makefile
@@ -721,6 +721,7 @@ TEST_BUILTINS_OBJS += test-match-trees.o
 TEST_BUILTINS_OBJS += test-mergesort.o
 TEST_BUILTINS_OBJS += test-mktemp.o
 TEST_BUILTINS_OBJS += test-online-cpus.o
+TEST_BUILTINS_OBJS += test-parse-options.o
 TEST_BUILTINS_OBJS += test-path-utils.o
 TEST_BUILTINS_OBJS += test-pkt-line.o
 TEST_BUILTINS_OBJS += test-prio-queue.o
@@ -745,7 +746,6 @@ TEST_BUILTINS_OBJS += test-write-cache.o
 TEST_PROGRAMS_NEED_X += test-dump-fsmonitor
 TEST_PROGRAMS_NEED_X += test-fake-ssh
 TEST_PROGRAMS_NEED_X += test-line-buffer
-TEST_PROGRAMS_NEED_X += test-parse-options
 TEST_PROGRAMS_NEED_X += test-svn-fe
 TEST_PROGRAMS_NEED_X += test-tool
 
diff --git a/t/helper/test-parse-options.c b/t/helper/test-parse-options.c
index 630c76d127..9cb8a0ea0f 100644
--- a/t/helper/test-parse-options.c
+++ b/t/helper/test-parse-options.c
@@ -1,3 +1,4 @@
+#include "test-tool.h"
 #include "cache.h"
 #include "parse-options.h"
 #include "string-list.h"
@@ -94,11 +95,11 @@ static void show(struct string_list *expect, int *status, 
const char *fmt, ...)
strbuf_release();
 }
 
-int cmd_main(int argc, const char **argv)
+int cmd__parse_options(int argc, const char **argv)
 {
const char *prefix = "prefix/";
const char *usage[] = {
-   "test-parse-options ",
+   "test-tool parse-options ",
"",
"A helper function for the parse-options API.",
NULL
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index 0ef53152c4..9cc21024e9 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -26,6 +26,7 @@ static struct test_cmd cmds[] = {
{ "mergesort", cmd__mergesort },
{ "mktemp", cmd__mktemp },
{ "online-cpus", cmd__online_cpus },
+   { "parse-options", cmd__parse_options },
{ "path-utils", cmd__path_utils },
{ "pkt-line", cmd__pkt_line },
{ "prio-queue", cmd__prio_queue },
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index 7a0ac22ef7..527722f4b0 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -22,6 +22,7 @@ int cmd__match_trees(int argc, const char **argv);
 int cmd__mergesort(int argc, const char **argv);
 int cmd__mktemp(int argc, const char **argv);
 int cmd__online_cpus(int argc, const char **argv);
+int cmd__parse_options(int argc, const char **argv);
 int cmd__path_utils(int argc, const char **argv);
 int cmd__pkt_line(int argc, const char **argv);
 int cmd__prio_queue(int argc, const char **argv);
diff --git a/t/t0040-parse-options.sh b/t/t0040-parse-options.sh
index 5b0560fa20..17d0c18feb 100755
--- a/t/t0040-parse-options.sh
+++ b/t/t0040-parse-options.sh
@@ -8,7 +8,7 @@ test_description='our own option parser'
 . ./test-lib.sh
 
 cat >expect <<\EOF
-usage: test-parse-options 
+usage: test-tool parse-options 
 
 A helper function for the parse-options API.
 
@@ -52,7 +52,7 @@ Standard options
 EOF
 
 test_expect_success 'test help' '
-   test_must_fail test-parse-options -h >output 2>output.err &&
+   test_must_fail test-tool parse-options -h >output 2>output.err &&
test_must_be_empty output.err &&
test_i18ncmp expect output
 '
@@ -64,7 +64,7 @@ check () {
shift &&
expect="$1" &&
shift &&
-   test-parse-options --expect="$what $expect" "$@"
+   test-tool parse-options --expect="$what $expect" "$@"
 }
 
 check_unknown_i18n() {
@@ -75,7 +75,7 @@ check_unknown_i18n() {
echo error: unknown switch \`${1#-}\' >expect ;;
esac &&
cat expect.err >>expect &&
-   test_must_fail test-parse-options $* >output 2>output.err &&
+   test_must_fail test-tool parse-options $* >output 2>output.err &&
test_must_be_empty output &&
test_i18ncmp expect output.err
 }
@@ -133,7 +133,7 @@ file: prefix/my.file
 EOF
 
 test_expect_success 'short options' '
-   test-parse-options -s123 -b -i 1729 -m 16k -b -vv -n -F my.file \
+   test-tool parse-options -s123 -b -i 1729 -m 16k -b -vv -n -F my.file \
>output 2>output.err &&
test_cmp expect output &&
test_must_be_empty output.err
@@ -153,7 +153,7 @@ file: prefix/fi.le
 EOF
 
 test_expect_success 'long options' '
-   test-parse-options --boolean --integer 1729 --magnitude 16k \
+   test-tool parse-options --boolean --integer 1729 --magnitude 16k \
--boolean --string2=321 --verbose --verbose --no-dry-run \
--abbrev=10 --file fi.le --obsolete \
>output 2>output.err &&
@@ -162,9 +162,9 @@ test_expect_success 'long 

[PATCH 0/6] Merge remaining t/helper binaries to test-tool

2018-09-09 Thread Nguyễn Thái Ngọc Duy
Last time when I added test-tool in 27f25845cf (Merge branch
'nd/combined-test-helper' - 2018-04-11) I left out a few test programs
because there were a couple in-flight new tests that used them. All
those topics are merged now. So we can merge these to test-tool and
call it done.

Nguyễn Thái Ngọc Duy (6):
  t/helper: keep test-tool command list sorted
  t/helper: merge test-dump-untracked-cache into test-tool
  t/helper: merge test-pkt-line into test-tool
  t/helper: merge test-parse-options into test-tool
  t/helper: merge test-dump-fsmonitor into test-tool
  Makefile: add a hint about TEST_BUILTINS_OBJS

 Makefile | 12 +++--
 t/helper/test-dump-fsmonitor.c   |  3 +-
 t/helper/test-dump-untracked-cache.c |  3 +-
 t/helper/test-parse-options.c|  5 +-
 t/helper/test-pkt-line.c |  3 +-
 t/helper/test-tool.c |  6 ++-
 t/helper/test-tool.h |  6 ++-
 t/t0040-parse-options.sh | 70 ++--
 t/t5701-git-serve.sh | 36 +++---
 t/t5702-protocol-v2.sh   |  2 +-
 t/t5703-upload-pack-ref-in-want.sh   | 14 +++---
 t/t7063-status-untracked-cache.sh| 68 +--
 t/t7519-status-fsmonitor.sh  | 14 +++---
 13 files changed, 128 insertions(+), 114 deletions(-)

-- 
2.19.0.rc0.337.ge906d732e7



[PATCH 1/6] t/helper: keep test-tool command list sorted

2018-09-09 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Makefile | 2 +-
 t/helper/test-tool.c | 2 +-
 t/helper/test-tool.h | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index 5a969f5830..1208584fa1 100644
--- a/Makefile
+++ b/Makefile
@@ -729,8 +729,8 @@ TEST_BUILTINS_OBJS += test-repository.o
 TEST_BUILTINS_OBJS += test-revision-walking.o
 TEST_BUILTINS_OBJS += test-run-command.o
 TEST_BUILTINS_OBJS += test-scrap-cache-tree.o
-TEST_BUILTINS_OBJS += test-sha1-array.o
 TEST_BUILTINS_OBJS += test-sha1.o
+TEST_BUILTINS_OBJS += test-sha1-array.o
 TEST_BUILTINS_OBJS += test-sigchain.o
 TEST_BUILTINS_OBJS += test-strcmp-offset.o
 TEST_BUILTINS_OBJS += test-string-list.o
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index 0edafcfd65..79e03eecb5 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -34,8 +34,8 @@ static struct test_cmd cmds[] = {
{ "revision-walking", cmd__revision_walking },
{ "run-command", cmd__run_command },
{ "scrap-cache-tree", cmd__scrap_cache_tree },
-   { "sha1-array", cmd__sha1_array },
{ "sha1", cmd__sha1 },
+   { "sha1-array", cmd__sha1_array },
{ "sigchain", cmd__sigchain },
{ "strcmp-offset", cmd__strcmp_offset },
{ "string-list", cmd__string_list },
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index e954e8c522..4b7212827a 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -30,8 +30,8 @@ int cmd__repository(int argc, const char **argv);
 int cmd__revision_walking(int argc, const char **argv);
 int cmd__run_command(int argc, const char **argv);
 int cmd__scrap_cache_tree(int argc, const char **argv);
-int cmd__sha1_array(int argc, const char **argv);
 int cmd__sha1(int argc, const char **argv);
+int cmd__sha1_array(int argc, const char **argv);
 int cmd__sigchain(int argc, const char **argv);
 int cmd__strcmp_offset(int argc, const char **argv);
 int cmd__string_list(int argc, const char **argv);
-- 
2.19.0.rc0.337.ge906d732e7



Re: [PATCH v6 17/21] range-diff: populate the man page

2018-09-09 Thread Ævar Arnfjörð Bjarmason


On Sun, Sep 09 2018, SZEDER Gábor wrote:

> On Sun, Sep 09, 2018 at 01:14:25PM +0200, Ævar Arnfjörð Bjarmason wrote:
>>
>> On Mon, Aug 13 2018, Johannes Schindelin via GitGitGadget wrote:
>>
>> I realize this topic has long since landed, just seemed like a good
>> thing to reply to to ask this question:
>>
>> > [...]
>> > +  (   | ... |)
>> > [...]
>> > + ::
>> > +  Compare the commits specified by the two ranges, where
>> > +  `` is considered an older version of ``.
>> > +
>> > +...::
>> > +  Equivalent to passing `..` and `..`.
>> > +
>> > +  ::
>> > +  Equivalent to passing `..` and `..`.
>> > +  Note that `` does not need to be the exact branch point
>> > +  of the branches. Example: after rebasing a branch `my-topic`,
>> > +  `git range-diff my-topic@{u} my-topic@{1} my-topic` would
>> > +  show the differences introduced by the rebase.
>>
>> I find myself using range-diff often by watching forced pushes to public
>> repos to see what others are doing, e.g. just now:
>>
>>  + 38b5f0fe72...718fbdedbc split-index-racy   -> 
>> szeder/split-index-racy  (forced update)
>
> Heh, spying on my wip bugfixes :)
>
>> And then I turn that into:
>>
>> # @{u} because I happen to be on 'master' and it's shorter to type
>> # than origin/master...
>> git range-diff @{u} 38b5f0fe72...718fbdedbc
>
> I don't understand what you want with that @{u} or 'origin/master' in
> the first place.  It's unnecessary, the three-dot notation on its own
> works just fine.

Maybe I've been using the wrong mode all along, I passed over by habits
from tbdiff, which were surely copy/pasted from somewhere.

Looking at the git-range-diff manpage though it recommends  
 over ... when the topic has been rebased, which is
usually the case for e.g. a topic that's submitted to git.git (usually
be the time feedback has been gathered & a re-submission has been made
Junio has pushed another "master").

So isn't "  " the right thing to use over
"..." for git.git use? I think so, but I'm not sure.

In any case, there are going to be those use-case where you should be
using "  ", and a rebase will be propagated by a
force-push, so I thought it made sense that range-diff could directly
consume the output of "fetch" in that case...

>> Only to get an error because it doesn't support that, but just:
>>
>> git range-diff @{u} 38b5f0fe72 718fbdedbc
>>
>> I think it would be convenient given that "fetch" produces this output
>> to support this sort of invocation as synonymous with the three-arg
>> form. Then you can directly copy/paste that from terminals that have a
>> convenient feature to highlight a continuous \S+ reason to copy/paste
>> it.
>>
>> I can patch it in, but maybe there's UI reasons not to do this that I'm
>> missing, e.g. confusion with the existing ... syntax. What
>> do you think?


Re: [PATCH v6 17/21] range-diff: populate the man page

2018-09-09 Thread SZEDER Gábor
On Sun, Sep 09, 2018 at 01:14:25PM +0200, Ævar Arnfjörð Bjarmason wrote:
> 
> On Mon, Aug 13 2018, Johannes Schindelin via GitGitGadget wrote:
> 
> I realize this topic has long since landed, just seemed like a good
> thing to reply to to ask this question:
> 
> > [...]
> > +   (   | ... |)
> > [...]
> > + ::
> > +   Compare the commits specified by the two ranges, where
> > +   `` is considered an older version of ``.
> > +
> > +...::
> > +   Equivalent to passing `..` and `..`.
> > +
> > +  ::
> > +   Equivalent to passing `..` and `..`.
> > +   Note that `` does not need to be the exact branch point
> > +   of the branches. Example: after rebasing a branch `my-topic`,
> > +   `git range-diff my-topic@{u} my-topic@{1} my-topic` would
> > +   show the differences introduced by the rebase.
> 
> I find myself using range-diff often by watching forced pushes to public
> repos to see what others are doing, e.g. just now:
> 
>  + 38b5f0fe72...718fbdedbc split-index-racy   -> 
> szeder/split-index-racy  (forced update)

Heh, spying on my wip bugfixes :)

> And then I turn that into:
> 
> # @{u} because I happen to be on 'master' and it's shorter to type
> # than origin/master...
> git range-diff @{u} 38b5f0fe72...718fbdedbc

I don't understand what you want with that @{u} or 'origin/master' in
the first place.  It's unnecessary, the three-dot notation on its own
works just fine.


> Only to get an error because it doesn't support that, but just:
> 
> git range-diff @{u} 38b5f0fe72 718fbdedbc
> 
> I think it would be convenient given that "fetch" produces this output
> to support this sort of invocation as synonymous with the three-arg
> form. Then you can directly copy/paste that from terminals that have a
> convenient feature to highlight a continuous \S+ reason to copy/paste
> it.
> 
> I can patch it in, but maybe there's UI reasons not to do this that I'm
> missing, e.g. confusion with the existing ... syntax. What
> do you think?


Re: Temporary git files for the gitdir created on a separate drive in workdir

2018-09-09 Thread Hultqvist
Since this thread started I haven't seen a single file mentioned being created,
Usually they appear during work days when there is more activity.
I've never seen the files created directly, only a larger amount of
them once in a while.

I will run process monitor and get back once I find out more.
Den lör 8 sep. 2018 kl 15:44 skrev Duy Nguyen :
>
> On Sat, Sep 8, 2018 at 3:09 PM Duy Nguyen  wrote:
> >
> > On Sat, Sep 8, 2018 at 11:28 AM Hultqvist  wrote:
> > >
> > > The bash commands are using a git and bash bundle that was installed
> > > in parallel with gitextensions(a gui for git)
> > >
> > > G:\Min enhet> set GIT_TRACE_SETUP=1
> > > G:\Min enhet> git st
> > > 10:40:28.881927 trace.c:318 setup: git_dir:
> > > C:/Users/hultqvist/Drive.git
> > > 10:40:28.881927 trace.c:319 setup: git_common_dir:
> > > C:/Users/hultqvist/Drive.git
> > > 10:40:28.881927 trace.c:320 setup: worktree: G:/Min enhet
> > > 10:40:28.881927 trace.c:321 setup: cwd: G:/Min enhet
> > > 10:40:28.881927 trace.c:322 setup: prefix: (null)
> > > 10:40:28.882930 chdir-notify.c:67   setup: chdir from 'G:/Min
> > > enhet' to 'G:/Min enhet'
> >
> > Unfortunately this looks good. Whenever those files 'index',
> > 'config'... are created, they should always be created in
> > C:\Users\hultqvist\Drive.git, not G:\Min enhet, including their
> > temporary versions. I don't know if there are any more changes on the
> > windows fork that could affect this though, I only checked git.git.
>
> BTW do you notice these files showing up after any particular command
> or they're always there after cloning? Perhaps some command got the
> ".git" directory discovery wrong and assumed $GIT_DIR=$GIT_WORK_TREE.
> We have a much bigger problem then.
> --
> Duy


[GIT PULL] l10n updates for 2.19.0 round 2

2018-09-09 Thread Jiang Xin
Hi Junio,

The following changes since commit 2f743933341f27603550fbf383a34dfcfd38:

  Git 2.19-rc1 (2018-08-28 12:01:01 -0700)

are available in the Git repository at:

  git://github.com/git-l10n/git-po tags/l10n-2.19.0-rnd2

for you to fetch changes up to c1ac5258dccbb62438c8df73d728271f7a316c99:

  l10n: zh_CN: for git v2.19.0 l10n round 1 to 2 (2018-09-09 22:38:39 +0800)


l10n for Git 2.19.0 round 2


Alexander Shopov (1):
  l10n: bg.po: Updated Bulgarian translation (3958t)

Christopher Díaz Riveros (1):
  l10n: es.po v2.19.0 round 2

Dimitriy Ryazantcev (1):
  l10n: ru.po: update Russian translation

Jean-Noël Avila (2):
  l10n: fr.po v2.19.0 rnd 1
  l10n: fr.po v2.19.0 rnd 2

Jiang Xin (8):
  l10n: zh_CN: review for git 2.18.0
  Merge branch 'maint' of git://github.com/git-l10n/git-po
  l10n: git.pot: v2.19.0 round 1 (382 new, 30 removed)
  Merge branch 'master' of git://github.com/git-l10n/git-po
  l10n: git.pot: v2.19.0 round 2 (3 new, 5 removed)
  Merge branch 'fr_2.19.0_rnd1' of git://github.com/jnavila/git
  Merge branch 'master' of git://github.com/alshopov/git-po
  l10n: zh_CN: for git v2.19.0 l10n round 1 to 2

Peter Krefting (2):
  l10n: sv.po: Update Swedish translation(3608t0f0u)
  l10n: sv.po: Update Swedish translation (3958t0f0u)

Ralf Thielow (1):
  l10n: de.po: translate 108 new messages

Raphaël Hertzog (1):
  l10n: fr: fix a message seen in git bisect

Trần Ngọc Quân (1):
  l10n: vi.po(3958t): updated Vietnamese translation v2.19.0 round 2

 po/bg.po|  7453 +
 po/de.po|  5183 +++-
 po/es.po|  7328 +---
 po/fr.po|  7384 
 po/git.pot  |  7316 
 po/ru.po| 10552 ++
 po/sv.po|  7373 
 po/vi.po|  7376 
 po/zh_CN.po |  7411 +
 9 files changed, 41801 insertions(+), 25575 deletions(-)


Fwd: [Possible GIT Bug]

2018-09-09 Thread Dylan Young
Works:



git show -C --find-copies-harder  055f6c89fa4506037d1621761f13430f469b8029

git show -C --find-copies-harder
055f6c89fa4506037d1621761f13430f469b8029 --name-status





Doesn’t Work:



git show -C --find-copies-harder
055f6c89fa4506037d1621761f13430f469b8029  --  PATH_TO_MY_COPIED_FILE



i.e.

--- /dev/null

+++ b/ PATH_TO_MY_COPIED_FILE





Hope that’s self-explanatory!!!



Best,





Casey Meijer


Re: [PATCH v6 17/21] range-diff: populate the man page

2018-09-09 Thread Ævar Arnfjörð Bjarmason


On Mon, Aug 13 2018, Johannes Schindelin via GitGitGadget wrote:

I realize this topic has long since landed, just seemed like a good
thing to reply to to ask this question:

> [...]
> + (   | ... |)
> [...]
> + ::
> + Compare the commits specified by the two ranges, where
> + `` is considered an older version of ``.
> +
> +...::
> + Equivalent to passing `..` and `..`.
> +
> +  ::
> + Equivalent to passing `..` and `..`.
> + Note that `` does not need to be the exact branch point
> + of the branches. Example: after rebasing a branch `my-topic`,
> + `git range-diff my-topic@{u} my-topic@{1} my-topic` would
> + show the differences introduced by the rebase.

I find myself using range-diff often by watching forced pushes to public
repos to see what others are doing, e.g. just now:

 + 38b5f0fe72...718fbdedbc split-index-racy   -> 
szeder/split-index-racy  (forced update)

And then I turn that into:

# @{u} because I happen to be on 'master' and it's shorter to type
# than origin/master...
git range-diff @{u} 38b5f0fe72...718fbdedbc

Only to get an error because it doesn't support that, but just:

git range-diff @{u} 38b5f0fe72 718fbdedbc

I think it would be convenient given that "fetch" produces this output
to support this sort of invocation as synonymous with the three-arg
form. Then you can directly copy/paste that from terminals that have a
convenient feature to highlight a continuous \S+ reason to copy/paste
it.

I can patch it in, but maybe there's UI reasons not to do this that I'm
missing, e.g. confusion with the existing ... syntax. What
do you think?


[PATCH v3 22/23] revision.c: remove implicit dependency on the_index

2018-09-09 Thread Nguyễn Thái Ngọc Duy
---
 .../technical/api-revision-walking.txt|  2 +-
 bisect.c  |  4 +--
 builtin/add.c |  4 +--
 builtin/am.c  |  6 ++--
 builtin/blame.c   |  2 +-
 builtin/checkout.c|  4 +--
 builtin/commit.c  |  2 +-
 builtin/describe.c|  4 +--
 builtin/diff-files.c  |  2 +-
 builtin/diff-index.c  |  2 +-
 builtin/diff-tree.c   |  2 +-
 builtin/diff.c|  2 +-
 builtin/fast-export.c |  2 +-
 builtin/fmt-merge-msg.c   |  2 +-
 builtin/log.c | 16 +-
 builtin/merge.c   |  4 +--
 builtin/pack-objects.c|  2 +-
 builtin/prune.c   |  2 +-
 builtin/reflog.c  |  2 +-
 builtin/rev-list.c|  2 +-
 builtin/revert.c  |  2 +-
 builtin/shortlog.c|  2 +-
 builtin/submodule--helper.c   |  2 +-
 bundle.c  |  4 +--
 diff-lib.c|  4 +--
 http-push.c   |  2 +-
 merge-recursive.c |  2 +-
 pack-bitmap-write.c   |  2 +-
 ref-filter.c  |  2 +-
 remote.c  |  2 +-
 revision.c| 32 +++
 revision.h| 13 ++--
 sequencer.c   |  8 ++---
 shallow.c |  2 +-
 submodule.c   |  6 ++--
 t/helper/test-revision-walking.c  |  2 +-
 wt-status.c   | 10 +++---
 37 files changed, 88 insertions(+), 77 deletions(-)

diff --git a/Documentation/technical/api-revision-walking.txt 
b/Documentation/technical/api-revision-walking.txt
index 55b878ade8..83e62533a0 100644
--- a/Documentation/technical/api-revision-walking.txt
+++ b/Documentation/technical/api-revision-walking.txt
@@ -15,7 +15,7 @@ revision list.
 Functions
 -
 
-`init_revisions`::
+`repo_init_revisions`::
 
Initialize a rev_info structure with default values. The second
parameter may be NULL or can be prefix path, and then the `.prefix`
diff --git a/bisect.c b/bisect.c
index e1275ba79e..6ae5e5b49e 100644
--- a/bisect.c
+++ b/bisect.c
@@ -632,7 +632,7 @@ static void bisect_rev_setup(struct rev_info *revs, const 
char *prefix,
struct argv_array rev_argv = ARGV_ARRAY_INIT;
int i;
 
-   init_revisions(revs, prefix);
+   repo_init_revisions(the_repository, revs, prefix);
revs->abbrev = 0;
revs->commit_format = CMIT_FMT_UNSPECIFIED;
 
@@ -889,7 +889,7 @@ static void show_diff_tree(const char *prefix, struct 
commit *commit)
struct rev_info opt;
 
/* diff-tree init */
-   init_revisions(, prefix);
+   repo_init_revisions(the_repository, , prefix);
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
opt.abbrev = 0;
opt.diff = 1;
diff --git a/builtin/add.c b/builtin/add.c
index 9916498a29..f94b614c1c 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -110,7 +110,7 @@ int add_files_to_cache(const char *prefix,
memset(, 0, sizeof(data));
data.flags = flags;
 
-   init_revisions(, prefix);
+   repo_init_revisions(the_repository, , prefix);
setup_revisions(0, NULL, , NULL);
if (pathspec)
copy_pathspec(_data, pathspec);
@@ -232,7 +232,7 @@ static int edit_patch(int argc, const char **argv, const 
char *prefix)
if (read_cache() < 0)
die(_("Could not read the index"));
 
-   init_revisions(, prefix);
+   repo_init_revisions(the_repository, , prefix);
rev.diffopt.context = 7;
 
argc = setup_revisions(argc, argv, , NULL);
diff --git a/builtin/am.c b/builtin/am.c
index 45344af676..5c743ba4f5 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1372,7 +1372,7 @@ static void write_commit_patch(const struct am_state 
*state, struct commit *comm
FILE *fp;
 
fp = xfopen(am_path(state, "patch"), "w");
-   init_revisions(_info, NULL);
+   repo_init_revisions(the_repository, _info, NULL);
rev_info.diff = 1;
rev_info.abbrev = 0;
rev_info.disable_stdin = 1;
@@ -1407,7 +1407,7 @@ static void write_index_patch(const struct am_state 
*state)
   the_repository->hash_algo->empty_tree);
 
fp = xfopen(am_path(state, "patch"), "w");
-   init_revisions(_info, NULL);
+   

[PATCH v3 12/23] merge-blobs.c: remove implicit dependency on the_index

2018-09-09 Thread 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 v3 23/23] revision.c: reduce implicit dependency the_repository

2018-09-09 Thread Nguyễn Thái Ngọc Duy
---
 list-objects.c |  8 +---
 revision.c | 44 +++-
 revision.h |  2 +-
 3 files changed, 29 insertions(+), 25 deletions(-)

diff --git a/list-objects.c b/list-objects.c
index c99c47ac18..0c2989d5ca 100644
--- a/list-objects.c
+++ b/list-objects.c
@@ -196,7 +196,7 @@ static void mark_edge_parents_uninteresting(struct commit 
*commit,
struct commit *parent = parents->item;
if (!(parent->object.flags & UNINTERESTING))
continue;
-   mark_tree_uninteresting(get_commit_tree(parent));
+   mark_tree_uninteresting(revs->repo, get_commit_tree(parent));
if (revs->edge_hint && !(parent->object.flags & SHOWN)) {
parent->object.flags |= SHOWN;
show_edge(parent);
@@ -213,7 +213,8 @@ void mark_edges_uninteresting(struct rev_info *revs, 
show_edge_fn show_edge)
struct commit *commit = list->item;
 
if (commit->object.flags & UNINTERESTING) {
-   mark_tree_uninteresting(get_commit_tree(commit));
+   mark_tree_uninteresting(revs->repo,
+   get_commit_tree(commit));
if (revs->edge_hint_aggressive && 
!(commit->object.flags & SHOWN)) {
commit->object.flags |= SHOWN;
show_edge(commit);
@@ -228,7 +229,8 @@ void mark_edges_uninteresting(struct rev_info *revs, 
show_edge_fn show_edge)
struct commit *commit = (struct commit *)obj;
if (obj->type != OBJ_COMMIT || !(obj->flags & 
UNINTERESTING))
continue;
-   mark_tree_uninteresting(get_commit_tree(commit));
+   mark_tree_uninteresting(revs->repo,
+   get_commit_tree(commit));
if (!(obj->flags & SHOWN)) {
obj->flags |= SHOWN;
show_edge(commit);
diff --git a/revision.c b/revision.c
index f8a801d5f6..28366eaccf 100644
--- a/revision.c
+++ b/revision.c
@@ -51,7 +51,8 @@ static void mark_blob_uninteresting(struct blob *blob)
blob->object.flags |= UNINTERESTING;
 }
 
-static void mark_tree_contents_uninteresting(struct tree *tree)
+static void mark_tree_contents_uninteresting(struct repository *r,
+struct tree *tree)
 {
struct tree_desc desc;
struct name_entry entry;
@@ -63,10 +64,10 @@ static void mark_tree_contents_uninteresting(struct tree 
*tree)
while (tree_entry(, )) {
switch (object_type(entry.mode)) {
case OBJ_TREE:
-   mark_tree_uninteresting(lookup_tree(the_repository, 
entry.oid));
+   mark_tree_uninteresting(r, lookup_tree(r, entry.oid));
break;
case OBJ_BLOB:
-   mark_blob_uninteresting(lookup_blob(the_repository, 
entry.oid));
+   mark_blob_uninteresting(lookup_blob(r, entry.oid));
break;
default:
/* Subproject commit - not in this repository */
@@ -81,7 +82,7 @@ static void mark_tree_contents_uninteresting(struct tree 
*tree)
free_tree_buffer(tree);
 }
 
-void mark_tree_uninteresting(struct tree *tree)
+void mark_tree_uninteresting(struct repository *r, struct tree *tree)
 {
struct object *obj;
 
@@ -92,7 +93,7 @@ void mark_tree_uninteresting(struct tree *tree)
if (obj->flags & UNINTERESTING)
return;
obj->flags |= UNINTERESTING;
-   mark_tree_contents_uninteresting(tree);
+   mark_tree_contents_uninteresting(r, tree);
 }
 
 struct commit_stack {
@@ -198,7 +199,7 @@ void add_head_to_pending(struct rev_info *revs)
struct object *obj;
if (get_oid("HEAD", ))
return;
-   obj = parse_object(the_repository, );
+   obj = parse_object(revs->repo, );
if (!obj)
return;
add_pending_object(revs, obj, "HEAD");
@@ -210,7 +211,7 @@ static struct object *get_reference(struct rev_info *revs, 
const char *name,
 {
struct object *object;
 
-   object = parse_object(the_repository, oid);
+   object = parse_object(revs->repo, oid);
if (!object) {
if (revs->ignore_missing)
return object;
@@ -247,7 +248,7 @@ static struct commit *handle_commit(struct rev_info *revs,
add_pending_object(revs, object, tag->tag);
if (!tag->tagged)
die("bad tag");
-   object = parse_object(the_repository, >tagged->oid);
+   object = parse_object(revs->repo, >tagged->oid);
if (!object) {

[PATCH v3 11/23] ll-merge.c: remove implicit dependency on the_index

2018-09-09 Thread 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 1bcc0818df..a06c3b070c 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 *check;
int marker_size = 

[PATCH v3 20/23] tree-diff.c: remove implicit dependency on the_index

2018-09-09 Thread 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 57a15f51f0..16b28ff6d6 100644
--- a/tree-diff.c
+++ b/tree-diff.c
@@ -605,7 +605,7 @@ static void try_to_follow_renames(const struct object_id 
*old_oid,
choice = q->queue[0];
q->nr = 0;
 
-   repo_diff_setup(the_repository, _opts);
+   repo_diff_setup(opt->repo, _opts);
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 v3 21/23] ws.c: remove implicit dependency on the_index

2018-09-09 Thread 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 571b89c2e0..fdae1d423b 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 094652a503..eb0f7d5470 100644
--- a/cache.h
+++ b/cache.h
@@ -1694,7 +1694,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 5256b9eabc..c5b5e7ac41 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 v3 16/23] rerere.c: remove implicit dependency on the_index

2018-09-09 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.
---
 apply.c  |   2 +-
 builtin/am.c |   4 +-
 builtin/commit.c |   2 +-
 builtin/merge.c  |   2 +-
 builtin/rerere.c |   6 +--
 rerere.c | 119 +--
 rerere.h |  10 ++--
 sequencer.c  |   4 +-
 8 files changed, 81 insertions(+), 68 deletions(-)

diff --git a/apply.c b/apply.c
index ea111ab13f..571b89c2e0 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);
+   repo_rerere(state->repo, 0);
}
 
return errs;
diff --git a/builtin/am.c b/builtin/am.c
index 9f7ecf6ecb..45344af676 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);
+   repo_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);
+   repo_rerere(the_repository, 0);
 
do_commit(state);
 
diff --git a/builtin/commit.c b/builtin/commit.c
index 0d9828e29e..bf06fbf49f 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);
+   repo_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 5f79fc5fd7..3c003ce797 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);
+   repo_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..1ca271b711 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 repo_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..8d4ac8426b 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 *sha1, const 

[PATCH v3 14/23] patch-ids.c: remove implicit dependency on the_index

2018-09-09 Thread 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 4b602236d6..978fe7c10f 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(the_repository, ids);
 
/* 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 342950c79d..7da86047d9 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 repository *r, struct patch_ids *ids)
 {
memset(ids, 0, sizeof(*ids));
-   repo_diff_setup(the_repository, >diffopts);
+   repo_diff_setup(r, >diffopts);
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..82a12b66f8 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 repository *, struct patch_ids *);
 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 0c6dc8c163..d70587678c 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 v3 15/23] sha1-file.c: remove implicit dependency on the_index

2018-09-09 Thread 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 49fe83331c..094652a503 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 a06c3b070c..140d0e86df 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) &&
@@ -4359,8 +4359,8 @@ static void 

[PATCH v3 19/23] submodule.c: remove implicit dependency on the_index

2018-09-09 Thread 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 33b7100837..9c455984d1 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;
 
argv_array_clear();
@@ -1346,7 

[PATCH v3 18/23] line-range.c: remove implicit dependency on the_index

2018-09-09 Thread 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 35adf199a5..d1d429d738 100644
--- a/line-log.c
+++ b/line-log.c
@@ -574,7 +574,7 @@ parse_lines(struct repository *r, struct commit *commit,
long begin = 0, end = 0;
long anchor;
 
-   name_part = skip_range_arg(item->string);
+   name_part = skip_range_arg(item->string, r->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 *r, struct commit *commit,
 
if (parse_range_arg(range_part, nth_line, _data,
lines, anchor, , ,
-   full_name))
+   full_name, r->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
 #define LINE_RANGE_H
 
+struct index_state;
+
 

[PATCH v3 17/23] userdiff.c: remove implicit dependency on the_index

2018-09-09 Thread 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 9b43e557a1..41ab5b01de 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 140d0e86df..5256b9eabc 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 *userdiff_word_regex(struct diff_filespec *one,
+   

[PATCH v3 07/23] grep.c: remove implicit dependency on the_index

2018-09-09 Thread 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..6c0eede3a1 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 *r,
+ 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(r, 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);
+   init_grep_defaults(the_repository);
+   

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

2018-09-09 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 unfortunate 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.
---
 cache.h  | 2 +-
 read-cache.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/cache.h b/cache.h
index 4d014541ab..260e4ee44a 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/read-cache.c b/read-cache.c
index 7b1354d759..86134e56a6 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -2122,7 +2122,7 @@ int unmerged_index(const struct index_state *istate)
return 0;
 }
 
-int index_has_changes(const struct index_state *istate,
+int index_has_changes(struct index_state *istate,
  struct tree *tree,
  struct strbuf *sb)
 {
-- 
2.19.0.rc0.337.ge906d732e7



[PATCH v3 00/23] Kill the_index part 4

2018-09-09 Thread Nguyễn Thái Ngọc Duy
The last patch 24/24 has been merged into individual patches to add
repo_ prefix and avoid breaking in-flight topics. "repo" argument is
also moved up in rerere(), diff_setup() and init_revisions().

All three macros that take the_repository is wrapped in NO_THE_REPO...
similar to NO_THE_INDEX_... After part 5, these macros will be only
available to builtin/ (or even removed if no in-flight topics use
them)

Interdiff

diff --git a/Documentation/technical/api-diff.txt 
b/Documentation/technical/api-diff.txt
index 8b001de0db..30fc0e9c93 100644
--- a/Documentation/technical/api-diff.txt
+++ b/Documentation/technical/api-diff.txt
@@ -18,8 +18,8 @@ Calling sequence
 
 
 * Prepare `struct diff_options` to record the set of diff options, and
-  then call `diff_setup()` to initialize this structure.  This sets up
-  the vanilla default.
+  then call `repo_diff_setup()` to initialize this structure.  This
+  sets up the vanilla default.
 
 * Fill in the options structure to specify desired output format, rename
   detection, etc.  `diff_opt_parse()` can be used to parse options given
diff --git a/Documentation/technical/api-revision-walking.txt 
b/Documentation/technical/api-revision-walking.txt
index 55b878ade8..83e62533a0 100644
--- a/Documentation/technical/api-revision-walking.txt
+++ b/Documentation/technical/api-revision-walking.txt
@@ -15,7 +15,7 @@ revision list.
 Functions
 -
 
-`init_revisions`::
+`repo_init_revisions`::
 
Initialize a rev_info structure with default values. The second
parameter may be NULL or can be prefix path, and then the `.prefix`
diff --git a/bisect.c b/bisect.c
index 560493acd2..6ae5e5b49e 100644
--- a/bisect.c
+++ b/bisect.c
@@ -632,7 +632,7 @@ static void bisect_rev_setup(struct rev_info *revs, const 
char *prefix,
struct argv_array rev_argv = ARGV_ARRAY_INIT;
int i;
 
-   repo_init_revisions(revs, the_repository, prefix);
+   repo_init_revisions(the_repository, revs, prefix);
revs->abbrev = 0;
revs->commit_format = CMIT_FMT_UNSPECIFIED;
 
@@ -889,7 +889,7 @@ static void show_diff_tree(const char *prefix, struct 
commit *commit)
struct rev_info opt;
 
/* diff-tree init */
-   repo_init_revisions(, the_repository, prefix);
+   repo_init_revisions(the_repository, , prefix);
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
opt.abbrev = 0;
opt.diff = 1;
diff --git a/blame.c b/blame.c
index 39fbd796c0..c229a10c0e 100644
--- a/blame.c
+++ b/blame.c
@@ -563,7 +563,7 @@ static struct blame_origin *find_origin(struct repository 
*r,
 * and origin first.  Most of the time they are the
 * same and diff-tree is fairly efficient about this.
 */
-   repo_diff_setup(_opts, r);
+   repo_diff_setup(r, _opts);
diff_opts.flags.recursive = 1;
diff_opts.detect_rename = 0;
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
@@ -638,7 +638,7 @@ static struct blame_origin *find_rename(struct repository 
*r,
struct diff_options diff_opts;
int i;
 
-   repo_diff_setup(_opts, r);
+   repo_diff_setup(r, _opts);
diff_opts.flags.recursive = 1;
diff_opts.detect_rename = DIFF_DETECT_RENAME;
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
@@ -1262,7 +1262,7 @@ static void find_copy_in_parent(struct blame_scoreboard 
*sb,
if (!unblamed)
return; /* nothing remains for this target */
 
-   repo_diff_setup(_opts, sb->repo);
+   repo_diff_setup(sb->repo, _opts);
diff_opts.flags.recursive = 1;
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
 
diff --git a/builtin/add.c b/builtin/add.c
index c8f99083fc..f94b614c1c 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -110,7 +110,7 @@ int add_files_to_cache(const char *prefix,
memset(, 0, sizeof(data));
data.flags = flags;
 
-   repo_init_revisions(, the_repository, prefix);
+   repo_init_revisions(the_repository, , prefix);
setup_revisions(0, NULL, , NULL);
if (pathspec)
copy_pathspec(_data, pathspec);
@@ -232,7 +232,7 @@ static int edit_patch(int argc, const char **argv, const 
char *prefix)
if (read_cache() < 0)
die(_("Could not read the index"));
 
-   repo_init_revisions(, the_repository, prefix);
+   repo_init_revisions(the_repository, , prefix);
rev.diffopt.context = 7;
 
argc = setup_revisions(argc, argv, , NULL);
diff --git a/builtin/am.c b/builtin/am.c
index 70afd6c15a..5c743ba4f5 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1372,7 +1372,7 @@ static void write_commit_patch(const struct am_state 
*state, struct commit *comm
FILE *fp;
 
fp = xfopen(am_path(state, "patch"), "w");
-   repo_init_revisions(_info, the_repository, NULL);
+   repo_init_revisions(the_repository, _info, NULL);
rev_info.diff = 1;
rev_info.abbrev = 0;
   

[PATCH v3 03/23] diff.c: reduce implicit dependency on the_index

2018-09-09 Thread Nguyễn Thái Ngọc Duy
diff and textconv code has so widespread use that it's hard to simply
update their api and all call sites at once because it would result in
a big patch. For now reduce the_index references to two places:
diff_setup() and fill_textconv().
---
 builtin/reset.c   |   1 +
 diff.c| 176 +++---
 diff.h|   3 +
 diffcore-break.c  |  12 ++--
 diffcore-delta.c  |  12 ++--
 diffcore-rename.c |  35 +
 diffcore.h|  13 ++--
 line-log.c|  21 +++---
 8 files changed, 161 insertions(+), 112 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/diff.c b/diff.c
index 145cfbae59..e5d6d30a67 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 *r, 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(r, 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 *r,
+   struct diff_filespec *one)
 {
if (!DIFF_FILE_VALID(one))
return 0;
-   diff_populate_filespec(one, CHECK_SIZE_ONLY);
+   diff_populate_filespec(r, 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 *r,
+   struct diff_filespec *one)
 {
if (one->is_binary == -1) {
diff_filespec_load_driver(one);
@@ -3258,7 +3262,7 @@ int diff_filespec_is_binary(struct diff_filespec *one)
one->is_binary = one->driver->binary;
else {
if (!one->data && DIFF_FILE_VALID(one))
-   diff_populate_filespec(one, CHECK_BINARY);
+   diff_populate_filespec(r, one, CHECK_BINARY);
if (one->is_binary == -1 && one->data)
one->is_binary = buffer_is_binary(one->data,
one->size);
@@ -3380,13 +3384,13 @@ static void builtin_diff(const char *name_a,
if ((one->mode ^ two->mode) & S_IFMT)
goto free_ab_and_return;
if (complete_rewrite &&
-   (textconv_one || 

[PATCH v3 10/23] diff-lib.c: remove implicit dependency on the_index

2018-09-09 Thread 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 v3 13/23] merge.c: remove implicit dependency on the_index

2018-09-09 Thread 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 592cb19caf..5f79fc5fd7 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 681c127a07..33b7100837 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 260e4ee44a..49fe83331c 100644
--- a/cache.h
+++ b/cache.h
@@ -1716,10 +1716,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 *r,
+   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 *r,
+ const struct object_id *from,
  const struct object_id *to,
  int overwrite_ignore);
 
diff --git a/merge.c b/merge.c
index e30e03fb84..91008f7602 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 *r,
+ 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(r->index);
+   if (read_index(r->index) < 0)
die(_("failed to read the cache"));
-   resolve_undo_clear();
+   resolve_undo_clear_index(r->index);
 
return ret;
 }
 
-int checkout_fast_forward(const struct object_id *head,
+int checkout_fast_forward(struct repository *r,
+ 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);
+   refresh_index(r->index, REFRESH_QUIET, NULL, NULL, NULL);
 

[PATCH v3 04/23] combine-diff.c: remove implicit dependency on the_index

2018-09-09 Thread 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 v3 09/23] read-cache.c: remove implicit dependency on the_index

2018-09-09 Thread 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 6f772b2885..563500fe98 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 v3 06/23] diff.c: remove the_index dependency in textconv() functions

2018-09-09 Thread 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 98bf50d89a..9d57c76baa 100644
--- a/blame.c
+++ b/blame.c
@@ -234,7 +234,7 @@ static struct commit *fake_working_tree_commit(struct 
repository *r,
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(r, 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, ,
@@ -1857,7 +1858,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..9b43e557a1 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 *r,
+  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 = fill_textconv(r, textconv, df, );
 

[PATCH v3 08/23] diff.c: remove implicit dependency on the_index

2018-09-09 Thread Nguyễn Thái Ngọc Duy
A new variant repo_diff_setup() is added that takes 'struct repository *'
and diff_setup() becomes a thin macro around it that is protected by
NO_THE_REPOSITORY_COMPATIBILITY_MACROS, similar to NO_THE_INDEX_
The plan is these macros will always be defined for all library files
and the macros are only accessible in builtin/
---
 Documentation/technical/api-diff.txt |  4 ++--
 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   |  7 +--
 merge-recursive.c|  2 +-
 notes-merge.c|  4 ++--
 patch-ids.c  |  2 +-
 read-cache.c |  2 +-
 revision.c   |  2 +-
 tree-diff.c  |  2 +-
 15 files changed, 38 insertions(+), 28 deletions(-)

diff --git a/Documentation/technical/api-diff.txt 
b/Documentation/technical/api-diff.txt
index 8b001de0db..30fc0e9c93 100644
--- a/Documentation/technical/api-diff.txt
+++ b/Documentation/technical/api-diff.txt
@@ -18,8 +18,8 @@ Calling sequence
 
 
 * Prepare `struct diff_options` to record the set of diff options, and
-  then call `diff_setup()` to initialize this structure.  This sets up
-  the vanilla default.
+  then call `repo_diff_setup()` to initialize this structure.  This
+  sets up the vanilla default.
 
 * Fill in the options structure to specify desired output format, rename
   detection, etc.  `diff_opt_parse()` can be used to parse options given
diff --git a/blame.c b/blame.c
index 9d57c76baa..c229a10c0e 100644
--- a/blame.c
+++ b/blame.c
@@ -541,8 +541,9 @@ static int fill_blob_sha1_and_mode(struct repository *r,
  * 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 *r,
+   struct commit *parent,
+   struct blame_origin *origin)
 {
struct blame_origin *porigin;
struct diff_options diff_opts;
@@ -562,7 +563,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);
+   repo_diff_setup(r, _opts);
diff_opts.flags.recursive = 1;
diff_opts.detect_rename = 0;
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
@@ -629,14 +630,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 *r,
+   struct commit *parent,
+   struct blame_origin *origin)
 {
struct blame_origin *porigin = NULL;
struct diff_options diff_opts;
int i;
 
-   diff_setup(_opts);
+   repo_diff_setup(r, _opts);
diff_opts.flags.recursive = 1;
diff_opts.detect_rename = DIFF_DETECT_RENAME;
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
@@ -1260,7 +1262,7 @@ static void find_copy_in_parent(struct blame_scoreboard 
*sb,
if (!unblamed)
return; /* nothing remains for this target */
 
-   diff_setup(_opts);
+   repo_diff_setup(sb->repo, _opts);
diff_opts.flags.recursive = 1;
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
 
@@ -1442,7 +1444,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);
@@ -1455,7 +1457,7 @@ static void pass_blame(struct blame_scoreboard *sb, 
struct blame_origin *origin,
continue;
if (parse_commit(p))
continue;
-   porigin = find(p, origin);
+

[PATCH v3 05/23] blame.c: rename "repo" argument to "r"

2018-09-09 Thread Nguyễn Thái Ngọc Duy
The current naming convention for 'struct repository *' is 'r' for
temporary variables or arguments. I did not notice this. Since we're
updating blame.c again in the next patch, let's fix this.
---
 blame.c | 36 ++--
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/blame.c b/blame.c
index aca06f4b12..98bf50d89a 100644
--- a/blame.c
+++ b/blame.c
@@ -90,7 +90,7 @@ static struct blame_origin *get_origin(struct commit *commit, 
const char *path)
 
 
 
-static void verify_working_tree_path(struct repository *repo,
+static void verify_working_tree_path(struct repository *r,
 struct commit *work_tree, const char *path)
 {
struct commit_list *parents;
@@ -102,15 +102,15 @@ static void verify_working_tree_path(struct repository 
*repo,
unsigned mode;
 
if (!get_tree_entry(commit_oid, path, _oid, ) &&
-   oid_object_info(repo, _oid, NULL) == OBJ_BLOB)
+   oid_object_info(r, _oid, NULL) == OBJ_BLOB)
return;
}
 
-   pos = index_name_pos(repo->index, path, strlen(path));
+   pos = index_name_pos(r->index, path, strlen(path));
if (pos >= 0)
; /* path is in the index */
-   else if (-1 - pos < repo->index->cache_nr &&
-!strcmp(repo->index->cache[-1 - pos]->name, path))
+   else if (-1 - pos < r->index->cache_nr &&
+!strcmp(r->index->cache[-1 - pos]->name, path))
; /* path is in the index, unmerged */
else
die("no such path '%s' in HEAD", path);
@@ -166,7 +166,7 @@ static void set_commit_buffer_from_strbuf(struct commit *c, 
struct strbuf *sb)
  * Prepare a dummy commit that represents the work tree (or staged) item.
  * Note that annotating work tree item never works in the reverse.
  */
-static struct commit *fake_working_tree_commit(struct repository *repo,
+static struct commit *fake_working_tree_commit(struct repository *r,
   struct diff_options *opt,
   const char *path,
   const char *contents_from)
@@ -183,7 +183,7 @@ static struct commit *fake_working_tree_commit(struct 
repository *repo,
unsigned mode;
struct strbuf msg = STRBUF_INIT;
 
-   read_index(repo->index);
+   read_index(r->index);
time();
commit = alloc_commit_node(the_repository);
commit->object.parsed = 1;
@@ -195,7 +195,7 @@ static struct commit *fake_working_tree_commit(struct 
repository *repo,
 
parent_tail = append_parent(parent_tail, _oid);
append_merge_parents(parent_tail);
-   verify_working_tree_path(repo, commit, path);
+   verify_working_tree_path(r, commit, path);
 
origin = make_origin(commit, path);
 
@@ -253,7 +253,7 @@ static struct commit *fake_working_tree_commit(struct 
repository *repo,
if (strbuf_read(, 0, 0) < 0)
die_errno("failed to read from stdin");
}
-   convert_to_git(repo->index, path, buf.buf, buf.len, , 0);
+   convert_to_git(r->index, path, buf.buf, buf.len, , 0);
origin->file.ptr = buf.buf;
origin->file.size = buf.len;
pretend_object_file(buf.buf, buf.len, OBJ_BLOB, >blob_oid);
@@ -264,28 +264,28 @@ static struct commit *fake_working_tree_commit(struct 
repository *repo,
 * bits; we are not going to write this index out -- we just
 * want to run "diff-index --cached".
 */
-   discard_index(repo->index);
-   read_index(repo->index);
+   discard_index(r->index);
+   read_index(r->index);
 
len = strlen(path);
if (!mode) {
-   int pos = index_name_pos(repo->index, path, len);
+   int pos = index_name_pos(r->index, path, len);
if (0 <= pos)
-   mode = repo->index->cache[pos]->ce_mode;
+   mode = r->index->cache[pos]->ce_mode;
else
/* Let's not bother reading from HEAD tree */
mode = S_IFREG | 0644;
}
-   ce = make_empty_cache_entry(repo->index, len);
+   ce = make_empty_cache_entry(r->index, len);
oidcpy(>oid, >blob_oid);
memcpy(ce->name, path, len);
ce->ce_flags = create_ce_flags(0);
ce->ce_namelen = len;
ce->ce_mode = create_ce_mode(mode);
-   add_index_entry(repo->index, ce,
+   add_index_entry(r->index, ce,
ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
 
-   cache_tree_invalidate_path(repo->index, path);
+   cache_tree_invalidate_path(r->index, path);
 
return commit;
 }
@@ -520,14 +520,14 @@ static void queue_blames(struct blame_scoreboard *sb, 
struct blame_origin *porig
  *
  * This also fills origin->mode for corresponding tree 

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

2018-09-09 Thread Nguyễn Thái Ngọc Duy
The new "repo" field in archive_args has been added since b612ee202a
(archive.c: avoid access to the_index - 2018-08-13). Use it instead of
hard coding the_repository.
---
 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



Re: [PATCH v2 24/24] Rename functions to avoid breaking in-flight topics

2018-09-09 Thread Duy Nguyen
On Wed, Sep 5, 2018 at 11:04 PM Junio C Hamano  wrote:
> > now and here, but at some later date, we would want to
> > 'git revert 24/24' after fixing all in-flights of today.
>
> No.  We do not want to revert the whole thing.
>
> If the function that takes a_repository is called repo_rerere(), as
> opposed to just rerere(), it should keep that name after we
> deprecate the function rerere().
>
> We will want to get rid of #define that gives a thin wrapper and
> make everybody use the API that requires a_repository parameter.
>
> And from that point of view, it is backwards not to introduce
> repo_rerere() when rerere.c gains a variant that can work in an
> arbitrary repository, not limited to the_repository, and fix it up
> saying "oops, we were wrong and this will break topics in flight" at
> the very end.

In the end, there's no variant, only one function that always takes
'struct repository *' and I wanted to keep the shorter name 'rerere'.
But let's go with adding repo_rerere() and deprecating rerere(). If it
turns out later that repo_rerere is too long (or it's repo_xyz
everywhere) then we can do another rename.
-- 
Duy


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

2018-09-09 Thread Duy Nguyen
On Tue, Sep 4, 2018 at 9:54 PM Stefan Beller  wrote:
>
> On Mon, Sep 3, 2018 at 11:03 AM Duy Nguyen  wrote:
> >
> > On Mon, Aug 27, 2018 at 9:13 PM Stefan Beller  wrote:
> > >
> > > > -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);
> > >
> > > Just realized when looking at this diff, though it applies to
> > > other patches as well. (and reading Documentation/technical/api-diff.txt
> > > confirms my thinking IMHO)
> > >
> > > What makes the repository argument any special compared
> > > to the rest of the diff options?
> > >
> > > So I would expect the setup to look like
> > >
> > > memset(ids, 0, sizeof(*ids));
> > > ids->diffopts->repo = the_repository;
> > > diff_setup(>diffopts);
> > >
> > > here and in diff_setup, we'd have
> > >
> > >   if (!options->repo)
> > > options->repo = the_repository;
> > >
> > > or even put the_repository into default_diff_options,
> > > but then I wonder how this deals with no-repo invocations
> > > (git diff --no-index examples for bug reports)
> >
> > That makes "repo" field optional and I'm very much against falling
> > back to the_repository. revisions.c in the end does not have any
> > the_repository reference, and it's actually undefined for most files.
> > This makes accidentally adding the_repository back much more
> > difficult.
>
> Thanks for the clear explanation. I agree that this is a good approach
> with these reasons given. So in case a resend is needed, maybe add
> these to the commit message, as it explains why we deviate from
> the pattern here.

Actually I looked at it again and diff_setup() clears diffopts as the
first step, so any assignments prior to the diff_setup() call has no
effect.

> > Yes the --no-index stuff will have to be taken care of at some point,
> > but I think for now we could just put "struct repository *" in place
> > first to see what it looks like, then go from there.
>
> I would think repo = NULL would do? But we can defer this
> discussion to later.

Yes. But the the_hash_algo currently points to
the_repository->hash_algo. We need to at least make the_hash_algo
independent from 'struct repository *', then figure out how to set
the_hash_algo without $GIT_DIR/config file...
-- 
Duy


Re: [PATCH 1/2] t0051: test GIT_TRACE to a windows named pipe

2018-09-09 Thread Sebastian Schuberth

On 9/7/2018 8:19 PM, Jeff Hostetler via GitGitGadget wrote:


+test_expect_success MINGW 'o_append write to named pipe' '


Shouldn't this be "test_expect_failure" here, and then be changed to 
"test_expect_success" by your second patch?



--
Sebastian Schuberth