git
6 years agotag: avoid NULL pointer arithmetic
René Scharfe [Sun, 1 Oct 2017 14:45:13 +0000 (16:45 +0200)] 
tag: avoid NULL pointer arithmetic

lookup_blob() etc. can return NULL if the referenced object isn't of the
expected type.  In theory it's wrong to reference the object member in
that case.  In practice it's OK because it's located at offset 0 for all
types, so the pointer arithmetic (NULL + 0) is optimized out by the
compiler.  The issue is reported by Clang's AddressSanitizer, though.

Avoid the ASan error by casting the results of the lookup functions to
struct object pointers.  That works fine with NULL pointers as well.  We
already rely on the object member being first in all object types in
other places in the code.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agograph: use strbuf_addchars() to add spaces
René Scharfe [Sun, 1 Oct 2017 14:45:45 +0000 (16:45 +0200)] 
graph: use strbuf_addchars() to add spaces

strbuf_addf() can be used to add a specific number of space characters
by using the format "%*s" with an empty string and specifying the
desired width.  Use strbuf_addchars() instead as it's shorter, makes the
intent clearer and is a bit more efficient.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agouse strbuf_addstr() for adding strings to strbufs
René Scharfe [Sun, 1 Oct 2017 14:44:20 +0000 (16:44 +0200)] 
use strbuf_addstr() for adding strings to strbufs

Use strbuf_addstr() instead of strbuf_addf() for adding strings.  That's
simpler and makes the intent clearer.

Patch generated by Coccinelle and contrib/coccinelle/strbuf.cocci;
adjusted indentation in refs/packed-backend.c manually.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agopath: use strbuf_add_real_path()
René Scharfe [Sun, 1 Oct 2017 14:44:06 +0000 (16:44 +0200)] 
path: use strbuf_add_real_path()

Avoid a string copy to a static buffer by using strbuf_add_real_path()
instead of combining strbuf_addstr() and real_path().

Patch generated by Coccinelle and contrib/coccinelle/strbuf.cocci.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agobuiltin/: add UNLEAKs
Martin Ågren [Sun, 1 Oct 2017 17:42:08 +0000 (19:42 +0200)] 
builtin/: add UNLEAKs

Add some UNLEAKs where we are about to return from `cmd_*`. UNLEAK the
variables in the same order as we've declared them. While addressing
`msg` in builtin/tag.c, convert the existing `strbuf_release()` calls as
well.

Signed-off-by: Martin Ågren <martin.agren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agococcinelle: remove parentheses that become unnecessary
René Scharfe [Sun, 1 Oct 2017 15:12:08 +0000 (17:12 +0200)] 
coccinelle: remove parentheses that become unnecessary

Transformations that hide multiplications can end up with an pair of
parentheses that is no longer needed.  E.g. with a rule like this:

  @@
  expression E;
  @@
  - E * 2
  + double(E)

... we might get a patch like this:

  - x = (a + b) * 2;
  + x = double((a + b));

Add a pair of parentheses to the preimage side of such rules.
Coccinelle will generate patches that remove them if they are present,
and it will still match expressions that lack them.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agopretty.c: delimit "%(trailers)" arguments with ","
Taylor Blau [Sun, 1 Oct 2017 16:18:47 +0000 (09:18 -0700)] 
pretty.c: delimit "%(trailers)" arguments with ","

In preparation for adding consistent "%(trailers)" atom options to
`git-for-each-ref(1)`'s "--format" argument, change "%(trailers)" in
pretty.c to separate sub-arguments with a ",", instead of a ":".

Multiple sub-arguments are given either as "%(trailers:unfold,only)" or
"%(trailers:only,unfold)".

This change disambiguates between "top-level" arguments, and arguments
given to the trailers atom itself. It is consistent with the behavior of
"%(upstream)" and "%(push)" atoms.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agorefs: pass NULL to resolve_refdup() if hash is not needed
René Scharfe [Sun, 1 Oct 2017 07:29:03 +0000 (09:29 +0200)] 
refs: pass NULL to resolve_refdup() if hash is not needed

This allows us to get rid of several write-only variables.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agorefs: pass NULL to refs_resolve_refdup() if hash is not needed
René Scharfe [Sun, 1 Oct 2017 07:28:50 +0000 (09:28 +0200)] 
refs: pass NULL to refs_resolve_refdup() if hash is not needed

This gets us rid of a write-only variable.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agooidmap: map with OID as key
Jonathan Tan [Fri, 29 Sep 2017 22:54:22 +0000 (15:54 -0700)] 
oidmap: map with OID as key

This is similar to using the hashmap in hashmap.c, but with an
easier-to-use API. In particular, custom entry comparisons no longer
need to be written, and lookups can be done without constructing a
temporary entry structure.

This is implemented as a thin wrapper over the hashmap API. In
particular, this means that there is an additional 4-byte overhead due
to the fact that the first 4 bytes of the hash is redundantly stored.
For now, I'm taking the simpler approach, but if need be, we can
reimplement oidmap without affecting the callers significantly.

oidset has been updated to use oidmap.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoclang-format: adjust line break penalties
Johannes Schindelin [Fri, 29 Sep 2017 18:26:44 +0000 (20:26 +0200)] 
clang-format: adjust line break penalties

We really, really, really want to limit the columns to 80 per line: One
of the few consistent style comments on the Git mailing list is that the
lines should not have more than 80 columns/line (even if 79 columns/line
would make more sense, given that the code is frequently viewed as diff,
and diffs adding an extra character).

The penalty of 5 for excess characters is way too low to guarantee that,
though, as pointed out by Brandon Williams.

From the existing clang-format examples and documentation, it appears
that 100 is a penalty deemed appropriate for Stuff You Really Don't
Want, so let's assign that as the penalty for "excess characters", i.e.
overly long lines.

While at it, adjust the penalties further: we are actually not that keen
on preventing new line breaks within comments or string literals, so the
penalty of 100 seems awfully high.

Likewise, we are not all that adamant about keeping line breaks away
from assignment operators (a lot of Git's code breaks immediately after
the `=` character just to keep that 80 columns/line limit).

We do frown a little bit more about functions' return types being on
their own line than the penalty 0 would suggest, so this was adjusted,
too.

Finally, we do not particularly fancy breaking before the first parameter
in a call, but if it keeps the line shorter than 80 columns/line, that's
what we do, so lower the penalty for breaking before a call's first
parameter, but not quite as much as introducing new line breaks to
comments.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agofast-import: checkpoint: dump branches/tags/marks even if object_count==0
Eric Rannaud [Fri, 29 Sep 2017 03:09:36 +0000 (20:09 -0700)] 
fast-import: checkpoint: dump branches/tags/marks even if object_count==0

The checkpoint command cycles packfiles if object_count != 0, a sensible
test or there would be no pack files to write. Since 820b931012, the
command also dumps branches, tags and marks, but still conditionally.
However, it is possible for a command stream to modify refs or create
marks without creating any new objects.

For example, reset a branch (and keep fast-import running):

$ git fast-import
reset refs/heads/master
from refs/heads/master^

checkpoint

but refs/heads/master remains unchanged.

Other example: a commit command that re-creates an object that already
exists in the object database.

