]> git.neil.brown.name Git - git.git/log
git.git
6 years agoMerge branch 'pw/rebase-i-regression-fix-tests'
Junio C Hamano [Fri, 30 Jun 2017 20:45:21 +0000 (13:45 -0700)]
Merge branch 'pw/rebase-i-regression-fix-tests'

Fix a recent regression to "git rebase -i" and add tests that would
have caught it and others.

* pw/rebase-i-regression-fix-tests:
  t3420: fix under GETTEXT_POISON build
  rebase: add more regression tests for console output
  rebase: add regression tests for console output
  rebase -i: add test for reflog message
  sequencer: print autostash messages to stderr

6 years agohashmap: migrate documentation from Documentation/technical into header
Stefan Beller [Fri, 30 Jun 2017 19:14:07 +0000 (12:14 -0700)]
hashmap: migrate documentation from Documentation/technical into header

While at it, clarify the use of `key`, `keydata`, `entry_or_key` as well
as documenting the new data pointer for the compare function.

Rework the example.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agopatch-ids.c: use hashmap correctly
Stefan Beller [Fri, 30 Jun 2017 19:14:06 +0000 (12:14 -0700)]
patch-ids.c: use hashmap correctly

As alluded to in the previous patch, the code in patch-ids.c is
using the hashmaps API wrong.

Luckily we do not have a bug, as all hashmap functionality that we use
here (hashmap_get) passes through the keydata.  If hashmap_get_next were
to be used, a bug would occur as that passes NULL for the key_data.

So instead use the hashmap API correctly and provide the caller required
data in the compare function via the first argument that always gets
passed and was setup via the hashmap_init function.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agohashmap.h: compare function has access to a data field
Stefan Beller [Fri, 30 Jun 2017 19:14:05 +0000 (12:14 -0700)]
hashmap.h: compare function has access to a data field

When using the hashmap a common need is to have access to caller provided
data in the compare function. A couple of times we abuse the keydata field
to pass in the data needed. This happens for example in patch-ids.c.

This patch changes the function signature of the compare function
to have one more void pointer available. The pointer given for each
invocation of the compare function must be defined in the init function
of the hashmap and is just passed through.

Documentation of this new feature is deferred to a later patch.
This is a rather mechanical conversion, just adding the new pass-through
parameter.  However while at it improve the naming of the fields of all
compare functions used by hashmaps by ensuring unused parameters are
prefixed with 'unused_' and naming the parameters what they are (instead
of 'unused' make it 'unused_keydata').

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agomerge-recursive: use DIFF_XDL_SET macro
Stefan Beller [Thu, 29 Jun 2017 22:19:32 +0000 (15:19 -0700)]
merge-recursive: use DIFF_XDL_SET macro

Instead of implementing this on our own, just use a convenience macro.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agogrep: remove redundant REG_NEWLINE when compiling fixed regex
Ævar Arnfjörð Bjarmason [Thu, 29 Jun 2017 22:22:22 +0000 (22:22 +0000)]
grep: remove redundant REG_NEWLINE when compiling fixed regex

Remove the redundant REG_NEWLINE regcomp() flag from the code that
compiles a fixed-string regular-expression.

The REG_NEWLINE causes metacharacters such as "." to match a newline,
since the basic_regex_quote_buf() function being called here escapes
all metacharacters using REG_NEWLINE is confusing and redundant.

The use of this flag was introduced as an unintended emergent property
of 793dc676e0 ("grep/icase: avoid kwsset when -F is specified",
2016-06-25).

That change amended the existing regflags, which were initialized to
REG_NEWLINE in init_grep_defaults() assuming a subsequent non-fixed
regcomp().

Manual testing reveals that this was always redundant, since no flags
of any use were inherited from opt->regflags even back
then. 793dc676e0 passes all tests with this on top:

    diff --git a/grep.c b/grep.c
    index 627ae3e3e8..89e84ed7fd 100644
    --- a/grep.c
    +++ b/grep.c
    @@ -407,3 +407,3 @@ static void compile_fixed_regexp(struct grep_pat *p, struct grep_opt *opt)
            basic_regex_quote_buf(&sb, p->pattern);
    -       regflags = opt->regflags & ~REG_EXTENDED;
    +       regflags = 0;
            if (opt->ignore_case)

Since this isn't used for anything and never was, remove it to reduce
confusion when reading this code.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agogrep: remove regflags from the public grep_opt API
Ævar Arnfjörð Bjarmason [Thu, 29 Jun 2017 22:22:21 +0000 (22:22 +0000)]
grep: remove regflags from the public grep_opt API

Refactor calls to the grep machinery to always pass opt.ignore_case &
opt.extended_regexp_option instead of setting the equivalent regflags
bits.

