git/git-svn.git
6 years agoMerge branch 'bp/sub-process-convert-filter'
Junio C Hamano [Tue, 30 May 2017 02:16:42 +0000 (30 11:16 +0900)]
Merge branch 'bp/sub-process-convert-filter'

Code from "conversion using external process" codepath has been
extracted to a separate sub-process.[ch] module.

* bp/sub-process-convert-filter:
  convert: update subprocess_read_status() to not die on EOF
  sub-process: move sub-process functions into separate files
  convert: rename reusable sub-process functions
  convert: update generic functions to only use generic data structures
  convert: separate generic structures and variables from the filter specific ones
  convert: split start_multi_file_filter() into two separate functions
  pkt-line: annotate packet_writel with LAST_ARG_MUST_BE_NULL
  convert: move packet_write_line() into pkt-line as packet_writel()
  pkt-line: add packet_read_line_gently()
  pkt-line: fix packet_read_line() to handle len < 0 errors
  convert: remove erroneous tests for errno == EPIPE

6 years agoMerge branch 'bw/forking-and-threading'
Junio C Hamano [Tue, 30 May 2017 02:16:41 +0000 (30 11:16 +0900)]
Merge branch 'bw/forking-and-threading'

The "run-command" API implementation has been made more robust
against dead-locking in a threaded environment.

* bw/forking-and-threading:
  usage.c: drop set_error_handle()
  run-command: restrict PATH search to executable files
  run-command: expose is_executable function
  run-command: block signals between fork and execve
  run-command: add note about forking and threading
  run-command: handle dup2 and close errors in child
  run-command: eliminate calls to error handling functions in child
  run-command: don't die in child when duping /dev/null
  run-command: prepare child environment before forking
  string-list: add string_list_remove function
  run-command: use the async-signal-safe execv instead of execvp
  run-command: prepare command before forking
  t0061: run_command executes scripts without a #! line
  t5550: use write_script to generate post-update hook

6 years agoMerge branch 'ab/perf-wildmatch'
Junio C Hamano [Tue, 30 May 2017 02:16:40 +0000 (30 11:16 +0900)]
Merge branch 'ab/perf-wildmatch'

Add perf-test for wildmatch.

* ab/perf-wildmatch:
  perf: add test showing exponential growth in path globbing
  perf: add function to setup a fresh test repo

6 years agoMerge branch 'bw/pathspec-sans-the-index'
Junio C Hamano [Tue, 30 May 2017 02:16:40 +0000 (30 11:16 +0900)]
Merge branch 'bw/pathspec-sans-the-index'

Simplify parse_pathspec() codepath and stop it from looking at the
default in-core index.

* bw/pathspec-sans-the-index:
  pathspec: convert find_pathspecs_matching_against_index to take an index
  pathspec: remove PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP
  ls-files: prevent prune_cache from overeagerly pruning submodules
  pathspec: remove PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE flag
  submodule: add die_in_unpopulated_submodule function
  pathspec: provide a more descriptive die message

6 years agoMerge branch 'jc/name-rev-lw-tag'
Junio C Hamano [Tue, 30 May 2017 02:16:39 +0000 (30 11:16 +0900)]
Merge branch 'jc/name-rev-lw-tag'

"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 agobranch test: fix invalid config key access
Sahil Dua [Sun, 28 May 2017 17:12:16 +0000 (28 19:12 +0200)]
branch test: fix invalid config key access

Fixes the test by changing "branch.s/s/dummy" to "branch.s/s.dummy" which is
the right way of accessing config key "branch.s/s.dummy". Purpose of
this test is to confirm that this key doesn't exist after the branch
"s/s" has been renamed to "s".

Earlier it was trying to access invalid config key and hence was getting
an error. However, this wasn't caught because we were expecting the
command to fail for other reason as mentioned above.

Signed-off-by: Sahil Dua <sahildua2305@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoThird batch for 2.14
Junio C Hamano [Mon, 29 May 2017 03:39:46 +0000 (29 12:39 +0900)]
Third batch for 2.14

Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoMerge branch 'jk/ignore-broken-tags-when-ignoring-missing-links'
Junio C Hamano [Mon, 29 May 2017 03:34:54 +0000 (29 12:34 +0900)]
Merge branch 'jk/ignore-broken-tags-when-ignoring-missing-links'

Tag objects, which are not reachable from any ref, that point at
missing objects were mishandled by "git gc" and friends (they
should silently be ignored instead)

* jk/ignore-broken-tags-when-ignoring-missing-links:
  revision.c: ignore broken tags with ignore_missing_links

6 years agoMerge branch 'jk/alternate-ref-optim'
Junio C Hamano [Mon, 29 May 2017 03:34:53 +0000 (29 12:34 +0900)]
Merge branch 'jk/alternate-ref-optim'

A test allowed both "git push" and "git receive-pack" on the other
end write their traces into the same file.  This is OK on platforms
that allows atomically appending to a file opened with O_APPEND,
but on other platforms led to a mangled output, causing
intermittent test failures.  This has been fixed by disabling
traces from "receive-pack" in the test.

* jk/alternate-ref-optim:
  t5400: avoid concurrent writes into a trace file

6 years agoMerge branch 'bm/interpret-trailers-cut-line-is-eom'
Junio C Hamano [Mon, 29 May 2017 03:34:52 +0000 (29 12:34 +0900)]
Merge branch 'bm/interpret-trailers-cut-line-is-eom'

"git interpret-trailers", when used as GIT_EDITOR for "git commit
-v", looked for and appended to a trailer block at the very end,
i.e. at the end of the "diff" output.  The command has been
corrected to pay attention to the cut-mark line "commit -v" adds to
the buffer---the real trailer block should appear just before it.

* bm/interpret-trailers-cut-line-is-eom:
  interpret-trailers: honor the cut line

6 years agoMerge branch 'tg/stash-push-fixup'
Junio C Hamano [Mon, 29 May 2017 03:34:52 +0000 (29 12:34 +0900)]
Merge branch 'tg/stash-push-fixup'

The shell completion script (in contrib/) learned "git stash" has
a new "push" subcommand.

* tg/stash-push-fixup:
  completion: add git stash push

6 years agoMerge branch 'pw/rebase-i-regression-fix'
Junio C Hamano [Mon, 29 May 2017 03:34:51 +0000 (29 12:34 +0900)]
Merge branch 'pw/rebase-i-regression-fix'

Regression fix to topic recently merged to 'master'.

* pw/rebase-i-regression-fix:
  rebase -i: add missing newline to end of message
  rebase -i: silence stash apply
  rebase -i: fix reflog message

6 years agoMerge branch 'kn/ref-filter-branch-list'
Junio C Hamano [Mon, 29 May 2017 03:34:50 +0000 (29 12:34 +0900)]
Merge branch 'kn/ref-filter-branch-list'

"git for-each-ref --format=..." with %(HEAD) in the format used to
resolve the HEAD symref as many times as it had processed refs,
which was wasteful, and "git branch" shared the same problem.

* kn/ref-filter-branch-list:
  ref-filter: resolve HEAD when parsing %(HEAD) atom

6 years agoMerge branch 'km/log-showsignature-doc'
Junio C Hamano [Mon, 29 May 2017 03:34:49 +0000 (29 12:34 +0900)]
Merge branch 'km/log-showsignature-doc'

* km/log-showsignature-doc:
  config.txt: add an entry for log.showSignature

6 years agoMerge branch 'jk/update-links-in-docs'
Junio C Hamano [Mon, 29 May 2017 03:34:48 +0000 (29 12:34 +0900)]
Merge branch 'jk/update-links-in-docs'

A few http:// links that are redirected to https:// in the
documentation have been updated to https:// links.

* jk/update-links-in-docs:
  doc: use https links to Wikipedia to avoid http redirects

6 years agoMerge branch 'ja/do-not-ask-needless-questions'
Junio C Hamano [Mon, 29 May 2017 03:34:48 +0000 (29 12:34 +0900)]
Merge branch 'ja/do-not-ask-needless-questions'

Git sometimes gives an advice in a rhetorical question that does
not require an answer, which can confuse new users and non native
speakers.  Attempt to rephrase them.

* ja/do-not-ask-needless-questions:
  git-filter-branch: be more direct in an error message
  read-tree -m: make error message for merging 0 trees less smart aleck
  usability: don't ask questions if no reply is required

6 years agoMerge branch 'jk/doc-config-include'
Junio C Hamano [Mon, 29 May 2017 03:34:47 +0000 (29 12:34 +0900)]
Merge branch 'jk/doc-config-include'

Clarify documentation for include.path and includeIf.<condition>.path
configuration variables.

* jk/doc-config-include:
  docs/config: consistify include.path examples
  docs/config: avoid the term "expand" for includes
  docs/config: give a relative includeIf example
  docs/config: clarify include/includeIf relationship