The man page also states that checkpoint "updates the refs" and that
"placing a progress command immediately after a checkpoint will inform
the reader when the checkpoint has been completed and it can safely
access the refs that fast-import updated". This wasn't always true
without this patch.

This fix unconditionally calls dump_{branches,tags,marks}() for all
checkpoint commands. dump_branches() and dump_tags() are cheap to call
in the case of a no-op.

Add tests to t9300 that observe the (non-packfiles) effects of
checkpoint.

Signed-off-by: Eric Rannaud <e@nanocritical.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agopoll.c: always set revents, even if to zero
Randall S. Becker [Thu, 28 Sep 2017 22:47:17 +0000 (07:47 +0900)] 
poll.c: always set revents, even if to zero

Match what is done to pfd[i].revents when compute_revents() returns
0 to the upstream gnulib's commit d42461c3 ("poll: fixes for large
fds", 2015-02-20).  The revents field is set to 0, without
incrementing the value rc to be returned from the function.  The
original code left the field to whatever random value the field was
initialized to.

This fixes occasional hangs in git-upload-pack on HPE NonStop.

Signed-off-by: Randall S. Becker <randall.becker@nexbridge.ca>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoThe eleventh batch for 2.15
Junio C Hamano [Fri, 29 Sep 2017 02:25:46 +0000 (11:25 +0900)] 
The eleventh batch for 2.15

Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoMerge branch 'sb/doc-config-submodule-update'
Junio C Hamano [Fri, 29 Sep 2017 02:23:44 +0000 (11:23 +0900)] 
Merge branch 'sb/doc-config-submodule-update'

* sb/doc-config-submodule-update:
  Documentation/config: clarify the meaning of submodule.<name>.update

6 years agoMerge branch 'ma/leakplugs'
Junio C Hamano [Fri, 29 Sep 2017 02:23:43 +0000 (11:23 +0900)] 
Merge branch 'ma/leakplugs'

Memory leaks in various codepaths have been plugged.

* ma/leakplugs:
  pack-bitmap[-write]: use `object_array_clear()`, don't leak
  object_array: add and use `object_array_pop()`
  object_array: use `object_array_clear()`, not `free()`
  leak_pending: use `object_array_clear()`, not `free()`
  commit: fix memory leak in `reduce_heads()`
  builtin/commit: fix memory leak in `prepare_index()`

6 years agoMerge branch 'rj/no-sign-compare'
Junio C Hamano [Fri, 29 Sep 2017 02:23:42 +0000 (11:23 +0900)] 
Merge branch 'rj/no-sign-compare'

Many codepaths have been updated to squelch -Wsign-compare
warnings.

* rj/no-sign-compare:
  ALLOC_GROW: avoid -Wsign-compare warnings
  cache.h: hex2chr() - avoid -Wsign-compare warnings
  commit-slab.h: avoid -Wsign-compare warnings
  git-compat-util.h: xsize_t() - avoid -Wsign-compare warnings

6 years agoMerge branch 'sb/merge-commit-msg-hook'
Junio C Hamano [Fri, 29 Sep 2017 02:23:42 +0000 (11:23 +0900)] 
Merge branch 'sb/merge-commit-msg-hook'

As "git commit" to conclude a conflicted "git merge" honors the
commit-msg hook, "git merge" that records a merge commit that
cleanly auto-merges should, but it didn't.
* sb/merge-commit-msg-hook (2017-09-22) 1 commit
(merged to 'next' on 2017-09-25 at 096e0502a8)
+ Documentation/githooks: mention merge in commit-msg hook

Add documentation for a topic that has recently graduated to the
'master' branch.

* sb/merge-commit-msg-hook:
  Documentation/githooks: mention merge in commit-msg hook

6 years agoMerge branch 'jt/fast-export-copy-modify-fix'
Junio C Hamano [Fri, 29 Sep 2017 02:23:42 +0000 (11:23 +0900)] 
Merge branch 'jt/fast-export-copy-modify-fix'

"git fast-export" with -M/-C option issued "copy" instruction on a
path that is simultaneously modified, which was incorrect.

* jt/fast-export-copy-modify-fix:
  fast-export: do not copy from modified file

6 years agoMerge branch 'mk/describe-match-with-all'
Junio C Hamano [Fri, 29 Sep 2017 02:23:41 +0000 (11:23 +0900)] 
Merge branch 'mk/describe-match-with-all'

"git describe --match <pattern>" has been taught to play well with
the "--all" option.

* mk/describe-match-with-all:
  describe: teach --match to handle branches and remotes

6 years agoMerge branch 'jm/status-ignored-directory-optim'
Junio C Hamano [Fri, 29 Sep 2017 02:23:40 +0000 (11:23 +0900)] 
Merge branch 'jm/status-ignored-directory-optim'

"git status --ignored", when noticing that a directory without any
tracked path is ignored, still enumerated all the ignored paths in
the directory, which is unnecessary.  The codepath has been
optimized to avoid this overhead.

* jm/status-ignored-directory-optim:
  Improve performance of git status --ignored

6 years agodoc: correct command formatting
Adam Dinwoodie [Thu, 28 Sep 2017 14:06:48 +0000 (15:06 +0100)] 
doc: correct command formatting

