gitweb.git
add strip_suffix functionJeff King Mon, 30 Jun 2014 16:57:51 +0000 (12:57 -0400)

add strip_suffix function

Many callers of ends_with want to not only find out whether
a string has a suffix, but want to also strip it off. Doing
that separately has two minor problems:

1. We often run over the string twice (once to find
the suffix, and then once more to find its length to
subtract the suffix length).

2. We have to specify the suffix length again, which means
either a magic number, or repeating ourselves with
strlen("suffix").

Just as we have skip_prefix to avoid these cases with
starts_with, we can add a strip_suffix to avoid them with
ends_with.

Note that we add two forms of strip_suffix here: one that
takes a string, with the resulting length as an
out-parameter; and one that takes a pointer/length pair, and
reuses the length as an out-parameter. The latter is more
efficient when the caller already has the length (e.g., when
using strbufs), but it can be easy to confuse the two, as
they take the same number and types of parameters.

For that reason, the "mem" form puts its length parameter
next to the buffer (since they are a pair), and the string
form puts it at the end (since it is an out-parameter). The
compiler can notice when you get the order wrong, which
should help prevent writing one when you meant the other.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

sha1_file: replace PATH_MAX buffer with strbuf in prepa... René Scharfe Mon, 30 Jun 2014 16:55:52 +0000 (12:55 -0400)

sha1_file: replace PATH_MAX buffer with strbuf in prepare_packed_git_one()

Instead of using strbuf to create a message string in case a path is
too long for our fixed-size buffer, replace that buffer with a strbuf
and thus get rid of the limitation.

Helped-by: Duy Nguyen <pclouds@gmail.com>
Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

submodule.c: use the ARRAY_SIZE macroElia Pinto Fri, 27 Jun 2014 12:11:39 +0000 (05:11 -0700)

submodule.c: use the ARRAY_SIZE macro

Use the ARRAY_SIZE macro to get the number
of elements in an array.

Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

wt-status: simplify building of summary limit argumentRené Scharfe Sun, 29 Jun 2014 20:55:44 +0000 (22:55 +0200)

wt-status: simplify building of summary limit argument

Use argv_array_pushf for building the number string for the option
--summary-limit directly instead of using an intermediate buffer.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

wt-status: use argv_array for environmentRené Scharfe Sun, 29 Jun 2014 20:47:00 +0000 (22:47 +0200)

wt-status: use argv_array for environment

Instead of using a PATH_MAX buffer, use argv_array for constructing the
environment for git submodule summary. This simplifies the code a bit
and removes the arbitrary length limit.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

Merge git://ozlabs.org/~paulus/gitkJunio C Hamano Fri, 27 Jun 2014 18:23:03 +0000 (11:23 -0700)

Merge git://ozlabs.org/~paulus/gitk

* git://ozlabs.org/~paulus/gitk:
gitk: Add visiblerefs option, which lists always-shown branches
gitk: Catch mkdtemp errors
gitk: Use mktemp -d to avoid predictable temporary directories
gitk: Honor TMPDIR when viewing external diffs

gitk: Add visiblerefs option, which lists always-shown... Max Kirillov Tue, 24 Jun 2014 05:19:44 +0000 (08:19 +0300)

gitk: Add visiblerefs option, which lists always-shown branches

When many branches contain a commit, the branches used to be shown in
the form "A, B and many more", where A, B can be master of current
HEAD. But there are more which might be interesting to always know about.
For example, "origin/master".

