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

Doc update.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Hotfix for a topic already in 'master'.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Suggested-by: Jeff King <redacted>
Signed-off-by: Rene Scharfe <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agosha1_file: let for_each_file_in_obj_subdir() handle subdir names
René Scharfe [Sat, 24 Jun 2017 12:12:30 +0000 (14:12 +0200)]
sha1_file: let for_each_file_in_obj_subdir() handle subdir names

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

Suggested-by: Jeff King <redacted>
Signed-off-by: Rene Scharfe <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agop4205: add perf test script for pretty log formats
René Scharfe [Sat, 24 Jun 2017 12:12:07 +0000 (14:12 +0200)]
p4205: add perf test script for pretty log formats

Add simple performance tests for expanded log format placeholders.

Suggested-by: Jeff King <redacted>
Signed-off-by: Rene Scharfe <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agowildmatch: remove unused wildopts parameter
Ævar Arnfjörð Bjarmason [Thu, 22 Jun 2017 21:38:08 +0000 (21:38 +0000)]
wildmatch: remove unused wildopts parameter

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

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

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

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

Signed-off-by: Brandon Williams <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agorepository: enable initialization of submodules
Brandon Williams [Thu, 22 Jun 2017 18:43:47 +0000 (11:43 -0700)]
repository: enable initialization of submodules

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

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

  1. The submodule is initialized and has a worktree.

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

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

Signed-off-by: Brandon Williams <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agosubmodule: convert is_submodule_initialized to work on a repository
Brandon Williams [Thu, 22 Jun 2017 18:43:46 +0000 (11:43 -0700)]
submodule: convert is_submodule_initialized to work on a repository

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

Signed-off-by: Brandon Williams <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agosubmodule: add repo_read_gitmodules
Brandon Williams [Thu, 22 Jun 2017 18:43:45 +0000 (11:43 -0700)]
submodule: add repo_read_gitmodules

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

Signed-off-by: Brandon Williams <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agosubmodule-config: store the_submodule_cache in the_repository
Brandon Williams [Thu, 22 Jun 2017 18:43:44 +0000 (11:43 -0700)]
submodule-config: store the_submodule_cache in the_repository

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

Signed-off-by: Brandon Williams <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agorepository: add index_state to struct repo
Brandon Williams [Thu, 22 Jun 2017 18:43:43 +0000 (11:43 -0700)]
repository: add index_state to struct repo

Signed-off-by: Brandon Williams <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agoconfig: read config from a repository object
Brandon Williams [Thu, 22 Jun 2017 18:43:42 +0000 (11:43 -0700)]
config: read config from a repository object

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

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

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

Signed-off-by: Brandon Williams <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agopath: add repo_worktree_path and strbuf_repo_worktree_path
Brandon Williams [Thu, 22 Jun 2017 18:43:41 +0000 (11:43 -0700)]
path: add repo_worktree_path and strbuf_repo_worktree_path

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

Signed-off-by: Brandon Williams <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agopath: add repo_git_path and strbuf_repo_git_path
Brandon Williams [Thu, 22 Jun 2017 18:43:40 +0000 (11:43 -0700)]
path: add repo_git_path and strbuf_repo_git_path

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

Signed-off-by: Brandon Williams <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agopath: worktree_git_path() should not use file relocation
Brandon Williams [Thu, 22 Jun 2017 18:43:39 +0000 (11:43 -0700)]
path: worktree_git_path() should not use file relocation

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

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

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

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

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

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

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

Signed-off-by: Brandon Williams <redacted>
Signed-off-by: Jonathan Nieder <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agopath: convert do_git_path to take a 'struct repository'
Brandon Williams [Thu, 22 Jun 2017 18:43:38 +0000 (11:43 -0700)]
path: convert do_git_path to take a 'struct repository'

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

Signed-off-by: Brandon Williams <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agopath: convert strbuf_git_common_path to take a 'struct repository'
Brandon Williams [Thu, 22 Jun 2017 18:43:37 +0000 (11:43 -0700)]
path: convert strbuf_git_common_path to take a 'struct repository'

Signed-off-by: Brandon Williams <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agopath: always pass in commondir to update_common_dir
Brandon Williams [Thu, 22 Jun 2017 18:43:36 +0000 (11:43 -0700)]
path: always pass in commondir to update_common_dir

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

Signed-off-by: Brandon Williams <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agopath: create path.h
Brandon Williams [Thu, 22 Jun 2017 18:43:35 +0000 (11:43 -0700)]
path: create path.h

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

Signed-off-by: Brandon Williams <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agoenvironment: store worktree in the_repository
Brandon Williams [Thu, 22 Jun 2017 18:43:34 +0000 (11:43 -0700)]
environment: store worktree in the_repository

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

Signed-off-by: Brandon Williams <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agoenvironment: place key repository state in the_repository
Brandon Williams [Thu, 22 Jun 2017 18:43:33 +0000 (11:43 -0700)]
environment: place key repository state in the_repository

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

Signed-off-by: Brandon Williams <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agorepository: introduce the repository object
Brandon Williams [Thu, 22 Jun 2017 18:43:32 +0000 (11:43 -0700)]
repository: introduce the repository object

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

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

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

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

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

Signed-off-by: Brandon Williams <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agoenvironment: remove namespace_len variable
Brandon Williams [Tue, 20 Jun 2017 19:19:34 +0000 (12:19 -0700)]
environment: remove namespace_len variable

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

