git
5 years agoMerge branch 'sb/more-repo-in-api'
Junio C Hamano [Tue, 5 Feb 2019 22:26:09 +0000 (14:26 -0800)] 
Merge branch 'sb/more-repo-in-api'

The in-core repository instances are passed through more codepaths.

* sb/more-repo-in-api: (23 commits)
  t/helper/test-repository: celebrate independence from the_repository
  path.h: make REPO_GIT_PATH_FUNC repository agnostic
  commit: prepare free_commit_buffer and release_commit_memory for any repo
  commit-graph: convert remaining functions to handle any repo
  submodule: don't add submodule as odb for push
  submodule: use submodule repos for object lookup
  pretty: prepare format_commit_message to handle arbitrary repositories
  commit: prepare logmsg_reencode to handle arbitrary repositories
  commit: prepare repo_unuse_commit_buffer to handle any repo
  commit: prepare get_commit_buffer to handle any repo
  commit-reach: prepare in_merge_bases[_many] to handle any repo
  commit-reach: prepare get_merge_bases to handle any repo
  commit-reach.c: allow get_merge_bases_many_0 to handle any repo
  commit-reach.c: allow remove_redundant to handle any repo
  commit-reach.c: allow merge_bases_many to handle any repo
  commit-reach.c: allow paint_down_to_common to handle any repo
  commit: allow parse_commit* to handle any repo
  object: parse_object to honor its repository argument
  object-store: prepare has_{sha1, object}_file to handle any repo
  object-store: prepare read_object_file to deal with any repo
  ...

5 years agoFourth batch after 2.20
Junio C Hamano [Tue, 29 Jan 2019 20:54:55 +0000 (12:54 -0800)] 
Fourth batch after 2.20

Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 years agoMerge branch 'it/log-format-source'
Junio C Hamano [Tue, 29 Jan 2019 20:47:56 +0000 (12:47 -0800)] 
Merge branch 'it/log-format-source'

Custom userformat "log --format" learned %S atom that stands for
the tip the traversal reached the commit from, i.e. --source.

* it/log-format-source:
  log: add %S option (like --source) to log --format

5 years agoMerge branch 'js/add-e-clear-patch-before-stating'
Junio C Hamano [Tue, 29 Jan 2019 20:47:56 +0000 (12:47 -0800)] 
Merge branch 'js/add-e-clear-patch-before-stating'

"git add -e" got confused when the change it wants to let the user
edit is smaller than the previous change that was left over in a
temporary file.

* js/add-e-clear-patch-before-stating:
  add --edit: truncate the patch file

5 years agoMerge branch 'bc/tree-walk-oid'
Junio C Hamano [Tue, 29 Jan 2019 20:47:56 +0000 (12:47 -0800)] 
Merge branch 'bc/tree-walk-oid'

The code to walk tree objects has been taught that we may be
working with object names that are not computed with SHA-1.

* bc/tree-walk-oid:
  cache: make oidcpy always copy GIT_MAX_RAWSZ bytes
  tree-walk: store object_id in a separate member
  match-trees: use hashcpy to splice trees
  match-trees: compute buffer offset correctly when splicing
  tree-walk: copy object ID before use

5 years agoMerge branch 'jt/upload-pack-deepen-relative-proto-v2'
Junio C Hamano [Tue, 29 Jan 2019 20:47:55 +0000 (12:47 -0800)] 
Merge branch 'jt/upload-pack-deepen-relative-proto-v2'

"git fetch --deepen=<more>" has been corrected to work over v2
protocol.

* jt/upload-pack-deepen-relative-proto-v2:
  upload-pack: teach deepen-relative in protocol v2
  fetch-pack: do not take shallow lock unnecessarily

5 years agoMerge branch 'jk/remote-insteadof-cleanup'
Junio C Hamano [Tue, 29 Jan 2019 20:47:55 +0000 (12:47 -0800)] 
Merge branch 'jk/remote-insteadof-cleanup'

Code clean-up.

* jk/remote-insteadof-cleanup:
  remote: check config validity before creating rewrite struct

5 years agoMerge branch 'ms/http-no-more-failonerror'
Junio C Hamano [Tue, 29 Jan 2019 20:47:55 +0000 (12:47 -0800)] 
Merge branch 'ms/http-no-more-failonerror'

Debugging help for http transport.

* ms/http-no-more-failonerror:
  test: test GIT_CURL_VERBOSE=1 shows an error
  remote-curl: unset CURLOPT_FAILONERROR
  remote-curl: define struct for CURLOPT_WRITEFUNCTION
  http: enable keep_error for HTTP requests
  http: support file handles for HTTP_KEEP_ERROR

5 years agoMerge branch 'os/rebase-runs-post-checkout-hook'
Junio C Hamano [Tue, 29 Jan 2019 20:47:55 +0000 (12:47 -0800)] 
Merge branch 'os/rebase-runs-post-checkout-hook'

"git rebase" internally runs "checkout" to switch between branches,
and the command used to call the post-checkout hook, but the
reimplementation stopped doing so, which is getting fixed.

* os/rebase-runs-post-checkout-hook:
  rebase: run post-checkout hook on checkout
  t5403: simplify by using a single repository

5 years agoMerge branch 'bc/sha-256'
Junio C Hamano [Tue, 29 Jan 2019 20:47:55 +0000 (12:47 -0800)] 
Merge branch 'bc/sha-256'

Add sha-256 hash and plug it through the code to allow building Git
with the "NewHash".

* bc/sha-256:
  hash: add an SHA-256 implementation using OpenSSL
  sha256: add an SHA-256 implementation using libgcrypt
  Add a base implementation of SHA-256 support
  commit-graph: convert to using the_hash_algo
  t/helper: add a test helper to compute hash speed
  sha1-file: add a constant for hash block size
  t: make the sha1 test-tool helper generic
  t: add basic tests for our SHA-1 implementation
  cache: make hashcmp and hasheq work with larger hashes
  hex: introduce functions to print arbitrary hashes
  sha1-file: provide functions to look up hash algorithms
  sha1-file: rename algorithm to "sha1"

5 years agoMerge branch 'sb/submodule-recursive-fetch-gets-the-tip'
Junio C Hamano [Tue, 29 Jan 2019 20:47:54 +0000 (12:47 -0800)] 
Merge branch 'sb/submodule-recursive-fetch-gets-the-tip'

"git fetch --recurse-submodules" may not fetch the necessary commit
that is bound to the superproject, which is getting corrected.

* sb/submodule-recursive-fetch-gets-the-tip:
  fetch: ensure submodule objects fetched
  submodule.c: fetch in submodules git directory instead of in worktree
  submodule: migrate get_next_submodule to use repository structs
  repository: repo_submodule_init to take a submodule struct
  submodule: store OIDs in changed_submodule_names
  submodule.c: tighten scope of changed_submodule_names struct
  submodule.c: sort changed_submodule_names before searching it
  submodule.c: fix indentation
  sha1-array: provide oid_array_filter

