Re: [PATCH] branch -l: print useful info whilst rebasing a non-local branch

2018-03-24 Thread Eric Sunshine
On Sun, Mar 25, 2018 at 09:11:34AM +0530, Kaartic Sivaraam wrote:
> On Sunday 25 March 2018 07:04 AM, Eric Sunshine wrote:
> > Can we have a couple new tests: one checking "git branch --list" for
> > the typical case (when rebasing off a named branch) and one checking
> > when rebasing from a detached HEAD?
> 
> Sure, but I guess it would take some time for me to add the tests. I'll
> send a v2 with the suggested changes.

A couple more comments:

* Please run the commit message through a spell checker; it contains
  several typographical errors.

* I wonder if it makes sense to give slightly different output in the
  detached HEAD case. Normal output is:

  (no branch, rebasing )

  and, with your change, detached HEAD output is:

  (no branch, rebasing d3adb33f)

  which is okay, but perhaps it could be better; for instance:

  (no branch, rebasing detached HEAD d3adb33f)

Anyhow, I wrote the tests for you. When you re-roll, you can make the
following patch 2/2 and your fix 1/2. (If you go with the above idea
of using a slightly different wording for the detached HEAD case, then
you'll need to adjust the 'grep' slightly in the second test.)

--- >8 ---
From: Eric Sunshine 
Date: Sun, 25 Mar 2018 01:29:58 -0400
Subject: [PATCH] t3200: verify "branch --list" sanity when rebasing from
 detached HEAD

"git branch --list" shows an in-progress rebase as:

  * (no branch, rebasing )
master
...

However, if the rebase is started from a detached HEAD, then there is no
, and it would attempt to print a NULL pointer. The previous
commit fixed this problem, so add a test to verify that the output is
sane in this situation.

Signed-off-by: Eric Sunshine 
---
 t/t3200-branch.sh | 24 
 1 file changed, 24 insertions(+)

diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index 6c0b7ea4ad..d1f80c80ab 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -6,6 +6,7 @@
 test_description='git branch assorted tests'
 
 . ./test-lib.sh
+. "$TEST_DIRECTORY"/lib-rebase.sh
 
 test_expect_success 'prepare a trivial repository' '
echo Hello >A &&
@@ -1246,6 +1247,29 @@ test_expect_success '--merged is incompatible with 
--no-merged' '
test_must_fail git branch --merged HEAD --no-merged HEAD
 '
 
+test_expect_success '--list during rebase' '
+   test_when_finished "reset_rebase" &&
+   git checkout master &&
+   FAKE_LINES="1 edit 2" &&
+   export FAKE_LINES &&
+   set_fake_editor &&
+   git rebase -i HEAD~2 &&
+   git branch --list >actual &&
+   grep "rebasing master" actual
+'
+
+test_expect_success '--list during rebase from detached HEAD' '
+   test_when_finished "reset_rebase && git checkout master" &&
+   git checkout HEAD^0 &&
+   oid=$(git rev-parse --short HEAD) &&
+   FAKE_LINES="1 edit 2" &&
+   export FAKE_LINES &&
+   set_fake_editor &&
+   git rebase -i HEAD~2 &&
+   git branch --list >actual &&
+   grep "rebasing $oid" actual
+'
+
 test_expect_success 'tracking with unexpected .fetch refspec' '
rm -rf a b c d &&
git init a &&
-- 
2.17.0.rc1.321.gba9d0f2565
--- >8 ---


Re: [PATCH] branch -l: print useful info whilst rebasing a non-local branch

2018-03-24 Thread Jeff King
On Sun, Mar 25, 2018 at 12:28:30AM -0400, Eric Sunshine wrote:

> On Sun, Mar 25, 2018 at 12:10 AM, Jeff King  wrote:
> > Alternatively, we could at least detect the situation that confused you:
> >
> > diff --git a/builtin/branch.c b/builtin/branch.c
> > @@ -676,6 +676,9 @@ int cmd_branch(int argc, const char **argv, const char 
> > *prefix)
> > +   if (list && reflog)
> > +   die(_("--reflog in list mode does not make sense"));
> > +
> >
> > That doesn't help somebody mistakenly doing "git branch -l foo", but
> > more likely they'd do "git branch -l jk/*" if they were trying to list
> > branches (and then "branch" would barf with "that's not a valid branch
> > name", though that may still leave them quite confused).
> 
> Assuming that existing clients of "-l" (if there are any) only invoke
> "git branch -l " to create a new branch, then it would be
> possible to interpret "-l" as --list when  is an existing
> branch. That is, the "-l" in "git branch -l" and "git branch -l
> ..." is recognized as --list, and (for backward
> compatibility only) the "-l" in "git branch -l " is still
> recognized as --create-reflog.
> 
> This idea falls flat, however, if there are clients out there which
> actually depend upon "git branch -l " failing.

I agree that might work most of the time as a sort of "do what I mean",
but I'd prefer to avoid those kinds of magic rules if we can. They're
very hard to explain to the user, and can be quite baffling when they go
wrong.

IMHO we should do one of:

  1. Nothing. ;)

  2. Complain about "-l" in list mode to help educate users about the
 current craziness.

  3. Drop "-l" (probably with a deprecation period); it seems unlikely
 to me that anybody uses it for branch creation, and this would at
 least reduce the confusion (then it would just be "so why don't we
 have -l" instead of "why is -l not what I expect").

  4. Repurpose "-l" as a shortcut for --list (also after a deprecation
 period). This is slightly more dangerous in that it may confuse
 people using multiple versions of Git that cross the deprecation
 line. But that's kind of what the deprecation period is for...

-Peff


Re: [PATCH] branch -l: print useful info whilst rebasing a non-local branch

2018-03-24 Thread Eric Sunshine
On Sun, Mar 25, 2018 at 12:10 AM, Jeff King  wrote:
> Alternatively, we could at least detect the situation that confused you:
>
> diff --git a/builtin/branch.c b/builtin/branch.c
> @@ -676,6 +676,9 @@ int cmd_branch(int argc, const char **argv, const char 
> *prefix)
> +   if (list && reflog)
> +   die(_("--reflog in list mode does not make sense"));
> +
>
> That doesn't help somebody mistakenly doing "git branch -l foo", but
> more likely they'd do "git branch -l jk/*" if they were trying to list
> branches (and then "branch" would barf with "that's not a valid branch
> name", though that may still leave them quite confused).

Assuming that existing clients of "-l" (if there are any) only invoke
"git branch -l " to create a new branch, then it would be
possible to interpret "-l" as --list when  is an existing
branch. That is, the "-l" in "git branch -l" and "git branch -l
..." is recognized as --list, and (for backward
compatibility only) the "-l" in "git branch -l " is still
recognized as --create-reflog.

This idea falls flat, however, if there are clients out there which
actually depend upon "git branch -l " failing.


Re: [PATCH] branch -l: print useful info whilst rebasing a non-local branch

2018-03-24 Thread Eric Sunshine
On Sun, Mar 25, 2018 at 12:10 AM, Jeff King  wrote:
> So:
>
>   git branch -l
>
> _looks_ like it works, but only because list mode is the default. If you
> did:
>
>   git branch -l foo
>
> you would find that it does list "foo" at all, but instead creates a new
> branch "foo" with reflog.

s/does/doesn't/


Re: [PATCH] branch -l: print useful info whilst rebasing a non-local branch

2018-03-24 Thread Jeff King
On Sun, Mar 25, 2018 at 09:11:34AM +0530, Kaartic Sivaraam wrote:

> >> When rebasing interacitvely (rebase -i), "git branch -l" prints a line
> > 
> > The "git branch -l" threw me since "-l" is short for --create-reflog.
> > I'm guessing you meant "git branch --list".
> 
> That's surprising, I just tried "git branch -l" on a repository and I
> did get a list of branch names. Is this a consequence of some option
> parsing weirdness ?!

Sort of. The "-l" option causes us to set the "reflog" variable to 1.
And then we have no other command-line options, so we default to
"--list" mode. The listing code does not look at the "reflog" variable
at all, so it's just silently ignored.

So:

  git branch -l

_looks_ like it works, but only because list mode is the default. If you
did:

  git branch -l foo

you would find that it does list "foo" at all, but instead creates a new
branch "foo" with reflog.

> To be honest, I actually assumed "-l" to be a shorthand for "--list" and
> didn't check with it in the documentation; which I should have. Sorry,
> for that. I still wonder why "git branch -l" prints a list of branch
> names when it is not a shorthand for "--list" ? (BTW, I'm also surprised
> by the fact that "-l" is not act shorthand for "--list"!)

It's historical and quite unfortunate. Doubly so since probably nobody
has ever actually wanted to use the short "-l" to create a reflog, since
it's typically the default and has been for a decade.

We've been hesitant to change it due to backwards compatibility. While
"branch" is generally considered porcelain, it probably is the main
scripting interface for creating branches (the only other option would
be using "update-ref" manually). So I dunno. Maybe it would be OK to
transition.

Alternatively, we could at least detect the situation that confused you:

diff --git a/builtin/branch.c b/builtin/branch.c
index 6d0cea9d4b..89e7fdc89c 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -676,6 +676,9 @@ int cmd_branch(int argc, const char **argv, const char 
*prefix)
colopts = 0;
}
 