Signed-off-by: Brandon Williams <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agosetup: add comment indicating a hack
Brandon Williams [Tue, 20 Jun 2017 19:19:33 +0000 (12:19 -0700)]
setup: add comment indicating a hack

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

Signed-off-by: Brandon Williams <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agosetup: don't perform lazy initialization of repository state
Brandon Williams [Tue, 20 Jun 2017 19:19:32 +0000 (12:19 -0700)]
setup: don't perform lazy initialization of repository state

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

and the submodule as:

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

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

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

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

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

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

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

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

and the submodule as:

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

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

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

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

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

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

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

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

This patch implements (3) only.

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

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

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

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

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

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

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

Signed-off-by: Brandon Williams <redacted>
Signed-off-by: Stefan Beller <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agobuiltin/fetch: parse recurse-submodules-default at default options parsing
Stefan Beller [Fri, 23 Jun 2017 19:13:01 +0000 (12:13 -0700)]
builtin/fetch: parse recurse-submodules-default at default options parsing

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

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

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

Signed-off-by: Stefan Beller <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agocommit_packed_refs(): remove call to `packed_refs_unlock()`
Michael Haggerty [Fri, 23 Jun 2017 07:01:45 +0000 (09:01 +0200)]
commit_packed_refs(): remove call to `packed_refs_unlock()`

Instead, change the callers of `commit_packed_refs()` to call
`packed_refs_unlock()`.

Signed-off-by: Michael Haggerty <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agoclear_packed_ref_cache(): don't protest if the lock is held
Michael Haggerty [Fri, 23 Jun 2017 07:01:44 +0000 (09:01 +0200)]
clear_packed_ref_cache(): don't protest if the lock is held

The existing callers already check that the lock isn't held just
before calling `clear_packed_ref_cache()`, and in the near future we
want to be able to call this function when the lock is held.

Signed-off-by: Michael Haggerty <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agopacked_refs_unlock(), packed_refs_is_locked(): new functions
Michael Haggerty [Fri, 23 Jun 2017 07:01:43 +0000 (09:01 +0200)]
packed_refs_unlock(), packed_refs_is_locked(): new functions

Add two new public functions, `packed_refs_unlock()` and
`packed_refs_is_locked()`, with which callers can manage and query the
`packed-refs` lock externally.

Call `packed_refs_unlock()` from `commit_packed_refs()` and
`rollback_packed_refs()`.

Signed-off-by: Michael Haggerty <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agopacked_refs_lock(): report errors via a `struct strbuf *err`
Michael Haggerty [Fri, 23 Jun 2017 07:01:42 +0000 (09:01 +0200)]
packed_refs_lock(): report errors via a `struct strbuf *err`

That way the callers don't have to come up with error messages
themselves.

Signed-off-by: Michael Haggerty <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agopacked_refs_lock(): function renamed from lock_packed_refs()
Michael Haggerty [Fri, 23 Jun 2017 07:01:41 +0000 (09:01 +0200)]
packed_refs_lock(): function renamed from lock_packed_refs()

Rename `lock_packed_refs()` to `packed_refs_lock()` for consistency
with how other methods are named. Also, it's about to get some
companions.

Signed-off-by: Michael Haggerty <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agocommit_packed_refs(): use a staging file separate from the lockfile
Michael Haggerty [Fri, 23 Jun 2017 07:01:40 +0000 (09:01 +0200)]
commit_packed_refs(): use a staging file separate from the lockfile

We will want to be able to hold the lockfile for `packed-refs` even
after we have activated the new values. So use a separate tempfile,
`packed-refs.new`, as a place to stage the new contents of the
`packed-refs` file. For now this is all done within
`commit_packed_refs()`, but that will change shortly.

Signed-off-by: Michael Haggerty <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agocommit_packed_refs(): report errors rather than dying
Michael Haggerty [Fri, 23 Jun 2017 07:01:39 +0000 (09:01 +0200)]
commit_packed_refs(): report errors rather than dying

Report errors via a `struct strbuf *err` rather than by calling
`die()`. To enable this goal, change `write_packed_entry()` to report
errors via a return value and `errno` rather than dying.

Signed-off-by: Michael Haggerty <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agopacked_ref_store: make class into a subclass of `ref_store`
Michael Haggerty [Fri, 23 Jun 2017 07:01:38 +0000 (09:01 +0200)]
packed_ref_store: make class into a subclass of `ref_store`

Add the infrastructure to make `packed_ref_store` implement
`ref_store`, at least formally (few of the methods are actually
implemented yet). Change the functions in its interface to take
`ref_store *` arguments. Change `files_ref_store` to store a pointer
to `ref_store *` and to call functions via the virtual `ref_store`
interface where possible. This also means that a few
`packed_ref_store` functions can become static.

This is a work in progress. Some more `ref_store` methods will soon be
implemented (e.g., those having to do with reference transactions).
But some of them will never be implemented (e.g., those having to do
with symrefs or reflogs).

Signed-off-by: Michael Haggerty <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agopacked-backend: new module for handling packed references
Michael Haggerty [Fri, 23 Jun 2017 07:01:37 +0000 (09:01 +0200)]
packed-backend: new module for handling packed references