5 years agoMerge branch 'jt/fetch-pack-v2'
Junio C Hamano [Tue, 29 Jan 2019 20:47:54 +0000 (12:47 -0800)] 
Merge branch 'jt/fetch-pack-v2'

"git fetch-pack" now can talk the version 2 protocol.

* jt/fetch-pack-v2:
  fetch-pack: support protocol version 2

5 years agoMerge branch 'jk/proto-v2-hidden-refs-fix'
Junio C Hamano [Tue, 29 Jan 2019 20:47:54 +0000 (12:47 -0800)] 
Merge branch 'jk/proto-v2-hidden-refs-fix'

The v2 upload-pack protocol implementation failed to honor
hidden-ref configuration, which has been corrected.
An earlier attempt reverted out of 'next'.

* jk/proto-v2-hidden-refs-fix:
  upload-pack: support hidden refs with protocol v2

5 years agoMerge branch 'jk/save-getenv-result'
Junio C Hamano [Tue, 29 Jan 2019 20:47:53 +0000 (12:47 -0800)] 
Merge branch 'jk/save-getenv-result'

There were many places the code relied on the string returned from
getenv() to be non-volatile, which is not true, that have been
corrected.

* jk/save-getenv-result:
  builtin_diff(): read $GIT_DIFF_OPTS closer to use
  merge-recursive: copy $GITHEAD strings
  init: make a copy of $GIT_DIR string
  config: make a copy of $GIT_CONFIG string
  commit: copy saved getenv() result
  get_super_prefix(): copy getenv() result

5 years agoMerge branch 'pw/diff-color-moved-ws-fix'
Junio C Hamano [Tue, 29 Jan 2019 20:47:53 +0000 (12:47 -0800)] 
Merge branch 'pw/diff-color-moved-ws-fix'

"git diff --color-moved-ws" updates.

* pw/diff-color-moved-ws-fix:
  diff --color-moved-ws: handle blank lines
  diff --color-moved-ws: modify allow-indentation-change
  diff --color-moved-ws: optimize allow-indentation-change
  diff --color-moved=zebra: be stricter with color alternation
  diff --color-moved-ws: fix false positives
  diff --color-moved-ws: demonstrate false positives
  diff: allow --no-color-moved-ws
  Use "whitespace" consistently
  diff: document --no-color-moved

5 years agoMerge branch 'ja/doc-build-l10n'
Junio C Hamano [Tue, 29 Jan 2019 20:47:53 +0000 (12:47 -0800)] 
Merge branch 'ja/doc-build-l10n'

Prepare Documentation/Makefile so that manpage localization can
reuse it by overriding and tweaking the list of build products.

* ja/doc-build-l10n:
  Documentation/Makefile add optional targets for l10n

5 years agoMerge branch 'js/rebase-i-redo-exec'
Junio C Hamano [Tue, 29 Jan 2019 20:47:53 +0000 (12:47 -0800)] 
Merge branch 'js/rebase-i-redo-exec'

"git rebase -i" learned to re-execute a command given with 'exec'
to run after it failed the last time.

* js/rebase-i-redo-exec:
  rebase: introduce a shortcut for --reschedule-failed-exec
  rebase: add a config option to default to --reschedule-failed-exec
  rebase: introduce --reschedule-failed-exec

5 years agoMerge branch 'cc/fetch-error-message-fix'
Junio C Hamano [Tue, 29 Jan 2019 20:47:53 +0000 (12:47 -0800)] 
Merge branch 'cc/fetch-error-message-fix'

Error message fix.

* cc/fetch-error-message-fix:
  fetch: fix extensions.partialclone name in error message

5 years agoMerge branch 'cc/partial-clone-doc-typofix'
Junio C Hamano [Tue, 29 Jan 2019 20:47:52 +0000 (12:47 -0800)] 
Merge branch 'cc/partial-clone-doc-typofix'

Doc fix.

* cc/partial-clone-doc-typofix:
  partial-clone: add missing 'is' in doc

5 years agoMerge branch 'kg/external-diff-save-env'
Junio C Hamano [Tue, 29 Jan 2019 20:47:51 +0000 (12:47 -0800)] 
Merge branch 'kg/external-diff-save-env'

The code to drive GIT_EXTERNAL_DIFF command relied on the string
returned from getenv() to be non-volatile, which is not true, that
has been corrected.

* kg/external-diff-save-env:
  diff: ensure correct lifetime of external_diff_cmd

5 years agoThird batch after 2.20
Junio C Hamano [Fri, 18 Jan 2019 21:56:54 +0000 (13:56 -0800)] 
Third batch after 2.20

Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 years agoMerge branch 'js/gc-repack-close-before-remove'
Junio C Hamano [Fri, 18 Jan 2019 21:49:57 +0000 (13:49 -0800)] 
Merge branch 'js/gc-repack-close-before-remove'

"git gc" and "git repack" did not close the open packfiles that
they found unneeded before removing them, which didn't work on a
platform incapable of removing an open file.  This has been
corrected.

* js/gc-repack-close-before-remove:
  gc/repack: release packs when needed

5 years agoMerge branch 'en/show-ref-doc-fix'
Junio C Hamano [Fri, 18 Jan 2019 21:49:56 +0000 (13:49 -0800)] 
Merge branch 'en/show-ref-doc-fix'

Doc update.

* en/show-ref-doc-fix:
  git-show-ref.txt: fix order of flags

5 years agoMerge branch 'ot/ref-filter-object-info'
Junio C Hamano [Fri, 18 Jan 2019 21:49:56 +0000 (13:49 -0800)] 
Merge branch 'ot/ref-filter-object-info'

The "--format=<placeholder>" option of for-each-ref, branch and tag
learned to show a few more traits of objects that can be learned by
the object_info API.

* ot/ref-filter-object-info:
  ref-filter: give uintmax_t to format with %PRIuMAX
  ref-filter: add docs for new options
  ref-filter: add tests for deltabase
  ref-filter: add deltabase option
  ref-filter: add tests for objectsize:disk
  ref-filter: add check for negative file size
  ref-filter: add objectsize:disk option

5 years agoMerge branch 'sg/stress-test'
Junio C Hamano [Fri, 18 Jan 2019 21:49:56 +0000 (13:49 -0800)] 
Merge branch 'sg/stress-test'

Flaky tests can now be repeatedly run under load with the
"--stress" option.

* sg/stress-test:
  test-lib: add the '--stress' option to run a test repeatedly under load
  test-lib-functions: introduce the 'test_set_port' helper function
  test-lib: set $TRASH_DIRECTORY earlier
  test-lib: consolidate naming of test-results paths
  test-lib: parse command line options earlier
  test-lib: parse options in a for loop to keep $@ intact
  test-lib: extract Bash version check for '-x' tracing
  test-lib: translate SIGTERM and SIGHUP to an exit