+   if (list && reflog)
+   die(_("--reflog in list mode does not make sense"));
+
if (force) {
delete *= 2;
rename *= 2;

That doesn't help somebody mistakenly doing "git branch -l foo", but
more likely they'd do "git branch -l jk/*" if they were trying to list
branches (and then "branch" would barf with "that's not a valid branch
name", though that may still leave them quite confused).

-Peff


Re: [PATCH] branch -l: print useful info whilst rebasing a non-local branch

2018-03-24 Thread Kaartic Sivaraam
On Sunday 25 March 2018 07:04 AM, Eric Sunshine wrote:
> On Sat, Mar 24, 2018 at 2:38 PM, Kaartic Sivaraam
>  wrote:
>> When rebasing interacitvely (rebase -i), "git branch -l" prints a line
> 
> The "git branch -l" threw me since "-l" is short for --create-reflog.
> I'm guessing you meant "git branch --list".
> 

That's surprising, I just tried "git branch -l" on a repository and I
did get a list of branch names. Is this a consequence of some option
parsing weirdness ?!

To be honest, I actually assumed "-l" to be a shorthand for "--list" and
didn't check with it in the documentation; which I should have. Sorry,
for that. I still wonder why "git branch -l" prints a list of branch
names when it is not a shorthand for "--list" ? (BTW, I'm also surprised
by the fact that "-l" is not act shorthand for "--list"!)

Regardless, I'll update the commit message to use "--list" in place of "-l".


>> indicating the current branch being rebased. This works well when the
>> interactive rebase was intiated when a local branch is checked out.
>>
>> This doesn't play well when the rebase was initiated on a remote
>> branch or an arbitrary commit that is not pointed to by a local
>> branch.
> 
> A shorter way of saying "arbitrary commit ... not pointed at by local
> branch" would be "detached HEAD".
> 

Thanks. I was actually searching for this word. It didn't strike when I
wrote the commit message, yesterday.


> You could collapse the whole thing back down to:
> 
> strbuf_addf(, _("(no branch, rebasing %s)"),
> state.branch ? state.branch : state.detached_from);
> 
> which means you don't need the 'rebasing' variable or the braces.
> 

Nice point.


> Can we have a couple new tests: one checking "git branch --list" for
> the typical case (when rebasing off a named branch) and one checking
> when rebasing from a detached HEAD?
> 

Sure, but I guess it would take some time for me to add the tests. I'll
send a v2 with the suggested changes.


-- 
Kaartic



signature.asc
Description: OpenPGP digital signature


query on git submodule (ignore)

2018-03-24 Thread prashant Nidgunde
Hello,

I am new to this community ,so please ignore if I am asking anything silly.

Case :
Today when I built my submodule , and did a git status , it shows as modified.

After reading certain suggestions on web i found out that i can ignore
that adding a line in .gitmodules

But, I had to add that line manually ( which could be errorprone
because of typos )


Question:
1. Is it feasible to build a feature like :
   git submodule "zlib" ignore dirty ( which will
ignore submodule zlib when its built and dirty  as it has new files in
its directory)

If this feature is feasible , how do i know if its developed  (
awaiting merge ) or can I build the patch ?

Regards,
Prashant


Re: [PATCH] branch -l: print useful info whilst rebasing a non-local branch

2018-03-24 Thread Eric Sunshine
On Sat, Mar 24, 2018 at 2:38 PM, Kaartic Sivaraam
 wrote:
> When rebasing interacitvely (rebase -i), "git branch -l" prints a line

The "git branch -l" threw me since "-l" is short for --create-reflog.
I'm guessing you meant "git branch --list".

> indicating the current branch being rebased. This works well when the
> interactive rebase was intiated when a local branch is checked out.
>
> This doesn't play well when the rebase was initiated on a remote
> branch or an arbitrary commit that is not pointed to by a local
> branch.

A shorter way of saying "arbitrary commit ... not pointed at by local
branch" would be "detached HEAD".

> In this case "git branch -l" tries to print the name of a
> branch using an unintialized variable and thus tries to print a "null
> pointer string". As a consequence, it does not provide useful
> information while also inducing undefined behaviour.
>
> So, print the commit from which the rebase started when interactive
> rebasing a non-local branch.

Makes sense. The commit message gives enough information for the
reader to understand the problem easily.

> Signed-off-by: Kaartic Sivaraam 
> ---
> diff --git a/ref-filter.c b/ref-filter.c
> @@ -1310,8 +1310,16 @@ char *get_head_description(void)
> wt_status_get_state(, 1);
> if (state.rebase_in_progress ||
> state.rebase_interactive_in_progress)
> +   {

Style: attach '{' to the line above it (don't make it standalone)

> +   const char *rebasing = NULL;
> +   if (state.branch != NULL)
> +   rebasing = state.branch;
> +   else
> +   rebasing = state.detached_from;
> +
> strbuf_addf(, _("(no branch, rebasing %s)"),
> -   state.branch);
> +   rebasing);

You could collapse the whole thing back down to:

strbuf_addf(, _("(no branch, rebasing %s)"),
state.branch ? state.branch : state.detached_from);

which means you don't need the 'rebasing' variable or the braces.

> +   }
> else if (state.bisect_in_progress)

Style: cuddle 'else' with '}': } else

> strbuf_addf(, _("(no branch, bisect started on %s)"),
> state.branch);

Can we have a couple new tests: one checking "git branch --list" for
the typical case (when rebasing off a named branch) and one checking
when rebasing from a detached HEAD?


Re: [PATCH v2 5/8] completion: add --option completion for most builtin commands

2018-03-24 Thread Eric Sunshine
On Sat, Mar 24, 2018 at 4:35 PM, Nguyễn Thái Ngọc Duy  wrote:
> Many builtin commands use parseopt which supports expose the option

s/expose/exposing/ maybe?

> list via --git-completion-helper but do not have explicit support in
> git-completion.bash. This patch detects those commands and uses
> __gitcomp_builtin for option completion.
>
> This does not pollute the command name completion though. "git "
> will show you the same set as before. This only kicks in when you type
> the correct command name.
>
> Signed-off-by: Nguyễn Thái Ngọc Duy 


Re: [RFC v3][GSoC] Project proposal: convert interactive rebase to C

2018-03-24 Thread Alban Gruin
Hi,
this is the first draft of my proposal.

---
ABSTRACT

git is a modular source control management software, and all of its
subcommands are programs on their own. A lot of them are written in C,
but a couple of them are shell or Perl scripts. This is the case of
=git-rebase--interactive= (or interactive rebase), which is a shell
script. Rewriting it in C would improve its performance, its
portability, and maybe its robustness.


ABOUT `git-rebase` AND `git-rebase--interactive`

git-rebase allows to re-apply changes on top of another branch. For
instance, when a local branch and a remote branch have diverged,
git-rebase can re-unify them, applying each change made on the
local branch on top of the remote branch.

git-rebase--interactive is used to reorganize commits by reordering,
rewording, or squashing them. To achieve this purpose, =git= opens the
list of commits to be modified in a text editor (hence the
interactivity), as well as the actions to be performed for each of
them.


PROJECT GOALS

Back in 2016, Johannes Schindelin discussed[1] about retiring
git-rebase.sh (described here as a “hacky shell script”) in favor of
a builtin. He explained that, as it’s only a command-line parser for
git-rebase--am.sh, git-rebase--interactive.sh, and
git-rebase--merge.sh, these 3 scripts should be rewritten first.

The goal of this project is to rewrite git-rebase--interactive.sh in
C, for multiple reasons :

Performance improvements
Shell scripts are inherently slow. When Johannes Schindelin began to
rewrite some parts of git-rebase--interactive in C, its performance
increased from 3 to 5 times, depending on the platform[2].

That’s because each command is a program by itself. So, for each
command, the shell interpreter has to spawn a new process and to load
a new program (with fork() and exec() syscalls), which is an
expensive process.

Those commands can be other git commands. Sometimes, they are
wrappers to call internal C functions (eg. git-rebase--helper),
something shell scripts can’t do natively. These wrappers basically
parse the parameters, then start the appropriate function, which is
obviously slower than just calling a function from C.

Other commands can be POSIX utilities (eg. sed, cut, etc.). They
have their own problems (speed aside), namely portability.

Portability improvements
Shell scripts often relies on many of those POSIX utilities, which are
not necessarily natively available on all platforms (most notably,
Windows), or may have more or less features depending on the
implementation.

Although C is not perfect portability-wise, it’s still better than
shell scripts. For instance, the resulting binaries will not
necessarily depend on third-party programs or libraries.


RISKS

Of course, rewriting a piece of software takes time, and can lead to
regressions (ie. new bugs). To mitigate that risk, I should understand
well the functions I want to rewrite, run tests on a regular basis and
write new if needed, and of course discuss about my code with the
community during reviews.


APPROXIMATIVE TIMELINE

Normally, I would be able to work 35 to 40 hours a week. When I have
courses or exams at university, I could work between 20 and 25 hours a
week.

Community bonding --- April 23, 2018 -- May 14, 2018
/I’ll still have courses at the university during this period./

During the community bonding, I would like to dive into git’s
codebase, and to understand what git-rebase--interactive does under
the hood. At the same time, I’d communicate with the community and my
mentor, seeking for clarifications, and asking questions about how
things should or should not be done.

Weeks 1 & 2 --- May 14, 2018 -- May 27, 2018
/From May 14 to 18, I have exams at the university, so I won’t be able
to work full time./

I would search for edge cases not covered by current tests and write
some if needed.

Week 3 --- May 28, 2018 -- June 3, 2018
At the same time, I would refactor --preserve-merges in its own
shell script, if it has not been deprecated or moved in the
meantime. Dscho explained that this would be the first step of the
conversion[1]. This operation is not really tricky by itself,
as --preserve-merges is about only 50 lines of code into
git_rebase__interactive(), plus some specific functions
(eg. pick_one()).

Weeks 4 to 7 --- June 4, 2018 -- July 1, 2018
Then, I would start to incrementally rewrite
git-rebase--interactive.sh functions in C, and move them
git-rebase--helper.c. Newly-rewritten C functions are then
associated to command-line parameters to be able to use them from
shell scripts.

Examples of such conversion can be found in commits
0cce4a2756[3] (rebase -i -x: add exec commands via the
rebase--helper) and b903674b35[4] (bisect--helper:
`is_expected_rev` & `check_expected_revs` shell function in C).

There is a lot of functions into git-rebase--interactive.sh to
rewrite. Most of them are small, and some of them are even wrappers
for a single command (eg. do_next()), so they shouldn’t be really

Re: [PATCH v2] Makefile: detect compiler and enable more warnings in DEVELOPER=1

2018-03-24 Thread Eric Sunshine
On Sat, Mar 24, 2018 at 8:53 AM, Nguyễn Thái Ngọc Duy  wrote:
> The set of extra warnings we enable when DEVELOPER has to be
> conservative because we can't assume any compiler version the
> developer may use. Detect the compiler version so we know when it's
> safe to enable -Wextra and maybe more.
>
> These warning settings are mostly from my custom config.mak a long
> time ago when I tried to enable as many warnings as possible that can
> still build without showing warnings. Some of them those warnings are

s/them those/those/

> probably worth fixing instead of just suppressing in future.
>
> Helped-by: Jeff King 
> Signed-off-by: Nguyễn Thái Ngọc Duy 


**Herzlichen Glückwunsch**

2018-03-24 Thread Euro Millions
Herzlichen Glückwunsch, Sie haben 650.000 Euro in den monatlichen Gewinnspielen 
von Euro Millions/Google Promo am 10. März 2018 gewonnen.

Kontaktieren Sie unseren Schadenregulierungsbeauftragten mit den folgenden 
Informationen

Vollständiger Name
Heimatadresse
Geschlecht
Alter
Telefon

Mr.Pianese Germano



Re: [ANNOUNCE] Git Rev News edition 37

2018-03-24 Thread Philip Oakley

From: "Christian Couder" 

Hi everyone,

The 37th edition of Git Rev News is now published:

 https://git.github.io/rev_news/2018/03/21/edition-37/

Thanks a lot to all the contributors!

Enjoy,
Christian, Jakub, Markus and Gabriel.



Thank you for the Git Rev News. I've been off-line for 5 weeks, so seeing 
the newsletter is great.


Next is to peruse Junio's "What's Cooking" lists.

Thanks to all.

Philip 



Re: [PATCH v4 4/4] worktree: teach "add" to check out existing branches

2018-03-24 Thread Thomas Gummerer
On 03/20, Eric Sunshine wrote:
> On Sat, Mar 17, 2018 at 6:22 PM, Thomas Gummerer  wrote:
> > [...]
> > However we can do a little better than that, and check the branch out if
> > it is not checked out anywhere else.  This will help users who just want
> > to check an existing branch out into a new worktree, and save a few
> > keystrokes.
> > [...]
> > We will still 'die()' if the branch is checked out in another worktree,
> > unless the --force flag is passed.
> >
> > Signed-off-by: Thomas Gummerer 
> > ---
> > diff --git a/Documentation/git-worktree.txt b/Documentation/git-worktree.txt
> > @@ -61,8 +61,13 @@ $ git worktree add --track -b   
> > /
> >  If `` is omitted and neither `-b` nor `-B` nor `--detach` used,
> > -then, as a convenience, a new branch based at HEAD is created 
> > automatically,
> > -as if `-b $(basename )` was specified.
> > +then, as a convenience, a worktree with a branch named after
> > +`$(basename )` (call it ``) is created.  If ``
> > +doesn't exist, a new branch based on HEAD is automatically created as
> > +if `-b ` was given.  If `` exists in the repository,
> > +it will be checked out in the new worktree, if it's not checked out
> > +anywhere else, otherwise the command will refuse to create the
> > +worktree.
> 
> Should this mention --force?
> 
> ... refuse to create the worktree (unless --force is used).

Yeah, will add.

> > diff --git a/builtin/worktree.c b/builtin/worktree.c
> > @@ -29,6 +29,7 @@ struct add_opts {
> > int keep_locked;
> > const char *new_branch;
> > int force_new_branch;
> > +   int checkout_existing_branch;
> 
> As 'force_new_branch' and 'checkout_existing_branch' are mutually
> exclusive, I wonder if they should be combined into an enum to make it
> easier to reason about.

I gave this a try, but I'm not sure the end result is nicer.  The
problem is that 'new_branch' and 'force_new_branch' both are mutually
exclusive with 'checkout_existing_branch', but 'force_new_branch' is a
"superset" of 'new_branch'.

I can't seem to think of a nice way to encode that, especially not
without duplicating information we're already carrying in
'new_branch'.  Looking at the code however I see that
'force_new_branch' is already only duplicating information that we
already have in a variable in the same function.  I think just
removing that duplication and keeping the 'checkout_existing_branch'
variable in the 'add_opts' would make most sense.

> > @@ -318,8 +319,11 @@ static int add_worktree(const char *path, const char 
> > *refname,
> > -   if (opts->new_branch)
> > -   fprintf(stderr, _("creating new branch '%s'"), 
> > opts->new_branch);
> > +   if (opts->checkout_existing_branch)
> > +   fprintf(stderr, _("checking out branch '%s'"),
> > +   refname);
> 
> As with "creating branch" in 2/4, "checking out branch..." here is
> missing a newline.

Thanks will add.

> > +   else if (opts->new_branch)
> > +   fprintf(stderr, _("creating branch '%s'"), 
> > opts->new_branch);
> >
> > fprintf(stderr, _("worktree HEAD is now at %s"),
> > find_unique_abbrev(commit->object.oid.hash, 
> > DEFAULT_ABBREV));
> > diff --git a/t/t2025-worktree-add.sh b/t/t2025-worktree-add.sh
> > @@ -198,13 +198,22 @@ test_expect_success '"add" with  omitted' '
> > -test_expect_success '"add" auto-vivify does not clobber existing branch' '
> > +test_expect_success '"add" auto-vivify checks out existing branch' '
> > test_commit c1 &&
> > test_commit c2 &&
> > git branch precious HEAD~1 &&
> > -   test_must_fail git worktree add precious &&
> > +   git worktree add precious &&
> > test_cmp_rev HEAD~1 precious &&
> > -   test_path_is_missing precious
> > +   (
> > +   cd precious &&
> > +   test_cmp_rev precious HEAD
> > +   )
> > +'
> 
> This test is no longer checking auto-vivification ("bringing a new
> branch to life automatically"), but rather branch name inference, so
> the title is now misleading. Perhaps retitle it to '"add" checks out
> existing branch of dwim'd name' or something.
> 
> (The name "precious" is also now misleading since it's no longer
> checking that a precious branch does not get clobbered, however,
> changing the name would make the diff unnecessarily noisy, so it's
> probably okay as is.)

Good point.  I can add an additional patch with that rename, so the
changes here stay more obvious, but the end result would still end up
less confusing.

> > +test_expect_success '"add" auto-vivify fails with checked out branch' '
> > +   git checkout -b test-branch &&
> > +   test_must_fail git worktree add test-branch &&
> > +   test_path_is_missing test-branch
> >  '
> 
> Should we also have a corresponding test that this "fail" can be
> overridden by --force? (I realize that --force is tested elsewhere,
> but only with an 

Re: Null pointer dereference in git-submodule

2018-03-24 Thread René Scharfe
Am 24.03.2018 um 18:42 schrieb Jeremy Feusi:
> Hi,
> While bootstrapping a gnu repository I noticed that git segfaulted when
> called as "git submodule status". After compiling git with address
> sanitizer and minimizing the directory I finally narrowed it down to the
> files which I have attached as a tar archive. Here is a detailed backtrace:
> 
> AddressSanitizer:DEADLYSIGNAL
> =
> ==63400==ERROR: AddressSanitizer: SEGV on unknown address 0x (pc 
> 0x00c27a93 bp 0x7ffdcb4eec10 sp 0x7ffdcb4eeb80 T0)
> ==63400==The signal is caused by a READ memory access.
> ==63400==Hint: address points to the zero page.
>  #0 0xc27a92 in refs_read_raw_ref /home/jfe/git/refs.c:1451:20
>  #1 0xc174a6 in refs_resolve_ref_unsafe /home/jfe/git/refs.c:1493:7
>  #2 0xc1826a in refs_read_ref_full /home/jfe/git/refs.c:224:6
>  #3 0xc26d53 in refs_head_ref /home/jfe/git/refs.c:1314:7
>  #4 0x8071e6 in status_submodule 
> /home/jfe/git/builtin/submodule--helper.c:658:7
>  #5 0x806a89 in status_submodule_cb 
> /home/jfe/git/builtin/submodule--helper.c:699:2
>  #6 0x80523e in for_each_listed_submodule 
> /home/jfe/git/builtin/submodule--helper.c:438:3
>  #7 0x7f7e9a in module_status 
> /home/jfe/git/builtin/submodule--helper.c:732:2
>  #8 0x7efd69 in cmd_submodule__helper 
> /home/jfe/git/builtin/submodule--helper.c:1859:11
>  #9 0x51e024 in run_builtin /home/jfe/git/git.c:346:11
>  #10 0x5192c2 in handle_builtin /home/jfe/git/git.c:554:8
>  #11 0x51d0f0 in run_argv /home/jfe/git/git.c:606:4
>  #12 0x518600 in cmd_main /home/jfe/git/git.c:683:19
>  #13 0x8501d6 in main /home/jfe/git/common-main.c:43:9
>  #14 0x7f49fdaf2f29 in __libc_start_main 
> (/lib/x86_64-linux-gnu/libc.so.6+0x20f29)
>  #15 0x41f4b9 in _start (/home/jfe/git/inst/libexec/git-core/git+0x41f4b9)
> 
> AddressSanitizer can not provide additional info.
> SUMMARY: AddressSanitizer: SEGV /home/jfe/git/refs.c:1451:20 in 
> refs_read_raw_ref
> ==63400==ABORTING
> 
> As mentioned above, this bug is triggered by issuing the command
> "git submodule status" while in the attached directory.
> 
> This bug was confirmed on Debian with version 2.16.1 and
> 2.17.0.rc1.35.g90bbd502d as well as on Arch Linux with version 2.16.2
> where further output is given by git:
> 
> /usr/lib/git-core/git-submodule: line 979:  8119 Segmentation fault  
> (core dumped) git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix 
> "$prefix"} submodule--helper status ${GIT_QUIET:+--quiet} ${cached:+--cached} 
> ${recursive:+--recursive} "$@"
> 

You may have minimized too much.  With the patch below I get:

fatal: no ref store in submodule 'gnulib'

I guess you'll get a different one in your original repo.

The patch seems like a good idea in any case, though.

-- >8 --
Subject: [PATCH] submodule: check for NULL return of get_submodule_ref_store()

refs_head_ref() requires a valid ref_store pointer to be given as its
first argument.  get_submodule_ref_store() can return NULL.  Exit and
report the failure to find a ref store in that case instead of
segfaulting.

Reported-by: Jeremy Feusi 
Signed-off-by: Rene Scharfe 
---
 builtin/submodule--helper.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index ee020d4749..0f74e81005 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -654,9 +654,11 @@ static void status_submodule(const char *path, const 
struct object_id *ce_oid,
 displaypath);
} else if (!(flags & OPT_CACHED)) {
struct object_id oid;
+   struct ref_store *refs = get_submodule_ref_store(path);
 
-   if (refs_head_ref(get_submodule_ref_store(path),
- handle_submodule_head_ref, ))
+   if (!refs)
+   die(_("no ref store in submodule '%s'"), path);
+   if (refs_head_ref(refs, handle_submodule_head_ref, ))
die(_("could not resolve HEAD ref inside the "
  "submodule '%s'"), path);
 
-- 
2.16.3


[PATCH v2 6/8] completion: delete option-only completion commands

2018-03-24 Thread Nguyễn Thái Ngọc Duy
The new function __git_complete_common can take over this job with
less code to maintain.

Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 contrib/completion/git-completion.bash | 15 ---
 1 file changed, 15 deletions(-)

diff --git a/contrib/completion/git-completion.bash 
b/contrib/completion/git-completion.bash
index a90b0e8db4..0ee0ad7ac3 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1501,16 +1501,6 @@ _git_fsck ()
esac
 }
 
-_git_gc ()
-{
-   case "$cur" in
-   --*)
-   __gitcomp_builtin gc
-   return
-   ;;
-   esac
-}
-
 _git_gitk ()
 {
_gitk
@@ -1810,11 +1800,6 @@ _git_mv ()
fi
 }
 
-_git_name_rev ()
-{
-   __gitcomp_builtin name-rev
-}
-
 _git_notes ()
 {
local subcommands='add append copy edit get-ref list merge prune remove 
show'
-- 
2.17.0.rc0.348.gd5a49e0b6f



[PATCH v2 5/8] completion: add --option completion for most builtin commands

2018-03-24 Thread Nguyễn Thái Ngọc Duy
Many builtin commands use parseopt which supports expose the option
list via --git-completion-helper but do not have explicit support in
git-completion.bash. This patch detects those commands and uses
__gitcomp_builtin for option completion.

This does not pollute the command name completion though. "git "
will show you the same set as before. This only kicks in when you type
the correct command name.

Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 contrib/completion/git-completion.bash | 28 ++
 t/t9902-completion.sh  |  6 ++
 2 files changed, 34 insertions(+)

diff --git a/contrib/completion/git-completion.bash 
b/contrib/completion/git-completion.bash
index b3a9ecfad0..a90b0e8db4 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -3034,12 +3034,40 @@ _git_worktree ()
fi
 }
 
+__git_complete_common () {
+   local command="$1"
+
+   case "$cur" in
+   --*)
+   __gitcomp_builtin "$command"
+   ;;
+   esac
+}
+
+__git_cmds_with_parseopt_helper=
+__git_support_parseopt_helper () {
+   test -n "$__git_cmds_with_parseopt_helper" ||
+   __git_cmds_with_parseopt_helper="$(__git 
--list-parseopt-builtins)"
+
+   case " $__git_cmds_with_parseopt_helper " in
+   *" $1 "*)
+   return 0
+   ;;
+   *)
+   return 1
+   ;;
+   esac
+}
+
 __git_complete_command () {
local command="$1"
local completion_func="_git_${command//-/_}"
if declare -f $completion_func >/dev/null 2>/dev/null; then
$completion_func
return 0
+   elif __git_support_parseopt_helper "$command"; then
+   __git_complete_common "$command"
+   return 0
else
return 1
fi
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index e6485feb0a..d0a1e4c988 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -1454,6 +1454,12 @@ test_expect_success 'completion used  completion 
for alias: !f() { : git 

[PATCH v2 3/8] completion: mention the oldest version we need to support

2018-03-24 Thread Nguyễn Thái Ngọc Duy
This is more of a note for git-completion.bash contributors, not
users. The bash version is from MacOS [1]. Most Linux distros should
be 4.x at this point.

[1] 
https://public-inbox.org/git/%3ccapig+cqxt1ov4mjzszqilbzr4wn1xcp7asxmp+_dhtwtywh...@mail.gmail.com%3E/

Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 contrib/completion/git-completion.bash | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/contrib/completion/git-completion.bash 
b/contrib/completion/git-completion.bash
index c7957f0a90..9bef457792 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -29,6 +29,8 @@
 # tell the completion to use commit completion.  This also works with aliases
 # of form "!sh -c '...'".  For example, "!sh -c ': git commit ; ... '".
 #
+# Compatible with bash 3.2.57.
+#
 # You can set the following environment variables to influence the behavior of
 # the completion routines:
 #
-- 
2.17.0.rc0.348.gd5a49e0b6f



[PATCH v2 0/8] completion: add option completion for most builtin commands

2018-03-24 Thread Nguyễn Thái Ngọc Duy
This series adds option completion for many more commands. More
importantly it introduces a generic completion function
__git_complete_common(). With --git-completion-helper providing more
and more information in future, this function can start to replace
many other _git_xxx() in this file.

Nguyễn Thái Ngọc Duy (8):
  git.c: move cmd_struct declaration up
  git.c: add hidden option --list-parseopt-builtins
  completion: mention the oldest version we need to support
  completion: factor out _git_xxx calling code
  completion: add --option completion for most builtin commands
  completion: delete option-only completion commands
  completion: use __gitcomp_builtin in _git_ls_tree
  completion: use __gitcomp_builtin in _git_cherry

 contrib/completion/git-completion.bash |  75 +++
 git.c  | 122 +
 t/t9902-completion.sh  |   6 ++
 3 files changed, 127 insertions(+), 76 deletions(-)

-- 
2.17.0.rc0.348.gd5a49e0b6f



[PATCH v2 7/8] completion: use __gitcomp_builtin in _git_ls_tree

2018-03-24 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 contrib/completion/git-completion.bash | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/contrib/completion/git-completion.bash 
b/contrib/completion/git-completion.bash
index 0ee0ad7ac3..2f16264413 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1625,6 +1625,13 @@ _git_ls_remote ()
 
 _git_ls_tree ()
 {
+   case "$cur" in
+   --*)
+   __gitcomp_builtin ls-tree
+   return
+   ;;
+   esac
+
__git_complete_file
 }
 
-- 
2.17.0.rc0.348.gd5a49e0b6f



[PATCH v2 2/8] git.c: add hidden option --list-parseopt-builtins

2018-03-24 Thread Nguyễn Thái Ngọc Duy
This is another step to help automate git-completion.bash. This option
gives a list of all builtin commands that do use parse_options(),
which supports another hidden option --git-completion-helper. The
output is prepared for easy consumption by git-completion.bash and
separates items by spaces instead of \n

Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 git.c | 90 ---
 1 file changed, 49 insertions(+), 41 deletions(-)

diff --git a/git.c b/git.c
index bc4a5459d3..3a89893712 100644
--- a/git.c
+++ b/git.c
@@ -14,11 +14,12 @@
 #define NEED_WORK_TREE (1<<3)
 #define SUPPORT_SUPER_PREFIX   (1<<4)
 #define DELAY_PAGER_CONFIG (1<<5)
+#define NO_PARSEOPT(1<<6) /* parse-options is not used */
 
 struct cmd_struct {
const char *cmd;
int (*fn)(int, const char **, const char *);
-   int option;
+   unsigned int option;
 };
 
 const char git_usage_string[] =
@@ -35,7 +36,7 @@ const char git_more_info_string[] =
 
 static int use_pager = -1;
 
-static void list_builtins(void);
+static void list_builtins(unsigned int exclude_option, char sep);
 
 static void commit_pager_choice(void) {
switch (use_pager) {
@@ -223,7 +224,10 @@ static int handle_options(const char ***argv, int *argc, 
int *envchanged)
(*argv)++;
(*argc)--;
} else if (!strcmp(cmd, "--list-builtins")) {
-   list_builtins();
+   list_builtins(0, '\n');
+   exit(0);
+   } else if (!strcmp(cmd, "--list-parseopt-builtins")) {
+   list_builtins(NO_PARSEOPT, ' ');
exit(0);
} else {
fprintf(stderr, _("unknown option: %s\n"), cmd);
@@ -367,18 +371,18 @@ static int run_builtin(struct cmd_struct *p, int argc, 
const char **argv)
 static struct cmd_struct commands[] = {
{ "add", cmd_add, RUN_SETUP | NEED_WORK_TREE },
{ "am", cmd_am, RUN_SETUP | NEED_WORK_TREE },
-   { "annotate", cmd_annotate, RUN_SETUP },
+   { "annotate", cmd_annotate, RUN_SETUP | NO_PARSEOPT },
{ "apply", cmd_apply, RUN_SETUP_GENTLY },
{ "archive", cmd_archive, RUN_SETUP_GENTLY },
{ "bisect--helper", cmd_bisect__helper, RUN_SETUP },
{ "blame", cmd_blame, RUN_SETUP },
{ "branch", cmd_branch, RUN_SETUP | DELAY_PAGER_CONFIG },
-   { "bundle", cmd_bundle, RUN_SETUP_GENTLY },
+   { "bundle", cmd_bundle, RUN_SETUP_GENTLY | NO_PARSEOPT },
{ "cat-file", cmd_cat_file, RUN_SETUP },
{ "check-attr", cmd_check_attr, RUN_SETUP },
{ "check-ignore", cmd_check_ignore, RUN_SETUP | NEED_WORK_TREE },
{ "check-mailmap", cmd_check_mailmap, RUN_SETUP },
-   { "check-ref-format", cmd_check_ref_format },
+   { "check-ref-format", cmd_check_ref_format, NO_PARSEOPT  },
{ "checkout", cmd_checkout, RUN_SETUP | NEED_WORK_TREE },
{ "checkout-index", cmd_checkout_index,
RUN_SETUP | NEED_WORK_TREE},
@@ -388,30 +392,30 @@ static struct cmd_struct commands[] = {
{ "clone", cmd_clone },
{ "column", cmd_column, RUN_SETUP_GENTLY },
{ "commit", cmd_commit, RUN_SETUP | NEED_WORK_TREE },
-   { "commit-tree", cmd_commit_tree, RUN_SETUP },
+   { "commit-tree", cmd_commit_tree, RUN_SETUP | NO_PARSEOPT },
{ "config", cmd_config, RUN_SETUP_GENTLY | DELAY_PAGER_CONFIG },
{ "count-objects", cmd_count_objects, RUN_SETUP },
-   { "credential", cmd_credential, RUN_SETUP_GENTLY },
+   { "credential", cmd_credential, RUN_SETUP_GENTLY | NO_PARSEOPT },
{ "describe", cmd_describe, RUN_SETUP },
-   { "diff", cmd_diff },
-   { "diff-files", cmd_diff_files, RUN_SETUP | NEED_WORK_TREE },
-   { "diff-index", cmd_diff_index, RUN_SETUP },
-   { "diff-tree", cmd_diff_tree, RUN_SETUP },
+   { "diff", cmd_diff, NO_PARSEOPT },
+   { "diff-files", cmd_diff_files, RUN_SETUP | NEED_WORK_TREE | 
NO_PARSEOPT },
+   { "diff-index", cmd_diff_index, RUN_SETUP | NO_PARSEOPT },
+   { "diff-tree", cmd_diff_tree, RUN_SETUP | NO_PARSEOPT },
{ "difftool", cmd_difftool, RUN_SETUP | NEED_WORK_TREE },
{ "fast-export", cmd_fast_export, RUN_SETUP },
{ "fetch", cmd_fetch, RUN_SETUP },
-   { "fetch-pack", cmd_fetch_pack, RUN_SETUP },
+   { "fetch-pack", cmd_fetch_pack, RUN_SETUP | NO_PARSEOPT },
{ "fmt-merge-msg", cmd_fmt_merge_msg, RUN_SETUP },
{ "for-each-ref", cmd_for_each_ref, RUN_SETUP },
{ "format-patch", cmd_format_patch, RUN_SETUP },
{ "fsck", cmd_fsck, RUN_SETUP },
{ "fsck-objects", cmd_fsck, RUN_SETUP },
{ "gc", cmd_gc, RUN_SETUP },
-   { "get-tar-commit-id", cmd_get_tar_commit_id },
+   { "get-tar-commit-id", cmd_get_tar_commit_id, NO_PARSEOPT },
{ "grep", cmd_grep, RUN_SETUP_GENTLY },
{ 

[PATCH v2 4/8] completion: factor out _git_xxx calling code

2018-03-24 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 contrib/completion/git-completion.bash | 17 +
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/contrib/completion/git-completion.bash 
b/contrib/completion/git-completion.bash
index 9bef457792..b3a9ecfad0 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -3034,6 +3034,17 @@ _git_worktree ()
fi
 }
 
+__git_complete_command () {
+   local command="$1"
+   local completion_func="_git_${command//-/_}"
+   if declare -f $completion_func >/dev/null 2>/dev/null; then
+   $completion_func
+   return 0
+   else
+   return 1
+   fi
+}
+
 __git_main ()
 {
local i c=1 command __git_dir __git_repo_path
@@ -3093,14 +3104,12 @@ __git_main ()
return
fi
 
-   local completion_func="_git_${command//-/_}"
-   declare -f $completion_func >/dev/null 2>/dev/null && $completion_func 
&& return
+   __git_complete_command "$command" && return
 
local expansion=$(__git_aliased_command "$command")
if [ -n "$expansion" ]; then
words[1]=$expansion
-   completion_func="_git_${expansion//-/_}"
-   declare -f $completion_func >/dev/null 2>/dev/null && 
$completion_func
+   __git_complete_command "$expansion"
fi
 }
 
-- 
2.17.0.rc0.348.gd5a49e0b6f



[PATCH v2 1/8] git.c: move cmd_struct declaration up

2018-03-24 Thread Nguyễn Thái Ngọc Duy
In a later patch we need access to one of these command option
constants near the top of this file. Move this block up so we will be
able to access the command options.

Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 git.c | 34 +-
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/git.c b/git.c
index ceaa58ef40..bc4a5459d3 100644
--- a/git.c
+++ b/git.c
@@ -4,6 +4,23 @@
 #include "help.h"
 #include "run-command.h"
 
+#define RUN_SETUP  (1<<0)
+#define RUN_SETUP_GENTLY   (1<<1)
+#define USE_PAGER  (1<<2)
+/*
+ * require working tree to be present -- anything uses this needs
+ * RUN_SETUP for reading from the configuration file.
+ */
+#define NEED_WORK_TREE (1<<3)
+#define SUPPORT_SUPER_PREFIX   (1<<4)
+#define DELAY_PAGER_CONFIG (1<<5)
+
+struct cmd_struct {
+   const char *cmd;
+   int (*fn)(int, const char **, const char *);
+   int option;
+};
+
 const char git_usage_string[] =
N_("git [--version] [--help] [-C ] [-c =]\n"
   "   [--exec-path[=]] [--html-path] [--man-path] 
[--info-path]\n"
@@ -288,23 +305,6 @@ static int handle_alias(int *argcp, const char ***argv)
return ret;
 }
 
-#define RUN_SETUP  (1<<0)
-#define RUN_SETUP_GENTLY   (1<<1)
-#define USE_PAGER  (1<<2)
-/*
- * require working tree to be present -- anything uses this needs
- * RUN_SETUP for reading from the configuration file.
- */
-#define NEED_WORK_TREE (1<<3)
-#define SUPPORT_SUPER_PREFIX   (1<<4)
-#define DELAY_PAGER_CONFIG (1<<5)
-
-struct cmd_struct {
-   const char *cmd;
-   int (*fn)(int, const char **, const char *);
-   int option;
-};
-
 static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
 {
int status, help;
-- 
2.17.0.rc0.348.gd5a49e0b6f



[PATCH v2 8/8] completion: use __gitcomp_builtin in _git_cherry

2018-03-24 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 contrib/completion/git-completion.bash | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/contrib/completion/git-completion.bash 
b/contrib/completion/git-completion.bash
index 2f16264413..0fe91d016f 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1282,6 +1282,12 @@ _git_checkout ()
 
 _git_cherry ()
 {
+   case "$cur" in
+   --*)
+   __gitcomp_builtin cherry
+   return
+   esac
+
__git_complete_refs
 }
 
-- 
2.17.0.rc0.348.gd5a49e0b6f



Re: [PATCH v4 2/4] worktree: be clearer when "add" dwim-ery kicks in

2018-03-24 Thread Thomas Gummerer
On 03/20, Eric Sunshine wrote:
> On Tue, Mar 20, 2018 at 3:26 AM, Eric Sunshine  
> wrote:
> > On Sat, Mar 17, 2018 at 6:22 PM, Thomas Gummerer  
> > wrote:
> >> Currently there is no indication in the "git worktree add" output that
> >> a new branch was created.  This would be especially useful information
> >> in the case where the dwim of "git worktree add " kicks in, as the
> >> user didn't explicitly ask for a new branch, but we create one from
> >> them.
> >>
> >> Print some additional output showing that a branch was created and the
> >> branch name to help the user.
> >> [...]
> >> Signed-off-by: Thomas Gummerer 
> >> ---
> >> diff --git a/builtin/worktree.c b/builtin/worktree.c
> >> @@ -318,6 +318,9 @@ static int add_worktree(const char *path, const char 
> >> *refname,
> >> +   if (opts->new_branch)
> >> +   fprintf(stderr, _("creating new branch '%s'"), 
> >> opts->new_branch);
> >> +
> >> fprintf(stderr, _("worktree HEAD is now at %s"),
> >> find_unique_abbrev(commit->object.oid.hash, 
> >> DEFAULT_ABBREV));
> >
> > The "creating" message is missing a newline, which results in rather
> > ugly output:
> >
> > creating new branch 'foo'worktree HEAD is now at ...
> 
> Also, I believe that the agreement[1] was that this message should say
> merely "creating branch", not "creating _new_ branch". And, indeed,
> patch 4/4 stealthily drops "new" from the message, but it really ought
> to be introduced with correct text in this patch, not fixed by 4/4.

Ah yeah thanks for catching those, will fix.

> [1]: https://public-inbox.org/git/xmqqh8qv9ojb@gitster-ct.c.googlers.com/


Re: [PATCH v4 1/4] worktree: improve message when creating a new worktree

2018-03-24 Thread Thomas Gummerer
On 03/20, Eric Sunshine wrote:
> On Sat, Mar 17, 2018 at 6:22 PM, Thomas Gummerer  wrote:
> > [...]
> > Fix these inconsistencies, and no longer show the identifier by making
> > the 'git reset --hard' call quiet, and printing the message directly
> > from the builtin command instead.
> >
> > Signed-off-by: Thomas Gummerer 
> > ---
> > diff --git a/builtin/worktree.c b/builtin/worktree.c
> > @@ -303,8 +303,6 @@ static int add_worktree(const char *path, const char 
> > *refname,
> > strbuf_addf(, "%s/commondir", sb_repo.buf);
> > write_file(sb.buf, "../..");
> >
> > -   fprintf_ln(stderr, _("Preparing %s (identifier %s)"), path, name);
> 
> A minor regression with this change is that error messages from
> git-update-ref or git-symbolic-ref -- which could be emitted after
> this point but before the new "worktree HEAD is now at..." message --
> are now somewhat orphaned. I'm not sure that it matters, though.

If those commands fail, we would now not print the "worktree HEAD is
now at..." message, but go directly to "done", and clean up the
working tree.

So while we no longer emit the "Preparing worktree" header, the user
should still be aware that they are creating a new worktree, and that
the error happened while creating a new worktree.  From a (admittedly
very quick) look the error messages would all make sense in this
context, without an additional message.

Printing the "worktree HEAD is now at ..." message before that
wouldn't make much sense, as we may not even have a new working tree
at the end.  We could add the message back, but that would also put us
back at three lines of output.  I think I prefer the more concise
version here in the normal case, and I think we can live with the
slight regression.  But if others have a strong preference for the
current way I'm happy to add that message back.

> > argv_array_pushf(_env, "%s=%s", GIT_DIR_ENVIRONMENT, 
> > sb_git.buf);
> > argv_array_pushf(_env, "%s=%s", GIT_WORK_TREE_ENVIRONMENT, 
> > path);
> > cp.git_cmd = 1;
> > @@ -320,10 +318,19 @@ static int add_worktree(const char *path, const char 
> > *refname,
> > +   fprintf(stderr, _("worktree HEAD is now at %s"),
> > +   find_unique_abbrev(commit->object.oid.hash, 
> > DEFAULT_ABBREV));
> 
> I wonder if this should say "new worktree HEAD is now at..." to
> clearly indicate that it is talking about HEAD in the _new_ worktree,
> not HEAD in the current worktree.

Yeah I aggree that's nicer.  Will change.

> > +   strbuf_reset();
> > +   pp_commit_easy(CMIT_FMT_ONELINE, commit, );
> > +   if (sb.len > 0)
> > +   fprintf(stderr, " %s", sb.buf);
> > +   fputc('\n', stderr);


[PATCH v3] filter-branch: fix errors caused by refs that point at non-committish

2018-03-24 Thread Yuki Kokubun
"git filter-branch -- --all" print error messages when refs that point at
objects that are not committish. Such refs can be created by "git replace" with
trees or blobs. And also "git tag" with trees or blobs can create such refs.

Filter these problematic refs out early, before they are seen by the logic to
see which refs have been modified and which have been left intact (which is
where the unwanted error messages come from), and warn that these refs are left
unwritten while doing so.
---
 git-filter-branch.sh | 14 --
 t/t7003-filter-branch.sh | 14 ++
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index 1b7e4b2..41efecb 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -251,8 +251,18 @@ done < "$tempdir"/backup-refs
 
 # The refs should be updated if their heads were rewritten
 git rev-parse --no-flags --revs-only --symbolic-full-name \
-   --default HEAD "$@" > "$tempdir"/raw-heads || exit
-sed -e '/^^/d' "$tempdir"/raw-heads >"$tempdir"/heads
+   --default HEAD "$@" > "$tempdir"/raw-refs || exit
+while read ref
+do
+   case "$ref" in ^?*) continue ;; esac
+
+   if git rev-parse --verify "$ref"^0 >/dev/null 2>&1
+   then
+   echo "$ref"
+   else
+   warn "WARNING: not rewriting '$ref' (not a committish)"
+   fi
+done >"$tempdir"/heads <"$tempdir"/raw-refs
 
 test -s "$tempdir"/heads ||
die "You must specify a ref to rewrite."
diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh
index 7cb6079..04f79f3 100755
--- a/t/t7003-filter-branch.sh
+++ b/t/t7003-filter-branch.sh
@@ -470,4 +470,18 @@ test_expect_success 'tree-filter deals with object name vs 
pathname ambiguity' '
git show HEAD:$ambiguous
 '
 
+test_expect_success 'rewrite repository including refs that point at 
non-commit object' '
+   test_when_finished "git reset --hard original" &&
+   tree=$(git rev-parse HEAD^{tree}) &&
+   test_when_finished "git replace -d $tree" &&
+   echo A >new &&
+   git add new &&
+   new_tree=$(git write-tree) &&
+   git replace $tree $new_tree &&
+   git tag -a -m "tag to a tree" treetag $new_tree &&
+   git reset --hard HEAD &&
+   git filter-branch -f -- --all >filter-output 2>&1 &&
+   ! fgrep fatal filter-output
+'
+
 test_done
-- 
1.9.1



Re: [PATCH] filter-branch: consider refs can refer to an object other than commit or tag

2018-03-24 Thread Yuki Kokubun
>> "git filter-branch -- --all" print unwanted error messages when refs that
>> cannot be used with ^0 exist.
>
> It is not incorrect per-se, but if I were writing this, I'd say
> "... when refs that point at objects that are not committish" or
> something like that, as that is much closer to people (both end
> users and Git developers) than the "^0" implementation detail.

I agree that readability to users is important than the implementation detail.
So, I'm gonna change the commit message.

>> Such refs can be created by "git replace" with
>> trees or blobs. Also, "git tag" with trees or blobs can create such refs.
> 
> Taking two paragraphs above together, you wrote an excellent
> description of the problem to be solved (i.e. what would be seen by
> users and under what condition the symptom would trigger).  If there
> is a single obvious solution that would trivially follow from the
> problem description, it is perfectly fine to stop here.  Otherwise,
> it would help to describe how it is solved next.  Something as brief
> like
> 
>   Filter these problematic refs out early, and warn that these
>   refs are left unwritten while doing so.
> 
> would suffice in this case, I think.  We _could_ insert
> 
>   before they are seen by the logic to see which refs have
>   been modified and which have been left intact (which is
>   where the unwanted error messages come from),
> 
> between "early," and "and warn", if we wanted to.

I think the detailed description is better than the shorter one in this case.
So I'm gonna follow to detailed one.


Re: [GSoC] Convert “git stash” to builtin proposal

2018-03-24 Thread Paul-Sebastian Ungureanu

On 23.03.2018 19:11, Christian Couder wrote:


* Ensure that no regression occurred: considering that there are plenty
of tests and that I have a good understanding of the function, this
should be a trivial task.


There are a lot of things that the test suite doesn't test.


Hopefully, by first adding new tests, any eventual bug will be spotted.


* In the end, an analysis based on performance can be made.
Benchmarking the script will be done by recording the running time
given a large set of diversified tests that cover all the
functionalities, before and after conversion. The new commands should
run faster just because they were written in C, but I expect to see
even more improvements.


If you want to do benchmarks, you might want to add performance tests
into t/perf.


That is great. I will surely make use of the existent testing framework 
to do benchmarks.



## Example of conversion (for “git stash list”)
--
To test my capabilities and to be sure that I am able to work on a
project of this kind, I tried to convert “git stash list” into a built-
in. The result can be found below in text-only version or at the Github
link.


I think it would be better if it was sent as a patch (maybe an RFC
patch) to the mailing list and add the link to the patch email in the
maling list archive to your proposal.


I sent it as a [RFC] patch to the mailing list and included it in the 
proposal.





It could be useful if you described a bit more how you could (re)use
the work that has already been made.

In the rest of your proposal it looks like you are starting from
scratch, which is a bit strange if a lot of progress has already been
made.


The patches about converting ‘git stash’ are a great starting point and 
I will definitely use them. Each time I start converting a new command I 
will first take a look at what other patches there are, evaluate them 
and if I consider the patch to be good enough I will continue my work on 
top of that patch. Otherwise, I will start from scratch and that patch 
will only serve for comparison.


One other resource that is of great importance is git itself. I can 
learn how a builtin is structured and how it is built by considering 
examples the other Git commands. Having a similar coding standard used, 
the codebase will be homogeneous and hopefully easier to maintain.


Another important resource are commands that are Google Summer of Code 
projects from previous years (2016 and 2017) which had as purpose to 
convert “git bisect” and “git submodule”. I can always take a look at 
the patches they submitted and read their code reviews to avoid making 
same mistakes they did.



It is probably better especially for reviewers and more common to work
in small batches, for example to send a patch series converting a few
related commands, then to start working on the next small batch of
commands in another patch series while improving the first patch
series according to reviews.

Also we ask GSoC students to communicate publicly every week about
their project for example by writing a blg post or sending a report to
the mailing list.


Noted.


## Git contributions
--
My first contribution to Git was to help making “git tag --contains
” les chatty if  is invalid. Looking over the list of available
microprojects, there were a couple of microprojects which got my
attention, but I picked this up because it seemed to be a long-standing
bug (I noticed it was approached by students in 2016, 2017 and now in
2018). Thanks to the code reviews from the mailing list, after a few
iterations I succeeded in coming up with a patch that not only fixed
the mentioned problem, but also a few others that were having the same
cause.

It got merged in the proposed updates branch.


What is its status in Junio's "What's cooking in Git" emails?


It is now in the ‘next’ branch of the Git repository.

I updated the proposal, in which I included these ideas and some 
additional examples. Thank you a lot!


Best regards,
Paul Ungureanu


[PATCH] branch -l: print useful info whilst rebasing a non-local branch

2018-03-24 Thread Kaartic Sivaraam
When rebasing interacitvely (rebase -i), "git branch -l" prints a line
indicating the current branch being rebased. This works well when the
interactive rebase was intiated when a local branch is checked out.

This doesn't play well when the rebase was initiated on a remote
branch or an arbitrary commit that is not pointed to by a local
branch. In this case "git branch -l" tries to print the name of a
branch using an unintialized variable and thus tries to print a "null
pointer string". As a consequence, it does not provide useful
information while also inducing undefined behaviour.

So, print the commit from which the rebase started when interactive
rebasing a non-local branch.

Signed-off-by: Kaartic Sivaraam 
---
 ref-filter.c | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/ref-filter.c b/ref-filter.c
index f9e25aea7..a4c917c96 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1310,8 +1310,16 @@ char *get_head_description(void)
wt_status_get_state(, 1);
if (state.rebase_in_progress ||
state.rebase_interactive_in_progress)
+   {
+   const char *rebasing = NULL;
+   if (state.branch != NULL)
+   rebasing = state.branch;
+   else
+   rebasing = state.detached_from;
+
strbuf_addf(, _("(no branch, rebasing %s)"),
-   state.branch);
+   rebasing);
+   }
else if (state.bisect_in_progress)
strbuf_addf(, _("(no branch, bisect started on %s)"),
state.branch);
-- 
2.17.0.rc0.231.g781580f06



[RFC PATCH 0/1] json-writer: add cast to uintmax_t

2018-03-24 Thread Wink Saville
Building the pu branch at commit 8b49f5c076c using Travis-Ci all linux
builds worked but the two OSX builds failed with:

CC ident.o
CC json-writer.o

json-writer.c:123:38: error: format specifies type 'uintmax_t' (aka 'unsigned 
long') but the argument has type 'uint64_t' (aka 'unsigned long long') 
[-Werror,-Wformat]

strbuf_addf(>json, ":%"PRIuMAX, value);

json-writer.c:228:37: error: format specifies type 'uintmax_t' (aka 'unsigned 
long') but the argument has type 'uint64_t' (aka 'unsigned long long') 
[-Werror,-Wformat]

strbuf_addf(>json, "%"PRIuMAX, value);

Corrected in Patch 1/1 by casting value to uintmax_t.

Wink Saville (1):
  json-writer: add cast to uintmax_t

 json-writer.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

-- 
2.16.2



[RFC PATCH v2 1/1] json-writer: add cast to uintmax_t

2018-03-24 Thread Wink Saville
Correct a compile error on Mac OSX by adding a cast to uintmax_t
in calls to strbuf_addf.

Helped-by: Ramsay Jones 
Tested-by: travis-ci
Signed-off-by: Wink Saville 
---
 json-writer.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/json-writer.c b/json-writer.c
index 89a6abb57..1f40482ff 100644
--- a/json-writer.c
+++ b/json-writer.c
@@ -120,7 +120,7 @@ void jw_object_uint64(struct json_writer *jw, const char 
*key, uint64_t value)
maybe_add_comma(jw);
 
append_quoted_string(>json, key);
-   strbuf_addf(>json, ":%"PRIuMAX, value);
+   strbuf_addf(>json, ":%"PRIuMAX, (uintmax_t)value);
 }
 
 void jw_object_double(struct json_writer *jw, const char *fmt,
@@ -225,7 +225,7 @@ void jw_array_uint64(struct json_writer *jw, uint64_t value)
assert_in_array(jw);
maybe_add_comma(jw);
 
-   strbuf_addf(>json, "%"PRIuMAX, value);
+   strbuf_addf(>json, "%"PRIuMAX, (uintmax_t)value);
 }
 
 void jw_array_double(struct json_writer *jw, const char *fmt, double value)
-- 
2.16.2



[RFC][PATCH] git-stash: convert git stash list to C builtin

2018-03-24 Thread Paul-Sebastian Ungureanu
Currently, because git stash is not fully converted to C, I
introduced a new helper that will hold the converted commands.
---
 Makefile|  1 +
 builtin.h   |  1 +
 builtin/stash--helper.c | 52 +
 git-stash.sh|  7 +-
 git.c   |  1 +
 5 files changed, 56 insertions(+), 6 deletions(-)
 create mode 100644 builtin/stash--helper.c

diff --git a/Makefile b/Makefile
index a1d8775ad..8ca361c57 100644
--- a/Makefile
+++ b/Makefile
@@ -1020,6 +1020,7 @@ BUILTIN_OBJS += builtin/send-pack.o
 BUILTIN_OBJS += builtin/shortlog.o
 BUILTIN_OBJS += builtin/show-branch.o
 BUILTIN_OBJS += builtin/show-ref.o
+BUILTIN_OBJS += builtin/stash--helper.o
 BUILTIN_OBJS += builtin/stripspace.o
 BUILTIN_OBJS += builtin/submodule--helper.o
 BUILTIN_OBJS += builtin/symbolic-ref.o
diff --git a/builtin.h b/builtin.h
index 42378f3aa..2ddb4bd5c 100644
--- a/builtin.h
+++ b/builtin.h
@@ -220,6 +220,7 @@ extern int cmd_show(int argc, const char **argv, const char 
*prefix);
 extern int cmd_show_branch(int argc, const char **argv, const char *prefix);
 extern int cmd_status(int argc, const char **argv, const char *prefix);
 extern int cmd_stripspace(int argc, const char **argv, const char *prefix);
+extern int cmd_stash__helper(int argc, const char **argv, const char *prefix);
 extern int cmd_submodule__helper(int argc, const char **argv, const char 
*prefix);
 extern int cmd_symbolic_ref(int argc, const char **argv, const char *prefix);
 extern int cmd_tag(int argc, const char **argv, const char *prefix);
diff --git a/builtin/stash--helper.c b/builtin/stash--helper.c
new file mode 100644
index 0..61fd5390d
--- /dev/null
+++ b/builtin/stash--helper.c
@@ -0,0 +1,52 @@
+#include "builtin.h"
+#include "cache.h"
+#include "parse-options.h"
+#include "argv-array.h"
+
+enum {
+   LIST_STASH = 1
+};
+
+static const char * ref_stash = "refs/stash";
+
+static const char * const git_stash__helper_usage[] = {
+   N_("git stash--helper --list []"),
+   NULL
+};
+
+static int list_stash(int argc, const char **argv, const char *prefix)
+{
+   struct object_id obj;
+   struct argv_array args = ARGV_ARRAY_INIT;
+
+   if (get_oid(ref_stash, ))
+   return 0;
+
+   argv_array_pushl(, "log", "--format=%gd: %gs", "-g", 
"--first-parent", "-m", NULL);
+   argv_array_pushv(, argv);
+   argv_array_push(, ref_stash);
+   return !!cmd_log(args.argc, args.argv, prefix);
+}
+
+int cmd_stash__helper(int argc, const char **argv, const char *prefix)
+{
+   int cmdmode = 0;
+
+   struct option options[] = {
+   OPT_CMDMODE(0, "list", ,
+N_("list stash entries"), LIST_STASH),
+   OPT_END()
+   };
+
+   argc = parse_options(argc, argv, prefix, options,
+git_stash__helper_usage, PARSE_OPT_KEEP_UNKNOWN);
+
+   if (!cmdmode)
+   usage_with_options(git_stash__helper_usage, options);
+
+   switch (cmdmode) {
+   case LIST_STASH:
+   return list_stash(argc, argv, prefix);
+   }
+   return 0;
+}
diff --git a/git-stash.sh b/git-stash.sh
index fc8f8ae64..a5b9f5fb6 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -380,11 +380,6 @@ have_stash () {
git rev-parse --verify --quiet $ref_stash >/dev/null
 }
 
-list_stash () {
-   have_stash || return 0
-   git log --format="%gd: %gs" -g --first-parent -m "$@" $ref_stash --
-}
-
 show_stash () {
ALLOW_UNKNOWN_FLAGS=t
assert_stash_like "$@"
@@ -695,7 +690,7 @@ test -n "$seen_non_option" || set "push" "$@"
 case "$1" in
 list)
shift
-   list_stash "$@"
+   git stash--helper --list "$@"
;;
 show)
shift
diff --git a/git.c b/git.c
index 96cd734f1..6fd2ccd9a 100644
--- a/git.c
+++ b/git.c
@@ -466,6 +466,7 @@ static struct cmd_struct commands[] = {
{ "show-branch", cmd_show_branch, RUN_SETUP },
{ "show-ref", cmd_show_ref, RUN_SETUP },
{ "stage", cmd_add, RUN_SETUP | NEED_WORK_TREE },
+   { "stash--helper", cmd_stash__helper, RUN_SETUP },
{ "status", cmd_status, RUN_SETUP | NEED_WORK_TREE },
{ "stripspace", cmd_stripspace },
{ "submodule--helper", cmd_submodule__helper, RUN_SETUP | 
SUPPORT_SUPER_PREFIX},
-- 
2.16.2.647.gb9d10dde1



Re: [PATCH 3/4] stash: convert drop and clear to builtin

2018-03-24 Thread Christian Couder
> +   argv_array_pushl(, "reflog", "delete", "--updateref", 
> "--rewrite", NULL);
> +   argv_array_push(, info->revision);
> +   ret = cmd_reflog(args.argc, args.argv, prefix);
> +   if (!ret) {
> +   if (!quiet) {
> +   printf(_("Dropped %s (%s)\n"), info->revision, 
> sha1_to_hex(info->w_commit.hash));
> +   }

The brackets are not needed.

> +   } else {
> +   return error(_("%s: Could not drop stash entry"), 
> info->revision);
> +   }


Re: [PATCH 1/4] stash: convert apply to builtin

2018-03-24 Thread Christian Couder
> +   if (unpack_trees(nr_trees, t, ))
> +   return -1;
> +
> +   if (write_locked_index(_index, _file, COMMIT_LOCK)) {
> +   error(_("unable to write new index file"));
> +   return -1;

Maybe: return error(...);

> +   }
> +
> +   return 0;
> +}

[...]

> +   argc = parse_options(argc, argv, prefix, options,
> +   git_stash_helper_apply_usage, 0);
> +
> +   if (argc == 1) {
> +   commit = argv[0];
> +   }

The brackets are not needed.

> +   if (get_stash_info(, commit))
> +   return -1;
> +
> +

Spurious new line.

> +   return do_apply_stash(prefix, , index);
> +}


Null pointer dereference in git-submodule

2018-03-24 Thread Jeremy Feusi
Hi,
While bootstrapping a gnu repository I noticed that git segfaulted when
called as "git submodule status". After compiling git with address
sanitizer and minimizing the directory I finally narrowed it down to the
files which I have attached as a tar archive. Here is a detailed backtrace:

AddressSanitizer:DEADLYSIGNAL
=
==63400==ERROR: AddressSanitizer: SEGV on unknown address 0x (pc 
0x00c27a93 bp 0x7ffdcb4eec10 sp 0x7ffdcb4eeb80 T0)
==63400==The signal is caused by a READ memory access.
==63400==Hint: address points to the zero page.
#0 0xc27a92 in refs_read_raw_ref /home/jfe/git/refs.c:1451:20
#1 0xc174a6 in refs_resolve_ref_unsafe /home/jfe/git/refs.c:1493:7
#2 0xc1826a in refs_read_ref_full /home/jfe/git/refs.c:224:6
#3 0xc26d53 in refs_head_ref /home/jfe/git/refs.c:1314:7
#4 0x8071e6 in status_submodule 
/home/jfe/git/builtin/submodule--helper.c:658:7
#5 0x806a89 in status_submodule_cb 
/home/jfe/git/builtin/submodule--helper.c:699:2
#6 0x80523e in for_each_listed_submodule 
/home/jfe/git/builtin/submodule--helper.c:438:3
#7 0x7f7e9a in module_status /home/jfe/git/builtin/submodule--helper.c:732:2
#8 0x7efd69 in cmd_submodule__helper 
/home/jfe/git/builtin/submodule--helper.c:1859:11
#9 0x51e024 in run_builtin /home/jfe/git/git.c:346:11
#10 0x5192c2 in handle_builtin /home/jfe/git/git.c:554:8
#11 0x51d0f0 in run_argv /home/jfe/git/git.c:606:4
#12 0x518600 in cmd_main /home/jfe/git/git.c:683:19
#13 0x8501d6 in main /home/jfe/git/common-main.c:43:9
#14 0x7f49fdaf2f29 in __libc_start_main 
(/lib/x86_64-linux-gnu/libc.so.6+0x20f29)
#15 0x41f4b9 in _start (/home/jfe/git/inst/libexec/git-core/git+0x41f4b9)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/jfe/git/refs.c:1451:20 in 
refs_read_raw_ref
==63400==ABORTING

As mentioned above, this bug is triggered by issuing the command
"git submodule status" while in the attached directory.

This bug was confirmed on Debian with version 2.16.1 and
2.17.0.rc1.35.g90bbd502d as well as on Arch Linux with version 2.16.2
where further output is given by git:

/usr/lib/git-core/git-submodule: line 979:  8119 Segmentation fault  (core 
dumped) git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} 
submodule--helper status ${GIT_QUIET:+--quiet} ${cached:+--cached} 
${recursive:+--recursive} "$@"

cheers
Jeremy


min-man.tar.gz
Description: application/gzip


[PATCH 2/4] stash: convert branch to builtin

2018-03-24 Thread Joel Teichroeb
---
 builtin/stash--helper.c | 44 
 git-stash.sh|  3 ++-
 2 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/builtin/stash--helper.c b/builtin/stash--helper.c
index e9a9574f40..18c4aba665 100644
--- a/builtin/stash--helper.c
+++ b/builtin/stash--helper.c
@@ -12,6 +12,7 @@
 
 static const char * const git_stash_helper_usage[] = {
N_("git stash--helper apply [--index] [-q|--quiet] []"),
+   N_("git stash--helper branch  []"),
NULL
 };
 
@@ -20,6 +21,11 @@ static const char * const git_stash_helper_apply_usage[] = {
NULL
 };
 
+static const char * const git_stash_helper_branch_usage[] = {
+   N_("git stash--helper branch  []"),
+   NULL
+};
+
 static const char *ref_stash = "refs/stash";
 static int quiet;
 static char stash_index_path[PATH_MAX];
@@ -307,6 +313,42 @@ static int apply_stash(int argc, const char **argv, const 
char *prefix)
return do_apply_stash(prefix, , index);
 }
 
+static int branch_stash(int argc, const char **argv, const char *prefix)
+{
+   const char *commit = NULL, *branch = NULL;
+   int ret;
+   struct argv_array args = ARGV_ARRAY_INIT;
+   struct stash_info info;
+   struct option options[] = {
+   OPT_END()
+   };
+
+   argc = parse_options(argc, argv, prefix, options,
+   git_stash_helper_branch_usage, 0);
+
+   if (argc != 0) {
+   branch = argv[0];
+   if (argc == 2)
+   commit = argv[1];
+   }
+
+   if (get_stash_info(, commit))
+   return -1;
+
+   argv_array_pushl(, "checkout", "-b", NULL);
+   argv_array_push(, branch);
+   argv_array_push(, sha1_to_hex(info.b_commit.hash));
+   ret = cmd_checkout(args.argc, args.argv, prefix);
+   if (ret)
+   return -1;
+
+   ret = do_apply_stash(prefix, , 1);
+   if (!ret && info.is_stash_ref)
+   ret = do_drop_stash(prefix, );
+
+   return ret;
+}
+
 int cmd_stash__helper(int argc, const char **argv, const char *prefix)
 {
int result = 0;
@@ -329,6 +371,8 @@ int cmd_stash__helper(int argc, const char **argv, const 
char *prefix)
usage_with_options(git_stash_helper_usage, options);
else if (!strcmp(argv[0], "apply"))
result = apply_stash(argc, argv, prefix);
+   else if (!strcmp(argv[0], "branch"))
+   result = branch_stash(argc, argv, prefix);
else {
error(_("unknown subcommand: %s"), argv[0]);
usage_with_options(git_stash_helper_usage, options);
diff --git a/git-stash.sh b/git-stash.sh
index 92c084eb17..360643ad4e 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -736,7 +736,8 @@ pop)
;;
 branch)
shift
-   apply_to_branch "$@"
+   cd "$START_DIR"
+   git stash--helper branch "$@"
;;
 *)
case $# in
-- 
2.16.2



[PATCH 0/4] Convert some stash functionality to a builtin

2018-03-24 Thread Joel Teichroeb
I've been working on converting all of git stash to be a
builtin, however it's hard to get it all working at once with
limited time, so I've moved around half of it to a new
stash--helper builtin and called these functions from the shell
script. Once this is stabalized, it should be easier to convert
the rest of the commands one at a time without breaking
anything.

I've sent most of this code before, but that was targetting a
full replacement of stash. The code is overall the same, but
with some code review changes and updates for internal api
changes.

Since there seems to be interest from GSOC students who want to
work on converting builtins, I figured I should finish what I
have that works now so they could build on top of it.

Joel Teichroeb (4):
  stash: convert apply to builtin
  stash: convert branch to builtin
  stash: convert drop and clear to builtin
  stash: convert pop to builtin

 .gitignore  |   1 +
 Makefile|   1 +
 builtin.h   |   1 +
 builtin/stash--helper.c | 514 
 git-stash.sh|  13 +-
 git.c   |   1 +
 6 files changed, 526 insertions(+), 5 deletions(-)
 create mode 100644 builtin/stash--helper.c

-- 
2.16.2



[PATCH 3/4] stash: convert drop and clear to builtin

2018-03-24 Thread Joel Teichroeb
---
 builtin/stash--helper.c | 93 +
 git-stash.sh|  4 +--
 2 files changed, 95 insertions(+), 2 deletions(-)

diff --git a/builtin/stash--helper.c b/builtin/stash--helper.c
index 18c4aba665..1598b82ac2 100644
--- a/builtin/stash--helper.c
+++ b/builtin/stash--helper.c
@@ -11,8 +11,15 @@
 #include "dir.h"
 
 static const char * const git_stash_helper_usage[] = {
+   N_("git stash--helper drop [-q|--quiet] []"),
N_("git stash--helper apply [--index] [-q|--quiet] []"),
N_("git stash--helper branch  []"),
+   N_("git stash--helper clear"),
+   NULL
+};
+
+static const char * const git_stash_helper_drop_usage[] = {
+   N_("git stash--helper drop [-q|--quiet] []"),
NULL
 };
 
@@ -26,6 +33,11 @@ static const char * const git_stash_helper_branch_usage[] = {
NULL
 };
 
+static const char * const git_stash_helper_clear_usage[] = {
+   N_("git stash--helper clear"),
+   NULL
+};
+
 static const char *ref_stash = "refs/stash";
 static int quiet;
 static char stash_index_path[PATH_MAX];
@@ -114,6 +126,29 @@ static int get_stash_info(struct stash_info *info, const 
char *commit)
return 0;
 }
 
+static int do_clear_stash(void)
+{
+   struct object_id obj;
+   if (get_oid(ref_stash, ))
+   return 0;
+
+   return delete_ref(NULL, ref_stash, , 0);
+}
+
+static int clear_stash(int argc, const char **argv, const char *prefix)
+{
+   struct option options[] = {
+   OPT_END()
+   };
+
+   argc = parse_options(argc, argv, prefix, options, 
git_stash_helper_clear_usage, PARSE_OPT_STOP_AT_NON_OPTION);
+
+   if (argc != 0)
+   return error(_("git stash--helper clear with parameters is 
unimplemented"));
+
+   return do_clear_stash();
+}
+
 static int reset_tree(struct object_id i_tree, int update, int reset)
 {
struct unpack_trees_options opts;
@@ -313,6 +348,60 @@ static int apply_stash(int argc, const char **argv, const 
char *prefix)
return do_apply_stash(prefix, , index);
 }
 
+static int do_drop_stash(const char *prefix, struct stash_info *info)
+{
+   struct argv_array args = ARGV_ARRAY_INIT;
+   int ret;
+   struct child_process cp = CHILD_PROCESS_INIT;
+
+   argv_array_pushl(, "reflog", "delete", "--updateref", "--rewrite", 
NULL);
+   argv_array_push(, info->revision);
+   ret = cmd_reflog(args.argc, args.argv, prefix);
+   if (!ret) {
+   if (!quiet) {
+   printf(_("Dropped %s (%s)\n"), info->revision, 
sha1_to_hex(info->w_commit.hash));
+   }
+   } else {
+   return error(_("%s: Could not drop stash entry"), 
info->revision);
+   }
+
+   cp.git_cmd = 1;
+   /* Even though --quiet is specified, rev-parse still outputs the hash */
+   cp.no_stdout = 1;
+   argv_array_pushl(, "rev-parse", "--verify", "--quiet", NULL);
+   argv_array_pushf(, "%s@{0}", ref_stash);
+   ret = run_command();
+
+   if (ret)
+   do_clear_stash();
+
+   return 0;
+}
+
+static int drop_stash(int argc, const char **argv, const char *prefix)
+{
+   const char *commit = NULL;
+   struct stash_info info;
+   struct option options[] = {
+   OPT__QUIET(, N_("be quiet, only report errors")),
+   OPT_END()
+   };
+
+   argc = parse_options(argc, argv, prefix, options,
+   git_stash_helper_drop_usage, 0);
+
+   if (argc == 1)
+   commit = argv[0];
+
+   if (get_stash_info(, commit))
+   return -1;
+
+   if (!info.is_stash_ref)
+   return error(_("'%s' is not a stash reference"), commit);
+
+   return do_drop_stash(prefix, );
+}
+
 static int branch_stash(int argc, const char **argv, const char *prefix)
 {
const char *commit = NULL, *branch = NULL;
@@ -371,6 +460,10 @@ int cmd_stash__helper(int argc, const char **argv, const 
char *prefix)
usage_with_options(git_stash_helper_usage, options);
else if (!strcmp(argv[0], "apply"))
result = apply_stash(argc, argv, prefix);
+   else if (!strcmp(argv[0], "clear"))
+   result = clear_stash(argc, argv, prefix);
+   else if (!strcmp(argv[0], "drop"))
+   result = drop_stash(argc, argv, prefix);
else if (!strcmp(argv[0], "branch"))
result = branch_stash(argc, argv, prefix);
else {
diff --git a/git-stash.sh b/git-stash.sh
index 360643ad4e..54d0a6c21f 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -716,7 +716,7 @@ apply)
;;
 clear)
shift
-   clear_stash "$@"
+   git stash--helper clear "$@"
;;
 create)
shift
@@ -728,7 +728,7 @@ store)
;;
 drop)