Now that the interface between `files_ref_store` and
`packed_ref_store` is relatively narrow, move the latter into a new
module, "refs/packed-backend.h" and "refs/packed-backend.c". It still
doesn't quite implement the `ref_store` interface, but it will soon.

This commit moves code around and adjusts its visibility, but doesn't
change anything.

Signed-off-by: Michael Haggerty <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agopacked_read_raw_ref(): new function, replacing `resolve_packed_ref()`
Michael Haggerty [Fri, 23 Jun 2017 07:01:36 +0000 (09:01 +0200)]
packed_read_raw_ref(): new function, replacing `resolve_packed_ref()`

Add a new function, `packed_read_raw_ref()`, which is nearly a
`read_raw_ref_fn`. Use it in place of `resolve_packed_ref()`.

Signed-off-by: Michael Haggerty <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agopacked_ref_store: support iteration
Michael Haggerty [Fri, 23 Jun 2017 07:01:35 +0000 (09:01 +0200)]
packed_ref_store: support iteration

Add the infrastructure to iterate over a `packed_ref_store`. It's a
lot of boilerplate, but it's all part of a campaign to make
`packed_ref_store` implement `ref_store`. In the future, this iterator
will work much differently.

Signed-off-by: Michael Haggerty <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agopacked_peel_ref(): new function, extracted from `files_peel_ref()`
Michael Haggerty [Fri, 23 Jun 2017 07:01:34 +0000 (09:01 +0200)]
packed_peel_ref(): new function, extracted from `files_peel_ref()`

This will later become a method of `packed_ref_store`.

Signed-off-by: Michael Haggerty <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agorepack_without_refs(): take a `packed_ref_store *` parameter
Michael Haggerty [Fri, 23 Jun 2017 07:01:33 +0000 (09:01 +0200)]
repack_without_refs(): take a `packed_ref_store *` parameter

It only cares about the packed-refs part of the reference store.

Signed-off-by: Michael Haggerty <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agoget_packed_ref(): take a `packed_ref_store *` parameter
Michael Haggerty [Fri, 23 Jun 2017 07:01:32 +0000 (09:01 +0200)]
get_packed_ref(): take a `packed_ref_store *` parameter

It only cares about the packed-refs part of the reference store.

Signed-off-by: Michael Haggerty <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agorollback_packed_refs(): take a `packed_ref_store *` parameter
Michael Haggerty [Fri, 23 Jun 2017 07:01:31 +0000 (09:01 +0200)]
rollback_packed_refs(): take a `packed_ref_store *` parameter

It only cares about the packed-refs part of the reference store.

Signed-off-by: Michael Haggerty <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agocommit_packed_refs(): take a `packed_ref_store *` parameter
Michael Haggerty [Fri, 23 Jun 2017 07:01:30 +0000 (09:01 +0200)]
commit_packed_refs(): take a `packed_ref_store *` parameter

It only cares about the packed-refs part of the reference store.

Signed-off-by: Michael Haggerty <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agolock_packed_refs(): take a `packed_ref_store *` parameter
Michael Haggerty [Fri, 23 Jun 2017 07:01:29 +0000 (09:01 +0200)]
lock_packed_refs(): take a `packed_ref_store *` parameter

It only cares about the packed-refs part of the reference store.

Signed-off-by: Michael Haggerty <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agoadd_packed_ref(): take a `packed_ref_store *` parameter
Michael Haggerty [Fri, 23 Jun 2017 07:01:28 +0000 (09:01 +0200)]
add_packed_ref(): take a `packed_ref_store *` parameter

It only cares about the packed-refs part of the reference store.

Signed-off-by: Michael Haggerty <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agoget_packed_refs(): take a `packed_ref_store *` parameter
Michael Haggerty [Fri, 23 Jun 2017 07:01:27 +0000 (09:01 +0200)]
get_packed_refs(): take a `packed_ref_store *` parameter

It only cares about the packed-refs part of the reference store.

Signed-off-by: Michael Haggerty <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agoget_packed_ref_cache(): take a `packed_ref_store *` parameter
Michael Haggerty [Fri, 23 Jun 2017 07:01:26 +0000 (09:01 +0200)]
get_packed_ref_cache(): take a `packed_ref_store *` parameter

It only cares about the packed-refs part of the reference store.

Signed-off-by: Michael Haggerty <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agovalidate_packed_ref_cache(): take a `packed_ref_store *` parameter
Michael Haggerty [Fri, 23 Jun 2017 07:01:25 +0000 (09:01 +0200)]
validate_packed_ref_cache(): take a `packed_ref_store *` parameter

It only cares about the packed-refs part of the reference store.

Signed-off-by: Michael Haggerty <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agoclear_packed_ref_cache(): take a `packed_ref_store *` parameter
Michael Haggerty [Fri, 23 Jun 2017 07:01:24 +0000 (09:01 +0200)]
clear_packed_ref_cache(): take a `packed_ref_store *` parameter

It only cares about the packed-refs part of the reference store.

Signed-off-by: Michael Haggerty <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agopacked_ref_store: move `packed_refs_lock` member here
Michael Haggerty [Fri, 23 Jun 2017 07:01:23 +0000 (09:01 +0200)]
packed_ref_store: move `packed_refs_lock` member here

Move the `packed_refs_lock` member from `files_ref_store` to
`packed_ref_store`, and rename it to `lock` since it's now more
obvious what it is locking.