5 years agoMerge branch 'rs/sha1-file-close-mapped-file-on-error'
Junio C Hamano [Fri, 18 Jan 2019 21:49:56 +0000 (13:49 -0800)] 
Merge branch 'rs/sha1-file-close-mapped-file-on-error'

Code clean-up.

* rs/sha1-file-close-mapped-file-on-error:
  sha1-file: close fd of empty file in map_sha1_file_1()

5 years agoMerge branch 'rs/loose-object-cache-perffix'
Junio C Hamano [Fri, 18 Jan 2019 21:49:56 +0000 (13:49 -0800)] 
Merge branch 'rs/loose-object-cache-perffix'

The loose object cache used to optimize existence look-up has been
updated.

* rs/loose-object-cache-perffix:
  object-store: retire odb_load_loose_cache()
  object-store: use one oid_array per subdirectory for loose cache
  object-store: factor out odb_clear_loose_cache()
  object-store: factor out odb_loose_cache()

5 years agoMerge branch 'po/git-p4-wo-login'
Junio C Hamano [Fri, 18 Jan 2019 21:49:55 +0000 (13:49 -0800)] 
Merge branch 'po/git-p4-wo-login'

"git p4" update.

* po/git-p4-wo-login:
  git-p4: fix problem when p4 login is not necessary

5 years agoMerge branch 'mm/multimail-1.5'
Junio C Hamano [Fri, 18 Jan 2019 21:49:55 +0000 (13:49 -0800)] 
Merge branch 'mm/multimail-1.5'

Update "git multimail" from the upstream.

* mm/multimail-1.5:
  git-multimail: update to release 1.5.0

5 years agoMerge branch 'tg/t5570-drop-racy-test'
Junio C Hamano [Fri, 18 Jan 2019 21:49:55 +0000 (13:49 -0800)] 
Merge branch 'tg/t5570-drop-racy-test'

An inherently racy test that caused intermittent failures has been
removed.

* tg/t5570-drop-racy-test:
  Revert "t/lib-git-daemon: record daemon log"
  t5570: drop racy test

5 years agoMerge branch 'jk/dev-build-format-security'
Junio C Hamano [Fri, 18 Jan 2019 21:49:55 +0000 (13:49 -0800)] 
Merge branch 'jk/dev-build-format-security'

Earlier we added "-Wformat-security" to developer builds, assuming
that "-Wall" (which includes "-Wformat" which in turn is required
to use "-Wformat-security") is always in effect.  This is not true
when config.mak.autogen is in use, unfortunately.  This has been
fixed by unconditionally adding "-Wall" to developer builds.

* jk/dev-build-format-security:
  config.mak.dev: add -Wall, primarily for -Wformat, to help autoconf users

5 years agoMerge branch 'so/cherry-pick-always-allow-m1'
Junio C Hamano [Fri, 18 Jan 2019 21:49:54 +0000 (13:49 -0800)] 
Merge branch 'so/cherry-pick-always-allow-m1'

"git cherry-pick -m1" was forbidden when picking a non-merge
commit, even though there _is_ parent number 1 for such a commit.
This was done to avoid mistakes back when "cherry-pick" was about
picking a single commit, but is no longer useful with "cherry-pick"
that can pick a range of commits.  Now the "-m$num" option is
allowed when picking any commit, as long as $num names an existing
parent of the commit.

Technically this is a backward incompatible change; hopefully
nobody is relying on the error-checking behaviour.

* so/cherry-pick-always-allow-m1:
  t3506: validate '-m 1 -ff' is now accepted for non-merge commits
  t3502: validate '-m 1' argument is now accepted for non-merge commits
  cherry-pick: do not error on non-merge commits when '-m 1' is specified
  t3510: stop using '-m 1' to force failure mid-sequence of cherry-picks

5 years agoMerge branch 'nd/worktree-remove-with-uninitialized-submodules'
Junio C Hamano [Fri, 18 Jan 2019 21:49:54 +0000 (13:49 -0800)] 
Merge branch 'nd/worktree-remove-with-uninitialized-submodules'

"git worktree remove" and "git worktree move" refused to work when
there is a submodule involved.  This has been loosened to ignore
uninitialized submodules.

* nd/worktree-remove-with-uninitialized-submodules:
  worktree: allow to (re)move worktrees with uninitialized submodules

5 years agoMerge branch 'sg/test-bash-version-fix'
Junio C Hamano [Fri, 18 Jan 2019 21:49:54 +0000 (13:49 -0800)] 
Merge branch 'sg/test-bash-version-fix'

The test suite tried to see if it is run under bash, but the check
itself failed under some other implementations of shell (notably
under NetBSD).  This has been corrected.

* sg/test-bash-version-fix:
  test-lib: check Bash version for '-x' without using shell arrays

5 years agoMerge branch 'rb/hpe'
Junio C Hamano [Fri, 18 Jan 2019 21:49:54 +0000 (13:49 -0800)] 
Merge branch 'rb/hpe'

Portability updates for the HPE NonStop platform.

* rb/hpe:
  compat/regex/regcomp.c: define intptr_t and uintptr_t on NonStop
  git-compat-util.h: add FLOSS headers for HPE NonStop
  config.mak.uname: support for modern HPE NonStop config.
  transport-helper: drop read/write errno checks
  transport-helper: use xread instead of read

5 years agoMerge branch 'ed/simplify-setup-git-dir'
Junio C Hamano [Fri, 18 Jan 2019 21:49:54 +0000 (13:49 -0800)] 
Merge branch 'ed/simplify-setup-git-dir'

Code simplification.

* ed/simplify-setup-git-dir:
  Simplify handling of setup_git_directory_gently() failure cases.

5 years agoMerge branch 'cy/zsh-completion-SP-in-path'
Junio C Hamano [Fri, 18 Jan 2019 21:49:54 +0000 (13:49 -0800)] 
Merge branch 'cy/zsh-completion-SP-in-path'

With zsh, "git cmd path<TAB>" was completed to "git cmd path name"
when the completed path has a special character like SP in it,
without any attempt to keep "path name" a single filename.  This
has been fixed to complete it to "git cmd path\ name" just like
Bash completion does.

* cy/zsh-completion-SP-in-path:
  completion: treat results of git ls-tree as file paths
  zsh: complete unquoted paths with spaces correctly

5 years agoMerge branch 'cy/completion-typofix'
Junio C Hamano [Fri, 18 Jan 2019 21:49:53 +0000 (13:49 -0800)] 
Merge branch 'cy/completion-typofix'

Typofix.

* cy/completion-typofix:
  completion: fix typo in git-completion.bash

5 years agoMerge branch 'ew/ban-strncat'
Junio C Hamano [Fri, 18 Jan 2019 21:49:53 +0000 (13:49 -0800)] 
Merge branch 'ew/ban-strncat'

The "strncat()" function is now among the banned functions.

* ew/ban-strncat:
  banned.h: mark strncat() as banned