6 years agoMerge branch 'sg/core-filemode-doc-typofix'
Junio C Hamano [Mon, 29 May 2017 03:34:46 +0000 (29 12:34 +0900)]
Merge branch 'sg/core-filemode-doc-typofix'

* sg/core-filemode-doc-typofix:
  docs/config.txt: fix indefinite article in core.fileMode description

6 years agoMerge branch 'jk/bug-to-abort'
Junio C Hamano [Mon, 29 May 2017 03:34:45 +0000 (29 12:34 +0900)]
Merge branch 'jk/bug-to-abort'

Introduce the BUG() macro to improve die("BUG: ...").

* jk/bug-to-abort:
  usage: add NORETURN to BUG() function definitions
  config: complain about --local outside of a git repo
  setup_git_env: convert die("BUG") to BUG()
  usage.c: add BUG() function

6 years agoMerge branch 'js/eol-on-ourselves'
Junio C Hamano [Mon, 29 May 2017 03:34:45 +0000 (29 12:34 +0900)]
Merge branch 'js/eol-on-ourselves'

Make sure our tests would pass when the sources are checked out
with "platform native" line ending convention by default on
Windows.  Some "text" files out tests use and the test scripts
themselves that are meant to be run with /bin/sh, ought to be
checked out with eol=LF even on Windows.

* js/eol-on-ourselves:
  t4051: mark supporting files as requiring LF-only line endings
  Fix the remaining tests that failed with core.autocrlf=true
  t3901: move supporting files into t/t3901/
  completion: mark bash script as LF-only
  git-new-workdir: mark script as LF-only
  Fix build with core.autocrlf=true

6 years agoMerge branch 'jc/read-tree-empty-with-m'
Junio C Hamano [Mon, 29 May 2017 03:34:45 +0000 (29 12:34 +0900)]
Merge branch 'jc/read-tree-empty-with-m'

"git read-tree -m" (no tree-ish) gave a nonsense suggestion "use
--empty if you want to clear the index".  With "-m", such a request
will still fail anyway, as you'd need to name at least one tree-ish
to be merged.

* jc/read-tree-empty-with-m:
  read-tree: "read-tree -m --empty" does not make sense

6 years agoMerge branch 'js/plug-leaks'
Junio C Hamano [Mon, 29 May 2017 03:34:44 +0000 (29 12:34 +0900)]
Merge branch 'js/plug-leaks'

Fix memory leaks pointed out by Coverity (and people).

* js/plug-leaks: (26 commits)
  checkout: fix memory leak
  submodule_uses_worktrees(): plug memory leak
  show_worktree(): plug memory leak
  name-rev: avoid leaking memory in the `deref` case
  remote: plug memory leak in match_explicit()
  add_reflog_for_walk: avoid memory leak
  shallow: avoid memory leak
  line-log: avoid memory leak
  receive-pack: plug memory leak in update()
  fast-export: avoid leaking memory in handle_tag()
  mktree: plug memory leaks reported by Coverity
  pack-redundant: plug memory leak
  setup_discovered_git_dir(): plug memory leak
  setup_bare_git_dir(): help static analysis
  split_commit_in_progress(): simplify & fix memory leak
  checkout: fix memory leak
  cat-file: fix memory leak
  mailinfo & mailsplit: check for EOF while parsing
  status: close file descriptor after reading git-rebase-todo
  difftool: address a couple of resource/memory leaks
  ...

6 years agoMerge branch 'jk/disable-pack-reuse-when-broken'
Junio C Hamano [Mon, 29 May 2017 03:34:44 +0000 (29 12:34 +0900)]
Merge branch 'jk/disable-pack-reuse-when-broken'

"pack-objects" can stream a slice of an existing packfile out when
the pack bitmap can tell that the reachable objects are all needed
in the output, without inspecting individual objects.  This
strategy however would not work well when "--local" and other
options are in use, and need to be disabled.

* jk/disable-pack-reuse-when-broken:
  t5310: fix "; do" style
  pack-objects: disable pack reuse for object-selection options

6 years agoMerge branch 'bc/object-id'
Junio C Hamano [Mon, 29 May 2017 03:34:43 +0000 (29 12:34 +0900)]
Merge branch 'bc/object-id'

Conversion from uchar[20] to struct object_id continues.

* bc/object-id: (53 commits)
  object: convert parse_object* to take struct object_id
  tree: convert parse_tree_indirect to struct object_id
  sequencer: convert do_recursive_merge to struct object_id
  diff-lib: convert do_diff_cache to struct object_id
  builtin/ls-tree: convert to struct object_id
  merge: convert checkout_fast_forward to struct object_id
  sequencer: convert fast_forward_to to struct object_id
  builtin/ls-files: convert overlay_tree_on_cache to object_id
  builtin/read-tree: convert to struct object_id
  sha1_name: convert internals of peel_onion to object_id
  upload-pack: convert remaining parse_object callers to object_id
  revision: convert remaining parse_object callers to object_id
  revision: rename add_pending_sha1 to add_pending_oid
  http-push: convert process_ls_object and descendants to object_id
  refs/files-backend: convert many internals to struct object_id
  refs: convert struct ref_update to use struct object_id
  ref-filter: convert some static functions to struct object_id
  Convert struct ref_array_item to struct object_id
  Convert the verify_pack callback to struct object_id
  Convert lookup_tag to struct object_id
  ...

6 years agoMerge branch 'nd/split-index-unshare'
Junio C Hamano [Mon, 29 May 2017 03:34:43 +0000 (29 12:34 +0900)]
Merge branch 'nd/split-index-unshare'

Plug some leaks and updates internal API used to implement the
split index feature to make it easier to avoid such a leak in the
future.

* nd/split-index-unshare:
  p3400: add perf tests for rebasing many changes
  split-index: add and use unshare_split_index()

6 years agoMerge branch 'jk/diff-submodule-diff-inline'
Junio C Hamano [Mon, 29 May 2017 03:34:42 +0000 (29 12:34 +0900)]
Merge branch 'jk/diff-submodule-diff-inline'

"git diff --submodule=diff" now recurses into nested submodules.

* jk/diff-submodule-diff-inline:
  diff: recurse into nested submodules for inline diff

6 years agoMerge branch 'bw/dir-c-stops-relying-on-the-index'
Junio C Hamano [Mon, 29 May 2017 03:34:41 +0000 (29 12:34 +0900)]
Merge branch 'bw/dir-c-stops-relying-on-the-index'

API update.

* bw/dir-c-stops-relying-on-the-index:
  dir: convert fill_directory to take an index
  dir: convert read_directory to take an index
  dir: convert read_directory_recursive to take an index
  dir: convert open_cached_dir to take an index
  dir: convert is_excluded to take an index
  dir: convert prep_exclude to take an index
  dir: convert add_excludes to take an index
  dir: convert is_excluded_from_list to take an index
  dir: convert last_exclude_matching_from_list to take an index
  dir: convert dir_add* to take an index
  dir: convert get_dtype to take index
  dir: convert directory_exists_in_index to take index
  dir: convert read_skip_worktree_file_from_index to take an index
  dir: stop using the index compatibility macros

6 years agoMerge branch 'sb/checkout-recurse-submodules'
Junio C Hamano [Mon, 29 May 2017 03:34:41 +0000 (29 12:34 +0900)]
Merge branch 'sb/checkout-recurse-submodules'

"git checkout --recurse-submodules" did not quite work with a
submodule that itself has submodules.

* sb/checkout-recurse-submodules:
  submodule: properly recurse for read-tree and checkout
  submodule: avoid auto-discovery in new working tree manipulator code
  submodule_move_head: reuse child_process structure for futher commands

6 years agoMerge branch 'jc/repack-threads'
Junio C Hamano [Mon, 29 May 2017 03:34:41 +0000 (29 12:34 +0900)]
Merge branch 'jc/repack-threads'

"git repack" learned to accept the --threads=<n> option and pass it
to pack-objects.

* jc/repack-threads:
  repack: accept --threads=<n> and pass it down to pack-objects

6 years agoMerge branch 'sb/reset-recurse-submodules'
Junio C Hamano [Mon, 29 May 2017 03:34:40 +0000 (29 12:34 +0900)]
Merge branch 'sb/reset-recurse-submodules'

"git reset" learned "--recurse-submodules" option.

* sb/reset-recurse-submodules:
  builtin/reset: add --recurse-submodules switch
  submodule.c: submodule_move_head works with broken submodules
  submodule.c: uninitialized submodules are ignored in recursive commands
  entry.c: submodule recursing: respect force flag correctly

6 years agowildmatch test: remove redundant duplicate test
Ævar Arnfjörð Bjarmason [Fri, 26 May 2017 20:56:57 +0000 (26 20:56 +0000)]
wildmatch test: remove redundant duplicate test

