git-submodule.sh: 'checkout' is a valid update mode

'checkout' is documented as one of the valid values for the
'submodule.<name>.update' variable, and in a repository with the
variable set to 'checkout', "git submodule update" command does
update using the 'checkout' mode.

However, it has been an accident that the implementation works this
way; any unknown value would trigger the same codepath and update
using the 'checkout' mode.

Explicitly list 'checkout' as one of the known update modes, and
error out when an unknown update mode is used.

Teach the codepath that initializes the configuration variable from
an in-tree .gitmodules that 'checkout' is one of the valid values.
The code since ac1fbbda (submodule: do not copy unknown update mode
from .gitmodules, 2013-12-02) used to treat the value 'checkout' as
unknown and mapped it to 'none', which made little sense.  With this
change, 'checkout' specified in .gitmodules will stay to be 'checkout'.

Signed-off-by: Francesco Pretto <ceztko@gmail.com>
Signed-off-by: Signed-off-by: Junio C Hamano <gitster@pobox.com>
pager: set LV=-c alongside LESS=FRSX

On systems with lv configured as the preferred pager (i.e.,
DEFAULT_PAGER=lv at build time, or PAGER=lv exported in the
environment) git commands that use color show control codes instead of
color in the pager:

	$ git diff
	^[[1mdiff --git a/.mailfilter b/.mailfilter^[[m
	^[[1mindex aa4f0b2..17e113e 100644^[[m
	^[[1m--- a/.mailfilter^[[m
	^[[1m+++ b/.mailfilter^[[m
	^[[36m@@ -1,11 +1,58 @@^[[m

"less" avoids this problem because git uses the LESS environment
variable to pass the -R option ('output ANSI color escapes in raw
form') by default.  Use the LV environment variable to pass 'lv' the
-c option ('allow ANSI escape sequences for text decoration / color')
to fix it for lv, too.

Noticed when the default value for color.ui flipped to 'auto' in
v1.8.4-rc0~36^2~1 (2013-06-10).

Reported-by: Olaf Meeuwissen <olaf.meeuwissen@avasys.jp>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sha1_name: don't resolve refs when core.warnambiguousrefs is false

When seeing a full 40-hex object name, get_sha1_basic()
unconditionally checks if the string can also be interpreted as a
refname, but the result will not be used unless warn_ambiguous_refs
is in effect.

Omitting this unnecessary ref resolution provides a substantial
performance improvement, especially when passing many hashes to a
command (like "git rev-list --stdin") and core.warnambiguousrefs is
set to false.  The check incurs 6 stat()s for every hash supplied,
which can be costly over NFS.

Signed-off-by: Brodie Rao <brodie@sf.io>
Acked-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
completion: complete format.coverLetter

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
stash: handle specifying stashes with $IFS

When trying to pop/apply a stash specified with an argument
containing IFS whitespace, git-stash will throw an error:

    $ git stash pop 'stash@{two hours ago}'
    Too many revisions specified: stash@{two hours ago}

This happens because word splitting is used to count non-option
arguments. Make use of rev-parse's --sq option to quote the arguments
for us to ensure a correct count. Add quotes where necessary.

Also add a test that verifies correct behaviour.

Helped-by: Thomas Rast <tr@thomasrast.ch>
Signed-off-by: Øystein Walle <oystwa@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
submodule: respect requested branch on all clones

The previous code only checked out the requested branch in cmd_add
but not in cmd_update; this left the user on a detached HEAD after
an update initially cloned, and subsequent updates using rebase or
merge mode would have kept the HEAD detached, unless the user moved
to the desired branch himself.

Move the branch-checkout logic into module_clone, where it can be
shared by cmd_add and cmd_update.  Also update the initial checkout
command to reset to the specified commit, instead of checking out
the specified commit in a detached HEAD state, in order to preserve
branches setup during module_clone.  This way, unless the user
explicitly asks to work on a detached HEAD, subsequent updates all
happen on the specified branch, which matches the end-user
expectation much better.

Signed-off-by: W. Trevor King <wking@tremily.us>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
DONTMERGE: RFC will be rerolled with tests ($gmane/239967)
cat-file: refactor error handling of batch_objects

This just pulls the return value for the function out of the
inner loop, so we can break out of the loop rather than do
an early return. This will make it easier to put any cleanup
for the function in one place.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
cat-file: fix a minor memory leak in batch_objects

We should always have been freeing our strbuf, but doing so
consistently was annoying until the refactoring in the
previous patch.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
cat-file: restore ambiguity warning flag in batch_objects

Since commit 25fba78, we turn off the object/refname
ambiguity warning using a global flag. However, we never
restore it. This doesn't really matter in the current code,
since the program generally exits immediately after the
function is done, but it's good code hygeine to clean up
after ourselves.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
revision: turn off object/refname ambiguity check for --stdin

We currently check that any 40-hex object name we receive is
not also a refname, and output a warning if this is the
case.  When "rev-list --stdin" is used to receive object
names, we may receive a large number of inputs, and the cost
of checking each name as a ref is relatively high.

Commit 25fba78d already dropped this warning for "cat-file
--batch-check". The same reasoning applies for "rev-list
--stdin". Let's disable the check in that instance.

Here are before and after numbers:

  $ git rev-list --all >commits

  [before]
  $ best-of-five -i commits ./git rev-list --stdin --no-walk --pretty=raw

  real    0m0.675s
  user    0m0.552s
  sys     0m0.120s

  [after]
  $ best-of-five -i commits ./git rev-list --stdin --no-walk --pretty=raw

  real    0m0.415s
  user    0m0.400s
  sys     0m0.012s

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
mv: better document side effects when moving a submodule

The "Submodules" section of the "git mv" documentation mentions what will
happen when a submodule with a gitfile gets moved with newer git. But it
doesn't talk about what happens when the user changes between commits
before and after the move, which does not update the work tree like using
the mv command did the first time.

Explain what happens and what the user has to do manually to fix that in
the new BUGS section. Also document this behavior in a new test.

Reported-by: George Papanikolaou <g3orge.app@gmail.com>
Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
rm: better document side effects when removing a submodule

The "Submodules" section of the "git rm" documentation mentions what will
happen when a submodule with a gitfile gets removed with newer git. But it
doesn't talk about what happens when the user changes between commits
before and after the removal, which does not remove the submodule from the
work tree like using the rm command did the first time.

Explain what happens and what the user has to do manually to fix that in
the new BUGS section. Also document this behavior in a new test.

Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Merge branch 'cc/starts-n-ends-with-endgame' into jch

Endgame for the cc/starts-n-ends-with topic; this needs to be
evil-merged with other topics that introduce new uses of
prefix/suffix-cmp functions.

* cc/starts-n-ends-with-endgame:
  strbuf: remove prefixcmp() and suffixcmp()
### match next
Merge branch 'fp/submodule-checkout-mode' into jch

* fp/submodule-checkout-mode:
  git-submodule.sh: 'checkout' is a valid update mode
Merge branch 'br/sha1-name-40-hex-no-disambiguation' into jch

* br/sha1-name-40-hex-no-disambiguation:
  revision: turn off object/refname ambiguity check for --stdin
  cat-file: restore ambiguity warning flag in batch_objects
  cat-file: fix a minor memory leak in batch_objects
  cat-file: refactor error handling of batch_objects
  sha1_name: don't resolve refs when core.warnambiguousrefs is false
Merge branch 'jl/submodule-mv-checkout-caveat' into jch

* jl/submodule-mv-checkout-caveat:
  rm: better document side effects when removing a submodule
  mv: better document side effects when moving a submodule
Merge branch 'jn/pager-lv-default-env' into jch

* jn/pager-lv-default-env:
  pager: set LV=-c alongside LESS=FRSX
Merge branch 'ow/stash-with-ifs' into jch

* ow/stash-with-ifs:
  stash: handle specifying stashes with $IFS