shift
-   drop_stash "$@"
+   git stash--helper drop "$@"
;;
 pop)
shift
-- 
2.16.2



[PATCH 4/4] stash: convert pop to builtin

2018-03-24 Thread Joel Teichroeb
---
 builtin/stash--helper.c | 38 ++
 git-stash.sh|  3 ++-
 2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/builtin/stash--helper.c b/builtin/stash--helper.c
index 1598b82ac2..b912f84c97 100644
--- a/builtin/stash--helper.c
+++ b/builtin/stash--helper.c
@@ -12,6 +12,7 @@
 
 static const char * const git_stash_helper_usage[] = {
N_("git stash--helper drop [-q|--quiet] []"),
+   N_("git stash--helper pop [--index] [-q|--quiet] []"),
N_("git stash--helper apply [--index] [-q|--quiet] []"),
N_("git stash--helper branch  []"),
N_("git stash--helper clear"),
@@ -23,6 +24,11 @@ static const char * const git_stash_helper_drop_usage[] = {
NULL
 };
 
+static const char * const git_stash_helper_pop_usage[] = {
+   N_("git stash--helper pop [--index] [-q|--quiet] []"),
+   NULL
+};
+
 static const char * const git_stash_helper_apply_usage[] = {
N_("git stash--helper apply [--index] [-q|--quiet] []"),
NULL
@@ -402,6 +408,36 @@ static int drop_stash(int argc, const char **argv, const 
char *prefix)
return do_drop_stash(prefix, );
 }
 
+static int pop_stash(int argc, const char **argv, const char *prefix)
+{
+   int index = 0;
+   const char *commit = NULL;
+   struct stash_info info;
+   struct option options[] = {
+   OPT__QUIET(, N_("be quiet, only report errors")),
+   OPT_BOOL(0, "index", ,
+   N_("attempt to ininstate the index")),
+   OPT_END()
+   };
+
+   argc = parse_options(argc, argv, prefix, options,
+   git_stash_helper_pop_usage, 0);
+
+   if (argc == 1)
+   commit = argv[0];
+
+   if (get_stash_info(, commit))
+   return -1;
+
+   if (!info.is_stash_ref)
+   return error(_("'%s' is not a stash reference"), commit);
+
+   if (do_apply_stash(prefix, , index))
+   return -1;
+
+   return do_drop_stash(prefix, );
+}
+
 static int branch_stash(int argc, const char **argv, const char *prefix)
 {
const char *commit = NULL, *branch = NULL;
@@ -464,6 +500,8 @@ int cmd_stash__helper(int argc, const char **argv, const 
char *prefix)
result = clear_stash(argc, argv, prefix);
else if (!strcmp(argv[0], "drop"))
result = drop_stash(argc, argv, prefix);
+   else if (!strcmp(argv[0], "pop"))
+   result = pop_stash(argc, argv, prefix);
else if (!strcmp(argv[0], "branch"))
result = branch_stash(argc, argv, prefix);
else {
diff --git a/git-stash.sh b/git-stash.sh
index 54d0a6c21f..d595bbaf64 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -732,7 +732,8 @@ drop)
;;
 pop)
shift
-   pop_stash "$@"
+   cd "$START_DIR"
+   git stash--helper pop "$@"
;;
 branch)
shift
-- 
2.16.2



[PATCH 1/4] stash: convert apply to builtin

2018-03-24 Thread Joel Teichroeb
---
 .gitignore  |   1 +
 Makefile|   1 +
 builtin.h   |   1 +
 builtin/stash--helper.c | 339 
 git-stash.sh|   3 +-
 git.c   |   1 +
 6 files changed, 345 insertions(+), 1 deletion(-)
 create mode 100644 builtin/stash--helper.c

diff --git a/.gitignore b/.gitignore
index 833ef3b0b7..296d5f376d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -152,6 +152,7 @@
 /git-show-ref
 /git-stage
 /git-stash
+/git-stash--helper
 /git-status
 /git-stripspace
 /git-submodule
diff --git a/Makefile b/Makefile
index a1d8775adb..8ca361c57a 100644
--- a/Makefile
+++ b/Makefile
@@ -1020,6 +1020,7 @@ BUILTIN_OBJS += builtin/send-pack.o
 BUILTIN_OBJS += builtin/shortlog.o
 BUILTIN_OBJS += builtin/show-branch.o
 BUILTIN_OBJS += builtin/show-ref.o
+BUILTIN_OBJS += builtin/stash--helper.o
 BUILTIN_OBJS += builtin/stripspace.o
 BUILTIN_OBJS += builtin/submodule--helper.o
 BUILTIN_OBJS += builtin/symbolic-ref.o
diff --git a/builtin.h b/builtin.h
index 42378f3aa4..a14fd85b0e 100644
--- a/builtin.h
+++ b/builtin.h
@@ -219,6 +219,7 @@ extern int cmd_shortlog(int argc, const char **argv, const 
char *prefix);
 extern int cmd_show(int argc, const char **argv, const char *prefix);
 extern int cmd_show_branch(int argc, const char **argv, const char *prefix);
 extern int cmd_status(int argc, const char **argv, const char *prefix);
+extern int cmd_stash__helper(int argc, const char **argv, const char *prefix);
 extern int cmd_stripspace(int argc, const char **argv, const char *prefix);
 extern int cmd_submodule__helper(int argc, const char **argv, const char 
*prefix);
 extern int cmd_symbolic_ref(int argc, const char **argv, const char *prefix);