Signed-off-by: Michael Haggerty <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agopacked_ref_store: move `packed_refs_path` here
Michael Haggerty [Fri, 23 Jun 2017 07:01:22 +0000 (09:01 +0200)]
packed_ref_store: move `packed_refs_path` here

Move `packed_refs_path` from `files_ref_store` to `packed_ref_store`,
and rename it to `path` since its meaning is clear from its new
context.

Inline `files_packed_refs_path()`.

Signed-off-by: Michael Haggerty <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agopacked_ref_store: new struct
Michael Haggerty [Fri, 23 Jun 2017 07:01:21 +0000 (09:01 +0200)]
packed_ref_store: new struct

Start extracting the packed-refs-related data structures into a new
class, `packed_ref_store`. It doesn't yet implement `ref_store`, but
it will.

Signed-off-by: Michael Haggerty <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agoadd_packed_ref(): teach function to overwrite existing refs
Michael Haggerty [Fri, 23 Jun 2017 07:01:20 +0000 (09:01 +0200)]
add_packed_ref(): teach function to overwrite existing refs

Teach `add_packed_ref()` to overwrite an existing entry if one already
exists for the specified `refname`. This means that we can call it
from `files_pack_refs()`, thereby reducing the amount that the latter
function needs to know about the internals of packed-reference
handling.

Signed-off-by: Michael Haggerty <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agot1408: add a test of stale packed refs covered by loose refs
Junio C Hamano [Fri, 23 Jun 2017 07:01:19 +0000 (09:01 +0200)]
t1408: add a test of stale packed refs covered by loose refs

It is OK for the packed-refs file to contain old reference definitions
that might even refer to objects that have since been
garbage-collected, as long as there is a corresponding loose reference
definition that overrides it. Add a test that such references don't
cause problems.

Signed-off-by: Junio C Hamano <redacted>
Signed-off-by: Michael Haggerty <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agopathspec: die on empty strings as pathspec
Emily Xie [Wed, 7 Jun 2017 03:33:08 +0000 (23:33 -0400)]
pathspec: die on empty strings as pathspec

An empty string as a pathspec element matches all paths.  A buggy
script, however, could accidentally assign an empty string to a
variable that then gets passed to a Git command invocation, e.g.:

  path=... compute a path to be removed in $path ...
        git rm -r "$path"

which would unintentionally remove all paths in the current
directory.

