gitweb.git
name-rev: use commit-slab for rev-name instead of commi... Nguyễn Thái Ngọc Duy Sat, 19 May 2018 05:28:26 +0000 (07:28 +0200)

name-rev: use commit-slab for rev-name instead of commit->util

It's done so that commit->util can be removed. See more explanation in
the commit that removes commit->util.

Signed-off-by: Junio C Hamano <gitster@pobox.com>

bisect.c: use commit-slab for commit weight instead... Nguyễn Thái Ngọc Duy Sat, 19 May 2018 05:28:25 +0000 (07:28 +0200)

bisect.c: use commit-slab for commit weight instead of commit->util

It's done so that commit->util can be removed. See more explanation in
the commit that removes commit->util.

Signed-off-by: Junio C Hamano <gitster@pobox.com>

revision.c: use commit-slab for show_sourceNguyễn Thái Ngọc Duy Sat, 19 May 2018 05:28:24 +0000 (07:28 +0200)

revision.c: use commit-slab for show_source

Instead of relying on commit->util to store the source string, let the
user provide a commit-slab to store the source strings in.

It's done so that commit->util can be removed. See more explanation in
the commit that removes commit->util.

Signed-off-by: Junio C Hamano <gitster@pobox.com>

sequencer.c: use commit-slab to associate todo items... Nguyễn Thái Ngọc Duy Sat, 19 May 2018 05:28:23 +0000 (07:28 +0200)

sequencer.c: use commit-slab to associate todo items to commits

It's done so that commit->util can be removed. See more explanation in
the commit that removes commit->util.

Signed-off-by: Junio C Hamano <gitster@pobox.com>

sequencer.c: use commit-slab to mark seen commitsNguyễn Thái Ngọc Duy Sat, 19 May 2018 05:28:22 +0000 (07:28 +0200)

sequencer.c: use commit-slab to mark seen commits

It's done so that commit->util can be removed. See more explanation in
the commit that removes commit->util.

Signed-off-by: Junio C Hamano <gitster@pobox.com>

shallow.c: use commit-slab for commit depth instead... Nguyễn Thái Ngọc Duy Sat, 19 May 2018 05:28:21 +0000 (07:28 +0200)

shallow.c: use commit-slab for commit depth instead of commit->util

It's done so that commit->util can be removed. See more explanation in
the commit that removes commit->util.

While at there, plug a leak for keeping track of depth in this code.

Signed-off-by: Junio C Hamano <gitster@pobox.com>

describe: use commit-slab for commit names instead... Nguyễn Thái Ngọc Duy Sat, 19 May 2018 05:28:20 +0000 (07:28 +0200)

describe: use commit-slab for commit names instead of commit->util

It's done so that commit->util can be removed. See more explanation in
the commit that removes commit->util.

Signed-off-by: Junio C Hamano <gitster@pobox.com>

blame: use commit-slab for blame suspects instead of... Nguyễn Thái Ngọc Duy Sat, 19 May 2018 05:28:19 +0000 (07:28 +0200)

blame: use commit-slab for blame suspects instead of commit->util

It's done so that commit->util can be removed. See more explanation in
the commit that removes commit->util.

Signed-off-by: Junio C Hamano <gitster@pobox.com>

commit-slab: support shared commit-slabNguyễn Thái Ngọc Duy Sat, 19 May 2018 05:28:18 +0000 (07:28 +0200)

commit-slab: support shared commit-slab

define_shared_commit_slab() could be used in a header file to define a
commit-slab. One of these C files must include commit-slab-impl.h and
"call" implement_shared_commit_slab().

Signed-off-by: Junio C Hamano <gitster@pobox.com>

commit-slab.h: code splitNguyễn Thái Ngọc Duy Sat, 19 May 2018 05:28:17 +0000 (07:28 +0200)

commit-slab.h: code split

The struct declaration and implementation macros are moved to
commit-slab-hdr.h and commit-slab-impl.h respectively.

This right now is not needed for current users but if we make a public
commit-slab type, we may want to avoid including the slab
implementation in a header file which gets replicated in every c file
that includes it.

Signed-off-by: Junio C Hamano <gitster@pobox.com>

regex: do not call `regfree()` if compilation failsMartin Ågren Sun, 20 May 2018 10:50:32 +0000 (12:50 +0200)

regex: do not call `regfree()` if compilation fails

It is apparently undefined behavior to call `regfree()` on a regex where
`regcomp()` failed. The language in [1] is a bit muddy, at least to me,
but the clearest hint is this (`preg` is the `regex_t *`):

Upon successful completion, the regcomp() function shall return 0.
Otherwise, it shall return an integer value indicating an error as
described in <regex.h>, and the content of preg is undefined.

Funnily enough, there is also the `regerror()` function which should be
given a pointer to such a "failed" `regex_t` -- the content of which
would supposedly be undefined -- and which may investigate it to come up
with a detailed error message.

In any case, the example in that document shows how `regfree()` is not
called after `regcomp()` fails.

We have quite a few users of this API and most get this right. These
three users do not.

Several implementations can handle this just fine [2] and these code paths
supposedly have not wreaked havoc or we'd have heard about it. (These
are all in code paths where git got bad input and is just about to die
anyway.) But let's just avoid the issue altogether.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/regcomp.html

[2] https://www.redhat.com/archives/libvir-list/2013-September/msg00262.html

Researched-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-byi Martin Ågren <martin.agren@gmail.com>

Signed-off-by: Junio C Hamano <gitster@pobox.com>