Leaving spaces around the `-delimeters for commands means asciidoc fails
to parse them as the start of a literal string.  Remove an extraneous
space that is causing a literal to not be formatted as such.

Signed-off-by: Adam Dinwoodie <adam@dinwoodie.org>
Acked-by: Andreas Heiduk <asheiduk@gmail.com>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agotechnical doc: add a design doc for hash function transition
Jonathan Nieder [Thu, 28 Sep 2017 04:43:21 +0000 (21:43 -0700)] 
technical doc: add a design doc for hash function transition

This document describes what a transition to a new hash function for
Git would look like.  Add it to Documentation/technical/ as the plan
of record so that future changes can be recorded as patches.

Also-by: Brandon Williams <bmwill@google.com>
Also-by: Jonathan Tan <jonathantanmy@google.com>
Also-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoThe tenth batch for 2.15
Junio C Hamano [Thu, 28 Sep 2017 05:51:45 +0000 (14:51 +0900)] 
The tenth batch for 2.15

Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoMerge branch 'js/win32-lazyload-dll'
Junio C Hamano [Thu, 28 Sep 2017 05:47:57 +0000 (14:47 +0900)] 
Merge branch 'js/win32-lazyload-dll'

Add a helper in anticipation for its need in a future topic RSN.

* js/win32-lazyload-dll:
  Win32: simplify loading of DLL functions

6 years agoMerge branch 'jc/merge-x-theirs-docfix'
Junio C Hamano [Thu, 28 Sep 2017 05:47:57 +0000 (14:47 +0900)] 
Merge branch 'jc/merge-x-theirs-docfix'

The documentation for '-X<option>' for merges was misleadingly
written to suggest that "-s theirs" exists, which is not the case.

* jc/merge-x-theirs-docfix:
  merge-strategies: avoid implying that "-s theirs" exists

6 years agoMerge branch 'ks/doc-use-camelcase-for-config-name'
Junio C Hamano [Thu, 28 Sep 2017 05:47:56 +0000 (14:47 +0900)] 
Merge branch 'ks/doc-use-camelcase-for-config-name'

Doc update.

* ks/doc-use-camelcase-for-config-name:
  doc: camelCase the config variables to improve readability

6 years agoMerge branch 'mk/diff-delta-avoid-large-offset'
Junio C Hamano [Thu, 28 Sep 2017 05:47:56 +0000 (14:47 +0900)] 
Merge branch 'mk/diff-delta-avoid-large-offset'

The delta format used in the packfile cannot reference data at
offset larger than what can be expressed in 4-byte, but the
generator for the data failed to make sure the offset does not
overflow.  This has been corrected.

* mk/diff-delta-avoid-large-offset:
  diff-delta: do not allow delta offset truncation

6 years agoMerge branch 'mk/diff-delta-uint-may-be-shorter-than-ulong'
Junio C Hamano [Thu, 28 Sep 2017 05:47:56 +0000 (14:47 +0900)] 
Merge branch 'mk/diff-delta-uint-may-be-shorter-than-ulong'

The machinery to create xdelta used in pack files received the
sizes of the data in size_t, but lost the higher bits of them by
storing them in "unsigned int" during the computation, which is
fixed.

* mk/diff-delta-uint-may-be-shorter-than-ulong:
  diff-delta: fix encoding size that would not fit in "unsigned int"

6 years agoMerge branch 'rs/resolve-ref-optional-result'
Junio C Hamano [Thu, 28 Sep 2017 05:47:56 +0000 (14:47 +0900)] 
Merge branch 'rs/resolve-ref-optional-result'

Code clean-up.

* rs/resolve-ref-optional-result:
  refs: pass NULL to resolve_ref_unsafe() if hash is not needed
  refs: pass NULL to refs_resolve_ref_unsafe() if hash is not needed
  refs: make sha1 output parameter of refs_resolve_ref_unsafe() optional

6 years agoMerge branch 'rs/mailinfo-qp-decode-fix'
Junio C Hamano [Thu, 28 Sep 2017 05:47:55 +0000 (14:47 +0900)] 
Merge branch 'rs/mailinfo-qp-decode-fix'

"git mailinfo" was loose in decoding quoted printable and produced
garbage when the two letters after the equal sign are not
hexadecimal.  This has been fixed.

* rs/mailinfo-qp-decode-fix:
  mailinfo: don't decode invalid =XY quoted-printable sequences

6 years agoMerge branch 'jk/doc-read-tree-table-asciidoctor-fix'
Junio C Hamano [Thu, 28 Sep 2017 05:47:55 +0000 (14:47 +0900)] 
Merge branch 'jk/doc-read-tree-table-asciidoctor-fix'

A docfix.

* jk/doc-read-tree-table-asciidoctor-fix:
  doc: put literal block delimiter around table

6 years agoMerge branch 'ik/userdiff-html-h-element-fix'
Junio C Hamano [Thu, 28 Sep 2017 05:47:54 +0000 (14:47 +0900)] 
Merge branch 'ik/userdiff-html-h-element-fix'

The built-in pattern to detect the "function header" for HTML did
not match <H1>..<H6> elements without any attributes, which has
been fixed.

* ik/userdiff-html-h-element-fix:
  userdiff: fix HTML hunk header regexp

6 years agoMerge branch 'jk/fallthrough'
Junio C Hamano [Thu, 28 Sep 2017 05:47:53 +0000 (14:47 +0900)] 
Merge branch 'jk/fallthrough'

Many codepaths have been updated to squelch -Wimplicit-fallthrough
warnings from Gcc 7 (which is a good code hygiene).

* jk/fallthrough:
  consistently use "fallthrough" comments in switches
  curl_trace(): eliminate switch fallthrough
  test-line-buffer: simplify command parsing

6 years agoMerge branch 'jk/diff-blob'
Junio C Hamano [Thu, 28 Sep 2017 05:47:53 +0000 (14:47 +0900)] 
Merge branch 'jk/diff-blob'

"git cat-file --textconv" started segfaulting recently, which
has been corrected.

* jk/diff-blob:
  cat-file: handle NULL object_context.path

6 years agoMerge branch 'hn/typofix'
Junio C Hamano [Thu, 28 Sep 2017 05:47:52 +0000 (14:47 +0900)] 
Merge branch 'hn/typofix'

* hn/typofix:
  submodule.h: typofix

6 years agoMerge branch 'ic/fix-filter-branch-to-handle-tag-without-tagger'
Junio C Hamano [Thu, 28 Sep 2017 05:47:52 +0000 (14:47 +0900)] 
Merge branch 'ic/fix-filter-branch-to-handle-tag-without-tagger'

"git filter-branch" cannot reproduce a history with a tag without
the tagger field, which only ancient versions of Git allowed to be
created.  This has been corrected.

* ic/fix-filter-branch-to-handle-tag-without-tagger:
  filter-branch: use hash-object instead of mktag
  filter-branch: stash away ref map in a branch
  filter-branch: preserve and restore $GIT_AUTHOR_* and $GIT_COMMITTER_*
  filter-branch: reset $GIT_* before cleaning up

6 years agoMerge branch 'jk/describe-omit-some-refs'
Junio C Hamano [Thu, 28 Sep 2017 05:47:52 +0000 (14:47 +0900)] 
Merge branch 'jk/describe-omit-some-refs'

"git describe --match" learned to take multiple patterns in v2.13
series, but the feature ignored the patterns after the first one
and did not work at all.  This has been fixed.

* jk/describe-omit-some-refs:
  describe: fix matching to actually match all patterns

6 years agosubmodule: correct error message for missing commits
Stefan Beller [Tue, 26 Sep 2017 18:27:56 +0000 (11:27 -0700)] 
submodule: correct error message for missing commits

When a submodule diff should be displayed we currently just add the
submodule objects to the main object store and then e.g. walk the
revision graph and create a summary for that submodule.

It is possible that we are missing the submodule either completely or
partially, which we currently differentiate with different error messages
depending on whether (1) the whole submodule object store is missing or
(2) just the needed for this particular diff. (1) is reported as
"not initialized", and (2) is reported as "commits not present".

If a submodule is deinit'ed its repository data is still around inside
the superproject, such that the diff can still be produced. In that way
the error message (1) is misleading as we can have a diff despite the
submodule being not initialized.

Downgrade the error message (1) to be the same as (2) and just say
the commits are not present, as that is the true reason why the diff
cannot be shown.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agodiff: correct newline in summary for renamed files
Stefan Beller [Wed, 27 Sep 2017 22:51:26 +0000 (15:51 -0700)] 
diff: correct newline in summary for renamed files

In 146fdb0dfe (diff.c: emit_diff_symbol learns about DIFF_SYMBOL_SUMMARY,
2017-06-29), the conversion from direct printing to the symbol emission
dropped the new line character for renamed, copied and rewritten files.

Add the emission of a newline, add a test for this case.

Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Stefan Beller <sbeller@google.com>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agogit: add --no-optional-locks option
Jeff King [Wed, 27 Sep 2017 06:54:30 +0000 (02:54 -0400)] 
git: add --no-optional-locks option

Some tools like IDEs or fancy editors may periodically run
commands like "git status" in the background to keep track
of the state of the repository. Some of these commands may
refresh the index and write out the result in an
opportunistic way: if they can get the index lock, then they
update the on-disk index with any updates they find. And if
not, then their in-core refresh is lost and just has to be
recomputed by the next caller.

But taking the index lock may conflict with other operations
in the repository. Especially ones that the user is doing
themselves, which _aren't_ opportunistic. In other words,
"git status" knows how to back off when somebody else is
holding the lock, but other commands don't know that status
would be happy to drop the lock if somebody else wanted it.

There are a couple possible solutions:

  1. Have some kind of "pseudo-lock" that allows other
     commands to tell status that they want the lock.

     This is likely to be complicated and error-prone to
     implement (and maybe even impossible with just
     dotlocks to work from, as it requires some
     inter-process communication).

  2. Avoid background runs of commands like "git status"
     that want to do opportunistic updates, preferring
     instead plumbing like diff-files, etc.

     This is awkward for a couple of reasons. One is that
     "status --porcelain" reports a lot more about the
     repository state than is available from individual
     plumbing commands. And two is that we actually _do_
     want to see the refreshed index. We just don't want to
     take a lock or write out the result. Whereas commands
     like diff-files expect us to refresh the index
     separately and write it to disk so that they can depend
     on the result. But that write is exactly what we're
     trying to avoid.

  3. Ask "status" not to lock or write the index.

     This is easy to implement. The big downside is that any
     work done in refreshing the index for such a call is
     lost when the process exits. So a background process
     may end up re-hashing a changed file multiple times
     until the user runs a command that does an index
     refresh themselves.

This patch implements the option 3. The idea (and the test)
is largely stolen from a Git for Windows patch by Johannes
Schindelin, 67e5ce7f63 (status: offer *not* to lock the
index and update it, 2016-08-12). The twist here is that
instead of making this an option to "git status", it becomes
a "git" option and matching environment variable.

The reason there is two-fold:

  1. An environment variable is carried through to
     sub-processes. And whether an invocation is a
     background process or not should apply to the whole
     process tree. So you could do "git --no-optional-locks
     foo", and if "foo" is a script or alias that calls
     "status", you'll still get the effect.

  2. There may be other programs that want the same
     treatment.

     I've punted here on finding more callers to convert,
     since "status" is the obvious one to call as a repeated
     background job. But "git diff"'s opportunistic refresh
     of the index may be a good candidate.

The test is taken from 67e5ce7f63, and it's worth repeating
Johannes's explanation:

  Note that the regression test added in this commit does
  not *really* verify that no index.lock file was written;
  that test is not possible in a portable way. Instead, we
  verify that .git/index is rewritten *only* when `git
  status` is run without `--no-optional-locks`.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agovalidate_headref: use get_oid_hex for detached HEADs
Jeff King [Wed, 27 Sep 2017 06:17:36 +0000 (02:17 -0400)] 
validate_headref: use get_oid_hex for detached HEADs

If a candidate HEAD isn't a symref, we check that it
contains a viable sha1. But in a post-sha1 world, we should
be checking whether it has any plausible object-id.

We can do that by switching to get_oid_hex().

Note that both before and after this patch, we only check
for a plausible object id at the start of the file, and then
call that good enough.  We ignore any content _after_ the
hex, so a string like:

  0123456789012345678901234567890123456789 foo

is accepted. Though we do put extra bytes like this into
some pseudorefs (e.g., FETCH_HEAD), we don't typically do so
with HEAD. We could tighten this up by using parse_oid_hex(),
like:

  if (!parse_oid_hex(buffer, &oid, &end) &&
      *end++ == '\n' && *end == '\0')
          return 0;

But we're probably better to remain on the loose side. We're
just checking here for a plausible-looking repository
directory, so heuristics are acceptable (if we really want
to be meticulous, we should use the actual ref code to parse
HEAD).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agovalidate_headref: use skip_prefix for symref parsing
Jeff King [Wed, 27 Sep 2017 06:17:26 +0000 (02:17 -0400)] 
validate_headref: use skip_prefix for symref parsing

Since the previous commit guarantees that our symref buffer
is NUL-terminated, we can just use skip_prefix() and friends
to parse it. This is shorter and saves us having to deal
with magic numbers and keeping the "len" counter up to date.

While we're at it, let's name the rather obscure "buf" to
"refname", since that is the thing we are parsing with it.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agovalidate_headref: NUL-terminate HEAD buffer
Jeff King [Wed, 27 Sep 2017 06:17:23 +0000 (02:17 -0400)] 
validate_headref: NUL-terminate HEAD buffer

When we are checking to see if we have a git repo, we peek
into the HEAD file and see if it's a plausible symlink,
symref, or detached HEAD.

For the latter two, we read the contents with read_in_full(),
which means they aren't NUL-terminated. The symref check is
careful to respect the length we got, but the sha1 check
will happily parse up to 40 bytes, even if we read fewer.

E.g.,:

  echo 1234 >.git/HEAD
  git rev-parse

will parse 36 uninitialized bytes from our stack buffer.

This isn't a big deal in practice. Our buffer is 256 bytes,
so we know we'll never read outside of it. The worst case is
that the uninitialized bytes look like valid hex, and we
claim a bogus HEAD file is valid. The chances of this
happening randomly are quite slim, but let's be careful.

One option would be to check that "len == 41" before feeding
the buffer to get_sha1_hex(). But we'd like to eventually
prepare for a world with variable-length hashes. Let's
NUL-terminate as soon as we've read the buffer (we already
even leave a spare byte to do so!). That fixes this problem
without depending on the size of an object id.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoworktree: check the result of read_in_full()
Jeff King [Wed, 27 Sep 2017 06:02:27 +0000 (02:02 -0400)] 
worktree: check the result of read_in_full()

We try to read "len" bytes into a buffer and just assume
that it happened correctly. In practice this should usually
be the case, since we just stat'd the file to get the
length.  But we could be fooled by transient errors or by
other processes racily truncating the file.

Let's be more careful. There's a slim chance this could
catch a real error, but it also prevents people and tools
from getting worried while reading the code.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoworktree: use xsize_t to access file size
Jeff King [Wed, 27 Sep 2017 06:02:21 +0000 (02:02 -0400)] 
worktree: use xsize_t to access file size

To read the "gitdir" file into memory, we stat the file and
allocate a buffer. But we store the size in an "int", which
may be truncated. We should use a size_t and xsize_t(),
which will detect truncation.

An overflow is unlikely for a "gitdir" file, but it's a good
practice to model.

Signed-off-by: Jeff King <peff@peff.net>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agodistinguish error versus short read from read_in_full()
Jeff King [Wed, 27 Sep 2017 06:02:11 +0000 (02:02 -0400)] 
distinguish error versus short read from read_in_full()

Many callers of read_in_full() expect to see the exact
number of bytes requested, but their error handling lumps
together true read errors and short reads due to unexpected
EOF.

We can give more specific error messages by separating these
cases (showing errno when appropriate, and otherwise
describing the short read).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoavoid looking at errno for short read_in_full() returns
Jeff King [Wed, 27 Sep 2017 06:01:07 +0000 (02:01 -0400)] 
avoid looking at errno for short read_in_full() returns

When a caller tries to read a particular set of bytes via
read_in_full(), there are three possible outcomes:

  1. An error, in which case -1 is returned and errno is
     set.

  2. A short read, in which fewer bytes are returned and
     errno is unspecified (we never saw a read error, so we
     may have some random value from whatever syscall failed
     last).

  3. The full read completed successfully.

Many callers handle cases 1 and 2 together by just checking
the result against the requested size. If their combined
error path looks at errno (e.g., by calling die_errno), they
may report a nonsense value.

Let's fix these sites by having them distinguish between the
two error cases. That avoids the random errno confusion, and
lets us give more detailed error messages.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoprefer "!=" when checking read_in_full() result
Jeff King [Wed, 27 Sep 2017 06:00:28 +0000 (02:00 -0400)] 
prefer "!=" when checking read_in_full() result

Comparing the result of read_in_full() using less-than is
potentially dangerous, as a negative return value may be
converted to an unsigned type and be considered a success.
This is discussed further in 561598cfcf (read_pack_header:
handle signed/unsigned comparison in read result,
2017-09-13).

Each of these instances is actually fine in practice:

 - in get-tar-commit-id, the HEADERSIZE macro expands to a
   signed integer. If it were switched to an unsigned type
   (e.g., a size_t), then it would be a bug.

 - the other two callers check for a short read only after
   handling a negative return separately. This is a fine
   practice, but we'd prefer to model "!=" as a general
   rule.

So all of these cases can be considered cleanups and not
actual bugfixes.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agot7406: submodule.<name>.update command must not be run from .gitmodules
Stefan Beller [Tue, 26 Sep 2017 19:54:13 +0000 (12:54 -0700)] 
t7406: submodule.<name>.update command must not be run from .gitmodules

submodule.<name>.update can be assigned an arbitrary command via setting
it to "!command". When this command is found in the regular config, Git
ought to just run that command instead of other update mechanisms.

However if that command is just found in the .gitmodules file, it is
potentially untrusted, which is why we do not run it.  Add a test
confirming the behavior.

Suggested-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agostring-list.h: move documentation from Documentation/api/ into header
Han-Wen Nienhuys [Tue, 26 Sep 2017 11:21:50 +0000 (13:21 +0200)] 
string-list.h: move documentation from Documentation/api/ into header

This mirrors commit 'bdfdaa497 ("strbuf.h: integrate api-strbuf.txt
documentation, 2015-01-16") which did the same for strbuf.h:

* API documentation uses /** */ to set it apart from other comments.

* Function names were stripped from the comments.

* Ordering of the header was adjusted to follow the one from the text
  file.

* Edited some existing comments from string-list.h for consistency.

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoread_gitfile_gently: clarify return value ownership.
Han-Wen Nienhuys [Tue, 26 Sep 2017 11:21:49 +0000 (13:21 +0200)] 
read_gitfile_gently: clarify return value ownership.

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoreal_path: clarify return value ownership
Han-Wen Nienhuys [Tue, 26 Sep 2017 11:21:48 +0000 (13:21 +0200)] 
real_path: clarify return value ownership

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoSync with 2.14.2
Junio C Hamano [Tue, 26 Sep 2017 05:15:55 +0000 (14:15 +0900)] 
Sync with 2.14.2

* maint:
  Git 2.14.2
  Git 2.13.6
  Git 2.12.5
  Git 2.11.4
  Git 2.10.5
  cvsimport: shell-quote variable used in backticks
  archimport: use safe_pipe_capture for user input
  shell: drop git-cvsserver support by default
  cvsserver: use safe_pipe_capture for `constant commands` as well
  cvsserver: use safe_pipe_capture instead of backticks
  cvsserver: move safe_pipe_capture() to the main package

6 years agosubmodule.c: describe submodule_to_gitdir() in a new comment
Han-Wen Nienhuys [Mon, 25 Sep 2017 15:59:26 +0000 (17:59 +0200)] 
submodule.c: describe submodule_to_gitdir() in a new comment

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agonotes-merge: drop dead zero-write code
Jeff King [Mon, 25 Sep 2017 20:27:57 +0000 (16:27 -0400)] 
notes-merge: drop dead zero-write code

We call write_in_full() with a size that we know is greater
than zero. The return value can never be zero, then, since
write_in_full() converts such a failed write() into ENOSPC
and returns -1.  We can just drop this branch of the error
handling entirely.

Suggested-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Jeff King <peff@peff.net>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agofiles-backend: prefer "0" for write_in_full() error check
Jeff King [Mon, 25 Sep 2017 20:27:17 +0000 (16:27 -0400)] 
files-backend: prefer "0" for write_in_full() error check

Commit 06f46f237a (avoid "write_in_full(fd, buf, len) !=
len" pattern, 2017-09-13) converted this callsite from:

  write_in_full(...) != 1

to

  write_in_full(...) < 0

But during the conflict resolution in c50424a6f0 (Merge
branch 'jk/write-in-full-fix', 2017-09-25), this morphed
into

  write_in_full(...) < 1

This behaves as we want, but we prefer to avoid modeling the
"less than length" error-check which can be subtly buggy, as
shown in efacf609c8 (config: avoid "write_in_full(fd, buf,
len) < len" pattern, 2017-09-13).

Signed-off-by: Jeff King <peff@peff.net>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoWin32: simplify loading of DLL functions
Johannes Schindelin [Mon, 25 Sep 2017 16:06:24 +0000 (18:06 +0200)] 
Win32: simplify loading of DLL functions

Dynamic loading of DLL functions is duplicated in several places in Git
for Windows' source code.

This patch adds a pair of macros to simplify the process: the
DECLARE_PROC_ADDR(<dll>, <return-type>, <function-name>,
...<function-parameter-types>...) macro to be used at the beginning of a
code block, and the INIT_PROC_ADDR(<function-name>) macro to call before
using the declared function. The return value of the INIT_PROC_ADDR()
call has to be checked; If it is NULL, the function was not found in the
specified DLL.

Example:

        DECLARE_PROC_ADDR(kernel32.dll, BOOL, CreateHardLinkW,
                          LPCWSTR, LPCWSTR, LPSECURITY_ATTRIBUTES);

        if (!INIT_PROC_ADDR(CreateHardLinkW))
                return error("Could not find CreateHardLinkW() function";

if (!CreateHardLinkW(source, target, NULL))
return error("could not create hardlink from %S to %S",
     source, target);
return 0;

Signed-off-by: Karsten Blees <blees@dcon.de>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agopacked-backend.c: rename a bunch of things and update comments
Michael Haggerty [Mon, 25 Sep 2017 08:00:18 +0000 (10:00 +0200)] 
packed-backend.c: rename a bunch of things and update comments

We've made huge changes to this file, and some of the old names and
comments are no longer very fitting. So rename a bunch of things:

* `struct packed_ref_cache` → `struct snapshot`
* `acquire_packed_ref_cache()` → `acquire_snapshot()`
* `release_packed_ref_buffer()` → `clear_snapshot_buffer()`
* `release_packed_ref_cache()` → `release_snapshot()`
* `clear_packed_ref_cache()` → `clear_snapshot()`
* `struct packed_ref_entry` → `struct snapshot_record`
* `cmp_packed_ref_entries()` → `cmp_packed_ref_records()`
* `cmp_entry_to_refname()` → `cmp_record_to_refname()`
* `sort_packed_refs()` → `sort_snapshot()`
* `read_packed_refs()` → `create_snapshot()`
* `validate_packed_ref_cache()` → `validate_snapshot()`
* `get_packed_ref_cache()` → `get_snapshot()`
* Renamed local variables and struct members accordingly.

Also update a bunch of comments to reflect the renaming and the
accumulated changes that the code has undergone.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agommapped_ref_iterator: inline into `packed_ref_iterator`
Michael Haggerty [Mon, 25 Sep 2017 08:00:17 +0000 (10:00 +0200)] 
mmapped_ref_iterator: inline into `packed_ref_iterator`

Since `packed_ref_iterator` is now delegating to
`mmapped_ref_iterator` rather than `cache_ref_iterator` to do the
heavy lifting, there is no need to keep the two iterators separate. So
"inline" `mmapped_ref_iterator` into `packed_ref_iterator`. This
removes a bunch of boilerplate.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoref_cache: remove support for storing peeled values
Michael Haggerty [Mon, 25 Sep 2017 08:00:16 +0000 (10:00 +0200)] 
ref_cache: remove support for storing peeled values

Now that the `packed-refs` backend doesn't use `ref_cache`, there is
nobody left who might want to store peeled values of references in
`ref_cache`. So remove that feature.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agopacked_ref_store: get rid of the `ref_cache` entirely
Michael Haggerty [Mon, 25 Sep 2017 08:00:15 +0000 (10:00 +0200)] 
packed_ref_store: get rid of the `ref_cache` entirely

Now that everything has been changed to read what it needs directly
out of the `packed-refs` file, `packed_ref_store` doesn't need to
maintain a `ref_cache` at all. So get rid of it.

First of all, this will save a lot of memory and lots of little
allocations. Instead of needing to store complicated parsed data
structures in memory, we just mmap the file (potentially sharing
memory with other processes) and parse only what we need.

Moreover, since the mmapped access to the file reads only the parts of
the file that it needs, this might save reading all of the data from
disk at all (at least if the file starts out sorted).

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoref_store: implement `refs_peel_ref()` generically
Michael Haggerty [Mon, 25 Sep 2017 08:00:14 +0000 (10:00 +0200)] 
ref_store: implement `refs_peel_ref()` generically

We're about to stop storing packed refs in a `ref_cache`. That means
that the only way we have left to optimize `peel_ref()` is by checking
whether the reference being peeled is the one currently being iterated
over (in `current_ref_iter`), and if so, using `ref_iterator_peel()`.
But this can be done generically; it doesn't have to be implemented
per-backend.

So implement `refs_peel_ref()` in `refs.c` and remove the `peel_ref()`
method from the refs API.

This removes the last callers of a couple of functions, so delete
them. More cleanup to come...

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agopacked_read_raw_ref(): read the reference from the mmapped buffer
Michael Haggerty [Mon, 25 Sep 2017 08:00:13 +0000 (10:00 +0200)] 
packed_read_raw_ref(): read the reference from the mmapped buffer

Instead of reading the reference from the `ref_cache`, read it
directly from the mmapped buffer.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agopacked_ref_iterator_begin(): iterate using `mmapped_ref_iterator`
Michael Haggerty [Mon, 25 Sep 2017 08:00:12 +0000 (10:00 +0200)] 
packed_ref_iterator_begin(): iterate using `mmapped_ref_iterator`

Now that we have an efficient way to iterate, in order, over the
mmapped contents of the `packed-refs` file, we can use that directly
to implement reference iteration for the `packed_ref_store`, rather
than iterating over the `ref_cache`. This is the next step towards
getting rid of the `ref_cache` entirely.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoread_packed_refs(): ensure that references are ordered when read
Michael Haggerty [Mon, 25 Sep 2017 08:00:11 +0000 (10:00 +0200)] 
read_packed_refs(): ensure that references are ordered when read

It doesn't actually matter now, because the references are only
iterated over to fill the associated `ref_cache`, which itself puts
them in the correct order. But we want to get rid of the `ref_cache`,
so we want to be able to iterate directly over the `packed-refs`
buffer, and then the iteration will need to be ordered correctly.

In fact, we already write the `packed-refs` file sorted, but it is
possible that other Git clients don't get it right. So let's not
assume that a `packed-refs` file is sorted unless it is explicitly
declared to be so via a `sorted` trait in its header line.

If it is *not* declared to be sorted, then scan quickly through the
file to check. If it is found to be out of order, then sort the
records into a new memory-only copy. This checking and sorting is done
quickly, without parsing the full file contents. However, it needs a
little bit of care to avoid reading past the end of the buffer even if
the `packed-refs` file is corrupt.

Since *we* always write the file correctly sorted, include that trait
when we write or rewrite a `packed-refs` file. This means that the
scan described in the previous paragraph should only have to be done
for `packed-refs` files that were written by older versions of the Git
command-line client, or by other clients that haven't yet learned to
write the `sorted` trait.

If `packed-refs` was already sorted, then (if the system allows it) we
can use the mmapped file contents directly. But if the system doesn't
allow a file that is currently mmapped to be replaced using
`rename()`, then it would be bad for us to keep the file mmapped for
any longer than necessary. So, on such systems, always make a copy of
the file contents, either as part of the sorting process, or
afterwards.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agopacked_ref_cache: keep the `packed-refs` file mmapped if possible
Michael Haggerty [Mon, 25 Sep 2017 08:00:10 +0000 (10:00 +0200)] 
packed_ref_cache: keep the `packed-refs` file mmapped if possible

Keep a copy of the `packed-refs` file contents in memory for as long
as a `packed_ref_cache` object is in use:

* If the system allows it, keep the `packed-refs` file mmapped.

* If not (either because the system doesn't support `mmap()` at all,
  or because a file that is currently mmapped cannot be replaced via
  `rename()`), then make a copy of the file's contents in
  heap-allocated space, and keep that around instead.

We base the choice of behavior on a new build-time switch,
`MMAP_PREVENTS_DELETE`. By default, this switch is set for Windows
variants.

After this commit, `MMAP_NONE` and `MMAP_TEMPORARY` are still handled
identically. But the next commit will introduce a difference.

This whole change is still pointless, because we only read the
`packed-refs` file contents immediately after instantiating the
`packed_ref_cache`. But that will soon change.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agopacked-backend.c: reorder some definitions
Michael Haggerty [Mon, 25 Sep 2017 08:00:09 +0000 (10:00 +0200)] 
packed-backend.c: reorder some definitions

No code has been changed. This will make subsequent patches more
self-contained.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agommapped_ref_iterator_advance(): no peeled value for broken refs
Michael Haggerty [Mon, 25 Sep 2017 08:00:08 +0000 (10:00 +0200)] 
mmapped_ref_iterator_advance(): no peeled value for broken refs

If a reference is broken, suppress its peeled value.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agommapped_ref_iterator: add iterator over a packed-refs file
Michael Haggerty [Mon, 25 Sep 2017 08:00:07 +0000 (10:00 +0200)] 
mmapped_ref_iterator: add iterator over a packed-refs file

Add a new `mmapped_ref_iterator`, which can iterate over the
references in an mmapped `packed-refs` file directly. Use this
iterator from `read_packed_refs()` to fill the packed refs cache.

Note that we are not yet willing to promise that the new iterator
generates its output in order. That doesn't matter for now, because
the packed refs cache doesn't care what order it is filled.

This change adds a lot of boilerplate without providing any obvious
benefits. The benefits will come soon, when we get rid of the
`ref_cache` for packed references altogether.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agopacked_ref_cache: remember the file-wide peeling state
Michael Haggerty [Mon, 25 Sep 2017 08:00:06 +0000 (10:00 +0200)] 
packed_ref_cache: remember the file-wide peeling state

Rather than store the peeling state (i.e., the one defined by traits
in the `packed-refs` file header line) in a local variable in
`read_packed_refs()`, store it permanently in `packed_ref_cache`. This
will be needed when we stop reading all packed refs at once.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoread_packed_refs(): read references with minimal copying
Michael Haggerty [Mon, 25 Sep 2017 08:00:05 +0000 (10:00 +0200)] 
read_packed_refs(): read references with minimal copying

Instead of copying data from the `packed-refs` file one line at time
and then processing it, process the data in place as much as possible.

Also, instead of processing one line per iteration of the main loop,
process a reference line plus its corresponding peeled line (if
present) together.

Note that this change slightly tightens up the parsing of the
`packed-refs` file. Previously, the parser would have accepted
multiple "peeled" lines for a single reference (ignoring all but the
last one). Now it would reject that.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agodocs: improve discoverability of exclude pathspec
Manav Rathi [Mon, 25 Sep 2017 08:09:00 +0000 (13:39 +0530)] 
docs: improve discoverability of exclude pathspec

The ability to exclude paths with a negative pathspec is not mentioned
in the man pages for git grep and other commands where it might be
useful.

Add an example and a pointer to the pathspec glossary entry in the man
page for git grep to help the user to discover this ability.

Add similar pointers from the git-add and git-status man pages.

Additionally,

- Add a test for the behaviour when multiple exclusions are present.
- Add a test for the ^ alias.
- Improve name of existing test.
- Improve grammar in glossary description of the exclude pathspec.

Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Manav Rathi <mnvrth@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agodoc: camelCase the config variables to improve readability
Kaartic Sivaraam [Sat, 23 Sep 2017 04:56:17 +0000 (10:26 +0530)] 
doc: camelCase the config variables to improve readability

References to multi-word configuration variable names in our
documentation must consistently use camelCase to highlight where
the word boundaries are, even though these are treated case
insensitively.

Fix a few places that spell them in all lowercase, which makes
them harder to read.

Signed-off-by: Kaartic Sivaraam <kaarticsivaraam91196@gmail.com>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoThe ninth batch for 2.15
Junio C Hamano [Mon, 25 Sep 2017 06:28:27 +0000 (15:28 +0900)] 
The ninth batch for 2.15

Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoMerge branch 'ks/test-readme-phrasofix'
Junio C Hamano [Mon, 25 Sep 2017 06:24:10 +0000 (15:24 +0900)] 
Merge branch 'ks/test-readme-phrasofix'

Doc updates.

* ks/test-readme-phrasofix:
  t/README: fix typo and grammatically improve a sentence

6 years agoMerge branch 'ow/rev-parse-is-shallow-repo'
Junio C Hamano [Mon, 25 Sep 2017 06:24:10 +0000 (15:24 +0900)] 
Merge branch 'ow/rev-parse-is-shallow-repo'

"git rev-parse" learned "--is-shallow-repository", that is to be
used in a way similar to existing "--is-bare-repository" and
friends.

* ow/rev-parse-is-shallow-repo:
  rev-parse: rev-parse: add --is-shallow-repository

6 years agoMerge branch 'rj/test-ulimit-on-windows'
Junio C Hamano [Mon, 25 Sep 2017 06:24:09 +0000 (15:24 +0900)] 
Merge branch 'rj/test-ulimit-on-windows'

On Cygwin, "ulimit -s" does not report failure but it does not work
at all, which causes an unexpected success of some tests that
expect failures under a limited stack situation.  This has been
fixed.

* rj/test-ulimit-on-windows:
  t9010-*.sh: skip all tests if the PIPE prereq is missing
  test-lib: use more compact expression in PIPE prerequisite
  test-lib: don't use ulimit in test prerequisites on cygwin

6 years agoMerge branch 'jk/info-alternates-fix'
Junio C Hamano [Mon, 25 Sep 2017 06:24:09 +0000 (15:24 +0900)] 
Merge branch 'jk/info-alternates-fix'

A regression fix for 2.11 that made the code to read the list of
alternate object stores overrun the end of the string.

* jk/info-alternates-fix:
  read_info_alternates: warn on non-trivial errors
  read_info_alternates: read contents into strbuf

6 years agoMerge branch 'mh/for-each-string-list-item-empty-fix'
Junio C Hamano [Mon, 25 Sep 2017 06:24:09 +0000 (15:24 +0900)] 
Merge branch 'mh/for-each-string-list-item-empty-fix'

Code cmp.std.c nitpick.

* mh/for-each-string-list-item-empty-fix:
  for_each_string_list_item: avoid undefined behavior for empty list

6 years agoMerge branch 'tb/test-lint-echo-e'
Junio C Hamano [Mon, 25 Sep 2017 06:24:09 +0000 (15:24 +0900)] 
Merge branch 'tb/test-lint-echo-e'

The test linter has been taught that we do not like "echo -e".

* tb/test-lint-echo-e:
  test-lint: echo -e (or -E) is not portable

6 years agoMerge branch 'jk/revision-remove-cmdline-pathspec'
Junio C Hamano [Mon, 25 Sep 2017 06:24:09 +0000 (15:24 +0900)] 
Merge branch 'jk/revision-remove-cmdline-pathspec'

Code clean-up that also plugs memory leaks.

* jk/revision-remove-cmdline-pathspec:
  pathspec doc: parse_pathspec does not maintain references to args
  revision: replace "struct cmdline_pathspec" with argv_array

6 years agoMerge branch 'ls/travis-scriptify'
Junio C Hamano [Mon, 25 Sep 2017 06:24:09 +0000 (15:24 +0900)] 
Merge branch 'ls/travis-scriptify'

The scripts to drive TravisCI has been reorganized and then an
optimization to avoid spending cycles on a branch whose tip is
tagged has been implemented.

* ls/travis-scriptify:
  travis-ci: fix "skip_branch_tip_with_tag()" string comparison
  travis: dedent a few scripts that are indented overly deeply
  travis-ci: skip a branch build if equal tag is present
  travis-ci: move Travis CI code into dedicated scripts

6 years agoMerge branch 'aw/gc-lockfile-fscanf-fix'
Junio C Hamano [Mon, 25 Sep 2017 06:24:08 +0000 (15:24 +0900)] 
Merge branch 'aw/gc-lockfile-fscanf-fix'

"git gc" tries to avoid running two instances at the same time by
reading and writing pid/host from and to a lock file; it used to
use an incorrect fscanf() format when reading, which has been
corrected.

* aw/gc-lockfile-fscanf-fix:
  gc: call fscanf() with %<len>s, not %<len>c, when reading hostname

6 years agoMerge branch 'hv/mv-nested-submodules-test'
Junio C Hamano [Mon, 25 Sep 2017 06:24:08 +0000 (15:24 +0900)] 
Merge branch 'hv/mv-nested-submodules-test'

A test to demonstrate "git mv" failing to adjust nested submodules
has been added.

* hv/mv-nested-submodules-test:
  add test for bug in git-mv for recursive submodules

6 years agoMerge branch 'bw/git-clang-format'
Junio C Hamano [Mon, 25 Sep 2017 06:24:07 +0000 (15:24 +0900)] 
Merge branch 'bw/git-clang-format'

"make style" runs git-clang-format to help developers by pointing
out coding style issues.

* bw/git-clang-format:
  Makefile: add style build rule
  clang-format: outline the git project's coding style

6 years agoMerge branch 'nm/imap-send-with-curl'
Junio C Hamano [Mon, 25 Sep 2017 06:24:07 +0000 (15:24 +0900)] 
Merge branch 'nm/imap-send-with-curl'

"git imap-send" has our own implementation of the protocol and also
can use more recent libCurl with the imap protocol support.  Update
the latter so that it can use the credential subsystem, and then
make it the default option to use, so that we can eventually
deprecate and remove the former.

* nm/imap-send-with-curl:
  imap-send: use curl by default when possible
  imap_send: setup_curl: retreive credentials if not set in config file
  imap-send: add wrapper to get server credentials if needed
  imap-send: return with error if curl failed

6 years agoMerge branch 'ks/commit-do-not-touch-cut-line'
Junio C Hamano [Mon, 25 Sep 2017 06:24:07 +0000 (15:24 +0900)] 
Merge branch 'ks/commit-do-not-touch-cut-line'

The explanation of the cut-line in the commit log editor has been
slightly tweaked.

* ks/commit-do-not-touch-cut-line:
  commit-template: change a message to be more intuitive

6 years agoMerge branch 'tg/refs-allowed-flags'
Junio C Hamano [Mon, 25 Sep 2017 06:24:07 +0000 (15:24 +0900)] 
Merge branch 'tg/refs-allowed-flags'

API error-proofing which happens to also squelch warnings from GCC.

* tg/refs-allowed-flags:
  refs: strip out not allowed flags from ref_transaction_update

6 years agoMerge branch 'rs/archive-excluded-directory'
Junio C Hamano [Mon, 25 Sep 2017 06:24:07 +0000 (15:24 +0900)] 
Merge branch 'rs/archive-excluded-directory'

"git archive", especially when used with pathspec, stored an empty
directory in its output, even though Git itself never does so.
This has been fixed.

* rs/archive-excluded-directory:
  archive: don't add empty directories to archives

6 years agoMerge branch 'ks/help-alias-label'
Junio C Hamano [Mon, 25 Sep 2017 06:24:07 +0000 (15:24 +0900)] 
Merge branch 'ks/help-alias-label'

"git help co" now says "co is aliased to ...", not "git co is".

* ks/help-alias-label:
  help: change a message to be more precise

6 years agoMerge branch 'jn/per-repo-object-store-fixes'
Junio C Hamano [Mon, 25 Sep 2017 06:24:06 +0000 (15:24 +0900)] 
Merge branch 'jn/per-repo-object-store-fixes'

Step #0 of a planned & larger series to make the in-core object
store per in-core repository object.

* jn/per-repo-object-store-fixes:
  replace-objects: evaluate replacement refs without using the object store
  push, fetch: error out for submodule entries not pointing to commits
  pack: make packed_git_mru global a value instead of a pointer

6 years agoMerge branch 'jk/write-in-full-fix'
Junio C Hamano [Mon, 25 Sep 2017 06:24:06 +0000 (15:24 +0900)] 
Merge branch 'jk/write-in-full-fix'

Many codepaths did not diagnose write failures correctly when disks
go full, due to their misuse of write_in_full() helper function,
which have been corrected.

* jk/write-in-full-fix:
  read_pack_header: handle signed/unsigned comparison in read result
  config: flip return value of store_write_*()
  notes-merge: use ssize_t for write_in_full() return value
  pkt-line: check write_in_full() errors against "< 0"
  convert less-trivial versions of "write_in_full() != len"
  avoid "write_in_full(fd, buf, len) != len" pattern
  get-tar-commit-id: check write_in_full() return against 0
  config: avoid "write_in_full(fd, buf, len) < len" pattern

6 years agoMerge branch 'ez/doc-duplicated-words-fix'
Junio C Hamano [Mon, 25 Sep 2017 06:24:06 +0000 (15:24 +0900)] 
Merge branch 'ez/doc-duplicated-words-fix'

Typofix.

* ez/doc-duplicated-words-fix:
  doc: fix minor typos (extra/duplicated words)

6 years agoMerge branch 'kd/doc-for-each-ref'
Junio C Hamano [Mon, 25 Sep 2017 06:24:06 +0000 (15:24 +0900)] 
Merge branch 'kd/doc-for-each-ref'

Doc update.

* kd/doc-for-each-ref:
  doc/for-each-ref: explicitly specify option names
  doc/for-each-ref: consistently use '=' to between argument names and values

6 years agoMerge branch 'cc/subprocess-handshake-missing-capabilities'
Junio C Hamano [Mon, 25 Sep 2017 06:24:06 +0000 (15:24 +0900)] 
Merge branch 'cc/subprocess-handshake-missing-capabilities'

Finishing touches to a topic already in 'master'.

* cc/subprocess-handshake-missing-capabilities:
  subprocess: loudly die when subprocess asks for an unsupported capability

6 years agoMerge branch 'kw/write-index-reduce-alloc'
Junio C Hamano [Mon, 25 Sep 2017 06:24:05 +0000 (15:24 +0900)] 
Merge branch 'kw/write-index-reduce-alloc'

A hotfix to a topic already in 'master'.

* kw/write-index-reduce-alloc:
  read-cache: fix index corruption with index v4
  Add t/helper/test-write-cache to .gitignore

6 years agoMerge branch 'mg/name-rev-tests-with-short-stack'
Junio C Hamano [Mon, 25 Sep 2017 06:24:05 +0000 (15:24 +0900)] 
Merge branch 'mg/name-rev-tests-with-short-stack'

A handful of tests to demonstrates a recursive implementation of
"name-rev" hurts.

* mg/name-rev-tests-with-short-stack:
  t6120: test describe and name-rev with deep repos
  t6120: clean up state after breaking repo
  t6120: test name-rev --all and --stdin
  t7004: move limited stack prereq to test-lib

6 years agoparse-options: only insert newline in help text if needed
Brandon Casey [Mon, 25 Sep 2017 04:08:05 +0000 (21:08 -0700)] 
parse-options: only insert newline in help text if needed

Currently, when parse_options() produces a help message it always emits
a blank line after the usage text to separate it from the options text.
If the option spec does not define any switches, or only defines hidden
switches that will not be displayed, then the help text will end up with
two trailing blank lines instead of one.  Let's defer emitting the blank
line between the usage text and the options text until it is clear that
the options section will not be empty.

Fixes t1502.5, t1502.6.

Signed-off-by: Brandon Casey <drafnel@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoparse-options: write blank line to correct output stream
Brandon Casey [Mon, 25 Sep 2017 04:08:04 +0000 (21:08 -0700)] 
parse-options: write blank line to correct output stream

When commit 54e6dc7 added translation support to parse-options, an
fprintf was mistakenly replaced by a call to putchar().  Let's use fputc
instead.

Fixes t0040.11, t0040.12, t0040.33, and t1502.8.

Signed-off-by: Brandon Casey <drafnel@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>