Remove a test line that's exactly the same as the preceding
line.

This was brought in in commit feabcc173b ("Integrate wildmatch to
git", 2012-10-15), these tests are originally copied from rsync.git,
but the duplicate line was never present there, so must have just
snuck in during integration with git by accident.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agodoc: filter-branch does not require re-export of vars
Andreas Heiduk [Fri, 26 May 2017 17:36:54 +0000 (26 19:36 +0200)]
doc: filter-branch does not require re-export of vars

The function `set_ident` in `filter-branch` exported the variables
GIT_(AUTHOR|COMMITTER)_(NAME|EMAIL|DATE) at least since 6f6826c52b in 2007.
Therefore the filter scripts don't need to re-eport them again.

Signed-off-by: Andreas Heiduk <asheiduk@gmail.com>
Reviewed-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agogrep: assert that threading is enabled when calling grep_{lock,unlock}
Ævar Arnfjörð Bjarmason [Thu, 25 May 2017 19:45:35 +0000 (25 19:45 +0000)]
grep: assert that threading is enabled when calling grep_{lock,unlock}

Change the grep_{lock,unlock} functions to assert that num_threads is
true, instead of only locking & unlocking the pthread mutex lock when
it is.

These functions are never called when num_threads isn't true, this
logic has gone through multiple iterations since the initial
introduction of grep threading in commit 5b594f457a ("Threaded grep",
2010-01-25), but ever since then they'd only be called if num_threads
was true, so this check made the code confusing to read.

Replace the check with an assertion, so that it's clear to the reader
that this code path is never taken unless we're spawning threads.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agogrep: given --threads with NO_PTHREADS=YesPlease, warn
Ævar Arnfjörð Bjarmason [Thu, 25 May 2017 19:45:34 +0000 (25 19:45 +0000)]
grep: given --threads with NO_PTHREADS=YesPlease, warn

Add a warning about missing thread support when grep.threads or
--threads is set to a non 0 (default) or 1 (no parallelism) value
under NO_PTHREADS=YesPlease.

This is for consistency with the index-pack & pack-objects commands,
which also take a --threads option & are configurable via
pack.threads, and have long warned about the same under
NO_PTHREADS=YesPlease.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agopack-objects: fix buggy warning about threads
Ævar Arnfjörð Bjarmason [Thu, 25 May 2017 19:45:33 +0000 (25 19:45 +0000)]
pack-objects: fix buggy warning about threads

Fix a buggy warning about threads under NO_PTHREADS=YesPlease. Due to
re-using the delta_search_threads variable for both the state of the
"pack.threads" config & the --threads option, setting "pack.threads"
but not supplying --threads would trigger the warning for both
"pack.threads" & --threads.

Solve this bug by resetting the delta_search_threads variable in
git_pack_config(), it might then be set by --threads again and be
subsequently warned about, as the test I'm changing here asserts.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agopack-objects & index-pack: add test for --threads warning
Ævar Arnfjörð Bjarmason [Thu, 25 May 2017 19:45:32 +0000 (25 19:45 +0000)]
pack-objects & index-pack: add test for --threads warning

Add a test for the warning that's emitted when --threads or
pack.threads is provided under NO_PTHREADS=YesPlease. This uses the
new PTHREADS prerequisite.

The assertion for C_LOCALE_OUTPUT in the latter test is currently
redundant, since unlike index-pack the pack-objects warnings aren't
i18n'd. However they might be changed to be i18n'd in the future, and
there's no harm in future-proofing the test.

There's an existing bug in the implementation of pack-objects which
this test currently tests for as-is. Details about the bug & the fix
are included in a follow-up change.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agotest-lib: add a PTHREADS prerequisite
Ævar Arnfjörð Bjarmason [Thu, 25 May 2017 19:45:31 +0000 (25 19:45 +0000)]
test-lib: add a PTHREADS prerequisite

Add a PTHREADS prerequisite which is false when git is compiled with
NO_PTHREADS=YesPlease.

There's lots of custom code that runs when threading isn't available,
but before this prerequisite there was no way to test it.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agogrep: move is_fixed() earlier to avoid forward declaration
Ævar Arnfjörð Bjarmason [Thu, 25 May 2017 19:45:30 +0000 (25 19:45 +0000)]
grep: move is_fixed() earlier to avoid forward declaration

Move the is_fixed() function which are currently only used in
compile_regexp() earlier so it can be used in the PCRE family of
functions in a later change.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agogrep: change internal *pcre* variable & function names to be *pcre1*
Ævar Arnfjörð Bjarmason [Thu, 25 May 2017 19:45:29 +0000 (25 19:45 +0000)]
grep: change internal *pcre* variable & function names to be *pcre1*

Change the internal PCRE variable & function names to have a "1"
suffix. This is for preparation for libpcre2 support, where having
non-versioned names would be confusing.

An earlier change in this series ("grep: change the internal PCRE
macro names to be PCRE1", 2017-04-07) elaborates on the motivations
behind this change.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agogrep: change the internal PCRE macro names to be PCRE1
Ævar Arnfjörð Bjarmason [Thu, 25 May 2017 19:45:28 +0000 (25 19:45 +0000)]
grep: change the internal PCRE macro names to be PCRE1

Change the internal USE_LIBPCRE define, & build options flag to use a
naming convention ending in PCRE1, without changing the long-standing
USE_LIBPCRE Makefile flag which enables this code.

This is for preparation for libpcre2 support where having things like
USE_LIBPCRE and USE_LIBPCRE2 in any more places than we absolutely
need to for backwards compatibility with old Makefile arguments would
be confusing.

In some ways it would be better to change everything that now uses
USE_LIBPCRE to use USE_LIBPCRE1, and to make specifying
USE_LIBPCRE (or --with-pcre) an error. This would impose a one-time
burden on packagers of git to s/USE_LIBPCRE/USE_LIBPCRE1/ in their
build scripts.

However I'd like to leave the door open to making
USE_LIBPCRE=YesPlease eventually mean USE_LIBPCRE2=YesPlease,
i.e. once PCRE v2 is ubiquitous enough that it makes sense to make it
the default.

This code and the USE_LIBPCRE Makefile argument was added in commit
63e7e9d8b6 ("git-grep: Learn PCRE", 2011-05-09). At the time there was
no indication that the PCRE project would release an entirely new &
incompatible API around 3 years later.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agogrep: factor test for \0 in grep patterns into a function
Ævar Arnfjörð Bjarmason [Thu, 25 May 2017 19:45:27 +0000 (25 19:45 +0000)]
grep: factor test for \0 in grep patterns into a function

Factor the test for \0 in grep patterns into a function. Since commit
9eceddeec6 ("Use kwset in grep", 2011-08-21) any pattern containing a
\0 is considered fixed as regcomp() can't handle it.

This change makes later changes that make use of either has_null() or
is_fixed() (but not both) smaller.

While I'm at it make the comment conform to the style guide, i.e. add
an opening "/*\n".

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agogrep: remove redundant regflags assignments
Ævar Arnfjörð Bjarmason [Thu, 25 May 2017 19:45:26 +0000 (25 19:45 +0000)]
grep: remove redundant regflags assignments

Remove redundant assignments to the "regflags" variable. This variable
is only used set under GREP_PATTERN_TYPE_ERE, so there's no need to
un-set it under GREP_PATTERN_TYPE_{FIXED,BRE,PCRE}.

Back in 5010cb5fcc[1], we did do "opt.regflags &= ~REG_EXTENDED" upon
seeing "-G" on the command line and flipped the bit on upon seeing
"-E", but I think that was perfectly sensible and it would have been a
bug if we didn't.  They were part of the command line parsing that
could have seen "-E" on the command line earlier.

When cca2c172 ("git-grep: do not die upon -F/-P when
grep.extendedRegexp is set.", 2011-05-09) switched the command line
parsing to "read into a 'tentatively this is what we saw the last'
variable and then finally commit just once", we didn't touch
opt.regflags for PCRE and FIXED, but we still had to flip regflags
between BRE and ERE, because parsing of grep.extendedregexp
configuration variable directly touched opt.regflags back then, which
was done by b22520a3 ("grep: allow -E and -n to be turned on by
default via configuration", 2011-03-30).

When 84befcd0 ("grep: add a grep.patternType configuration setting",
2012-08-03) introduced extended_regexp_option field, we stopped
flipping regflags while reading the configuration, and that was when
we should have noticed and stopped dropping REG_EXTENDED bit in the
"now we can commit what type to use" helper function.

There is no reason to do this anymore, so stop doing it, more to
reduce "wait this is used under fixed/BRE/PCRE how?" confusion when
reading the code, than to to save ourselves trivial CPU cycles by
removing one assignment.

1. "built-in "git grep"", 2006-04-30.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agogrep: catch a missing enum in switch statement
Ævar Arnfjörð Bjarmason [Thu, 25 May 2017 19:45:25 +0000 (25 19:45 +0000)]
grep: catch a missing enum in switch statement

Add a die(...) to a default case for the switch statement selecting
between grep pattern types under --recurse-submodules.

Normally this would be caught by -Wswitch, but the grep_pattern_type
type is converted to int by going through parse_options(). Changing
the argument type passed to compile_submodule_options() won't work,
the value will just get coerced. The -Wswitch-default warning will
warn about it, but that produces a lot of noise across the codebase,
this potential issue would be drowned in that noise.

Thus catching this at runtime is the least bad option. This won't ever
trigger in practice, but if a new pattern type were to be added this
catches an otherwise silent bug during development.

See commit 0281e487fd ("grep: optionally recurse into submodules",
2016-12-16) for the initial addition of this code.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoperf: add a comparison test of log --grep regex engines with -F
Ævar Arnfjörð Bjarmason [Thu, 25 May 2017 19:45:24 +0000 (25 19:45 +0000)]
perf: add a comparison test of log --grep regex engines with -F

Add a performance comparison test of log --grepgrep regex engines
given fixed strings.

See the preceding fixed-string t/perf change ("perf: add a comparison
test of grep regex engines with -F", 2017-04-21) for notes about this,
in particular this mostly tests exactly the same codepath now, but
might not in the future:

    $ GIT_PERF_REPEAT_COUNT=10 GIT_PERF_LARGE_REPO=~/g/linux ./run p4221-log-grep-engines-fixed.sh
    [...]
    Test                                     this tree
    --------------------------------------------------------
    4221.1: fixed log --grep='int'           5.99(5.55+0.40)
    4221.2: basic log --grep='int'           5.92(5.56+0.31)
    4221.3: extended log --grep='int'        6.01(5.51+0.45)
    4221.4: perl log --grep='int'            5.99(5.56+0.38)
    4221.6: fixed log --grep='uncommon'      5.06(4.76+0.27)
    4221.7: basic log --grep='uncommon'      5.02(4.78+0.21)
    4221.8: extended log --grep='uncommon'   4.99(4.78+0.20)
    4221.9: perl log --grep='uncommon'       5.00(4.72+0.26)
    4221.11: fixed log --grep='æ'            5.35(5.12+0.20)
    4221.12: basic log --grep='æ'            5.34(5.11+0.20)
    4221.13: extended log --grep='æ'         5.39(5.10+0.22)
    4221.14: perl log --grep='æ'             5.44(5.16+0.23)

Only the non-ASCII -i case is different:

    $ GIT_PERF_REPEAT_COUNT=10 GIT_PERF_LARGE_REPO=~/g/linux GIT_PERF_4221_LOG_OPTS=' -i' ./run p4221-log-grep-engines-fixed.sh
    [...]
    Test                                        this tree
    -----------------------------------------------------------
    4221.1: fixed log -i --grep='int'           6.17(5.77+0.35)
    4221.2: basic log -i --grep='int'           6.16(5.59+0.39)
    4221.3: extended log -i --grep='int'        6.15(5.70+0.39)
    4221.4: perl log -i --grep='int'            6.15(5.69+0.38)
    4221.6: fixed log -i --grep='uncommon'      5.10(4.88+0.21)
    4221.7: basic log -i --grep='uncommon'      5.04(4.76+0.25)
    4221.8: extended log -i --grep='uncommon'   5.07(4.82+0.23)
    4221.9: perl log -i --grep='uncommon'       5.03(4.78+0.22)
    4221.11: fixed log -i --grep='æ'            5.93(5.65+0.25)
    4221.12: basic log -i --grep='æ'            5.88(5.62+0.25)
    4221.13: extended log -i --grep='æ'         6.02(5.69+0.29)
    4221.14: perl log -i --grep='æ'             5.36(5.06+0.29)

See commit ("perf: add a comparison test of grep regex engines",
2017-04-19) for details on the machine the above test run was executed
on.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoperf: add a comparison test of log --grep regex engines
Ævar Arnfjörð Bjarmason [Thu, 25 May 2017 19:45:23 +0000 (25 19:45 +0000)]
perf: add a comparison test of log --grep regex engines

Add a very basic performance comparison test comparing the POSIX
basic, extended and perl engines with patterns matching log messages
via --grep=<pattern>.

    $ GIT_PERF_REPEAT_COUNT=10 GIT_PERF_LARGE_REPO=~/g/linux ./run p4220-log-grep-engines.sh
    [...]
    Test                                                  this tree
    ---------------------------------------------------------------------
    4220.1: basic log --grep='how.to'                     6.22(6.00+0.21)
    4220.2: extended log --grep='how.to'                  6.23(5.98+0.23)
    4220.3: perl log --grep='how.to'                      6.07(5.79+0.25)
    4220.5: basic log --grep='^how to'                    6.19(5.93+0.22)
    4220.6: extended log --grep='^how to'                 6.19(5.93+0.23)
    4220.7: perl log --grep='^how to'                     6.14(5.88+0.24)
    4220.9: basic log --grep='[how] to'                   6.96(6.65+0.28)
    4220.10: extended log --grep='[how] to'               6.96(6.69+0.24)
    4220.11: perl log --grep='[how] to'                   6.95(6.58+0.33)
    4220.13: basic log --grep='\(e.t[^ ]*\|v.ry\) rare'   7.10(6.80+0.27)
    4220.14: extended log --grep='(e.t[^ ]*|v.ry) rare'   7.07(6.80+0.26)
    4220.15: perl log --grep='(e.t[^ ]*|v.ry) rare'       7.70(7.46+0.22)
    4220.17: basic log --grep='m\(ú\|u\)lt.b\(æ\|y\)te'   6.12(5.87+0.24)
    4220.18: extended log --grep='m(ú|u)lt.b(æ|y)te'      6.14(5.84+0.26)
    4220.19: perl log --grep='m(ú|u)lt.b(æ|y)te'          6.16(5.93+0.20)

With -i:

    $ GIT_PERF_REPEAT_COUNT=10 GIT_PERF_LARGE_REPO=~/g/linux GIT_PERF_4220_LOG_OPTS=' -i' ./run p4220-log-grep-engines.sh
    [...]
    Test                                                     this tree
    ------------------------------------------------------------------------
    4220.1: basic log -i --grep='how.to'                     6.74(6.41+0.32)
    4220.2: extended log -i --grep='how.to'                  6.78(6.55+0.22)
    4220.3: perl log -i --grep='how.to'                      6.06(5.77+0.28)
    4220.5: basic log -i --grep='^how to'                    6.80(6.57+0.22)
    4220.6: extended log -i --grep='^how to'                 6.83(6.52+0.29)
    4220.7: perl log -i --grep='^how to'                     6.16(5.94+0.20)
    4220.9: basic log -i --grep='[how] to'                   7.87(7.61+0.24)
    4220.10: extended log -i --grep='[how] to'               7.85(7.57+0.27)
    4220.11: perl log -i --grep='[how] to'                   7.03(6.75+0.25)
    4220.13: basic log -i --grep='\(e.t[^ ]*\|v.ry\) rare'   8.68(8.41+0.25)
    4220.14: extended log -i --grep='(e.t[^ ]*|v.ry) rare'   8.80(8.44+0.28)
    4220.15: perl log -i --grep='(e.t[^ ]*|v.ry) rare'       7.85(7.56+0.26)
    4220.17: basic log -i --grep='m\(ú\|u\)lt.b\(æ\|y\)te'   6.94(6.68+0.24)
    4220.18: extended log -i --grep='m(ú|u)lt.b(æ|y)te'      7.04(6.76+0.24)
    4220.19: perl log -i --grep='m(ú|u)lt.b(æ|y)te'          6.26(5.92+0.29)

See commit ("perf: add a comparison test of grep regex engines",
2017-04-19) for details on the machine the above test run was executed
on.

Before commit ("log: make --regexp-ignore-case work with
--perl-regexp", 2017-05-20) this test will almost definitely
fail (depending on the repo) if passed the -i option, since it wasn't
properly supported under PCRE.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoperf: add a comparison test of grep regex engines with -F
Ævar Arnfjörð Bjarmason [Thu, 25 May 2017 19:45:22 +0000 (25 19:45 +0000)]
perf: add a comparison test of grep regex engines with -F

Add a performance comparison test of grep regex engines given fixed
strings.

The current logic in compile_regexp() ignores the engine parameter and
uses kwset() to search for these, so this test shows no difference
between engines right now:

    $ GIT_PERF_REPEAT_COUNT=10 GIT_PERF_LARGE_REPO=~/g/linux ./run p7821-grep-engines-fixed.sh
    [...]
    Test                             this tree
    ------------------------------------------------
    7821.1: fixed grep int           0.56(1.67+0.68)
    7821.2: basic grep int           0.57(1.70+0.57)
    7821.3: extended grep int        0.59(1.76+0.51)
    7821.4: perl grep int            1.08(1.71+0.55)
    7821.6: fixed grep uncommon      0.23(0.55+0.50)
    7821.7: basic grep uncommon      0.24(0.55+0.50)
    7821.8: extended grep uncommon   0.26(0.55+0.52)
    7821.9: perl grep uncommon       0.24(0.58+0.47)
    7821.11: fixed grep æ            0.36(1.30+0.42)
    7821.12: basic grep æ            0.36(1.32+0.40)
    7821.13: extended grep æ         0.38(1.30+0.42)
    7821.14: perl grep æ             0.35(1.24+0.48)

Only when run with -i via GIT_PERF_7821_GREP_OPTS=' -i' do we avoid
avoid going through the same kwset.[ch] codepath, see the "Even when
-F..."  comment in grep.c. This only kicks for the non-ASCII case:

    $ GIT_PERF_REPEAT_COUNT=10 GIT_PERF_LARGE_REPO=~/g/linux GIT_PERF_7821_GREP_OPTS=' -i' ./run p7821-grep-engines-fixed.sh
    [...]
    Test                                this tree
    ---------------------------------------------------
    7821.1: fixed grep -i int           0.62(2.10+0.57)
    7821.2: basic grep -i int           0.68(1.90+0.61)
    7821.3: extended grep -i int        0.78(1.94+0.57)
    7821.4: perl grep -i int            0.98(1.78+0.74)
    7821.6: fixed grep -i uncommon      0.24(0.44+0.64)
    7821.7: basic grep -i uncommon      0.25(0.56+0.54)
    7821.8: extended grep -i uncommon   0.27(0.62+0.45)
    7821.9: perl grep -i uncommon       0.24(0.59+0.49)
    7821.11: fixed grep -i æ            0.30(0.96+0.39)
    7821.12: basic grep -i æ            0.27(0.92+0.44)
    7821.13: extended grep -i æ         0.28(0.90+0.46)
    7821.14: perl grep -i æ             0.28(0.74+0.49)

I'm planning to change how fixed-string searching happens. This test
gives a baseline for comparing performance before & after any such
change.

See commit ("perf: add a comparison test of grep regex engines",
2017-04-19) for details on the machine the above test run was executed
on.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoperf: add a comparison test of grep regex engines
Ævar Arnfjörð Bjarmason [Thu, 25 May 2017 19:45:21 +0000 (25 19:45 +0000)]
perf: add a comparison test of grep regex engines

Add a very basic performance comparison test comparing the POSIX
basic, extended and perl engines.

In theory the "basic" and "extended" engines should be implemented
using the same underlying code with a slightly different pattern
parser, but some implementations may not do this. Jump through some
slight hoops to test both, which is worthwhile since "basic" is the
default.

Running this on an i7 3.4GHz Linux 4.9.0-2 Debian testing against a
checkout of linux.git & latest upstream PCRE, both PCRE and git
compiled with -O3 using gcc 7.1.1:

    $ GIT_PERF_REPEAT_COUNT=10 GIT_PERF_LARGE_REPO=~/g/linux ./run p7820-grep-engines.sh
    [...]
    Test                                            this tree
    ---------------------------------------------------------------
    7820.1: basic grep 'how.to'                     0.34(1.24+0.53)
    7820.2: extended grep 'how.to'                  0.33(1.23+0.45)
    7820.3: perl grep 'how.to'                      0.31(1.05+0.56)
    7820.5: basic grep '^how to'                    0.32(1.24+0.42)
    7820.6: extended grep '^how to'                 0.33(1.20+0.44)
    7820.7: perl grep '^how to'                     0.57(2.67+0.42)
    7820.9: basic grep '[how] to'                   0.51(2.16+0.45)
    7820.10: extended grep '[how] to'               0.49(2.20+0.43)
    7820.11: perl grep '[how] to'                   0.56(2.60+0.43)
    7820.13: basic grep '\(e.t[^ ]*\|v.ry\) rare'   0.66(3.25+0.40)
    7820.14: extended grep '(e.t[^ ]*|v.ry) rare'   0.65(3.19+0.46)
    7820.15: perl grep '(e.t[^ ]*|v.ry) rare'       1.05(5.74+0.34)
    7820.17: basic grep 'm\(ú\|u\)lt.b\(æ\|y\)te'   0.34(1.28+0.47)
    7820.18: extended grep 'm(ú|u)lt.b(æ|y)te'      0.34(1.38+0.38)
    7820.19: perl grep 'm(ú|u)lt.b(æ|y)te'          0.39(1.56+0.44)

Options can also be passed to git-grep via the GIT_PERF_7820_GREP_OPTS
environment variable. There are various modes such as "-v" that have
very different performance profiles, but handling the combinatorial
explosion of testing all those options would make this script much
more complex and harder to maintain. Instead just add the ability to
do one-shot runs with arbitrary options, e.g.:

    $ GIT_PERF_REPEAT_COUNT=10 GIT_PERF_LARGE_REPO=~/g/linux GIT_PERF_7820_GREP_OPTS=" -i" ./run p7820-grep-engines.sh
    [...]
    Test                                               this tree
    ------------------------------------------------------------------
    7820.1: basic grep -i 'how.to'                     0.49(1.72+0.38)
    7820.2: extended grep -i 'how.to'                  0.46(1.64+0.42)
    7820.3: perl grep -i 'how.to'                      0.44(1.45+0.45)
    7820.5: basic grep -i '^how to'                    0.47(1.76+0.38)
    7820.6: extended grep -i '^how to'                 0.47(1.70+0.42)
    7820.7: perl grep -i '^how to'                     0.65(2.72+0.37)
    7820.9: basic grep -i '[how] to'                   0.86(3.64+0.42)
    7820.10: extended grep -i '[how] to'               0.84(3.62+0.46)
    7820.11: perl grep -i '[how] to'                   0.73(3.06+0.39)
    7820.13: basic grep -i '\(e.t[^ ]*\|v.ry\) rare'   1.63(8.13+0.36)
    7820.14: extended grep -i '(e.t[^ ]*|v.ry) rare'   1.64(8.01+0.44)
    7820.15: perl grep -i '(e.t[^ ]*|v.ry) rare'       1.44(6.88+0.44)
    7820.17: basic grep -i 'm\(ú\|u\)lt.b\(æ\|y\)te'   0.66(2.67+0.44)
    7820.18: extended grep -i 'm(ú|u)lt.b(æ|y)te'      0.66(2.67+0.43)
    7820.19: perl grep -i 'm(ú|u)lt.b(æ|y)te'          0.59(2.31+0.37)

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoconnect.c: fix leak in parse_one_symref_info()
Jeff King [Thu, 25 May 2017 19:33:05 +0000 (25 15:33 -0400)]
connect.c: fix leak in parse_one_symref_info()

If we successfully parse a symref value like
"HEAD:refs/heads/master", we add the result to a string
list. But because the string list is marked
STRING_LIST_INIT_DUP, the string list code will make a copy
of the string and add the copy.

This patch fixes it by adding the entry with
string_list_append_nodup(), which lets the string list take
ownership of our newly allocated string. There are two
alternatives that seem like they would work, but aren't the
right solution.

The first is to initialize the list with the "NODUP"
initializer. That would avoid the copy, but then the string
list would not realize that it owns the strings. When we
eventually call string_list_clear(), it would not free the
strings, causing a leak.

The second option would be to use the normal
string_list_append(), but free the local copy in our
function. We can't do this because the local copy actually
contains _two_ strings; the symref name and its target. We
point to the target pointer via the "util" field, and its
memory must last as long as the string list does.

You may also wonder whether it's safe to ever free the local
copy, since the target points into it. The answer is yes,
because we duplicate it in annotaate_refs_with_symref_info
before clearing the string list.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agodocs/config.txt: fix indefinite article in core.fileMode description
SZEDER Gábor [Thu, 25 May 2017 23:20:46 +0000 (26 01:20 +0200)]
docs/config.txt: fix indefinite article in core.fileMode description

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoWindows: do not treat a path with backslashes as a remote's nick name
Johannes Sixt [Thu, 25 May 2017 12:00:13 +0000 (25 14:00 +0200)]
Windows: do not treat a path with backslashes as a remote's nick name

On Windows, the remote repository name in, e.g., `git fetch foo\bar`
is clearly not a nickname for a configured remote repository. However,
the function valid_remote_nick() does not account for backslashes.
Use is_dir_sep() to check for both slashes and backslashes on Windows.

This was discovered while playing with Duy's patches that warn after
fopen() failures. The functions that read the branches and remotes
files are protected by a valid_remote_nick() check. Without this
change, a Windows style absolute path is incorrectly regarded as
nickname and is concatenated to a prefix and used with fopen(). This
triggers warnings because a colon in a path name is not allowed:

C:\Temp\gittest>git fetch C:\Temp\gittest
warning: unable to access '.git/remotes/C:\Temp\gittest': Invalid argument
warning: unable to access '.git/branches/C:\Temp\gittest': Invalid argument
From C:\Temp\gittest
 * branch            HEAD       -> FETCH_HEAD

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoblame: move entry prepend to libgit
Jeff Smith [Wed, 24 May 2017 05:15:37 +0000 (24 00:15 -0500)]
blame: move entry prepend to libgit

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoblame: move scoreboard setup to libgit
Jeff Smith [Wed, 24 May 2017 05:15:36 +0000 (24 00:15 -0500)]
blame: move scoreboard setup to libgit

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoblame: move scoreboard-related methods to libgit
Jeff Smith [Wed, 24 May 2017 05:15:35 +0000 (24 00:15 -0500)]
blame: move scoreboard-related methods to libgit

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoblame: move fake-commit-related methods to libgit
Jeff Smith [Wed, 24 May 2017 05:15:34 +0000 (24 00:15 -0500)]
blame: move fake-commit-related methods to libgit

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoblame: move origin-related methods to libgit
Jeff Smith [Wed, 24 May 2017 05:15:33 +0000 (24 00:15 -0500)]
blame: move origin-related methods to libgit

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoblame: move core structures to header
Jeff Smith [Wed, 24 May 2017 05:15:32 +0000 (24 00:15 -0500)]
blame: move core structures to header

The origin, entry, and scoreboard structures are core to the blame
interface and need to be exposed for blame functionality.

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoblame: create entry prepend function
Jeff Smith [Wed, 24 May 2017 05:15:31 +0000 (24 00:15 -0500)]
blame: create entry prepend function

Create function that populates a blame_entry and prepends it to a list.

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoblame: create scoreboard setup function
Jeff Smith [Wed, 24 May 2017 05:15:30 +0000 (24 00:15 -0500)]
blame: create scoreboard setup function

Create function that completes setting up blame_scoreboard structure.

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoblame: create scoreboard init function
Jeff Smith [Wed, 24 May 2017 05:15:29 +0000 (24 00:15 -0500)]
blame: create scoreboard init function

Create function that initializes blame_scoreboard to default values.

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoblame: rework methods that determine 'final' commit
Jeff Smith [Wed, 24 May 2017 05:15:28 +0000 (24 00:15 -0500)]
blame: rework methods that determine 'final' commit

Either prepare_initial or prepare_final is used to determine which
commit is marked as 'final'. Call the underlying methods directly to
make this more clear.

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoblame: wrap blame_sort and compare_blame_final
Jeff Smith [Wed, 24 May 2017 05:15:27 +0000 (24 00:15 -0500)]
blame: wrap blame_sort and compare_blame_final

The new method's interface is marginally cleaner than blame_sort, and
will avoid the need to expose the compare_blame_final method.

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoblame: move progress updates to a scoreboard callback
Jeff Smith [Wed, 24 May 2017 05:15:26 +0000 (24 00:15 -0500)]
blame: move progress updates to a scoreboard callback

Allow the interface user to decide how to handle a progress update.

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agocache_ref_iterator_begin(): avoid priming unneeded directories
Michael Haggerty [Mon, 22 May 2017 14:17:55 +0000 (22 16:17 +0200)]
cache_ref_iterator_begin(): avoid priming unneeded directories

When iterating over references, reference priming is used to make sure
that loose references are read into the ref-cache before packed
references, to avoid races. It used to be that the prefix passed to
reference iterators almost always ended in `/`, for example
`refs/heads/`. In that case, the priming code would read all loose
references under `find_containing_dir("refs/heads/")`, which is
"refs/heads/". That's just what we want.

But now that `ref-filter` knows how to pass refname prefixes to
`for_each_fullref_in()`, the prefix might come from user input; for
example,

    git for-each-ref refs/heads

Since the argument doesn't include a trailing slash, the reference
iteration code would prime all of the loose references under
`find_containing_dir("refs/heads")`, which is "refs/". Thus we would
unnecessarily read tags, remote-tracking references, etc., when the
user is only interested in branches.

It is a bit awkward to get around this problem. We can't just append a
slash to the argument, because we don't know ab initio whether an
argument like `refs/tags/release` corresponds to a single tag or to a
directory containing tags.

Moreover, until now a `prefix_ref_iterator` was used to make the final
decision about which references fall within the prefix (the
`cache_ref_iterator` only did a rough cut). This is also inefficient,
because the `prefix_ref_iterator` can't know, for example, that while
you are in a subdirectory that is completely within the prefix, you
don't have to do the prefix check.

So:

* Move the responsibility for doing the prefix check directly to
  `cache_ref_iterator`. This means that `cache_ref_iterator_begin()`
  never has to wrap its return value in a `prefix_ref_iterator`.

* Teach `cache_ref_iterator_begin()` (and `prime_ref_dir()`) to be
  stricter about what they iterate over and what directories they
  prime.

* Teach `cache_ref_iterator` to keep track of whether the current
  `cache_ref_iterator_level` is fully within the prefix. If so, skip
  the prefix checks entirely.

The main benefit of these optimizations is for loose references, since
packed references are always read all at once.

Note that after this change, `prefix_ref_iterator` is only ever used
for its trimming feature and not for its "prefix" feature. But I'm not
ripping out the latter yet, because it might be useful for another
patch series that I'm working on.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoblame: make sanity_check use a callback in scoreboard
Jeff Smith [Wed, 24 May 2017 05:15:25 +0000 (24 00:15 -0500)]
blame: make sanity_check use a callback in scoreboard

Allow the interface user to decide how to handle a failed sanity check,
whether that be to output with the current state or to do nothing.

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoblame: move no_whole_file_rename flag to scoreboard
Jeff Smith [Wed, 24 May 2017 05:15:24 +0000 (24 00:15 -0500)]
blame: move no_whole_file_rename flag to scoreboard

The no_whole_file_rename flag is used in parts of blame that are being
moved to libgit, and should be accessible via the scoreboard structure.

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoblame: move xdl_opts flags to scoreboard
Jeff Smith [Wed, 24 May 2017 05:15:23 +0000 (24 00:15 -0500)]
blame: move xdl_opts flags to scoreboard

The xdl_opts flags are used in parts of blame that are being moved to
libgit, and should be accessible via the scoreboard structure.

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoblame: move show_root flag to scoreboard
Jeff Smith [Wed, 24 May 2017 05:15:22 +0000 (24 00:15 -0500)]
blame: move show_root flag to scoreboard

The show_root flag is used in parts of blame that are being moved to
libgit, and should be accessible via the scoreboard structure.

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoblame: move reverse flag to scoreboard
Jeff Smith [Wed, 24 May 2017 05:15:21 +0000 (24 00:15 -0500)]
blame: move reverse flag to scoreboard

The reverse flag is used in parts of blame that are being moved to
libgit, and should be accessible via the scoreboard structure.

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoblame: move contents_from to scoreboard
Jeff Smith [Wed, 24 May 2017 05:15:20 +0000 (24 00:15 -0500)]
blame: move contents_from to scoreboard

The argument from --contents is used in parts of blame that are being
moved to libgit, and should be accessible via the scoreboard structure.

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoblame: move copy/move thresholds to scoreboard
Jeff Smith [Wed, 24 May 2017 05:15:19 +0000 (24 00:15 -0500)]
blame: move copy/move thresholds to scoreboard

Copy and move score thresholds are used in parts of blame that are being
moved to libgit, and should be accessible via the scoreboard structure.

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoblame: move stat counters to scoreboard
Jeff Smith [Wed, 24 May 2017 05:15:18 +0000 (24 00:15 -0500)]
blame: move stat counters to scoreboard

Statistic counters are used in parts of blame that are being moved to
libgit, and should be accessible via the scoreboard structure.

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoblame: rename nth_line function
Jeff Smith [Wed, 24 May 2017 05:15:17 +0000 (24 00:15 -0500)]
blame: rename nth_line function

Functions that will be publicly exposed should have names that better
reflect what they are a part of.

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoblame: rename ent_score function
Jeff Smith [Wed, 24 May 2017 05:15:16 +0000 (24 00:15 -0500)]
blame: rename ent_score function

Functions that will be publicly exposed should have names that better
reflect what they are a part of.

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoblame: rename coalesce function
Jeff Smith [Wed, 24 May 2017 05:15:15 +0000 (24 00:15 -0500)]
blame: rename coalesce function

Functions that will be publicly exposed should have names that better
reflect what they are a part of.

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoblame: rename origin-related functions
Jeff Smith [Wed, 24 May 2017 05:15:14 +0000 (24 00:15 -0500)]
blame: rename origin-related functions

Functions related to blame_origin that will be publicly exposed should
have names that better reflect what they are a part of.

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoblame: rename scoreboard structure to blame_scoreboard
Jeff Smith [Wed, 24 May 2017 05:15:13 +0000 (24 00:15 -0500)]
blame: rename scoreboard structure to blame_scoreboard

The scoreboard structure is core to the blame interface. Since
scoreboard will become more exposed, rename it to blame_scoreboard to
clarify what it is a part of.

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoblame: rename origin structure to blame_origin
Jeff Smith [Wed, 24 May 2017 05:15:12 +0000 (24 00:15 -0500)]
blame: rename origin structure to blame_origin

The origin structure is core to the blame interface.  Since origin will
become more exposed, rename it to blame_origin to clarify what it is a
part of.

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoblame: remove unused parameters
Jeff Smith [Wed, 24 May 2017 05:15:11 +0000 (24 00:15 -0500)]
blame: remove unused parameters

Clean up blame code before moving it into libgit

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoblame: move textconv_object with related functions
Jeff Smith [Wed, 24 May 2017 05:15:10 +0000 (24 00:15 -0500)]
blame: move textconv_object with related functions

textconv_object is used in places other than blame.c and should be moved
to a more appropriate location.  Other textconv related functions are
located in diff.c so that seems as good a place as any.

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoblame: remove unneeded dependency on blob.h
Jeff Smith [Wed, 24 May 2017 05:15:09 +0000 (24 00:15 -0500)]
blame: remove unneeded dependency on blob.h

With commit 21666f1 ("convert object type handling from a string to a
number", 2007-02-26), there was no longer a need for blame.c to include
blob.h but it was not removed.

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agodiff: use blob path for blob/file diffs
Jeff King [Fri, 19 May 2017 12:59:34 +0000 (19 08:59 -0400)]
diff: use blob path for blob/file diffs

When we diff a blob against a working tree file like:

  git diff HEAD:Makefile Makefile

we always use the working tree filename for both sides of
the diff. In most cases that's fine, as the two would be the
same anyway, as above. And until recently, we used the
"name" for the blob, not the path, which would have the
messy "HEAD:" on the beginning.

But when they don't match, like:

  git diff HEAD:old_path new_path

it makes sense to show both names.

This patch uses the blob's path field if it's available, and
otherwise falls back to using the filename (in preference to
the blob's name, which is likely to be garbage like a raw
sha1).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agodiff: use pending "path" if it is available
Jeff King [Fri, 19 May 2017 12:59:15 +0000 (19 08:59 -0400)]
diff: use pending "path" if it is available

There's a subtle distinction between "name" and "path" for a
blob that we resolve: the name is what the user told us on
the command line, and the path is what we traversed when
finding the blob within a tree (if we did so).

When we diff blobs directly, we use "name", but "path" is
more likely to be useful to the user (it will find the
correct .gitattributes, and give them a saner diff header).

We still have to fall back to using the name for some cases
(i.e., any blob reference that isn't of the form tree:path).
That's the best we can do in such a case.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agodiff: use the word "path" instead of "name" for blobs
Jeff King [Fri, 19 May 2017 12:58:05 +0000 (19 08:58 -0400)]
diff: use the word "path" instead of "name" for blobs

The stuff_change() function makes diff_filespecs out of
blobs. The term we generally use for filespecs is "path",
not "name", so let's be consistent here.  That will make
things less confusing when the next patch starts caring
about the path/name distinction inside the pending object
array.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agodiff: pass whole pending entry in blobinfo
Jeff King [Fri, 19 May 2017 12:57:30 +0000 (19 08:57 -0400)]
diff: pass whole pending entry in blobinfo

When diffing blobs directly, git-diff picks the blobs out of
the rev_info's pending array and copies the relevant bits to
a custom "struct blobinfo". But the pending array entry
already has all of this information (and more, which we'll
use in future patches). Let's just pass the original entry
instead.

In practice, these two blobs are probably adjacent in the
revs->pending array, and we could just pass the whole array.
But the current code is careful to pick each blob out
separately and put it into another array, so we'll continue
to do so and make our own array-of-pointers.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agohandle_revision_arg: record paths for pending objects
Jeff King [Fri, 19 May 2017 12:55:26 +0000 (19 08:55 -0400)]
handle_revision_arg: record paths for pending objects

If the revision parser sees an argument like tree:path, we
parse it down to the correct blob (or tree), but throw away
the "path" portion. Let's ask get_sha1_with_context() to
record it, and pass it along in the pending array.

This will let programs like git-diff which rely on the
revision-parser show more accurate paths.

Note that the implementation is a little tricky; we have to
make sure we free oc.path in all code paths. For handle_dotdot(),
we can piggy-back on the existing cleanup-wrapper pattern.
The real work happens in handle_dotdot_1(), but the
handle_dotdot() wrapper makes sure that the path is freed no
matter how we exit the function (and for that reason we make
sure that the object_context struct is zero'd, so if we fail
to even get to the get_sha1_with_context() call, we just end
up calling free(NULL)).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agohandle_revision_arg: record modes for "a..b" endpoints
Jeff King [Fri, 19 May 2017 12:55:11 +0000 (19 08:55 -0400)]
handle_revision_arg: record modes for "a..b" endpoints

The "a..b" revision syntax was designed to handle commits,
so it doesn't bother to record any mode we find while
traversing a "tree:path" endpoint. These days "git diff" can
diff blobs using either "a:path..b:path" (with dots) or
"a:path b:path" (without), but the two behave
inconsistently, as the with-dots version fails to notice the
mode.

Let's teach the dot-dot range parser to record modes; it
doesn't cost us anything, and it makes this case work.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agot4063: add tests of direct blob diffs
Jeff King [Fri, 19 May 2017 12:54:56 +0000 (19 08:54 -0400)]
t4063: add tests of direct blob diffs

The git-diff command can directly compare two blobs (or a
blob and a file), but we don't test this at all. Let's add
some basic tests that reveal a few problems.

There are basically four interesting inputs:

  1. sha1 against sha1 (where diff has no information beyond
     the contents)

  2. tree:path against tree:path (where it can get
     information via get_sha1_with_context)

  3. Same as (2), but using the ".." range syntax

  4. tree:path against a filename

And beyond generating a sane diff, we care about a few
little bits: which paths they show in the diff header, and
whether they correctly pick up a mode change.

They should all be able to show a mode except for (1),
though note that case (3) is currently broken.

For the headers, we would ideally show the path within the
tree if we have it, making:

  git diff a:path b:path

look the same as:

  git diff a b -- path

We can't always do that (e.g., in the direct sha1/sha1 diff,
we have no path to show), in which case we should fall back
to the name that resolved to the blob (which is nonsense
from the repository's perspective, but is the best we can
do).

Aside from the fallback case in (1), none of the cases get
this right. Cases (2) and (3) always show the full
tree:path, even though we should be able to know just the
"path" portion.

Case (4) picks up the filename path, but assigns it to
_both_ sides of the diff. So this works for:

  git diff tree:path path

but not for:

  git diff tree:other_path path

The appropriate tests are marked to expect failure.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoget_sha1_with_context: dynamically allocate oc->path
Jeff King [Fri, 19 May 2017 12:54:43 +0000 (19 08:54 -0400)]
get_sha1_with_context: dynamically allocate oc->path

When a sha1 lookup returns the tree path via "struct
object_context", it just copies it into a fixed-size buffer.
This means the result can be truncated, and it means our
"struct object_context" consumes a lot of stack space.

Instead, let's allocate a string on the heap. Because most
callers don't care about this information, we'll avoid doing
it by default (so they don't all have to start calling
free() on the result). There are basically two options for
the caller to signal to us that it's interested:

  1. By setting a pointer to storage in the object_context.

  2. By passing a flag in another parameter.

Doing (1) would match the way that sha1_object_info_extended()
works. But it would mean that every caller would have to
initialize the object_context, which they don't currently
have to do.

This patch does (2), and adds a new bit to the function's
flags field. All of the callers that look at the "path"
field are updated to pass the new flag.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoget_sha1_with_context: always initialize oc->symlink_path
Jeff King [Fri, 19 May 2017 12:52:25 +0000 (19 08:52 -0400)]
get_sha1_with_context: always initialize oc->symlink_path

The get_sha1_with_context() function zeroes out the
oc->symlink_path strbuf, but doesn't use strbuf_init() to
set up the usual invariants (like pointing to the slopbuf).
We don't actually write to the oc->symlink_path strbuf
unless we call get_tree_entry_follow_symlinks(), and that
function does initialize it. However, readers may still look
at the zero'd strbuf.

In practice this isn't a triggerable bug. The only caller
that looks at it only does so when the mode we found is 0.
This doesn't happen for non-tree-entries (where we return
S_IFINVALID). A broken tree entry could have a mode of 0,
but canon_mode() quietly rewrites that into S_IFGITLINK.
So the "0" mode should only come up when we did indeed find
a symlink.

This is mostly just an accident of how the code happens to
work, though. Let's future-proof ourselves to make sure the
strbuf is properly initialized for all calls (it's only a
few struct member assignments, not a heap allocation).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agosha1_name: consistently refer to object_context as "oc"
Jeff King [Fri, 19 May 2017 12:52:06 +0000 (19 08:52 -0400)]
sha1_name: consistently refer to object_context as "oc"

An early version of the patch to add object_context used the
name object_resolve_context. This was later shortened to
just object_context, but the "orc" variable name stuck in a
few places.  Let's use "oc", which is used elsewhere in the
code.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agohandle_revision_arg: add handle_dotdot() helper
Jeff King [Fri, 19 May 2017 12:52:00 +0000 (19 08:52 -0400)]
handle_revision_arg: add handle_dotdot() helper

The handle_revision_arg function is rather long, and a big
chunk of it is handling the range operators. Let's pull that
out to a separate helper. While we're doing so, we can clean
up a few of the rough edges that made the flow hard to
follow:

  - instead of manually restoring *dotdot (that we overwrote
    with a NUL), do the real work in a sub-helper, which
    makes it clear that the munge/restore lines are a
    matched pair

  - eliminate a goto which wasn't actually used for control
    flow, but only to avoid duplicating a few lines
    (instead, those lines are pushed into another helper
    function)

  - use early returns instead of deep nesting

  - consistently name all variables for the left-hand side
    of the range as "a" (rather than "this" or "from") and
    the right-hand side as "b" (rather than "next", or using
    the unadorned "sha1" or "flags" from the main function).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agohandle_revision_arg: hoist ".." check out of range parsing
Jeff King [Fri, 19 May 2017 12:51:40 +0000 (19 08:51 -0400)]
handle_revision_arg: hoist ".." check out of range parsing

Since 003c84f6d (specifying ranges: we did not mean to make
".." an empty set, 2011-05-02), we treat the argument ".."
specially. We detect it by noticing that both sides of the
range are empty, and that this is a non-symmetric two-dot
range.

While correct, this makes the code overly complicated. We
can just detect ".." up front before we try to do further
parsing. This avoids having to de-munge the NUL from dotdot,
and lets us eliminate an extra const array (which we needed
only to do direct pointer comparisons).

It also removes the one code path from the range-parsing
conditional that requires us to return -1. That will make it
simpler to pull the dotdot parsing out into its own
function.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agohandle_revision_arg: stop using "dotdot" as a generic pointer
Jeff King [Fri, 19 May 2017 12:50:07 +0000 (19 08:50 -0400)]
handle_revision_arg: stop using "dotdot" as a generic pointer

The handle_revision_arg() function has a "dotdot" variable
that it uses to find a ".." or "..." in the argument. If we
don't find one, we look for other marks, like "^!". But we
just keep re-using the "dotdot" variable, which is
confusing.

Let's introduce a separate "mark" variable that can be used
for these other marks. They still reuse the same variable,
but at least the name is no longer actively misleading.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agohandle_revision_arg: simplify commit reference lookups
Jeff King [Fri, 19 May 2017 12:48:46 +0000 (19 08:48 -0400)]
handle_revision_arg: simplify commit reference lookups

The "dotdot" range parser avoids calling
lookup_commit_reference() if we are directly fed two
commits. But its casts are unnecessarily complex; that
function will just return a commit we pass into it.

Just calling the function all the time is much simpler, and
doesn't do any significant extra work (the object is already
parsed, and deref_tag() on a non-tag is a noop; we do incur
one extra lookup_object() call, but that's fairly trivial).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agohandle_revision_arg: reset "dotdot" consistently
Jeff King [Tue, 23 May 2017 19:51:32 +0000 (23 15:51 -0400)]
handle_revision_arg: reset "dotdot" consistently

When we are parsing a range like "a..b", we write a
temporary NUL over the first ".", so that we can access the
names "a" and "b" as C strings. But our restoration of the
original "." is done at inconsistent times, which can lead
to confusing results.

For most calls, we restore the "." after we resolve the
names, but before we call verify_non_filename().  This means
that when we later call add_pending_object(), the name for
the left-hand "a" has been re-expanded to "a..b". You can
see this with:

  git log --source a...b

where "b" will be correctly marked with "b", but "a" will be
marked with "a...b". Likewise with "a..b" (though you need
to use --boundary to even see "a" at all in that case).

To top off the confusion, when the REVARG_CANNOT_BE_FILENAME
flag is set, we skip the non-filename check, and leave the
NUL in place.

That means we do report the correct name for "a" in the
pending array. But some code paths try to show the whole
"a...b" name in error messages, and these erroneously show
only "a" instead of "a...b". E.g.:

  $ git cherry-pick HEAD:foo...HEAD:foo
  error: object d95f3ad14dee633a758d2e331151e950dd13e4ed is a blob, not a commit
  error: object d95f3ad14dee633a758d2e331151e950dd13e4ed is a blob, not a commit
  fatal: Invalid symmetric difference expression HEAD:foo

(That last message should be "HEAD:foo...HEAD:foo"; I used
cherry-pick because it passes the CANNOT_BE_FILENAME flag).

As an interesting side note, cherry-pick actually looks at
and re-resolves the arguments from the pending->name fields.
So it would have been visibly broken by the first bug, but
the effect was canceled out by the second one.

This patch makes the whole function consistent by re-writing
the NUL immediately after calling verify_non_filename(), and
then restoring the "." as appropriate in some error-printing
and early-return code paths.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoclean: teach clean -d to preserve ignored paths
Samuel Lijin [Tue, 23 May 2017 10:09:37 +0000 (23 06:09 -0400)]
clean: teach clean -d to preserve ignored paths

There is an implicit assumption that a directory containing only
untracked and ignored paths should itself be considered untracked. This
makes sense in use cases where we're asking if a directory should be
added to the git database, but not when we're asking if a directory can
be safely removed from the working tree; as a result, clean -d would
assume that an "untracked" directory containing ignored paths could be
deleted, even though doing so would also remove the ignored paths.

To get around this, we teach clean -d to collect ignored paths and skip
an untracked directory if it contained an ignored path, instead just
removing the untracked contents thereof. To achieve this, cmd_clean()
has to collect all untracked contents of untracked directories, in
addition to all ignored paths, to determine which untracked dirs must be
skipped (because they contain ignored paths) and which ones should *not*
be skipped.

For this purpose, correct_untracked_entries() is introduced to prune a
given dir_struct of untracked entries containing ignored paths and those
untracked entries encompassed by the untracked entries which are not
pruned away.

A memory leak is also fixed in cmd_clean().

This also fixes the known breakage in t7300, since clean -d now skips
untracked directories containing ignored paths.

Signed-off-by: Samuel Lijin <sxlijin@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agotag: duplicate mention of --contains should mention --no-contains
Ævar Arnfjörð Bjarmason [Mon, 15 May 2017 12:23:31 +0000 (15 12:23 +0000)]
tag: duplicate mention of --contains should mention --no-contains

Fix a duplicate mention of --contains in the SYNOPSIS to mention
--no-contains.

This fixes an error introduced in my commit ac3f5a3468 ("ref-filter:
add --no-contains option to tag/branch/for-each-ref", 2017-03-24).

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agomingw: simplify PATH handling
René Scharfe [Sat, 20 May 2017 19:35:37 +0000 (20 21:35 +0200)]
mingw: simplify PATH handling

On Windows the environment variable PATH contains a semicolon-separated
list of directories to search for, in order, when looking for the
location of a binary to run.  get_path_split() parses it and returns an
array of string copies, which is iterated by path_lookup(), which in
turn passes each entry to lookup_prog().

Change lookup_prog() to take the directory name as a length-limited
string instead of as a NUL-terminated one and parse PATH directly in
path_lookup().  This avoids memory allocations, simplifying the code.

Helped-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Rene Scharfe <l.s.r@web.de>
Acked-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agomingw.h: permit arguments with side effects for is_dir_sep
Johannes Sixt [Mon, 22 May 2017 18:58:32 +0000 (22 20:58 +0200)]
mingw.h: permit arguments with side effects for is_dir_sep

Taking git-compat-util.h's cue (which uses an inline function to back
is_dir_sep()), let's use an inline function to back also the Windows
version of is_dir_sep(). This avoids problems when calling the function
with arguments that do more than just provide a single character, e.g.
incrementing a pointer. Example:

    is_dir_sep(*p++)

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 years agoDocumentation: fix formatting typo in pretty-formats.txt
Andreas Heiduk [Mon, 22 May 2017 20:59:58 +0000 (22 22:59 +0200)]
Documentation: fix formatting typo in pretty-formats.txt

A missing space messed up formatting of the `%(trailers)` format.

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