config: let `config_store_data_clear()` handle `key`Martin Ågren Sun, 20 May 2018 10:42:35 +0000 (12:42 +0200)

config: let `config_store_data_clear()` handle `key`

Instead of remembering to free `key` in each code path, let
`config_store_data_clear()` handle that.

We still need to free it before replacing it, though. Move that freeing
closer to the replacing to be safe. Note that in that same part of the
code, we can no longer set `key` to the original pointer, but need to
`xstrdup()` it.

Signed-off-by: Martin Ågren <martin.agren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

config: let `config_store_data_clear()` handle `value_r... Martin Ågren Sun, 20 May 2018 10:42:34 +0000 (12:42 +0200)

config: let `config_store_data_clear()` handle `value_regex`

Instead of duplicating the logic for clearing up `value_regex`, let
`config_store_data_clear()` handle that.

When `regcomp()` fails, the current code does not call `regfree()`. Make
sure we do the same by immediately invalidating `value_regex`. Some
implementations are able to handle such an extra `regfree()`-call [1],
but from the example in [2], we should not do so. (The language itself
in [2] is not super-clear on this.)

[1] https://www.redhat.com/archives/libvir-list/2013-September/msg00262.html

[2] http://pubs.opengroup.org/onlinepubs/9699919799/functions/regcomp.html

Researched-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Martin Ågren <martin.agren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

config: free resources of `struct config_store_data`Martin Ågren Sun, 20 May 2018 10:42:33 +0000 (12:42 +0200)

config: free resources of `struct config_store_data`

Commit fee8572c6d (config: avoid using the global variable `store`,
2018-04-09) dropped the staticness of a certain struct, instead letting
the users create an instance on the stack and pass around a pointer.

We do not free all the memory that the struct tracks. When the struct
was static, the memory would always be reachable. Now that we keep the
struct on the stack, though, as soon as we return, it goes out of scope
and we leak the memory it points to. In particular, we leak the memory
pointed to by the `parsed` and `seen` fields.

Introduce and use a helper function `config_store_data_clear()` to plug
these leaks. The memory tracked here is config parser events. Once the
users (`git_config_set_multivar_in_file_gently()` and
`git_config_copy_or_rename_section_in_file()` at the moment) are done,
no-one should be holding on to a pointer into this memory.

There are two more members of the struct that are candidates for freeing
in this new function (`key` and `value_regex`). Those are actually
already being taken care of. The next couple of patches will move their
freeing into the function we are adding here.

Signed-off-by: Martin Ågren <martin.agren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

t5300: abstract away SHA-1-specific constantsbrian m. carlson Mon, 21 May 2018 02:01:47 +0000 (02:01 +0000)

t5300: abstract away SHA-1-specific constants

Adjust the test so that it computes variables for object IDs instead of
using hard-coded hashes.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

t4208: abstract away SHA-1-specific constantsbrian m. carlson Mon, 21 May 2018 02:01:46 +0000 (02:01 +0000)

t4208: abstract away SHA-1-specific constants

Adjust the test so that it computes variables for object IDs instead of
using hard-coded hashes.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

t4045: abstract away SHA-1-specific constantsbrian m. carlson Mon, 21 May 2018 02:01:45 +0000 (02:01 +0000)

t4045: abstract away SHA-1-specific constants

Adjust the test so that it computes variables for blobs instead of using
hard-coded hashes.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

t4042: abstract away SHA-1-specific constantsbrian m. carlson Mon, 21 May 2018 02:01:44 +0000 (02:01 +0000)

t4042: abstract away SHA-1-specific constants

Adjust the test so that it computes variables for blobs instead of using
hard-coded hashes.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

t4205: sort log output in a hash-independent waybrian m. carlson Mon, 21 May 2018 02:01:43 +0000 (02:01 +0000)

t4205: sort log output in a hash-independent way

This test enumerates log entries and then sorts them. For SHA-1, this
produces results that happen to sort in the order specified in the test,
but for other hash algorithms they sort differently. Ensure we sort the
log entries in a hash-independent way by sorting on the ref name instead
of the object ID.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

t/lib-diff-alternative: abstract away SHA-1-specific... brian m. carlson Mon, 21 May 2018 02:01:42 +0000 (02:01 +0000)

t/lib-diff-alternative: abstract away SHA-1-specific constants

Adjust the test code so that it computes variables for blobs instead of
using hard-coded hashes. This makes t4033 and t4050 (the patience and
histogram tests) pass.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

t4030: abstract away SHA-1-specific constantsbrian m. carlson Mon, 21 May 2018 02:01:41 +0000 (02:01 +0000)

t4030: abstract away SHA-1-specific constants

Adjust the test so that it computes variables for blobs instead of using
hard-coded hashes.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

t4029: abstract away SHA-1-specific constantsbrian m. carlson Mon, 21 May 2018 02:01:40 +0000 (02:01 +0000)

t4029: abstract away SHA-1-specific constants

Adjust the test so that it computes variables for blobs instead of using
hard-coded hashes.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

t4029: fix test indentationbrian m. carlson Mon, 21 May 2018 02:01:39 +0000 (02:01 +0000)

t4029: fix test indentation

We typically indent our tests with a single tab, partially so that we
can take advantage of indented heredocs. Make this change and move the
quote marks to be in the typical position for our tests.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

t4022: abstract away SHA-1-specific constantsbrian m. carlson Mon, 21 May 2018 02:01:38 +0000 (02:01 +0000)

t4022: abstract away SHA-1-specific constants

Adjust the test so that it computes variables for blobs instead of using
hard-coded hashes.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

t4020: abstract away SHA-1-specific constantsbrian m. carlson Mon, 21 May 2018 02:01:37 +0000 (02:01 +0000)

t4020: abstract away SHA-1-specific constants

Adjust the test so that it computes variables for blobs instead of using
hard-coded hashes.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

t4014: abstract away SHA-1-specific constantsbrian m. carlson Mon, 21 May 2018 02:01:36 +0000 (02:01 +0000)

t4014: abstract away SHA-1-specific constants

Adjust the test so that it computes values for blobs instead of using
hard-coded hashes.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

t4008: abstract away SHA-1-specific constantsbrian m. carlson Mon, 21 May 2018 02:01:35 +0000 (02:01 +0000)

t4008: abstract away SHA-1-specific constants

Adjust the test so that it computes variables for blobs instead of using
hard-coded hashes.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

t4007: abstract away SHA-1-specific constantsbrian m. carlson Mon, 21 May 2018 02:01:34 +0000 (02:01 +0000)

t4007: abstract away SHA-1-specific constants

Adjust the test so that it computes variables for blobs and uses the
ZERO_OID variable instead of using hard-coded hashes.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

t3905: abstract away SHA-1-specific constantsbrian m. carlson Mon, 21 May 2018 02:01:33 +0000 (02:01 +0000)

t3905: abstract away SHA-1-specific constants

Adjust the test so that it computes variables for blobs instead of using
hard-coded hashes.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

t3702: abstract away SHA-1-specific constantsbrian m. carlson Mon, 21 May 2018 02:01:32 +0000 (02:01 +0000)

t3702: abstract away SHA-1-specific constants

Strip out the index lines in the diff before comparing them, as these
will differ between hash algorithms. This leads to a smaller, simpler
change than editing the index line.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

completion: allow to customize the completable command... Nguyễn Thái Ngọc Duy Sun, 20 May 2018 18:40:09 +0000 (20:40 +0200)

completion: allow to customize the completable command list

By default we show porcelain, external commands and a couple others
that are also popular. If you are not happy with this list, you can
now customize it a new config variable.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

completion: add and use --list-cmds=aliasNguyễn Thái Ngọc Duy Sun, 20 May 2018 18:40:08 +0000 (20:40 +0200)

completion: add and use --list-cmds=alias

By providing aliases via --list-cmds=, we could simplify command
collection code in the script. We only issue one git command. Before
this patch that is "git config", after it's "git --list-cmds=". In
"git help" completion case we actually reduce one "git" process (for
getting guides) but that call was added in this series so it does not
really count.

A couple of bash functions are removed because they are not needed
anymore. __git_compute_all_commands() and $__git_all_commands stay
because they are still needed for completing pager.* config and
without "alias" group, the result is still cacheable.

There is a slight (good) change in _git_help() with this patch: before
"git help <tab>" shows external commands (as in _not_ part of git) as
well as part of $__git_all_commands. We have finer control over
command listing now and can exclude that because we can't provide a
man page for external commands anyway.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

completion: add and use --list-cmds=nohelpersNguyễn Thái Ngọc Duy Sun, 20 May 2018 18:40:07 +0000 (20:40 +0200)

completion: add and use --list-cmds=nohelpers

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

Move declaration for alias.c to alias.hNguyễn Thái Ngọc Duy Sun, 20 May 2018 18:40:06 +0000 (20:40 +0200)

Move declaration for alias.c to alias.h

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

completion: reduce completable command listNguyễn Thái Ngọc Duy Sun, 20 May 2018 18:40:05 +0000 (20:40 +0200)

completion: reduce completable command list

The following commands are removed from the complete list:

- annotate obsolete, discouraged to use
- filter-branch not often used
- get-tar-commit-id not often used
- imap-send not often used
- interpreter-trailers not for interactive use
- name-rev plumbing, just use git-describe
- p4 too short and probably not often used (*)
- svn same category as p4 (*)
- verify-commit not often used

(*) to be fair, send-email command which is in the same foreignscminterface
group as svn and p4 does get completion, just because it's used by git
and kernel development. So maybe we should include them.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

completion: let git provide the completable command... Nguyễn Thái Ngọc Duy Sun, 20 May 2018 18:40:04 +0000 (20:40 +0200)

completion: let git provide the completable command list

Instead of maintaining a separate list of command classification,
which often could go out of date, let's centralize the information
back in git.

While the function in git-completion.bash implies "list porcelain
commands", that's not exactly what it does. It gets all commands (aka
--list-cmds=main,others) then exclude certain non-porcelain ones. We
could almost recreate this list two lists list-mainporcelain and
others. The non-porcelain-but-included-anyway is added by the third
category list-complete.

Note that the current completion script incorrectly classifies
filter-branch as porcelain and t9902 tests this behavior. We keep it
this way in t9902 because this test does not really care which
particular command is porcelain or plumbing, they're just names.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

command-list.txt: documentation and guide lineNguyễn Thái Ngọc Duy Sun, 20 May 2018 18:40:03 +0000 (20:40 +0200)

command-list.txt: documentation and guide line

This is intended to help anybody who needs to update command-list.txt.
It gives a brief introduction of all attributes a command can take.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

help: use command-list.txt for the source of guidesNguyễn Thái Ngọc Duy Sun, 20 May 2018 18:40:02 +0000 (20:40 +0200)

help: use command-list.txt for the source of guides

The help command currently hard codes the list of guides and their
summary in C. Let's move this list to command-list.txt. This lets us
extract summary lines from Documentation/git*.txt. This also
potentially lets us list guides in git.txt, but I'll leave that for
now.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

help: add "-a --verbose" to list all commands with... Nguyễn Thái Ngọc Duy Sun, 20 May 2018 18:40:01 +0000 (20:40 +0200)

help: add "-a --verbose" to list all commands with synopsis

This lists all recognized commands [1] by category. The group order
follows closely git.txt.

[1] We may actually show commands that are not built (e.g. if you set
NO_PERL you don't have git-instaweb but it's still listed here). I
ignore the problem because on Linux a git package could be split
anyway. The "git-core" package may not contain git-instaweb even if
it's built because it may end up in a separate package. We can't know
anyway.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

git: support --list-cmds=list-<category>Nguyễn Thái Ngọc Duy Sun, 20 May 2018 18:40:00 +0000 (20:40 +0200)

git: support --list-cmds=list-<category>

This allows us to select any group of commands by a category defined
in command-list.txt. This is an internal/hidden option so we don't
have to be picky about the category name or worried about exposing too
much.

This will be used later by git-completion.bash to retrieve certain
command groups.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

completion: implement and use --list-cmds=main,othersNguyễn Thái Ngọc Duy Sun, 20 May 2018 18:39:59 +0000 (20:39 +0200)

completion: implement and use --list-cmds=main,others

This is part of the effort to break down and provide commands by
category in machine-readable form. This could be helpful later on when
completion script switches to use --list-cmds for selecting
completable commands. It would be much easier for the user to choose
to complete _all_ commands instead of the default selection by passing
different values to --list-cmds in git-completino.bash.

While at there, replace "git help -a" in git-completion.bash with
--list-cmds since it's better suited for this task.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

git --list-cmds: collect command list in a string_listNguyễn Thái Ngọc Duy Sun, 20 May 2018 18:39:58 +0000 (20:39 +0200)

git --list-cmds: collect command list in a string_list

Instead of printing the command directly one by one, keep them in a
list and print at the end. This allows more modification before we
print out (e.g. sorting, removing duplicates or even excluding some
items).

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

git.c: convert --list-* to --list-cmds=*Nguyễn Thái Ngọc Duy Sun, 20 May 2018 18:39:57 +0000 (20:39 +0200)

git.c: convert --list-* to --list-cmds=*

Even if these are hidden options, let's make them a bit more generic
since we're introducing more listing types shortly. The code is
structured to allow combining multiple listing types together because
we will soon add more types the 'builtins'.

'parseopt' remains separate because it has separate (SPC) to match
git-completion.bash needs and will not combine with others.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

fmt_with_err: add a comment that truncation is OKJeff King Sat, 19 May 2018 01:58:44 +0000 (18:58 -0700)

fmt_with_err: add a comment that truncation is OK

Functions like die_errno() use fmt_with_err() to combine the
caller-provided format with the strerror() string. We use a
fixed stack buffer because we're already handling an error
and don't have any way to report another one. Our buffer
should generally be big enough to fit this, but if it's not,
truncation is our best option. Let's add a comment to that
effect, so that anybody auditing the code for truncation
bugs knows that this is fine.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

shorten_unambiguous_ref: use xsnprintfJeff King Sat, 19 May 2018 01:58:20 +0000 (18:58 -0700)

shorten_unambiguous_ref: use xsnprintf

We convert the ref_rev_parse_rules array into scanf formats
on the fly, and use snprintf() to write into each string. We
should have enough memory to hold everything because of the
earlier total_len computation. Let's use xsnprintf() to
give runtime confirmation that this is the case, and to make
it easy for people auditing the code to know there's no
truncation bug.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

fsmonitor: use internal argv_array of struct child_processRené Scharfe Sat, 19 May 2018 08:27:46 +0000 (10:27 +0200)

fsmonitor: use internal argv_array of struct child_process

Avoid magic array sizes and indexes by constructing the fsmonitor
command line using the embedded argv_array of the child_process. The
resulting code is shorter and easier to extend.

Getting rid of the snprintf() calls is a bonus -- even though the
buffers were big enough here to avoid truncation -- as it makes auditing
the remaining callers easier.

Inspired-by: Jeff King <peff@peff.net>
Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

log_write_email_headers: use strbufsJeff King Sat, 19 May 2018 01:57:44 +0000 (18:57 -0700)

log_write_email_headers: use strbufs

When we write a MIME attachment, we write the mime headers
into fixed-size buffers. These are likely to be big enough
in practice, but technically the input could be arbitrarily
large (e.g., if the caller provided a lot of content in the
extra_headers string), in which case we'd quietly truncate
it and generate bogus output. Let's convert these buffers to
strbufs.

The memory ownership here is a bit funny. The original fixed
buffers were static, and we merely pass out pointers to them
to be used by the caller (and in one case, we even just
stuff our value into the opt->diffopt.stat_sep value).
Ideally we'd actually pass back heap buffers, and the caller
would be responsible for freeing them.

This patch punts on that cleanup for now, and instead just
marks the strbufs as static. That means we keep ownership in
this function, making it not a complete leak. This also
takes us one step closer to fixing it in the long term
(since we can eventually use strbuf_detach() to hand
ownership to the caller, once it's ready).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

http: use strbufs instead of fixed buffersJeff King Sat, 19 May 2018 01:56:37 +0000 (18:56 -0700)

http: use strbufs instead of fixed buffers

We keep the names of incoming packs and objects in fixed
PATH_MAX-size buffers, and snprintf() into them. This is
unlikely to end up with truncated filenames, but it is
possible (especially on systems where PATH_MAX is shorter
than actual paths can be). Let's switch to using strbufs,
which makes the question go away entirely.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

config: die when --blob is used outside a repositoryJeff King Fri, 18 May 2018 22:27:04 +0000 (15:27 -0700)

config: die when --blob is used outside a repository

If you run "config --blob" outside of a repository, then we
eventually try to resolve the blob name and hit a BUG().
Let's catch this earlier and provide a useful message.

Note that we could also catch this much lower in the stack,
in git_config_from_blob_ref(). That might cover other
callsites, too, but it's unclear whether those ones would
actually be bugs or not. So let's leave the low-level
functions to assume the caller knows what it's doing (and
BUG() if it turns out it doesn't).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

get_main_ref_store: BUG() when outside a repositoryJeff King Fri, 18 May 2018 22:25:53 +0000 (15:25 -0700)

get_main_ref_store: BUG() when outside a repository

If we don't have a repository, then we can't initialize the
ref store. Prior to 64a741619d (refs: store the main ref
store inside the repository struct, 2018-04-11), we'd try to
access get_git_dir(), and outside a repository that would
trigger a BUG(). After that commit, though, we directly use
the_repository->git_dir; if it's NULL we'll just segfault.

Let's catch this case and restore the BUG() behavior.
Obviously we don't ever want to hit this code, but a BUG()
is a lot more helpful than a segfault if we do.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

t9902-completion: exercise __git_complete_index_file... SZEDER Gábor Fri, 18 May 2018 14:17:51 +0000 (16:17 +0200)

t9902-completion: exercise __git_complete_index_file() directly

The tests added in 2f271cd9cf (t9902-completion: add tests
demonstrating issues with quoted pathnames, 2018-05-08) and in
2ab6eab4fe (completion: improve handling quoted paths in 'git
ls-files's output, 2018-03-28) have a few shortcomings:

- All these tests use the 'test_completion' helper function, thus
they are exercising the whole completion machinery, although they
are only interested in how git-aware path completion, specifically
the __git_complete_index_file() function deals with unusual
characters in pathnames and on the command line.

- These tests can't satisfactorily test the case of pathnames
containing spaces, because 'test_completion' gets the words on the
command line as a single argument and it uses space as word
separator.

- Some of the tests are protected by different FUNNYNAMES_* prereqs
depending on whether they put backslashes and double quotes or
separator characters (FS, GS, RS, US) in pathnames, although a
filesystem not allowing one likely doesn't allow the others
either.

- One of the tests operates on paths containing '|' and '&'
characters without being protected by a FUNNYNAMES prereq, but
some filesystems (notably on Windows) don't allow these characters
in pathnames, either.

Replace these tests with basically equivalent, more focused tests that
call __git_complete_index_file() directly. Since this function only
looks at the current word to be completed, i.e. the $cur variable, we
can easily include pathnames containing spaces in the tests, so use
such pathnames instead of pathnames containing '|' and '&'. Finally,
use only a single FUNNYNAMES prereq for all kinds of special
characters.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

completion: don't return with error from __gitcomp_file... SZEDER Gábor Fri, 18 May 2018 14:17:50 +0000 (16:17 +0200)

completion: don't return with error from __gitcomp_file_direct()

In __gitcomp_file_direct() we tell Bash that it should handle our
possible completion words as filenames with the following piece of
cleverness:

# use a hack to enable file mode in bash < 4
compopt -o filenames +o nospace 2>/dev/null ||
compgen -f /non-existing-dir/ > /dev/null

Unfortunately, this makes this function always return with error
when it is not invoked in real completion, but e.g. in tests of
't9902-completion.sh':

- First the 'compopt' line errors out
- either because in Bash v3.x there is no such command,
- or because in Bash v4.x it complains about "not currently
executing completion function",

- then 'compgen' just silently returns with error because of the
non-existing directory.

Since __gitcomp_file_direct() is now the last command executed in
__git_complete_index_file(), that function returns with error as well,
which prevents it from being invoked in tests directly as is, and
would require extra steps in test to hide its error code.

So let's make sure that __gitcomp_file_direct() doesn't return with
error, because in the tests coming in the following patch we do want
to exercise __git_complete_index_file() directly,

__gitcomp_file() contains the same construct, and thus it, too, always
returns with error. Update that function accordingly as well.

While at it, also remove the space from between the redirection
operator and the filename in both functions.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

merge-recursive: provide pair of `unpack_trees_{start... Elijah Newren Sun, 20 May 2018 10:17:35 +0000 (12:17 +0200)

merge-recursive: provide pair of `unpack_trees_{start,finish}()`

Rename `git_merge_trees()` to `unpack_trees_start()` and extract the
call to `discard_index()` into a new function `unpack_trees_finish()`.
As a result, these are called early resp. late in `merge_trees()`,
making the resource handling clearer. A later commit will expand on
that, teaching `..._finish()` to free more memory. (So rather than
moving the FIXME-comment, just drop it, since it will be addressed soon
enough.)

Also call `..._finish()` when `merge_trees()` returns early.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Martin Ågren <martin.agren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

merge: setup `opts` later in `checkout_fast_forward()`Martin Ågren Sun, 20 May 2018 10:17:34 +0000 (12:17 +0200)

merge: setup `opts` later in `checkout_fast_forward()`

After we initialize the various fields in `opts` but before we actually
use them, we might return early. Move the initialization further down,
to immediately before we use `opts`.

This limits the scope of `opts` and will help a later commit fix a
memory leak without having to worry about those early returns.

This patch is best viewed using something like this (note the tab!):
--color-moved --anchored=" trees[nr_trees] = parse_tree_indirect"

Signed-off-by: Martin Ågren <martin.agren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

config: a user-provided invalid section is not a BUGJohannes Schindelin Thu, 17 May 2018 21:47:06 +0000 (23:47 +0200)

config: a user-provided invalid section is not a BUG

This was pointed out by Jeff King while the empty-config-section-fix
patch series was cooking, and was not addressed in time for that patch
series to advance to `master`.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

merge-recursive: give notice when submodule commit... Leif Middelschulte Thu, 17 May 2018 18:40:08 +0000 (11:40 -0700)

merge-recursive: give notice when submodule commit gets fast-forwarded

Inform the user about an automatically fast-forwarded submodule. The
silent merge behavior was introduced by commit 68d03e4a6e44 ("Implement
automatic fast-forward merge for submodules", 2010-07-07)).

Signed-off-by: Leif Middelschulte <Leif.Middelschulte@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

object.c: clear replace map before freeing itStefan Beller Thu, 17 May 2018 18:29:57 +0000 (11:29 -0700)

object.c: clear replace map before freeing it

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

fetch: generate ref-prefixes when using a configured... Brandon Williams Wed, 16 May 2018 23:48:22 +0000 (16:48 -0700)

fetch: generate ref-prefixes when using a configured refspec

Teach fetch to generate ref-prefixes, to be used for server-side
filtering of the ref-advertisement, based on the configured fetch
refspec ('remote.<name>.fetch') when no user provided refspec exists.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

refspec: consolidate ref-prefix generation logicBrandon Williams Wed, 16 May 2018 23:48:21 +0000 (16:48 -0700)

refspec: consolidate ref-prefix generation logic

When using protocol v2 a client constructs a list of ref-prefixes which
are sent across the wire so that the server can do server-side filtering
of the ref-advertisement. The logic that does this exists for both
fetch and push (even though no push support for v2 currently exists yet)
and is roughly the same so lets consolidate this logic and make it
general enough that it can be used for both the push and fetch cases.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

submodule: convert push_unpushed_submodules to take... Brandon Williams Wed, 16 May 2018 22:58:23 +0000 (15:58 -0700)

submodule: convert push_unpushed_submodules to take a struct refspec

Convert 'push_unpushed_submodules()' to take a 'struct refspec' as a
parameter instead of an array of 'const char *'.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

remote: convert check_push_refs to take a struct refspecBrandon Williams Wed, 16 May 2018 22:58:22 +0000 (15:58 -0700)

remote: convert check_push_refs to take a struct refspec

Convert 'check_push_refs()' to take a 'struct refspec' as a parameter
instead of an array of 'const char *'.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

remote: convert match_push_refs to take a struct refspecBrandon Williams Wed, 16 May 2018 22:58:21 +0000 (15:58 -0700)

remote: convert match_push_refs to take a struct refspec

Convert 'match_push_refs()' to take a 'struct refspec' as a parameter
instead of an array of 'const char *'.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

http-push: store refspecs in a struct refspecBrandon Williams Wed, 16 May 2018 22:58:20 +0000 (15:58 -0700)

http-push: store refspecs in a struct refspec

Convert http-push.c to store refspecs in a 'struct refspec' instead of
in an array of 'const char *'.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

transport: remove transport_verify_remote_namesBrandon Williams Wed, 16 May 2018 22:58:19 +0000 (15:58 -0700)

transport: remove transport_verify_remote_names

Remove 'transprot_verify_remote_names()' because all callers have
migrated to using 'struct refspec' which performs the same checks in
'parse_refspec()'.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

send-pack: store refspecs in a struct refspecBrandon Williams Wed, 16 May 2018 22:58:18 +0000 (15:58 -0700)

send-pack: store refspecs in a struct refspec

Convert send-pack.c to store refspecs in a 'struct refspec' instead of
as an array of 'const char *'.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

transport: convert transport_push to take a struct... Brandon Williams Wed, 16 May 2018 22:58:17 +0000 (15:58 -0700)

transport: convert transport_push to take a struct refspec

Convert 'transport_push()' to take a 'struct refspec' as a
parameter instead of an array of strings which represent
refspecs.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

push: convert to use struct refspecBrandon Williams Wed, 16 May 2018 22:58:16 +0000 (15:58 -0700)

push: convert to use struct refspec

Convert the refspecs in builtin/push.c to be stored in a 'struct
refspec' instead of being stored in a list of 'struct refspec_item's.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

push: check for errors earlierBrandon Williams Wed, 16 May 2018 22:58:15 +0000 (15:58 -0700)

push: check for errors earlier

Move the error checking for using the "--mirror", "--all", and "--tags"
options earlier and explicitly check for the presence of the flags
instead of checking for a side-effect of the flag.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

remote: convert match_explicit_refs to take a struct... Brandon Williams Wed, 16 May 2018 22:58:14 +0000 (15:58 -0700)

remote: convert match_explicit_refs to take a struct refspec

Convert 'match_explicit_refs()' to take a 'struct refspec' as a
parameter instead of a list of 'struct refspec_item'.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

remote: convert get_ref_match to take a struct refspecBrandon Williams Wed, 16 May 2018 22:58:13 +0000 (15:58 -0700)

remote: convert get_ref_match to take a struct refspec

Convert 'get_ref_match()' to take a 'struct refspec' as a parameter
instead of a list of 'struct refspec_item'.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

remote: convert query_refspecs to take a struct refspecBrandon Williams Wed, 16 May 2018 22:58:12 +0000 (15:58 -0700)

remote: convert query_refspecs to take a struct refspec

Convert 'query_refspecs()' to take a 'struct refspec' as a parameter instead
of a list of 'struct refspec_item'.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

remote: convert apply_refspecs to take a struct refspecBrandon Williams Wed, 16 May 2018 22:58:11 +0000 (15:58 -0700)

remote: convert apply_refspecs to take a struct refspec

Convert 'apply_refspecs()' to take a 'struct refspec' as a parameter instead
of a list of 'struct refspec_item'.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

remote: convert get_stale_heads to take a struct refspecBrandon Williams Wed, 16 May 2018 22:58:10 +0000 (15:58 -0700)

remote: convert get_stale_heads to take a struct refspec

Convert 'get_stale_heads()' to take a 'struct refspec' as a parameter instead
of a list of 'struct refspec_item'.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

fetch: convert prune_refs to take a struct refspecBrandon Williams Wed, 16 May 2018 22:58:09 +0000 (15:58 -0700)

fetch: convert prune_refs to take a struct refspec

Convert 'prune_refs()' to take a 'struct refspec' as a parameter instead
of a list of 'struct refspec_item'.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

fetch: convert get_ref_map to take a struct refspecBrandon Williams Wed, 16 May 2018 22:58:08 +0000 (15:58 -0700)

fetch: convert get_ref_map to take a struct refspec

Convert 'get_ref_map()' to take a 'struct refspec' as a parameter
instead of a list of 'struct refspec_item'.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

fetch: convert do_fetch to take a struct refspecBrandon Williams Wed, 16 May 2018 22:58:07 +0000 (15:58 -0700)

fetch: convert do_fetch to take a struct refspec

Convert 'do_fetch()' to take a 'struct refspec' as a parameter instead
of a list of 'struct refspec_item'.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

refspec: remove the deprecated functionsBrandon Williams Wed, 16 May 2018 22:58:06 +0000 (15:58 -0700)

refspec: remove the deprecated functions

Now that there are no callers of 'parse_push_refspec()',
'parse_fetch_refspec()', and 'free_refspec()', remove these
functions.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

fetch: convert refmap to use struct refspecBrandon Williams Wed, 16 May 2018 22:58:05 +0000 (15:58 -0700)

fetch: convert refmap to use struct refspec

Convert the refmap in builtin/fetch.c to be stored in a
'struct refspec'.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

fetch: convert fetch_one to use struct refspecBrandon Williams Wed, 16 May 2018 22:58:04 +0000 (15:58 -0700)

fetch: convert fetch_one to use struct refspec

Convert 'fetch_one()' to use 'struct refspec'.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

transport-helper: convert to use struct refspecBrandon Williams Wed, 16 May 2018 22:58:03 +0000 (15:58 -0700)

transport-helper: convert to use struct refspec

Convert the refspecs in transport-helper.c to be stored in a
'struct refspec'.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

remote: remove add_prune_tags_to_fetch_refspecBrandon Williams Wed, 16 May 2018 22:58:02 +0000 (15:58 -0700)

remote: remove add_prune_tags_to_fetch_refspec

Remove 'add_prune_tags_to_fetch_refspec()' function and instead have the
only caller directly add the tag refspec using 'refspec_append()'.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

remote: convert fetch refspecs to struct refspecBrandon Williams Wed, 16 May 2018 22:58:01 +0000 (15:58 -0700)

remote: convert fetch refspecs to struct refspec

Convert the set of fetch refspecs stored in 'struct remote' to use
'struct refspec'.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

remote: convert push refspecs to struct refspecBrandon Williams Wed, 16 May 2018 22:58:00 +0000 (15:58 -0700)

remote: convert push refspecs to struct refspec

Convert the set of push refspecs stored in 'struct remote' to use
'struct refspec'.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

fast-export: convert to use struct refspecBrandon Williams Wed, 16 May 2018 22:57:59 +0000 (15:57 -0700)

fast-export: convert to use struct refspec

Convert fast-export to use 'struct refspec' instead of using a list of
refspec_item's.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

clone: convert cmd_clone to use refspec_item_initBrandon Williams Wed, 16 May 2018 22:57:58 +0000 (15:57 -0700)

clone: convert cmd_clone to use refspec_item_init

Convert 'cmd_clone()' to use 'refspec_item_init()' instead of relying on
the old 'parse_fetch_refspec()' to initialize a single refspec item.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

remote: convert match_push_refs to use struct refspecBrandon Williams Wed, 16 May 2018 22:57:57 +0000 (15:57 -0700)

remote: convert match_push_refs to use struct refspec

Convert 'match_push_refs()' to use struct refspec.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

remote: convert check_push_refs to use struct refspecBrandon Williams Wed, 16 May 2018 22:57:56 +0000 (15:57 -0700)

remote: convert check_push_refs to use struct refspec

Convert 'check_push_refs()' to use 'struct refspec'.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

transport: convert transport_push to use struct refspecBrandon Williams Wed, 16 May 2018 22:57:55 +0000 (15:57 -0700)

transport: convert transport_push to use struct refspec

Convert the logic in 'transport_push()' which calculates a list of
ref-prefixes to use 'struct refspec'.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

pull: convert get_tracking_branch to use refspec_item_initBrandon Williams Wed, 16 May 2018 22:57:54 +0000 (15:57 -0700)

pull: convert get_tracking_branch to use refspec_item_init

Convert 'get_tracking_branch()' to use 'refspec_item_init()' instead of
the old 'parse_fetch_refspec()' function.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

submodule--helper: convert push_check to use struct... Brandon Williams Wed, 16 May 2018 22:57:53 +0000 (15:57 -0700)

submodule--helper: convert push_check to use struct refspec

Convert 'push_check()' to use 'struct refspec'.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

refspec: convert valid_fetch_refspec to use parse_refspecBrandon Williams Wed, 16 May 2018 22:57:52 +0000 (15:57 -0700)

refspec: convert valid_fetch_refspec to use parse_refspec

Convert 'valid_fetch_refspec()' to use the new 'parse_refspec()'
function to only parse a single refspec and eliminate an allocation.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

refspec: introduce struct refspecBrandon Williams Wed, 16 May 2018 22:57:51 +0000 (15:57 -0700)

refspec: introduce struct refspec

Introduce 'struct refspec', an abstraction around a collection of
'struct refspec_item's much like how 'struct pathspec' holds a
collection of 'struct pathspec_item's.

A refspec struct also contains an array of the original refspec strings
which will be used to facilitate the migration to using this new
abstraction throughout the code base.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

refspec: factor out parsing a single refspecBrandon Williams Wed, 16 May 2018 22:57:50 +0000 (15:57 -0700)

refspec: factor out parsing a single refspec

Factor out the logic which parses a single refspec into its own
function. This makes it easier to reuse this logic in a future patch.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

refspec: rename struct refspec to struct refspec_itemBrandon Williams Wed, 16 May 2018 22:57:49 +0000 (15:57 -0700)

refspec: rename struct refspec to struct refspec_item

In preparation for introducing an abstraction around a collection of
refspecs (much like how a 'struct pathspec' is a collection of 'struct
pathspec_item's) rename the existing 'struct refspec' to 'struct
refspec_item'.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

refspec: move refspec parsing logic into its own fileBrandon Williams Wed, 16 May 2018 22:57:48 +0000 (15:57 -0700)

refspec: move refspec parsing logic into its own file

In preparation for performing a refactor on refspec related code, move
the refspec parsing logic into its own file.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

alloc: allow arbitrary repositories for alloc functionsStefan Beller Tue, 15 May 2018 21:48:42 +0000 (14:48 -0700)

alloc: allow arbitrary repositories for alloc functions

We have to convert all of the alloc functions at once, because alloc_report
uses a funky macro for reporting. It is better for the sake of mechanical
conversion to convert multiple functions at once rather than changing the
structure of the reporting function.

We record all memory allocation in alloc.c, and free them in
clear_alloc_state, which is called for all repositories except
the_repository.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

merge-recursive: i18n submodule merge output and respec... Stefan Beller Tue, 15 May 2018 20:00:29 +0000 (13:00 -0700)

merge-recursive: i18n submodule merge output and respect verbosity

The submodule merge code now uses the output() function that is used by
all the rest of the merge-recursive-code. This allows for respecting
internationalisation as well as the verbosity setting.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

submodule.c: move submodule merging to merge-recursive.cStefan Beller Tue, 15 May 2018 20:00:28 +0000 (13:00 -0700)

submodule.c: move submodule merging to merge-recursive.c

In a later patch we want to improve submodule merging by using the output()
function in merge-recursive.c for submodule merges to deliver a consistent
UI to users.

To do so we could either make the output() function globally available
so we can use it in submodule.c#merge_submodule(), or we could integrate
the submodule merging into the merging code. Choose the later as we
generally want to move submodules closer into the core.

Therefore we move any function related to merging submodules
(merge_submodule(), find_first_merges() and print_commit) to
merge-recursive.c. We'll keep add_submodule_odb() in submodule.c as it
is used by other submodule functions. While at it, add a TODO note that
we do not really like the function add_submodule_odb().

This commit is best viewed with --color-moved.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

git-submodule.sh: try harder to fetch a submoduleStefan Beller Tue, 15 May 2018 19:40:54 +0000 (12:40 -0700)

git-submodule.sh: try harder to fetch a submodule

This is the logical continuum of fb43e31f2b4 (submodule: try harder to
fetch needed sha1 by direct fetching sha1, 2016-02-23) and fixes it as
some assumptions were not correct.

The commit states:
> If $sha1 was not part of the default fetch ... fail ourselves here
> assumes that the fetch_in_submodule only fails when the serverside does
> not support fetching by sha1.

There are other failures, why such a fetch may fail, such as
fatal: Couldn't find remote ref HEAD
which can happen if the remote side doesn't advertise HEAD and we do not
have a local fetch refspec.

Not advertising HEAD is allowed by the protocol spec and would happen,
if HEAD points at an unborn branch for example.

Not having a local fetch refspec can happen when submodules are fetched
shallowly, as then git-clone doesn't setup a fetch refspec.

So do try even harder for a submodule by ignoring the exit code of the
first fetch and rather relying on the following is_tip_reachable to
see if we try fetching again.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

grep: handle corrupt index files earlyStefan Beller Tue, 15 May 2018 01:04:25 +0000 (18:04 -0700)

grep: handle corrupt index files early

Any other caller of 'repo_read_index' dies upon a negative return of
it, so grep should, too.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>