The new option, visiblerefs, is stored in ~/.gitk. It contains a list
of references which are always shown before "and many more" if they
contain the commit. By default it is `{"master"}', which is compatible
with previous behavior.

Signed-off-by: Max Kirillov <max@max630.net>
Signed-off-by: Paul Mackerras <paulus@samba.org>

gitk: Catch mkdtemp errorsDavid Aguilar Thu, 19 Jun 2014 02:53:14 +0000 (19:53 -0700)

gitk: Catch mkdtemp errors

105b5d3f ("gitk: Use mktemp -d to avoid predictable temporary
directories") introduced a dependency on mkdtemp, which is not
available on Windows.

Use the original temporary directory behavior when mkdtemp fails.
This makes the code use mkdtemp when available and gracefully
fallback to the existing behavior when it is not available.

Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: David Aguilar <davvid@gmail.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>

Merge early parts from git://ozlabs.org/~paulus/gitk.gitJunio C Hamano Thu, 26 Jun 2014 20:46:09 +0000 (13:46 -0700)

Merge early parts from git://ozlabs.org/~paulus/gitk.git

* master~2:
gitk: Show staged submodules regardless of ignore config
gitk: Allow displaying time zones from author and commit dates timestamps
gitk: Switch to patch mode when searching for line origin
gitk: Replace SHA1 entry field on keyboard paste
l10n: Init Vietnamese translation

Merge git://repo.or.cz/git-guiJunio C Hamano Thu, 26 Jun 2014 20:44:11 +0000 (13:44 -0700)

Merge git://repo.or.cz/git-gui

* git://repo.or.cz/git-gui:
git-gui: tolerate major version changes when comparing the git version
git-gui: show staged submodules regardless of ignore config

replace: add a --raw mode for --editJeff King Tue, 24 Jun 2014 09:46:31 +0000 (05:46 -0400)

replace: add a --raw mode for --edit

One of the purposes of "git replace --edit" is to help a
user repair objects which are malformed or corrupted.
Usually we pretty-print trees with "ls-tree", which is much
easier to work with than the raw binary data. However, some
forms of corruption break the tree-walker, in which case our
pretty-printing fails, rendering "--edit" useless for the
user.

This patch introduces a "--raw" option, which lets you edit
the binary data in these instances.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

replace: use argv_array in export_objectJeff King Tue, 24 Jun 2014 09:46:05 +0000 (05:46 -0400)

replace: use argv_array in export_object

This is a little more verbose, but will make it easier to
make parts of our command-line conditional (without
resorting to magic numbers or lots of NULLs to get an
appropriately sized argv array).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

avoid double close of descriptors handed to run_commandJeff King Tue, 24 Jun 2014 09:45:46 +0000 (05:45 -0400)

avoid double close of descriptors handed to run_command

When a file descriptor is given to run_command via the
"in", "out", or "err" parameters, run_command takes
ownership. The descriptor will be closed in the parent
process whether the process is spawned successfully or not,
and closing it again is wrong.

In practice this has not caused problems, because we usually
close() right after start_command returns, meaning no other
code has opened a descriptor in the meantime. So we just get
EBADF and ignore it (rather than accidentally closing
somebody else's descriptor!).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

replace: replace spaces with tabs in indentationJeff King Tue, 24 Jun 2014 09:43:07 +0000 (05:43 -0400)

replace: replace spaces with tabs in indentation

This matches our usual style and the surrounding code.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

move "%G" format test from t7510 to t6006Jeff King Wed, 25 Jun 2014 21:42:17 +0000 (17:42 -0400)

move "%G" format test from t7510 to t6006

The final test in t7510 checks that "--format" placeholders
that look similar to GPG placeholders (but that we don't
actually understand) are passed through. That test was
placed in t7510, since the other GPG placeholder tests are
there. However, it does not have a GPG prerequisite, because
it is not actually checking any signed commits.

This causes the test to erroneously fail when gpg is not
installed on a system, however. Not because we need signed
commits, but because we need _any_ commit to run "git log".
If we don't have gpg installed, t7510 doesn't create any
commits at all.

We can fix this by moving the test into t6006. This is
arguably a better place anyway, because it is where we test
most of the other placeholders (we do not test GPG
placeholders there because of the infrastructure needed to
make signed commits).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

Sync with maintJunio C Hamano Wed, 25 Jun 2014 19:32:58 +0000 (12:32 -0700)

Sync with maint

Fifth batch for 2.1Junio C Hamano Wed, 25 Jun 2014 19:32:23 +0000 (12:32 -0700)

Fifth batch for 2.1

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

Merge branch 'jm/dedup-name-compare'Junio C Hamano Wed, 25 Jun 2014 19:23:57 +0000 (12:23 -0700)

Merge branch 'jm/dedup-name-compare'

* jm/dedup-name-compare:
cleanup duplicate name_compare() functions
name-hash.c: replace cache_name_compare() with memcmp(3)

Merge branch 'ep/avoid-test-a-o'Junio C Hamano Wed, 25 Jun 2014 19:23:56 +0000 (12:23 -0700)

Merge branch 'ep/avoid-test-a-o'

Update tests and scripts to avoid "test ... -a ...", which is often
more error-prone than "test ... && test ...".

Squashed misconversion fix-up into git-submodule.sh updates.

* ep/avoid-test-a-o:
git-submodule.sh: avoid "echo" path-like values
git-submodule.sh: avoid "test <cond> -a/-o <cond>"
t/test-lib-functions.sh: avoid "test <cond> -a/-o <cond>"
t/t9814-git-p4-rename.sh: avoid "test <cond> -a/-o <cond>"
t/t5538-push-shallow.sh: avoid "test <cond> -a/-o <cond>"
t/t5403-post-checkout-hook.sh: avoid "test <cond> -a/-o <cond>"
t/t5000-tar-tree.sh: avoid "test <cond> -a/-o <cond>"
t/t4102-apply-rename.sh: avoid "test <cond> -a/-o <cond>"
t/t0026-eol-config.sh: avoid "test <cond> -a/-o <cond>"
t/t0025-crlf-auto.sh: avoid "test <cond> -a/-o <cond>"
t/lib-httpd.sh: avoid "test <cond> -a/-o <cond>"
git-rebase--interactive.sh: avoid "test <cond> -a/-o <cond>"
git-mergetool.sh: avoid "test <cond> -a/-o <cond>"
git-bisect.sh: avoid "test <cond> -a/-o <cond>"
contrib/examples/git-resolve.sh: avoid "test <cond> -a/-o <cond>"
contrib/examples/git-repack.sh: avoid "test <cond> -a/-o <cond>"
contrib/examples/git-merge.sh: avoid "test <cond> -a/-o <cond>"
contrib/examples/git-commit.sh: avoid "test <cond> -a/-o <cond>"
contrib/examples/git-clone.sh: avoid "test <cond> -a/-o <cond>"
check_bindir: avoid "test <cond> -a/-o <cond>"

Merge branch 'tb/unicode-7.0-display-width'Junio C Hamano Wed, 25 Jun 2014 19:23:54 +0000 (12:23 -0700)

Merge branch 'tb/unicode-7.0-display-width'

* tb/unicode-7.0-display-width:
Update of unicode_width.h to Unicode Version 7.0

Merge branch 'ye/doc-http-proto'Junio C Hamano Wed, 25 Jun 2014 19:23:52 +0000 (12:23 -0700)

Merge branch 'ye/doc-http-proto'

* ye/doc-http-proto:
http-protocol.txt: Basic Auth is defined in RFC 2617, not RFC 2616

Merge branch 'rs/blame-refactor'Junio C Hamano Wed, 25 Jun 2014 19:23:36 +0000 (12:23 -0700)

Merge branch 'rs/blame-refactor'

* rs/blame-refactor:
blame: simplify prepare_lines()
blame: factor out get_next_line()

Merge branch 'pb/trim-trailing-spaces'Junio C Hamano Wed, 25 Jun 2014 19:23:34 +0000 (12:23 -0700)

Merge branch 'pb/trim-trailing-spaces'

* pb/trim-trailing-spaces:
t0008: do not depend on 'echo' handling backslashes specially

Merge branch 'mc/doc-submodule-sync-recurse'Junio C Hamano Wed, 25 Jun 2014 19:23:29 +0000 (12:23 -0700)

Merge branch 'mc/doc-submodule-sync-recurse'

* mc/doc-submodule-sync-recurse:
submodule: document "sync --recursive"

Merge branch 'sp/complete-ext-alias'Junio C Hamano Wed, 25 Jun 2014 19:23:27 +0000 (12:23 -0700)

Merge branch 'sp/complete-ext-alias'

* sp/complete-ext-alias:
completion: handle '!f() { ... }; f' and "!sh -c '...' -" aliases

Merge branch 'mc/git-p4-prepare-p4-only'Junio C Hamano Wed, 25 Jun 2014 19:23:24 +0000 (12:23 -0700)

Merge branch 'mc/git-p4-prepare-p4-only'

* mc/git-p4-prepare-p4-only:
git-p4: fix submit in non --prepare-p4-only mode

Merge branch 'jk/repack-pack-writebitmaps-config'Junio C Hamano Wed, 25 Jun 2014 19:23:19 +0000 (12:23 -0700)

Merge branch 'jk/repack-pack-writebitmaps-config'

* jk/repack-pack-writebitmaps-config:
t7700: drop explicit --no-pack-kept-objects from .keep test
repack: introduce repack.writeBitmaps config option
repack: simplify handling of --write-bitmap-index
pack-objects: stop respecting pack.writebitmaps

Merge branch 'nd/init-restore-env'Junio C Hamano Wed, 25 Jun 2014 19:22:00 +0000 (12:22 -0700)

Merge branch 'nd/init-restore-env'

Some subcommands do not want to be aliased because of the side
effects that happens while the definitions of the aliases are looked
up from configuration system.

* nd/init-restore-env:
git potty: restore environments after alias expansion

Merge branch 'jk/repack-pack-keep-objects'Junio C Hamano Wed, 25 Jun 2014 19:21:51 +0000 (12:21 -0700)

Merge branch 'jk/repack-pack-keep-objects'

Recent updates to "git repack" started to duplicate objects that
are in packfiles marked with .keep flag into the new packfile by
mistake.

* jk/repack-pack-keep-objects:
repack: s/write_bitmap/&s/ in code
repack: respect pack.writebitmaps
repack: do not accidentally pack kept objects by default

Merge branch 'fr/sequencer-fail-with-not-one-upon-no-ff'Junio C Hamano Wed, 25 Jun 2014 19:21:45 +0000 (12:21 -0700)

Merge branch 'fr/sequencer-fail-with-not-one-upon-no-ff'

* fr/sequencer-fail-with-not-one-upon-no-ff:
sequencer: signal failed ff as an aborted, not a conflicted merge

Git 2.0.1 v2.0.1Junio C Hamano Wed, 25 Jun 2014 19:21:11 +0000 (12:21 -0700)

Git 2.0.1

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

Merge branch 'na/no-http-test-in-the-middle' into maintJunio C Hamano Wed, 25 Jun 2014 18:50:13 +0000 (11:50 -0700)

Merge branch 'na/no-http-test-in-the-middle' into maint

The mode to run tests with HTTP server tests disabled was broken.

* na/no-http-test-in-the-middle:
t5538: move http push tests out to t5542

Merge branch 'jl/status-added-submodule-is-never-ignore... Junio C Hamano Wed, 25 Jun 2014 18:50:03 +0000 (11:50 -0700)

Merge branch 'jl/status-added-submodule-is-never-ignored' into maint

"git status" (and "git commit") behaved as if changes in a modified
submodule are not there if submodule.*.ignore configuration is set,
which was misleading. The configuration is only to unclutter diff
output during the course of development, and should not to hide
changes in the "status" output to cause the users forget to commit
them.

* jl/status-added-submodule-is-never-ignored:
commit -m: commit staged submodules regardless of ignore config
status/commit: show staged submodules regardless of ignore config

Merge branch 'ym/fix-opportunistic-index-update-race... Junio C Hamano Wed, 25 Jun 2014 18:49:48 +0000 (11:49 -0700)

Merge branch 'ym/fix-opportunistic-index-update-race' into maint

"git status", even though it is a read-only operation, tries to
update the index with refreshed lstat(2) info to optimize future
accesses to the working tree opportunistically, but this could
race with a "read-write" operation that modify the index while it
is running. Detect such a race and avoid overwriting the index.

* ym/fix-opportunistic-index-update-race:
read-cache.c: verify index file before we opportunistically update it
wrapper.c: add xpread() similar to xread()

Merge branch 'mk/show-s-no-extra-blank-line-for-merges... Junio C Hamano Wed, 25 Jun 2014 18:49:39 +0000 (11:49 -0700)

Merge branch 'mk/show-s-no-extra-blank-line-for-merges' into maint

"git show -s" (i.e. show log message only) used to incorrectly emit
an extra blank line after a merge commit.

* mk/show-s-no-extra-blank-line-for-merges:
git-show: fix 'git show -s' to not add extra terminator after merge commit

Merge branch 'rr/rebase-autostash-fix' into maintJunio C Hamano Wed, 25 Jun 2014 18:49:31 +0000 (11:49 -0700)

Merge branch 'rr/rebase-autostash-fix' into maint

The autostash mode of "git rebase -i" did not restore the dirty
working tree state if the user aborted the interactive rebase by
emptying the insn sheet.

* rr/rebase-autostash-fix:
rebase -i: test "Nothing to do" case with autostash
rebase -i: handle "Nothing to do" case with autostash

Merge branch 'jc/shortlog-ref-exclude' into maintJunio C Hamano Wed, 25 Jun 2014 18:49:10 +0000 (11:49 -0700)

Merge branch 'jc/shortlog-ref-exclude' into maint

"git log --exclude=<glob> --all | git shortlog" worked as expected,
but "git shortlog --exclude=<glob> --all", which is supposed to be
identical to the above pipeline, was not accepted at the command
line argument parser level.

* jc/shortlog-ref-exclude:
shortlog: allow --exclude=<glob> to be passed

Merge branch 'jl/remote-rm-prune' into maintJunio C Hamano Wed, 25 Jun 2014 18:49:01 +0000 (11:49 -0700)

Merge branch 'jl/remote-rm-prune' into maint

"git remote rm" and "git remote prune" can involve removing many
refs at once, which is not a very efficient thing to do when very
many refs exist in the packed-refs file.

* jl/remote-rm-prune:
remote prune: optimize "dangling symref" check/warning
remote: repack packed-refs once when deleting multiple refs
remote rm: delete remote configuration as the last

Merge branch 'fc/rerere-conflict-style' into maintJunio C Hamano Wed, 25 Jun 2014 18:48:54 +0000 (11:48 -0700)

Merge branch 'fc/rerere-conflict-style' into maint

"git rerere forget" did not work well when merge.conflictstyle
was set to a non-default value.

* fc/rerere-conflict-style:
rerere: fix for merge.conflictstyle

Merge branch 'rs/pack-objects-no-unnecessary-realloc... Junio C Hamano Wed, 25 Jun 2014 18:48:42 +0000 (11:48 -0700)

Merge branch 'rs/pack-objects-no-unnecessary-realloc' into maint

"git pack-objects" unnecessarily copied the previous contents when
extending the hashtable, even though it will populate the table
from scratch anyway.

* rs/pack-objects-no-unnecessary-realloc:
pack-objects: use free()+xcalloc() instead of xrealloc()+memset()

Merge branch 'dt/merge-recursive-case-insensitive'... Junio C Hamano Wed, 25 Jun 2014 18:48:34 +0000 (11:48 -0700)

Merge branch 'dt/merge-recursive-case-insensitive' into maint

On a case insensitive filesystem, merge-recursive incorrectly
deleted the file that is to be renamed to a name that is the same
except for case differences.

* dt/merge-recursive-case-insensitive:
mv: allow renaming to fix case on case insensitive filesystems
merge-recursive.c: fix case-changing merge bug

Merge branch 'rs/mailinfo-header-cmp' into maintJunio C Hamano Wed, 25 Jun 2014 18:48:23 +0000 (11:48 -0700)

Merge branch 'rs/mailinfo-header-cmp' into maint

"git mailinfo" used to read beyond the end of header string while
parsing an incoming e-mail message to extract the patch.

* rs/mailinfo-header-cmp:
mailinfo: use strcmp() for string comparison

Merge branch 'jk/index-pack-report-missing' into maintJunio C Hamano Wed, 25 Jun 2014 18:48:13 +0000 (11:48 -0700)

Merge branch 'jk/index-pack-report-missing' into maint

The error reporting from "git index-pack" has been improved to
distinguish missing objects from type errors.

* jk/index-pack-report-missing:
index-pack: distinguish missing objects from type errors

Merge branch 'nd/index-pack-one-fd-per-thread' into... Junio C Hamano Wed, 25 Jun 2014 18:47:58 +0000 (11:47 -0700)

Merge branch 'nd/index-pack-one-fd-per-thread' into maint

We used to disable threaded "git index-pack" on platforms without
thread-safe pread(); use a different workaround for such
platforms to allow threaded "git index-pack".

* nd/index-pack-one-fd-per-thread:
index-pack: work around thread-unsafe pread()

Merge branch 'sk/spawn-less-case-insensitively-from... Junio C Hamano Wed, 25 Jun 2014 18:47:49 +0000 (11:47 -0700)

Merge branch 'sk/spawn-less-case-insensitively-from-grep-O-i' into maint

"git grep -O" to show the lines that hit in the pager did not work
well with case insensitive search. We now spawn "less" with its
"-I" option when it is used as the pager (which is the default).

* sk/spawn-less-case-insensitively-from-grep-O-i:
git grep -O -i: if the pager is 'less', pass the '-I' option

Merge branch 'nd/daemonize-gc' into maintJunio C Hamano Wed, 25 Jun 2014 18:47:36 +0000 (11:47 -0700)

Merge branch 'nd/daemonize-gc' into maint

"git gc --auto" was recently changed to run in the background to
give control back early to the end-user sitting in front of the
terminal, but it forgot that housekeeping involving reflogs should
be done without other processes competing for accesses to the refs.

* nd/daemonize-gc:
gc --auto: do not lock refs in the background

Merge branch 'jk/diff-follow-must-take-one-pathspec... Junio C Hamano Wed, 25 Jun 2014 18:47:23 +0000 (11:47 -0700)

Merge branch 'jk/diff-follow-must-take-one-pathspec' into maint

"git format-patch" did not enforce the rule that the "--follow"
option from the log/diff family of commands must be used with
exactly one pathspec.

* jk/diff-follow-must-take-one-pathspec:
move "--follow needs one pathspec" rule to diff_setup_done

Merge branch 'jk/diff-files-assume-unchanged' into... Junio C Hamano Wed, 25 Jun 2014 18:47:09 +0000 (11:47 -0700)

Merge branch 'jk/diff-files-assume-unchanged' into maint

"git diff --find-copies-harder" sometimes pretended as if the mode
bits have changed for paths that are marked with assume-unchanged
bit.

* jk/diff-files-assume-unchanged:
run_diff_files: do not look at uninitialized stat data

Merge branch 'jk/commit-C-pick-empty' into maintJunio C Hamano Wed, 25 Jun 2014 18:46:54 +0000 (11:46 -0700)

Merge branch 'jk/commit-C-pick-empty' into maint

"git commit --allow-empty-message -C $commit" did not work when the
commit did not have any log message.

* jk/commit-C-pick-empty:
commit: do not complain of empty messages from -C

Merge branch 'bc/blame-crlf-test' into maintJunio C Hamano Wed, 25 Jun 2014 18:46:44 +0000 (11:46 -0700)

Merge branch 'bc/blame-crlf-test' into maint

"git blame" assigned the blame to the copy in the working-tree if
the repository is set to core.autocrlf=input and the file used CRLF
line endings.

* bc/blame-crlf-test:
blame: correctly handle files regardless of autocrlf

Merge branch 'jx/blame-align-relative-time' into maintJunio C Hamano Wed, 25 Jun 2014 18:46:34 +0000 (11:46 -0700)

Merge branch 'jx/blame-align-relative-time' into maint

"git blame" miscounted number of columns needed to show localized
timestamps, resulting in jaggy left-side-edge of the source code
lines in its output.

* jx/blame-align-relative-time:
blame: dynamic blame_date_width for different locales
blame: fix broken time_buf paddings in relative timestamp

Merge branch 'jc/apply-ignore-whitespace' into maintJunio C Hamano Wed, 25 Jun 2014 18:46:23 +0000 (11:46 -0700)

Merge branch 'jc/apply-ignore-whitespace' into maint

"--ignore-space-change" option of "git apply" ignored the spaces
at the beginning of line too aggressively, which is inconsistent
with the option of the same name "diff" and "git diff" have.

* jc/apply-ignore-whitespace:
apply --ignore-space-change: lines with and without leading whitespaces do not match

Merge branch 'jk/complete-merge-pull' into maintJunio C Hamano Wed, 25 Jun 2014 18:46:12 +0000 (11:46 -0700)

Merge branch 'jk/complete-merge-pull' into maint

The completion scripts (in contrib/) did not know about quite a few
options that are common between "git merge" and "git pull", and a
couple of options unique to "git merge".

* jk/complete-merge-pull:
completion: add missing options for git-merge
completion: add a note that merge options are shared

Merge branch 'ow/config-mailmap-pathname' into maintJunio C Hamano Wed, 25 Jun 2014 18:45:55 +0000 (11:45 -0700)

Merge branch 'ow/config-mailmap-pathname' into maint

The "mailmap.file" configuration option did not support the tilde
expansion (i.e. ~user/path and ~/path).

* ow/config-mailmap-pathname:
config: respect '~' and '~user' in mailmap.file

Merge branch 'as/pretty-truncate' into maintJunio C Hamano Wed, 25 Jun 2014 18:45:31 +0000 (11:45 -0700)

Merge branch 'as/pretty-truncate' into maint

The "%<(10,trunc)%s" pretty format specifier in the log family of
commands is used to truncate the string to a given length (e.g. 10
in the example) with padding to column-align the output, but did
not take into account that number of bytes and number of display
columns are different.

* as/pretty-truncate:
pretty.c: format string with truncate respects logOutputEncoding
t4205, t6006: add tests that fail with i18n.logOutputEncoding set
t4205 (log-pretty-format): use `tformat` rather than `format`
t4041, t4205, t6006, t7102: don't hardcode tested encoding value
t4205 (log-pretty-formats): don't hardcode SHA-1 in expected outputs

Merge branch 'jc/revision-dash-count-parsing' into... Junio C Hamano Wed, 25 Jun 2014 18:44:53 +0000 (11:44 -0700)

Merge branch 'jc/revision-dash-count-parsing' into maint

"git log -2master" is a common typo that shows two commits starting
from whichever random branch that is not 'master' that happens to
be checked out currently.

* jc/revision-dash-count-parsing:
revision: parse "git log -<count>" more carefully

Merge branch 'jk/report-fail-to-read-objects-better... Junio C Hamano Wed, 25 Jun 2014 18:43:57 +0000 (11:43 -0700)

Merge branch 'jk/report-fail-to-read-objects-better' into maint

Reworded the error message given upon a failure to open an existing
loose object file due to e.g. permission issues; it was reported as
the object being corrupt, but that is not quite true.

* jk/report-fail-to-read-objects-better:
open_sha1_file: report "most interesting" errno

Merge branch 'mn/sideband-no-ansi' into maintJunio C Hamano Wed, 25 Jun 2014 18:43:43 +0000 (11:43 -0700)

Merge branch 'mn/sideband-no-ansi' into maint

Tools that read diagnostic output in our standard error stream do
not want to see terminal control sequence (e.g. erase-to-eol).
Detect them by checking if the standard error stream is connected
to a tty.

* mn/sideband-no-ansi:
sideband.c: do not use ANSI control sequence on non-terminal

Merge branch 'je/pager-do-not-recurse' into maintJunio C Hamano Wed, 25 Jun 2014 18:43:07 +0000 (11:43 -0700)

Merge branch 'je/pager-do-not-recurse' into maint

We used to unconditionally disable the pager in the pager process
we spawn to feed out output, but that prevented people who want to
run "less" within "less" from doing so.

* je/pager-do-not-recurse:
pager: do allow spawning pager recursively

setup_git_env(): introduce git_path_from_env() helperJeff King Tue, 24 Jun 2014 20:58:15 +0000 (16:58 -0400)

setup_git_env(): introduce git_path_from_env() helper

"Check the value of an environment and fall back to a known path
inside $GIT_DIR" is repeated a few times to determine the location
of the data store, the index and the graft file, but the return
value of getenv is not guaranteed to survive across further
invocations of setenv or even getenv.

Make sure to xstrdup() the value we receive from getenv(3), and
encapsulate the pattern into a helper function.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

t7510: test verify-commitMichael J Gruber Mon, 23 Jun 2014 07:05:51 +0000 (09:05 +0200)

t7510: test verify-commit

This mixes the "git verify-commit" tests in with the "git show
--show-signature" tests, to keep the tests more readable.

The tests already mix in the "call show" tests with the "verify" tests.
So in case of a test beakage, a '-v' run would be needed to reveal the
exact point of breakage anyway.

Additionally, test the actual output of "git verify-commit" and "git
show --show-signature" and compare to "git cat-file".

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

t7510: exit for loop with test resultMichael J Gruber Mon, 23 Jun 2014 07:05:50 +0000 (09:05 +0200)

t7510: exit for loop with test result

t7510 uses for loops in a subshell, which need to make sure that the test
returns with the appropriate error code from within the loop.

Restructure the loops as the usual && chains with a single point of
"exit 1" at the end of the loop to make this clearer.

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

verify-commit: scriptable commit signature verificationMichael J Gruber Mon, 23 Jun 2014 07:05:49 +0000 (09:05 +0200)

verify-commit: scriptable commit signature verification

Commit signatures can be verified using "git show -s --show-signature"
or the "%G?" pretty format and parsing the output, which is well suited
for user inspection, but not for scripting.

Provide a command "verify-commit" which is analogous to "verify-tag": It
returns 0 for good signatures and non-zero otherwise, has the gpg output
on stderr and (optionally) the commit object on stdout, sans the
signature, just like "verify-tag" does.

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

gpg-interface: provide access to the payloadMichael J Gruber Mon, 23 Jun 2014 07:05:48 +0000 (09:05 +0200)

gpg-interface: provide access to the payload

In contrast to tag signatures, commit signatures are put into the
header, that is between the other header parts and commit messages.

Provide access to the commit content sans the signature, which is the
payload that is actually signed. Commit signature verification does the
parsing anyways, and callers may wish to act on or display the commit
object sans the signature.

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

gpg-interface: provide clear helper for struct signatur... Michael J Gruber Mon, 23 Jun 2014 07:05:47 +0000 (09:05 +0200)

gpg-interface: provide clear helper for struct signature_check

The struct has been growing members whose malloced memory needs to be
freed. Do this with one helper function so that no malloced memory shall
be left unfreed.

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

builtin/clone.c: detect a clone starting at a tag correctlyJunio C Hamano Mon, 23 Jun 2014 21:27:36 +0000 (14:27 -0700)

builtin/clone.c: detect a clone starting at a tag correctly

31b808a0 (clone --single: limit the fetch refspec to fetched branch,
2012-09-20) tried to see if the given "branch" to follow is actually
a tag at the remote repository by checking with "refs/tags/" but it
incorrectly used strstr(3); it is actively wrong to treat a "branch"
"refs/heads/refs/tags/foo" and use the logic for the "refs/tags/"
ref hierarchy. What the code really wanted to do is to see if it
starts with "refs/tags/".

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

Fourth batch for 2.1Junio C Hamano Fri, 20 Jun 2014 20:22:55 +0000 (13:22 -0700)

Fourth batch for 2.1

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

Merge branch 'jc/test-lazy-prereq' (early part)Junio C Hamano Fri, 20 Jun 2014 20:21:26 +0000 (13:21 -0700)

Merge branch 'jc/test-lazy-prereq' (early part)

* 'jc/test-lazy-prereq' (early part):
t3419: drop unnecessary NOT_EXPENSIVE pseudo-prerequisite
t3302: drop unnecessary NOT_EXPENSIVE pseudo-prerequisite
t3302: do not chdir around in the primary test process
t3302: coding style updates
test: turn USR_BIN_TIME into a lazy prerequisite
test: turn EXPENSIVE into a lazy prerequisite

Merge branch 'jc/fetch-pull-refmap'Junio C Hamano Fri, 20 Jun 2014 20:14:10 +0000 (13:14 -0700)

Merge branch 'jc/fetch-pull-refmap'

* jc/fetch-pull-refmap:
docs: Explain the purpose of fetch's and pull's <refspec> parameter.
fetch: allow explicit --refmap to override configuration
fetch doc: add a section on configured remote-tracking branches
fetch doc: remove "short-cut" section
fetch doc: update refspec format description
fetch doc: on pulling multiple refspecs
fetch doc: remove notes on outdated "mixed layout"
fetch doc: update note on '+' in front of the refspec
fetch doc: move FETCH_HEAD material lower and add an example
fetch doc: update introductory part for clarity

Merge branch 'mt/send-email-cover-to-cc'Junio C Hamano Fri, 20 Jun 2014 20:12:19 +0000 (13:12 -0700)

Merge branch 'mt/send-email-cover-to-cc'

* mt/send-email-cover-to-cc:
t9001: avoid non-portable '\n' with sed
test/send-email: to-cover, cc-cover tests
git-send-email: two new options: to-cover, cc-cover

Merge branch 'tb/t5551-clone-notice-to-stderr'Junio C Hamano Fri, 20 Jun 2014 20:12:17 +0000 (13:12 -0700)

Merge branch 'tb/t5551-clone-notice-to-stderr'

* tb/t5551-clone-notice-to-stderr:
t5551: fix the 50,000 tag test

Merge branch 'rs/more-starts-with'Junio C Hamano Fri, 20 Jun 2014 20:12:13 +0000 (13:12 -0700)

Merge branch 'rs/more-starts-with'

* rs/more-starts-with:
Use starts_with() for C strings instead of memcmp()

Merge branch 'jm/api-strbuf-doc'Junio C Hamano Fri, 20 Jun 2014 20:12:10 +0000 (13:12 -0700)

Merge branch 'jm/api-strbuf-doc'

* jm/api-strbuf-doc:
api-strbuf.txt minor typos

Merge branch 'jc/revision-dash-count-parsing'Junio C Hamano Fri, 20 Jun 2014 20:10:25 +0000 (13:10 -0700)

Merge branch 'jc/revision-dash-count-parsing'

"git log -2master" is a common typo that shows two commits starting
from whichever random branch that is not 'master' that happens to
be checked out currently.

* jc/revision-dash-count-parsing:
revision: parse "git log -<count>" more carefully

http-push: refactor parsing of remote object namesJeff King Thu, 19 Jun 2014 21:58:10 +0000 (17:58 -0400)

http-push: refactor parsing of remote object names

We get loose object names like "objects/??/..." from the
remote side, and need to convert them to their hex
representation.

The code to do so is rather hard to follow, as it uses some
calculated lengths whose origins are hard to understand and
verify (e.g., the path must be exactly 49 characters long.
why? Why doesn't the strcpy overflow obj_hex, which is the
same length as path?).

We can simplify this a bit by using skip_prefix, using standard
40- and 20-character buffers for hex and binary sha1s, and
adding some comments.

We also drop a totally bogus comment that claims strlcpy
cannot be used because "path" is not NUL-terminated. Right
between a call to strlen(path) and strcpy(path).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

imap-send: use skip_prefix instead of using magic numbersTanay Abhra Thu, 19 Jun 2014 05:22:46 +0000 (05:22 +0000)

imap-send: use skip_prefix instead of using magic numbers

Signed-off-by: Tanay Abhra <tanayabh@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

use skip_prefix to avoid repeated calculationsJeff King Wed, 18 Jun 2014 19:57:17 +0000 (15:57 -0400)

use skip_prefix to avoid repeated calculations

In some cases, we use starts_with to check for a prefix, and
then use an already-calculated prefix length to advance a
pointer past the prefix. There are no magic numbers or
duplicated strings here, but we can still make the code
simpler and more obvious by using skip_prefix.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

git: avoid magic number with skip_prefixJeff King Wed, 18 Jun 2014 19:56:48 +0000 (15:56 -0400)

git: avoid magic number with skip_prefix

After handling options, any leftover arguments should be
commands. However, we pass through "--help" and "--version",
so that we convert them into "git help" and "git version"
respectively.

This is a straightforward use of skip_prefix to avoid a
magic number, but while we are there, it is worth adding a
comment to explain this otherwise confusing behavior.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

fetch-pack: refactor parsing in get_ackJeff King Wed, 18 Jun 2014 19:56:03 +0000 (15:56 -0400)

fetch-pack: refactor parsing in get_ack

There are several uses of the magic number "line+45" when
parsing ACK lines from the server, and it's rather unclear
why 45 is the correct number. We can make this more clear by
keeping a running pointer as we parse, using skip_prefix to
jump past the first "ACK ", then adding 40 to jump past
get_sha1_hex (which is still magical, but hopefully 40 is
less magical to readers of git code).

Note that this actually puts us at line+44. The original
required some character between the sha1 and further ACK
flags (it is supposed to be a space, but we never enforced
that). We start our search for flags at line+44, which
meanas we are slightly more liberal than the old code.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

fast-import: refactor parsing of spacesJeff King Wed, 18 Jun 2014 19:51:57 +0000 (15:51 -0400)

fast-import: refactor parsing of spaces

When we see a file change in a commit, we expect one of:

1. A mark.

2. An "inline" keyword.

3. An object sha1.

The handling of spaces is inconsistent between the three
options. Option 1 calls a sub-function which checks for the
space, but doesn't parse past it. Option 2 parses the space,
then deliberately avoids moving the pointer past it. Option
3 detects the space locally but doesn't move past it.

This is confusing, because it looks like option 1 forgets to
check for the space (it's just buried). And option 2 checks
for "inline ", but only moves strlen("inline") characters
forward, which looks like a bug but isn't.

We can make this more clear by just having each branch move
past the space as it is checked (and we can replace the
doubled use of "inline" with a call to skip_prefix).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

stat_opt: check extra strlen callJeff King Wed, 18 Jun 2014 19:51:17 +0000 (15:51 -0400)

stat_opt: check extra strlen call

As in earlier commits, the diff option parser uses
starts_with to find that an argument starts with "--stat-",
and then adds strlen("stat-") to find the rest of the
option.

However, in this case the starts_with and the strlen are
separated across functions, making it easy to call the
latter without the former. Let's use skip_prefix instead of
raw pointer arithmetic to catch such a case.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

daemon: use skip_prefix to avoid magic numbersJeff King Wed, 18 Jun 2014 19:49:44 +0000 (15:49 -0400)

daemon: use skip_prefix to avoid magic numbers

Like earlier cases, we can use skip_prefix to avoid magic
numbers that must match the length of starts_with prefixes.
However, the numbers are a little more complicated here, as
we keep parsing past the prefix. We can solve it by keeping
a running pointer as we parse; its final value is the
location we want.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

fast-import: use skip_prefix for parsing inputJeff King Wed, 18 Jun 2014 19:49:12 +0000 (15:49 -0400)

fast-import: use skip_prefix for parsing input

Fast-import does a lot of parsing of commands and
dispatching to sub-functions. For example, given "option
foo", we might recognize "option " using starts_with, and
then hand it off to parse_option() to do the rest.

However, we do not let parse_option know that we have parsed
the first part already. It gets the full buffer, and has to
skip past the uninteresting bits. Some functions simply add
a magic constant:

char *option = command_buf.buf + 7;

Others use strlen:

char *option = command_buf.buf + strlen("option ");

And others use strchr:

char *option = strchr(command_buf.buf, ' ') + 1;

All of these are brittle and easy to get wrong (especially
given that the starts_with call and the code that assumes
the presence of the prefix are far apart). Instead, we can
use skip_prefix, and just pass each handler a pointer to its
arguments.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

use skip_prefix to avoid repeating stringsJeff King Wed, 18 Jun 2014 19:48:29 +0000 (15:48 -0400)

use skip_prefix to avoid repeating strings

It's a common idiom to match a prefix and then skip past it
with strlen, like:

if (starts_with(foo, "bar"))
foo += strlen("bar");

This avoids magic numbers, but means we have to repeat the
string (and there is no compiler check that we didn't make a
typo in one of the strings).

We can use skip_prefix to handle this case without repeating
ourselves.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

use skip_prefix to avoid magic numbersJeff King Wed, 18 Jun 2014 19:47:50 +0000 (15:47 -0400)

use skip_prefix to avoid magic numbers

It's a common idiom to match a prefix and then skip past it
with a magic number, like:

if (starts_with(foo, "bar"))
foo += 3;

This is easy to get wrong, since you have to count the
prefix string yourself, and there's no compiler check if the
string changes. We can use skip_prefix to avoid the magic
numbers here.

Note that some of these conversions could be much shorter.
For example:

if (starts_with(arg, "--foo=")) {
bar = arg + 6;
continue;
}

could become:

if (skip_prefix(arg, "--foo=", &bar))
continue;

However, I have left it as:

if (skip_prefix(arg, "--foo=", &v)) {
bar = v;
continue;
}

to visually match nearby cases which need to actually
process the string. Like:

if (skip_prefix(arg, "--foo=", &v)) {
bar = atoi(v);
continue;
}

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

transport-helper: avoid reading past end-of-stringJeff King Wed, 18 Jun 2014 19:47:17 +0000 (15:47 -0400)

transport-helper: avoid reading past end-of-string

We detect the "import-marks" capability by looking for that
string, but _without_ a trailing space. Then we skip past it
using strlen("import-marks "), with a space. So if a remote
helper gives us exactly "import-marks", we will read past
the end-of-string by one character.

This is unlikely to be a problem in practice, because such
input is malformed in the first place, and because there is
a good chance that the string has an extra NUL terminator
one character after the original (because it formerly had a
newline in it that we parsed off).

We can fix it by using skip_prefix with "import-marks ",
with the space. The other form appears to be a typo from
a515ebe (transport-helper: implement marks location as
capability, 2011-07-16); "import-marks" has never existed
without an argument, and it should match the "export-marks"
definition above.

Speaking of which, we can also use skip_prefix in a few
other places while we are in the function.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

fast-import: fix read of uninitialized argv memoryJeff King Wed, 18 Jun 2014 19:46:15 +0000 (15:46 -0400)

fast-import: fix read of uninitialized argv memory

Fast-import shares code between its command-line parser and
the "option" command. To do so, it strips the "--" from any
command-line options and passes them to the option parser.
However, it does not confirm that the option even begins
with "--" before blindly passing "arg + 2".

It does confirm that the option starts with "-", so the only
affected case was:

git fast-import -

which would read uninitialized memory after the argument. We
can fix it by using skip_prefix and checking the result. As
a bonus, this gets rid of some magic numbers.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

apply: use skip_prefix instead of raw additionJeff King Wed, 18 Jun 2014 19:45:34 +0000 (15:45 -0400)

apply: use skip_prefix instead of raw addition

A submodule diff generally has content like:

-Subproject commit [0-9a-f]{40}
+Subproject commit [0-9a-f]{40}

When we are using "git apply --index" with a submodule, we
first apply the textual diff, and then parse that result to
figure out the new sha1.

If the diff has bogus input like:

-Subproject commit 1234567890123456789012345678901234567890
+bogus

we will parse the "bogus" portion. Our parser assumes that
the buffer starts with "Subproject commit", and blindly
skips past it using strlen(). This can cause us to read
random memory after the buffer.

This problem was unlikely to have come up in practice (since
it requires a malformed diff), and even when it did, we
likely noticed the problem anyway as the next operation was
to call get_sha1_hex on the random memory.

However, we can easily fix it by using skip_prefix to notice
the parsing error.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

refactor skip_prefix to return a booleanJeff King Wed, 18 Jun 2014 19:44:19 +0000 (15:44 -0400)

refactor skip_prefix to return a boolean

The skip_prefix() function returns a pointer to the content
past the prefix, or NULL if the prefix was not found. While
this is nice and simple, in practice it makes it hard to use
for two reasons:

1. When you want to conditionally skip or keep the string
as-is, you have to introduce a temporary variable.
For example:

tmp = skip_prefix(buf, "foo");
if (tmp)
buf = tmp;

2. It is verbose to check the outcome in a conditional, as
you need extra parentheses to silence compiler
warnings. For example:

if ((cp = skip_prefix(buf, "foo"))
/* do something with cp */

Both of these make it harder to use for long if-chains, and
we tend to use starts_with() instead. However, the first line
of "do something" is often to then skip forward in buf past
the prefix, either using a magic constant or with an extra
strlen(3) (which is generally computed at compile time, but
means we are repeating ourselves).

This patch refactors skip_prefix() to return a simple boolean,
and to provide the pointer value as an out-parameter. If the
prefix is not found, the out-parameter is untouched. This
lets you write:

if (skip_prefix(arg, "foo ", &arg))
do_foo(arg);
else if (skip_prefix(arg, "bar ", &arg))
do_bar(arg);

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

cleanup duplicate name_compare() functionsJeremiah Mahler Fri, 20 Jun 2014 02:06:44 +0000 (19:06 -0700)

cleanup duplicate name_compare() functions

We often represent our strings as a counted string, i.e. a pair of
the pointer to the beginning of the string and its length, and the
string may not be NUL terminated to that length.

To compare a pair of such counted strings, unpack-trees.c and
read-cache.c implement their own name_compare() functions
identically. In addition, the cache_name_compare() function in
read-cache.c is nearly identical. The only difference is when one
string is the prefix of the other string, in which case
name_compare() returns -1/+1 to show which one is longer, and
cache_name_compare() returns the difference of the lengths to show
the same information.

Unify these three functions by using the implementation from
cache_name_compare(). This does not make any difference to the
existing and future callers, as they must be paying attention only
to the sign of the returned value (and not the magnitude) because
the original implementations of these two functions return values
returned by memcmp(3) when the one string is not a prefix of the
other string, and the only thing memcmp(3) guarantees its callers is
the sign of the returned value, not the magnitude.

Signed-off-by: Jeremiah Mahler <jmmahler@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

name-hash.c: replace cache_name_compare() with memcmp(3)Jeremiah Mahler Fri, 20 Jun 2014 02:06:43 +0000 (19:06 -0700)

name-hash.c: replace cache_name_compare() with memcmp(3)

The same_name() private function wants a quick-and-exact check to
see if they two names are byte-for-byte identical first and then
fall back to the slow path. Use memcmp(3) for the former to make it
clear that we do not want any "name" specific comparison.

Signed-off-by: Jeremiah Mahler <jmmahler@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

unique_path: fix unlikely heap overflowJeff King Thu, 19 Jun 2014 21:30:26 +0000 (17:30 -0400)

unique_path: fix unlikely heap overflow

When merge-recursive creates a unique filename, it uses a
template like:

path~branch_%d

where the final "_%d" is filled by an incrementing counter
until we find a unique name. We allocate 8 characters for
the counter, but there is no logic to limit the size of the
integer.

Of course, this is extremely unlikely, as you would need a
hundred million collisions to trigger the problem. Even if
an attacker constructed a specialized repo, it is unlikely
that the victim would have the patience to run the merge.

However, we can make it trivially correct (and hopefully
more readable) by using a strbuf.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

walker_fetch: fix minor memory leakJeff King Thu, 19 Jun 2014 21:29:48 +0000 (17:29 -0400)

walker_fetch: fix minor memory leak

We sometimes allocate "msg" on the heap, but will fail to
free it if we hit the failure code path. We can instead keep
a separate variable that is safe to be freed no matter how
we get to the failure code path.

While we're here, we can also do two readability
improvements:

1. Use xstrfmt instead of a manual malloc/sprintf

2. Due to the "maybe we allocate msg, maybe we don't"
strategy, the logic for deciding which message to show
was split into two parts. Since the deallocation is now
pushed onto a separate variable, this is no longer a
concern, and we can keep all of the logic in the same
place.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

merge: use argv_array when spawning merge strategyJeff King Thu, 19 Jun 2014 21:29:31 +0000 (17:29 -0400)

merge: use argv_array when spawning merge strategy

This is shorter, and avoids a rather complicated set of
allocation and free steps.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

sequencer: use argv_array_pushfJeff King Thu, 19 Jun 2014 21:28:20 +0000 (17:28 -0400)

sequencer: use argv_array_pushf

This avoids a manual allocation calculation, and is shorter
to boot.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

setup_git_env: use git_pathdup instead of xmalloc ... Jeff King Thu, 19 Jun 2014 21:28:00 +0000 (17:28 -0400)

setup_git_env: use git_pathdup instead of xmalloc + sprintf

This is shorter, harder to get wrong, and more clearly
captures the intent.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

use xstrfmt to replace xmalloc + strcpy/strcatJeff King Thu, 19 Jun 2014 21:26:56 +0000 (17:26 -0400)

use xstrfmt to replace xmalloc + strcpy/strcat

It's easy to get manual allocation calculations wrong, and
the use of strcpy/strcat raise red flags for people looking
for buffer overflows (though in this case each site was
fine).

It's also shorter to use xstrfmt, and the printf-format
tends to be easier for a reader to see what the final string
will look like.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

use xstrfmt to replace xmalloc + sprintfJeff King Thu, 19 Jun 2014 21:24:33 +0000 (17:24 -0400)

use xstrfmt to replace xmalloc + sprintf

This is one line shorter, and makes sure the length in the
malloc and sprintf steps match.

These conversions are very straightforward; we can drop the
malloc entirely, and replace the sprintf with xstrfmt.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

use xstrdup instead of xmalloc + strcpyJeff King Thu, 19 Jun 2014 21:19:43 +0000 (17:19 -0400)

use xstrdup instead of xmalloc + strcpy

This is one line shorter, and makes sure the length in the
malloc and copy steps match.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

git-submodule.sh: avoid "echo" path-like valuesJunio C Hamano Tue, 10 Jun 2014 15:33:39 +0000 (08:33 -0700)

git-submodule.sh: avoid "echo" path-like values

SysV-derived implementation of "echo" interprets some backslash
sequences as special instruction, e.g. "echo 'ab\c'" shows an
incomplete line with 'a' and 'b' on it. Avoid using it when showing
a path-like values in the script.

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