The fix for this issue comprises of two steps. Step 1, which warns
that empty strings as pathspecs will become invalid, has already
been implemented in commit d426430 ("pathspec: warn on empty strings
as pathspec", 2016-06-22).

This patch is step 2. It removes the warning and throws an error
instead.

Signed-off-by: Emily Xie <redacted>
Reported-by: David Turner <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agot0027: do not use an empty string as a pathspec element
Junio C Hamano [Fri, 23 Jun 2017 18:04:14 +0000 (11:04 -0700)]
t0027: do not use an empty string as a pathspec element

In an upcoming update, we will finally make an empty string illegal
as an element in a pathspec; it traditionally meant the same as ".",
i.e. include everything, so update this test that passes "" to pass
a dot instead.

At this point in the test sequence, there is no modified path that
need to be further added before committing; the working tree is
empty except for .gitattributes which was just added to the index.
So we could instead pass no pathspec, but this is a conversion more
faithful to the original.

Signed-off-by: Junio C Hamano <redacted>
8 years agot3420: fix under GETTEXT_POISON build
Junio C Hamano [Fri, 23 Jun 2017 18:56:25 +0000 (11:56 -0700)]
t3420: fix under GETTEXT_POISON build

Newly added tests to t3420 in this series prepare expected
human-readable output from "git rebase -i" and then compare the
actual output with it.  As the output from the command is designed
to go through i18n/l10n, we need to use test_i18ncmp to tell
GETTEXT_POISON build that it is OK the output does not match.

Signed-off-by: Junio C Hamano <redacted>
8 years agosubmodules: overhaul documentation
Stefan Beller [Thu, 22 Jun 2017 21:01:49 +0000 (14:01 -0700)]
submodules: overhaul documentation

This patch aims to detangle (a) the usage of `git-submodule`
from (b) the concept of submodules and (c) how the actual
implementation looks like, such as where they are configured
and (d) what the best practices are.

To do so, move the conceptual parts of the 'git-submodule'
man page to a new man page gitsubmodules(7). This new page
is just like gitmodules(5), gitattributes(5), gitcredentials(7),
gitnamespaces(7), gittutorial(7), which introduce a concept
rather than explaining a specific command.

Signed-off-by: Stefan Beller <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agoTenth batch for 2.14
Junio C Hamano [Thu, 22 Jun 2017 21:18:02 +0000 (14:18 -0700)]
Tenth batch for 2.14

Signed-off-by: Junio C Hamano <redacted>
8 years agoMerge branch 'rs/strbuf-addftime-zZ'
Junio C Hamano [Thu, 22 Jun 2017 21:15:25 +0000 (14:15 -0700)]
Merge branch 'rs/strbuf-addftime-zZ'

As there is no portable way to pass timezone information to
strftime, some output format from "git log" and friends are
impossible to produce.  Teach our own strbuf_addftime to replace %z
and %Z with caller-supplied values to help working around this.

* rs/strbuf-addftime-zZ:
  date: use localtime() for "-local" time formats
  t0006: check --date=format zone offsets
  strbuf: let strbuf_addftime handle %z and %Z itself

8 years agoMerge branch 'sd/t3200-branch-m-test'
Junio C Hamano [Thu, 22 Jun 2017 21:15:25 +0000 (14:15 -0700)]
Merge branch 'sd/t3200-branch-m-test'

New test.

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

8 years agoMerge branch 'ps/stash-push-pathspec-fix'
Junio C Hamano [Thu, 22 Jun 2017 21:15:24 +0000 (14:15 -0700)]
Merge branch 'ps/stash-push-pathspec-fix'

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

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

8 years agoMerge branch 'ls/github'
Junio C Hamano [Thu, 22 Jun 2017 21:15:24 +0000 (14:15 -0700)]
Merge branch 'ls/github'

Help contributors that visit us at GitHub.

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

8 years agoMerge branch 'sg/revision-parser-skip-prefix'
Junio C Hamano [Thu, 22 Jun 2017 21:15:23 +0000 (14:15 -0700)]
Merge branch 'sg/revision-parser-skip-prefix'

Code clean-up.

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

8 years agoMerge branch 'mh/fast-import-raise-default-depth'
Junio C Hamano [Thu, 22 Jun 2017 21:15:23 +0000 (14:15 -0700)]
Merge branch 'mh/fast-import-raise-default-depth'

"fast-import" uses a default pack chain depth that is consistent
with other parts of the system.

* mh/fast-import-raise-default-depth:
  fast-import: increase the default pack depth to 50

8 years agoMerge branch 'km/test-mailinfo-b-failure'
Junio C Hamano [Thu, 22 Jun 2017 21:15:22 +0000 (14:15 -0700)]
Merge branch 'km/test-mailinfo-b-failure'

New tests.

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

8 years agoMerge branch 'ah/filter-branch-setup'
Junio C Hamano [Thu, 22 Jun 2017 21:15:21 +0000 (14:15 -0700)]
Merge branch 'ah/filter-branch-setup'

"filter-branch" learned a pseudo filter "--setup" that can be used
to define a common function/variable that can be used by other
filters.

* ah/filter-branch-setup:
  filter-branch: add [--] to usage
  filter-branch: add `--setup` step

8 years agoMerge branch 'pc/dir-count-slashes'
Junio C Hamano [Thu, 22 Jun 2017 21:15:21 +0000 (14:15 -0700)]
Merge branch 'pc/dir-count-slashes'

Three instances of the same helper function have been consolidated
to one.

* pc/dir-count-slashes:
  dir: create function count_slashes()

8 years agoMerge branch 'sb/t4005-modernize'
Junio C Hamano [Thu, 22 Jun 2017 21:15:21 +0000 (14:15 -0700)]
Merge branch 'sb/t4005-modernize'

Test clean-up.

* sb/t4005-modernize:
  t4005: modernize style and drop hard coded sha1

8 years agoMerge branch 'nd/fopen-errors'
Junio C Hamano [Thu, 22 Jun 2017 21:15:20 +0000 (14:15 -0700)]
Merge branch 'nd/fopen-errors'

Hotfix for a topic that is already in 'master'.

* nd/fopen-errors:
  configure.ac: loosen FREAD_READS_DIRECTORIES test program

8 years agoDocumentation/git-submodule: cleanup "add" section
Kaartic Sivaraam [Thu, 22 Jun 2017 02:51:42 +0000 (02:51 +0000)]
Documentation/git-submodule: cleanup "add" section

The "add" section for 'git-submodule' is redundant in its
description and the short synopsis line. Fix it.

Remove the redundant mentioning of the 'repository' argument
being mandatory.

The text is hard to read because of back-references, so remove
those.

Replace the word "humanish" by "canonical" as that conveys better
what we do to guess the path.

While at it, quote all occurrences of '.gitmodules' as that is an
important file in the submodule context, also link to it on its
first mention.

Helped-by: Stefan Beller <redacted>
Signed-off-by: Kaartic Sivaraam <redacted>
Reviewed-by: Stefan Beller <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agosha1_name: cache readdir(3) results in find_short_object_filename()
René Scharfe [Thu, 22 Jun 2017 18:19:48 +0000 (20:19 +0200)]
sha1_name: cache readdir(3) results in find_short_object_filename()

Read each loose object subdirectory at most once when looking for unique
abbreviated hashes.  This speeds up commands like "git log --pretty=%h"
considerably, which previously caused one readdir(3) call for each
candidate, even for subdirectories that were visited before.

The new cache is kept until the program ends and never invalidated.  The
same is already true for pack indexes.  The inherent racy nature of
finding unique short hashes makes it still fit for this purpose -- a
conflicting new object may be added at any time.  Tasks with higher
consistency requirements should not use it, though.

The cached object names are stored in an oid_array, which is quite
compact.  The bitmap for remembering which subdir was already read is
stored as a char array, with one char per directory -- that's not quite
as compact, but really simple and incurs only an overhead equivalent to
11 hashes after all.

Suggested-by: Jeff King <redacted>
Helped-by: Jeff King <redacted>
Signed-off-by: Rene Scharfe <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agostatus: contextually notify user about an initial commit
Kaartic Sivaraam [Wed, 21 Jun 2017 18:16:14 +0000 (23:46 +0530)]
status: contextually notify user about an initial commit

The existing message, "Initial commit", makes sense for the commit template
notifying users that it's their initial commit, but is confusing when
merely checking the status of a fresh repository (or orphan branch)
without having any commits yet.

Change the output of "status" to say "No commits yet" when "git
status" is run on a fresh repo (or orphan branch), while retaining the
current "Initial commit" message displayed in the template that's
displayed in the editor when the initial commit is being authored.

Correspondingly change the output of "short status" to "No commits yet
on " when "git status -sb" is run on a fresh repo (or orphan branch).

A few alternatives considered were,

 * Waiting for initial commit
 * Your current branch does not have any commits
 * Current branch waiting for initial commit

The most succint one among the alternatives was chosen.

[with help on tests from Ævar]

Helped-by: Junio C Hamano <redacted>
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
Signed-off-by: Kaartic Sivaraam <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agosha1_file: refactor read_object
Jonathan Tan [Thu, 22 Jun 2017 00:40:21 +0000 (17:40 -0700)]
sha1_file: refactor read_object

read_object() and sha1_object_info_extended() both implement mechanisms
such as object replacement, retrying the packed store after failing to
find the object in the packed store then the loose store, and being able
to mark a packed object as bad and then retrying the whole process.
Consolidating these mechanisms would be a great help to maintainability.

Therefore, consolidate them by extending sha1_object_info_extended() to
support the functionality needed, and then modifying read_object() to
use sha1_object_info_extended().

Signed-off-by: Jonathan Tan <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agosha1_file: move delta base cache code up
Jonathan Tan [Thu, 22 Jun 2017 00:40:20 +0000 (17:40 -0700)]
sha1_file: move delta base cache code up

In a subsequent patch, packed_object_info() will be modified to use the
delta base cache, so move the relevant code to before
packed_object_info().

Signed-off-by: Jonathan Tan <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agosha1_file: rename LOOKUP_REPLACE_OBJECT
Jonathan Tan [Thu, 22 Jun 2017 00:40:19 +0000 (17:40 -0700)]
sha1_file: rename LOOKUP_REPLACE_OBJECT

The LOOKUP_REPLACE_OBJECT flag controls whether the
lookup_replace_object() function is invoked by
sha1_object_info_extended(), read_sha1_file_extended(), and
lookup_replace_object_extended(), but it is not immediately clear which
functions accept that flag.

Therefore restrict this flag to only sha1_object_info_extended(),
renaming it appropriately to OBJECT_INFO_LOOKUP_REPLACE and adding some
documentation. Update read_sha1_file_extended() to have a boolean
parameter instead, and delete lookup_replace_object_extended().

parse_sha1_header() also passes this flag to
parse_sha1_header_extended() since commit 46f0344 ("sha1_file: support
reading from a loose object of unknown type", 2015-05-03), but that has
had no effect since that commit. Therefore this patch also removes this
flag from that invocation.

Signed-off-by: Jonathan Tan <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agosha1_file: rename LOOKUP_UNKNOWN_OBJECT
Jonathan Tan [Thu, 22 Jun 2017 00:40:18 +0000 (17:40 -0700)]
sha1_file: rename LOOKUP_UNKNOWN_OBJECT

The LOOKUP_UNKNOWN_OBJECT flag was introduced in commit 46f0344
("sha1_file: support reading from a loose object of unknown type",
2015-05-03) in order to support a feature in cat-file subsequently
introduced in commit 39e4ae3 ("cat-file: teach cat-file a
'--allow-unknown-type' option", 2015-05-03). Despite its name and
location in cache.h, this flag is used neither in
read_sha1_file_extended() nor in any of the lookup functions, but used
only in sha1_object_info_extended().

Therefore rename this flag to OBJECT_INFO_ALLOW_UNKNOWN_TYPE, taking the
name of the cat-file flag that invokes this feature, and move it closer
to the declaration of sha1_object_info_extended(). Also add
documentation for this flag.

OBJECT_INFO_ALLOW_UNKNOWN_TYPE is defined to 2, not 1, to avoid
conflicting with LOOKUP_REPLACE_OBJECT. Avoidance of this conflict is
necessary because sha1_object_info_extended() supports both flags.

Signed-off-by: Jonathan Tan <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agodie(): stop hiding errors due to overzealous recursion guard
Ævar Arnfjörð Bjarmason [Wed, 21 Jun 2017 20:47:42 +0000 (20:47 +0000)]
die(): stop hiding errors due to overzealous recursion guard

Change the recursion limit for the default die routine from a *very*
low 1 to 1024. This ensures that infinite recursions are broken, but
doesn't lose the meaningful error messages under threaded execution
where threads concurrently start to die.

The intent of the existing code, as explained in commit
cd163d4b4e ("usage.c: detect recursion in die routines and bail out
immediately", 2012-11-14), is to break infinite recursion in cases
where the die routine itself calls die(), and would thus infinitely
recurse.

However, doing that very aggressively by immediately printing out
"recursion detected in die handler" if we've already called die() once
means that threaded invocations of git can end up only printing out
the "recursion detected" error, while hiding the meaningful error.

An example of this is running a threaded grep which dies on execution
against pretty much any repo, git.git will do:

    git grep -P --threads=8 '(*LIMIT_MATCH=1)-?-?-?---$'

With the current version of git this will print some combination of
multiple PCRE failures that caused the abort and multiple "recursion
detected", some invocations will print out multiple "recursion
detected" errors with no PCRE error at all!

Before this change, running the above grep command 1000 times against
git.git[1] and taking the top 20 results will on my system yield the
following distribution of actual errors ("E") and recursion
errors ("R"):

    322 E R
    306 E
    116 E R R
     65 R R
     54 R E
     49 E E
     44 R
     15 E R R R
      9 R R R
      7 R E R
      5 R R E
      3 E R R R R
      2 E E R
      1 R R R R
      1 R R R E
      1 R E R R

The exact results are obviously random and system-dependent, but this
shows the race condition in this code. Some small part of the time
we're about to print out the actual error ("E") but another thread's
recursion error beats us to it, and sometimes we print out nothing but
the recursion error.

With this change we get, now with "W" to mean the new warning being
emitted indicating that we've called die() many times:

    502 E
    160 E W E
    120 E E
     53 E W
     35 E W E E
     34 W E E
     29 W E E E
     16 E E W
     16 E E E
     11 W E E E E
      7 E E W E
      4 W E
      3 W W E E
      2 E W E E E
      1 W W E
      1 W E W E
      1 E W W E E E
      1 E W W E E
      1 E W W E
      1 E W E E W

Which still sucks a bit, due to a still present race-condition in this
code we're sometimes going to print out several errors still, or
several warnings, or two duplicate errors without the warning.

But we will never have a case where we completely hide the actual
error as we do now.

Now, git-grep could make use of the pluggable error facility added in
commit c19a490e37 ("usage: allow pluggable die-recursion checks",
2013-04-16). There's other threaded code that calls set_die_routine()
or set_die_is_recursing_routine().

But this is about fixing the general die() behavior with threading
when we don't have such a custom routine yet. Right now the common
case is not an infinite recursion in the handler, but us losing error
messages by default because we're overly paranoid about our recursion
check.

So let's just set the recursion limit to a number higher than the
number of threads we're ever likely to spawn. Now we won't lose
errors, and if we have a recursing die handler we'll still die within
microseconds.

There are race conditions in this code itself, in particular the
"dying" variable is not thread mutexed, so we e.g. won't be dying at
exactly 1024, or for that matter even be able to accurately test
"dying == 2", see the cases where we print out more than one "W"
above.

But that doesn't really matter, for the recursion guard we just need
to die "soon", not at exactly 1024 calls, and for printing the correct
error and only one warning most of the time in the face of threaded
death this is good enough and a net improvement on the current code.

1. for i in {1..1000}; do git grep -P --threads=8 '(*LIMIT_MATCH=1)-?-?-?---$' 2>&1|perl -pe 's/^fatal: r.*/R/; s/^fatal: p.*/E/; s/^warning.*/W/' | tr '\n' ' '; echo; done | sort | uniq -c | sort -nr | head -n 20

Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agoadd--interactive: quote commentChar regex
Jeff King [Wed, 21 Jun 2017 19:28:59 +0000 (15:28 -0400)]
add--interactive: quote commentChar regex

Since c9d961647 (i18n: add--interactive: mark
edit_hunk_manually message for translation, 2016-12-14),
when the user asks to edit a hunk manually, we respect
core.commentChar in generating the edit instructions.
However, when we then strip out comment lines, we use a
simple regex like:

  /^$commentChar/

If your chosen comment character is a regex metacharacter,
then that will behave in a confusing manner ("$", for
instance, would only eliminate blank lines, not actual
comment lines).

We can fix that by telling perl not to respect
metacharacters.

Reported-by: Christian Rösch <redacted>
Signed-off-by: Jeff King <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agoadd--interactive: handle EOF in prompt_yesno
Jeff King [Wed, 21 Jun 2017 19:26:36 +0000 (15:26 -0400)]
add--interactive: handle EOF in prompt_yesno

The prompt_yesno function loops indefinitely waiting for a
"y" or "n" response. But it doesn't handle EOF, meaning
that we can end up in an infinite loop of reading EOF from
stdin. One way to simulate that is with:

  echo e | GIT_EDITOR='echo corrupt >' git add -p

Let's break out of the loop and propagate the undef to the
caller. Without modifying the callers that effectively turns
it into a "no" response. This is reasonable for both of the
current callers, and it leaves room for any future caller to
check for undef explicitly.

Signed-off-by: Jeff King <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agoauto-correct: tweak phrasing
Marc Branchaud [Wed, 21 Jun 2017 13:57:38 +0000 (09:57 -0400)]
auto-correct: tweak phrasing

When help.autoCorrect is enabled, an invalid git command prints a
warning and a continuation message, which differs depending on
whether or not the value of help.autoCorrect is positive or
negative.

With help.autoCorrect = 15:

   WARNING: You called a Git command named 'lgo', which does not exist.
   Continuing under the assumption that you meant 'log'
   in 1.5 seconds automatically...

With help.autoCorrect < 0:

   WARNING: You called a Git command named 'lgo', which does not exist.
   Continuing under the assumption that you meant 'log'

The continuation message's phrasing is awkward.  This commit cleans it up.
As a bonus, we now use full-sentence strings which make translation easier.

With help.autoCorrect = 15:

   WARNING: You called a Git command named 'lgo', which does not exist.
   Continuing in 1.5 seconds, assuming that you meant 'log'.

With help.autoCorrect < 0:

   WARNING: You called a Git command named 'lgo', which does not exist.
   Continuing under the assumption that you meant 'log'.

Signed-off-by: Marc Branchaud <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agodocs: update 64-bit core.packedGitLimit default
Jeff King [Wed, 21 Jun 2017 13:51:30 +0000 (09:51 -0400)]
docs: update 64-bit core.packedGitLimit default

We bumped the default in be4ca2905 (Increase
core.packedGitLimit, 2017-04-20) but never adjusted the
documentation to match.

Signed-off-by: Jeff King <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agot7508: fix a broken indentation
Kaartic Sivaraam [Wed, 21 Jun 2017 12:31:45 +0000 (18:01 +0530)]
t7508: fix a broken indentation

Change the indentation from "\t " to "\t". This indenting issue was
introduced when the test was added in commit 1d2f393ac9
("status/commit: show staged submodules regardless of ignore
config", 2014-04-05).

Helped-by: Ævar Arnfjörð Bjarmason <redacted>
Signed-off-by: Kaartic Sivaraam <redacted>
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agogrep: fix erroneously copy/pasted variable in check/assert pattern
Ævar Arnfjörð Bjarmason [Mon, 19 Jun 2017 22:01:48 +0000 (22:01 +0000)]
grep: fix erroneously copy/pasted variable in check/assert pattern

Fix an erroneously copy/pasted check for the pcre2_jit_stack variable
to check pcre2_match_context instead. The former was already checked
in the preceding "if" statement.

This is a trivial and obvious error introduced in my commit
94da9193a6 ("grep: add support for PCRE v2", 2017-06-01).

In practice if pcre2_match_context_create() returned NULL we were
likely in a situation where malloc() was returning NULL, and were thus
screwed anyway, but if only the pcre2_match_context_create() call
returned NULL (through some transitory bug) PCRE v2 would just
allocate and supply its own context object when matching, and we'd run
normally at the trivial expense of not getting a slight speedup by
sharing the context object between successive matches.

Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
Signed-off-by: Junio C Hamano <redacted>
8 years agoNinth batch for 2.14
Junio C Hamano [Mon, 19 Jun 2017 19:41:12 +0000 (12:41 -0700)]
Ninth batch for 2.14

Signed-off-by: Junio C Hamano <redacted>
8 years agoMerge branch 'jk/consistent-h'
Junio C Hamano [Mon, 19 Jun 2017 19:38:45 +0000 (12:38 -0700)]
Merge branch 'jk/consistent-h'

"git $cmd -h" for builtin commands calls the implementation of the
command (i.e. cmd_$cmd() function) without doing any repository
set-up, and the commands that expect RUN_SETUP is done by the Git
potty needs to be prepared to show the help text without barfing.

* jk/consistent-h:
  t0012: test "-h" with builtins
  git: add hidden --list-builtins option
  version: convert to parse-options
  diff- and log- family: handle "git cmd -h" early
  submodule--helper: show usage for "-h"
  remote-{ext,fd}: print usage message on invalid arguments
  upload-archive: handle "-h" option early
  credential: handle invalid arguments earlier

8 years agoMerge branch 'ab/perf-remove-index-lock'
Junio C Hamano [Mon, 19 Jun 2017 19:38:44 +0000 (12:38 -0700)]
Merge branch 'ab/perf-remove-index-lock'

When an existing repository is used for t/perf testing, we first
create bit-for-bit copy of it, which may grab a transient state of
the repository and freeze it into the repository used for testing,
which then may cause Git operations to fail.  Single out "the index
being locked" case and forcibly drop the lock from the copy.

* ab/perf-remove-index-lock:
  perf: work around the tested repo having an index.lock

8 years agoMerge branch 'bw/object-id'
Junio C Hamano [Mon, 19 Jun 2017 19:38:44 +0000 (12:38 -0700)]
Merge branch 'bw/object-id'

Conversion from uchar[20] to struct object_id continues.

* bw/object-id: (33 commits)
  diff: rename diff_fill_sha1_info to diff_fill_oid_info
  diffcore-rename: use is_empty_blob_oid
  tree-diff: convert path_appendnew to object_id
  tree-diff: convert diff_tree_paths to struct object_id
  tree-diff: convert try_to_follow_renames to struct object_id
  builtin/diff-tree: cleanup references to sha1
  diff-tree: convert diff_tree_sha1 to struct object_id
  notes-merge: convert write_note_to_worktree to struct object_id
  notes-merge: convert verify_notes_filepair to struct object_id
  notes-merge: convert find_notes_merge_pair_ps to struct object_id
  notes-merge: convert merge_from_diffs to struct object_id
  notes-merge: convert notes_merge* to struct object_id
  tree-diff: convert diff_root_tree_sha1 to struct object_id
  combine-diff: convert find_paths_* to struct object_id
  combine-diff: convert diff_tree_combined to struct object_id
  diff: convert diff_flush_patch_id to struct object_id
  patch-ids: convert to struct object_id
  diff: finish conversion for prepare_temp_file to struct object_id
  diff: convert reuse_worktree_file to struct object_id
  diff: convert fill_filespec to struct object_id
  ...

git clone https://git.99rst.org/PROJECT