5 years agoMerge branch 'ds/commit-graph-assert-missing-parents'
Junio C Hamano [Fri, 18 Jan 2019 21:49:53 +0000 (13:49 -0800)] 
Merge branch 'ds/commit-graph-assert-missing-parents'

Tightening error checking in commit-graph writer.

* ds/commit-graph-assert-missing-parents:
  commit-graph: writing missing parents is a BUG

5 years agoMerge branch 'es/doc-worktree-guessremote-config'
Junio C Hamano [Fri, 18 Jan 2019 21:49:53 +0000 (13:49 -0800)] 
Merge branch 'es/doc-worktree-guessremote-config'

Doc clarification.

* es/doc-worktree-guessremote-config:
  doc/config: do a better job of introducing 'worktree.guessRemote'

5 years agoMerge branch 'sb/submodule-unset-core-worktree-when-worktree-is-lost'
Junio C Hamano [Fri, 18 Jan 2019 21:49:53 +0000 (13:49 -0800)] 
Merge branch 'sb/submodule-unset-core-worktree-when-worktree-is-lost'

The core.worktree setting in a submodule repository should not be
pointing at a directory when the submodule loses its working tree
(e.g. getting deinit'ed), but the code did not properly maintain
this invariant.

* sb/submodule-unset-core-worktree-when-worktree-is-lost:
  submodule deinit: unset core.worktree
  submodule--helper: fix BUG message in ensure_core_worktree
  submodule: unset core.worktree if no working tree is present
  submodule update: add regression test with old style setups

5 years agoMerge branch 'ma/asciidoctor'
Junio C Hamano [Fri, 18 Jan 2019 21:49:53 +0000 (13:49 -0800)] 
Merge branch 'ma/asciidoctor'

Some of the documentation pages formatted incorrectly with
Asciidoctor, which have been fixed.

* ma/asciidoctor:
  git-status.txt: render tables correctly under Asciidoctor
  Documentation: do not nest open blocks
  git-column.txt: fix section header

5 years agoMerge branch 'jn/stripspace-wo-repository'
Junio C Hamano [Fri, 18 Jan 2019 21:49:53 +0000 (13:49 -0800)] 
Merge branch 'jn/stripspace-wo-repository'

"git stripspace" should be usable outside a git repository, but
under the "-s" or "-c" mode, it didn't.

* jn/stripspace-wo-repository:
  stripspace: allow -s/-c outside git repository

5 years agoMerge branch 'sb/submodule-fetchjobs-default-to-one'
Junio C Hamano [Fri, 18 Jan 2019 21:49:52 +0000 (13:49 -0800)] 
Merge branch 'sb/submodule-fetchjobs-default-to-one'

"git submodule update" ought to use a single job unless asked, but
by mistake used multiple jobs, which has been fixed.

* sb/submodule-fetchjobs-default-to-one:
  submodule update: run at most one fetch job unless otherwise set

5 years agoMerge branch 'la/quiltimport-keep-non-patch'
Junio C Hamano [Fri, 18 Jan 2019 21:49:52 +0000 (13:49 -0800)] 
Merge branch 'la/quiltimport-keep-non-patch'

"git quiltimport" learned "--keep-non-patch" option.

* la/quiltimport-keep-non-patch:
  git-quiltimport: add --keep-non-patch option

5 years agoMerge branch 'nd/style-opening-brace'
Junio C Hamano [Fri, 18 Jan 2019 21:49:52 +0000 (13:49 -0800)] 
Merge branch 'nd/style-opening-brace'

Code clean-up.

* nd/style-opening-brace:
  style: the opening '{' of a function is in a separate line

5 years agoMerge branch 'ds/gc-doc-typofix'
Junio C Hamano [Fri, 18 Jan 2019 21:49:52 +0000 (13:49 -0800)] 
Merge branch 'ds/gc-doc-typofix'

Typofix.

* ds/gc-doc-typofix:
  git-gc.txt: fix typo about gc.writeCommitGraph

5 years agoadd --edit: truncate the patch file
Johannes Schindelin [Tue, 15 Jan 2019 15:42:52 +0000 (07:42 -0800)] 
add --edit: truncate the patch file

If there is already a .git/ADD_EDIT.patch file, we fail to truncate it
properly, which could result in very funny errors.

Of course, this file should not be left lying around. But at least in
one case, there was a stale copy, larger than the current diff. So the
result was a corrupt diff.

Let's just truncate the file when we write it and not worry about it too
much.

Reported by J Wyman.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 years agocache: make oidcpy always copy GIT_MAX_RAWSZ bytes
brian m. carlson [Tue, 15 Jan 2019 00:39:45 +0000 (00:39 +0000)] 
cache: make oidcpy always copy GIT_MAX_RAWSZ bytes

There are some situations in which we want to store an object ID into
struct object_id without the_hash_algo necessarily being set correctly.
One such case is when cloning a repository, where we must read refs from
the remote side without having a repository from which to read the
preferred algorithm.

In this cases, we may have the_hash_algo set to SHA-1, which is the
default, but read refs into struct object_id that are SHA-256. When
copying these values, we will want to copy them completely, not just the
first 20 bytes. Consequently, make sure that oidcpy copies the maximum
number of bytes at all times, regardless of the setting of
the_hash_algo.

Since oidcpy and hashcpy are no longer functionally identical, remove
the Cocinelle object_id transformations that convert from one into the
other.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 years agotree-walk: store object_id in a separate member
brian m. carlson [Tue, 15 Jan 2019 00:39:44 +0000 (00:39 +0000)] 
tree-walk: store object_id in a separate member

When parsing a tree, we read the object ID directly out of the tree
buffer. This is normally fine, but such an object ID cannot be used with
oidcpy, which copies GIT_MAX_RAWSZ bytes, because if we are using SHA-1,
there may not be that many bytes to copy.

Instead, store the object ID in a separate struct member. Since we can
no longer efficiently compute the path length, store that information as
well in struct name_entry. Ensure we only copy the object ID into the
new buffer if the path length is nonzero, as some callers will pass us
an empty path with no object ID following it, and we will not want to
read past the end of the buffer.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 years agomatch-trees: use hashcpy to splice trees
brian m. carlson [Tue, 15 Jan 2019 00:39:43 +0000 (00:39 +0000)] 
match-trees: use hashcpy to splice trees

When we splice trees together, we operate in place on the tree buffer.
If we're using SHA-1 for the hash algorithm, we may not have a full
GIT_MAX_RAWSZ (32) bytes to copy. Consequently, it doesn't logically
make sense for us to use a struct object_id to represent this type,
since it isn't a complete object.

Represent this value as a unsigned char pointer instead and copy it when
necessary.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 years agomatch-trees: compute buffer offset correctly when splicing
brian m. carlson [Tue, 15 Jan 2019 00:39:42 +0000 (00:39 +0000)] 
match-trees: compute buffer offset correctly when splicing

Currently, the struct object_id pointer returned from tree_entry_extract
lives directly inside the parsed tree buffer. In a future commit, this
will change so that it instead points to a dedicated struct member.
Since in this code path, we want to modify the buffer directly, compute
the buffer offset we want to modify by using the pointer to the path
instead.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 years agotree-walk: copy object ID before use
brian m. carlson [Tue, 15 Jan 2019 00:39:41 +0000 (00:39 +0000)] 
tree-walk: copy object ID before use

In a future commit, the pointer returned by tree_entry_extract will
point into the struct tree_desc, causing its lifetime to be bound to
that of the struct tree_desc itself.  To ensure this code path keeps
working, copy the object_id into a local variable so that it lives long
enough.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 years agoSecond batch after 2.20
Junio C Hamano [Mon, 14 Jan 2019 23:33:36 +0000 (15:33 -0800)] 
Second batch after 2.20

Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 years agoMerge branch 'do/gitweb-strict-export-conf-doc'
Junio C Hamano [Mon, 14 Jan 2019 23:29:33 +0000 (15:29 -0800)] 
Merge branch 'do/gitweb-strict-export-conf-doc'

Doc update.

* do/gitweb-strict-export-conf-doc:
  docs: fix $strict_export text in gitweb.conf.txt

5 years agoMerge branch 'nd/indentation-fix'
Junio C Hamano [Mon, 14 Jan 2019 23:29:32 +0000 (15:29 -0800)] 
Merge branch 'nd/indentation-fix'

Code cleanup.

* nd/indentation-fix:
  Indent code with TABs

5 years agoMerge branch 'en/directory-renames-nothanks-doc-update'
Junio C Hamano [Mon, 14 Jan 2019 23:29:32 +0000 (15:29 -0800)] 
Merge branch 'en/directory-renames-nothanks-doc-update'

Doc update.

* en/directory-renames-nothanks-doc-update:
  git-rebase.txt: update note about directory rename detection and am

5 years agoMerge branch 'bw/mailmap'
Junio C Hamano [Mon, 14 Jan 2019 23:29:32 +0000 (15:29 -0800)] 
Merge branch 'bw/mailmap'

* bw/mailmap:
  mailmap: update brandon williams's email address

5 years agoMerge branch 'fd/gitweb-snapshot-conf-doc-fix'
Junio C Hamano [Mon, 14 Jan 2019 23:29:32 +0000 (15:29 -0800)] 
Merge branch 'fd/gitweb-snapshot-conf-doc-fix'

Doc update.

* fd/gitweb-snapshot-conf-doc-fix:
  docs/gitweb.conf: config variable typo

5 years agoMerge branch 'tb/use-common-win32-pathfuncs-on-cygwin'
Junio C Hamano [Mon, 14 Jan 2019 23:29:32 +0000 (15:29 -0800)] 
Merge branch 'tb/use-common-win32-pathfuncs-on-cygwin'

Cygwin update.

* tb/use-common-win32-pathfuncs-on-cygwin:
  git clone <url> C:\cygwin\home\USER\repo' is working (again)

5 years agoMerge branch 'km/rebase-doc-typofix'
Junio C Hamano [Mon, 14 Jan 2019 23:29:32 +0000 (15:29 -0800)] 
Merge branch 'km/rebase-doc-typofix'

Doc update.

* km/rebase-doc-typofix:
  rebase docs: drop stray word in merge command description

5 years agoMerge branch 'md/exclude-promisor-objects-fix-cleanup'
Junio C Hamano [Mon, 14 Jan 2019 23:29:31 +0000 (15:29 -0800)] 
Merge branch 'md/exclude-promisor-objects-fix-cleanup'

Code clean-up.

* md/exclude-promisor-objects-fix-cleanup:
  revision.c: put promisor option in specialized struct

5 years agoMerge branch 'tb/log-G-binary'
Junio C Hamano [Mon, 14 Jan 2019 23:29:31 +0000 (15:29 -0800)] 
Merge branch 'tb/log-G-binary'

"git log -G<regex>" looked for a hunk in the "git log -p" patch
output that contained a string that matches the given pattern.
Optimize this code to ignore binary files, which by default will
not show any hunk that would match any pattern (unless textconv or
the --text option is in effect, that is).

* tb/log-G-binary:
  log -G: ignore binary files

5 years agoMerge branch 'sb/diff-color-moved-config-option-fixup'
Junio C Hamano [Mon, 14 Jan 2019 23:29:31 +0000 (15:29 -0800)] 
Merge branch 'sb/diff-color-moved-config-option-fixup'

Minor inconsistency fix.

* sb/diff-color-moved-config-option-fixup:
  diff: align move detection error handling with other options

5 years agoMerge branch 'hn/highlight-sideband-keywords'
Junio C Hamano [Mon, 14 Jan 2019 23:29:30 +0000 (15:29 -0800)] 
Merge branch 'hn/highlight-sideband-keywords'

Lines that begin with a certain keyword that come over the wire, as
well as lines that consist only of one of these keywords, ought to
be painted in color for easier eyeballing, but the latter was
broken ever since the feature was introduced in 2.19, which has
been corrected.

* hn/highlight-sideband-keywords:
  sideband: color lines with keyword only

5 years agoMerge branch 'cb/test-lint-cp-a'
Junio C Hamano [Mon, 14 Jan 2019 23:29:30 +0000 (15:29 -0800)] 
Merge branch 'cb/test-lint-cp-a'

BSD port update.

* cb/test-lint-cp-a:
  tests: add lint for non portable cp -a

5 years agoMerge branch 'cb/t5004-empty-tar-archive-fix'
Junio C Hamano [Mon, 14 Jan 2019 23:29:30 +0000 (15:29 -0800)] 
Merge branch 'cb/t5004-empty-tar-archive-fix'

BSD port update.

* cb/t5004-empty-tar-archive-fix:
  t5004: avoid using tar for empty packages

5 years agoMerge branch 'cb/openbsd-allows-reading-directory'
Junio C Hamano [Mon, 14 Jan 2019 23:29:30 +0000 (15:29 -0800)] 
Merge branch 'cb/openbsd-allows-reading-directory'

BSD port update.

* cb/openbsd-allows-reading-directory:
  config.mak.uname: OpenBSD uses BSD semantics with fread for directories

5 years agoMerge branch 'hb/t0061-dot-in-path-fix'
Junio C Hamano [Mon, 14 Jan 2019 23:29:29 +0000 (15:29 -0800)] 
Merge branch 'hb/t0061-dot-in-path-fix'

Test update.

* hb/t0061-dot-in-path-fix:
  t0061: do not fail test if '.' is part of $PATH

5 years agoMerge branch 'nd/checkout-noisy'
Junio C Hamano [Mon, 14 Jan 2019 23:29:28 +0000 (15:29 -0800)] 
Merge branch 'nd/checkout-noisy'

"git checkout [<tree-ish>] path..." learned to report the number of
paths that have been checked out of the index or the tree-ish,
which gives it the same degree of noisy-ness as the case in which
the command checks out a branch.

* nd/checkout-noisy:
  t0027: squelch checkout path run outside test_expect_* block
  checkout: print something when checking out paths

5 years agoMerge branch 'ab/commit-graph-progress-fix'
Junio C Hamano [Mon, 14 Jan 2019 23:29:28 +0000 (15:29 -0800)] 
Merge branch 'ab/commit-graph-progress-fix'

* ab/commit-graph-progress-fix:
  commit-graph: split up close_reachable() progress output

5 years agoMerge branch 'nd/attr-pathspec-in-tree-walk'
Junio C Hamano [Mon, 14 Jan 2019 23:29:28 +0000 (15:29 -0800)] 
Merge branch 'nd/attr-pathspec-in-tree-walk'

The traversal over tree objects has learned to honor
":(attr:label)" pathspec match, which has been implemented only for
enumerating paths on the filesystem.

* nd/attr-pathspec-in-tree-walk:
  tree-walk: support :(attr) matching
  dir.c: move, rename and export match_attrs()
  pathspec.h: clean up "extern" in function declarations
  tree-walk.c: make tree_entry_interesting() take an index
  tree.c: make read_tree*() take 'struct repository *'

5 years agoMerge branch 'md/list-lazy-objects-fix'
Junio C Hamano [Mon, 14 Jan 2019 23:29:28 +0000 (15:29 -0800)] 
Merge branch 'md/list-lazy-objects-fix'

"git rev-list --exclude-promisor-objects" had to take an object
that does not exist locally (and is lazily available) from the
command line without barfing, but the code dereferenced NULL.

* md/list-lazy-objects-fix:
  list-objects.c: don't segfault for missing cmdline objects

5 years agopartial-clone: add missing 'is' in doc
Christian Couder [Mon, 14 Jan 2019 06:10:52 +0000 (07:10 +0100)] 
partial-clone: add missing 'is' in doc

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 years agofetch: fix extensions.partialclone name in error message
Christian Couder [Sun, 13 Jan 2019 08:52:19 +0000 (09:52 +0100)] 
fetch: fix extensions.partialclone name in error message

There is "extensions.partialclone" and "core.partialCloneFilter", but
not "core.partialclone". Only "extensions.partialclone" is meant to
contain a remote name.

While at it, let's wrap the relevant code lines to keep them at a
reasonable length.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 years agobuiltin_diff(): read $GIT_DIFF_OPTS closer to use
Jeff King [Fri, 11 Jan 2019 22:17:22 +0000 (17:17 -0500)] 
builtin_diff(): read $GIT_DIFF_OPTS closer to use

The value returned by getenv() is not guaranteed to remain valid across
other environment function calls. But in between our call and using the
value, we run fill_textconv(), which may do quite a bit of work,
including spawning sub-processes.

We can make this safer by calling getenv() right before we actually look
at its value.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 years agomerge-recursive: copy $GITHEAD strings
Jeff King [Fri, 11 Jan 2019 22:16:55 +0000 (17:16 -0500)] 
merge-recursive: copy $GITHEAD strings

If $GITHEAD_1234abcd is set in the environment, we use its value as a
"better branch name" in generating conflict markers. However, we pick
these better names early in the process, and the return value from
getenv() is not guaranteed to stay valid.

Let's make a copy of the returned string. And to make memory management
easier, let's just always return an allocated string from
better_branch_name(), so we know that it must always be freed.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 years agoinit: make a copy of $GIT_DIR string
Jeff King [Fri, 11 Jan 2019 22:16:31 +0000 (17:16 -0500)] 
init: make a copy of $GIT_DIR string

We pass the result of getenv("GIT_DIR") to init_db() and assume that the
string remains valid. But that's not guaranteed across calls to setenv()
or even getenv(), although it often works in practice. Let's make a copy
of the string so that we follow the rules.

Note that we need to mark it with UNLEAK(), since the value persists
until the end of program (but we have no opportunity to free it).

This patch also handles $GIT_WORK_TREE the same way. It actually doesn't
have as long a lifetime and is probably fine, but it's simpler to just
treat the two side-by-side variables the same.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 years agoconfig: make a copy of $GIT_CONFIG string
Jeff King [Fri, 11 Jan 2019 22:15:54 +0000 (17:15 -0500)] 
config: make a copy of $GIT_CONFIG string

cmd_config() points our source filename pointer at the return value of
getenv(), but that value may be invalidated by further calls to
environment functions. Let's copy it to make sure it remains valid.

We don't need to bother freeing it, as it remains part of the
whole-process global state until we exit.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 years agocommit: copy saved getenv() result
Jeff King [Fri, 11 Jan 2019 22:15:40 +0000 (17:15 -0500)] 
commit: copy saved getenv() result

We save the result of $GIT_INDEX_FILE so that we can restore it after
setting it to a new value and running add--interactive. However, the
pointer returned by getenv() is not guaranteed to be valid after calling
setenv(). This _usually_ works fine, but can fail if libc needs to
reallocate the environment block during the setenv().

Let's just duplicate the string, so we know that it remains valid.

In the long run it may be more robust to teach interactive_add() to take
a set of environment variables to pass along to run-command when it
execs add--interactive. And then we would not have to do this
save/restore dance at all. But this is an easy fix in the meantime.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 years agoget_super_prefix(): copy getenv() result
Jeff King [Fri, 11 Jan 2019 22:15:00 +0000 (17:15 -0500)] 
get_super_prefix(): copy getenv() result

The return value of getenv() is not guaranteed to remain valid across
multiple calls (nor across calls to setenv()). Since this function
caches the result for the length of the program, we must make a copy to
ensure that it is still valid when we need it.

Reported-by: Yngve N. Pettersen <yngve@vivaldi.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 years agoremote: check config validity before creating rewrite struct
Jeff King [Thu, 22 Nov 2018 17:31:09 +0000 (12:31 -0500)] 
remote: check config validity before creating rewrite struct

When parsing url.foo.insteadOf, we call make_rewrite() and only then
check to make sure the config value is a string (and return an error if
it isn't). This isn't quite a leak, because the struct we allocate is
part of a global array, but it does leave a funny half-finished struct.

In practice, it doesn't make much difference because we exit soon after
due to the config error anyway. But let's flip the order here to avoid
leaving a trap for somebody in the future.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 years agodiff: ensure correct lifetime of external_diff_cmd
Kim Gybels [Fri, 11 Jan 2019 20:26:08 +0000 (21:26 +0100)] 
diff: ensure correct lifetime of external_diff_cmd

According to getenv(3)'s notes:

    The implementation of getenv() is not required to be reentrant.  The
    string pointed to by the return value of getenv() may be statically
    allocated, and can be modified by a subsequent call to getenv(),
    putenv(3), setenv(3), or unsetenv(3).

Since strings returned by getenv() are allowed to change on subsequent
calls to getenv(), make sure to duplicate when caching external_diff_cmd
from environment.

This problem becomes apparent on Git for Windows since fe21c6b285df
(mingw: reencode environment variables on the fly (UTF-16 <-> UTF-8)),
when the getenv() implementation provided in compat/mingw.c was changed
to keep a certain amount of alloc'ed strings and freeing them on
subsequent calls.

This fixes https://github.com/git-for-windows/git/issues/2007:

    $ yes n | git -c difftool.prompt=yes difftool fe21c6b285df fe21c6b285df~100

    Viewing (1/404): '.gitignore'
    Launch 'bc3' [Y/n]?
    Viewing (2/404): 'Documentation/.gitignore'
    Launch 'bc3' [Y/n]?
    Viewing (3/404): 'Documentation/Makefile'
    Launch 'bc3' [Y/n]?
    Viewing (4/404): 'Documentation/RelNotes/2.14.5.txt'
    Launch 'bc3' [Y/n]?
    Viewing (5/404): 'Documentation/RelNotes/2.15.3.txt'
    Launch 'bc3' [Y/n]?
    Viewing (6/404): 'Documentation/RelNotes/2.16.5.txt'
    Launch 'bc3' [Y/n]?
    Viewing (7/404): 'Documentation/RelNotes/2.17.2.txt'
    Launch 'bc3' [Y/n]?
    Viewing (8/404): 'Documentation/RelNotes/2.18.1.txt'
    Launch 'bc3' [Y/n]?
    Viewing (9/404): 'Documentation/RelNotes/2.19.0.txt'
    Launch 'bc3' [Y/n]? error: cannot spawn ¦?: No such file or directory
    fatal: external diff died, stopping at Documentation/RelNotes/2.19.1.txt

Signed-off-by: Kim Gybels <kgybels@infogroep.be>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 years agolog: add %S option (like --source) to log --format
Issac Trotts [Fri, 11 Jan 2019 06:30:46 +0000 (22:30 -0800)] 
log: add %S option (like --source) to log --format

Make it possible to write for example

        git log --format="%H,%S"

where the %S at the end is a new placeholder that prints out the ref
(tag/branch) for each commit.

Using %d might seem like an alternative but it only shows the ref for the last
commit in the branch.

Signed-off-by: Issac Trotts <issactrotts@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 years agogc/repack: release packs when needed
Johannes Schindelin [Sat, 15 Dec 2018 22:04:01 +0000 (14:04 -0800)] 
gc/repack: release packs when needed

On Windows, files cannot be removed nor renamed if there are still
handles held by a process. To remedy that, we introduced the
close_all_packs() function.

Earlier, we made sure that the packs are released just before `git gc`
is spawned, in case that gc wants to remove no-longer needed packs.

But this developer forgot that gc itself also needs to let go of packs,
e.g. when consolidating all packs via the --aggressive option.

Likewise, `git repack -d` wants to delete obsolete packs and therefore
needs to close all pack handles, too.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 years agotest: test GIT_CURL_VERBOSE=1 shows an error
Masaya Suzuki [Thu, 10 Jan 2019 19:33:50 +0000 (11:33 -0800)] 
test: test GIT_CURL_VERBOSE=1 shows an error

This tests GIT_CURL_VERBOSE shows an error when an URL returns 500. This
exercises the code in remote_curl.

Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 years agoremote-curl: unset CURLOPT_FAILONERROR
Masaya Suzuki [Thu, 10 Jan 2019 19:33:49 +0000 (11:33 -0800)] 
remote-curl: unset CURLOPT_FAILONERROR

By not setting CURLOPT_FAILONERROR, curl parses the HTTP response
headers even if the response is an error. This makes GIT_CURL_VERBOSE to
show the HTTP headers, which is useful for debugging.

Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 years agoremote-curl: define struct for CURLOPT_WRITEFUNCTION
Masaya Suzuki [Thu, 10 Jan 2019 19:33:48 +0000 (11:33 -0800)] 
remote-curl: define struct for CURLOPT_WRITEFUNCTION

In order to pass more values for rpc_in, define a struct and pass it as
an additional value.

Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 years agohttp: enable keep_error for HTTP requests
Masaya Suzuki [Thu, 10 Jan 2019 19:33:47 +0000 (11:33 -0800)] 
http: enable keep_error for HTTP requests

curl stops parsing a response when it sees a bad HTTP status code and it
has CURLOPT_FAILONERROR set. This prevents GIT_CURL_VERBOSE to show HTTP
headers on error.

keep_error is an option to receive the HTTP response body for those
error responses. By enabling this option, curl will process the HTTP
response headers, and they're shown if GIT_CURL_VERBOSE is set.

Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 years agohttp: support file handles for HTTP_KEEP_ERROR
Masaya Suzuki [Thu, 10 Jan 2019 19:33:46 +0000 (11:33 -0800)] 
http: support file handles for HTTP_KEEP_ERROR

HTTP_KEEP_ERROR makes it easy to debug HTTP transport errors. In order
to make HTTP_KEEP_ERROR enabled for all requests, file handles need to
be supported.

Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 years agoupload-pack: teach deepen-relative in protocol v2
Jonathan Tan [Tue, 18 Dec 2018 21:24:35 +0000 (13:24 -0800)] 
upload-pack: teach deepen-relative in protocol v2

Commit 685fbd3291 ("fetch-pack: perform a fetch using v2", 2018-03-15)
attempted to teach Git deepen-relative in protocol v2 (among other
things), but it didn't work:

 (1) fetch-pack.c needs to emit "deepen-relative".
 (2) upload-pack.c needs to ensure that the correct deepen_relative
     variable is passed to deepen() (there are two - the static variable
     and the one in struct upload_pack_data).
 (3) Before deepen() computes the list of reachable shallows, it first
     needs to mark all "our" refs as OUR_REF. v2 currently does not do
     this, because unlike v0, it is not needed otherwise.

Fix all this and include a test demonstrating that it works now. For
(2), the static variable deepen_relative is also eliminated, removing a
source of confusion.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Reviewed-by: Josh Steadmon <steadmon@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 years agofetch-pack: do not take shallow lock unnecessarily
Jonathan Tan [Thu, 10 Jan 2019 19:36:45 +0000 (11:36 -0800)] 
fetch-pack: do not take shallow lock unnecessarily

When fetching using protocol v2, the remote may send a "shallow-info"
section if the client is shallow. If so, Git as the client currently
takes the shallow file lock, even if the "shallow-info" section is
empty.

This is not a problem except that Git does not support taking the
shallow file lock after modifying the shallow file, because
is_repository_shallow() stores information that is never cleared. And
this take-after-modify occurs when Git does a tag-following fetch from a
shallow repository on a transport that does not support tag following
(since in this case, 2 fetches are performed).

To solve this issue, take the shallow file lock (and perform all other
shallow processing) only if the "shallow-info" section is non-empty;
otherwise, behave as if it were empty.

A full solution (probably, ensuring that any action of committing
shallow file locks also includes clearing the information stored by
is_repository_shallow()) would solve the issue without need for this
patch, but this patch is independently useful (as an optimization to
prevent writing a file in an unnecessary case), hence why I wrote it. I
have included a NEEDSWORK outlining the full solution.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 years agofetch-pack: support protocol version 2
Jonathan Tan [Mon, 17 Dec 2018 22:40:54 +0000 (23:40 +0100)] 
fetch-pack: support protocol version 2

When the scaffolding for protocol version 2 was initially added in
8f6982b4e1 ("protocol: introduce enum protocol_version value
protocol_v2", 2018-03-14). As seen in:

    git log -p -G'support for protocol v2 not implemented yet' --full-diff --reverse v2.17.0..v2.20.0

Many of those scaffolding "die" placeholders were removed, but we
hadn't gotten around to fetch-pack yet.

The test here for "fetch refs from cmdline" is very minimal. There's
much better coverage when running the entire test suite under the WIP
GIT_TEST_PROTOCOL_VERSION=2 mode[1], we should ideally have better
coverage without needing to invoke a special test mode.

1. https://public-inbox.org/git/20181213155817.27666-1-avarab@gmail.com/

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 years agoupload-pack: support hidden refs with protocol v2
Jeff King [Tue, 18 Dec 2018 12:47:50 +0000 (07:47 -0500)] 
upload-pack: support hidden refs with protocol v2

In the v2 protocol, upload-pack's advertisement has been moved to the
"ls-refs" command. That command does not respect hidden-ref config (like
transfer.hiderefs) at all, and advertises everything.

While there are some features that are not supported in v2 (e.g., v2
always allows fetching any sha1 without respect to advertisements), the
lack of this feature is not documented and is likely just a bug. Let's
make it work, as otherwise upgrading a server to a v2-capable git will
start exposing these refs that the repository admin has asked to remain
hidden.

Note that we assume we're operating on behalf of a fetch here, since
that's the only thing implemented in v2 at this point. See the in-code
comment. We'll have to figure out how this works when the v2 push
protocol is designed (both here in ls-refs, but also rejecting updates
to hidden refs).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 years agodiff --color-moved-ws: handle blank lines
Phillip Wood [Fri, 23 Nov 2018 11:16:58 +0000 (11:16 +0000)] 
diff --color-moved-ws: handle blank lines

When using --color-moved-ws=allow-indentation-change allow lines with
the same indentation change to be grouped across blank lines. For now
this only works if the blank lines have been moved as well, not for
blocks that have just had their indentation changed.

This completes the changes to the implementation of
--color-moved=allow-indentation-change. Running

  git diff --color-moved=allow-indentation-change v2.18.0 v2.19.0

now takes 5.0s. This is a saving of 41% from 8.5s for the optimized
version of the previous implementation and 66% from the original which
took 14.6s.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Reviewed-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 years agodiff --color-moved-ws: modify allow-indentation-change
Phillip Wood [Fri, 23 Nov 2018 11:16:57 +0000 (11:16 +0000)] 
diff --color-moved-ws: modify allow-indentation-change

Currently diff --color-moved-ws=allow-indentation-change does not
support indentation that contains a mix of tabs and spaces. For
example in commit 546f70f377 ("convert.h: drop 'extern' from function
declaration", 2018-06-30) the function parameters in the following
lines are not colored as moved [1].

-extern int stream_filter(struct stream_filter *,
-                        const char *input, size_t *isize_p,
-                        char *output, size_t *osize_p);
+int stream_filter(struct stream_filter *,
+                 const char *input, size_t *isize_p,
+                 char *output, size_t *osize_p);

This commit changes the way the indentation is handled to track the
visual size of the indentation rather than the characters in the
indentation. This has the benefit that any whitespace errors do not
interfer with the move detection (the whitespace errors will still be
highlighted according to --ws-error-highlight). During the discussion
of this feature there were concerns about the correct detection of
indentation for python. However those concerns apply whether or not
we're detecting moved lines so no attempt is made to determine if the
indentation is 'pythonic'.

[1] Note that before the commit to fix the erroneous coloring of moved
    lines each line was colored as a different block, since that commit
    they are uncolored.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Reviewed-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 years agodiff --color-moved-ws: optimize allow-indentation-change
Phillip Wood [Fri, 23 Nov 2018 11:16:56 +0000 (11:16 +0000)] 
diff --color-moved-ws: optimize allow-indentation-change

When running

  git diff --color-moved-ws=allow-indentation-change v2.18.0 v2.19.0

cmp_in_block_with_wsd() is called 694908327 times. Of those 42.7%
return after comparing a and b. By comparing the lengths first we can
return early in all but 0.03% of those cases without dereferencing the
string pointers. The comparison between a and c fails in 6.8% of
calls, by comparing the lengths first we reject all the failing calls
without dereferencing the string pointers.

This reduces the time to run the command above by by 42% from 14.6s to
8.5s. This is still much slower than the normal --color-moved which
takes ~0.6-0.7s to run but is a significant improvement.

The next commits will replace the current implementation with one that
works with mixed tabs and spaces in the indentation. I think it is
worth optimizing the current implementation first to enable a fair
comparison between the two implementations.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Reviewed-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 years agodiff --color-moved=zebra: be stricter with color alternation
Phillip Wood [Fri, 23 Nov 2018 11:16:55 +0000 (11:16 +0000)] 
diff --color-moved=zebra: be stricter with color alternation

Currently when using --color-moved=zebra the color of moved blocks
depends on the number of lines separating them. This means that adding
an odd number of unmoved lines between blocks that are already separated
by one or more unmoved lines will change the color of subsequent moved
blocks. This does not make much sense as the blocks were already
separated by unmoved lines and causes problems when adding lines to test
cases.

Fix this by only using the alternate colors for adjacent moved blocks.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Reviewed-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 years agodiff --color-moved-ws: fix false positives
Phillip Wood [Fri, 23 Nov 2018 11:16:54 +0000 (11:16 +0000)] 
diff --color-moved-ws: fix false positives

'diff --color-moved-ws=allow-indentation-change' can color lines as
moved when they are in fact different. For example in commit
1a07e59c3e ("Update messages in preparation for i18n", 2018-07-21) the
lines

-               die (_("must end with a color"));
+               die(_("must end with a color"));

are colored as moved even though they are different.

This is because if there is a fuzzy match for the first line of
a potential moved block the line is marked as moved before the
potential match is checked to see if it actually matches. The fix is
to delay marking the line as moved until after we have checked that
there really is at least one matching potential moved block.

Note that the test modified in the last commit still fails because
adding an unmoved line between two moved blocks that are already
separated by unmoved lines changes the color of the block following the
addition. This should not be the case and will be fixed in the next
commit.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Reviewed-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>