diff --git a/builtin/stash--helper.c b/builtin/stash--helper.c
new file mode 100644
index 00..e9a9574f40
--- /dev/null
+++ b/builtin/stash--helper.c
@@ -0,0 +1,339 @@
+#include "builtin.h"
+#include "config.h"
+#include "parse-options.h"
+#include "refs.h"
+#include "lockfile.h"
+#include "cache-tree.h"
+#include "unpack-trees.h"
+#include "merge-recursive.h"
+#include "argv-array.h"
+#include "run-command.h"
+#include "dir.h"
+
+static const char * const git_stash_helper_usage[] = {
+   N_("git stash--helper apply [--index] [-q|--quiet] []"),
+   NULL
+};
+
+static const char * const git_stash_helper_apply_usage[] = {
+   N_("git stash--helper apply [--index] [-q|--quiet] []"),
+   NULL
+};
+
+static const char *ref_stash = "refs/stash";
+static int quiet;
+static char stash_index_path[PATH_MAX];
+
+struct stash_info {
+   struct object_id w_commit;
+   struct object_id b_commit;
+   struct object_id i_commit;
+   struct object_id u_commit;
+   struct object_id w_tree;
+   struct object_id b_tree;
+   struct object_id i_tree;
+   struct object_id u_tree;
+   const char *message;
+   const char *revision;
+   int is_stash_ref;
+   int has_u;
+   const char *patch;
+};
+
+static int get_stash_info(struct stash_info *info, const char *commit)
+{
+   struct strbuf w_commit_rev = STRBUF_INIT;
+   struct strbuf b_commit_rev = STRBUF_INIT;
+   struct strbuf w_tree_rev = STRBUF_INIT;
+   struct strbuf b_tree_rev = STRBUF_INIT;
+   struct strbuf i_tree_rev = STRBUF_INIT;
+   struct strbuf u_tree_rev = STRBUF_INIT;
+   struct strbuf commit_buf = STRBUF_INIT;
+   struct strbuf symbolic = STRBUF_INIT;
+   struct strbuf out = STRBUF_INIT;
+   int ret;
+   const char *revision = commit;
+   char *end_of_rev;
+   struct child_process cp = CHILD_PROCESS_INIT;
+   info->is_stash_ref = 0;
+
+   if (commit == NULL) {
+   strbuf_addf(_buf, "%s@{0}", ref_stash);
+   revision = commit_buf.buf;
+   } else if (strspn(commit, "0123456789") == strlen(commit)) {
+   strbuf_addf(_buf, "%s@{%s}", ref_stash, commit);
+   revision = commit_buf.buf;
+   }
+   info->revision = revision;
+
+   strbuf_addf(_commit_rev, "%s", revision);
+   strbuf_addf(_commit_rev, "%s^1", revision);
+   strbuf_addf(_tree_rev, "%s:", revision);
+   strbuf_addf(_tree_rev, "%s^1:", revision);
+   strbuf_addf(_tree_rev, "%s^2:", revision);
+
+   ret = !get_oid(w_commit_rev.buf, >w_commit) &&
+   !get_oid(b_commit_rev.buf, >b_commit) &&
+   !get_oid(w_tree_rev.buf, >w_tree) &&
+   !get_oid(b_tree_rev.buf, >b_tree) &&
+   !get_oid(i_tree_rev.buf, >i_tree);
+
+   strbuf_release(_commit_rev);
+   strbuf_release(_commit_rev);
+   strbuf_release(_tree_rev);
+   strbuf_release(_tree_rev);
+   strbuf_release(_tree_rev);
+
+   if (!ret)
+   return error(_("%s is not a valid reference"), revision);
+
+   strbuf_addf(_tree_rev, "%s^3:", revision);
+
+   info->has_u = !get_oid(u_tree_rev.buf, >u_tree);
+
+   strbuf_release(_tree_rev);
+
+   

Re: [PATCH v4 2/3] builtin/branch: give more useful error messages when renaming

2018-03-24 Thread Kaartic Sivaraam
On Friday 16 March 2018 02:03 AM, Junio C Hamano wrote:
> Quite honestly, I am not sure if this amount of new code that
> results in sentence lego is really worth it.

Speaking specifically about the new code for the sentence lego: I
currently lack knowledge of a better way to achieve the same outcome the
new code does. Let me know if there is a better way.


> Is it so wrong for
> "branch -m tset master" to complain that master already exists so no
> branch can be renamed to it?
>

Speaking in general about the patch itself: though I still find the fact
that "the error about an inexistent source branch seconds the error
about an existing destination branch" to be a little unintuitive, I
actually went on to reboot this after a long time as this also seems to
bring consistency in the error messages related to moving a branch. It
seems that the commit message requires an update as it currently seems
to be misleading as it currently doesn't specify the motivation completely.

That said, I won't be against dropping the patch if it seems to be
adding less value at the cost of more code.

-- 
Kaartic



signature.asc
Description: OpenPGP digital signature


[PATCH 4/3] sha1_name: use bsearch_pack() in unique_in_pack()

2018-03-24 Thread René Scharfe
Replace the custom binary search in unique_in_pack() with a call to
bsearch_pack().  This reduces code duplication and makes use of the
fan-out table of packs.

Signed-off-by: Rene Scharfe 
---
This is basically the same replacement as done by patch 3.  Speed is
less of a concern here -- at least I don't know a commonly used
command that needs to resolve lots of short hashes.

 sha1_name.c | 21 ++---
 1 file changed, 2 insertions(+), 19 deletions(-)

diff --git a/sha1_name.c b/sha1_name.c
index 24894b3dbe..0185c6081a 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -150,31 +150,14 @@ static int match_sha(unsigned len, const unsigned char 
*a, const unsigned char *
 static void unique_in_pack(struct packed_git *p,
   struct disambiguate_state *ds)
 {
-   uint32_t num, last, i, first = 0;
+   uint32_t num, i, first = 0;
const struct object_id *current = NULL;
 
if (open_pack_index(p) || !p->num_objects)
return;
 
num = p->num_objects;
-   last = num;
-   while (first < last) {
-   uint32_t mid = first + (last - first) / 2;
-   const unsigned char *current;
-   int cmp;
-
-   current = nth_packed_object_sha1(p, mid);
-   cmp = hashcmp(ds->bin_pfx.hash, current);
-   if (!cmp) {
-   first = mid;
-   break;
-   }
-   if (cmp > 0) {
-   first = mid+1;
-   continue;
-   }
-   last = mid;
-   }
+   bsearch_pack(>bin_pfx, p, );
 
/*
 * At this point, "first" is the location of the lowest object
-- 
2.16.3


Re: [RFC PATCH 1/1] json-writer: incorrect format specifier

2018-03-24 Thread Ramsay Jones


On 24/03/18 15:14, Ramsay Jones wrote:
> 
> 
> On 24/03/18 05:37, Wink Saville wrote:
>> In routines jw_object_uint64 and jw_object_double strbuf_addf is
>> invoked with strbuf_addf(>json, ":%"PRIuMAX, value) where value
>> is a uint64_t. This causes a compile error on OSX.
>>
>> The correct format specifier is PRIu64 instead of PRIuMax.
>>
>> Signed-off-by: Wink Saville 
>> ---
>>  json-writer.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/json-writer.c b/json-writer.c
>> index 89a6abb57..04045448a 100644
>> --- a/json-writer.c
>> +++ b/json-writer.c
>> @@ -120,7 +120,7 @@ void jw_object_uint64(struct json_writer *jw, const char 
>> *key, uint64_t value)
>>  maybe_add_comma(jw);
>>  
>>  append_quoted_string(>json, key);
>> -strbuf_addf(>json, ":%"PRIuMAX, value);
>> +strbuf_addf(>json, ":%"PRIu64, value);
> 
> In this code-base, that would normally be written as:
> 
>   strbuf_addf(>json, ":%"PRIuMAX, (uintmax_t) value);

heh, I should learn not to reply in a hurry, just before
going out ...

I had not noticed that 'value' was declared with an 'sized type'
of uint64_t, so using PRIu64 should be fine. Well, except that
you may have to add a 'fallback' definition of PRIu64 to one of
the 'compat/mingw.h', 'compat/msvc.h' or 'git-compat-util.h'
header files. (see e.g. PRId64 at compat/mingw.h:429).

[About a decade ago, I heard microsoft were implementing C99
'real soon now' ;-) ]

ATB,
Ramsay Jones




hello

2018-03-24 Thread Miss Mariel
Am Miss. Mariel. i work in one of the prime bank here in Burkina
Faso, i want the bank to transfer the money left by our  late customer
is a foreigner from Korea. can you invest this money  and also help the
poor'  the amount value at  $13,300,000.00  (Thirteen Million Three
Hundred Thousand United States American Dollars), left in his account
still unclaimed. more details will be given to you if you are
interested. contact me here (77147missmar...@swissmail.com )
You’re faithful 
 Miss. Mariel





Re: [RFC PATCH 1/1] json-writer: incorrect format specifier

2018-03-24 Thread Ramsay Jones


On 24/03/18 05:37, Wink Saville wrote:
> In routines jw_object_uint64 and jw_object_double strbuf_addf is
> invoked with strbuf_addf(>json, ":%"PRIuMAX, value) where value
> is a uint64_t. This causes a compile error on OSX.
> 
> The correct format specifier is PRIu64 instead of PRIuMax.
> 
> Signed-off-by: Wink Saville 
> ---
>  json-writer.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/json-writer.c b/json-writer.c
> index 89a6abb57..04045448a 100644
> --- a/json-writer.c
> +++ b/json-writer.c
> @@ -120,7 +120,7 @@ void jw_object_uint64(struct json_writer *jw, const char 
> *key, uint64_t value)
>   maybe_add_comma(jw);
>  
>   append_quoted_string(>json, key);
> - strbuf_addf(>json, ":%"PRIuMAX, value);
> + strbuf_addf(>json, ":%"PRIu64, value);

In this code-base, that would normally be written as:

strbuf_addf(>json, ":%"PRIuMAX, (uintmax_t) value);

ATB,
Ramsay Jones


**Herzlichen Glückwunsch**

2018-03-24 Thread Euro Millions
Herzlichen Glückwunsch, Sie haben 650.000 Euro in den monatlichen Gewinnspielen 
von Euro Millions/Google Promo am 10. März 2018 gewonnen.

Kontaktieren Sie unseren Schadenregulierungsbeauftragten mit den folgenden 
Informationen

Vollständiger Name
Heimatadresse
Geschlecht
Alter
Telefon

Mr.Pianese Germano



Re: [PATCH] completion: add option completion for most builtin commands

2018-03-24 Thread Duy Nguyen
On Thu, Mar 22, 2018 at 6:56 PM, Junio C Hamano  wrote:
> Duy Nguyen  writes:
>
>> +__git_main_with_parseopt_helper='
>> + blame cat-file check-attr check-ignore
>> + check-mailmap checkout-index column count-objects fast-export
>> + hash-object index-pack interpret-trailers merge-file mktree
>> + pack-objects pack-refs prune prune-packed read-tree repack
>> + send-pack show-ref stripspace symbolic-ref update-index
>> + update-ref verify-commit verify-tag write-tree
>> +'
>> +__git_complete_command() {
>> + local command="$1"
>> + local completion_func="_git_${command//-/_}"
>> + if declare -f $completion_func >/dev/null 2>/dev/null; then
>> + $completion_func
>> + elif echo $__git_main_with_parseopt_helper | git grep -w "$command" 
>> >/dev/null; then
>
> "git grep"???
>
> I imagined that you'd keep an associative shell array (we are not
> constrained by POSIX here) that can be used like so
>
> elif test -n "${__git_main_with_parseopt_helper[$command]}"; then

Nope. We are not constrained by POSIX, but MacOS still runs the
ancient bash 3.x while associative arrays are in 4.x
-- 
Duy


Re: [PATCH v2 00/36] Combine t/helper binaries into a single one

2018-03-24 Thread Duy Nguyen
On Sat, Mar 24, 2018 at 1:50 PM, Ævar Arnfjörð Bjarmason
 wrote:
>
> On Sat, Mar 24 2018, Nguyễn Thái Ngọc Duy wrote:
>
>> v2 fixes a couple of typos in commit messages and use the cmd__ prefix
>> for test commands instead of test_, which avoids a naming conflict
>> with the existing function test_lazy_init_name_hash
>>
>> [the previous v2 send out was aborted because I messed it up with some
>> other patches]
>
> This whole thing looks good to me, and I've applied it to my own build
> and run several modes (normal, split index etc.) of the test suite with
> it. Didn't get any problems.
>
> Micronit: If you M-x sort-lines (and I assume similar in other editors
> that have a function to sort stuff in ASCII order) the test-tool.c list
> you get this diff on top:
>
> diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
> index cd5e28b045..c38939b93e 100644
> --- a/t/helper/test-tool.c
> +++ b/t/helper/test-tool.c
> @@ -32,8 +32,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 },
>
> I think it makes sense to keep such lists in ASCII order (" before -)
> for subsequent edits where one or more things are added to the list and
> then sorted before submission.

Yeah, my brain just failed to see that sha1-array should be behind
sha1. Bad brain!
-- 
Duy


[PATCH v2] Makefile: detect compiler and enable more warnings in DEVELOPER=1

2018-03-24 Thread Nguyễn Thái Ngọc Duy
The set of extra warnings we enable when DEVELOPER has to be
conservative because we can't assume any compiler version the
developer may use. Detect the compiler version so we know when it's
safe to enable -Wextra and maybe more.

These warning settings are mostly from my custom config.mak a long
time ago when I tried to enable as many warnings as possible that can
still build without showing warnings. Some of them those warnings are
probably worth fixing instead of just suppressing in future.

Helped-by: Jeff King 
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 v2 improves a bit over v1:

 - apple clang support (though I suspect we may want to make it a
   separate compiler family since apple clang has different
   versioning, but I can't and won't work on that front)

 - support CC='ccache gcc' (yes it breaks now if you have spaces in
   your cc path)

 - allow to skip detect-compiler by setting COMPILER_FEATURES in
   config.mak

 I notice Ramsay is working on clean -Wmaybe-uninitialized, if his
 series is merged first I'll stop disabling it here.

 Interdiff

diff --git a/Makefile b/Makefile
index 9dfd152a1e..04b2a39bab 100644
--- a/Makefile
+++ b/Makefile
@@ -434,6 +434,10 @@ all::
 #
 # When cross-compiling, define HOST_CPU as the canonical name of the CPU on
 # which the built Git will run (for instance "x86_64").
+#
+# Define DEVELOPER to enable more compiler warnings. Compiler version
+# and faimily are auto detected, but could be overridden by defining
+# COMPILER_FEATURES (see config.mak.dev)
 
 GIT-VERSION-FILE: FORCE
@$(SHELL_PATH) ./GIT-VERSION-GEN
diff --git a/config.mak.dev b/config.mak.dev
index 59aef342c4..d8beaf9347 100644
--- a/config.mak.dev
+++ b/config.mak.dev
@@ -8,7 +8,9 @@ CFLAGS += -Wstrict-prototypes
 CFLAGS += -Wunused
 CFLAGS += -Wvla
 
+ifndef COMPILER_FEATURES
 COMPILER_FEATURES := $(shell ./detect-compiler $(CC))
+endif
 
 ifneq ($(filter clang4,$(COMPILER_FEATURES)),)
 CFLAGS += -Wtautological-constant-out-of-range-compare
diff --git a/detect-compiler b/detect-compiler
index bc2ea39ef5..70b754481c 100755
--- a/detect-compiler
+++ b/detect-compiler
@@ -9,7 +9,7 @@ CC="$*"
 #
 # FreeBSD clang version 3.4.1 (tags/RELEASE...)
 get_version_line() {
-   "$CC" -v 2>&1 | grep ' version '
+   $CC -v 2>&1 | grep ' version '
 }
 
 get_family() {
@@ -38,12 +38,15 @@ case "$(get_family)" in
 gcc)
print_flags gcc
;;
-*clang)
+clang)
print_flags clang
;;
 "FreeBSD clang")
print_flags clang
;;
+"Apple LLVM")
+   print_flags clang
+   ;;
 *)
: unknown compiler family
;;

 Makefile| 15 +-
 config.mak.dev  | 30 
 detect-compiler | 53 +
 3 files changed, 88 insertions(+), 10 deletions(-)
 create mode 100644 config.mak.dev
 create mode 100755 detect-compiler

diff --git a/Makefile b/Makefile
index a1d8775adb..04b2a39bab 100644
--- a/Makefile
+++ b/Makefile
@@ -434,6 +434,10 @@ all::
 #
 # When cross-compiling, define HOST_CPU as the canonical name of the CPU on
 # which the built Git will run (for instance "x86_64").
+#
+# Define DEVELOPER to enable more compiler warnings. Compiler version
+# and faimily are auto detected, but could be overridden by defining
+# COMPILER_FEATURES (see config.mak.dev)
 
 GIT-VERSION-FILE: FORCE
@$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -442,15 +446,6 @@ GIT-VERSION-FILE: FORCE
 # CFLAGS and LDFLAGS are for the users to override from the command line.
 
 CFLAGS = -g -O2 -Wall
-DEVELOPER_CFLAGS = -Werror \
-   -Wdeclaration-after-statement \
-   -Wno-format-zero-length \
-   -Wold-style-definition \
-   -Woverflow \
-   -Wpointer-arith \
-   -Wstrict-prototypes \
-   -Wunused \
-   -Wvla
 LDFLAGS =
 ALL_CFLAGS = $(CPPFLAGS) $(CFLAGS)
 ALL_LDFLAGS = $(LDFLAGS)
@@ -1051,7 +1046,7 @@ include config.mak.uname
 -include config.mak
 
 ifdef DEVELOPER
-CFLAGS += $(DEVELOPER_CFLAGS)
+include config.mak.dev
 endif
 
 comma := ,
diff --git a/config.mak.dev b/config.mak.dev
new file mode 100644
index 00..d8beaf9347
--- /dev/null
+++ b/config.mak.dev
@@ -0,0 +1,30 @@
+CFLAGS += -Werror
+CFLAGS += -Wdeclaration-after-statement
+CFLAGS += -Wno-format-zero-length
+CFLAGS += -Wold-style-definition
+CFLAGS += -Woverflow
+CFLAGS += -Wpointer-arith
+CFLAGS += -Wstrict-prototypes
+CFLAGS += -Wunused
+CFLAGS += -Wvla
+
+ifndef COMPILER_FEATURES
+COMPILER_FEATURES := $(shell ./detect-compiler $(CC))
+endif
+
+ifneq ($(filter clang4,$(COMPILER_FEATURES)),)
+CFLAGS += -Wtautological-constant-out-of-range-compare
+endif
+
+ifneq ($(or $(filter gcc6,$(COMPILER_FEATURES)),$(filter 
clang4,$(COMPILER_FEATURES))),)
+CFLAGS += -Wextra
+CFLAGS += 

Re: [PATCH v2 00/36] Combine t/helper binaries into a single one

2018-03-24 Thread Ævar Arnfjörð Bjarmason

On Sat, Mar 24 2018, Nguyễn Thái Ngọc Duy wrote:

> v2 fixes a couple of typos in commit messages and use the cmd__ prefix
> for test commands instead of test_, which avoids a naming conflict
> with the existing function test_lazy_init_name_hash
>
> [the previous v2 send out was aborted because I messed it up with some
> other patches]

This whole thing looks good to me, and I've applied it to my own build
and run several modes (normal, split index etc.) of the test suite with
it. Didn't get any problems.

Micronit: If you M-x sort-lines (and I assume similar in other editors
that have a function to sort stuff in ASCII order) the test-tool.c list
you get this diff on top:

diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index cd5e28b045..c38939b93e 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -32,8 +32,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 },

I think it makes sense to keep such lists in ASCII order (" before -)
for subsequent edits where one or more things are added to the list and
then sorted before submission.


Re: [PATCH v7 06/13] pack-objects: move in_pack out of struct object_entry

2018-03-24 Thread Duy Nguyen
On Sat, Mar 24, 2018 at 10:42 AM, Ævar Arnfjörð Bjarmason
 wrote:
>
> On Sat, Mar 24 2018, Nguyễn Thái Ngọc Duy wrote:
>
>> + if (pack->in_pack_by_idx) {
>> + if (p->index <= 0)
>> + die("BUG: found_pack should be NULL "
>> + "instead of having non-positive 
>> index");
>> + e->in_pack_idx = p->index;
>> + } else
>
> The indentation after the die() here is wrong. GCC complaining about it:
>
> ./pack-objects.h: In function ‘oe_set_in_pack’:
> ./pack-objects.h:203:3: warning: this ‘if’ clause does not guard... 
> [-Wmisleading-indentation]
>if (p->index <= 0)
>^~
> ./pack-objects.h:206:4: note: ...this statement, but the latter is 
> misleadingly indented as if it were guarded by the ‘if’
> e->in_pack_idx = p->index;
> ^

Thanks. My gcc reported the same thing but only when not used with ccache, hm...
-- 
Duy


Re: [PATCH v4 3/7] gc: add --keep-largest-pack option

2018-03-24 Thread Duy Nguyen
On Sat, Mar 24, 2018 at 10:36 AM, Ævar Arnfjörð Bjarmason
 wrote:
>
> On Sat, Mar 24 2018, Nguyễn Thái Ngọc Duy wrote:
>
>>   struct option builtin_gc_options[] = {
>>   OPT__QUIET(, N_("suppress progress reporting")),
>> @@ -362,6 +390,8 @@ int cmd_gc(int argc, const char **argv, const char 
>> *prefix)
>>   OPT_BOOL(0, "aggressive", , N_("be more thorough 
>> (increased runtime)")),
>>   OPT_BOOL(0, "auto", _gc, N_("enable auto-gc mode")),
>>   OPT_BOOL(0, "force", , N_("force running gc even if 
>> there may be another gc running")),
>> + OPT_BOOL(0, "keep-largest-pack", _base_pack,
>> +  N_("repack all other packs except the largest pack")),
>>   OPT_END()
>>   };
>
> This conflicts with master because of your own 7e1eeaa431 ("completion:
> use __gitcomp_builtin in _git_gc", 2018-02-09). I pushed out a
> avar-pclouds/gc-auto-keep-base-pack branch to github.com/avar/git which
> resolves it as:
>
> @@ -365,6 +393,8 @@ int cmd_gc(int argc, const char **argv, const char 
> *prefix)
> OPT_BOOL_F(0, "force", ,
>N_("force running gc even if there may be 
> another gc running"),
>PARSE_OPT_NOCOMPLETE),
> +   OPT_BOOL(0, "keep-largest-pack", _base_pack,
> +N_("repack all other packs except the largest 
> pack")),
> OPT_END()
> };
>
> I assume that's the intention here.

Yeah, I want  to keep the same base for easy interdiff. There are
worse conflicts are with the other series I'm helping Stefan.
-- 
Duy


Re: [PATCH v7 06/13] pack-objects: move in_pack out of struct object_entry

2018-03-24 Thread Ævar Arnfjörð Bjarmason

On Sat, Mar 24 2018, Nguyễn Thái Ngọc Duy wrote:

> Instead of using 8 bytes (on 64 bit arch) to store a pointer to a
> pack. Use an index instead since the number of packs should be
> relatively small.
>
> This limits the number of packs we can handle to 1k. Since we can't be
> sure people can never run into the situation where they have more than
> 1k pack files. Provide a fall back route for it.
>
> If we find out they have too many packs, the new in_pack_by_idx[]
> array (which has at most 1k elements) will not be used. Instead we
> allocate in_pack[] array that holds nr_objects elements. This is
> similar to how the optional in_pack_pos field is handled.
>
> The new simple test is just to make sure the too-many-packs code path
> is at least executed. The true test is running
>
> make test GIT_TEST_FULL_IN_PACK_ARRAY=1

Aside from the tiny nit in 87efk9yfm2@evledraar.gmail.com this looks
good to me.

I've tested this with the same method noted in
87vadpxv27@evledraar.gmail.com against the version before it on
similar test data, and got:

 * Reduction in user time by 0.42%
 * Reduction in system time by 3.17%
 * Reduction in RSS by 0.003209%
 * Reduction in page faults by 0% & 0.006539% (time(1) reports two different 
numbers)
 * Reduction in the I of I/O by 99.504132% (note: from 4840 bytes to 24 bytes, 
so some fluke...)
 * Reduction in the O of I/O by 0%

I.e. there's no notable change at all, but I thought it would be useful
to re-run this for context.


Re: [GSoC] Re: Info: git log --oneline improvements

2018-03-24 Thread Christian Couder
Hi,

On Sat, Mar 24, 2018 at 9:41 AM, Pratik Karki  wrote:
>
> Hi Christian and Johannes,
>
> Though I sent a mail earlier, saying I would like to submit another
> proposal, I am now skeptical on re-writing another proposal as you
> guys are only available mentor for GSoC

Well Stefan Beller wrote in

https://public-inbox.org/git/cagz79kax5hip1wp3u60im__dm0gvh8nnd+byxg5oxmxrrkr...@mail.gmail.com/

that he would be ok to co-mentor, but I am not sure which projects he
would be ok to co-mentor. I just Cc'ed him so he can tell us more.

> and I believe Git doesn't
> select more than 2 proposals.

Yeah, because mentoring is a lot of work, and doesn't always work out
as well as we would expect, (mostly because it is difficult to explain
to new contributors that review cycles for significant patch series
take a lot more time than they could imagine), so not many people
volunteer to mentor or co-mentor.

I still hope though that over time some former GSoC student will
become (co-)mentors as this happens quite often in other projects that
participates in the GSoC.

Best,
Christian.


Re: [RFC PATCH 1/1] json-writer: incorrect format specifier

2018-03-24 Thread Jeff Hostetler



On 3/24/2018 1:37 AM, Wink Saville wrote:

In routines jw_object_uint64 and jw_object_double strbuf_addf is
invoked with strbuf_addf(>json, ":%"PRIuMAX, value) where value
is a uint64_t. This causes a compile error on OSX.

The correct format specifier is PRIu64 instead of PRIuMax.

Signed-off-by: Wink Saville 


That's odd.

A grep on the Git source tree did not find a "PRIu64" symbol.
Searching public-inbox only found one message [1] talking about it
(other than the ones associated with your messages here).

I have to wonder if that is defined in a OSX header file and
you're getting it from there [2].  (I don't have a MAC in front of
me, so I can't verify what's in that header.)  But [2] defines
PRIuMAX as PRIu64, so we shouldn't need to make that change in
json-writer -- unless something is getting lost in the #ifdefs.

Could you double check this in the header files on your system?
Any chance you are doing a 32-bit build?

Thanks
Jeff

[1] 
https://public-inbox.org/git/mwhpr21mb0478181ae0b64901da2c07cdf4...@mwhpr21mb0478.namprd21.prod.outlook.com/raw


[2] https://opensource.apple.com/source/gcc/gcc-926/inttypes.h.auto.html



---
  json-writer.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/json-writer.c b/json-writer.c
index 89a6abb57..04045448a 100644
--- a/json-writer.c
+++ b/json-writer.c
@@ -120,7 +120,7 @@ void jw_object_uint64(struct json_writer *jw, const char 
*key, uint64_t value)
maybe_add_comma(jw);
  
  	append_quoted_string(>json, key);

-   strbuf_addf(>json, ":%"PRIuMAX, value);
+   strbuf_addf(>json, ":%"PRIu64, value);
  }
  
  void jw_object_double(struct json_writer *jw, const char *fmt,

@@ -225,7 +225,7 @@ void jw_array_uint64(struct json_writer *jw, uint64_t value)
assert_in_array(jw);
maybe_add_comma(jw);
  
-	strbuf_addf(>json, "%"PRIuMAX, value);

+   strbuf_addf(>json, "%"PRIu64, value);
  }
  
  void jw_array_double(struct json_writer *jw, const char *fmt, double value)




Re: [RFC] [GSoC] Project proposal: convert scripts to builtins

2018-03-24 Thread Christian Couder
Hi,

On Wed, Mar 21, 2018 at 7:16 AM, Pratik Karki  wrote:
>
> Thanks for the feedback. Thanks to you, I realized my proposal was
> a bit ambitious. Both git-stash and git-rebase are big
> commitment. After much analyzing, I found out I cannot complete
> both in the given time frame. So, I decided to stick to one and
> complete it.

Great.

[...]

> There has been some development in `git-stash` as seen on
> []
> (https://public-inbox.org/git/20171110231314.30711-1-j...@teichroeb.net/).
> To maximize the productivity, the findings from the patch submitted can
> be used. Since, there are already much discussions regarding the
> rewrite.

In general it would be nice if you summarized what has already been
done, how you can reuse it and what is needed to complete it.

I see that you talk about some of that below, but a more general
overview might be nice too.

It could be interesting also to put the author(s) of the work that you
will reuse in Cc.

[...]

> Timeline and Development Cycle
> --
>
> -   Apr 23: Accepted student proposals announced.
>
> -   Apr 23 onwards: Researching of all the test suites. Discussion of
> possible test improvements in for `git-stash`.
>
> Firstly, the test suite coverage of every command will be reviewed
> using gcov and kcov.

I don't think it is necessary to spend a lot of time on the test suite coverage.

> The test suite might not be perfect or
> comprehensive but must cover all the major code paths and
> command-line switches of the script. For the tests which seem
> inadequate, minimum required tests are written and developed
> incrementally. The minimum tests must provide safety net for
> migration of scripts to built-ins. The tests would be sent as a
> separate patch for parallel development and review process so that
> development of built-ins can happen at the same time productively.

Nice.

> The tests will be written for every code changes and will be worked
> throughout the summer.
>
> -   May 1: Rewriting skeleton begins.
>
> The shell scripts are translated on a line-by-line basis into C
> code. The C code will be written in a way to maximize the use of git
> internal API. In git-stash `parse-options` API can be used for
> implementing parsing argument of command-line. This would be way
> better than parsing via the scripts. Firstly, I will start
> implementing `stash --helper`from respective scripts to C code. Then
> increment it further more. Then I'll start converting git-stash.sh
> on a line-by-line basis.

Not sure what you mean by line-by-line basis.

>  Again for git-stash some work seem to be done
> 
> []
> (https://public-inbox.org/git/20171110231314.30711-1-j...@teichroeb.net/).
> Now, to maximize the output I'll be taking findings from the
> previous patch and use it for my patch. As seen from the comments in
> the patch some tests for checking branch when `git stash branch`
> fails needs to be written.

Nice. Maybe writing those tests can come earlier in you schedule.

> New tests will be written and code
> coverage tools will be used for the written code.

Not sure that code coverage tools need to be used.

> -   May 13: Making minimal `builtin/stash.c` with `stash--helper` ready
> for review process. (This goes on for some time.)
>
> The initial review of minimal builtin would be ready for git-stash.
> The result C code at this stage may not be necessarily be efficient
> but would be free from obvious bugs and can serve as a baseline for
> the final patch. This is sent for review process which can take some
> time. The code will ofcourse be tested using the test suite with
> some additional tests.

How does that relates with the existing work? Will this be one or
several patch series? What will each patch do?

[...]

> -   June 10 - Jul 20: Start optimizing `builtin/stash.c`. Benchmarking
> and profiling is done. They are exclusively compared to their
> original shell scripts, to check whether they are more performant or
> not and the results are published in the mailing list for further
> discussion.

Will the performance tests be added to the t/perf tests?

> The C code will be optimized for speed and efficiency in this stage. The
> built-ins will now be profiled using the new efficient test suites to
> find hot spots. Bench-marking is also done in comparison to original
> scripts.The performance for stash can be measured by making it stash
> large number of changes in another working directory and measuring the
> time for completion of the task. After finding out, a graphical
> representation of performance findings will be published to git mailing
> list and discussions will commence on more 

[PATCH v3] git-svn: allow empty email-address using authors-prog and authors-file

2018-03-24 Thread Andreas Heiduk
The email address in --authors-file and --authors-prog can be empty but
git-svn translated it into a fictional email address in the form

jondoe 

containing the SVN repository UUID. Now git-svn behaves like git-commit:
If the email is *explicitly* set to the empty string using '<>', the
commit does not contain an email address, only the name:

jondoe <>

Allowing to remove the email address *intentionally* prevents automatic
systems from sending emails to those fictional addresses and avoids
cluttering the log output with unnecessary stuff.

Signed-off-by: Andreas Heiduk 
---
 Documentation/git-svn.txt   |  8 +---
 perl/Git/SVN.pm | 13 ++---
 t/t9130-git-svn-authors-file.sh | 14 ++
 t/t9138-git-svn-authors-prog.sh | 25 -
 4 files changed, 49 insertions(+), 11 deletions(-)

diff --git a/Documentation/git-svn.txt b/Documentation/git-svn.txt
index b858374649..d59379ee23 100644
--- a/Documentation/git-svn.txt
+++ b/Documentation/git-svn.txt
@@ -635,7 +635,8 @@ config key: svn.findcopiesharder
 
 -A::
 --authors-file=::
-   Syntax is compatible with the file used by 'git cvsimport':
+   Syntax is compatible with the file used by 'git cvsimport' but
+   an empty email address can be supplied with '<>':
 +
 
loginname = Joe User 
@@ -654,8 +655,9 @@ config key: svn.authorsfile
If this option is specified, for each SVN committer name that
does not exist in the authors file, the given file is executed
with the committer name as the first argument.  The program is
-   expected to return a single line of the form "Name ",
-   which will be treated as if included in the authors file.
+   expected to return a single line of the form "Name " or
+   "Name <>", which will be treated as if included in the authors
+   file.
 +
 Due to historical reasons a relative 'filename' is first searched
 relative to the current directory for 'init' and 'clone' and relative
diff --git a/perl/Git/SVN.pm b/perl/Git/SVN.pm
index bc4eed3d75..945ca4db2b 100644
--- a/perl/Git/SVN.pm
+++ b/perl/Git/SVN.pm
@@ -1482,7 +1482,6 @@ sub call_authors_prog {
}
if ($author =~ /^\s*(.+?)\s*<(.*)>\s*$/) {
my ($name, $email) = ($1, $2);
-   $email = undef if length $2 == 0;
return [$name, $email];
} else {
die "Author: $orig_author: $::_authors_prog returned "
@@ -2020,8 +2019,8 @@ sub make_log_entry {
remove_username($full_url);
$log_entry{metadata} = "$full_url\@$r $uuid";
$log_entry{svm_revision} = $r;
-   $email ||= "$author\@$uuid";
-   $commit_email ||= "$author\@$uuid";
+   $email = "$author\@$uuid" unless defined $email;
+   $commit_email = "$author\@$uuid" unless defined $commit_email;
} elsif ($self->use_svnsync_props) {
my $full_url = canonicalize_url(
add_path_to_url( $self->svnsync->{url}, $self->path )
@@ -2029,15 +2028,15 @@ sub make_log_entry {
remove_username($full_url);
my $uuid = $self->svnsync->{uuid};
$log_entry{metadata} = "$full_url\@$rev $uuid";
-   $email ||= "$author\@$uuid";
-   $commit_email ||= "$author\@$uuid";
+   $email = "$author\@$uuid" unless defined $email;
+   $commit_email = "$author\@$uuid" unless defined $commit_email;
} else {
my $url = $self->metadata_url;
remove_username($url);
my $uuid = $self->rewrite_uuid || $self->ra->get_uuid;
$log_entry{metadata} = "$url\@$rev " . $uuid;
-   $email ||= "$author\@" . $uuid;
-   $commit_email ||= "$author\@" . $uuid;
+   $email = "$author\@$uuid" unless defined $email;
+   $commit_email = "$author\@$uuid" unless defined $commit_email;
}
$log_entry{name} = $name;
$log_entry{email} = $email;
diff --git a/t/t9130-git-svn-authors-file.sh b/t/t9130-git-svn-authors-file.sh
index 41264818cc..6af6daf461 100755
--- a/t/t9130-git-svn-authors-file.sh
+++ b/t/t9130-git-svn-authors-file.sh
@@ -108,6 +108,20 @@ test_expect_success !MINGW 'fresh clone with 
svn.authors-file in config' '
)
 '
 
+cat >> svn-authors <
+EOF
+
+test_expect_success 'authors-file imported user without email' '
+   svn_cmd mkdir -m aa/branches/ff --username ff "$svnrepo/aa/branches/ff" 
&&
+   (
+   cd aa-work &&
+   git svn fetch --authors-file=../svn-authors &&
+   git rev-list -1 --pretty=raw refs/remotes/origin/ff | \
+ grep "^author FFF FFF <> "
+   )
+   '
+
 test_debug 

Re: [PATCH v7 06/13] pack-objects: move in_pack out of struct object_entry

2018-03-24 Thread Ævar Arnfjörð Bjarmason

On Sat, Mar 24 2018, Nguyễn Thái Ngọc Duy wrote:

> + if (pack->in_pack_by_idx) {
> + if (p->index <= 0)
> + die("BUG: found_pack should be NULL "
> + "instead of having non-positive index");
> + e->in_pack_idx = p->index;
> + } else

The indentation after the die() here is wrong. GCC complaining about it:

./pack-objects.h: In function ‘oe_set_in_pack’:
./pack-objects.h:203:3: warning: this ‘if’ clause does not guard... 
[-Wmisleading-indentation]
   if (p->index <= 0)
   ^~
./pack-objects.h:206:4: note: ...this statement, but the latter is 
misleadingly indented as if it were guarded by the ‘if’
e->in_pack_idx = p->index;
^


Re: [PATCH v4 3/7] gc: add --keep-largest-pack option

2018-03-24 Thread Ævar Arnfjörð Bjarmason

On Sat, Mar 24 2018, Nguyễn Thái Ngọc Duy wrote:

>   struct option builtin_gc_options[] = {
>   OPT__QUIET(, N_("suppress progress reporting")),
> @@ -362,6 +390,8 @@ int cmd_gc(int argc, const char **argv, const char 
> *prefix)
>   OPT_BOOL(0, "aggressive", , N_("be more thorough 
> (increased runtime)")),
>   OPT_BOOL(0, "auto", _gc, N_("enable auto-gc mode")),
>   OPT_BOOL(0, "force", , N_("force running gc even if there 
> may be another gc running")),
> + OPT_BOOL(0, "keep-largest-pack", _base_pack,
> +  N_("repack all other packs except the largest pack")),
>   OPT_END()
>   };

This conflicts with master because of your own 7e1eeaa431 ("completion:
use __gitcomp_builtin in _git_gc", 2018-02-09). I pushed out a
avar-pclouds/gc-auto-keep-base-pack branch to github.com/avar/git which
resolves it as:

@@ -365,6 +393,8 @@ int cmd_gc(int argc, const char **argv, const char 
*prefix)
OPT_BOOL_F(0, "force", ,
   N_("force running gc even if there may be 
another gc running"),
   PARSE_OPT_NOCOMPLETE),
+   OPT_BOOL(0, "keep-largest-pack", _base_pack,
+N_("repack all other packs except the largest 
pack")),
OPT_END()
};

I assume that's the intention here.


Re: [GSOC]About the microproject related to CI

2018-03-24 Thread Christian Couder
Hi,

On Fri, Mar 23, 2018 at 2:44 AM, Zhibin Li <08826794b...@gmail.com> wrote:
> Hi all,
>
> I'm Zhibin Li, an undergraduate from China and I'm interested in automated
> testing. Since the application deadline is coming, hope it's not too late
> for me to start with the microproject.

As the Student Application Period ends on March 27, I think there are
very few chances that your microproject and your proposal will get
advanced enough at the end of the period for you to be selected. You
can still try if you really want though.

> If it's ok, I would like to take Git
> CI Improvements 4 as my starting point. But the description on the website
> shows less details so I wonder what am I supposed to do more specifically?

It looks like the CI improvements 4 is:

install CVS on the build machines to run t94?? and t96?? tests
install SVN on the build machines to run t91?? tests
install Apache Web Server to run 5539, 5550, and 5561

So it seems to me that you should create a patch that changes:

https://github.com/git/git/blob/master/.travis.yml

so that the testing machines will have some software installed that is
required to run some tests.

See:

e7e9f5e7a1 (travis-ci: enable Git SVN tests t91xx on Linux, 2016-05-19), and

https://public-inbox.org/git/20180305200400.3769-1-sidm1...@gmail.com/

for example.

> Reporting the results or trying to figure out the how and why those results
> come out independently? It would be nice if you guys can tell me about any
> details.

No this is not about the results of the tests.


[GSoC] Re: Info: git log --oneline improvements

2018-03-24 Thread Pratik Karki

Hi Christian and Johannes,

Though I sent a mail earlier, saying I would like to submit another
proposal, I am now skeptical on re-writing another proposal as you
guys are only available mentor for GSoC and I believe Git doesn't
select more than 2 proposals. Hence, I will try to update my previous
proposal[1] and make it more worthy. Can you review it and explain
what I might be lacking there? Thank you for your time.


[1]: 
https://public-inbox.org/git/20180321061605.27814-1-predatoram...@gmail.com/

Cheers,
Pratik Karki


Re: [PATCH v2] Allow use of TLS 1.3

2018-03-24 Thread Loganaden Velvindron
On Sat, Mar 24, 2018 at 2:04 AM, Junio C Hamano  wrote:
> Daniel Stenberg  writes:
>
>> On Fri, 23 Mar 2018, Loganaden Velvindron wrote:
>>
>>> +#ifdef CURL_SSLVERSION_TLSv1_3
>>> +{ "tlsv1.3", CURL_SSLVERSION_TLSv1_3 }
>>> +#endif
>>
>> Unfortunately, CURL_SSLVERSION_TLSv1_3 is an enum so this construct
>> won't work.
>>
>> Also, let me just point out that 7.52.0 is 0x073400 in hex and not the
>> one used for the first version of this patch.
>

It's working with tls 1.3:

ldd for curl (showing linking to openssl 1.1.1 pre2 preview):
 ldd /usr/local/bin/curl
linux-vdso.so.1 (0x7ffd30599000)
libcurl.so.4 => /usr/local/lib/libcurl.so.4 (0x7f5a81845000)
libssl.so.1.1 => /usr/local/lib/libssl.so.1.1 (0x7f5a815b5000)
libcrypto.so.1.1 => /usr/local/lib/libcrypto.so.1.1 (0x7f5a810dd000)
libz.so.1 => /usr/lib/libz.so.1 (0x7f5a80ec6000)
libpthread.so.0 => /usr/lib/libpthread.so.0 (0x7f5a80ca7000)
libc.so.6 => /usr/lib/libc.so.6 (0x7f5a808f2000)
libnghttp2.so.14 => /usr/lib/libnghttp2.so.14 (0x7f5a806cd000)
libdl.so.2 => /usr/lib/libdl.so.2 (0x7f5a804c9000)
/lib/ld-linux-x86-64.so.2 (0x7f5a81ce5000)

handshake failure against a tls 1.2 server:

GIT_SSL_VERSION=tlsv1.3 ./git clone https://github.com/shuque/pydig
Cloning into 'pydig'...
warning: templates not found /usr/local/share/git-core/templates
fatal: unable to access 'https://github.com/shuque/pydig/':
error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake
failure

With a local server running nginx using only tls 1.3 (had to disable
ssl verification due to self-signed cert):
GIT_SSL_NO_VERIFY=true GIT_SSL_VERSION=tlsv1.2 ./git clone
https://192.168.1.214/git_test
error:1409442E:SSL routines:ssl3_read_bytes:tlsv1 alert protocol version


Now with TLS 1.3, it works:
GIT_SSL_NO_VERIFY=true GIT_SSL_VERSION=tlsv1.3 ./git clone
https://192.168.1.214/git_test



> Thanks!


Re: [GSoC] Info: git log --oneline improvements

2018-03-24 Thread Christian Couder
Hi,

On Sat, Mar 24, 2018 at 5:32 AM, Pratik Karki  wrote:
>
> Hi Christian and Johannes,
>
> I will like to send another proposal on git log --oneline improvements.
> My first proposal[1] was on "Convert scripts to builtins". Can
> you provide me information about "git log --online improvements"
> and point me to resources where I should focus on my proposal.

On the Idea page (https://git.github.io/SoC-2018-Ideas/) there are the
following links:

https://public-inbox.org/git/xmqqeg42fslw@gitster.mtv.corp.google.com/T/#t
http://public-inbox.org/git/ca+55afwt2hubzzo8gpt9thojtdrxv9oe3tdosh5jceoixrn...@mail.gmail.com/

so a good idea to start writing a proposal would be to summarize the
possible improvements that are discussed in these threads.

Thanks.


[PATCH v2 05/36] t/helper: merge test-config into test-tool

2018-03-24 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Makefile  |  2 +-
 t/helper/test-config.c|  5 +++--
 t/helper/test-tool.c  |  1 +
 t/helper/test-tool.h  |  1 +
 t/t1305-config-include.sh |  2 +-
 t/t1308-config-set.sh | 22 +++---
 t/t1309-early-config.sh   | 12 ++--
 7 files changed, 24 insertions(+), 21 deletions(-)

diff --git a/Makefile b/Makefile
index 31287cedf2..227f16ad17 100644
--- a/Makefile
+++ b/Makefile
@@ -653,11 +653,11 @@ X =
 PROGRAMS += $(patsubst %.o,git-%$X,$(PROGRAM_OBJS))
 
 TEST_BUILTINS_OBJS += test-chmtime.o
+TEST_BUILTINS_OBJS += test-config.o
 TEST_BUILTINS_OBJS += test-lazy-init-name-hash.o
 TEST_BUILTINS_OBJS += test-sha1.o
 
 TEST_PROGRAMS_NEED_X += test-ctype
-TEST_PROGRAMS_NEED_X += test-config
 TEST_PROGRAMS_NEED_X += test-date
 TEST_PROGRAMS_NEED_X += test-delta
 TEST_PROGRAMS_NEED_X += test-drop-caches
diff --git a/t/helper/test-config.c b/t/helper/test-config.c
index 1a7b8bd3d6..214003d5b2 100644
--- a/t/helper/test-config.c
+++ b/t/helper/test-config.c
@@ -1,3 +1,4 @@
+#include "test-tool.h"
 #include "cache.h"
 #include "config.h"
 #include "string-list.h"
@@ -32,7 +33,7 @@
  * Examples:
  *
  * To print the value with highest priority for key "foo.bAr Baz.rock":
- * test-config get_value "foo.bAr Baz.rock"
+ * test-tool config get_value "foo.bAr Baz.rock"
  *
  */
 
@@ -77,7 +78,7 @@ static int early_config_cb(const char *var, const char 
*value, void *vdata)
return 0;
 }
 
-int cmd_main(int argc, const char **argv)
+int cmd__config(int argc, const char **argv)
 {
int i, val;
const char *v;
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index afc7a518d6..e8d6c6b9eb 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -8,6 +8,7 @@ struct test_cmd {
 
 static struct test_cmd cmds[] = {
{ "chmtime", cmd__chmtime },
+   { "config", cmd__config },
{ "lazy-init-name-hash", cmd__lazy_init_name_hash },
{ "sha1", cmd__sha1 },
 };
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index 1dc4673c3a..3084f458a0 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -2,6 +2,7 @@
 #define __TEST_TOOL_H__
 
 int cmd__chmtime(int argc, const char **argv);
+int cmd__config(int argc, const char **argv);
 int cmd__lazy_init_name_hash(int argc, const char **argv);
 int cmd__sha1(int argc, const char **argv);
 
diff --git a/t/t1305-config-include.sh b/t/t1305-config-include.sh
index d9d2f545a4..f035ee40a3 100755
--- a/t/t1305-config-include.sh
+++ b/t/t1305-config-include.sh
@@ -224,7 +224,7 @@ test_expect_success 'conditional include, early config 
reading' '
echo "[includeIf \"gitdir:foo/\"]path=bar6" >>.git/config &&
echo "[test]six=6" >.git/bar6 &&
echo 6 >expect &&
-   test-config read_early_config test.six >actual &&
+   test-tool config read_early_config test.six >actual &&
test_cmp expect actual
)
 '
diff --git a/t/t1308-config-set.sh b/t/t1308-config-set.sh
index bafed5c9b8..3e00d1af01 100755
--- a/t/t1308-config-set.sh
+++ b/t/t1308-config-set.sh
@@ -18,7 +18,7 @@ check_config () {
then
printf "%s\n" "$@"
fi >expect &&
-   test_expect_code $expect_code test-config "$op" "$key" >actual &&
+   test_expect_code $expect_code test-tool config "$op" "$key" >actual &&
test_cmp expect actual
 }
 
@@ -125,7 +125,7 @@ test_expect_success 'find string value for a key' '
 '
 
 test_expect_success 'check line error when NULL string is queried' '
-   test_expect_code 128 test-config get_string case.foo 2>result &&
+   test_expect_code 128 test-tool config get_string case.foo 2>result &&
test_i18ngrep "fatal: .*case\.foo.*\.git/config.*line 7" result
 '
 
@@ -155,13 +155,13 @@ test_expect_success 'find value from a configset' '
baz = ball
EOF
echo silk >expect &&
-   test-config configset_get_value my.new config2 .git/config >actual &&
+   test-tool config configset_get_value my.new config2 .git/config >actual 
&&
test_cmp expect actual
 '
 
 test_expect_success 'find value with highest priority from a configset' '
echo hask >expect &&
-   test-config configset_get_value case.baz config2 .git/config >actual &&
+   test-tool config configset_get_value case.baz config2 .git/config 
>actual &&
test_cmp expect actual
 '
 
@@ -173,20 +173,20 @@ test_expect_success 'find value_list for a key from a 
configset' '
lama
ball
EOF
-   test-config configset_get_value case.baz config2 .git/config >actual &&
+   test-tool config configset_get_value case.baz config2 .git/config 
>actual &&
test_cmp expect actual
 '
 
 test_expect_success 'proper error on non-existent files' '
echo "Error (-1) reading configuration file non-existent-file." >expect 
&&
-   

[PATCH v2 04/36] t/helper: merge test-lazy-init-name-hash into test-tool

2018-03-24 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Makefile|  2 +-
 t/helper/test-lazy-init-name-hash.c | 13 +++--
 t/helper/test-tool.c|  1 +
 t/helper/test-tool.h|  1 +
 t/perf/p0004-lazy-init-name-hash.sh |  8 
 t/t3008-ls-files-lazy-init-name-hash.sh |  2 +-
 6 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/Makefile b/Makefile
index 3c0d0474af..31287cedf2 100644
--- a/Makefile
+++ b/Makefile
@@ -653,6 +653,7 @@ X =
 PROGRAMS += $(patsubst %.o,git-%$X,$(PROGRAM_OBJS))
 
 TEST_BUILTINS_OBJS += test-chmtime.o
+TEST_BUILTINS_OBJS += test-lazy-init-name-hash.o
 TEST_BUILTINS_OBJS += test-sha1.o
 
 TEST_PROGRAMS_NEED_X += test-ctype
@@ -669,7 +670,6 @@ TEST_PROGRAMS_NEED_X += test-fake-ssh
 TEST_PROGRAMS_NEED_X += test-genrandom
 TEST_PROGRAMS_NEED_X += test-hashmap
 TEST_PROGRAMS_NEED_X += test-index-version
-TEST_PROGRAMS_NEED_X += test-lazy-init-name-hash
 TEST_PROGRAMS_NEED_X += test-line-buffer
 TEST_PROGRAMS_NEED_X += test-match-trees
 TEST_PROGRAMS_NEED_X += test-mergesort
diff --git a/t/helper/test-lazy-init-name-hash.c 
b/t/helper/test-lazy-init-name-hash.c
index 297fb01d61..b99a37080d 100644
--- a/t/helper/test-lazy-init-name-hash.c
+++ b/t/helper/test-lazy-init-name-hash.c
@@ -1,3 +1,4 @@
+#include "test-tool.h"
 #include "cache.h"
 #include "parse-options.h"
 
@@ -184,14 +185,14 @@ static void analyze_run(void)
}
 }
 
-int cmd_main(int argc, const char **argv)
+int cmd__lazy_init_name_hash(int argc, const char **argv)
 {
const char *usage[] = {
-   "test-lazy-init-name-hash -d (-s | -m)",
-   "test-lazy-init-name-hash -p [-c c]",
-   "test-lazy-init-name-hash -a a [--step s] [-c c]",
-   "test-lazy-init-name-hash (-s | -m) [-c c]",
-   "test-lazy-init-name-hash -s -m [-c c]",
+   "test-tool lazy-init-name-hash -d (-s | -m)",
+   "test-tool lazy-init-name-hash -p [-c c]",
+   "test-tool lazy-init-name-hash -a a [--step s] [-c c]",
+   "test-tool lazy-init-name-hash (-s | -m) [-c c]",
+   "test-tool lazy-init-name-hash -s -m [-c c]",
NULL
};
struct option options[] = {
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index 7a9bb9f140..afc7a518d6 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -8,6 +8,7 @@ struct test_cmd {
 
 static struct test_cmd cmds[] = {
{ "chmtime", cmd__chmtime },
+   { "lazy-init-name-hash", cmd__lazy_init_name_hash },
{ "sha1", cmd__sha1 },
 };
 
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index a05b8bd14c..1dc4673c3a 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -2,6 +2,7 @@
 #define __TEST_TOOL_H__
 
 int cmd__chmtime(int argc, const char **argv);
+int cmd__lazy_init_name_hash(int argc, const char **argv);
 int cmd__sha1(int argc, const char **argv);
 
 #endif
diff --git a/t/perf/p0004-lazy-init-name-hash.sh 
b/t/perf/p0004-lazy-init-name-hash.sh
index 8de5a98cfc..1afc08fe7f 100755
--- a/t/perf/p0004-lazy-init-name-hash.sh
+++ b/t/perf/p0004-lazy-init-name-hash.sh
@@ -7,8 +7,8 @@ test_perf_large_repo
 test_checkout_worktree
 
 test_expect_success 'verify both methods build the same hashmaps' '
-   test-lazy-init-name-hash --dump --single >out.single &&
-   if test-lazy-init-name-hash --dump --multi >out.multi
+   test-tool lazy-init-name-hash --dump --single >out.single &&
+   if test-tool lazy-init-name-hash --dump --multi >out.multi
then
test_set_prereq REPO_BIG_ENOUGH_FOR_MULTI &&
sort sorted.single &&
@@ -46,11 +46,11 @@ test_expect_success 'calibrate' '
 '
 
 test_perf "single-threaded, $desc" "
-   test-lazy-init-name-hash --single --count=$count
+   test-tool lazy-init-name-hash --single --count=$count
 "
 
 test_perf REPO_BIG_ENOUGH_FOR_MULTI "multi-threaded, $desc" "
-   test-lazy-init-name-hash --multi --count=$count
+   test-tool lazy-init-name-hash --multi --count=$count
 "
 
 test_done
diff --git a/t/t3008-ls-files-lazy-init-name-hash.sh 
b/t/t3008-ls-files-lazy-init-name-hash.sh
index bdf5198b7e..8df4aa7c99 100755
--- a/t/t3008-ls-files-lazy-init-name-hash.sh
+++ b/t/t3008-ls-files-lazy-init-name-hash.sh
@@ -21,7 +21,7 @@ test_expect_success 'no buffer overflow in 
lazy_init_name_hash' '
) |
sed "s/^/100644 $EMPTY_BLOB /" |
git update-index --index-info &&
-   test-lazy-init-name-hash -m
+   test-tool lazy-init-name-hash -m
 '
 
 test_done
-- 
2.17.0.rc0.348.gd5a49e0b6f



[PATCH v2 03/36] t/helper: merge test-sha1 into test-tool

2018-03-24 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Documentation/howto/recover-corrupted-object-harder.txt | 2 +-
 Makefile| 4 ++--
 t/helper/test-sha1.c| 3 ++-
 t/helper/test-sha1.sh   | 4 ++--
 t/helper/test-tool.c| 1 +
 t/helper/test-tool.h| 1 +
 t/lib-pack.sh   | 2 +-
 t/t0013-sha1dc.sh   | 2 +-
 8 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/Documentation/howto/recover-corrupted-object-harder.txt 
b/Documentation/howto/recover-corrupted-object-harder.txt
index 9c4cd0915f..8994e2559e 100644
--- a/Documentation/howto/recover-corrupted-object-harder.txt
+++ b/Documentation/howto/recover-corrupted-object-harder.txt
@@ -80,7 +80,7 @@ valid pack like:
 # now add our object data
 cat object >>tmp.pack
 # and then append the pack trailer
-/path/to/git.git/test-sha1 -b trailer
+/path/to/git.git/t/helper/test-tool sha1 -b trailer
 cat trailer >>tmp.pack
 
 
diff --git a/Makefile b/Makefile
index 416a8e39c1..3c0d0474af 100644
--- a/Makefile
+++ b/Makefile
@@ -653,6 +653,7 @@ X =
 PROGRAMS += $(patsubst %.o,git-%$X,$(PROGRAM_OBJS))
 
 TEST_BUILTINS_OBJS += test-chmtime.o
+TEST_BUILTINS_OBJS += test-sha1.o
 
 TEST_PROGRAMS_NEED_X += test-ctype
 TEST_PROGRAMS_NEED_X += test-config
@@ -684,7 +685,6 @@ TEST_PROGRAMS_NEED_X += test-regex
 TEST_PROGRAMS_NEED_X += test-revision-walking
 TEST_PROGRAMS_NEED_X += test-run-command
 TEST_PROGRAMS_NEED_X += test-scrap-cache-tree
-TEST_PROGRAMS_NEED_X += test-sha1
 TEST_PROGRAMS_NEED_X += test-sha1-array
 TEST_PROGRAMS_NEED_X += test-sigchain
 TEST_PROGRAMS_NEED_X += test-strcmp-offset
@@ -2502,7 +2502,7 @@ t/helper/test-tool$X: $(patsubst 
%,t/helper/%,$(TEST_BUILTINS_OBJS))
 t/helper/test-%$X: t/helper/test-%.o GIT-LDFLAGS $(GITLIBS)
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) 
$(filter %.a,$^) $(LIBS)
 
-check-sha1:: t/helper/test-sha1$X
+check-sha1:: t/helper/test-tool$X
t/helper/test-sha1.sh
 
 SP_OBJ = $(patsubst %.o,%.sp,$(C_OBJ))
diff --git a/t/helper/test-sha1.c b/t/helper/test-sha1.c
index a1c13f54ec..1ba0675c75 100644
--- a/t/helper/test-sha1.c
+++ b/t/helper/test-sha1.c
@@ -1,6 +1,7 @@
+#include "test-tool.h"
 #include "cache.h"
 
-int cmd_main(int ac, const char **av)
+int cmd__sha1(int ac, const char **av)
 {
git_SHA_CTX ctx;
unsigned char sha1[20];
diff --git a/t/helper/test-sha1.sh b/t/helper/test-sha1.sh
index 750b95a0a1..84594885c7 100755
--- a/t/helper/test-sha1.sh
+++ b/t/helper/test-sha1.sh
@@ -1,7 +1,7 @@
 #!/bin/sh
 
 dd if=/dev/zero bs=1048576 count=100 2>/dev/null |
-/usr/bin/time t/helper/test-sha1 >/dev/null
+/usr/bin/time t/helper/test-tool sha1 >/dev/null
 
 while read expect cnt pfx
 do
@@ -11,7 +11,7 @@ do
test -z "$pfx" || echo "$pfx"
dd if=/dev/zero bs=1048576 count=$cnt 2>/dev/null |
perl -pe 'y/\000/g/'
-   } | ./t/helper/test-sha1 $cnt
+   } | ./t/helper/test-tool sha1 $cnt
)
if test "$expect" = "$actual"
then
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index 63ec15cb56..7a9bb9f140 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -8,6 +8,7 @@ struct test_cmd {
 
 static struct test_cmd cmds[] = {
{ "chmtime", cmd__chmtime },
+   { "sha1", cmd__sha1 },
 };
 
 int cmd_main(int argc, const char **argv)
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index 3a35e70e79..a05b8bd14c 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -2,5 +2,6 @@
 #define __TEST_TOOL_H__
 
 int cmd__chmtime(int argc, const char **argv);
+int cmd__sha1(int argc, const char **argv);
 
 #endif
diff --git a/t/lib-pack.sh b/t/lib-pack.sh
index 7509846571..501078249d 100644
--- a/t/lib-pack.sh
+++ b/t/lib-pack.sh
@@ -85,7 +85,7 @@ pack_obj () {
 
 # Compute and append pack trailer to "$1"
 pack_trailer () {
-   test-sha1 -b <"$1" >trailer.tmp &&
+   test-tool sha1 -b <"$1" >trailer.tmp &&
cat trailer.tmp >>"$1" &&
rm -f trailer.tmp
 }
diff --git a/t/t0013-sha1dc.sh b/t/t0013-sha1dc.sh
index 6d655cb161..419f31a8f7 100755
--- a/t/t0013-sha1dc.sh
+++ b/t/t0013-sha1dc.sh
@@ -11,7 +11,7 @@ then
 fi
 
 test_expect_success 'test-sha1 detects shattered pdf' '
-   test_must_fail test-sha1 <"$TEST_DATA/shattered-1.pdf" 2>err &&
+   test_must_fail test-tool sha1 <"$TEST_DATA/shattered-1.pdf" 2>err &&
test_i18ngrep collision err &&
grep 38762cf7f55934b34d179ae6a4c80cadccbb7f0a err
 '
-- 
2.17.0.rc0.348.gd5a49e0b6f



[PATCH v2 21/36] t/helper: merge test-prio-queue into test-tool

2018-03-24 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Makefile   | 2 +-
 t/helper/test-prio-queue.c | 3 ++-
 t/helper/test-tool.c   | 1 +
 t/helper/test-tool.h   | 1 +
 t/t0009-prio-queue.sh  | 6 +++---
 5 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/Makefile b/Makefile
index 751ea6cad7..076c778494 100644
--- a/Makefile
+++ b/Makefile
@@ -670,6 +670,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-prio-queue.o
 TEST_BUILTINS_OBJS += test-sha1.o
 
 TEST_PROGRAMS_NEED_X += test-dump-fsmonitor
@@ -677,7 +678,6 @@ 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
-TEST_PROGRAMS_NEED_X += test-prio-queue
 TEST_PROGRAMS_NEED_X += test-read-cache
 TEST_PROGRAMS_NEED_X += test-write-cache
 TEST_PROGRAMS_NEED_X += test-ref-store
diff --git a/t/helper/test-prio-queue.c b/t/helper/test-prio-queue.c
index ae58fff359..9807b649b1 100644
--- a/t/helper/test-prio-queue.c
+++ b/t/helper/test-prio-queue.c
@@ -1,3 +1,4 @@
+#include "test-tool.h"
 #include "cache.h"
 #include "prio-queue.h"
 
@@ -16,7 +17,7 @@ static void show(int *v)
free(v);
 }
 
-int cmd_main(int argc, const char **argv)
+int cmd__prio_queue(int argc, const char **argv)
 {
struct prio_queue pq = { intcmp };
 
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index 4c985074b7..be5f784865 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -25,6 +25,7 @@ static struct test_cmd cmds[] = {
{ "mktemp", cmd__mktemp },
{ "online-cpus", cmd__online_cpus },
{ "path-utils", cmd__path_utils },
+   { "prio-queue", cmd__prio_queue },
{ "sha1", cmd__sha1 },
 };
 
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index 3b7ced01f5..900c96dc02 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -19,6 +19,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__prio_queue(int argc, const char **argv);
 int cmd__sha1(int argc, const char **argv);
 
 #endif
diff --git a/t/t0009-prio-queue.sh b/t/t0009-prio-queue.sh
index 94045c3fad..e56dfce668 100755
--- a/t/t0009-prio-queue.sh
+++ b/t/t0009-prio-queue.sh
@@ -17,7 +17,7 @@ cat >expect <<'EOF'
 10
 EOF
 test_expect_success 'basic ordering' '
-   test-prio-queue 2 6 3 10 9 5 7 4 5 8 1 dump >actual &&
+   test-tool prio-queue 2 6 3 10 9 5 7 4 5 8 1 dump >actual &&
test_cmp expect actual
 '
 
@@ -30,7 +30,7 @@ cat >expect <<'EOF'
 6
 EOF
 test_expect_success 'mixed put and get' '
-   test-prio-queue 6 2 4 get 5 3 get get 1 dump >actual &&
+   test-tool prio-queue 6 2 4 get 5 3 get get 1 dump >actual &&
test_cmp expect actual
 '
 
@@ -43,7 +43,7 @@ NULL
 NULL
 EOF
 test_expect_success 'notice empty queue' '
-   test-prio-queue 1 2 get get get 1 2 get get get >actual &&
+   test-tool prio-queue 1 2 get get get 1 2 get get get >actual &&
test_cmp expect actual
 '
 
-- 
2.17.0.rc0.348.gd5a49e0b6f



[PATCH v2 19/36] t/helper: merge test-online-cpus into test-tool

2018-03-24 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Makefile| 2 +-
 t/helper/test-online-cpus.c | 3 ++-
 t/helper/test-tool.c| 1 +
 t/helper/test-tool.h| 1 +
 t/t3008-ls-files-lazy-init-name-hash.sh | 2 +-
 5 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index 3145a9b1b2..91af906d08 100644
--- a/Makefile
+++ b/Makefile
@@ -668,13 +668,13 @@ TEST_BUILTINS_OBJS += test-lazy-init-name-hash.o
 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-sha1.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-online-cpus
 TEST_PROGRAMS_NEED_X += test-parse-options
 TEST_PROGRAMS_NEED_X += test-path-utils
 TEST_PROGRAMS_NEED_X += test-prio-queue
diff --git a/t/helper/test-online-cpus.c b/t/helper/test-online-cpus.c
index 06c09c6b88..8cb0d53840 100644
--- a/t/helper/test-online-cpus.c
+++ b/t/helper/test-online-cpus.c
@@ -1,7 +1,8 @@
+#include "test-tool.h"
 #include "git-compat-util.h"
 #include "thread-utils.h"
 
-int cmd_main(int argc, const char **argv)
+int cmd__online_cpus(int argc, const char **argv)
 {
printf("%d\n", online_cpus());
return 0;
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index fd3bf560d4..8f78d61b68 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -23,6 +23,7 @@ static struct test_cmd cmds[] = {
{ "match-trees", cmd__match_trees },
{ "mergesort", cmd__mergesort },
{ "mktemp", cmd__mktemp },
+   { "online-cpus", cmd__online_cpus },
{ "sha1", cmd__sha1 },
 };
 
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index cf2598798a..aeabc9740f 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -17,6 +17,7 @@ int cmd__lazy_init_name_hash(int argc, const char **argv);
 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__sha1(int argc, const char **argv);
 
 #endif
diff --git a/t/t3008-ls-files-lazy-init-name-hash.sh 
b/t/t3008-ls-files-lazy-init-name-hash.sh
index 8df4aa7c99..08af596ba6 100755
--- a/t/t3008-ls-files-lazy-init-name-hash.sh
+++ b/t/t3008-ls-files-lazy-init-name-hash.sh
@@ -4,7 +4,7 @@ test_description='Test the lazy init name hash with various 
folder structures'
 
 . ./test-lib.sh
 
-if test 1 -eq $($GIT_BUILD_DIR/t/helper/test-online-cpus)
+if test 1 -eq $($GIT_BUILD_DIR/t/helper/test-tool online-cpus)
 then
skip_all='skipping lazy-init tests, single cpu'
test_done
-- 
2.17.0.rc0.348.gd5a49e0b6f



[PATCH v2 11/36] t/helper: merge test-dump-split-index into test-tool

2018-03-24 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Makefile |  2 +-
 t/helper/test-dump-split-index.c |  3 +-
 t/helper/test-tool.c |  1 +
 t/helper/test-tool.h |  1 +
 t/t0090-cache-tree.sh|  4 +--
 t/t1700-split-index.sh   | 48 
 6 files changed, 31 insertions(+), 28 deletions(-)

diff --git a/Makefile b/Makefile
index 991bafa6fb..8993cec274 100644
--- a/Makefile
+++ b/Makefile
@@ -659,11 +659,11 @@ 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-split-index.o
 TEST_BUILTINS_OBJS += test-lazy-init-name-hash.o
 TEST_BUILTINS_OBJS += test-sha1.o
 
 TEST_PROGRAMS_NEED_X += test-dump-fsmonitor
-TEST_PROGRAMS_NEED_X += test-dump-split-index
 TEST_PROGRAMS_NEED_X += test-dump-untracked-cache
 TEST_PROGRAMS_NEED_X += test-example-decorate
 TEST_PROGRAMS_NEED_X += test-fake-ssh
diff --git a/t/helper/test-dump-split-index.c b/t/helper/test-dump-split-index.c
index e44430b699..4e2fdb5e30 100644
--- a/t/helper/test-dump-split-index.c
+++ b/t/helper/test-dump-split-index.c
@@ -1,3 +1,4 @@
+#include "test-tool.h"
 #include "cache.h"
 #include "split-index.h"
 #include "ewah/ewok.h"
@@ -7,7 +8,7 @@ static void show_bit(size_t pos, void *data)
printf(" %d", (int)pos);
 }
 
-int cmd_main(int ac, const char **av)
+int cmd__dump_split_index(int ac, const char **av)
 {
struct split_index *si;
int i;
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index 3d8d9ed1ce..26ae209cd5 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-split-index", cmd__dump_split_index },
{ "lazy-init-name-hash", cmd__lazy_init_name_hash },
{ "sha1", cmd__sha1 },
 };
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index 2a0d034adf..e8363e851f 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -8,6 +8,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_split_index(int argc, const char **argv);
 int cmd__lazy_init_name_hash(int argc, const char **argv);
 int cmd__sha1(int argc, const char **argv);
 
diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh
index f81e3deead..3266209e41 100755
--- a/t/t0090-cache-tree.sh
+++ b/t/t0090-cache-tree.sh
@@ -246,9 +246,9 @@ test_expect_success 'switching trees does not invalidate 
shared index' '
git update-index --split-index &&
>split &&
git add split &&
-   test-dump-split-index .git/index | grep -v ^own >before &&
+   test-tool dump-split-index .git/index | grep -v ^own >before &&
git commit -m "as-is" &&
-   test-dump-split-index .git/index | grep -v ^own >after &&
+   test-tool dump-split-index .git/index | grep -v ^own >after &&
test_cmp before after
 '
 
diff --git a/t/t1700-split-index.sh b/t/t1700-split-index.sh
index b778975de8..ec179fbaf7 100755
--- a/t/t1700-split-index.sh
+++ b/t/t1700-split-index.sh
@@ -11,7 +11,7 @@ sane_unset GIT_FSMONITOR_TEST
 test_expect_success 'enable split index' '
git config splitIndex.maxPercentChange 100 &&
git update-index --split-index &&
-   test-dump-split-index .git/index >actual &&
+   test-tool dump-split-index .git/index >actual &&
indexversion=$(test-index-version <.git/index) &&
if test "$indexversion" = "4"
then
@@ -39,7 +39,7 @@ test_expect_success 'add one file' '
EOF
test_cmp ls-files.expect ls-files.actual &&
 
-   test-dump-split-index .git/index | sed "/^own/d" >actual &&
+   test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
cat >expect <<-EOF &&
base $base
100644 $EMPTY_BLOB 0one
@@ -57,8 +57,8 @@ test_expect_success 'disable split index' '
EOF
test_cmp ls-files.expect ls-files.actual &&
 
-   BASE=$(test-dump-split-index .git/index | grep "^own" | sed 
"s/own/base/") &&
-   test-dump-split-index .git/index | sed "/^own/d" >actual &&
+   BASE=$(test-tool dump-split-index .git/index | grep "^own" | sed 
"s/own/base/") &&
+   test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
cat >expect <<-EOF &&
not a split index
EOF
@@ -73,7 +73,7 @@ test_expect_success 'enable split index again, "one" now 
belongs to base index"'
EOF
test_cmp ls-files.expect ls-files.actual &&
 
-   test-dump-split-index .git/index | sed "/^own/d" >actual &&
+   test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
   

[PATCH v2 10/36] t/helper: merge test-dump-cache-tree into test-tool

2018-03-24 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Makefile| 2 +-
 t/helper/test-dump-cache-tree.c | 3 ++-
 t/helper/test-tool.c| 1 +
 t/helper/test-tool.h| 1 +
 t/t0090-cache-tree.sh   | 6 +++---
 t/t1700-split-index.sh  | 2 +-
 6 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/Makefile b/Makefile
index edd9c43982..991bafa6fb 100644
--- a/Makefile
+++ b/Makefile
@@ -658,10 +658,10 @@ TEST_BUILTINS_OBJS += test-ctype.o
 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-lazy-init-name-hash.o
 TEST_BUILTINS_OBJS += test-sha1.o
 
-TEST_PROGRAMS_NEED_X += test-dump-cache-tree
 TEST_PROGRAMS_NEED_X += test-dump-fsmonitor
 TEST_PROGRAMS_NEED_X += test-dump-split-index
 TEST_PROGRAMS_NEED_X += test-dump-untracked-cache
diff --git a/t/helper/test-dump-cache-tree.c b/t/helper/test-dump-cache-tree.c
index ebf3aab22d..98a4891f1d 100644
--- a/t/helper/test-dump-cache-tree.c
+++ b/t/helper/test-dump-cache-tree.c
@@ -1,3 +1,4 @@
+#include "test-tool.h"
 #include "cache.h"
 #include "tree.h"
 #include "cache-tree.h"
@@ -54,7 +55,7 @@ static int dump_cache_tree(struct cache_tree *it,
return errs;
 }
 
-int cmd_main(int ac, const char **av)
+int cmd__dump_cache_tree(int ac, const char **av)
 {
struct index_state istate;
struct cache_tree *another = cache_tree();
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index b6f648d387..3d8d9ed1ce 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -13,6 +13,7 @@ static struct test_cmd cmds[] = {
{ "date", cmd__date },
{ "delta", cmd__delta },
{ "drop-caches", cmd__drop_caches },
+   { "dump-cache-tree", cmd__dump_cache_tree },
{ "lazy-init-name-hash", cmd__lazy_init_name_hash },
{ "sha1", cmd__sha1 },
 };
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index f585b7776e..2a0d034adf 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -7,6 +7,7 @@ int cmd__ctype(int argc, const char **argv);
 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__lazy_init_name_hash(int argc, const char **argv);
 int cmd__sha1(int argc, const char **argv);
 
diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh
index adfd4f0b5e..f81e3deead 100755
--- a/t/t0090-cache-tree.sh
+++ b/t/t0090-cache-tree.sh
@@ -8,13 +8,13 @@ cache-tree extension.
  . ./test-lib.sh
 
 cmp_cache_tree () {
-   test-dump-cache-tree | sed -e '/#(ref)/d' >actual &&
+   test-tool dump-cache-tree | sed -e '/#(ref)/d' >actual &&
sed "s/$_x40/SHA/" filtered &&
test_cmp "$1" filtered
 }
 
 # We don't bother with actually checking the SHA1:
-# test-dump-cache-tree already verifies that all existing data is
+# test-tool dump-cache-tree already verifies that all existing data is
 # correct.
 generate_expected_cache_tree_rec () {
dir="$1${1:+/}" &&
@@ -47,7 +47,7 @@ test_cache_tree () {
 
 test_invalid_cache_tree () {
printf "invalid  %s ()\n" "" "$@" 
>expect &&
-   test-dump-cache-tree |
+   test-tool dump-cache-tree |
sed -n -e "s/[0-9]* subtrees//" -e '/#(ref)/d' -e '/^invalid /p' 
>actual &&
test_cmp expect actual
 }
diff --git a/t/t1700-split-index.sh b/t/t1700-split-index.sh
index 4b5d443280..b778975de8 100755
--- a/t/t1700-split-index.sh
+++ b/t/t1700-split-index.sh
@@ -435,7 +435,7 @@ test_expect_success 'writing split index with null sha1 
does not write cache tre
commit=$(git commit-tree $tree -p HEAD cache-tree.out || true) &&
+   (test-tool dump-cache-tree >cache-tree.out || true) &&
test_line_count = 0 cache-tree.out
 '
 
-- 
2.17.0.rc0.348.gd5a49e0b6f



[PATCH v2 20/36] t/helper: merge test-path-utils into test-tool

2018-03-24 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Makefile   |  2 +-
 t/helper/test-path-utils.c |  3 +-
 t/helper/test-tool.c   |  1 +
 t/helper/test-tool.h   |  1 +
 t/lib-git-p4.sh|  2 +-
 t/t0060-path-utils.sh  | 60 +++---
 t/t1501-work-tree.sh   |  8 ++---
 7 files changed, 40 insertions(+), 37 deletions(-)

diff --git a/Makefile b/Makefile
index 91af906d08..751ea6cad7 100644
--- a/Makefile
+++ b/Makefile
@@ -669,6 +669,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-path-utils.o
 TEST_BUILTINS_OBJS += test-sha1.o
 
 TEST_PROGRAMS_NEED_X += test-dump-fsmonitor
@@ -676,7 +677,6 @@ 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
-TEST_PROGRAMS_NEED_X += test-path-utils
 TEST_PROGRAMS_NEED_X += test-prio-queue
 TEST_PROGRAMS_NEED_X += test-read-cache
 TEST_PROGRAMS_NEED_X += test-write-cache
diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c
index 2b3c5092a1..e115d44ac2 100644
--- a/t/helper/test-path-utils.c
+++ b/t/helper/test-path-utils.c
@@ -1,3 +1,4 @@
+#include "test-tool.h"
 #include "cache.h"
 #include "string-list.h"
 
@@ -170,7 +171,7 @@ static struct test_data dirname_data[] = {
{ NULL,  NULL }
 };
 
-int cmd_main(int argc, const char **argv)
+int cmd__path_utils(int argc, const char **argv)
 {
if (argc == 3 && !strcmp(argv[1], "normalize_path_copy")) {
char *buf = xmallocz(strlen(argv[2]));
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index 8f78d61b68..4c985074b7 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -24,6 +24,7 @@ static struct test_cmd cmds[] = {
{ "mergesort", cmd__mergesort },
{ "mktemp", cmd__mktemp },
{ "online-cpus", cmd__online_cpus },
+   { "path-utils", cmd__path_utils },
{ "sha1", cmd__sha1 },
 };
 
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index aeabc9740f..3b7ced01f5 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -18,6 +18,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__path_utils(int argc, const char **argv);
 int cmd__sha1(int argc, const char **argv);
 
 #endif
diff --git a/t/lib-git-p4.sh b/t/lib-git-p4.sh
index 54fd5a6ca0..c27599474c 100644
--- a/t/lib-git-p4.sh
+++ b/t/lib-git-p4.sh
@@ -39,7 +39,7 @@ native_path () {
then
path=$(cygpath --windows "$path")
else
-   path=$(test-path-utils real_path "$path")
+   path=$(test-tool path-utils real_path "$path")
fi &&
echo "$path"
 }
diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh
index 7ea2bb515b..f46e3c4995 100755
--- a/t/t0060-path-utils.sh
+++ b/t/t0060-path-utils.sh
@@ -8,15 +8,15 @@ test_description='Test various path utilities'
 . ./test-lib.sh
 
 norm_path() {
-   expected=$(test-path-utils print_path "$2")
+   expected=$(test-tool path-utils print_path "$2")
test_expect_success $3 "normalize path: $1 => $2" \
-   "test \"\$(test-path-utils normalize_path_copy '$1')\" = '$expected'"
+   "test \"\$(test-tool path-utils normalize_path_copy '$1')\" = 
'$expected'"
 }
 
 relative_path() {
-   expected=$(test-path-utils print_path "$3")
+   expected=$(test-tool path-utils print_path "$3")
test_expect_success $4 "relative path: $1 $2 => $3" \
-   "test \"\$(test-path-utils relative_path '$1' '$2')\" = '$expected'"
+   "test \"\$(test-tool path-utils relative_path '$1' '$2')\" = 
'$expected'"
 }
 
 test_submodule_relative_url() {
@@ -37,7 +37,7 @@ test_git_path() {
 # On Windows, we are using MSYS's bash, which mangles the paths.
 # Absolute paths are anchored at the MSYS installation directory,
 # which means that the path / accounts for this many characters:
-rootoff=$(test-path-utils normalize_path_copy / | wc -c)
+rootoff=$(test-tool path-utils normalize_path_copy / | wc -c)
 # Account for the trailing LF:
 if test $rootoff = 2; then
rootoff=# we are on Unix
@@ -46,7 +46,7 @@ else
# In MSYS2, the root directory "/" is translated into a Windows
# directory *with* trailing slash. Let's test for that and adjust
# our expected longest ancestor length accordingly.
-   case "$(test-path-utils print_path /)" in
+   case "$(test-tool path-utils print_path /)" in
*/) rootslash=1;;
*) rootslash=0;;
esac
@@ -61,7 +61,7 @@ ancestor() {
expected=$(($expected+$rootoff))
fi
test_expect_success "longest ancestor: $1 $2 => 

[PATCH v2 22/36] t/helper: merge test-read-cache into test-tool

2018-03-24 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Makefile   | 2 +-
 t/helper/test-read-cache.c | 3 ++-
 t/helper/test-tool.c   | 1 +
 t/helper/test-tool.h   | 1 +
 t/perf/p0002-read-cache.sh | 2 +-
 5 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index 076c778494..393fb9aca4 100644
--- a/Makefile
+++ b/Makefile
@@ -671,6 +671,7 @@ TEST_BUILTINS_OBJS += test-mktemp.o
 TEST_BUILTINS_OBJS += test-online-cpus.o
 TEST_BUILTINS_OBJS += test-path-utils.o
 TEST_BUILTINS_OBJS += test-prio-queue.o
+TEST_BUILTINS_OBJS += test-read-cache.o
 TEST_BUILTINS_OBJS += test-sha1.o
 
 TEST_PROGRAMS_NEED_X += test-dump-fsmonitor
@@ -678,7 +679,6 @@ 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
-TEST_PROGRAMS_NEED_X += test-read-cache
 TEST_PROGRAMS_NEED_X += test-write-cache
 TEST_PROGRAMS_NEED_X += test-ref-store
 TEST_PROGRAMS_NEED_X += test-regex
diff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c
index 48255eef31..d674c88ba0 100644
--- a/t/helper/test-read-cache.c
+++ b/t/helper/test-read-cache.c
@@ -1,6 +1,7 @@
+#include "test-tool.h"
 #include "cache.h"
 
-int cmd_main(int argc, const char **argv)
+int cmd__read_cache(int argc, const char **argv)
 {
int i, cnt = 1;
if (argc == 2)
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index be5f784865..f64355c25c 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -26,6 +26,7 @@ static struct test_cmd cmds[] = {
{ "online-cpus", cmd__online_cpus },
{ "path-utils", cmd__path_utils },
{ "prio-queue", cmd__prio_queue },
+   { "read-cache", cmd__read_cache },
{ "sha1", cmd__sha1 },
 };
 
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index 900c96dc02..4d51c17f5a 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -20,6 +20,7 @@ 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__prio_queue(int argc, const char **argv);
+int cmd__read_cache(int argc, const char **argv);
 int cmd__sha1(int argc, const char **argv);
 
 #endif
diff --git a/t/perf/p0002-read-cache.sh b/t/perf/p0002-read-cache.sh
index 9180ae9343..cdd105a594 100755
--- a/t/perf/p0002-read-cache.sh
+++ b/t/perf/p0002-read-cache.sh
@@ -8,7 +8,7 @@ test_perf_default_repo
 
 count=1000
 test_perf "read_cache/discard_cache $count times" "
-   test-read-cache $count
+   test-tool read-cache $count
 "
 
 test_done
-- 
2.17.0.rc0.348.gd5a49e0b6f



[PATCH v2 17/36] t/helper: merge (unused) test-mergesort into test-tool

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

diff --git a/Makefile b/Makefile
index 6552a8f4ed..67f37b849e 100644
--- a/Makefile
+++ b/Makefile
@@ -666,13 +666,13 @@ TEST_BUILTINS_OBJS += test-hashmap.o
 TEST_BUILTINS_OBJS += test-index-version.o
 TEST_BUILTINS_OBJS += test-lazy-init-name-hash.o
 TEST_BUILTINS_OBJS += test-match-trees.o
+TEST_BUILTINS_OBJS += test-mergesort.o
 TEST_BUILTINS_OBJS += test-sha1.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-mergesort
 TEST_PROGRAMS_NEED_X += test-mktemp
 TEST_PROGRAMS_NEED_X += test-online-cpus
 TEST_PROGRAMS_NEED_X += test-parse-options
diff --git a/t/helper/test-mergesort.c b/t/helper/test-mergesort.c
index 335cf6b626..c5cffaa4b7 100644
--- a/t/helper/test-mergesort.c
+++ b/t/helper/test-mergesort.c
@@ -1,3 +1,4 @@
+#include "test-tool.h"
 #include "cache.h"
 #include "mergesort.h"
 
@@ -22,7 +23,7 @@ static int compare_strings(const void *a, const void *b)
return strcmp(x->text, y->text);
 }
 
-int cmd_main(int argc, const char **argv)
+int cmd__mergesort(int argc, const char **argv)
 {
struct line *line, *p = NULL, *lines = NULL;
struct strbuf sb = STRBUF_INIT;
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index 3653646f3a..7ec0e8efe5 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -21,6 +21,7 @@ static struct test_cmd cmds[] = {
{ "index-version", cmd__index_version },
{ "lazy-init-name-hash", cmd__lazy_init_name_hash },
{ "match-trees", cmd__match_trees },
+   { "mergesort", cmd__mergesort },
{ "sha1", cmd__sha1 },
 };
 
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index d2f009cb3e..6c9437ff5e 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -15,6 +15,7 @@ int cmd__hashmap(int argc, const char **argv);
 int cmd__index_version(int argc, const char **argv);
 int cmd__lazy_init_name_hash(int argc, const char **argv);
 int cmd__match_trees(int argc, const char **argv);
+int cmd__mergesort(int argc, const char **argv);
 int cmd__sha1(int argc, const char **argv);
 
 #endif
-- 
2.17.0.rc0.348.gd5a49e0b6f



[PATCH v2 24/36] t/helper: merge test-regex into test-tool

2018-03-24 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Makefile| 2 +-
 t/helper/test-regex.c   | 7 ---
 t/helper/test-tool.c| 1 +
 t/helper/test-tool.h| 1 +
 t/t0070-fundamental.sh  | 2 +-
 t/t7812-grep-icase-non-ascii.sh | 2 +-
 6 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/Makefile b/Makefile
index 20080fddb8..7444c00bbb 100644
--- a/Makefile
+++ b/Makefile
@@ -673,6 +673,7 @@ TEST_BUILTINS_OBJS += test-path-utils.o
 TEST_BUILTINS_OBJS += test-prio-queue.o
 TEST_BUILTINS_OBJS += test-read-cache.o
 TEST_BUILTINS_OBJS += test-ref-store.o
+TEST_BUILTINS_OBJS += test-regex.o
 TEST_BUILTINS_OBJS += test-sha1.o
 
 TEST_PROGRAMS_NEED_X += test-dump-fsmonitor
@@ -681,7 +682,6 @@ 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-write-cache
-TEST_PROGRAMS_NEED_X += test-regex
 TEST_PROGRAMS_NEED_X += test-revision-walking
 TEST_PROGRAMS_NEED_X += test-run-command
 TEST_PROGRAMS_NEED_X += test-scrap-cache-tree
diff --git a/t/helper/test-regex.c b/t/helper/test-regex.c
index b5ea8a97c5..10284cc56f 100644
--- a/t/helper/test-regex.c
+++ b/t/helper/test-regex.c
@@ -1,3 +1,4 @@
+#include "test-tool.h"
 #include "git-compat-util.h"
 #include "gettext.h"
 
@@ -36,7 +37,7 @@ static int test_regex_bug(void)
return 0;
 }
 
-int cmd_main(int argc, const char **argv)
+int cmd__regex(int argc, const char **argv)
 {
const char *pat;
const char *str;
@@ -47,8 +48,8 @@ int cmd_main(int argc, const char **argv)
if (argc == 2 && !strcmp(argv[1], "--bug"))
return test_regex_bug();
else if (argc < 3)
-   usage("test-regex --bug\n"
- "test-regex   []");
+   usage("test-tool regex --bug\n"
+ "test-tool regex   []");
 
argv++;
pat = *argv++;
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index 777150e4ad..0dd3b879ad 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -28,6 +28,7 @@ static struct test_cmd cmds[] = {
{ "prio-queue", cmd__prio_queue },
{ "read-cache", cmd__read_cache },
{ "ref-store", cmd__ref_store },
+   { "regex", cmd__regex },
{ "sha1", cmd__sha1 },
 };
 
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index 2b5cc6e117..5f73c83ac0 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -22,6 +22,7 @@ int cmd__path_utils(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);
+int cmd__regex(int argc, const char **argv);
 int cmd__sha1(int argc, const char **argv);
 
 #endif
diff --git a/t/t0070-fundamental.sh b/t/t0070-fundamental.sh
index ac007938ee..23fbe6434a 100755
--- a/t/t0070-fundamental.sh
+++ b/t/t0070-fundamental.sh
@@ -31,7 +31,7 @@ test_expect_success 'git_mkstemps_mode does not fail if fd 0 
is not open' '
 
 test_expect_success 'check for a bug in the regex routines' '
# if this test fails, re-build git with NO_REGEX=1
-   test-regex --bug
+   test-tool regex --bug
 '
 
 test_done
diff --git a/t/t7812-grep-icase-non-ascii.sh b/t/t7812-grep-icase-non-ascii.sh
index 0059a1f837..0c685d3598 100755
--- a/t/t7812-grep-icase-non-ascii.sh
+++ b/t/t7812-grep-icase-non-ascii.sh
@@ -12,7 +12,7 @@ test_expect_success GETTEXT_LOCALE 'setup' '
 '
 
 test_have_prereq GETTEXT_LOCALE &&
-test-regex "HALLÓ" "Halló" ICASE &&
+test-tool regex "HALLÓ" "Halló" ICASE &&
 test_set_prereq REGEX_LOCALE
 
 test_expect_success REGEX_LOCALE 'grep literal string, no -F' '
-- 
2.17.0.rc0.348.gd5a49e0b6f



[PATCH v2 23/36] t/helper: merge test-ref-store into test-tool

2018-03-24 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Makefile   | 2 +-
 t/helper/test-ref-store.c  | 3 ++-
 t/helper/test-tool.c   | 1 +
 t/helper/test-tool.h   | 1 +
 t/t1405-main-ref-store.sh  | 2 +-
 t/t1406-submodule-ref-store.sh | 2 +-
 t/t1407-worktree-ref-store.sh  | 4 ++--
 7 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/Makefile b/Makefile
index 393fb9aca4..20080fddb8 100644
--- a/Makefile
+++ b/Makefile
@@ -672,6 +672,7 @@ TEST_BUILTINS_OBJS += test-online-cpus.o
 TEST_BUILTINS_OBJS += test-path-utils.o
 TEST_BUILTINS_OBJS += test-prio-queue.o
 TEST_BUILTINS_OBJS += test-read-cache.o
+TEST_BUILTINS_OBJS += test-ref-store.o
 TEST_BUILTINS_OBJS += test-sha1.o
 
 TEST_PROGRAMS_NEED_X += test-dump-fsmonitor
@@ -680,7 +681,6 @@ 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-write-cache
-TEST_PROGRAMS_NEED_X += test-ref-store
 TEST_PROGRAMS_NEED_X += test-regex
 TEST_PROGRAMS_NEED_X += test-revision-walking
 TEST_PROGRAMS_NEED_X += test-run-command
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index 7120634b04..cdefb66a87 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -1,3 +1,4 @@
+#include "test-tool.h"
 #include "cache.h"
 #include "refs.h"
 #include "worktree.h"
@@ -274,7 +275,7 @@ static struct command commands[] = {
{ NULL, NULL }
 };
 
-int cmd_main(int argc, const char **argv)
+int cmd__ref_store(int argc, const char **argv)
 {
struct ref_store *refs;
const char *func;
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index f64355c25c..777150e4ad 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -27,6 +27,7 @@ static struct test_cmd cmds[] = {
{ "path-utils", cmd__path_utils },
{ "prio-queue", cmd__prio_queue },
{ "read-cache", cmd__read_cache },
+   { "ref-store", cmd__ref_store },
{ "sha1", cmd__sha1 },
 };
 
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index 4d51c17f5a..2b5cc6e117 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -21,6 +21,7 @@ int cmd__online_cpus(int argc, const char **argv);
 int cmd__path_utils(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);
 int cmd__sha1(int argc, const char **argv);
 
 #endif
diff --git a/t/t1405-main-ref-store.sh b/t/t1405-main-ref-store.sh
index e8115df5ba..a30a080b20 100755
--- a/t/t1405-main-ref-store.sh
+++ b/t/t1405-main-ref-store.sh
@@ -4,7 +4,7 @@ test_description='test main ref store api'
 
 . ./test-lib.sh
 
-RUN="test-ref-store main"
+RUN="test-tool ref-store main"
 
 test_expect_success 'pack_refs(PACK_REFS_ALL | PACK_REFS_PRUNE)' '
test_commit one &&
diff --git a/t/t1406-submodule-ref-store.sh b/t/t1406-submodule-ref-store.sh
index c32d4cc465..e093782cc3 100755
--- a/t/t1406-submodule-ref-store.sh
+++ b/t/t1406-submodule-ref-store.sh
@@ -4,7 +4,7 @@ test_description='test submodule ref store api'
 
 . ./test-lib.sh
 
-RUN="test-ref-store submodule:sub"
+RUN="test-tool ref-store submodule:sub"
 
 test_expect_success 'setup' '
git init sub &&
diff --git a/t/t1407-worktree-ref-store.sh b/t/t1407-worktree-ref-store.sh
index 8842d0329f..2211f9831f 100755
--- a/t/t1407-worktree-ref-store.sh
+++ b/t/t1407-worktree-ref-store.sh
@@ -4,8 +4,8 @@ test_description='test worktree ref store api'
 
 . ./test-lib.sh
 
-RWT="test-ref-store worktree:wt"
-RMAIN="test-ref-store worktree:main"
+RWT="test-tool ref-store worktree:wt"
+RMAIN="test-tool ref-store worktree:main"
 
 test_expect_success 'setup' '
test_commit first &&
-- 
2.17.0.rc0.348.gd5a49e0b6f



[PATCH v2 25/36] t/helper: merge test-revision-walking into test-tool

2018-03-24 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Makefile | 2 +-
 t/helper/test-revision-walking.c | 3 ++-
 t/helper/test-tool.c | 1 +
 t/helper/test-tool.h | 1 +
 t/t0062-revision-walking.sh  | 2 +-
 5 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index 7444c00bbb..3ed461cd55 100644
--- a/Makefile
+++ b/Makefile
@@ -674,6 +674,7 @@ TEST_BUILTINS_OBJS += test-prio-queue.o
 TEST_BUILTINS_OBJS += test-read-cache.o
 TEST_BUILTINS_OBJS += test-ref-store.o
 TEST_BUILTINS_OBJS += test-regex.o
+TEST_BUILTINS_OBJS += test-revision-walking.o
 TEST_BUILTINS_OBJS += test-sha1.o
 
 TEST_PROGRAMS_NEED_X += test-dump-fsmonitor
@@ -682,7 +683,6 @@ 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-write-cache
-TEST_PROGRAMS_NEED_X += test-revision-walking
 TEST_PROGRAMS_NEED_X += test-run-command
 TEST_PROGRAMS_NEED_X += test-scrap-cache-tree
 TEST_PROGRAMS_NEED_X += test-sha1-array
diff --git a/t/helper/test-revision-walking.c b/t/helper/test-revision-walking.c
index b8e6fe1d00..4f8bc75821 100644
--- a/t/helper/test-revision-walking.c
+++ b/t/helper/test-revision-walking.c
@@ -8,6 +8,7 @@
  * published by the Free Software Foundation.
  */
 
+#include "test-tool.h"
 #include "cache.h"
 #include "commit.h"
 #include "diff.h"
@@ -45,7 +46,7 @@ static int run_revision_walk(void)
return got_revision;
 }
 
-int cmd_main(int argc, const char **argv)
+int cmd__revision_walking(int argc, const char **argv)
 {
if (argc < 2)
return 1;
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index 0dd3b879ad..e43405bea9 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -29,6 +29,7 @@ static struct test_cmd cmds[] = {
{ "read-cache", cmd__read_cache },
{ "ref-store", cmd__ref_store },
{ "regex", cmd__regex },
+   { "revision-walking", cmd__revision_walking },
{ "sha1", cmd__sha1 },
 };
 
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index 5f73c83ac0..4dff220646 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -23,6 +23,7 @@ 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);
 int cmd__regex(int argc, const char **argv);
+int cmd__revision_walking(int argc, const char **argv);
 int cmd__sha1(int argc, const char **argv);
 
 #endif
diff --git a/t/t0062-revision-walking.sh b/t/t0062-revision-walking.sh
index 113c728e67..8e215867b8 100755
--- a/t/t0062-revision-walking.sh
+++ b/t/t0062-revision-walking.sh
@@ -26,7 +26,7 @@ test_expect_success 'setup' '
 '
 
 test_expect_success 'revision walking can be done twice' '
-   test-revision-walking run-twice >run_twice_actual &&
+   test-tool revision-walking run-twice >run_twice_actual &&
test_cmp run_twice_expected run_twice_actual
 '
 
-- 
2.17.0.rc0.348.gd5a49e0b6f



[PATCH v2 35/36] t/helper: merge test-wildmatch into test-tool

2018-03-24 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  |  1 +
 t/helper/test-tool.h  |  1 +
 t/helper/test-wildmatch.c |  3 ++-
 t/t3070-wildmatch.sh  | 14 +++---
 5 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/Makefile b/Makefile
index 7923ec3747..2ab76c6838 100644
--- a/Makefile
+++ b/Makefile
@@ -685,6 +685,7 @@ TEST_BUILTINS_OBJS += test-string-list.o
 TEST_BUILTINS_OBJS += test-submodule-config.o
 TEST_BUILTINS_OBJS += test-subprocess.o
 TEST_BUILTINS_OBJS += test-urlmatch-normalization.o
+TEST_BUILTINS_OBJS += test-wildmatch.o
 
 TEST_PROGRAMS_NEED_X += test-dump-fsmonitor
 TEST_PROGRAMS_NEED_X += test-dump-untracked-cache
@@ -694,7 +695,6 @@ TEST_PROGRAMS_NEED_X += test-parse-options
 TEST_PROGRAMS_NEED_X += test-write-cache
 TEST_PROGRAMS_NEED_X += test-svn-fe
 TEST_PROGRAMS_NEED_X += test-tool
-TEST_PROGRAMS_NEED_X += test-wildmatch
 
 TEST_PROGRAMS = $(patsubst %,t/helper/%$X,$(TEST_PROGRAMS_NEED_X))
 
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index b3d84fdac9..a804e64048 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -40,6 +40,7 @@ static struct test_cmd cmds[] = {
{ "submodule-config", cmd__submodule_config },
{ "subprocess", cmd__subprocess },
{ "urlmatch-normalization", cmd__urlmatch_normalization },
+   { "wildmatch", cmd__wildmatch },
 };
 
 int cmd_main(int argc, const char **argv)
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index fa53c82659..84c583e68f 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -34,5 +34,6 @@ int cmd__string_list(int argc, const char **argv);
 int cmd__submodule_config(int argc, const char **argv);
 int cmd__subprocess(int argc, const char **argv);
 int cmd__urlmatch_normalization(int argc, const char **argv);
+int cmd__wildmatch(int argc, const char **argv);
 
 #endif
diff --git a/t/helper/test-wildmatch.c b/t/helper/test-wildmatch.c
index 66d33dfcfd..2c103d1824 100644
--- a/t/helper/test-wildmatch.c
+++ b/t/helper/test-wildmatch.c
@@ -1,6 +1,7 @@
+#include "test-tool.h"
 #include "cache.h"
 
-int cmd_main(int argc, const char **argv)
+int cmd__wildmatch(int argc, const char **argv)
 {
int i;
for (i = 2; i < argc; i++) {
diff --git a/t/t3070-wildmatch.sh b/t/t3070-wildmatch.sh
index c1fc6ca730..dce102130f 100755
--- a/t/t3070-wildmatch.sh
+++ b/t/t3070-wildmatch.sh
@@ -79,12 +79,12 @@ match_with_function() {
if test "$match_expect" = 1
then
test_expect_success "$match_function: match '$text' '$pattern'" 
"
-   test-wildmatch $match_function '$text' '$pattern'
+   test-tool wildmatch $match_function '$text' '$pattern'
"
elif test "$match_expect" = 0
then
test_expect_success "$match_function: no match '$text' 
'$pattern'" "
-   test_must_fail test-wildmatch $match_function '$text' 
'$pattern'
+   test_must_fail test-tool wildmatch $match_function 
'$text' '$pattern'
"
else
test_expect_success "PANIC: Test framework error. Unknown 
matches value $match_expect" 'false'
@@ -148,7 +148,7 @@ match_with_ls_files() {
 match() {
if test "$#" = 6
then
-   # When test-wildmatch and git ls-files produce the same
+   # When test-tool wildmatch and git ls-files produce the same
# result.
match_glob=$1
match_file_glob=$match_glob
@@ -204,19 +204,19 @@ match() {
fi
'
 
-   # $1: Case sensitive glob match: test-wildmatch & ls-files
+   # $1: Case sensitive glob match: test-tool wildmatch & ls-files
match_with_function "$text" "$pattern" $match_glob "wildmatch"
match_with_ls_files "$text" "$pattern" $match_file_glob "wildmatch" " 
--glob-pathspecs"
 
-   # $2: Case insensitive glob match: test-wildmatch & ls-files
+   # $2: Case insensitive glob match: test-tool wildmatch & ls-files
match_with_function "$text" "$pattern" $match_iglob "iwildmatch"
match_with_ls_files "$text" "$pattern" $match_file_iglob "iwildmatch" " 
--glob-pathspecs --icase-pathspecs"
 
-   # $3: Case sensitive path match: test-wildmatch & ls-files
+   # $3: Case sensitive path match: test-tool wildmatch & ls-files
match_with_function "$text" "$pattern" $match_pathmatch "pathmatch"
match_with_ls_files "$text" "$pattern" $match_file_pathmatch 
"pathmatch" ""
 
-   # $4: Case insensitive path match: test-wildmatch & ls-files
+   # $4: Case insensitive path match: test-tool wildmatch & ls-files
match_with_function "$text" "$pattern" $match_pathmatchi "ipathmatch"
match_with_ls_files "$text" "$pattern" $match_file_pathmatchi 
"ipathmatch" " --icase-pathspecs"
 }
-- 
2.17.0.rc0.348.gd5a49e0b6f



[PATCH v2 36/36] t/helper: merge test-write-cache into test-tool

2018-03-24 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| 1 +
 t/helper/test-tool.h| 1 +
 t/helper/test-write-cache.c | 3 ++-
 t/perf/p0007-write-cache.sh | 2 +-
 5 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index 2ab76c6838..8ad9a2a1a9 100644
--- a/Makefile
+++ b/Makefile
@@ -686,13 +686,13 @@ TEST_BUILTINS_OBJS += test-submodule-config.o
 TEST_BUILTINS_OBJS += test-subprocess.o
 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-dump-untracked-cache
 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-write-cache
 TEST_PROGRAMS_NEED_X += test-svn-fe
 TEST_PROGRAMS_NEED_X += test-tool
 
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index a804e64048..cd5e28b045 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -41,6 +41,7 @@ static struct test_cmd cmds[] = {
{ "subprocess", cmd__subprocess },
{ "urlmatch-normalization", cmd__urlmatch_normalization },
{ "wildmatch", cmd__wildmatch },
+   { "write-cache", cmd__write_cache },
 };
 
 int cmd_main(int argc, const char **argv)
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index 84c583e68f..7116ddfb94 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -35,5 +35,6 @@ int cmd__submodule_config(int argc, const char **argv);
 int cmd__subprocess(int argc, const char **argv);
 int cmd__urlmatch_normalization(int argc, const char **argv);
 int cmd__wildmatch(int argc, const char **argv);
+int cmd__write_cache(int argc, const char **argv);
 
 #endif
diff --git a/t/helper/test-write-cache.c b/t/helper/test-write-cache.c
index b7ee039669..017dc30380 100644
--- a/t/helper/test-write-cache.c
+++ b/t/helper/test-write-cache.c
@@ -1,9 +1,10 @@
+#include "test-tool.h"
 #include "cache.h"
 #include "lockfile.h"
 
 static struct lock_file index_lock;
 
-int cmd_main(int argc, const char **argv)
+int cmd__write_cache(int argc, const char **argv)
 {
int i, cnt = 1, lockfd;
if (argc == 2)
diff --git a/t/perf/p0007-write-cache.sh b/t/perf/p0007-write-cache.sh
index 261fe92fd9..09595264f0 100755
--- a/t/perf/p0007-write-cache.sh
+++ b/t/perf/p0007-write-cache.sh
@@ -23,7 +23,7 @@ test_expect_success "setup repo" '
 
 count=3
 test_perf "write_locked_index $count times ($nr_files files)" "
-   test-write-cache $count
+   test-tool write-cache $count
 "
 
 test_done
-- 
2.17.0.rc0.348.gd5a49e0b6f



[PATCH v2 30/36] t/helper: merge test-strcmp-offset into test-tool

2018-03-24 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Makefile  | 2 +-
 t/helper/test-strcmp-offset.c | 3 ++-
 t/helper/test-tool.c  | 1 +
 t/helper/test-tool.h  | 1 +
 t/t0065-strcmp-offset.sh  | 2 +-
 5 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index 51de8882d0..528a80b6a6 100644
--- a/Makefile
+++ b/Makefile
@@ -680,6 +680,7 @@ 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-sigchain.o
+TEST_BUILTINS_OBJS += test-strcmp-offset.o
 
 TEST_PROGRAMS_NEED_X += test-dump-fsmonitor
 TEST_PROGRAMS_NEED_X += test-dump-untracked-cache
@@ -687,7 +688,6 @@ 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-write-cache
-TEST_PROGRAMS_NEED_X += test-strcmp-offset
 TEST_PROGRAMS_NEED_X += test-string-list
 TEST_PROGRAMS_NEED_X += test-submodule-config
 TEST_PROGRAMS_NEED_X += test-subprocess
diff --git a/t/helper/test-strcmp-offset.c b/t/helper/test-strcmp-offset.c
index e159c9a127..44e4a6d143 100644
--- a/t/helper/test-strcmp-offset.c
+++ b/t/helper/test-strcmp-offset.c
@@ -1,6 +1,7 @@
+#include "test-tool.h"
 #include "cache.h"
 
-int cmd_main(int argc, const char **argv)
+int cmd__strcmp_offset(int argc, const char **argv)
 {
int result;
size_t offset;
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index c1de1a3397..41b8f869ae 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -35,6 +35,7 @@ static struct test_cmd cmds[] = {
{ "sha1-array", cmd__sha1_array },
{ "sha1", cmd__sha1 },
{ "sigchain", cmd__sigchain },
+   { "strcmp-offset", cmd__strcmp_offset },
 };
 
 int cmd_main(int argc, const char **argv)
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index 1d366846f3..035e82ec6a 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -29,5 +29,6 @@ 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__sigchain(int argc, const char **argv);
+int cmd__strcmp_offset(int argc, const char **argv);
 
 #endif
diff --git a/t/t0065-strcmp-offset.sh b/t/t0065-strcmp-offset.sh
index 7d6d21425f..91fa639c4a 100755
--- a/t/t0065-strcmp-offset.sh
+++ b/t/t0065-strcmp-offset.sh
@@ -8,7 +8,7 @@ while read s1 s2 expect
 do
test_expect_success "strcmp_offset($s1, $s2)" '
echo "$expect" >expect &&
-   test-strcmp-offset "$s1" "$s2" >actual &&
+   test-tool strcmp-offset "$s1" "$s2" >actual &&
test_cmp expect actual
'
 done <<-EOF
-- 
2.17.0.rc0.348.gd5a49e0b6f



[PATCH v2 16/36] t/helper: merge (unused) test-match-trees into test-tool

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

diff --git a/Makefile b/Makefile
index d7342e3a8b..6552a8f4ed 100644
--- a/Makefile
+++ b/Makefile
@@ -665,13 +665,13 @@ TEST_BUILTINS_OBJS += test-genrandom.o
 TEST_BUILTINS_OBJS += test-hashmap.o
 TEST_BUILTINS_OBJS += test-index-version.o
 TEST_BUILTINS_OBJS += test-lazy-init-name-hash.o
+TEST_BUILTINS_OBJS += test-match-trees.o
 TEST_BUILTINS_OBJS += test-sha1.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-match-trees
 TEST_PROGRAMS_NEED_X += test-mergesort
 TEST_PROGRAMS_NEED_X += test-mktemp
 TEST_PROGRAMS_NEED_X += test-online-cpus
diff --git a/t/helper/test-match-trees.c b/t/helper/test-match-trees.c
index 356d8edef1..96857f26ac 100644
--- a/t/helper/test-match-trees.c
+++ b/t/helper/test-match-trees.c
@@ -1,7 +1,8 @@
+#include "test-tool.h"
 #include "cache.h"
 #include "tree.h"
 
-int cmd_main(int ac, const char **av)
+int cmd__match_trees(int ac, const char **av)
 {
struct object_id hash1, hash2, shifted;
struct tree *one, *two;
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index 88fbe8ddbd..3653646f3a 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -20,6 +20,7 @@ static struct test_cmd cmds[] = {
{ "hashmap", cmd__hashmap },
{ "index-version", cmd__index_version },
{ "lazy-init-name-hash", cmd__lazy_init_name_hash },
+   { "match-trees", cmd__match_trees },
{ "sha1", cmd__sha1 },
 };
 
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index b855203477..d2f009cb3e 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -14,6 +14,7 @@ int cmd__genrandom(int argc, const char **argv);
 int cmd__hashmap(int argc, const char **argv);
 int cmd__index_version(int argc, const char **argv);
 int cmd__lazy_init_name_hash(int argc, const char **argv);
+int cmd__match_trees(int argc, const char **argv);
 int cmd__sha1(int argc, const char **argv);
 
 #endif
-- 
2.17.0.rc0.348.gd5a49e0b6f



[PATCH v2 34/36] t/helper: merge test-urlmatch-normalization into test-tool

2018-03-24 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   |   1 +
 t/helper/test-tool.h   |   1 +
 t/helper/test-urlmatch-normalization.c |   5 +-
 t/t0110-urlmatch-normalization.sh  | 266 -
 5 files changed, 139 insertions(+), 136 deletions(-)

diff --git a/Makefile b/Makefile
index 893ea64ca2..7923ec3747 100644
--- a/Makefile
+++ b/Makefile
@@ -684,6 +684,7 @@ TEST_BUILTINS_OBJS += test-strcmp-offset.o
 TEST_BUILTINS_OBJS += test-string-list.o
 TEST_BUILTINS_OBJS += test-submodule-config.o
 TEST_BUILTINS_OBJS += test-subprocess.o
+TEST_BUILTINS_OBJS += test-urlmatch-normalization.o
 
 TEST_PROGRAMS_NEED_X += test-dump-fsmonitor
 TEST_PROGRAMS_NEED_X += test-dump-untracked-cache
@@ -693,7 +694,6 @@ TEST_PROGRAMS_NEED_X += test-parse-options
 TEST_PROGRAMS_NEED_X += test-write-cache
 TEST_PROGRAMS_NEED_X += test-svn-fe
 TEST_PROGRAMS_NEED_X += test-tool
-TEST_PROGRAMS_NEED_X += test-urlmatch-normalization
 TEST_PROGRAMS_NEED_X += test-wildmatch
 
 TEST_PROGRAMS = $(patsubst %,t/helper/%$X,$(TEST_PROGRAMS_NEED_X))
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index 96180f0350..b3d84fdac9 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -39,6 +39,7 @@ static struct test_cmd cmds[] = {
{ "string-list", cmd__string_list },
{ "submodule-config", cmd__submodule_config },
{ "subprocess", cmd__subprocess },
+   { "urlmatch-normalization", cmd__urlmatch_normalization },
 };
 
 int cmd_main(int argc, const char **argv)
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index a611801061..fa53c82659 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -33,5 +33,6 @@ int cmd__strcmp_offset(int argc, const char **argv);
 int cmd__string_list(int argc, const char **argv);
 int cmd__submodule_config(int argc, const char **argv);
 int cmd__subprocess(int argc, const char **argv);
+int cmd__urlmatch_normalization(int argc, const char **argv);
 
 #endif
diff --git a/t/helper/test-urlmatch-normalization.c 
b/t/helper/test-urlmatch-normalization.c
index 49b6e836be..8f4d67e646 100644
--- a/t/helper/test-urlmatch-normalization.c
+++ b/t/helper/test-urlmatch-normalization.c
@@ -1,9 +1,10 @@
+#include "test-tool.h"
 #include "git-compat-util.h"
 #include "urlmatch.h"
 
-int cmd_main(int argc, const char **argv)
+int cmd__urlmatch_normalization(int argc, const char **argv)
 {
-   const char usage[] = "test-urlmatch-normalization [-p | -l]  | 
 ";
+   const char usage[] = "test-tool urlmatch-normalization [-p | -l]  
|  ";
char *url1, *url2;
int opt_p = 0, opt_l = 0;
 
diff --git a/t/t0110-urlmatch-normalization.sh 
b/t/t0110-urlmatch-normalization.sh
index 410d5768ca..f99529d838 100755
--- a/t/t0110-urlmatch-normalization.sh
+++ b/t/t0110-urlmatch-normalization.sh
@@ -9,172 +9,172 @@ tu="$TEST_DIRECTORY/t0110/url"
 # Note that only file: URLs should be allowed without a host
 
 test_expect_success 'url scheme' '
-   ! test-urlmatch-normalization "" &&
-   ! test-urlmatch-normalization "_" &&
-   ! test-urlmatch-normalization "scheme" &&
-   ! test-urlmatch-normalization "scheme:" &&
-   ! test-urlmatch-normalization "scheme:/" &&
-   ! test-urlmatch-normalization "scheme://" &&
-   ! test-urlmatch-normalization "file" &&
-   ! test-urlmatch-normalization "file:" &&
-   ! test-urlmatch-normalization "file:/" &&
-   test-urlmatch-normalization "file://" &&
-   ! test-urlmatch-normalization "://acme.co" &&
-   ! test-urlmatch-normalization "x_test://acme.co" &&
-   ! test-urlmatch-normalization "-test://acme.co" &&
-   ! test-urlmatch-normalization "0test://acme.co" &&
-   ! test-urlmatch-normalization "+test://acme.co" &&
-   ! test-urlmatch-normalization ".test://acme.co" &&
-   ! test-urlmatch-normalization "schem%6e://" &&
-   test-urlmatch-normalization "x-Test+v1.0://acme.co" &&
-   test "$(test-urlmatch-normalization -p "AbCdeF://x.Y")" = 
"abcdef://x.y/"
+   ! test-tool urlmatch-normalization "" &&
+   ! test-tool urlmatch-normalization "_" &&
+   ! test-tool urlmatch-normalization "scheme" &&
+   ! test-tool urlmatch-normalization "scheme:" &&
+   ! test-tool urlmatch-normalization "scheme:/" &&
+   ! test-tool urlmatch-normalization "scheme://" &&
+   ! test-tool urlmatch-normalization "file" &&
+   ! test-tool urlmatch-normalization "file:" &&
+   ! test-tool urlmatch-normalization "file:/" &&
+   test-tool urlmatch-normalization "file://" &&
+   ! test-tool urlmatch-normalization "://acme.co" &&
+   ! test-tool urlmatch-normalization "x_test://acme.co" &&
+   ! test-tool urlmatch-normalization "-test://acme.co" &&
+   ! test-tool urlmatch-normalization "0test://acme.co" &&
+   ! test-tool urlmatch-normalization "+test://acme.co" &&
+   ! test-tool 

[PATCH v2 28/36] t/helper: merge test-sha1-array into test-tool

2018-03-24 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Makefile   |  2 +-
 t/helper/test-sha1-array.c |  3 ++-
 t/helper/test-tool.c   |  1 +
 t/helper/test-tool.h   |  1 +
 t/t0064-sha1-array.sh  | 16 
 5 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/Makefile b/Makefile
index ba7c7d8a79..b50a0818a9 100644
--- a/Makefile
+++ b/Makefile
@@ -677,6 +677,7 @@ TEST_BUILTINS_OBJS += test-regex.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_PROGRAMS_NEED_X += test-dump-fsmonitor
@@ -685,7 +686,6 @@ 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-write-cache
-TEST_PROGRAMS_NEED_X += test-sha1-array
 TEST_PROGRAMS_NEED_X += test-sigchain
 TEST_PROGRAMS_NEED_X += test-strcmp-offset
 TEST_PROGRAMS_NEED_X += test-string-list
diff --git a/t/helper/test-sha1-array.c b/t/helper/test-sha1-array.c
index edfd52d82a..ad5e69f9d3 100644
--- a/t/helper/test-sha1-array.c
+++ b/t/helper/test-sha1-array.c
@@ -1,3 +1,4 @@
+#include "test-tool.h"
 #include "cache.h"
 #include "sha1-array.h"
 
@@ -7,7 +8,7 @@ static int print_oid(const struct object_id *oid, void *data)
return 0;
 }
 
-int cmd_main(int argc, const char **argv)
+int cmd__sha1_array(int argc, const char **argv)
 {
struct oid_array array = OID_ARRAY_INIT;
struct strbuf line = STRBUF_INIT;
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index 96d8df69d4..27f7b6ff75 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -32,6 +32,7 @@ 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 },
 };
 
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index 448119a44a..d8066e3f63 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -26,6 +26,7 @@ int cmd__regex(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);
 
 #endif
diff --git a/t/t0064-sha1-array.sh b/t/t0064-sha1-array.sh
index 50b31ffe75..67484502a0 100755
--- a/t/t0064-sha1-array.sh
+++ b/t/t0064-sha1-array.sh
@@ -18,7 +18,7 @@ test_expect_success 'ordered enumeration' '
{
echo20 append 88 44 aa 55 &&
echo for_each_unique
-   } | test-sha1-array >actual &&
+   } | test-tool sha1-array >actual &&
test_cmp expect actual
 '
 
@@ -28,7 +28,7 @@ test_expect_success 'ordered enumeration with duplicate 
suppression' '
echo20 append 88 44 aa 55 &&
echo20 append 88 44 aa 55 &&
echo for_each_unique
-   } | test-sha1-array >actual &&
+   } | test-tool sha1-array >actual &&
test_cmp expect actual
 '
 
@@ -36,7 +36,7 @@ test_expect_success 'lookup' '
{
echo20 append 88 44 aa 55 &&
echo20 lookup 55
-   } | test-sha1-array >actual &&
+   } | test-tool sha1-array >actual &&
n=$(cat actual) &&
test "$n" -eq 1
 '
@@ -45,7 +45,7 @@ test_expect_success 'lookup non-existing entry' '
{
echo20 append 88 44 aa 55 &&
echo20 lookup 33
-   } | test-sha1-array >actual &&
+   } | test-tool sha1-array >actual &&
n=$(cat actual) &&
test "$n" -lt 0
 '
@@ -55,7 +55,7 @@ test_expect_success 'lookup with duplicates' '
echo20 append 88 44 aa 55 &&
echo20 append 88 44 aa 55 &&
echo20 lookup 55
-   } | test-sha1-array >actual &&
+   } | test-tool sha1-array >actual &&
n=$(cat actual) &&
test "$n" -ge 2 &&
test "$n" -le 3
@@ -66,7 +66,7 @@ test_expect_success 'lookup non-existing entry with 
duplicates' '
echo20 append 88 44 aa 55 &&
echo20 append 88 44 aa 55 &&
echo20 lookup 66
-   } | test-sha1-array >actual &&
+   } | test-tool sha1-array >actual &&
n=$(cat actual) &&
test "$n" -lt 0
 '
@@ -76,7 +76,7 @@ test_expect_success 'lookup with almost duplicate values' '
echo "append " &&
echo "append 555f" &&
echo20 lookup 55
-   } | test-sha1-array >actual &&
+   } | test-tool sha1-array >actual &&
n=$(cat actual) &&
test "$n" -eq 0
 '
@@ -85,7 +85,7 @@ test_expect_success 'lookup 

[PATCH v2 31/36] t/helper: merge test-string-list into test-tool

2018-03-24 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Makefile|  2 +-
 t/helper/test-string-list.c |  3 ++-
 t/helper/test-tool.c|  1 +
 t/helper/test-tool.h|  1 +
 t/perf/p0071-sort.sh|  2 +-
 t/t0063-string-list.sh  | 48 ++---
 6 files changed, 30 insertions(+), 27 deletions(-)

diff --git a/Makefile b/Makefile
index 528a80b6a6..6819792c2b 100644
--- a/Makefile
+++ b/Makefile
@@ -681,6 +681,7 @@ TEST_BUILTINS_OBJS += test-sha1-array.o
 TEST_BUILTINS_OBJS += test-sha1.o
 TEST_BUILTINS_OBJS += test-sigchain.o
 TEST_BUILTINS_OBJS += test-strcmp-offset.o
+TEST_BUILTINS_OBJS += test-string-list.o
 
 TEST_PROGRAMS_NEED_X += test-dump-fsmonitor
 TEST_PROGRAMS_NEED_X += test-dump-untracked-cache
@@ -688,7 +689,6 @@ 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-write-cache
-TEST_PROGRAMS_NEED_X += test-string-list
 TEST_PROGRAMS_NEED_X += test-submodule-config
 TEST_PROGRAMS_NEED_X += test-subprocess
 TEST_PROGRAMS_NEED_X += test-svn-fe
diff --git a/t/helper/test-string-list.c b/t/helper/test-string-list.c
index 829ec3d7d2..2123dda85b 100644
--- a/t/helper/test-string-list.c
+++ b/t/helper/test-string-list.c
@@ -1,3 +1,4 @@
+#include "test-tool.h"
 #include "cache.h"
 #include "string-list.h"
 
@@ -41,7 +42,7 @@ static int prefix_cb(struct string_list_item *item, void 
*cb_data)
return starts_with(item->string, prefix);
 }
 
-int cmd_main(int argc, const char **argv)
+int cmd__string_list(int argc, const char **argv)
 {
if (argc == 5 && !strcmp(argv[1], "split")) {
struct string_list list = STRING_LIST_INIT_DUP;
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index 41b8f869ae..90008533cd 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -36,6 +36,7 @@ static struct test_cmd cmds[] = {
{ "sha1", cmd__sha1 },
{ "sigchain", cmd__sigchain },
{ "strcmp-offset", cmd__strcmp_offset },
+   { "string-list", cmd__string_list },
 };
 
 int cmd_main(int argc, const char **argv)
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index 035e82ec6a..19ad2b0df8 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -30,5 +30,6 @@ int cmd__sha1_array(int argc, const char **argv);
 int cmd__sha1(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);
 
 #endif
diff --git a/t/perf/p0071-sort.sh b/t/perf/p0071-sort.sh
index 7c9a35a646..6e924f5fa3 100755
--- a/t/perf/p0071-sort.sh
+++ b/t/perf/p0071-sort.sh
@@ -16,7 +16,7 @@ test_perf 'sort(1)' '
 '
 
 test_perf 'string_list_sort()' '
-   test-string-list sort actual
+   test-tool string-list sort actual
 '
 
 test_expect_success 'string_list_sort() sorts like sort(1)' '
diff --git a/t/t0063-string-list.sh b/t/t0063-string-list.sh
index dbfc05ebdc..c6ee9f66b1 100755
--- a/t/t0063-string-list.sh
+++ b/t/t0063-string-list.sh
@@ -10,9 +10,9 @@ test_description='Test string list functionality'
 test_split () {
cat >expected &&
test_expect_success "split $1 at $2, max $3" "
-   test-string-list split '$1' '$2' '$3' >actual &&
+   test-tool string-list split '$1' '$2' '$3' >actual &&
test_cmp expected actual &&
-   test-string-list split_in_place '$1' '$2' '$3' >actual &&
+   test-tool string-list split_in_place '$1' '$2' '$3' >actual &&
test_cmp expected actual
"
 }
@@ -61,31 +61,31 @@ test_split ":" ":" "-1" <

[PATCH v2 33/36] t/helper: merge test-subprocess into test-tool

2018-03-24 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Makefile   | 2 +-
 t/helper/test-subprocess.c | 3 ++-
 t/helper/test-tool.c   | 1 +
 t/helper/test-tool.h   | 1 +
 t/t1501-work-tree.sh   | 2 +-
 5 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index c1dc9ff8d6..893ea64ca2 100644
--- a/Makefile
+++ b/Makefile
@@ -683,6 +683,7 @@ TEST_BUILTINS_OBJS += test-sigchain.o
 TEST_BUILTINS_OBJS += test-strcmp-offset.o
 TEST_BUILTINS_OBJS += test-string-list.o
 TEST_BUILTINS_OBJS += test-submodule-config.o
+TEST_BUILTINS_OBJS += test-subprocess.o
 
 TEST_PROGRAMS_NEED_X += test-dump-fsmonitor
 TEST_PROGRAMS_NEED_X += test-dump-untracked-cache
@@ -690,7 +691,6 @@ 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-write-cache
-TEST_PROGRAMS_NEED_X += test-subprocess
 TEST_PROGRAMS_NEED_X += test-svn-fe
 TEST_PROGRAMS_NEED_X += test-tool
 TEST_PROGRAMS_NEED_X += test-urlmatch-normalization
diff --git a/t/helper/test-subprocess.c b/t/helper/test-subprocess.c
index 30c5765bfc..92b69de635 100644
--- a/t/helper/test-subprocess.c
+++ b/t/helper/test-subprocess.c
@@ -1,7 +1,8 @@
+#include "test-tool.h"
 #include "cache.h"
 #include "run-command.h"
 
-int cmd_main(int argc, const char **argv)
+int cmd__subprocess(int argc, const char **argv)
 {
struct child_process cp = CHILD_PROCESS_INIT;
int nogit = 0;
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index 434fedc8d8..96180f0350 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -38,6 +38,7 @@ static struct test_cmd cmds[] = {
{ "strcmp-offset", cmd__strcmp_offset },
{ "string-list", cmd__string_list },
{ "submodule-config", cmd__submodule_config },
+   { "subprocess", cmd__subprocess },
 };
 
 int cmd_main(int argc, const char **argv)
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index be7e79738f..a611801061 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -32,5 +32,6 @@ 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);
 int cmd__submodule_config(int argc, const char **argv);
+int cmd__subprocess(int argc, const char **argv);
 
 #endif
diff --git a/t/t1501-work-tree.sh b/t/t1501-work-tree.sh
index b07cb9140e..02cf2013fc 100755
--- a/t/t1501-work-tree.sh
+++ b/t/t1501-work-tree.sh
@@ -341,7 +341,7 @@ test_expect_success 'make_relative_path handles double 
slashes in GIT_DIR' '
 
 test_expect_success 'relative $GIT_WORK_TREE and git subprocesses' '
GIT_DIR=repo.git GIT_WORK_TREE=repo.git/work \
-   test-subprocess --setup-work-tree rev-parse --show-toplevel >actual &&
+   test-tool subprocess --setup-work-tree rev-parse --show-toplevel 
>actual &&
echo "$(pwd)/repo.git/work" >expected &&
test_cmp expected actual
 '
-- 
2.17.0.rc0.348.gd5a49e0b6f



[PATCH v2 18/36] t/helper: merge test-mktemp into test-tool

2018-03-24 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Makefile   | 2 +-
 t/helper/test-mktemp.c | 3 ++-
 t/helper/test-tool.c   | 1 +
 t/helper/test-tool.h   | 1 +
 t/t0070-fundamental.sh | 4 ++--
 5 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/Makefile b/Makefile
index 67f37b849e..3145a9b1b2 100644
--- a/Makefile
+++ b/Makefile
@@ -667,13 +667,13 @@ TEST_BUILTINS_OBJS += test-index-version.o
 TEST_BUILTINS_OBJS += test-lazy-init-name-hash.o
 TEST_BUILTINS_OBJS += test-match-trees.o
 TEST_BUILTINS_OBJS += test-mergesort.o
+TEST_BUILTINS_OBJS += test-mktemp.o
 TEST_BUILTINS_OBJS += test-sha1.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-mktemp
 TEST_PROGRAMS_NEED_X += test-online-cpus
 TEST_PROGRAMS_NEED_X += test-parse-options
 TEST_PROGRAMS_NEED_X += test-path-utils
diff --git a/t/helper/test-mktemp.c b/t/helper/test-mktemp.c
index 89d9b2f7be..2290688940 100644
--- a/t/helper/test-mktemp.c
+++ b/t/helper/test-mktemp.c
@@ -1,9 +1,10 @@
 /*
  * test-mktemp.c: code to exercise the creation of temporary files
  */
+#include "test-tool.h"
 #include "git-compat-util.h"
 
-int cmd_main(int argc, const char **argv)
+int cmd__mktemp(int argc, const char **argv)
 {
if (argc != 2)
usage("Expected 1 parameter defining the temporary file 
template");
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index 7ec0e8efe5..fd3bf560d4 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -22,6 +22,7 @@ static struct test_cmd cmds[] = {
{ "lazy-init-name-hash", cmd__lazy_init_name_hash },
{ "match-trees", cmd__match_trees },
{ "mergesort", cmd__mergesort },
+   { "mktemp", cmd__mktemp },
{ "sha1", cmd__sha1 },
 };
 
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index 6c9437ff5e..cf2598798a 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -16,6 +16,7 @@ int cmd__index_version(int argc, const char **argv);
 int cmd__lazy_init_name_hash(int argc, const char **argv);
 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__sha1(int argc, const char **argv);
 
 #endif
diff --git a/t/t0070-fundamental.sh b/t/t0070-fundamental.sh
index 70d4d98a2e..ac007938ee 100755
--- a/t/t0070-fundamental.sh
+++ b/t/t0070-fundamental.sh
@@ -13,7 +13,7 @@ test_expect_success 'character classes (isspace, isalpha 
etc.)' '
 '
 
 test_expect_success 'mktemp to nonexistent directory prints filename' '
-   test_must_fail test-mktemp doesnotexist/testXX 2>err &&
+   test_must_fail test-tool mktemp doesnotexist/testXX 2>err &&
grep "doesnotexist/test" err
 '
 
@@ -21,7 +21,7 @@ test_expect_success POSIXPERM,SANITY 'mktemp to unwritable 
directory prints file
mkdir cannotwrite &&
chmod -w cannotwrite &&
test_when_finished "chmod +w cannotwrite" &&
-   test_must_fail test-mktemp cannotwrite/testXX 2>err &&
+   test_must_fail test-tool mktemp cannotwrite/testXX 2>err &&
grep "cannotwrite/test" err
 '
 
-- 
2.17.0.rc0.348.gd5a49e0b6f



[PATCH v2 15/36] t/helper: merge test-index-version into test-tool

2018-03-24 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Makefile  | 2 +-
 t/helper/test-index-version.c | 3 ++-
 t/helper/test-tool.c  | 1 +
 t/helper/test-tool.h  | 1 +
 t/t1600-index.sh  | 2 +-
 t/t1700-split-index.sh| 2 +-
 t/t2104-update-index-skip-worktree.sh | 6 +++---
 7 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/Makefile b/Makefile
index f6c3ddc703..d7342e3a8b 100644
--- a/Makefile
+++ b/Makefile
@@ -663,13 +663,13 @@ TEST_BUILTINS_OBJS += test-dump-split-index.o
 TEST_BUILTINS_OBJS += test-example-decorate.o
 TEST_BUILTINS_OBJS += test-genrandom.o
 TEST_BUILTINS_OBJS += test-hashmap.o
+TEST_BUILTINS_OBJS += test-index-version.o
 TEST_BUILTINS_OBJS += test-lazy-init-name-hash.o
 TEST_BUILTINS_OBJS += test-sha1.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-index-version
 TEST_PROGRAMS_NEED_X += test-line-buffer
 TEST_PROGRAMS_NEED_X += test-match-trees
 TEST_PROGRAMS_NEED_X += test-mergesort
diff --git a/t/helper/test-index-version.c b/t/helper/test-index-version.c
index f569f6b7ef..fcd10968cc 100644
--- a/t/helper/test-index-version.c
+++ b/t/helper/test-index-version.c
@@ -1,6 +1,7 @@
+#include "test-tool.h"
 #include "cache.h"
 
-int cmd_main(int argc, const char **argv)
+int cmd__index_version(int argc, const char **argv)
 {
struct cache_header hdr;
int version;
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index b9a6e7cbaa..88fbe8ddbd 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -18,6 +18,7 @@ static struct test_cmd cmds[] = {
{ "example-decorate", cmd__example_decorate },
{ "genrandom", cmd__genrandom },
{ "hashmap", cmd__hashmap },
+   { "index-version", cmd__index_version },
{ "lazy-init-name-hash", cmd__lazy_init_name_hash },
{ "sha1", cmd__sha1 },
 };
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index fba4bd80b9..b855203477 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -12,6 +12,7 @@ int cmd__dump_split_index(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);
+int cmd__index_version(int argc, const char **argv);
 int cmd__lazy_init_name_hash(int argc, const char **argv);
 int cmd__sha1(int argc, const char **argv);
 
diff --git a/t/t1600-index.sh b/t/t1600-index.sh
index 079d241145..c4422312f4 100755
--- a/t/t1600-index.sh
+++ b/t/t1600-index.sh
@@ -68,7 +68,7 @@ test_expect_success 'GIT_INDEX_VERSION takes precedence over 
config' '
git config --add index.version 2 &&
git add a 2>&1 &&
echo 4 >expect &&
-   test-index-version <.git/index >actual &&
+   test-tool index-version <.git/index >actual &&
test_cmp expect actual
)
 '
diff --git a/t/t1700-split-index.sh b/t/t1700-split-index.sh
index ec179fbaf7..e4f4c4df4e 100755
--- a/t/t1700-split-index.sh
+++ b/t/t1700-split-index.sh
@@ -12,7 +12,7 @@ test_expect_success 'enable split index' '
git config splitIndex.maxPercentChange 100 &&
git update-index --split-index &&
test-tool dump-split-index .git/index >actual &&
-   indexversion=$(test-index-version <.git/index) &&
+   indexversion=$(test-tool index-version <.git/index) &&
if test "$indexversion" = "4"
then
own=432ef4b63f32193984f339431fd50ca796493569
diff --git a/t/t2104-update-index-skip-worktree.sh 
b/t/t2104-update-index-skip-worktree.sh
index cc830da58d..7e2e7dd4ae 100755
--- a/t/t2104-update-index-skip-worktree.sh
+++ b/t/t2104-update-index-skip-worktree.sh
@@ -33,7 +33,7 @@ test_expect_success 'setup' '
 '
 
 test_expect_success 'index is at version 2' '
-   test "$(test-index-version < .git/index)" = 2
+   test "$(test-tool index-version < .git/index)" = 2
 '
 
 test_expect_success 'update-index --skip-worktree' '
@@ -42,7 +42,7 @@ test_expect_success 'update-index --skip-worktree' '
 '
 
 test_expect_success 'index is at version 3 after having some skip-worktree 
entries' '
-   test "$(test-index-version < .git/index)" = 3
+   test "$(test-tool index-version < .git/index)" = 3
 '
 
 test_expect_success 'ls-files -t' '
@@ -55,7 +55,7 @@ test_expect_success 'update-index --no-skip-worktree' '
 '
 
 test_expect_success 'index version is back to 2 when there is no skip-worktree 
entry' '
-   test "$(test-index-version < .git/index)" = 2
+   test "$(test-tool index-version < .git/index)" = 2
 '
 
 test_done
-- 
2.17.0.rc0.348.gd5a49e0b6f



[PATCH v2 32/36] t/helper: merge test-submodule-config into test-tool

2018-03-24 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Makefile |  2 +-
 t/helper/test-submodule-config.c |  3 ++-
 t/helper/test-tool.c |  1 +
 t/helper/test-tool.h |  1 +
 t/t7411-submodule-config.sh  | 18 +-
 5 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/Makefile b/Makefile
index 6819792c2b..c1dc9ff8d6 100644
--- a/Makefile
+++ b/Makefile
@@ -682,6 +682,7 @@ TEST_BUILTINS_OBJS += test-sha1.o
 TEST_BUILTINS_OBJS += test-sigchain.o
 TEST_BUILTINS_OBJS += test-strcmp-offset.o
 TEST_BUILTINS_OBJS += test-string-list.o
+TEST_BUILTINS_OBJS += test-submodule-config.o
 
 TEST_PROGRAMS_NEED_X += test-dump-fsmonitor
 TEST_PROGRAMS_NEED_X += test-dump-untracked-cache
@@ -689,7 +690,6 @@ 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-write-cache
-TEST_PROGRAMS_NEED_X += test-submodule-config
 TEST_PROGRAMS_NEED_X += test-subprocess
 TEST_PROGRAMS_NEED_X += test-svn-fe
 TEST_PROGRAMS_NEED_X += test-tool
diff --git a/t/helper/test-submodule-config.c b/t/helper/test-submodule-config.c
index f23db3b19a..5c6e4b010d 100644
--- a/t/helper/test-submodule-config.c
+++ b/t/helper/test-submodule-config.c
@@ -1,3 +1,4 @@
+#include "test-tool.h"
 #include "cache.h"
 #include "config.h"
 #include "submodule-config.h"
@@ -10,7 +11,7 @@ static void die_usage(int argc, const char **argv, const char 
*msg)
exit(1);
 }
 
-int cmd_main(int argc, const char **argv)
+int cmd__submodule_config(int argc, const char **argv)
 {
const char **arg = argv;
int my_argc = argc;
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index 90008533cd..434fedc8d8 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -37,6 +37,7 @@ static struct test_cmd cmds[] = {
{ "sigchain", cmd__sigchain },
{ "strcmp-offset", cmd__strcmp_offset },
{ "string-list", cmd__string_list },
+   { "submodule-config", cmd__submodule_config },
 };
 
 int cmd_main(int argc, const char **argv)
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index 19ad2b0df8..be7e79738f 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -31,5 +31,6 @@ int cmd__sha1(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);
+int cmd__submodule_config(int argc, const char **argv);
 
 #endif
diff --git a/t/t7411-submodule-config.sh b/t/t7411-submodule-config.sh
index 46c09c7765..0bde5850ac 100755
--- a/t/t7411-submodule-config.sh
+++ b/t/t7411-submodule-config.sh
@@ -41,7 +41,7 @@ test_expect_success 'configuration parsing with error' '
EOF
(
cd repo &&
-   test_must_fail test-submodule-config "" s 2>actual &&
+   test_must_fail test-tool submodule-config "" s 2>actual &&
test_i18ngrep "bad config" actual
)
 '
@@ -55,7 +55,7 @@ EOF
 
 test_expect_success 'test parsing and lookup of submodule config by path' '
(cd super &&
-   test-submodule-config \
+   test-tool submodule-config \
HEAD^ a \
HEAD b \
HEAD^ submodule \
@@ -67,7 +67,7 @@ test_expect_success 'test parsing and lookup of submodule 
config by path' '
 
 test_expect_success 'test parsing and lookup of submodule config by name' '
(cd super &&
-   test-submodule-config --name \
+   test-tool submodule-config --name \
HEAD^ a \
HEAD a \
HEAD^ submodule \
@@ -89,7 +89,7 @@ test_expect_success 'error in one submodule config lets 
continue' '
git add .gitmodules &&
mv .gitmodules.bak .gitmodules &&
git commit -m "add error" &&
-   test-submodule-config \
+   test-tool submodule-config \
HEAD b \
HEAD submodule \
>actual &&
@@ -100,7 +100,7 @@ test_expect_success 'error in one submodule config lets 
continue' '
 test_expect_success 'error message contains blob reference' '
(cd super &&
sha1=$(git rev-parse HEAD) &&
-   test-submodule-config \
+   test-tool submodule-config \
HEAD b \
HEAD submodule \
2>actual_err &&
@@ -114,9 +114,9 @@ test_expect_success 'using different treeishs works' '
git tag new_tag &&
tree=$(git rev-parse HEAD^{tree}) &&
commit=$(git rev-parse HEAD^{commit}) &&
-   test-submodule-config $commit b >expect &&
-   test-submodule-config $tree b >actual.1 &&
-   

[PATCH v2 29/36] t/helper: merge test-sigchain into test-tool

2018-03-24 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Makefile | 2 +-
 t/helper/test-sigchain.c | 3 ++-
 t/helper/test-tool.c | 1 +
 t/helper/test-tool.h | 1 +
 t/t0005-signals.sh   | 4 ++--
 5 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/Makefile b/Makefile
index b50a0818a9..51de8882d0 100644
--- a/Makefile
+++ b/Makefile
@@ -679,6 +679,7 @@ 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-sigchain.o
 
 TEST_PROGRAMS_NEED_X += test-dump-fsmonitor
 TEST_PROGRAMS_NEED_X += test-dump-untracked-cache
@@ -686,7 +687,6 @@ 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-write-cache
-TEST_PROGRAMS_NEED_X += test-sigchain
 TEST_PROGRAMS_NEED_X += test-strcmp-offset
 TEST_PROGRAMS_NEED_X += test-string-list
 TEST_PROGRAMS_NEED_X += test-submodule-config
diff --git a/t/helper/test-sigchain.c b/t/helper/test-sigchain.c
index b71edbd442..77ac5bc33f 100644
--- a/t/helper/test-sigchain.c
+++ b/t/helper/test-sigchain.c
@@ -1,3 +1,4 @@
+#include "test-tool.h"
 #include "cache.h"
 #include "sigchain.h"
 
@@ -13,7 +14,7 @@ X(two)
 X(three)
 #undef X
 
-int cmd_main(int argc, const char **argv) {
+int cmd__sigchain(int argc, const char **argv) {
sigchain_push(SIGTERM, one);
sigchain_push(SIGTERM, two);
sigchain_push(SIGTERM, three);
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index 27f7b6ff75..c1de1a3397 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -34,6 +34,7 @@ static struct test_cmd cmds[] = {
{ "scrap-cache-tree", cmd__scrap_cache_tree },
{ "sha1-array", cmd__sha1_array },
{ "sha1", cmd__sha1 },
+   { "sigchain", cmd__sigchain },
 };
 
 int cmd_main(int argc, const char **argv)
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index d8066e3f63..1d366846f3 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -28,5 +28,6 @@ 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__sigchain(int argc, const char **argv);
 
 #endif
diff --git a/t/t0005-signals.sh b/t/t0005-signals.sh
index c16947cf5d..4c214bd11c 100755
--- a/t/t0005-signals.sh
+++ b/t/t0005-signals.sh
@@ -10,7 +10,7 @@ one
 EOF
 
 test_expect_success 'sigchain works' '
-   { test-sigchain >actual; ret=$?; } &&
+   { test-tool sigchain >actual; ret=$?; } &&
{
# Signal death by raise() on Windows acts like exit(3),
# regardless of the signal number. So we must allow that
@@ -24,7 +24,7 @@ test_expect_success 'sigchain works' '
 test_expect_success !MINGW 'signals are propagated using shell convention' '
# we use exec here to avoid any sub-shell interpretation
# of the exit code
-   git config alias.sigterm "!exec test-sigchain" &&
+   git config alias.sigterm "!exec test-tool sigchain" &&
test_expect_code 143 git sigterm
 '
 
-- 
2.17.0.rc0.348.gd5a49e0b6f



[PATCH v2 26/36] t/helper: merge test-run-command into test-tool

2018-03-24 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Makefile|  2 +-
 t/helper/test-run-command.c |  3 ++-
 t/helper/test-tool.c|  1 +
 t/helper/test-tool.h|  1 +
 t/t0061-run-command.sh  | 24 
 5 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/Makefile b/Makefile
index 3ed461cd55..adece67b8e 100644
--- a/Makefile
+++ b/Makefile
@@ -675,6 +675,7 @@ TEST_BUILTINS_OBJS += test-read-cache.o
 TEST_BUILTINS_OBJS += test-ref-store.o
 TEST_BUILTINS_OBJS += test-regex.o
 TEST_BUILTINS_OBJS += test-revision-walking.o
+TEST_BUILTINS_OBJS += test-run-command.o
 TEST_BUILTINS_OBJS += test-sha1.o
 
 TEST_PROGRAMS_NEED_X += test-dump-fsmonitor
@@ -683,7 +684,6 @@ 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-write-cache
-TEST_PROGRAMS_NEED_X += test-run-command
 TEST_PROGRAMS_NEED_X += test-scrap-cache-tree
 TEST_PROGRAMS_NEED_X += test-sha1-array
 TEST_PROGRAMS_NEED_X += test-sigchain
diff --git a/t/helper/test-run-command.c b/t/helper/test-run-command.c
index 153342e44d..2cc93bb69c 100644
--- a/t/helper/test-run-command.c
+++ b/t/helper/test-run-command.c
@@ -8,6 +8,7 @@
  * published by the Free Software Foundation.
  */
 
+#include "test-tool.h"
 #include "git-compat-util.h"
 #include "run-command.h"
 #include "argv-array.h"
@@ -49,7 +50,7 @@ static int task_finished(int result,
return 1;
 }
 
-int cmd_main(int argc, const char **argv)
+int cmd__run_command(int argc, const char **argv)
 {
struct child_process proc = CHILD_PROCESS_INIT;
int jobs;
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index e43405bea9..94ceda66e7 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -30,6 +30,7 @@ static struct test_cmd cmds[] = {
{ "ref-store", cmd__ref_store },
{ "regex", cmd__regex },
{ "revision-walking", cmd__revision_walking },
+   { "run-command", cmd__run_command },
{ "sha1", cmd__sha1 },
 };
 
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index 4dff220646..0fe2dd640b 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -24,6 +24,7 @@ int cmd__read_cache(int argc, const char **argv);
 int cmd__ref_store(int argc, const char **argv);
 int cmd__regex(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__sha1(int argc, const char **argv);
 
 #endif
diff --git a/t/t0061-run-command.sh b/t/t0061-run-command.sh
index 24c92b6cd7..d03149be9f 100755
--- a/t/t0061-run-command.sh
+++ b/t/t0061-run-command.sh
@@ -14,13 +14,13 @@ EOF
 >empty
 
 test_expect_success 'start_command reports ENOENT' '
-   test-run-command start-command-ENOENT ./does-not-exist
+   test-tool run-command start-command-ENOENT ./does-not-exist
 '
 
 test_expect_success 'run_command can run a command' '
cat hello-script >hello.sh &&
chmod +x hello.sh &&
-   test-run-command run-command ./hello.sh >actual 2>err &&
+   test-tool run-command run-command ./hello.sh >actual 2>err &&
 
test_cmp hello-script actual &&
test_cmp empty err
@@ -31,7 +31,7 @@ test_expect_success !MINGW 'run_command can run a script 
without a #! line' '
cat hello-script
EOF
chmod +x hello &&
-   test-run-command run-command ./hello >actual 2>err &&
+   test-tool run-command run-command ./hello >actual 2>err &&
 
test_cmp hello-script actual &&
test_cmp empty err
@@ -45,7 +45,7 @@ test_expect_success 'run_command does not try to execute a 
directory' '
EOF
 
PATH=$PWD/bin1:$PWD/bin2:$PATH \
-   test-run-command run-command greet >actual 2>err &&
+   test-tool run-command run-command greet >actual 2>err &&
test_cmp bin2/greet actual &&
test_cmp empty err
 '
@@ -62,7 +62,7 @@ test_expect_success POSIXPERM 'run_command passes over 
non-executable file' '
EOF
 
PATH=$PWD/bin1:$PWD/bin2:$PATH \
-   test-run-command run-command greet >actual 2>err &&
+   test-tool run-command run-command greet >actual 2>err &&
test_cmp bin2/greet actual &&
test_cmp empty err
 '
@@ -70,7 +70,7 @@ test_expect_success POSIXPERM 'run_command passes over 
non-executable file' '
 test_expect_success POSIXPERM 'run_command reports EACCES' '
cat hello-script >hello.sh &&
chmod -x hello.sh &&
-   test_must_fail test-run-command run-command ./hello.sh 2>err &&
+   test_must_fail test-tool run-command run-command ./hello.sh 2>err &&
 
grep "fatal: cannot exec.*hello.sh" err
 '
@@ -104,17 +104,17 @@ World
 EOF
 
 test_expect_success 'run_command runs in parallel with more jobs available 
than tasks' '
-   test-run-command run-command-parallel 5 sh -c "printf \"%s\n%s\n\" 
Hello World" 2>actual &&

[PATCH v2 27/36] t/helper: merge test-scrap-cache-tree into test-tool

2018-03-24 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Makefile | 2 +-
 t/helper/test-scrap-cache-tree.c | 3 ++-
 t/helper/test-tool.c | 1 +
 t/helper/test-tool.h | 1 +
 t/t0090-cache-tree.sh| 8 
 5 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/Makefile b/Makefile
index adece67b8e..ba7c7d8a79 100644
--- a/Makefile
+++ b/Makefile
@@ -676,6 +676,7 @@ TEST_BUILTINS_OBJS += test-ref-store.o
 TEST_BUILTINS_OBJS += test-regex.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.o
 
 TEST_PROGRAMS_NEED_X += test-dump-fsmonitor
@@ -684,7 +685,6 @@ 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-write-cache
-TEST_PROGRAMS_NEED_X += test-scrap-cache-tree
 TEST_PROGRAMS_NEED_X += test-sha1-array
 TEST_PROGRAMS_NEED_X += test-sigchain
 TEST_PROGRAMS_NEED_X += test-strcmp-offset
diff --git a/t/helper/test-scrap-cache-tree.c b/t/helper/test-scrap-cache-tree.c
index d2a63bea43..d26d3e7c8b 100644
--- a/t/helper/test-scrap-cache-tree.c
+++ b/t/helper/test-scrap-cache-tree.c
@@ -1,3 +1,4 @@
+#include "test-tool.h"
 #include "cache.h"
 #include "lockfile.h"
 #include "tree.h"
@@ -5,7 +6,7 @@
 
 static struct lock_file index_lock;
 
-int cmd_main(int ac, const char **av)
+int cmd__scrap_cache_tree(int ac, const char **av)
 {
setup_git_directory();
hold_locked_index(_lock, LOCK_DIE_ON_ERROR);
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index 94ceda66e7..96d8df69d4 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -31,6 +31,7 @@ static struct test_cmd cmds[] = {
{ "regex", cmd__regex },
{ "revision-walking", cmd__revision_walking },
{ "run-command", cmd__run_command },
+   { "scrap-cache-tree", cmd__scrap_cache_tree },
{ "sha1", cmd__sha1 },
 };
 
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index 0fe2dd640b..448119a44a 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -25,6 +25,7 @@ int cmd__ref_store(int argc, const char **argv);
 int cmd__regex(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(int argc, const char **argv);
 
 #endif
diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh
index 3266209e41..4ae0995cd9 100755
--- a/t/t0090-cache-tree.sh
+++ b/t/t0090-cache-tree.sh
@@ -115,14 +115,14 @@ test_expect_success 'update-index invalidates cache-tree' 
'
 '
 
 test_expect_success 'write-tree establishes cache-tree' '
-   test-scrap-cache-tree &&
+   test-tool scrap-cache-tree &&
git write-tree &&
test_cache_tree
 '
 
-test_expect_success 'test-scrap-cache-tree works' '
+test_expect_success 'test-tool scrap-cache-tree works' '
git read-tree HEAD &&
-   test-scrap-cache-tree &&
+   test-tool scrap-cache-tree &&
test_no_cache_tree
 '
 
@@ -170,7 +170,7 @@ test_expect_success 'commit in child dir has cache-tree' '
 '
 
 test_expect_success 'reset --hard gives cache-tree' '
-   test-scrap-cache-tree &&
+   test-tool scrap-cache-tree &&
git reset --hard &&
test_cache_tree
 '
-- 
2.17.0.rc0.348.gd5a49e0b6f



[PATCH v2 14/36] t/helper: merge test-hashmap into test-tool

2018-03-24 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Makefile| 2 +-
 t/helper/test-hashmap.c | 5 +++--
 t/helper/test-tool.c| 1 +
 t/helper/test-tool.h| 1 +
 t/t0011-hashmap.sh  | 4 ++--
 5 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/Makefile b/Makefile
index d0bc6cfecf..f6c3ddc703 100644
--- a/Makefile
+++ b/Makefile
@@ -662,13 +662,13 @@ TEST_BUILTINS_OBJS += test-dump-cache-tree.o
 TEST_BUILTINS_OBJS += test-dump-split-index.o
 TEST_BUILTINS_OBJS += test-example-decorate.o
 TEST_BUILTINS_OBJS += test-genrandom.o
+TEST_BUILTINS_OBJS += test-hashmap.o
 TEST_BUILTINS_OBJS += test-lazy-init-name-hash.o
 TEST_BUILTINS_OBJS += test-sha1.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-hashmap
 TEST_PROGRAMS_NEED_X += test-index-version
 TEST_PROGRAMS_NEED_X += test-line-buffer
 TEST_PROGRAMS_NEED_X += test-match-trees
diff --git a/t/helper/test-hashmap.c b/t/helper/test-hashmap.c
index 9ae9281c07..23d2b172fe 100644
--- a/t/helper/test-hashmap.c
+++ b/t/helper/test-hashmap.c
@@ -1,3 +1,4 @@
+#include "test-tool.h"
 #include "git-compat-util.h"
 #include "hashmap.h"
 #include "strbuf.h"
@@ -77,7 +78,7 @@ static unsigned int hash(unsigned int method, unsigned int i, 
const char *key)
 
 /*
  * Test performance of hashmap.[ch]
- * Usage: time echo "perfhashmap method rounds" | test-hashmap
+ * Usage: time echo "perfhashmap method rounds" | test-tool hashmap
  */
 static void perf_hashmap(unsigned int method, unsigned int rounds)
 {
@@ -144,7 +145,7 @@ static void perf_hashmap(unsigned int method, unsigned int 
rounds)
  *
  * perfhashmap method rounds -> test hashmap.[ch] performance
  */
-int cmd_main(int argc, const char **argv)
+int cmd__hashmap(int argc, const char **argv)
 {
struct strbuf line = STRBUF_INIT;
struct hashmap map;
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index eb20b7d8fe..b9a6e7cbaa 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -17,6 +17,7 @@ static struct test_cmd cmds[] = {
{ "dump-split-index", cmd__dump_split_index },
{ "example-decorate", cmd__example_decorate },
{ "genrandom", cmd__genrandom },
+   { "hashmap", cmd__hashmap },
{ "lazy-init-name-hash", cmd__lazy_init_name_hash },
{ "sha1", cmd__sha1 },
 };
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index f7ec6ae0c3..fba4bd80b9 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -11,6 +11,7 @@ int cmd__dump_cache_tree(int argc, const char **argv);
 int cmd__dump_split_index(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);
 int cmd__lazy_init_name_hash(int argc, const char **argv);
 int cmd__sha1(int argc, const char **argv);
 
diff --git a/t/t0011-hashmap.sh b/t/t0011-hashmap.sh
index 9c217d948c..3f1f505e89 100755
--- a/t/t0011-hashmap.sh
+++ b/t/t0011-hashmap.sh
@@ -4,7 +4,7 @@ test_description='test hashmap and string hash functions'
 . ./test-lib.sh
 
 test_hashmap() {
-   echo "$1" | test-hashmap $3 > actual &&
+   echo "$1" | test-tool hashmap $3 > actual &&
echo "$2" > expect &&
test_cmp expect actual
 }
@@ -232,7 +232,7 @@ test_expect_success 'grow / shrink' '
echo value40 >> expect &&
echo size >> in &&
echo 64 39 >> expect &&
-   cat in | test-hashmap > out &&
+   cat in | test-tool hashmap > out &&
test_cmp expect out
 
 '
-- 
2.17.0.rc0.348.gd5a49e0b6f



[PATCH v2 12/36] t/helper: merge test-example-decorate into test-tool

2018-03-24 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Makefile | 2 +-
 t/helper/test-example-decorate.c | 3 ++-
 t/helper/test-tool.c | 1 +
 t/helper/test-tool.h | 1 +
 t/t9004-example.sh   | 2 +-
 5 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index 8993cec274..895b170fe3 100644
--- a/Makefile
+++ b/Makefile
@@ -660,12 +660,12 @@ 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-example-decorate.o
 TEST_BUILTINS_OBJS += test-lazy-init-name-hash.o
 TEST_BUILTINS_OBJS += test-sha1.o
 
 TEST_PROGRAMS_NEED_X += test-dump-fsmonitor
 TEST_PROGRAMS_NEED_X += test-dump-untracked-cache
-TEST_PROGRAMS_NEED_X += test-example-decorate
 TEST_PROGRAMS_NEED_X += test-fake-ssh
 TEST_PROGRAMS_NEED_X += test-genrandom
 TEST_PROGRAMS_NEED_X += test-hashmap
diff --git a/t/helper/test-example-decorate.c b/t/helper/test-example-decorate.c
index 90dc97a9d0..081115bf8e 100644
--- a/t/helper/test-example-decorate.c
+++ b/t/helper/test-example-decorate.c
@@ -1,8 +1,9 @@
+#include "test-tool.h"
 #include "cache.h"
 #include "object.h"
 #include "decorate.h"
 
-int cmd_main(int argc, const char **argv)
+int cmd__example_decorate(int argc, const char **argv)
 {
struct decoration n;
struct object_id one_oid = { {1} };
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index 26ae209cd5..a0e95c13ed 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 },
+   { "example-decorate", cmd__example_decorate },
{ "lazy-init-name-hash", cmd__lazy_init_name_hash },
{ "sha1", cmd__sha1 },
 };
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index e8363e851f..721a1e1b09 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -9,6 +9,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__example_decorate(int argc, const char **argv);
 int cmd__lazy_init_name_hash(int argc, const char **argv);
 int cmd__sha1(int argc, const char **argv);
 
diff --git a/t/t9004-example.sh b/t/t9004-example.sh
index b28a028f55..7e8894a4a7 100755
--- a/t/t9004-example.sh
+++ b/t/t9004-example.sh
@@ -4,7 +4,7 @@ test_description='check that example code compiles and runs'
 . ./test-lib.sh
 
 test_expect_success 'decorate' '
-   test-example-decorate
+   test-tool example-decorate
 '
 
 test_done
-- 
2.17.0.rc0.348.gd5a49e0b6f



[PATCH v2 00/36] Combine t/helper binaries into a single one

2018-03-24 Thread Nguyễn Thái Ngọc Duy
v2 fixes a couple of typos in commit messages and use the cmd__ prefix
for test commands instead of test_, which avoids a naming conflict
with the existing function test_lazy_init_name_hash

[the previous v2 send out was aborted because I messed it up with some
other patches]

Nguyễn Thái Ngọc Duy (36):
  t/helper: add an empty test-tool program
  t/helper: merge test-chmtime into test-tool
  t/helper: merge test-sha1 into test-tool
  t/helper: merge test-lazy-init-name-hash into test-tool
  t/helper: merge test-config into test-tool
  t/helper: merge test-ctype into test-tool
  t/helper: merge test-date into test-tool
  t/helper: merge (unused) test-delta into test-tool
  t/helper: merge test-drop-caches into test-tool
  t/helper: merge test-dump-cache-tree into test-tool
  t/helper: merge test-dump-split-index into test-tool
  t/helper: merge test-example-decorate into test-tool
  t/helper: merge test-genrandom into test-tool
  t/helper: merge test-hashmap into test-tool
  t/helper: merge test-index-version into test-tool
  t/helper: merge (unused) test-match-trees into test-tool
  t/helper: merge (unused) test-mergesort into test-tool
  t/helper: merge test-mktemp into test-tool
  t/helper: merge test-online-cpus into test-tool
  t/helper: merge test-path-utils into test-tool
  t/helper: merge test-prio-queue into test-tool
  t/helper: merge test-read-cache into test-tool
  t/helper: merge test-ref-store into test-tool
  t/helper: merge test-regex into test-tool
  t/helper: merge test-revision-walking into test-tool
  t/helper: merge test-run-command into test-tool
  t/helper: merge test-scrap-cache-tree into test-tool
  t/helper: merge test-sha1-array into test-tool
  t/helper: merge test-sigchain into test-tool
  t/helper: merge test-strcmp-offset into test-tool
  t/helper: merge test-string-list into test-tool
  t/helper: merge test-submodule-config into test-tool
  t/helper: merge test-subprocess into test-tool
  t/helper: merge test-urlmatch-normalization into test-tool
  t/helper: merge test-wildmatch into test-tool
  t/helper: merge test-write-cache into test-tool

 .../howto/recover-corrupted-object-harder.txt |   2 +-
 Makefile  |  79 +++---
 t/helper/test-chmtime.c   |  15 +-
 t/helper/test-config.c|   5 +-
 t/helper/test-ctype.c |   3 +-
 t/helper/test-date.c  |  17 +-
 t/helper/test-delta.c |   5 +-
 t/helper/test-drop-caches.c   |   3 +-
 t/helper/test-dump-cache-tree.c   |   3 +-
 t/helper/test-dump-split-index.c  |   3 +-
 t/helper/test-example-decorate.c  |   3 +-
 t/helper/test-genrandom.c |   3 +-
 t/helper/test-hashmap.c   |   5 +-
 t/helper/test-index-version.c |   3 +-
 t/helper/test-lazy-init-name-hash.c   |  13 +-
 t/helper/test-match-trees.c   |   3 +-
 t/helper/test-mergesort.c |   3 +-
 t/helper/test-mktemp.c|   3 +-
 t/helper/test-online-cpus.c   |   3 +-
 t/helper/test-path-utils.c|   3 +-
 t/helper/test-prio-queue.c|   3 +-
 t/helper/test-read-cache.c|   3 +-
 t/helper/test-ref-store.c |   3 +-
 t/helper/test-regex.c |   7 +-
 t/helper/test-revision-walking.c  |   3 +-
 t/helper/test-run-command.c   |   3 +-
 t/helper/test-scrap-cache-tree.c  |   3 +-
 t/helper/test-sha1-array.c|   3 +-
 t/helper/test-sha1.c  |   3 +-
 t/helper/test-sha1.sh |   4 +-
 t/helper/test-sigchain.c  |   3 +-
 t/helper/test-strcmp-offset.c |   3 +-
 t/helper/test-string-list.c   |   3 +-
 t/helper/test-submodule-config.c  |   3 +-
 t/helper/test-subprocess.c|   3 +-
 t/helper/test-tool.c  |  62 
 t/helper/test-tool.h  |  40 +++
 t/helper/test-urlmatch-normalization.c|   5 +-
 t/helper/test-wildmatch.c |   3 +-
 t/helper/test-write-cache.c   |   3 +-
 t/lib-git-p4.sh   |   2 +-
 t/lib-git-svn.sh  |   2 +-
 t/lib-pack.sh |   2 +-
 t/perf/p0002-read-cache.sh|   2 +-
 t/perf/p0004-lazy-init-name-hash.sh   |   8 +-
 t/perf/p0007-write-cache.sh   |   2 +-
 t/perf/p0071-sort.sh  |   2 +-
 t/perf/p7519-fsmonitor.sh |  12 +-
 t/t0005-signals.sh|   6 +-
 t/t0006-date.sh   |   8 +-
 t/t0009-prio-queue.sh |   6 +-
 t/t0011-hashmap.sh 

[PATCH v2 13/36] t/helper: merge test-genrandom into test-tool

2018-03-24 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Makefile  |  2 +-
 t/helper/test-genrandom.c |  3 ++-
 t/helper/test-tool.c  |  1 +
 t/helper/test-tool.h  |  1 +
 t/t0005-signals.sh|  2 +-
 t/t0021-conversion.sh |  4 ++--
 t/t1006-cat-file.sh   |  2 +-
 t/t1050-large.sh  |  6 +++---
 t/t5000-tar-tree.sh   |  2 +-
 t/t5300-pack-object.sh|  4 ++--
 t/t5301-sliding-window.sh |  2 +-
 t/t5302-pack-index.sh | 14 +++---
 t/t5303-pack-corruption-resilience.sh | 10 +-
 t/t5310-pack-bitmaps.sh   |  2 +-
 t/t5313-pack-bounds-checks.sh |  4 ++--
 t/t5314-pack-cycle-detection.sh   |  2 +-
 t/t5316-pack-delta-depth.sh   |  2 +-
 t/t5546-receive-limits.sh |  2 +-
 t/t5547-push-quarantine.sh|  2 +-
 t/t5608-clone-2gb.sh  |  2 +-
 t/t9300-fast-import.sh|  2 +-
 t/t9802-git-p4-filetype.sh|  2 +-
 22 files changed, 38 insertions(+), 35 deletions(-)

diff --git a/Makefile b/Makefile
index 895b170fe3..d0bc6cfecf 100644
--- a/Makefile
+++ b/Makefile
@@ -661,13 +661,13 @@ 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-example-decorate.o
+TEST_BUILTINS_OBJS += test-genrandom.o
 TEST_BUILTINS_OBJS += test-lazy-init-name-hash.o
 TEST_BUILTINS_OBJS += test-sha1.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-genrandom
 TEST_PROGRAMS_NEED_X += test-hashmap
 TEST_PROGRAMS_NEED_X += test-index-version
 TEST_PROGRAMS_NEED_X += test-line-buffer
diff --git a/t/helper/test-genrandom.c b/t/helper/test-genrandom.c
index 8d11d22d98..99b8dc1e2d 100644
--- a/t/helper/test-genrandom.c
+++ b/t/helper/test-genrandom.c
@@ -4,9 +4,10 @@
  * Copyright (C) 2007 by Nicolas Pitre, licensed under the GPL version 2.
  */
 
+#include "test-tool.h"
 #include "git-compat-util.h"
 
-int cmd_main(int argc, const char **argv)
+int cmd__genrandom(int argc, const char **argv)
 {
unsigned long count, next = 0;
unsigned char *c;
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index a0e95c13ed..eb20b7d8fe 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -16,6 +16,7 @@ static struct test_cmd cmds[] = {
{ "dump-cache-tree", cmd__dump_cache_tree },
{ "dump-split-index", cmd__dump_split_index },
{ "example-decorate", cmd__example_decorate },
+   { "genrandom", cmd__genrandom },
{ "lazy-init-name-hash", cmd__lazy_init_name_hash },
{ "sha1", cmd__sha1 },
 };
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index 721a1e1b09..f7ec6ae0c3 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -10,6 +10,7 @@ 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__example_decorate(int argc, const char **argv);
+int cmd__genrandom(int argc, const char **argv);
 int cmd__lazy_init_name_hash(int argc, const char **argv);
 int cmd__sha1(int argc, const char **argv);
 
diff --git a/t/t0005-signals.sh b/t/t0005-signals.sh
index 46042f1f13..c16947cf5d 100755
--- a/t/t0005-signals.sh
+++ b/t/t0005-signals.sh
@@ -36,7 +36,7 @@ large_git () {
 }
 
 test_expect_success 'create blob' '
-   test-genrandom foo 16384 >file &&
+   test-tool genrandom foo 16384 >file &&
git add file
 '
 
diff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh
index 46f8e583c3..9479a4aaab 100755
--- a/t/t0021-conversion.sh
+++ b/t/t0021-conversion.sh
@@ -19,7 +19,7 @@ write_script rot13-filter.pl "$PERL_PATH" \
 generate_random_characters () {
LEN=$1
NAME=$2
-   test-genrandom some-seed $LEN |
+   test-tool genrandom some-seed $LEN |
perl -pe "s/./chr((ord($&) % 26) + ord('a'))/sge" 
>"$TEST_ROOT/$NAME"
 }
 
@@ -267,7 +267,7 @@ test_expect_success 'filtering large input to small output 
should use little mem
 '
 
 test_expect_success 'filter that does not read is fine' '
-   test-genrandom foo $((128 * 1024 + 1)) >big &&
+   test-tool genrandom foo $((128 * 1024 + 1)) >big &&
echo "big filter=epipe" >.gitattributes &&
test_config filter.epipe.clean "echo xyzzy" &&
git add big &&
diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh
index b19f332694..2ac3b940c6 100755
--- a/t/t1006-cat-file.sh
+++ b/t/t1006-cat-file.sh
@@ -282,7 +282,7 @@ test_expect_success "--batch-check with multiple sha1s 
gives correct format" '
 '
 
 test_expect_success 'setup blobs which are likely to delta' '
-   test-genrandom foo 10240 >foo &&
+   test-tool 

[PATCH v2 09/36] t/helper: merge test-drop-caches into test-tool

2018-03-24 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Makefile|  2 +-
 t/helper/test-drop-caches.c |  3 ++-
 t/helper/test-tool.c|  1 +
 t/helper/test-tool.h|  1 +
 t/perf/p7519-fsmonitor.sh   | 12 ++--
 5 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/Makefile b/Makefile
index 327d63217a..edd9c43982 100644
--- a/Makefile
+++ b/Makefile
@@ -657,10 +657,10 @@ TEST_BUILTINS_OBJS += test-config.o
 TEST_BUILTINS_OBJS += test-ctype.o
 TEST_BUILTINS_OBJS += test-date.o
 TEST_BUILTINS_OBJS += test-delta.o
+TEST_BUILTINS_OBJS += test-drop-caches.o
 TEST_BUILTINS_OBJS += test-lazy-init-name-hash.o
 TEST_BUILTINS_OBJS += test-sha1.o
 
-TEST_PROGRAMS_NEED_X += test-drop-caches
 TEST_PROGRAMS_NEED_X += test-dump-cache-tree
 TEST_PROGRAMS_NEED_X += test-dump-fsmonitor
 TEST_PROGRAMS_NEED_X += test-dump-split-index
diff --git a/t/helper/test-drop-caches.c b/t/helper/test-drop-caches.c
index bd1a857d52..838760898b 100644
--- a/t/helper/test-drop-caches.c
+++ b/t/helper/test-drop-caches.c
@@ -1,3 +1,4 @@
+#include "test-tool.h"
 #include "git-compat-util.h"
 
 #if defined(GIT_WINDOWS_NATIVE)
@@ -157,7 +158,7 @@ static int cmd_dropcaches(void)
 
 #endif
 
-int cmd_main(int argc, const char **argv)
+int cmd__drop_caches(int argc, const char **argv)
 {
cmd_sync();
return cmd_dropcaches();
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index 6bef386842..b6f648d387 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -12,6 +12,7 @@ static struct test_cmd cmds[] = {
{ "ctype", cmd__ctype },
{ "date", cmd__date },
{ "delta", cmd__delta },
+   { "drop-caches", cmd__drop_caches },
{ "lazy-init-name-hash", cmd__lazy_init_name_hash },
{ "sha1", cmd__sha1 },
 };
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index 761705e110..f585b7776e 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -6,6 +6,7 @@ int cmd__config(int argc, const char **argv);
 int cmd__ctype(int argc, const char **argv);
 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__lazy_init_name_hash(int argc, const char **argv);
 int cmd__sha1(int argc, const char **argv);
 
diff --git a/t/perf/p7519-fsmonitor.sh b/t/perf/p7519-fsmonitor.sh
index 65e145c02d..def7ecdbc7 100755
--- a/t/perf/p7519-fsmonitor.sh
+++ b/t/perf/p7519-fsmonitor.sh
@@ -118,7 +118,7 @@ test_expect_success "setup for fsmonitor" '
 '
 
 if test -n "$GIT_PERF_7519_DROP_CACHE"; then
-   test-drop-caches
+   test-tool drop-caches
 fi
 
 test_perf "status (fsmonitor=$INTEGRATION_SCRIPT)" '
@@ -126,7 +126,7 @@ test_perf "status (fsmonitor=$INTEGRATION_SCRIPT)" '
 '
 
 if test -n "$GIT_PERF_7519_DROP_CACHE"; then
-   test-drop-caches
+   test-tool drop-caches
 fi
 
 test_perf "status -uno (fsmonitor=$INTEGRATION_SCRIPT)" '
@@ -134,7 +134,7 @@ test_perf "status -uno (fsmonitor=$INTEGRATION_SCRIPT)" '
 '
 
 if test -n "$GIT_PERF_7519_DROP_CACHE"; then
-   test-drop-caches
+   test-tool drop-caches
 fi
 
 test_perf "status -uall (fsmonitor=$INTEGRATION_SCRIPT)" '
@@ -148,7 +148,7 @@ test_expect_success "setup without fsmonitor" '
 '
 
 if test -n "$GIT_PERF_7519_DROP_CACHE"; then
-   test-drop-caches
+   test-tool drop-caches
 fi
 
 test_perf "status (fsmonitor=$INTEGRATION_SCRIPT)" '
@@ -156,7 +156,7 @@ test_perf "status (fsmonitor=$INTEGRATION_SCRIPT)" '
 '
 
 if test -n "$GIT_PERF_7519_DROP_CACHE"; then
-   test-drop-caches
+   test-tool drop-caches
 fi
 
 test_perf "status -uno (fsmonitor=$INTEGRATION_SCRIPT)" '
@@ -164,7 +164,7 @@ test_perf "status -uno (fsmonitor=$INTEGRATION_SCRIPT)" '
 '
 
 if test -n "$GIT_PERF_7519_DROP_CACHE"; then
-   test-drop-caches
+   test-tool drop-caches
 fi
 
 test_perf "status -uall (fsmonitor=$INTEGRATION_SCRIPT)" '
-- 
2.17.0.rc0.348.gd5a49e0b6f



[PATCH v2 08/36] t/helper: merge (unused) test-delta into test-tool

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

diff --git a/Makefile b/Makefile
index efb1872c52..327d63217a 100644
--- a/Makefile
+++ b/Makefile
@@ -656,10 +656,10 @@ TEST_BUILTINS_OBJS += test-chmtime.o
 TEST_BUILTINS_OBJS += test-config.o
 TEST_BUILTINS_OBJS += test-ctype.o
 TEST_BUILTINS_OBJS += test-date.o
+TEST_BUILTINS_OBJS += test-delta.o
 TEST_BUILTINS_OBJS += test-lazy-init-name-hash.o
 TEST_BUILTINS_OBJS += test-sha1.o
 
-TEST_PROGRAMS_NEED_X += test-delta
 TEST_PROGRAMS_NEED_X += test-drop-caches
 TEST_PROGRAMS_NEED_X += test-dump-cache-tree
 TEST_PROGRAMS_NEED_X += test-dump-fsmonitor
diff --git a/t/helper/test-delta.c b/t/helper/test-delta.c
index 591730adc4..34c7259248 100644
--- a/t/helper/test-delta.c
+++ b/t/helper/test-delta.c
@@ -8,14 +8,15 @@
  * published by the Free Software Foundation.
  */
 
+#include "test-tool.h"
 #include "git-compat-util.h"
 #include "delta.h"
 #include "cache.h"
 
 static const char usage_str[] =
-   "test-delta (-d|-p)   ";
+   "test-tool delta (-d|-p)   ";
 
-int cmd_main(int argc, const char **argv)
+int cmd__delta(int argc, const char **argv)
 {
int fd;
struct stat st;
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index e92f93ac3b..6bef386842 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -11,6 +11,7 @@ static struct test_cmd cmds[] = {
{ "config", cmd__config },
{ "ctype", cmd__ctype },
{ "date", cmd__date },
+   { "delta", cmd__delta },
{ "lazy-init-name-hash", cmd__lazy_init_name_hash },
{ "sha1", cmd__sha1 },
 };
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index 31c20bb656..761705e110 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -5,6 +5,7 @@ int cmd__chmtime(int argc, const char **argv);
 int cmd__config(int argc, const char **argv);
 int cmd__ctype(int argc, const char **argv);
 int cmd__date(int argc, const char **argv);
+int cmd__delta(int argc, const char **argv);
 int cmd__lazy_init_name_hash(int argc, const char **argv);
 int cmd__sha1(int argc, const char **argv);
 
-- 
2.17.0.rc0.348.gd5a49e0b6f



[PATCH v2 07/36] t/helper: merge test-date into test-tool

2018-03-24 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Makefile   |  2 +-
 t/helper/test-date.c   | 17 +
 t/helper/test-tool.c   |  1 +
 t/helper/test-tool.h   |  1 +
 t/t0006-date.sh|  8 
 t/t1300-repo-config.sh |  2 +-
 t/test-lib.sh  |  4 ++--
 7 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/Makefile b/Makefile
index d09710dc3d..efb1872c52 100644
--- a/Makefile
+++ b/Makefile
@@ -655,10 +655,10 @@ PROGRAMS += $(patsubst %.o,git-%$X,$(PROGRAM_OBJS))
 TEST_BUILTINS_OBJS += test-chmtime.o
 TEST_BUILTINS_OBJS += test-config.o
 TEST_BUILTINS_OBJS += test-ctype.o
+TEST_BUILTINS_OBJS += test-date.o
 TEST_BUILTINS_OBJS += test-lazy-init-name-hash.o
 TEST_BUILTINS_OBJS += test-sha1.o
 
-TEST_PROGRAMS_NEED_X += test-date
 TEST_PROGRAMS_NEED_X += test-delta
 TEST_PROGRAMS_NEED_X += test-drop-caches
 TEST_PROGRAMS_NEED_X += test-dump-cache-tree
diff --git a/t/helper/test-date.c b/t/helper/test-date.c
index ac83687970..a0837371ab 100644
--- a/t/helper/test-date.c
+++ b/t/helper/test-date.c
@@ -1,13 +1,14 @@
+#include "test-tool.h"
 #include "cache.h"
 
 static const char *usage_msg = "\n"
-"  test-date relative [time_t]...\n"
-"  test-date show: [time_t]...\n"
-"  test-date parse [date]...\n"
-"  test-date approxidate [date]...\n"
-"  test-date timestamp [date]...\n"
-"  test-date is64bit\n"
-"  test-date time_t-is64bit\n";
+"  test-tool date relative [time_t]...\n"
+"  test-tool date show: [time_t]...\n"
+"  test-tool date parse [date]...\n"
+"  test-tool date approxidate [date]...\n"
+"  test-tool date timestamp [date]...\n"
+"  test-tool date is64bit\n"
+"  test-tool date time_t-is64bit\n";
 
 static void show_relative_dates(const char **argv, struct timeval *now)
 {
@@ -81,7 +82,7 @@ static void parse_approx_timestamp(const char **argv, struct 
timeval *now)
}
 }
 
-int cmd_main(int argc, const char **argv)
+int cmd__date(int argc, const char **argv)
 {
struct timeval now;
const char *x;
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index d600a31935..e92f93ac3b 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -10,6 +10,7 @@ static struct test_cmd cmds[] = {
{ "chmtime", cmd__chmtime },
{ "config", cmd__config },
{ "ctype", cmd__ctype },
+   { "date", cmd__date },
{ "lazy-init-name-hash", cmd__lazy_init_name_hash },
{ "sha1", cmd__sha1 },
 };
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index 41805ecd1c..31c20bb656 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -4,6 +4,7 @@
 int cmd__chmtime(int argc, const char **argv);
 int cmd__config(int argc, const char **argv);
 int cmd__ctype(int argc, const char **argv);
+int cmd__date(int argc, const char **argv);
 int cmd__lazy_init_name_hash(int argc, const char **argv);
 int cmd__sha1(int argc, const char **argv);
 
diff --git a/t/t0006-date.sh b/t/t0006-date.sh
index 7ac9466d50..64ff86df8e 100755
--- a/t/t0006-date.sh
+++ b/t/t0006-date.sh
@@ -10,7 +10,7 @@ check_relative() {
t=$(($TEST_DATE_NOW - $1))
echo "$t -> $2" >expect
test_expect_${3:-success} "relative date ($2)" "
-   test-date relative $t >actual &&
+   test-tool date relative $t >actual &&
test_i18ncmp expect actual
"
 }
@@ -35,7 +35,7 @@ check_show () {
zone=$5
test_expect_success $prereqs "show date ($format:$time)" '
echo "$time -> $expect" >expect &&
-   TZ=${zone:-$TZ} test-date show:"$format" "$time" >actual &&
+   TZ=${zone:-$TZ} test-tool date show:"$format" "$time" >actual &&
test_cmp expect actual
'
 }
@@ -71,7 +71,7 @@ check_show iso-local "$FUTURE" "2152-06-19 22:24:56 +" 
TIME_IS_64BIT,TIME_T_
 check_parse() {
echo "$1 -> $2" >expect
test_expect_${4:-success} "parse date ($1${3:+ TZ=$3})" "
-   TZ=${3:-$TZ} test-date parse '$1' >actual &&
+   TZ=${3:-$TZ} test-tool date parse '$1' >actual &&
test_cmp expect actual
"
 }
@@ -92,7 +92,7 @@ check_parse '2008-02-14 20:30:45' '2008-02-14 20:30:45 -0500' 
EST5
 check_approxidate() {
echo "$1 -> $2 +" >expect
test_expect_${3:-success} "parse approxidate ($1)" "
-   test-date approxidate '$1' >actual &&
+   test-tool date approxidate '$1' >actual &&
test_cmp expect actual
"
 }
diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh
index 4f8e6f5fde..8780934478 100755
--- a/t/t1300-repo-config.sh
+++ b/t/t1300-repo-config.sh
@@ -914,7 +914,7 @@ test_expect_success 'get --expiry-date' '
invalid1 = "abc"
EOF
cat >expect <<-EOF &&
-   $(test-date timestamp $rel)
+   $(test-tool date timestamp $rel)
1275666415
1510441871
1510348087
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 7ab8af47a5..483c8d6d7c 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -1206,5 +1206,5 @@ test_lazy_prereq 

[PATCH v2 06/36] t/helper: merge test-ctype into test-tool

2018-03-24 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Makefile   | 2 +-
 t/helper/test-ctype.c  | 3 ++-
 t/helper/test-tool.c   | 1 +
 t/helper/test-tool.h   | 1 +
 t/t0070-fundamental.sh | 2 +-
 5 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index 227f16ad17..d09710dc3d 100644
--- a/Makefile
+++ b/Makefile
@@ -654,10 +654,10 @@ PROGRAMS += $(patsubst %.o,git-%$X,$(PROGRAM_OBJS))
 
 TEST_BUILTINS_OBJS += test-chmtime.o
 TEST_BUILTINS_OBJS += test-config.o
+TEST_BUILTINS_OBJS += test-ctype.o
 TEST_BUILTINS_OBJS += test-lazy-init-name-hash.o
 TEST_BUILTINS_OBJS += test-sha1.o
 
-TEST_PROGRAMS_NEED_X += test-ctype
 TEST_PROGRAMS_NEED_X += test-date
 TEST_PROGRAMS_NEED_X += test-delta
 TEST_PROGRAMS_NEED_X += test-drop-caches
diff --git a/t/helper/test-ctype.c b/t/helper/test-ctype.c
index bb72c47df5..92c4c2313e 100644
--- a/t/helper/test-ctype.c
+++ b/t/helper/test-ctype.c
@@ -1,3 +1,4 @@
+#include "test-tool.h"
 #include "cache.h"
 
 static int rc;
@@ -28,7 +29,7 @@ static int is_in(const char *s, int ch)
 #define LOWER "abcdefghijklmnopqrstuvwxyz"
 #define UPPER "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
 
-int cmd_main(int argc, const char **argv)
+int cmd__ctype(int argc, const char **argv)
 {
TEST_CLASS(isdigit, DIGIT);
TEST_CLASS(isspace, " \n\r\t");
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index e8d6c6b9eb..d600a31935 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -9,6 +9,7 @@ struct test_cmd {
 static struct test_cmd cmds[] = {
{ "chmtime", cmd__chmtime },
{ "config", cmd__config },
+   { "ctype", cmd__ctype },
{ "lazy-init-name-hash", cmd__lazy_init_name_hash },
{ "sha1", cmd__sha1 },
 };
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index 3084f458a0..41805ecd1c 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -3,6 +3,7 @@
 
 int cmd__chmtime(int argc, const char **argv);
 int cmd__config(int argc, const char **argv);
+int cmd__ctype(int argc, const char **argv);
 int cmd__lazy_init_name_hash(int argc, const char **argv);
 int cmd__sha1(int argc, const char **argv);
 
diff --git a/t/t0070-fundamental.sh b/t/t0070-fundamental.sh
index 991ed2a48d..70d4d98a2e 100755
--- a/t/t0070-fundamental.sh
+++ b/t/t0070-fundamental.sh
@@ -9,7 +9,7 @@ Verify wrappers and compatibility functions.
 . ./test-lib.sh
 
 test_expect_success 'character classes (isspace, isalpha etc.)' '
-   test-ctype
+   test-tool ctype
 '
 
 test_expect_success 'mktemp to nonexistent directory prints filename' '
-- 
2.17.0.rc0.348.gd5a49e0b6f



[PATCH v2 01/36] t/helper: add an empty test-tool program

2018-03-24 Thread Nguyễn Thái Ngọc Duy
This will become an umbrella program that absorbs most [1] t/helper
programs in. By having a single executable binary we reduce disk usage
(libgit.a is replicated by every t/helper program) and shorten link
time a bit.

Running "make --jobs=1; du -sh t/helper" with ccache fully populated,
it takes 27 seconds and 277MB at the beginning of this series, 17
seconds and 42MB at the end.

[1] There are a couple programs that will not become part of
test-tool: test-line-buffer and test-svn-fe have extra
dependencies and test-fake-ssh's program name has to be a single
word for some ssh tests.

Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Makefile |  6 +-
 t/helper/test-tool.c | 27 +++
 t/helper/test-tool.h |  4 
 3 files changed, 36 insertions(+), 1 deletion(-)
 create mode 100644 t/helper/test-tool.c
 create mode 100644 t/helper/test-tool.h

diff --git a/Makefile b/Makefile
index a1d8775adb..2376646e98 100644
--- a/Makefile
+++ b/Makefile
@@ -546,6 +546,7 @@ SCRIPT_PERL =
 SCRIPT_PYTHON =
 SCRIPT_SH =
 SCRIPT_LIB =
+TEST_BUILTINS_OBJS =
 TEST_PROGRAMS_NEED_X =
 
 # Having this variable in your environment would break pipelines because
@@ -690,6 +691,7 @@ TEST_PROGRAMS_NEED_X += test-string-list
 TEST_PROGRAMS_NEED_X += test-submodule-config
 TEST_PROGRAMS_NEED_X += test-subprocess
 TEST_PROGRAMS_NEED_X += test-svn-fe
+TEST_PROGRAMS_NEED_X += test-tool
 TEST_PROGRAMS_NEED_X += test-urlmatch-normalization
 TEST_PROGRAMS_NEED_X += test-wildmatch
 
@@ -2083,7 +2085,7 @@ VCSSVN_OBJS += vcs-svn/fast_export.o
 VCSSVN_OBJS += vcs-svn/svndiff.o
 VCSSVN_OBJS += vcs-svn/svndump.o
 
-TEST_OBJS := $(patsubst %$X,%.o,$(TEST_PROGRAMS))
+TEST_OBJS := $(patsubst %$X,%.o,$(TEST_PROGRAMS)) $(patsubst 
%,t/helper/%,$(TEST_BUILTINS_OBJS))
 OBJECTS := $(LIB_OBJS) $(BUILTIN_OBJS) $(PROGRAM_OBJS) $(TEST_OBJS) \
$(XDIFF_OBJS) \
$(VCSSVN_OBJS) \
@@ -2494,6 +2496,8 @@ t/helper/test-svn-fe$X: $(VCSSVN_LIB)
 
 .PRECIOUS: $(TEST_OBJS)
 
+t/helper/test-tool$X: $(patsubst %,t/helper/%,$(TEST_BUILTINS_OBJS))
+
 t/helper/test-%$X: t/helper/test-%.o GIT-LDFLAGS $(GITLIBS)
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) 
$(filter %.a,$^) $(LIBS)
 
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
new file mode 100644
index 00..c730f718ca
--- /dev/null
+++ b/t/helper/test-tool.c
@@ -0,0 +1,27 @@
+#include "git-compat-util.h"
+#include "test-tool.h"
+
+struct test_cmd {
+   const char *name;
+   int (*main)(int argc, const char **argv);
+};
+
+static struct test_cmd cmds[] = {
+};
+
+int cmd_main(int argc, const char **argv)
+{
+   int i;
+
+   if (argc < 2)
+   die("I need a test name!");
+
+   for (i = 0; i < ARRAY_SIZE(cmds); i++) {
+   if (!strcmp(cmds[i].name, argv[1])) {
+   argv++;
+   argc--;
+   return cmds[i].main(argc, argv);
+   }
+   }
+   die("There is no test named '%s'", argv[1]);
+}
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
new file mode 100644
index 00..6ce57ae0cc
--- /dev/null
+++ b/t/helper/test-tool.h
@@ -0,0 +1,4 @@
+#ifndef __TEST_TOOL_H__
+#define __TEST_TOOL_H__
+
+#endif
-- 
2.17.0.rc0.348.gd5a49e0b6f



  1   2   >