The bug fixed when making -i work with -P in commit 9e3cbc59d5 ("log:
make --regexp-ignore-case work with --perl-regexp", 2017-05-20) was
really just plastering over the code smell which this change fixes.

The reason for adding the extensive commentary here is that I
discovered some subtle complexity in implementing this that really
should be called out explicitly to future readers.

Before this change we'd rely on the difference between
`extended_regexp_option` and `regflags` to serve as a membrane between
our preliminary parsing of grep.extendedRegexp and grep.patternType,
and what we decided to do internally.

Now that those two are the same thing, it's necessary to unset
`extended_regexp_option` just before we commit in cases where both of
those config variables are set. See 84befcd0a4 ("grep: add a
grep.patternType configuration setting", 2012-08-03) for the code and
documentation related to that.

The explanation of why the if/else branches in
grep_commit_pattern_type() are ordered the way they are exists in that
commit message, but I think it's worth calling this subtlety out
explicitly with a comment for future readers.

Even though grep_commit_pattern_type() is the only caller of
grep_set_pattern_type_option() it's simpler to reset the
extended_regexp_option flag in the latter, since 2/3 branches in the
former would otherwise need to reset it, this way we can do it in one
place.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agogrep: remove redundant and verbose re-assignments to 0
Ævar Arnfjörð Bjarmason [Thu, 29 Jun 2017 22:22:20 +0000 (22:22 +0000)]
grep: remove redundant and verbose re-assignments to 0

Remove the redundant re-assignments of the fixed/pcre1/pcre2 fields to
zero right after the entire struct has been set to zero via
memset(...).

See an earlier related cleanup commit e0b9f8ae09 ("grep: remove
redundant regflags assignments", 2017-05-25) for an explanation of why
the code was structured like this to begin with.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agogrep: remove redundant "fixed" field re-assignment to 0
Ævar Arnfjörð Bjarmason [Thu, 29 Jun 2017 22:22:19 +0000 (22:22 +0000)]
grep: remove redundant "fixed" field re-assignment to 0

Remove the redundant re-assignment of the fixed field to zero right
after the entire struct has been set to zero via memset(...).

Unlike some nearby commits this pattern doesn't date back to the
pattern described in e0b9f8ae09 ("grep: remove redundant regflags
assignments", 2017-05-25), instead it was apparently cargo-culted in
9eceddeec6 ("Use kwset in grep", 2011-08-21).

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agogrep: adjust a redundant grep pattern type assignment
Ævar Arnfjörð Bjarmason [Thu, 29 Jun 2017 22:22:18 +0000 (22:22 +0000)]
grep: adjust a redundant grep pattern type assignment

Adjust a now-redundant assignment to extended_regexp_option to make it
zero if grep.extendedRegexp is not set. This is always called right
after init_grep_defaults() which memsets the entire structure to 0, so
there's no need to set it again to zero.

However the reason for the if/else pattern is a holdover from[1] where
this was adjusted from a bitfield assignment to a boolean. Rather than
getting rid of the assignment to 0 in all cases, let's just use the
value returned by git_config_bool(), which is more idiomatic and in
sync with the rest of the boolean handling in this function.

This is a logical follow-up to my commit to remove redundant regflags
assignments[2]. This logic was originally introduced in [3], but as
explained in the former commit it's working around a pattern in our
code that no longer exists, and is now confusing as it leads the
reader to think that this needs to be flipped back & forth.

1. 84befcd0a4 ("grep: add a grep.patternType configuration setting",
   2012-08-03)
2. e0b9f8ae09 ("grep: remove redundant regflags assignments",
   2017-05-25)
3. b22520a37c ("grep: allow -E and -n to be turned on by default via
   configuration", 2011-03-30)

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agogrep: remove redundant double assignment to 0
Ævar Arnfjörð Bjarmason [Thu, 29 Jun 2017 22:22:17 +0000 (22:22 +0000)]
grep: remove redundant double assignment to 0

Stop assigning 0 to the extended_regexp_option field right after we've
zeroed out the entire struct with memset() just a few lines earlier.

Unlike some of the code being refactored in subsequent commits, this
was always completely redundant. See the original code introduced in
84befcd0a4 ("grep: add a grep.patternType configuration setting",
2012-08-03).

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agot9700: add tests for Git::unquote_path()
Phillip Wood [Fri, 30 Jun 2017 09:49:12 +0000 (10:49 +0100)]
t9700: add tests for Git::unquote_path()

Check that unquote_path() handles spaces and escape sequences
properly.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoGit::unquote_path(): throw an exception on bad path
Phillip Wood [Fri, 30 Jun 2017 09:49:11 +0000 (10:49 +0100)]
Git::unquote_path(): throw an exception on bad path

This is what the other routines in Git.pm do if there's an error.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoGit::unquote_path(): handle '\a'
Phillip Wood [Fri, 30 Jun 2017 09:49:10 +0000 (10:49 +0100)]
Git::unquote_path(): handle '\a'

unquote_path() does not handle quoted paths containing '\a',
even though quote.c::unquote_c_style() does, and quote.c:sq_lookup[]
tells quote.c::sq_must_quote() that '\007' must be quoted as '\a'.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoadd -i: move unquote_path() to Git.pm
Phillip Wood [Fri, 30 Jun 2017 09:49:09 +0000 (10:49 +0100)]
add -i: move unquote_path() to Git.pm

Move unquote_path() from git-add--interactive to Git.pm so it can be
used by other scripts. Note this is a straight copy, it does not
handle '\a'. That will be fixed in the next commit.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agocommit-template: distinguish status information unconditionally
Kaartic Sivaraam [Fri, 30 Jun 2017 12:12:21 +0000 (17:42 +0530)]
commit-template: distinguish status information unconditionally

The commit template adds the status information without
adding a new line to distinguish them in the absence
of optional parts. This results in difficulty in interpreting
it's content, specifically for inexperienced users.

Unconditionally, add new lines to separate the status message
from the other parts of the commit-template to make it more
readable.

Signed-off-by: Kaartic Sivaraam <kaarticsivaraam91196@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agocommit-template: remove outdated notice about explicit paths
Kaartic Sivaraam [Fri, 30 Jun 2017 12:12:20 +0000 (17:42 +0530)]
commit-template: remove outdated notice about explicit paths

The notice that "git commit <paths>" default to "git commit
--only <paths>" was there since 756e3ee0 ("Merge branch
'jc/commit'", 2006-02-14).  Back then, existing users of Git
expected the command doing "git commit --include <paths>", and
after the behaviour of the command was changed to align with
other people's "$scm commit <paths>", the text was added to help
them transition their expectations.

Remove the message that now has outlived its usefulness.

Signed-off-by: Kaartic Sivaraam <kaarticsivaraam91196@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agococcinelle: polish FREE_AND_NULL rules
René Scharfe [Sun, 25 Jun 2017 08:01:04 +0000 (10:01 +0200)]
coccinelle: polish FREE_AND_NULL rules

There are two rules for using FREE_AND_NULL in free.cocci, one for
pointer types and one for expressions.  Both cause coccinelle to remove
empty lines and even newline characters between replacements for some
reason; consecutive "free(x);/x=NULL;" sequences end up as multiple
FREE_AND_NULL calls on the same time.

Remove the type rule, as the expression rule already covers it, and
rearrange the lines of the latter to place the addition of FREE_AND_NULL
between the removals, which causes coccinelle to leave surrounding
whitespace untouched.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agosubmodule--helper: do not call utf8_fprintf() unnecessarily
Junio C Hamano [Wed, 28 Jun 2017 20:38:48 +0000 (13:38 -0700)]
submodule--helper: do not call utf8_fprintf() unnecessarily

The helper function utf8_fprintf(fp, ...) has exactly the same
effect to the output stream fp as fprintf(fp, ...) does, and the
only difference is that its return value counts in display columns
consumed (assuming that the payload is encoded in UTF-8), as opposed
to number of bytes.

There is no reason to call it unless the caller cares about its
return value.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agot1450: use egrep for regexp "alternation"
Junio C Hamano [Wed, 28 Jun 2017 17:17:04 +0000 (10:17 -0700)]
t1450: use egrep for regexp "alternation"

GNU grep allows "\(A\|B\)" as alternation in BRE, but this is an
extension not understood by some other implementations of grep
(Michael Kebe reported an breakage on Solaris).

Rewrite the offending test to ERE and use egrep instead.

Noticed-by: Michael Kebe <michael.kebe@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agosubtree: honour USE_ASCIIDOCTOR when set
A. Wilcox [Wed, 28 Jun 2017 02:49:16 +0000 (21:49 -0500)]
subtree: honour USE_ASCIIDOCTOR when set

Defining USE_ASCIIDOCTOR=1 when building Git uses asciidoctor over
asciidoc when generating DocBook and man page documentation.  However,
the contrib/subtree module does not presently honour that flag.

This causes a build failure when asciidoc is not present on the build
system.  Instead, adapt the main Documentation/Makefile logic to use
asciidoctor when requested.

Signed-off-by: A. Wilcox <AWilcox@Wilcox-Tech.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agobuiltin/fetch cleanup: always set default value for submodule recursing
Stefan Beller [Tue, 27 Jun 2017 21:31:59 +0000 (14:31 -0700)]
builtin/fetch cleanup: always set default value for submodule recursing

The check for the default was introduced with 88a21979c5 (fetch/pull:
recurse into submodules when necessary, 2011-03-06), which replaced an
older construct (builtin/fetchs own implementation of the super-prefix)
introduced in be254a0ea9 (Add the 'fetch.recurseSubmodules' config setting,
2010-11-11) which made sense at the time as there was no default fetch
option for submodules at the time.

Set builtin/fetch.c#recurse_submodules_default to the same value as
submodule.c#config_fetch_recurse_submodules which is set via
set_config_fetch_recurse_submodules, such that the condition for checking
whether we have to set the default value becomes unnecessary.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoapply: check git diffs for mutually exclusive header lines
René Scharfe [Tue, 27 Jun 2017 17:03:39 +0000 (19:03 +0200)]
apply: check git diffs for mutually exclusive header lines

A file can either be added, removed, copied, or renamed, but no two of
these actions can be done by the same patch.  Some of these combinations
provoke error messages due to missing file names, and some are only
caught by an assertion.  Check git patches already as they are parsed
and report conflicting lines on sight.

Found by Vegard Nossum using AFL.

Reported-by: Vegard Nossum <vegard.nossum@oracle.com>
Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoapply: check git diffs for invalid file modes
René Scharfe [Tue, 27 Jun 2017 17:03:47 +0000 (19:03 +0200)]
apply: check git diffs for invalid file modes

An empty string as mode specification is accepted silently by git apply,
as Vegard Nossum found out using AFL.  It's interpreted as zero.  Reject
such bogus file modes, and only accept ones consisting exclusively of
octal digits.

Reported-by: Vegard Nossum <vegard.nossum@oracle.com>
Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoapply: check git diffs for missing old filenames
René Scharfe [Tue, 27 Jun 2017 17:03:30 +0000 (19:03 +0200)]
apply: check git diffs for missing old filenames

2c93286a (fix "git apply --index ..." not to deref NULL) added a check
for git patches missing a +++ line, preventing a segfault.  Check for
missing --- lines as well, and add a test for each case.

Found by Vegard Nossum using AFL.

Original-patch-by: Vegard Nossum <vegard.nossum@oracle.com>
Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoSpelling fixes
Ville Skyttä [Sun, 25 Jun 2017 10:20:41 +0000 (13:20 +0300)]
Spelling fixes

Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoTwelfth batch for 2.14
Junio C Hamano [Mon, 26 Jun 2017 21:12:46 +0000 (14:12 -0700)]
Twelfth batch for 2.14

Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoMerge branch 'mb/reword-autocomplete-message'
Junio C Hamano [Mon, 26 Jun 2017 21:09:33 +0000 (14:09 -0700)]
Merge branch 'mb/reword-autocomplete-message'

Message update.

* mb/reword-autocomplete-message:
  auto-correct: tweak phrasing

6 years agoMerge branch 'ks/t7508-indent-fix'
Junio C Hamano [Mon, 26 Jun 2017 21:09:32 +0000 (14:09 -0700)]
Merge branch 'ks/t7508-indent-fix'

Cosmetic update to a test.

* ks/t7508-indent-fix:
  t7508: fix a broken indentation

6 years agoMerge branch 'jk/add-p-commentchar-fix'
Junio C Hamano [Mon, 26 Jun 2017 21:09:31 +0000 (14:09 -0700)]
Merge branch 'jk/add-p-commentchar-fix'

"git add -p" were updated in 2.12 timeframe to cope with custom
core.commentchar but the implementation was buggy and a
metacharacter like $ and * did not work.

* jk/add-p-commentchar-fix:
  add--interactive: quote commentChar regex
  add--interactive: handle EOF in prompt_yesno

6 years agoMerge branch 'dt/raise-core-packed-git-limit'
Junio C Hamano [Mon, 26 Jun 2017 21:09:30 +0000 (14:09 -0700)]
Merge branch 'dt/raise-core-packed-git-limit'

Doc update for a topic already in 'master'.

* dt/raise-core-packed-git-limit:
  docs: update 64-bit core.packedGitLimit default

6 years agoMerge branch 'mh/packed-ref-store-prep'
Junio C Hamano [Mon, 26 Jun 2017 21:09:29 +0000 (14:09 -0700)]
Merge branch 'mh/packed-ref-store-prep'

Bugfix for a topic that is (only) in 'master'.

* mh/packed-ref-store-prep:
  for_each_bisect_ref(): don't trim refnames
  lock_packed_refs(): fix cache validity check

6 years agoMerge branch 'lb/status-stash-count'
Junio C Hamano [Mon, 26 Jun 2017 21:09:29 +0000 (14:09 -0700)]
Merge branch 'lb/status-stash-count'

"git status" learned to optionally give how many stash entries the
user has in its output.

* lb/status-stash-count:
  glossary: define 'stash entry'
  status: add optional stash count information
  stash: update documentation to use 'stash entry'

6 years agopack-bitmap: don't perform unaligned memory access
James Clarke [Mon, 26 Jun 2017 15:16:12 +0000 (16:16 +0100)]
pack-bitmap: don't perform unaligned memory access

The preceding bitmap entries have a 1-byte XOR-offset and 1-byte flags,
so their size is not a multiple of 4. Thus the name-hash cache is only
guaranteed to be 2-byte aligned and so we must use get_be32 rather than
indexing the array directly.

Signed-off-by: James Clarke <jrtc27@jrtc27.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agosha1_file: refactor has_sha1_file_with_flags
Jonathan Tan [Thu, 22 Jun 2017 00:40:24 +0000 (17:40 -0700)]
sha1_file: refactor has_sha1_file_with_flags

has_sha1_file_with_flags() implements many mechanisms in common with
sha1_object_info_extended(). Make has_sha1_file_with_flags() a
convenience function for sha1_object_info_extended() instead.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agosha1_file: do not access pack if unneeded
Jonathan Tan [Thu, 22 Jun 2017 00:40:23 +0000 (17:40 -0700)]
sha1_file: do not access pack if unneeded

Currently, regardless of the contents of the "struct object_info" passed
to sha1_object_info_extended(), that function always accesses the
packfile whenever it returns information about a packed object, since it
needs to populate "u.packed".

Add the ability to pass NULL, and use NULL-ness of the argument to
activate an optimization in which sha1_object_info_extended() does not
needlessly access the packfile. A subsequent patch will make use of this
optimization.

A similar optimization is not made for the cached and loose cases as it
would not cause a significant performance improvement.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agosha1_file: teach sha1_object_info_extended more flags
Jonathan Tan [Thu, 22 Jun 2017 00:40:22 +0000 (17:40 -0700)]
sha1_file: teach sha1_object_info_extended more flags

Improve sha1_object_info_extended() by supporting additional
flags. This allows has_sha1_file_with_flags() to be modified to use
sha1_object_info_extended() in a subsequent patch.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agot1700: make sure split-index respects core.sharedrepository
Christian Couder [Sun, 25 Jun 2017 04:34:29 +0000 (06:34 +0200)]
t1700: make sure split-index respects core.sharedrepository

Add a few tests to check that both the split-index file and the
shared-index file are created using the right permissions when
core.sharedrepository is set.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agot1301: move modebits() to test-lib-functions.sh
Christian Couder [Sun, 25 Jun 2017 04:34:28 +0000 (06:34 +0200)]
t1301: move modebits() to test-lib-functions.sh

As the modebits() function can be useful outside t1301,
let's move it into test-lib-functions.sh, and while at
it let's rename it test_modebits().

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoread-cache: use shared perms when writing shared index
Christian Couder [Sun, 25 Jun 2017 04:34:27 +0000 (06:34 +0200)]
read-cache: use shared perms when writing shared index

Since f6ecc62dbf (write_shared_index(): use tempfile module, 2015-08-10)
write_shared_index() has been using mks_tempfile() to create the
temporary file that will become the shared index.

But even before that, it looks like the functions used to create this
file didn't call adjust_shared_perm(), which means that the shared
index file has always been created with 600 permissions regardless
of the shared permission settings.

Because of that, on repositories created with `git init --shared=all`
and using the split index feature, one gets an error like:

fatal: .git/sharedindex.a52f910b489bc462f187ab572ba0086f7b5157de: index file open failed: Permission denied

when another user performs any operation that reads the shared index.

Call adjust_shared_perm() on the temporary file created by
mks_tempfile() ourselves to adjust the permission bits.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoSync with 2.13.2
Junio C Hamano [Sat, 24 Jun 2017 22:34:14 +0000 (15:34 -0700)]
Sync with 2.13.2

Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoGit 2.13.2 v2.13.2
Junio C Hamano [Sat, 24 Jun 2017 22:31:36 +0000 (15:31 -0700)]
Git 2.13.2

Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoMerge branch 'sn/reset-doc-typofix' into maint
Junio C Hamano [Sat, 24 Jun 2017 22:29:35 +0000 (15:29 -0700)]
Merge branch 'sn/reset-doc-typofix' into maint

Doc update.

* sn/reset-doc-typofix:
  doc: git-reset: fix a trivial typo

6 years agoMerge branch 'sg/doc-pretty-formats' into maint
Junio C Hamano [Sat, 24 Jun 2017 22:29:35 +0000 (15:29 -0700)]
Merge branch 'sg/doc-pretty-formats' into maint

Doc update.

* sg/doc-pretty-formats:
  docs/pretty-formats: stress that %- removes all preceding line-feeds

6 years agoMerge branch 'sd/t3200-branch-m-test' into maint
Junio C Hamano [Sat, 24 Jun 2017 22:29:34 +0000 (15:29 -0700)]
Merge branch 'sd/t3200-branch-m-test' into maint

New test.

* sd/t3200-branch-m-test:
  t3200: add test for single parameter passed to -m option

6 years agoMerge branch 'sg/revision-parser-skip-prefix' into maint
Junio C Hamano [Sat, 24 Jun 2017 22:29:34 +0000 (15:29 -0700)]
Merge branch 'sg/revision-parser-skip-prefix' into maint

Code clean-up.

* sg/revision-parser-skip-prefix:
  revision.c: use skip_prefix() in handle_revision_pseudo_opt()
  revision.c: use skip_prefix() in handle_revision_opt()
  revision.c: stricter parsing of '--early-output'
  revision.c: stricter parsing of '--no-{min,max}-parents'
  revision.h: turn rev_info.early_output back into an unsigned int

6 years agoMerge branch 'km/test-mailinfo-b-failure' into maint
Junio C Hamano [Sat, 24 Jun 2017 22:29:33 +0000 (15:29 -0700)]
Merge branch 'km/test-mailinfo-b-failure' into maint

New tests.

* km/test-mailinfo-b-failure:
  t5100: add some more mailinfo tests

6 years agoMerge branch 'sb/submodule-rm-absorb' into maint
Junio C Hamano [Sat, 24 Jun 2017 22:29:32 +0000 (15:29 -0700)]
Merge branch 'sb/submodule-rm-absorb' into maint

Doc update to a recently graduated topic.

* sb/submodule-rm-absorb:
  Documentation/git-rm: correct submodule description

6 years agoMerge branch 'jc/diff-tree-stale-comment' into maint
Junio C Hamano [Sat, 24 Jun 2017 22:29:31 +0000 (15:29 -0700)]
Merge branch 'jc/diff-tree-stale-comment' into maint

Comment fix.

* jc/diff-tree-stale-comment:
  diff-tree: update stale in-code comments

6 years agoMerge branch 'ps/stash-push-pathspec-fix' into maint
Junio C Hamano [Sat, 24 Jun 2017 22:29:30 +0000 (15:29 -0700)]
Merge branch 'ps/stash-push-pathspec-fix' into maint

"git stash push <pathspec>" did not work from a subdirectory at all.
Bugfix for a topic in v2.13

* ps/stash-push-pathspec-fix:
  git-stash: fix pushing stash with pathspec from subdir

6 years agoMerge branch 'ls/github' into maint
Junio C Hamano [Sat, 24 Jun 2017 22:29:29 +0000 (15:29 -0700)]
Merge branch 'ls/github' into maint

Help contributors that visit us at GitHub.

* ls/github:
  Configure Git contribution guidelines for github.com

6 years agoMerge branch 'jk/pack-idx-corruption-safety' into maint
Junio C Hamano [Sat, 24 Jun 2017 22:29:29 +0000 (15:29 -0700)]
Merge branch 'jk/pack-idx-corruption-safety' into maint

A flaky test has been corrected.

* jk/pack-idx-corruption-safety:
  t5313: make extended-table test more deterministic

6 years agoMerge branch 'jk/diff-blob' into maint
Junio C Hamano [Sat, 24 Jun 2017 22:29:28 +0000 (15:29 -0700)]
Merge branch 'jk/diff-blob' into maint

The result from "git diff" that compares two blobs, e.g. "git diff
$commit1:$path $commit2:$path", used to be shown with the full
object name as given on the command line, but it is more natural to
use the $path in the output and use it to look up .gitattributes.

* jk/diff-blob:
  diff: use blob path for blob/file diffs
  diff: use pending "path" if it is available
  diff: use the word "path" instead of "name" for blobs
  diff: pass whole pending entry in blobinfo
  handle_revision_arg: record paths for pending objects
  handle_revision_arg: record modes for "a..b" endpoints
  t4063: add tests of direct blob diffs
  get_sha1_with_context: dynamically allocate oc->path
  get_sha1_with_context: always initialize oc->symlink_path
  sha1_name: consistently refer to object_context as "oc"
  handle_revision_arg: add handle_dotdot() helper
  handle_revision_arg: hoist ".." check out of range parsing
  handle_revision_arg: stop using "dotdot" as a generic pointer
  handle_revision_arg: simplify commit reference lookups
  handle_revision_arg: reset "dotdot" consistently

6 years agoMerge branch 'jc/name-rev-lw-tag' into maint
Junio C Hamano [Sat, 24 Jun 2017 22:29:27 +0000 (15:29 -0700)]
Merge branch 'jc/name-rev-lw-tag' into maint

"git describe --contains" penalized light-weight tags so much that
they were almost never considered.  Instead, give them about the
same chance to be considered as an annotated tag that is the same
age as the underlying commit would.

* jc/name-rev-lw-tag:
  name-rev: favor describing with tags and use committer date to tiebreak
  name-rev: refactor logic to see if a new candidate is a better name

6 years agoEleventh batch for 2.14
Junio C Hamano [Sat, 24 Jun 2017 21:34:11 +0000 (14:34 -0700)]
Eleventh batch for 2.14

Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoMerge branch 'ab/free-and-null'
Junio C Hamano [Sat, 24 Jun 2017 21:28:41 +0000 (14:28 -0700)]
Merge branch 'ab/free-and-null'

A common pattern to free a piece of memory and assign NULL to the
pointer that used to point at it has been replaced with a new
FREE_AND_NULL() macro.

* ab/free-and-null:
  *.[ch] refactoring: make use of the FREE_AND_NULL() macro
  coccinelle: make use of the "expression" FREE_AND_NULL() rule
  coccinelle: add a rule to make "expression" code use FREE_AND_NULL()
  coccinelle: make use of the "type" FREE_AND_NULL() rule
  coccinelle: add a rule to make "type" code use FREE_AND_NULL()
  git-compat-util: add a FREE_AND_NULL() wrapper around free(ptr); ptr = NULL

6 years agoMerge branch 'jk/warn-add-gitlink'
Junio C Hamano [Sat, 24 Jun 2017 21:28:41 +0000 (14:28 -0700)]
Merge branch 'jk/warn-add-gitlink'

Using "git add d/i/r" when d/i/r is the top of the working tree of
a separate repository would create a gitlink in the index, which
would appear as a not-quite-initialized submodule to others.  We
learned to give warnings when this happens.

* jk/warn-add-gitlink:
  t: move "git add submodule" into test blocks
  add: warn when adding an embedded repository

6 years agoMerge branch 'bw/config-h'
Junio C Hamano [Sat, 24 Jun 2017 21:28:40 +0000 (14:28 -0700)]
Merge branch 'bw/config-h'

Fix configuration codepath to pay proper attention to commondir
that is used in multi-worktree situation, and isolate config API
into its own header file.

* bw/config-h:
  config: don't implicitly use gitdir or commondir
  config: respect commondir
  setup: teach discover_git_directory to respect the commondir
  config: don't include config.h by default
  config: remove git_config_iter
  config: create config.h

6 years agoMerge branch 'bw/ls-files-sans-the-index'
Junio C Hamano [Sat, 24 Jun 2017 21:28:40 +0000 (14:28 -0700)]
Merge branch 'bw/ls-files-sans-the-index'

Code clean-up.

* bw/ls-files-sans-the-index:
  ls-files: factor out tag calculation
  ls-files: factor out debug info into a function
  ls-files: convert show_files to take an index
  ls-files: convert show_ce_entry to take an index
  ls-files: convert prune_cache to take an index
  ls-files: convert ce_excluded to take an index
  ls-files: convert show_ru_info to take an index
  ls-files: convert show_other_files to take an index
  ls-files: convert show_killed_files to take an index
  ls-files: convert write_eolinfo to take an index
  ls-files: convert overlay_tree_on_cache to take an index
  tree: convert read_tree to take an index parameter
  convert: convert renormalize_buffer to take an index
  convert: convert convert_to_git to take an index
  convert: convert convert_to_git_filter_fd to take an index
  convert: convert crlf_to_git to take an index
  convert: convert get_cached_convert_stats_ascii to take an index

6 years agoMerge branch 'js/alias-early-config'
Junio C Hamano [Sat, 24 Jun 2017 21:28:39 +0000 (14:28 -0700)]
Merge branch 'js/alias-early-config'

The code to pick up and execute command alias definition from the
configuration used to switch to the top of the working tree and
then come back when the expanded alias was executed, which was
unnecessarilyl complex.  Attempt to simplify the logic by using the
early-config mechanism that does not chdir around.

* js/alias-early-config:
  alias: use the early config machinery to expand aliases
  t7006: demonstrate a problem with aliases in subdirectories
  t1308: relax the test verifying that empty alias values are disallowed
  help: use early config when autocorrecting aliases
  config: report correct line number upon error
  discover_git_directory(): avoid setting invalid git_dir

6 years agoMerge branch 'sn/reset-doc-typofix'
Junio C Hamano [Sat, 24 Jun 2017 21:28:39 +0000 (14:28 -0700)]
Merge branch 'sn/reset-doc-typofix'

Doc update.

* sn/reset-doc-typofix:
  doc: git-reset: fix a trivial typo

6 years agoMerge branch 'sg/doc-pretty-formats'
Junio C Hamano [Sat, 24 Jun 2017 21:28:39 +0000 (14:28 -0700)]
Merge branch 'sg/doc-pretty-formats'

Doc update.

* sg/doc-pretty-formats:
  docs/pretty-formats: stress that %- removes all preceding line-feeds

6 years agoMerge branch 'rs/pretty-add-again'
Junio C Hamano [Sat, 24 Jun 2017 21:28:38 +0000 (14:28 -0700)]
Merge branch 'rs/pretty-add-again'

The pretty-format specifiers like '%h', '%t', etc. had an
optimization that no longer works correctly.  In preparation/hope
of getting it correctly implemented, first discard the optimization
that is broken.

* rs/pretty-add-again:
  pretty: recalculate duplicate short hashes

6 years agoMerge branch 'jk/diff-highlight-module'
Junio C Hamano [Sat, 24 Jun 2017 21:28:37 +0000 (14:28 -0700)]
Merge branch 'jk/diff-highlight-module'

The 'diff-highlight' program (in contrib/) has been restructured
for easier reuse by an external project 'diff-so-fancy'.

* jk/diff-highlight-module:
  diff-highlight: split code into module

6 years agoMerge branch 'ah/doc-gitattributes-empty-index'
Junio C Hamano [Sat, 24 Jun 2017 21:28:37 +0000 (14:28 -0700)]
Merge branch 'ah/doc-gitattributes-empty-index'

An example in documentation that does not work in multi worktree
configuration has been corrected.

* ah/doc-gitattributes-empty-index:
  doc: do not use `rm .git/index` when normalizing line endings

6 years agoMerge branch 'ab/wildmatch-glob-slash-test'
Junio C Hamano [Sat, 24 Jun 2017 21:28:37 +0000 (14:28 -0700)]
Merge branch 'ab/wildmatch-glob-slash-test'

A new test to show the interaction between the pattern [^a-z]
(which matches '/') and a slash in a path has been added.  The
pattern should not match the slash with "pathmatch", but should
with "wildmatch".

* ab/wildmatch-glob-slash-test:
  wildmatch test: cover a blind spot in "/" matching

6 years agoMerge branch 'ab/pcre-v2'
Junio C Hamano [Sat, 24 Jun 2017 21:28:36 +0000 (14:28 -0700)]
Merge branch 'ab/pcre-v2'

Hotfix for a topic already in 'master'.

* ab/pcre-v2:
  grep: fix erroneously copy/pasted variable in check/assert pattern

6 years agoMerge branch 'da/mergetools-meld-output-opt-on-macos'
Junio C Hamano [Sat, 24 Jun 2017 21:28:36 +0000 (14:28 -0700)]
Merge branch 'da/mergetools-meld-output-opt-on-macos'

"git mergetool" learned to work around a wrapper MacOS X adds
around underlying meld.

* da/mergetools-meld-output-opt-on-macos:
  mergetools/meld: improve compatibiilty with Meld on macOS X

6 years agoMerge branch 'nd/split-index-unshare'
Junio C Hamano [Sat, 24 Jun 2017 19:04:25 +0000 (12:04 -0700)]
Merge branch 'nd/split-index-unshare'

* nd/split-index-unshare:
  Revert "split-index: add and use unshare_split_index()"

6 years agoRevert "split-index: add and use unshare_split_index()"
Junio C Hamano [Sat, 24 Jun 2017 19:02:39 +0000 (12:02 -0700)]
Revert "split-index: add and use unshare_split_index()"

This reverts commit f9d7abec2ad2f9eb3d8873169cc28c34273df082;
see public-inbox.org/git/CAP8UFD0bOfzY-_hBDKddOcJdPUpP2KEVaX_SrCgvAMYAHtseiQ@mail.gmail.com

6 years agodoc: clarify syntax for %C(auto,...) in pretty formats
Andreas Heiduk [Sat, 24 Jun 2017 07:22:58 +0000 (09:22 +0200)]
doc: clarify syntax for %C(auto,...) in pretty formats

The manual correctly describes the syntax with `auto,` but the
trailing `,` is hard to spot in a terminal.  The HTML format does not
have this problem.  Adding an example helps both worlds.

Signed-off-by: Andreas Heiduk <asheiduk@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agostrbuf.h comment: discuss strbuf_addftime() arguments in order
Ævar Arnfjörð Bjarmason [Sat, 24 Jun 2017 12:14:51 +0000 (12:14 +0000)]
strbuf.h comment: discuss strbuf_addftime() arguments in order

Change the comment documenting the strbuf_addftime() function to
discuss the parameters in the order in which they appear, which makes
this easier to read than discussing them out of order.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agosha1_file: guard against invalid loose subdirectory numbers
René Scharfe [Sat, 24 Jun 2017 14:09:39 +0000 (16:09 +0200)]
sha1_file: guard against invalid loose subdirectory numbers

Loose object subdirectories have hexadecimal names based on the first
byte of the hash of contained objects, thus their numerical
representation can range from 0 (0x00) to 255 (0xff).  Change the type
of the corresponding variable in for_each_file_in_obj_subdir() and
associated callback functions to unsigned int and add a range check.

Suggested-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>
6 years agosha1_file: let for_each_file_in_obj_subdir() handle subdir names
René Scharfe [Sat, 24 Jun 2017 12:12:30 +0000 (14:12 +0200)]
sha1_file: let for_each_file_in_obj_subdir() handle subdir names

The function for_each_file_in_obj_subdir() takes a object subdirectory
number and expects the name of the same subdirectory to be included in
the path strbuf.  Avoid this redundancy by letting the function append
the hexadecimal subdirectory name itself.  This makes it a bit easier
and safer to use the function -- it becomes impossible to specify
different subdirectories in subdir_nr and path.

Suggested-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>
6 years agop4205: add perf test script for pretty log formats
René Scharfe [Sat, 24 Jun 2017 12:12:07 +0000 (14:12 +0200)]
p4205: add perf test script for pretty log formats

Add simple performance tests for expanded log format placeholders.

Suggested-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>
6 years agowildmatch: remove unused wildopts parameter
Ævar Arnfjörð Bjarmason [Thu, 22 Jun 2017 21:38:08 +0000 (21:38 +0000)]
wildmatch: remove unused wildopts parameter

Remove the unused wildopts placeholder struct from being passed to all
wildmatch() invocations, or rather remove all the boilerplate NULL
parameters.

This parameter was added back in commit 9b3497cab9 ("wildmatch: rename
constants and update prototype", 2013-01-01) as a placeholder for
future use. Over 4 years later nothing has made use of it, let's just
remove it. It can be added in the future if we find some reason to
start using such a parameter.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agols-files: use repository object
Brandon Williams [Thu, 22 Jun 2017 18:43:48 +0000 (11:43 -0700)]
ls-files: use repository object

Convert ls-files to use a repository struct and recurse submodules
inprocess.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agorepository: enable initialization of submodules
Brandon Williams [Thu, 22 Jun 2017 18:43:47 +0000 (11:43 -0700)]
repository: enable initialization of submodules

Introduce 'repo_submodule_init()' which performs initialization of a
'struct repository' as a submodule of another 'struct repository'.

The resulting submodule 'struct repository' can be in one of three states:

  1. The submodule is initialized and has a worktree.

  2. The submodule is initialized but does not have a worktree.  This
     would occur when the submodule's gitdir is present in the
     superproject's 'gitdir/modules/' directory yet the submodule has not
     been checked out in superproject's worktree.

  3. The submodule remains uninitialized due to an error in the
     initialization process or there is no matching submodule at the
     provided path in the superproject.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agosubmodule: convert is_submodule_initialized to work on a repository
Brandon Williams [Thu, 22 Jun 2017 18:43:46 +0000 (11:43 -0700)]
submodule: convert is_submodule_initialized to work on a repository

Convert 'is_submodule_initialized()' to take a repository object and
while we're at it, lets rename the function to 'is_submodule_active()'
and remove the NEEDSWORK comment.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agosubmodule: add repo_read_gitmodules
Brandon Williams [Thu, 22 Jun 2017 18:43:45 +0000 (11:43 -0700)]
submodule: add repo_read_gitmodules

Teach the repo object to be able to populate the submodule_cache by
reading the repository's gitmodules file.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agosubmodule-config: store the_submodule_cache in the_repository
Brandon Williams [Thu, 22 Jun 2017 18:43:44 +0000 (11:43 -0700)]
submodule-config: store the_submodule_cache in the_repository

Refactor how 'the_submodule_cache' is handled so that it can be stored
inside of a repository object.  Also migrate 'the_submodule_cache' to be
stored in 'the_repository'.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agorepository: add index_state to struct repo
Brandon Williams [Thu, 22 Jun 2017 18:43:43 +0000 (11:43 -0700)]
repository: add index_state to struct repo

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoconfig: read config from a repository object
Brandon Williams [Thu, 22 Jun 2017 18:43:42 +0000 (11:43 -0700)]
config: read config from a repository object

Teach the config machinery to read config information from a repository
object.  This involves storing a 'struct config_set' inside the
repository object and adding a number of functions (repo_config*) to be
able to query a repository's config.

The current config API enables lazy-loading of the config.  This means
that when 'git_config_get_int()' is called, if the_config_set hasn't
been populated yet, then it will be populated and properly initialized by
reading the necessary config files (system wide .gitconfig, user's home
.gitconfig, and the repository's config).  To maintain this paradigm,
the new API to read from a repository object's config will also perform
this lazy-initialization.

Since both APIs (git_config_get* and repo_config_get*) have the same
semantics we can migrate the default config to be stored within
'the_repository' and just have the 'git_config_get*' family of functions
redirect to the 'repo_config_get*' functions.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agopath: add repo_worktree_path and strbuf_repo_worktree_path
Brandon Williams [Thu, 22 Jun 2017 18:43:41 +0000 (11:43 -0700)]
path: add repo_worktree_path and strbuf_repo_worktree_path

Introduce 'repo_worktree_path' and 'strbuf_repo_worktree_path' which
take a repository struct and constructs a path relative to the
repository's worktree.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agopath: add repo_git_path and strbuf_repo_git_path
Brandon Williams [Thu, 22 Jun 2017 18:43:40 +0000 (11:43 -0700)]
path: add repo_git_path and strbuf_repo_git_path

Introduce 'repo_git_path' and 'strbuf_repo_git_path' which take a
repository struct and constructs a path into the repository's git
directory.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agopath: worktree_git_path() should not use file relocation
Brandon Williams [Thu, 22 Jun 2017 18:43:39 +0000 (11:43 -0700)]
path: worktree_git_path() should not use file relocation

git_path is a convenience function that usually produces a string
$GIT_DIR/<path>.  Since v2.5.0-rc0~143^2~35 (git_path(): be aware of
file relocation in $GIT_DIR, 2014-11-30), as a side benefit callers
get support for path relocation variables like $GIT_OBJECT_DIRECTORY:

- git_path("index") is $GIT_INDEX_FILE when set
- git_path("info/grafts") is $GIT_GRAFTS_FILE when set
- git_path("objects/<foo>") is $GIT_OBJECT_DIRECTORY/<foo> when set
- git_path("hooks/<foo>") is <foo> under core.hookspath when set
- git_path("refs/<foo>") etc (see path.c::common_list) is relative
  to $GIT_COMMON_DIR instead of $GIT_DIR

worktree_git_path, by comparison, is designed to resolve files in a
specific worktree's git dir.  Unfortunately, it shares code with
git_path and performs the same relocation.  The result is that paths
that are meant to be relative to the specified worktree's git dir end
up replaced by paths from environment variables within the current git
dir.

Luckily, no current callers pass such arguments.  The relocation was
noticed when testing the result of merging two patches under review,
one of which introduces a caller:

* The first patch made git prune check the index file in each
  worktree's git dir (using worktree_git_path(wt, "index")) for
  objects not to prune.  This would trigger the unwanted relocation
  when GIT_INDEX_FILE is set, causing objects reachable from the
  index to be pruned.

* The second patch simplified the relocation logic for index,
  info/grafts, objects, and hooks to happen unconditionally instead of
  based on whether environment or configuration variables are set.
  This caused the relocation to trigger even when GIT_INDEX_FILE is
  not set.

[jn: rewrote commit message; skipping all relocation instead of just
 GIT_INDEX_FILE]

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agopath: convert do_git_path to take a 'struct repository'
Brandon Williams [Thu, 22 Jun 2017 18:43:38 +0000 (11:43 -0700)]
path: convert do_git_path to take a 'struct repository'

In preparation to adding 'git_path' like functions which operate on a
'struct repository' convert 'do_git_path' to take a 'struct repository'.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agopath: convert strbuf_git_common_path to take a 'struct repository'
Brandon Williams [Thu, 22 Jun 2017 18:43:37 +0000 (11:43 -0700)]
path: convert strbuf_git_common_path to take a 'struct repository'

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agopath: always pass in commondir to update_common_dir
Brandon Williams [Thu, 22 Jun 2017 18:43:36 +0000 (11:43 -0700)]
path: always pass in commondir to update_common_dir

Instead of passing in 'NULL' and having 'update_common_dir()' query for
the commondir, have the callers of 'update_common_dir()' be responsible
for providing the commondir.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agopath: create path.h
Brandon Williams [Thu, 22 Jun 2017 18:43:35 +0000 (11:43 -0700)]
path: create path.h

Move all path related declarations from cache.h to a new path.h header
file.  This makes cache.h smaller and makes it easier to add new path
related functions.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoenvironment: store worktree in the_repository
Brandon Williams [Thu, 22 Jun 2017 18:43:34 +0000 (11:43 -0700)]
environment: store worktree in the_repository

Migrate 'work_tree' to be stored in 'the_repository'.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoenvironment: place key repository state in the_repository
Brandon Williams [Thu, 22 Jun 2017 18:43:33 +0000 (11:43 -0700)]
environment: place key repository state in the_repository

Migrate 'git_dir', 'git_common_dir', 'git_object_dir', 'git_index_file',
'git_graft_file', and 'namespace' to be stored in 'the_repository'.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agorepository: introduce the repository object
Brandon Williams [Thu, 22 Jun 2017 18:43:32 +0000 (11:43 -0700)]
repository: introduce the repository object

Introduce the repository object 'struct repository' which can be used to
hold all state pertaining to a git repository.

Some of the benefits of object-ifying a repository are:

  1. Make the code base more readable and easier to reason about.

  2. Allow for working on multiple repositories, specifically
     submodules, within the same process.  Currently the process for
     working on a submodule involves setting up an argv_array of options
     for a particular command and then launching a child process to
     execute the command in the context of the submodule.  This is
     clunky and can require lots of little hacks in order to ensure
     correctness.  Ideally it would be nice to simply pass a repository
     and an options struct to a command.

  3. Eliminating reliance on global state will make it easier to
     enable the use of threading to improve performance.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoenvironment: remove namespace_len variable
Brandon Williams [Tue, 20 Jun 2017 19:19:34 +0000 (12:19 -0700)]
environment: remove namespace_len variable

Use 'skip_prefix' instead of 'starts_with' so that we can drop the need
to keep around 'namespace_len'.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agosetup: add comment indicating a hack
Brandon Williams [Tue, 20 Jun 2017 19:19:33 +0000 (12:19 -0700)]
setup: add comment indicating a hack

'GIT_TOPLEVEL_PREFIX_ENVIRONMENT' was added in (b58a68c1c setup: allow
for prefix to be passed to git commands) to aid in fixing a bug where
'ls-files' and 'grep' were not able to properly recurse when called from
within a subdirectory.  Add a 'NEEDSWORK' comment indicating that this
envvar should be removed once 'ls-files' and 'grep' can recurse
in-process.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agosetup: don't perform lazy initialization of repository state
Brandon Williams [Tue, 20 Jun 2017 19:19:32 +0000 (12:19 -0700)]
setup: don't perform lazy initialization of repository state

Under some circumstances (bogus GIT_DIR value or the discovered gitdir
is '.git') 'setup_git_directory()' won't initialize key repository
state.  This leads to inconsistent state after running the setup code.
To account for this inconsistent state, lazy initialization is done once
a caller asks for the repository's gitdir or some other piece of
repository state.  This is confusing and can be error prone.

Instead let's tighten the expected outcome of 'setup_git_directory()'
and ensure that it initializes repository state in all cases that would
have been handled by lazy initialization.

This also lets us drop the requirement to have 'have_git_dir()' check if
the environment variable GIT_DIR was set as that will be handled by the
end of the setup code.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoMerge branches 'bw/ls-files-sans-the-index' and 'bw/config-h' into bw/repo-object
Junio C Hamano [Wed, 21 Jun 2017 22:20:44 +0000 (15:20 -0700)]
Merge branches 'bw/ls-files-sans-the-index' and 'bw/config-h' into bw/repo-object

* bw/ls-files-sans-the-index:
  ls-files: factor out tag calculation
  ls-files: factor out debug info into a function
  ls-files: convert show_files to take an index
  ls-files: convert show_ce_entry to take an index
  ls-files: convert prune_cache to take an index
  ls-files: convert ce_excluded to take an index
  ls-files: convert show_ru_info to take an index
  ls-files: convert show_other_files to take an index
  ls-files: convert show_killed_files to take an index
  ls-files: convert write_eolinfo to take an index
  ls-files: convert overlay_tree_on_cache to take an index
  tree: convert read_tree to take an index parameter
  convert: convert renormalize_buffer to take an index
  convert: convert convert_to_git to take an index
  convert: convert convert_to_git_filter_fd to take an index
  convert: convert crlf_to_git to take an index
  convert: convert get_cached_convert_stats_ascii to take an index

* bw/config-h:
  config: don't implicitly use gitdir or commondir
  config: respect commondir
  setup: teach discover_git_directory to respect the commondir
  config: don't include config.h by default
  config: remove git_config_iter
  config: create config.h
  alias: use the early config machinery to expand aliases
  t7006: demonstrate a problem with aliases in subdirectories
  t1308: relax the test verifying that empty alias values are disallowed
  help: use early config when autocorrecting aliases
  config: report correct line number upon error
  discover_git_directory(): avoid setting invalid git_dir

6 years agopull: optionally rebase submodules (remote submodule changes only)
Stefan Beller [Fri, 23 Jun 2017 19:13:02 +0000 (12:13 -0700)]
pull: optionally rebase submodules (remote submodule changes only)

Teach pull to optionally update submodules when '--recurse-submodules'
is provided.  This will teach pull to run 'submodule update --rebase'
when the '--recurse-submodules' and '--rebase' flags are given under
specific circumstances.

On a rebase workflow:
=====================

1. Both sides change the submodule
 ------------------------------
Let's assume the following history in a submodule:

  H---I---J---K---L local branch
       \
        M---N---O---P remote branch

and the following in the superproject (recorded submodule in parens):

  A(H)---B(I)---F(K)---G(L)  local branch
          \
           C(N)---D(N)---E(P) remote branch

In an ideal world this would rebase the submodule and rewrite
the submodule pointers that the superproject points at such that
the superproject looks like

  A(H)---B(I)              F(K')---G(L')  rebased branch
           \                /
           C(N)---D(N)---E(P) remote branch

and the submodule as:

        J---K---L (old dangeling tip)
       /
  H---I               J'---K'---L' rebased branch
       \             /
        M---N---O---P remote branch

And if a conflict arises in the submodule the superproject rebase
would stop at that commit at which the submodule conflict occurs.

Currently a "pull --rebase" in the superproject produces
a merge conflict as the submodule pointer changes are
conflicting and cannot be resolved.

2. Local submodule changes only
 -----------------------
Assuming histories as above, except that the remote branch
would not contain submodule changes, then a result as

  A(H)---B(I)               F(K)---G(L)  rebased branch
           \                /
           C(I)---D(I)---E(I) remote branch

is desire-able. This is what currently happens in rebase.

If the recursive flag is given, the ideal git would
produce a superproject as:

  A(H)---B(I)              F(K')---G(L')  rebased branch (incl. sub rebase!)
           \                /
           C(I)---D(I)---E(I) remote branch

and the submodule as:

        J---K---L (old dangeling tip)
       /
  H---I               J'---K'---L' locally rebased branch
       \             /
        M---N---O---P advanced branch

This patch doesn't address this issue, however
a test is added that this fails up front.

3. Remote submodule changes only
 ----------------------
Assuming histories as in (1) except that the local superproject branch
would not have touched the submodule the rebase already works out in the
superproject with no conflicts:

  A(H)---B(I)               F(P)---G(P)  rebased branch (no sub changes)
           \                 /
           C(N)---D(N)---E(P) remote branch

The recurse flag as presented in this patch would additionally
update the submodule as:

  H---I              J'---K'---L' rebased branch
       \            /
        M---N---O---P remote branch

As neither J, K, L nor J', K', L' are referred to from the superproject,
no rewriting of the superproject commits is required.

Conclusion for 'pull --rebase --recursive'
 -----------------------------------------
If there are no local superproject changes it is sufficient to call
"submodule update --rebase" as this produces the desired results. In case
of conflicts, the behavior is the same as in 'submodule update --recursive'
which is assumed to be sane.

This patch implements (3) only.

On a merge workflow:
====================

We'll start off with the same underlying DAG as in (1) in the rebase
workflow. So in an ideal world a 'pull --merge --recursive' would
produce this:

  H---I---J---K---L----X
       \              /
        M---N---O---P

with X as the new merge-commit in the submodule and the superproject
as:

  A(H)---B(I)---F(K)---G(L)---Y(X)
          \                  /
           C(N)---D(N)---E(P)

However modifying the submodules on the fly is not supported in git-merge
such that Y(X) is not easy to produce in a single patch. In fact git-merge
doesn't know about submodules at all.

However when at least one side does not contain commits touching the
submodule at all, then we do not need to perform the merge for the
submodule but a fast-forward can be done via checking out either L or P
in the submodule.  This strategy is implemented in 68d03e4a6e (Implement
automatic fast-forward merge for submodules, 2010-07-07) already, so
to align with the rebase behavior we need to also update the worktree
of the submodule.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agobuiltin/fetch: parse recurse-submodules-default at default options parsing
Stefan Beller [Fri, 23 Jun 2017 19:13:01 +0000 (12:13 -0700)]
builtin/fetch: parse recurse-submodules-default at default options parsing

Instead of just storing the string and then later calling our own
parsing function 'parse_fetch_recurse_submodules_arg', make use of the
function callback 'option_fetch_parse_recurse_submodules' that was
introduced in the last patch. Also move all submodule recursing variables
in one spot at the top of the file.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agobuiltin/fetch: factor submodule recurse parsing out to submodule config
Stefan Beller [Fri, 23 Jun 2017 19:13:00 +0000 (12:13 -0700)]
builtin/fetch: factor submodule recurse parsing out to submodule config

Later we want to access this parsing in builtin/pull as well.

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