shorten_unambiguous_ref(): introduce a new local variable

When filling the scanf_fmts array, use a separate variable to keep
track of the offset to avoid clobbering total_len (which we will need
in the next commit).

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
gen_scanf_fmt(): delete function and use snprintf() instead

To replace "%.*s" with "%s", all we have to do is use snprintf()
to interpolate "%s" into the pattern.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
shorten_unambiguous_ref(): tighten up pointer arithmetic

As long as we're being pathologically stingy with mallocs, we might as
well do the math right and save 6 (!) bytes.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
mv: let 'git mv file no-such-dir/' error out on Windows, too

The previous commit c57f628 (mv: let 'git mv file no-such-dir/' error out)
relies on that rename("file", "no-such-dir/") fails if the directory does not
exist (note the trailing slash).  This does not work as expected on Windows:
This rename() call does not fail, but renames "file" to "no-such-dir" (not to
"no-such-dir/file"). Insert an explicit check for this case to force an error.

This changes the error message from

   $ git mv file no-such-dir/
   fatal: renaming 'file' failed: Not a directory

to

   $ git mv file no-such-dir/
   fatal: destination directory does not exist, source=file, destination=no-such-dir/

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
diff test: reading a directory as a file need not error out

There is no guarantee that strbuf_read_file must error out for
directories.  On some operating systems (e.g., Debian GNU/kFreeBSD
wheezy), reading a directory gives its raw content:

	$ head -c5 < / | cat -A
	^AM-|^_^@^L$

As a result, 'git diff -O/' succeeds instead of erroring out on
these systems, causing t4056.5 "orderfile is a directory" to fail.

On some weird OS it might even make sense to pass a directory to the
-O option and this is not a common user mistake that needs catching.
Remove the test.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t5531: further "matching" fixups

Commit 43eb920 switched one of the sub-repository in this
test to matching to prepare for a world where the default
becomes "simple". However, the main repository needs a
similar change.

We did not notice any test failure when merged with b2ed944
(push: switch default from "matching" to "simple", 2013-01-04)
because t5531.6 is trying to provoke a failure of "git push"
due to a submodule check. When combined with b2ed944 the
push still fails, but for the wrong reason (because our
upstream setup does not exist, not because of the submodule).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
pack-heuristics.txt: mark up the file header properly

AsciiDoc wants these header-lines left-aligned.

Signed-off-by: Thomas Ackermann <th.acker@arcor.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Merge branch 'jk/cat-file-regression-fix' into maint

"git cat-file --batch=", an admittedly useless command, did not
behave very well.

* jk/cat-file-regression-fix:
  cat-file: handle --batch format with missing type/size
  cat-file: pass expand_data to print_object_or_die
Merge branch 'jk/rev-parse-double-dashes' into maint

"git rev-parse <revs> -- <paths>" did not implement the usual
disambiguation rules the commands in the "git log" family used in
the same way.

* jk/rev-parse-double-dashes:
  rev-parse: be more careful with munging arguments
  rev-parse: correctly diagnose revision errors before "--"
Merge branch 'mm/mv-file-to-no-such-dir-with-slash' into maint

"git mv A B/", when B does not exist as a directory, should error
out, but it didn't.

* mm/mv-file-to-no-such-dir-with-slash:
  mv: let 'git mv file no-such-dir/' error out on Windows, too
  mv: let 'git mv file no-such-dir/' error out
Merge branch 'jk/credential-plug-leak' into maint

An earlier "clean-up" introduced an unnecessary memory leak.

* jk/credential-plug-leak:
  Revert "prompt: clean up strbuf usage"
Merge branch 'km/gc-eperm' into maint

A "gc" process running as a different user should be able to stop a
new "gc" process from starting.

* km/gc-eperm:
  gc: notice gc processes run by other users
Merge branch 'nd/daemon-informative-errors-typofix' into maint

The "--[no-]informative-errors" options to "git daemon" were parsed
a bit too loosely, allowing any other string after these option
names.

* nd/daemon-informative-errors-typofix:
  daemon: be strict at parsing parameters --[no-]informative-errors
Git 1.8.5.3
Merge branch 'br/sha1-name-40-hex-no-disambiguation'

When parsing a 40-hex string into the object name, the string is
checked to see if it can be interpreted as a ref so that a warning
can be given for ambiguity. The code kicked in even when the
core.warnambiguousrefs is set to false to squelch this warning, in
which case the cycles spent to look at the ref namespace were an
expensive no-op, as the result was discarded without being used.

* br/sha1-name-40-hex-no-disambiguation:
  sha1_name: don't resolve refs when core.warnambiguousrefs is false
Merge branch 'jn/pager-lv-default-env'

Just like we give a reasonable default for "less" via the LESS
environment variable, specify a reasonable default for "lv" via the
"LV" environment variable when spawning the pager.

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

The implementation of 'git stash $cmd "stash@{...}"' did not quote
the stash argument properly and left it split at IFS whitespace.

* ow/stash-with-ifs:
  stash: handle specifying stashes with $IFS
Merge branch 'rr/completion-format-coverletter'

The bash/zsh completion code did not know about format.coverLetter
among many format.* configuration variables.

* rr/completion-format-coverletter:
  completion: complete format.coverLetter
Merge branch 'jk/pull-rebase-using-fork-point'

Finishing touches.

* jk/pull-rebase-using-fork-point:
  rebase: fix fork-point with zero arguments
Merge branch 'jl/submodule-mv-checkout-caveat'

With a submodule that was initialized in an old fashioned way
without gitlinks, switching branches in the superproject between
the one with and without the submodule may leave the submodule
working tree with its embedded repository behind, as there may be
unexpendable state there. Document and warn users about this.

* jl/submodule-mv-checkout-caveat:
  rm: better document side effects when removing a submodule
  mv: better document side effects when moving a submodule