]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'kb/path-max-must-go'
authorJunio C Hamano <gitster@pobox.com>
Wed, 16 Jul 2014 18:32:33 +0000 (11:32 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 16 Jul 2014 18:32:33 +0000 (11:32 -0700)
* kb/path-max-must-go:
  cache.h: rename cache_def_free to cache_def_clear

341 files changed:
.gitignore
Documentation/CodingGuidelines
Documentation/Makefile
Documentation/RelNotes/2.0.2.txt [new file with mode: 0644]
Documentation/RelNotes/2.1.0.txt [new file with mode: 0644]
Documentation/config.txt
Documentation/diff-config.txt
Documentation/fetch-options.txt
Documentation/git-bisect.txt
Documentation/git-config.txt
Documentation/git-daemon.txt
Documentation/git-fast-export.txt
Documentation/git-fast-import.txt
Documentation/git-fetch.txt
Documentation/git-format-patch.txt
Documentation/git-grep.txt
Documentation/git-help.txt
Documentation/git-ls-files.txt
Documentation/git-merge.txt
Documentation/git-mergetool.txt
Documentation/git-patch-id.txt
Documentation/git-read-tree.txt
Documentation/git-replace.txt
Documentation/git-rev-parse.txt
Documentation/git-send-email.txt
Documentation/git-submodule.txt
Documentation/git-svn.txt
Documentation/git-update-index.txt
Documentation/git-update-ref.txt
Documentation/git-verify-commit.txt [new file with mode: 0644]
Documentation/git-web--browse.txt
Documentation/git.txt
Documentation/gitcli.txt
Documentation/gitk.txt
Documentation/gitrepository-layout.txt
Documentation/gitweb.conf.txt
Documentation/glossary-content.txt
Documentation/howto/keep-canonical-history-correct.txt [new file with mode: 0644]
Documentation/howto/setup-git-server-over-http.txt
Documentation/pull-fetch-param.txt
Documentation/revisions.txt
Documentation/technical/api-argv-array.txt
Documentation/technical/api-builtin.txt
Documentation/technical/api-run-command.txt
Documentation/technical/api-strbuf.txt
Documentation/technical/api-string-list.txt
Documentation/technical/http-protocol.txt
Documentation/technical/index-format.txt
Documentation/user-manual.txt
GIT-VERSION-GEN
Makefile
RelNotes
advice.c
alias.c
alloc.c
argv-array.c
argv-array.h
branch.c
builtin.h
builtin/add.c
builtin/apply.c
builtin/blame.c
builtin/branch.c
builtin/checkout-index.c
builtin/checkout.c
builtin/clone.c
builtin/commit-tree.c
builtin/commit.c
builtin/config.c
builtin/diff-tree.c
builtin/fast-export.c
builtin/fetch.c
builtin/fmt-merge-msg.c
builtin/for-each-ref.c
builtin/fsck.c
builtin/grep.c
builtin/index-pack.c
builtin/log.c
builtin/ls-remote.c
builtin/merge.c
builtin/mv.c
builtin/name-rev.c
builtin/notes.c
builtin/pack-objects.c
builtin/patch-id.c
builtin/push.c
builtin/read-tree.c
builtin/receive-pack.c
builtin/reflog.c
builtin/remote.c
builtin/repack.c
builtin/replace.c
builtin/reset.c
builtin/rev-list.c
builtin/rev-parse.c
builtin/rm.c
builtin/show-branch.c
builtin/tag.c
builtin/update-index.c
builtin/update-ref.c
builtin/verify-commit.c [new file with mode: 0644]
builtin/verify-pack.c
cache-tree.c
cache-tree.h
cache.h
check_bindir
column.c
combine-diff.c
command-list.txt
commit-slab.h
commit.c
commit.h
compat/bswap.h
compat/mingw.c
compat/mingw.h
compat/poll/poll.c
compat/win32/alloca.h [moved from compat/vcbuild/include/alloca.h with 100% similarity]
compat/win32/dirent.c
compat/win32/dirent.h
compat/winansi.c
config.c
config.mak.uname
configure.ac
connect.c
connected.c
contrib/completion/git-completion.bash
contrib/credential/wincred/Makefile
contrib/diffall/README [deleted file]
contrib/diffall/git-diffall [deleted file]
contrib/examples/builtin-fetch--tool.c
contrib/examples/git-clone.sh
contrib/examples/git-commit.sh
contrib/examples/git-merge.sh
contrib/examples/git-repack.sh
contrib/examples/git-resolve.sh
contrib/mw-to-git/git-remote-mediawiki.perl
contrib/mw-to-git/t/install-wiki.sh
contrib/mw-to-git/t/t9363-mw-to-git-export-import.sh
contrib/mw-to-git/t/t9365-continuing-queries.sh
contrib/mw-to-git/t/test-gitmw-lib.sh
contrib/subtree/Makefile
contrib/subtree/git-subtree.sh
contrib/subtree/t/t7900-subtree.sh
contrib/svn-fe/svnrdump_sim.py
contrib/thunderbird-patch-inline/appp.sh
contrib/vim/README [deleted file]
convert.c
credential-cache--daemon.c
credential.c
daemon.c
diff.c
diff.h
dir.c
entry.c
environment.c
ewah/ewah_io.c
ewah/ewok.h
fast-import.c
fetch-pack.c
fsck.c
git-bisect.sh
git-compat-util.h
git-filter-branch.sh
git-gui/git-gui.sh
git-gui/lib/diff.tcl
git-instaweb.sh
git-mergetool.sh
git-p4.py
git-pull.sh
git-rebase--interactive.sh
git-rebase--merge.sh
git-rebase.sh
git-remote-testgit.sh
git-send-email.perl
git-sh-setup.sh
git-stash.sh
git-submodule.sh
git-web--browse.sh
git.c
gitk-git/gitk
gitk-git/po/vi.po [new file with mode: 0644]
gpg-interface.c
gpg-interface.h
grep.c
help.c
http-backend.c
http-push.c
http-walker.c
http.c
http.h
imap-send.c
line-log.c
lockfile.c
log-tree.c
match-trees.c
merge-recursive.c
merge.c
mergetools/gvimdiff3 [new file with mode: 0644]
mergetools/vimdiff
mergetools/vimdiff3 [new file with mode: 0644]
name-hash.c
notes-cache.c
notes-merge.c
notes-utils.c
notes-utils.h
notes.c
object.c
pack-revindex.c
pager.c
parse-options.c
parse-options.h
path.c
perl/Git/SVN.pm
perl/Git/SVN/Log.pm
pretty.c
read-cache.c
reflog-walk.c
refs.c
refs.h
remote-curl.c
remote.c
rerere.c
resolve-undo.c
revision.c
run-command.c
run-command.h
sequencer.c
sha1_file.c
sha1_name.c
shell.c
split-index.c [new file with mode: 0644]
split-index.h [new file with mode: 0644]
strbuf.c
strbuf.h
string-list.h
submodule.c
t/README
t/check-non-portable-shell.pl
t/lib-credential.sh
t/lib-cvs.sh
t/lib-gpg.sh
t/lib-httpd.sh
t/lib-httpd/apache.conf
t/lib-httpd/broken-smart-http.sh [changed mode: 0755->0644]
t/lib-httpd/error.sh [new file with mode: 0755]
t/perf/p5302-pack-index.sh
t/perf/p5310-pack-bitmaps.sh
t/t0000-basic.sh
t/t0001-init.sh
t/t0008-ignores.sh
t/t0010-racy-git.sh
t/t0020-crlf.sh
t/t0021-conversion.sh
t/t0025-crlf-auto.sh
t/t0026-eol-config.sh
t/t0027-auto-crlf.sh [new file with mode: 0755]
t/t0030-stripspace.sh
t/t0300-credentials.sh
t/t1000-read-tree-m-3way.sh
t/t1001-read-tree-m-2way.sh
t/t1002-read-tree-m-u-2way.sh
t/t1003-read-tree-prefix.sh
t/t1004-read-tree-m-u-wf.sh
t/t1020-subdirectory.sh
t/t1050-large.sh
t/t1300-repo-config.sh
t/t1400-update-ref.sh
t/t1402-check-ref-format.sh
t/t1410-reflog.sh
t/t1700-split-index.sh [new file with mode: 0755]
t/t2104-update-index-skip-worktree.sh
t/t3032-merge-recursive-options.sh
t/t3302-notes-index-expensive.sh
t/t3402-rebase-merge.sh
t/t3404-rebase-interactive.sh
t/t3419-rebase-patch-id.sh
t/t3508-cherry-pick-many-commits.sh
t/t3905-stash-include-untracked.sh
t/t3910-mac-os-precompose.sh
t/t4006-diff-mode.sh
t/t4010-diff-pathspec.sh
t/t4012-diff-binary.sh
t/t4013-diff-various.sh
t/t4014-format-patch.sh
t/t4036-format-patch-signer-mime.sh
t/t4038-diff-combined.sh
t/t4057-diff-combined-paths.sh
t/t4102-apply-rename.sh
t/t4116-apply-reverse.sh
t/t4119-apply-config.sh
t/t4204-patch-id.sh
t/t5000-tar-tree.sh
t/t5001-archive-attr.sh
t/t5003-archive-zip.sh
t/t5004-archive-corner-cases.sh
t/t5150-request-pull.sh
t/t5310-pack-bitmaps.sh
t/t5403-post-checkout-hook.sh
t/t5510-fetch.sh
t/t5511-refspec.sh
t/t5550-http-fetch-dumb.sh
t/t5551-http-fetch-smart.sh
t/t5560-http-backend-noserver.sh
t/t5801-remote-helpers.sh
t/t6006-rev-list-format.sh
t/t6023-merge-file.sh
t/t6050-replace.sh
t/t7003-filter-branch.sh
t/t7004-tag.sh
t/t7501-commit.sh
t/t7502-commit.sh
t/t7508-status.sh
t/t7510-signed-commit.sh
t/t7700-repack.sh
t/t7800-difftool.sh
t/t7810-grep.sh
t/t9001-send-email.sh
t/t9138-git-svn-authors-prog.sh
t/t9300-fast-import.sh
t/t9350-fast-export.sh
t/t9807-git-p4-submit.sh
t/t9814-git-p4-rename.sh
t/t9902-completion.sh
t/test-lib-functions.sh
t/test-lib.sh
t/valgrind/default.supp
test-dump-cache-tree.c
test-dump-split-index.c [new file with mode: 0644]
test-scrap-cache-tree.c
transport-helper.c
transport.c
tree-diff.c
tree-walk.c
unicode_width.h [new file with mode: 0644]
unpack-trees.c
update_unicode.sh [new file with mode: 0755]
urlmatch.c
utf8.c
walker.c
wt-status.c
xdiff/xmerge.c

index dc600f9b36d09f0668064e044520c7ce633f09d8..81e12c0621d42b495ab540391e1cd8ece18587b7 100644 (file)
 /git-upload-archive
 /git-upload-pack
 /git-var
+/git-verify-commit
 /git-verify-pack
 /git-verify-tag
 /git-web--browse
 /test-date
 /test-delta
 /test-dump-cache-tree
+/test-dump-split-index
 /test-scrap-cache-tree
 /test-genrandom
 /test-hashmap
 /config.mak.autogen
 /config.mak.append
 /configure
+/unicode
 /tags
 /TAGS
 /cscope*
index f424dbd75c80abb4d6fecce18f6fc25859bdcb00..4d90c77c7bd643b11df8d3094efe142493df53b9 100644 (file)
@@ -18,6 +18,14 @@ code.  For Git in general, three rough rules are:
    judgement call, the decision based more on real world
    constraints people face than what the paper standard says.
 
+ - Fixing style violations while working on a real change as a
+   preparatory clean-up step is good, but otherwise avoid useless code
+   churn for the sake of conforming to the style.
+
+   "Once it _is_ in the tree, it's not really worth the patch noise to
+   go and fix it up."
+   Cf. http://article.gmane.org/gmane.linux.kernel/943020
+
 Make your code readable and sensible, and don't try to be clever.
 
 As for more concrete guidelines, just imitate the existing code
@@ -34,7 +42,17 @@ For shell scripts specifically (not exhaustive):
 
  - We use tabs for indentation.
 
- - Case arms are indented at the same depth as case and esac lines.
+ - Case arms are indented at the same depth as case and esac lines,
+   like this:
+
+       case "$variable" in
+       pattern1)
+               do this
+               ;;
+       pattern2)
+               do that
+               ;;
+       esac
 
  - Redirection operators should be written with space before, but no
    space after them.  In other words, write 'echo test >"$file"'
@@ -43,6 +61,14 @@ For shell scripts specifically (not exhaustive):
    redirection target in a variable (as shown above), our code does so
    because some versions of bash issue a warning without the quotes.
 
+       (incorrect)
+       cat hello > world < universe
+       echo hello >$world
+
+       (correct)
+       cat hello >world <universe
+       echo hello >"$world"
+
  - We prefer $( ... ) for command substitution; unlike ``, it
    properly nests.  It should have been the way Bourne spelled
    it from day one, but unfortunately isn't.
@@ -81,14 +107,33 @@ For shell scripts specifically (not exhaustive):
    "then" should be on the next line for if statements, and "do"
    should be on the next line for "while" and "for".
 
+       (incorrect)
+       if test -f hello; then
+               do this
+       fi
+
+       (correct)
+       if test -f hello
+       then
+               do this
+       fi
+
  - We prefer "test" over "[ ... ]".
 
  - We do not write the noiseword "function" in front of shell
    functions.
 
- - We prefer a space between the function name and the parentheses. The
-   opening "{" should also be on the same line.
-   E.g.: my_function () {
+ - We prefer a space between the function name and the parentheses,
+   and no space inside the parentheses. The opening "{" should also
+   be on the same line.
+
+       (incorrect)
+       my_function(){
+               ...
+
+       (correct)
+       my_function () {
+               ...
 
  - As to use of grep, stick to a subset of BRE (namely, no \{m,n\},
    [::], [==], or [..]) for portability.
@@ -106,6 +151,19 @@ For shell scripts specifically (not exhaustive):
    interface translatable. See "Marking strings for translation" in
    po/README.
 
+ - We do not write our "test" command with "-a" and "-o" and use "&&"
+   or "||" to concatenate multiple "test" commands instead, because
+   the use of "-a/-o" is often error-prone.  E.g.
+
+     test -n "$x" -a "$a" = "$b"
+
+   is buggy and breaks when $x is "=", but
+
+     test -n "$x" && test "$a" = "$b"
+
+   does not have such a problem.
+
+
 For C programs:
 
  - We use tabs to indent, and interpret tabs as taking up to
@@ -149,7 +207,7 @@ For C programs:
    of "else if" statements, it can make sense to add braces to
    single line blocks.
 
- - We try to avoid assignments inside if().
+ - We try to avoid assignments in the condition of an "if" statement.
 
  - Try to make your code understandable.  You may put comments
    in, but comments invariably tend to stale out when the code
@@ -177,6 +235,88 @@ For C programs:
  - Double negation is often harder to understand than no negation
    at all.
 
+ - There are two schools of thought when it comes to comparison,
+   especially inside a loop. Some people prefer to have the less stable
+   value on the left hand side and the more stable value on the right hand
+   side, e.g. if you have a loop that counts variable i down to the
+   lower bound,
+
+       while (i > lower_bound) {
+               do something;
+               i--;
+       }
+
+   Other people prefer to have the textual order of values match the
+   actual order of values in their comparison, so that they can
+   mentally draw a number line from left to right and place these
+   values in order, i.e.
+
+       while (lower_bound < i) {
+               do something;
+               i--;
+       }
+
+   Both are valid, and we use both.  However, the more "stable" the
+   stable side becomes, the more we tend to prefer the former
+   (comparison with a constant, "i > 0", is an extreme example).
+   Just do not mix styles in the same part of the code and mimic
+   existing styles in the neighbourhood.
+
+ - There are two schools of thought when it comes to splitting a long
+   logical line into multiple lines.  Some people push the second and
+   subsequent lines far enough to the right with tabs and align them:
+
+        if (the_beginning_of_a_very_long_expression_that_has_to ||
+               span_more_than_a_single_line_of ||
+               the_source_text) {
+                ...
+
+   while other people prefer to align the second and the subsequent
+   lines with the column immediately inside the opening parenthesis,
+   with tabs and spaces, following our "tabstop is always a multiple
+   of 8" convention:
+
+        if (the_beginning_of_a_very_long_expression_that_has_to ||
+           span_more_than_a_single_line_of ||
+           the_source_text) {
+                ...
+
+   Both are valid, and we use both.  Again, just do not mix styles in
+   the same part of the code and mimic existing styles in the
+   neighbourhood.
+
+ - When splitting a long logical line, some people change line before
+   a binary operator, so that the result looks like a parse tree when
+   you turn your head 90-degrees counterclockwise:
+
+        if (the_beginning_of_a_very_long_expression_that_has_to
+           || span_more_than_a_single_line_of_the_source_text) {
+
+   while other people prefer to leave the operator at the end of the
+   line:
+
+        if (the_beginning_of_a_very_long_expression_that_has_to ||
+           span_more_than_a_single_line_of_the_source_text) {
+
+   Both are valid, but we tend to use the latter more, unless the
+   expression gets fairly complex, in which case the former tends to
+   be easier to read.  Again, just do not mix styles in the same part
+   of the code and mimic existing styles in the neighbourhood.
+
+ - When splitting a long logical line, with everything else being
+   equal, it is preferable to split after the operator at higher
+   level in the parse tree.  That is, this is more preferable:
+
+       if (a_very_long_variable * that_is_used_in +
+           a_very_long_expression) {
+               ...
+
+   than
+
+       if (a_very_long_variable *
+           that_is_used_in + a_very_long_expression) {
+               ...
+
  - Some clever tricks, like using the !! operator with arithmetic
    constructs, can be extremely confusing to others.  Avoid them,
    unless there is a compelling reason to use them.
index fc6b2cf9ec0d2582b89d65ab6976275c4756bca5..cea0e7ae3db37dcd366e094abdd2a2f32514a247 100644 (file)
@@ -59,6 +59,7 @@ SP_ARTICLES += howto/recover-corrupted-blob-object
 SP_ARTICLES += howto/recover-corrupted-object-harder
 SP_ARTICLES += howto/rebuild-from-update-hook
 SP_ARTICLES += howto/rebase-from-internal-branch
+SP_ARTICLES += howto/keep-canonical-history-correct
 SP_ARTICLES += howto/maintain-git
 API_DOCS = $(patsubst %.txt,%,$(filter-out technical/api-index-skel.txt technical/api-index.txt, $(wildcard technical/api-*.txt)))
 SP_ARTICLES += $(API_DOCS)
diff --git a/Documentation/RelNotes/2.0.2.txt b/Documentation/RelNotes/2.0.2.txt
new file mode 100644 (file)
index 0000000..c48c0aa
--- /dev/null
@@ -0,0 +1,13 @@
+Git v2.0.2 Release Notes
+========================
+
+ * Documentation for "git submodule sync" forgot to say that the subcommand
+   can take the "--recursive" option.
+
+ * Mishandling of patterns in .gitignore that has trailing SPs quoted
+   with backslashes (e.g. ones that end with "\ ") have been
+   corrected.
+
+ * Recent updates to "git repack" started to duplicate objects that
+   are in packfiles marked with .keep flag into the new packfile by
+   mistake.
diff --git a/Documentation/RelNotes/2.1.0.txt b/Documentation/RelNotes/2.1.0.txt
new file mode 100644 (file)
index 0000000..3b65461
--- /dev/null
@@ -0,0 +1,341 @@
+Git v2.1 Release Notes
+======================
+
+Backward compatibility notes
+----------------------------
+
+ * The default value we give to the environment variable LESS has been
+   changed from "FRSX" to "FRX", losing "S" (chop long lines instead
+   of wrapping).  Existing users who prefer not to see line-wrapped
+   output may want to set
+
+     $ git config core.pager "less -S"
+
+   to restore the traditional behaviour.  It is expected that people
+   find output from the most subcommands easier to read with the new
+   default, except for "blame" which tends to produce really long
+   lines.  To override the new default only for "git blame", you can
+   do this:
+
+     $ git config pager.blame "less -S"
+
+ * A few disused directories in contrib/ have been retired.
+
+
+Updates since v2.0
+------------------
+
+UI, Workflows & Features
+
+ * Since the very beginning of Git, we gave the LESS environment a
+   default value "FRSX" when we spawn "less" as the pager.  "S" (chop
+   long lines instead of wrapping) has been removed from this default
+   set of options, because it is more or less a personal taste thing,
+   as opposed to others that have good justifications (i.e. "R" is
+   very much justified because many kinds of output we produce are
+   colored and "FX" is justified because output we produce is often
+   shorter than a page).
+
+ * The logic and data used to compute the display width needed for
+   UTF-8 strings have been updated to match Unicode 7.0 better.
+
+ * HTTP-based transports learned to propagate the error messages from
+   the webserver better to the client coming over the HTTP transport.
+
+ * The completion script for bash (in contrib/) has been updated to
+   handle aliases that define complex sequence of commands better.
+
+ * The "core.preloadindex" configuration variable is by default
+   enabled, allowing modern platforms to take advantage of the
+   multiple cores they have.
+
+ * "git commit --date=<date>" option learned to read from more
+   timestamp formats, including "--date=now".
+
+ * The `core.commentChar` configuration variable is used to specify a
+   custom comment character other than the default "#" to be used in
+   the commit log editor.  This can be set to `auto` to attempt to
+   choose a different character that does not conflict with what
+   already starts a line in the message being edited for cases like
+   "git commit --amend".
+
+ * "git format-patch" learned --signature-file=<file> to take the mail
+   signature from.
+
+ * "git grep" learned grep.fullname configuration variable to force
+   "--full-name" to be default.  This may cause regressions on
+   scripted users that do not expect this new behaviour.
+
+ * "git imap-send" learned to ask the credential helper for auth
+   material.
+
+ * "git log" and friends now understand the value "auto" set to the
+   "log.decorate" configuration variable to enable the "--decorate"
+   option automatically when the output is sent to tty.
+
+ * "git merge" without argument, even when there is an upstream
+   defined for the current branch, refused to run until
+   merge.defaultToUpstream is set to true.  Flip the default of that
+   configuration variable to true.
+
+ * "git mergetool" learned to drive the vimdiff3 backend.
+
+ * mergetool.prompt used to default to 'true', always asking "do you
+   really want to run the tool on this path?".  Among the two
+   purposes this prompt serves, ignore the use case to confirm that
+   the user wants to view particular path with the named tool, and
+   redefine the meaning of the prompt only to confirm the choice of
+   the tool made by the autodetection (for those who configured the
+   tool explicitly, the prompt shown for the latter purpose is
+   simply annoying).
+
+   Strictly speaking, this is a backward incompatible change and the
+   users need to explicitly set the variable to 'true' if they want
+   to resurrect the now-ignored use case.
+
+ * "git replace" learned the "--edit" subcommand.
+
+ * "git send-email" learned "--to-cover" and "--cc-cover" options, to
+   tell it to copy To: and Cc: headers found in the first input file
+   when emitting later input files.
+
+ * "git svn" learned to cope with malformed timestamps with only one
+   digit in the hour part, e.g. 2014-01-07T5:01:02.048176Z, emitted
+   by some broken subversion server implementations.
+
+ * "git tag" when editing the tag message shows the name of the tag
+   being edited as a comment in the editor.
+
+ * "git verify-commit" command to check GPG signature in signed
+   commits, in a way similar to "git verify-tag" is used to check
+   signed tags, was added.
+
+
+Performance, Internal Implementation, etc.
+
+ * Build procedure for 'subtree' (in contrib/) has been cleaned up.
+
+ * Effort to shrink the size of patches Windows folks maintain on top
+   by upstreaming them continues.
+
+ * Patches maintained by msysgit folks for Windows port are being
+   upstreamed here a bit by bit.
+
+ * The leaf function to check validity of a refname format has been
+   micro-optimized, using SSE2 instructions when available.  A few
+   breakages during its development have been caught and fixed already
+   but there might remain some more still; please test and report if
+   you find any.
+
+ * The `core.deltabasecachelimit` used to default to 16 MiB , but this
+   proved to be too small, and has been bumped to 96 MiB.
+
+ * "git blame" has been optimized greatly by reorganising the data
+   structure that is used to keep track of the work to be done.
+
+ * "git diff" that compares 3-or-more trees (e.g. parents and the
+   result of a merge) have been optimized.
+
+ * The API to update/delete references are being converted to handle
+   updates to multiple references in a transactional way.  As an
+   example, "update-ref --stdin [-z]" has been updated to use this
+   API.
+
+ * Parts of the test scripts can be skipped by using a range notation,
+   e.g. "sh t1234-test.sh --run='1-4 6 8-'" to omit test piece 5 and 7
+   and run everything else.
+
+
+Also contains various documentation updates and code clean-ups.
+
+
+Fixes since v2.0
+----------------
+
+Unless otherwise noted, all the fixes since v2.0 in the maintenance
+track are contained in this release (see the maintenance releases'
+notes for details).
+
+ * 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.
+   (merge c0459ca je/pager-do-not-recurse later to 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.
+   (merge 38de156 mn/sideband-no-ansi later to maint).
+
+ * Mishandling of patterns in .gitignore that has trailing SPs quoted
+   with backslashes (e.g. ones that end with "\ ") have been
+   corrected.
+   (merge 97c1364be6b pb/trim-trailing-spaces later to 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.
+   (merge d6c8a05 jk/report-fail-to-read-objects-better later to 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.
+   (merge e3fa568 jc/revision-dash-count-parsing later to maint).
+
+ * Code to avoid adding the same alternate object store twice was
+   subtly broken for a long time, but nobody seems to have noticed.
+   (merge 80b4785 rs/fix-alt-odb-path-comparison later to 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.
+   (merge 7d50987 as/pretty-truncate later to maint).
+
+ * "%G" (nothing after G) is an invalid pretty format specifier, but
+   the parser did not notice it as garbage.
+   (merge 958b2eb jk/pretty-G-format-fixes later to maint).
+
+ * A handful of code paths had to read the commit object more than
+   once when showing header fields that are usually not parsed.  The
+   internal data structure to keep track of the contents of the commit
+   object has been updated to reduce the need for this double-reading,
+   and to allow the caller find the length of the object.
+   (merge 218aa3a jk/commit-buffer-length later to maint).
+
+ * The "mailmap.file" configuration option did not support the tilde
+   expansion (i.e. ~user/path and ~/path).
+   (merge 9352fd5 ow/config-mailmap-pathname later to 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".
+   (merge 8fee872 jk/complete-merge-pull later to 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.
+   (merge 14d3bb4 jc/apply-ignore-whitespace later to 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.
+   (merge dd75553 jx/blame-align-relative-time later to 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.
+   (merge 4d4813a bc/blame-crlf-test later to maint).
+
+ * "git clone -b brefs/tags/bar" would have mistakenly thought we were
+   following a single tag, even though it was a name of the branch,
+   because it incorrectly used strstr().
+   (merge 60a5f5f jc/fix-clone-single-starting-at-a-tag later to maint).
+
+ * "git commit --allow-empty-messag -C $commit" did not work when the
+   commit did not have any log message.
+   (merge 076cbd6 jk/commit-C-pick-empty later to maint).
+
+ * "git diff --find-copies-harder" sometimes pretended as if the mode
+   bits have changed for paths that are marked with assume-unchanged
+   bit.
+   (merge 5304810 jk/diff-files-assume-unchanged later to 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.
+   (merge dd63f16 jk/diff-follow-must-take-one-pathspec later to 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.
+   (merge 62aad18 nd/daemonize-gc later to 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).
+   (merge f7febbe sk/spawn-less-case-insensitively-from-grep-O-i later to 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".
+   (merge 3953949 nd/index-pack-one-fd-per-thread later to maint).
+
+ * The error reporting from "git index-pack" has been improved to
+   distinguish missing objects from type errors.
+   (merge 77583e7 jk/index-pack-report-missing later to maint).
+
+ * "git mailinfo" used to read beyond the end of header string while
+   parsing an incoming e-mail message to extract the patch.
+   (merge b1a013d rs/mailinfo-header-cmp later to 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.
+   (merge baa37bf dt/merge-recursive-case-insensitive later to maint).
+
+ * "git pack-objects" unnecessarily copied the previous contents when
+   extending the hashtable, even though it will populate the table
+   from scratch anyway.
+   (merge fb79947 rs/pack-objects-no-unnecessary-realloc later to maint).
+
+ * Recent updates to "git repack" started to duplicate objects that
+   are in packfiles marked with .keep flag into the new packfile by
+   mistake.
+   (merge d078d85 jk/repack-pack-keep-objects later to maint).
+
+ * "git rerere forget" did not work well when merge.conflictstyle
+   was set to a non-default value.
+   (merge de3d8bb fc/rerere-conflict-style later to 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.
+   (merge e6bea66 jl/remote-rm-prune later to 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.
+   (merge eb07774 jc/shortlog-ref-exclude later to 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.
+   (merge ddb5432 rr/rebase-autostash-fix later to maint).
+
+ * During "git rebase --merge", a conflicted patch could not be
+   skipped with "--skip" if the next one also conflicted.
+   (merge 95104c7 bc/fix-rebase-merge-skip later to maint).
+
+ * "git show -s" (i.e. show log message only) used to incorrectly emit
+   an extra blank line after a merge commit.
+   (merge ad2f725 mk/show-s-no-extra-blank-line-for-merges later to 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.
+   (merge 426ddee ym/fix-opportunistic-index-update-race later to 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.
+   (merge c215d3d jl/status-added-submodule-is-never-ignored later to maint).
+
+ * Documentation for "git submodule sync" forgot to say that the subcommand
+   can take the "--recursive" option.
+   (merge 9393ae7 mc/doc-submodule-sync-recurse later to maint).
+
+ * "git update-index --cacheinfo" in 2.0 release crashed on a
+   malformed command line.
+   (merge c8e1ee4 jc/rev-parse-argh-dashed-multi-words later to maint).
+
+ * The mode to run tests with HTTP server tests disabled was broken.
+   (merge afa53fe na/no-http-test-in-the-middle later to maint).
index c08286e968ad057c288b72f77e877f42a640ae5f..1d718bdb9662735d9b446033607c5f2aa92f8a78 100644 (file)
@@ -381,7 +381,7 @@ false), while all other repositories are assumed to be bare (bare
 core.worktree::
        Set the path to the root of the working tree.
        This can be overridden by the GIT_WORK_TREE environment
-       variable and the '--work-tree' command line option.
+       variable and the '--work-tree' command-line option.
        The value can be an absolute path or relative to the path to
        the .git directory, which is either specified by --git-dir
        or GIT_DIR, or automatically discovered.
@@ -489,7 +489,7 @@ core.deltaBaseCacheLimit::
        to avoid unpacking and decompressing frequently used base
        objects multiple times.
 +
-Default is 16 MiB on all platforms.  This should be reasonable
+Default is 96 MiB on all platforms.  This should be reasonable
 for all users/operating systems, except on the largest projects.
 You probably do not need to adjust this value.
 +
@@ -523,7 +523,7 @@ core.askpass::
        environment variable. If not set, fall back to the value of the
        'SSH_ASKPASS' environment variable or, failing that, a simple password
        prompt. The external program shall be given a suitable prompt as
-       command line argument and write the password on its STDOUT.
+       command-line argument and write the password on its STDOUT.
 
 core.attributesfile::
        In addition to '.gitattributes' (per-directory) and
@@ -544,6 +544,9 @@ core.commentchar::
        messages consider a line that begins with this character
        commented, and removes them after the editor returns
        (default '#').
++
+If set to "auto", `git-commit` would select a character that is not
+the beginning character of any line in existing commit messages.
 
 sequence.editor::
        Text editor used by `git rebase -i` for editing the rebase instruction file.
@@ -558,14 +561,19 @@ core.pager::
        configuration, then `$PAGER`, and then the default chosen at
        compile time (usually 'less').
 +
-When the `LESS` environment variable is unset, Git sets it to `FRSX`
+When the `LESS` environment variable is unset, Git sets it to `FRX`
 (if `LESS` environment variable is set, Git does not change it at
 all).  If you want to selectively override Git's default setting
-for `LESS`, you can set `core.pager` to e.g. `less -+S`.  This will
+for `LESS`, you can set `core.pager` to e.g. `less -S`.  This will
 be passed to the shell by Git, which will translate the final
-command to `LESS=FRSX less -+S`. The environment tells the command
-to set the `S` option to chop long lines but the command line
-resets it to the default to fold long lines.
+command to `LESS=FRX less -S`. The environment does not set the
+`S` option but the command line does, instructing less to truncate
+long lines. Similarly, setting `core.pager` to `less -+F` will
+deactivate the `F` option specified by the environment from the
+command-line, deactivating the "quit if one screen" behavior of
+`less`.  One can specifically activate some flags for particular
+commands: for example, setting `pager.blame` to `less -S` enables
+line truncation only for `git blame`.
 +
 Likewise, when the `LV` environment variable is unset, Git sets it
 to `-c`.  You can override this setting by exporting `LV` with
@@ -613,9 +621,9 @@ core.preloadindex::
 +
 This can speed up operations like 'git diff' and 'git status' especially
 on filesystems like NFS that have weak caching semantics and thus
-relatively high IO latencies.  With this set to 'true', Git will do the
+relatively high IO latencies.  When enabled, Git will do the
 index comparison to the filesystem data in parallel, allowing
-overlapping IO's.
+overlapping IO's.  Defaults to true.
 
 core.createObject::
        You can set this to 'link', in which case a hardlink followed by
@@ -1114,6 +1122,10 @@ format.signature::
        Set this variable to the empty string ("") to suppress
        signature generation.
 
+format.signaturefile::
+       Works just like format.signature except the contents of the
+       file specified by this variable will be used as the signature.
+
 format.suffix::
        The default for format-patch is to output files with the suffix
        `.patch`. Use this variable to change that suffix (make sure to
@@ -1324,7 +1336,7 @@ grep.extendedRegexp::
 gpg.program::
        Use this custom program instead of "gpg" found on $PATH when
        making or verifying a PGP signature. The program must support the
-       same command line interface as GPG, namely, to verify a detached
+       same command-line interface as GPG, namely, to verify a detached
        signature, "gpg --verify $file - <$signature" is run, and the
        program is expected to signal a good signature by exiting with
        code 0, and to generate an ascii-armored detached signature, the
@@ -1893,12 +1905,7 @@ pack.useBitmaps::
        you are debugging pack bitmaps.
 
 pack.writebitmaps::
-       When true, git will write a bitmap index when packing all
-       objects to disk (e.g., when `git repack -a` is run).  This
-       index can speed up the "counting objects" phase of subsequent
-       packs created for clones and fetches, at the cost of some disk
-       space and extra time spent on the initial repack.  Defaults to
-       false.
+       This is a deprecated synonym for `repack.writeBitmaps`.
 
 pack.writeBitmapHashCache::
        When true, git will include a "hash cache" section in the bitmap
@@ -2175,7 +2182,15 @@ repack.packKeptObjects::
        `--pack-kept-objects` was passed. See linkgit:git-repack[1] for
        details. Defaults to `false` normally, but `true` if a bitmap
        index is being written (either via `--write-bitmap-index` or
-       `pack.writeBitmaps`).
+       `repack.writeBitmaps`).
+
+repack.writeBitmaps::
+       When true, git will write a bitmap index when packing all
+       objects to disk (e.g., when `git repack -a` is run).  This
+       index can speed up the "counting objects" phase of subsequent
+       packs created for clones and fetches, at the cost of some disk
+       space and extra time spent on the initial repack.  Defaults to
+       false.
 
 rerere.autoupdate::
        When set to true, `git-rerere` updates the index with the
@@ -2297,7 +2312,7 @@ status.submodulesummary::
        exception to that rule is that status and commit will show staged
        submodule changes. To
        also view the summary for ignored submodules you can either use
-       the --ignore-submodules=dirty command line option or the 'git
+       the --ignore-submodules=dirty command-line option or the 'git
        submodule summary' command, which shows a similar output but does
        not honor these settings.
 
@@ -2319,7 +2334,7 @@ submodule.<name>.branch::
 submodule.<name>.fetchRecurseSubmodules::
        This option can be used to control recursive fetching of this
        submodule. It can be overridden by using the --[no-]recurse-submodules
-       command line option to "git fetch" and "git pull".
+       command-line option to "git fetch" and "git pull".
        This setting will override that from in the linkgit:gitmodules[5]
        file.
 
index f07b4513ed76978e3bb7ef02ebf31d504f7098ff..b0017795208d971eb40001ff20bd2516c8d9a58e 100644 (file)
@@ -76,7 +76,7 @@ diff.ignoreSubmodules::
        this setting when reporting uncommitted changes. Setting it to
        'all' disables the submodule summary normally shown by 'git commit'
        and 'git status' when 'status.submodulesummary' is set unless it is
-       overridden by using the --ignore-submodules command line option.
+       overridden by using the --ignore-submodules command-line option.
        The 'git submodule' commands are not affected by this setting.
 
 diff.mnemonicprefix::
index 92c68c3fdabafd9ac5afe74256dbd2d56218c247..b09a783ee313bf67cb07db03bb3127d252ab70c3 100644 (file)
@@ -72,6 +72,14 @@ endif::git-pull[]
        setting. See linkgit:git-config[1].
 
 ifndef::git-pull[]
+--refmap=<refspec>::
+       When fetching refs listed on the command line, use the
+       specified refspec (can be given more than once) to map the
+       refs to remote-tracking branches, instead of the values of
+       `remote.*.fetch` configuration variables for the remote
+       repository.  See section on "Configured Remote-tracking
+       Branches" for details.
+
 -t::
 --tags::
        Fetch all tags from the remote (i.e., fetch remote tags
index f986c5cb3a09989aebefcd9ba28f419280ffc544..4cb52a7302077e17d5a05983a5e6c924b4694194 100644 (file)
@@ -117,7 +117,7 @@ $ git bisect visualize
 `view` may also be used as a synonym for `visualize`.
 
 If the 'DISPLAY' environment variable is not set, 'git log' is used
-instead.  You can also give command line options such as `-p` and
+instead.  You can also give command-line options such as `-p` and
 `--stat`.
 
 ------------
index e9917b89a91b36c87892ea1c08522f17be3c0d89..9dfa1a5ce265eacd64febc3775cb05525b58d7f0 100644 (file)
@@ -256,7 +256,7 @@ All writing options will per default write to the repository specific
 configuration file. Note that this also affects options like '--replace-all'
 and '--unset'. *'git config' will only ever change one file at a time*.
 
-You can override these rules either by command line options or by environment
+You can override these rules either by command-line options or by environment
 variables. The '--global' and the '--system' options will limit the file used
 to the global or system-wide file respectively. The GIT_CONFIG environment
 variable has a similar effect, but you can specify any filename you want.
index 223f7315236be845a158f63d5909804f965837ba..a69b3616ec3bdc9686114f4d0b7a851c0ce93339 100644 (file)
@@ -169,7 +169,7 @@ Git configuration files in that directory are readable by `<user>`.
 --forbid-override=<service>::
        Allow/forbid overriding the site-wide default with per
        repository configuration.  By default, all the services
-       are overridable.
+       may be overridden.
 
 --[no-]informative-errors::
        When informative errors are turned on, git-daemon will report
@@ -184,7 +184,7 @@ Git configuration files in that directory are readable by `<user>`.
        Every time a client connects, first run an external command
        specified by the <path> with service name (e.g. "upload-pack"),
        path to the repository, hostname (%H), canonical hostname
-       (%CH), ip address (%IP), and tcp port (%P) as its command line
+       (%CH), IP address (%IP), and TCP port (%P) as its command-line
        arguments. The external command can decide to decline the
        service by exiting with a non-zero status (or to allow it by
        exiting with a zero status).  It can also look at the $REMOTE_ADDR
@@ -204,7 +204,7 @@ SERVICES
 --------
 
 These services can be globally enabled/disabled using the
-command line options of this command.  If a finer-grained
+command-line options of this command.  If finer-grained
 control is desired (e.g. to allow 'git archive' to be run
 against only in a few selected repositories the daemon serves),
 the per-repository configuration file can be used to enable or
index 85f1f30fdf5c0a741c3c575bfa393fc7d88d308f..221506b04ba55fac2151d8ac95da7df57eb9d411 100644 (file)
@@ -105,6 +105,10 @@ marks the same across runs.
        in the commit (as opposed to just listing the files which are
        different from the commit's first parent).
 
+--refspec::
+       Apply the specified refspec to each ref exported. Multiple of them can
+       be specified.
+
 [<git-rev-list-args>...]::
        A list of arguments, acceptable to 'git rev-parse' and
        'git rev-list', that specifies the specific objects and references
index fd22a9a0c1312382a972a39e06063e7ff77b027d..377eeaa36db2407f76a9cd21777bb2eda4ff74bc 100644 (file)
@@ -231,7 +231,7 @@ Date Formats
 ~~~~~~~~~~~~
 The following date formats are supported.  A frontend should select
 the format it will use for this import by passing the format name
-in the \--date-format=<fmt> command line option.
+in the \--date-format=<fmt> command-line option.
 
 `raw`::
        This is the Git native format and is `<time> SP <offutc>`.
@@ -348,7 +348,7 @@ and control the current import process.  More detailed discussion
 `done`::
        Marks the end of the stream. This command is optional
        unless the `done` feature was requested using the
-       `--done` command line option or `feature done` command.
+       `--done` command-line option or `feature done` command.
 
 `cat-blob`::
        Causes fast-import to print a blob in 'cat-file --batch'
@@ -437,7 +437,7 @@ the email address from the other fields in the line.  Note that
 of bytes, except `LT`, `GT` and `LF`.  `<name>` is typically UTF-8 encoded.
 
 The time of the change is specified by `<when>` using the date format
-that was selected by the \--date-format=<fmt> command line option.
+that was selected by the \--date-format=<fmt> command-line option.
 See ``Date Formats'' above for the set of supported formats, and
 their syntax.
 
@@ -483,6 +483,9 @@ Marks must be declared (via `mark`) before they can be used.
 * Any valid Git SHA-1 expression that resolves to a commit.  See
   ``SPECIFYING REVISIONS'' in linkgit:gitrevisions[7] for details.
 
+* The special null SHA-1 (40 zeros) specifies that the branch is to be
+  removed.
+
 The special case of restarting an incremental import from the
 current branch value should be written as:
 ----
@@ -1085,7 +1088,7 @@ Option commands must be the first commands on the input (not counting
 feature commands), to give an option command after any non-option
 command is an error.
 
-The following commandline options change import semantics and may therefore
+The following command-line options change import semantics and may therefore
 not be passed as option:
 
 * date-format
@@ -1099,7 +1102,7 @@ not be passed as option:
 If the `done` feature is not in use, treated as if EOF was read.
 This can be used to tell fast-import to finish early.
 
-If the `--done` command line option or `feature done` command is
+If the `--done` command-line option or `feature done` command is
 in use, the `done` command is mandatory and marks the end of the
 stream.
 
index 5809aa4eb94e969bf700806b1ef3df504ebcfd2b..8deb61469d9cbd8786c27567851158c90c31aa8a 100644 (file)
@@ -17,22 +17,20 @@ SYNOPSIS
 
 DESCRIPTION
 -----------
-Fetches named heads or tags from one or more other repositories,
-along with the objects necessary to complete them.
+Fetch branches and/or tags (collectively, "refs") from one or more
+other repositories, along with the objects necessary to complete their
+histories.  Remote-tracking branches are updated (see the description
+of <refspec> below for ways to control this behavior).
 
-The ref names and their object names of fetched refs are stored
-in `.git/FETCH_HEAD`.  This information is left for a later merge
-operation done by 'git merge'.
-
-By default, tags are auto-followed.  This means that when fetching
-from a remote, any tags on the remote that point to objects that exist
-in the local repository are fetched.  The effect is to fetch tags that
+By default, any tag that points into the histories being fetched is
+also fetched; the effect is to fetch tags that
 point at branches that you are interested in.  This default behavior
-can be changed by using the --tags or --no-tags options, by
-configuring remote.<name>.tagopt, or by using a refspec that fetches
-tags explicitly.
+can be changed by using the --tags or --no-tags options or by
+configuring remote.<name>.tagopt.  By using a refspec that fetches tags
+explicitly, you can fetch tags that do not point into branches you
+are interested in as well.
 
-'git fetch' can fetch from either a single named repository,
+'git fetch' can fetch from either a single named repository or URL,
 or from several repositories at once if <group> is given and
 there is a remotes.<group> entry in the configuration file.
 (See linkgit:git-config[1]).
@@ -40,6 +38,10 @@ there is a remotes.<group> entry in the configuration file.
 When no remote is specified, by default the `origin` remote will be used,
 unless there's an upstream branch configured for the current branch.
 
+The names of refs that are fetched, together with the object names
+they point at, are written to `.git/FETCH_HEAD`.  This information
+may be used by scripts or other git commands, such as linkgit:git-pull[1].
+
 OPTIONS
 -------
 include::fetch-options.txt[]
@@ -49,6 +51,55 @@ include::pull-fetch-param.txt[]
 include::urls-remotes.txt[]
 
 
+CONFIGURED REMOTE-TRACKING BRANCHES[[CRTB]]
+-------------------------------------------
+
+You often interact with the same remote repository by
+regularly and repeatedly fetching from it.  In order to keep track
+of the progress of such a remote repository, `git fetch` allows you
+to configure `remote.<repository>.fetch` configuration variables.
+
+Typically such a variable may look like this:
+
+------------------------------------------------
+[remote "origin"]
+       fetch = +refs/heads/*:refs/remotes/origin/*
+------------------------------------------------
+
+This configuration is used in two ways:
+
+* When `git fetch` is run without specifying what branches
+  and/or tags to fetch on the command line, e.g. `git fetch origin`
+  or `git fetch`, `remote.<repository>.fetch` values are used as
+  the refspecs---they specify which refs to fetch and which local refs
+  to update.  The example above will fetch
+  all branches that exist in the `origin` (i.e. any ref that matches
+  the left-hand side of the value, `refs/heads/*`) and update the
+  corresponding remote-tracking branches in the `refs/remotes/origin/*`
+  hierarchy.
+
+* When `git fetch` is run with explicit branches and/or tags
+  to fetch on the command line, e.g. `git fetch origin master`, the
+  <refspec>s given on the command line determine what are to be
+  fetched (e.g. `master` in the example,
+  which is a short-hand for `master:`, which in turn means
+  "fetch the 'master' branch but I do not explicitly say what
+  remote-tracking branch to update with it from the command line"),
+  and the example command will
+  fetch _only_ the 'master' branch.  The `remote.<repository>.fetch`
+  values determine which
+  remote-tracking branch, if any, is updated.  When used in this
+  way, the `remote.<repository>.fetch` values do not have any
+  effect in deciding _what_ gets fetched (i.e. the values are not
+  used as refspecs when the command-line lists refspecs); they are
+  only used to decide _where_ the refs that are fetched are stored
+  by acting as a mapping.
+
+The latter use of the `remote.<repository>.fetch` values can be
+overridden by giving the `--refmap=<refspec>` parameter(s) on the
+command line.
+
+
 EXAMPLES
 --------
 
@@ -76,6 +127,19 @@ the local repository by fetching from the branches (respectively)
 The `pu` branch will be updated even if it is does not fast-forward,
 because it is prefixed with a plus sign; `tmp` will not be.
 
+* Peek at a remote's branch, without configuring the remote in your local
+repository:
++
+------------------------------------------------
+$ git fetch git://git.kernel.org/pub/scm/git/git.git maint
+$ git log FETCH_HEAD
+------------------------------------------------
++
+The first command fetches the `maint` branch from the repository at
+`git://git.kernel.org/pub/scm/git/git.git` and the second command uses
+`FETCH_HEAD` to examine the branch with linkgit:git-log[1].  The fetched
+objects will eventually be removed by git's built-in housekeeping (see
+linkgit:git-gc[1]).
 
 BUGS
 ----
index 5c0a4ab2d6d4c123899fa32e8f147a8c077f2130..c0fd470da42991404c722f45ee7ac48cd774287b 100644 (file)
@@ -14,6 +14,7 @@ SYNOPSIS
                   [(--attach|--inline)[=<boundary>] | --no-attach]
                   [-s | --signoff]
                   [--signature=<signature> | --no-signature]
+                  [--signature-file=<file>]
                   [-n | --numbered | -N | --no-numbered]
                   [--start-number <n>] [--numbered-files]
                   [--in-reply-to=Message-Id] [--suffix=.<sfx>]
@@ -233,6 +234,9 @@ configuration options in linkgit:git-notes[1] to use this workflow).
        signature option is omitted the signature defaults to the Git version
        number.
 
+--signature-file=<file>::
+       Works just like --signature except the signature is read from a file.
+
 --suffix=.<sfx>::
        Instead of using `.patch` as the suffix for generated
        filenames, use specified suffix.  A common alternative is
index f83733490f5a881f6f197b3b62000337c500ef9d..31811f16bdaac49d01d38dcdea82bb191942b1cf 100644 (file)
@@ -53,6 +53,9 @@ grep.extendedRegexp::
        option is ignored when the 'grep.patternType' option is set to a value
        other than 'default'.
 
+grep.fullName::
+       If set to true, enable '--full-name' option by default.
+
 
 OPTIONS
 -------
index b21e9d79be22cf134cf4e5f009fc8d71a635cc73..3956525218bf45f2968fe2039e4dfb75a6f2222b 100644 (file)
@@ -80,9 +80,9 @@ CONFIGURATION VARIABLES
 help.format
 ~~~~~~~~~~~
 
-If no command line option is passed, the 'help.format' configuration
+If no command-line option is passed, the 'help.format' configuration
 variable will be checked. The following values are supported for this
-variable; they make 'git help' behave as their corresponding command
+variable; they make 'git help' behave as their corresponding command-
 line option:
 
 * "man" corresponds to '-m|--man',
@@ -93,15 +93,15 @@ help.browser, web.browser and browser.<tool>.path
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 The 'help.browser', 'web.browser' and 'browser.<tool>.path' will also
-be checked if the 'web' format is chosen (either by command line
+be checked if the 'web' format is chosen (either by command-line
 option or configuration variable). See '-w|--web' in the OPTIONS
 section above and linkgit:git-web{litdd}browse[1].
 
 man.viewer
 ~~~~~~~~~~
 
-The 'man.viewer' config variable will be checked if the 'man' format
-is chosen. The following values are currently supported:
+The 'man.viewer' configuration variable will be checked if the 'man'
+format is chosen. The following values are currently supported:
 
 * "man": use the 'man' program as usual,
 * "woman": use 'emacsclient' to launch the "woman" mode in emacs
@@ -124,7 +124,7 @@ For example, this configuration:
                viewer = woman
 ------------------------------------------------
 
-will try to use konqueror first. But this may fail (for example if
+will try to use konqueror first. But this may fail (for example, if
 DISPLAY is not set) and in that case emacs' woman mode will be tried.
 
 If everything fails, or if no viewer is configured, the viewer specified
index c0856a6e0a0a625fcc4c394057597d633a0487ac..e26f01fb1d1aec3526879059fe6ee20438965f68 100644 (file)
@@ -185,15 +185,15 @@ specifies the format of exclude patterns.
 
 These exclude patterns come from these places, in order:
 
-  1. The command line flag --exclude=<pattern> specifies a
+  1. The command-line flag --exclude=<pattern> specifies a
      single pattern.  Patterns are ordered in the same order
      they appear in the command line.
 
-  2. The command line flag --exclude-from=<file> specifies a
+  2. The command-line flag --exclude-from=<file> specifies a
      file containing a list of patterns.  Patterns are ordered
      in the same order they appear in the file.
 
-  3. The command line flag --exclude-per-directory=<name> specifies
+  3. The command-line flag --exclude-per-directory=<name> specifies
      a name of the file in each directory 'git ls-files'
      examines, normally `.gitignore`.  Files in deeper
      directories take precedence.  Patterns are ordered in the
index a3c1fa332abb8d65051f6f6d5df6a14708fba980..cf2c374b710673e891f8337cb9bcc90d72be460a 100644 (file)
@@ -101,9 +101,8 @@ commit or stash your changes before running 'git merge'.
        Specifying more than one commit will create a merge with
        more than two parents (affectionately called an Octopus merge).
 +
-If no commit is given from the command line, and if `merge.defaultToUpstream`
-configuration variable is set, merge the remote-tracking branches
-that the current branch is configured to use as its upstream.
+If no commit is given from the command line, merge the remote-tracking
+branches that the current branch is configured to use as its upstream.
 See also the configuration section of this manual page.
 
 
index 07137f252b0fd57a671ef69884bea893cdd7767c..e846c2ed7f7f862f5324c0e95a2b17dabcaac58d 100644 (file)
@@ -71,11 +71,13 @@ success of the resolution after the custom tool has exited.
 --no-prompt::
        Don't prompt before each invocation of the merge resolution
        program.
+       This is the default if the merge resolution program is
+       explicitly specified with the `--tool` option or with the
+       `merge.tool` configuration variable.
 
 --prompt::
-       Prompt before each invocation of the merge resolution program.
-       This is the default behaviour; the option is provided to
-       override any configuration settings.
+       Prompt before each invocation of the merge resolution program
+       to give the user a chance to skip the path.
 
 TEMPORARY FILES
 ---------------
index 312c3b1fe5f970a5fdab0e7e1ba0fcbe021eaaa5..31efc587ee694da6885ed1ce9d1a4c1419808397 100644 (file)
@@ -8,14 +8,14 @@ git-patch-id - Compute unique ID for a patch
 SYNOPSIS
 --------
 [verse]
-'git patch-id' < <patch>
+'git patch-id' [--stable | --unstable] < <patch>
 
 DESCRIPTION
 -----------
-A "patch ID" is nothing but a SHA-1 of the diff associated with a patch, with
-whitespace and line numbers ignored.  As such, it's "reasonably stable", but at
-the same time also reasonably unique, i.e., two patches that have the same "patch
-ID" are almost guaranteed to be the same thing.
+A "patch ID" is nothing but a sum of SHA-1 of the file diffs associated with a
+patch, with whitespace and line numbers ignored.  As such, it's "reasonably
+stable", but at the same time also reasonably unique, i.e., two patches that
+have the same "patch ID" are almost guaranteed to be the same thing.
 
 IOW, you can use this thing to look for likely duplicate commits.
 
@@ -27,6 +27,33 @@ This can be used to make a mapping from patch ID to commit ID.
 
 OPTIONS
 -------
+
+--stable::
+       Use a "stable" sum of hashes as the patch ID. With this option:
+        - Reordering file diffs that make up a patch does not affect the ID.
+          In particular, two patches produced by comparing the same two trees
+          with two different settings for "-O<orderfile>" result in the same
+          patch ID signature, thereby allowing the computed result to be used
+          as a key to index some meta-information about the change between
+          the two trees;
+
+        - Result is different from the value produced by git 1.9 and older
+          or produced when an "unstable" hash (see --unstable below) is
+          configured - even when used on a diff output taken without any use
+          of "-O<orderfile>", thereby making existing databases storing such
+          "unstable" or historical patch-ids unusable.
+
+       This is the default if patchid.stable is set to true.
+
+--unstable::
+       Use an "unstable" hash as the patch ID. With this option,
+       the result produced is compatible with the patch-id value produced
+       by git 1.9 and older.  Users with pre-existing databases storing
+       patch-ids produced by git 1.9 and older (who do not deal with reordered
+       patches) may want to use this option.
+
+       This is the default.
+
 <patch>::
        The diff to create the ID of.
 
index 056c0dba81292ae63fedf2d911bce8f5fa3f7d19..fa1d557e5b98eb6dc40e3baa65964138b4cc0621 100644 (file)
@@ -283,7 +283,7 @@ merge. The different stages represent the "result tree" (stage 0, aka
 you are trying to merge (stage 2 and 3 respectively).
 
 The order of stages 1, 2 and 3 (hence the order of three
-<tree-ish> command line arguments) are significant when you
+<tree-ish> command-line arguments) are significant when you
 start a 3-way merge with an index file that is already
 populated.  Here is an outline of how the algorithm works:
 
index 0a02f70657776bc5d862add34f466b4fe98f6e35..089dcac0478407a89aea702988adcb4135510180 100644 (file)
@@ -9,6 +9,7 @@ SYNOPSIS
 --------
 [verse]
 'git replace' [-f] <object> <replacement>
+'git replace' [-f] --edit <object>
 'git replace' -d <object>...
 'git replace' [--format=<format>] [-l [<pattern>]]
 
@@ -63,6 +64,23 @@ OPTIONS
 --delete::
        Delete existing replace refs for the given objects.
 
+--edit <object>::
+       Edit an object's content interactively. The existing content
+       for <object> is pretty-printed into a temporary file, an
+       editor is launched on the file, and the result is parsed to
+       create a new object of the same type as <object>. A
+       replacement ref is then created to replace <object> with the
+       newly created object. See linkgit:git-var[1] for details about
+       how the editor will be chosen.
+
+--raw::
+       When editing, provide the raw object contents rather than
+       pretty-printed ones. Currently this only affects trees, which
+       will be shown in their binary form. This is harder to work with,
+       but can help when repairing a tree that is so corrupted it
+       cannot be pretty-printed. Note that you may need to configure
+       your editor to cleanly read and write binary data.
+
 -l <pattern>::
 --list <pattern>::
        List replace refs for objects that match the given pattern (or
@@ -92,7 +110,9 @@ CREATING REPLACEMENT OBJECTS
 
 linkgit:git-filter-branch[1], linkgit:git-hash-object[1] and
 linkgit:git-rebase[1], among other git commands, can be used to create
-replacement objects from existing objects.
+replacement objects from existing objects. The `--edit` option can
+also be used with 'git replace' to create a replacement object by
+editing an existing object.
 
 If you want to replace many blobs, trees or commits that are part of a
 string of commits, you may just want to create a replacement string of
@@ -117,6 +137,8 @@ linkgit:git-filter-branch[1]
 linkgit:git-rebase[1]
 linkgit:git-tag[1]
 linkgit:git-branch[1]
+linkgit:git-commit[1]
+linkgit:git-var[1]
 linkgit:git[1]
 
 GIT
index 987395d22af915832c535840ef59927fc5125294..9bd76a5a6b9327136871dd49cdad5c1ecd8dbcde 100644 (file)
@@ -245,6 +245,10 @@ print a message to stderr and exit with nonzero status.
 --show-toplevel::
        Show the absolute path of the top-level directory.
 
+--shared-index-path::
+       Show the path to the shared index file in split index mode, or
+       empty if not in split-index mode.
+
 Other Options
 ~~~~~~~~~~~~~
 
index f0e57a597b6e551d891c064fa69837db632237c6..a60776eb579e10507814c643cc292dfa99750aa9 100644 (file)
@@ -20,7 +20,7 @@ files in the directory), or directly as a revision list.  In the
 last case, any format accepted by linkgit:git-format-patch[1] can
 be passed to git send-email.
 
-The header of the email is configurable by command line options.  If not
+The header of the email is configurable via command-line options.  If not
 specified on the command line, the user will be prompted with a ReadLine
 enabled interface to provide the necessary information.
 
@@ -68,7 +68,7 @@ The --cc option must be repeated for each user you want on the cc list.
 When '--compose' is used, git send-email will use the From, Subject, and
 In-Reply-To headers specified in the message. If the body of the message
 (what you type after the headers and a blank line) only contains blank
-(or Git: prefixed) lines the summary won't be sent, but From, Subject,
+(or Git: prefixed) lines, the summary won't be sent, but From, Subject,
 and In-Reply-To headers will be used unless they are removed.
 +
 Missing From or In-Reply-To headers will be prompted for.
@@ -78,7 +78,7 @@ See the CONFIGURATION section for 'sendemail.multiedit'.
 --from=<address>::
        Specify the sender of the emails.  If not specified on the command line,
        the value of the 'sendemail.from' configuration option is used.  If
-       neither the command line option nor 'sendemail.from' are set, then the
+       neither the command-line option nor 'sendemail.from' are set, then the
        user will be prompted for the value.  The default for the prompt will be
        the value of GIT_AUTHOR_IDENT, or GIT_COMMITTER_IDENT if that is not
        set, as returned by "git var -l".
@@ -248,6 +248,18 @@ Automating
        cc list. Default is the value of 'sendemail.signedoffbycc' configuration
        value; if that is unspecified, default to --signed-off-by-cc.
 
+--[no-]cc-cover::
+       If this is set, emails found in Cc: headers in the first patch of
+       the series (typically the cover letter) are added to the cc list
+       for each email set. Default is the value of 'sendemail.cccover'
+       configuration value; if that is unspecified, default to --no-cc-cover.
+
+--[no-]to-cover::
+       If this is set, emails found in To: headers in the first patch of
+       the series (typically the cover letter) are added to the to list
+       for each email set. Default is the value of 'sendemail.tocover'
+       configuration value; if that is unspecified, default to --no-to-cover.
+
 --suppress-cc=<category>::
        Specify an additional category of recipients to suppress the
        auto-cc of:
index 89c4d3e39474ed601255371c30b98bdd569f671d..8e6af65da0e0f234315c42391a8bab42fc39abb6 100644 (file)
@@ -20,7 +20,7 @@ SYNOPSIS
 'git submodule' [--quiet] summary [--cached|--files] [(-n|--summary-limit) <n>]
              [commit] [--] [<path>...]
 'git submodule' [--quiet] foreach [--recursive] <command>
-'git submodule' [--quiet] sync [--] [<path>...]
+'git submodule' [--quiet] sync [--recursive] [--] [<path>...]
 
 
 DESCRIPTION
index fce585388c773f89bec19fdfb639f92651e62450..44c970ce18143e2a45c9f5364535e26508b50317 100644 (file)
@@ -148,8 +148,8 @@ the same local time zone.
 [verse]
 config key: svn-remote.<name>.ignore-paths
 +
-If the ignore-paths config key is set and the command line option is
-also given, both regular expressions will be used.
+If the ignore-paths configuration key is set, and the command-line
+option is also given, both regular expressions will be used.
 +
 Examples:
 +
index d6de4a008ce74b9aa3f83035b4392e8d4505fae7..dfc09d93d85f5ca598447e98327518082c8e1a16 100644 (file)
@@ -161,6 +161,17 @@ may not support it yet.
        Only meaningful with `--stdin` or `--index-info`; paths are
        separated with NUL character instead of LF.
 
+--split-index::
+--no-split-index::
+       Enable or disable split index mode. If enabled, the index is
+       split into two files, $GIT_DIR/index and $GIT_DIR/sharedindex.<SHA-1>.
+       Changes are accumulated in $GIT_DIR/index while the shared
+       index file contains all index entries stays unchanged. If
+       split-index mode is already enabled and `--split-index` is
+       given again, all changes in $GIT_DIR/index are pushed back to
+       the shared index file. This mode is designed for very large
+       indexes that take a signficant amount of time to read or write.
+
 \--::
        Do not interpret any more arguments as options.
 
index 0a0a5512b3c62eb1179a3d5a9687949c39b2a9ef..c8f5ae5cb362276de94aa867af59818a75b04595 100644 (file)
@@ -68,7 +68,12 @@ performs all modifications together.  Specify commands of the form:
        option SP <opt> LF
 
 Quote fields containing whitespace as if they were strings in C source
-code.  Alternatively, use `-z` to specify commands without quoting:
+code; i.e., surrounded by double-quotes and with backslash escapes.
+Use 40 "0" characters or the empty string to specify a zero value.  To
+specify a missing value, omit the value and its preceding SP entirely.
+
+Alternatively, use `-z` to specify in NUL-terminated format, without
+quoting:
 
        update SP <ref> NUL <newvalue> NUL [<oldvalue>] NUL
        create SP <ref> NUL <newvalue> NUL
@@ -76,8 +81,12 @@ code.  Alternatively, use `-z` to specify commands without quoting:
        verify SP <ref> NUL [<oldvalue>] NUL
        option SP <opt> NUL
 
-Lines of any other format or a repeated <ref> produce an error.
-Command meanings are:
+In this format, use 40 "0" to specify a zero value, and use the empty
+string to specify a missing value.
+
+In either format, values can be specified in any form that Git
+recognizes as an object name.  Commands in any other format or a
+repeated <ref> produce an error.  Command meanings are:
 
 update::
        Set <ref> to <newvalue> after verifying <oldvalue>, if given.
@@ -102,9 +111,6 @@ option::
        The only valid option is `no-deref` to avoid dereferencing
        a symbolic ref.
 
-Use 40 "0" or the empty string to specify a zero value, except that
-with `-z` an empty <oldvalue> is considered missing.
-
 If all <ref>s can be locked with matching <oldvalue>s
 simultaneously, all modifications are performed.  Otherwise, no
 modifications are performed.  Note that while each individual
diff --git a/Documentation/git-verify-commit.txt b/Documentation/git-verify-commit.txt
new file mode 100644 (file)
index 0000000..9413e28
--- /dev/null
@@ -0,0 +1,28 @@
+git-verify-commit(1)
+====================
+
+NAME
+----
+git-verify-commit - Check the GPG signature of commits
+
+SYNOPSIS
+--------
+[verse]
+'git verify-commit' <commit>...
+
+DESCRIPTION
+-----------
+Validates the gpg signature created by 'git commit -S'.
+
+OPTIONS
+-------
+-v::
+--verbose::
+       Print the contents of the commit object before validating it.
+
+<commit>...::
+       SHA-1 identifiers of Git commit objects.
+
+GIT
+---
+Part of the linkgit:git[1] suite
index 2de575f5beed10ed616289d88929c466a0fcb296..16ede5b4c36d3a231d6af3849f7eeb8f404daf98 100644 (file)
@@ -62,7 +62,7 @@ CONF.VAR (from -c option) and web.browser
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 The web browser can be specified using a configuration variable passed
-with the -c (or --config) command line option, or the 'web.browser'
+with the -c (or --config) command-line option, or the 'web.browser'
 configuration variable if the former is not used.
 
 browser.<tool>.path
@@ -87,7 +87,7 @@ the URLs passed as arguments.
 Note about konqueror
 --------------------
 
-When 'konqueror' is specified by a command line option or a
+When 'konqueror' is specified by a command-line option or a
 configuration variable, we launch 'kfmclient' to try to open the HTML
 man page on an already opened konqueror in a new tab if possible.
 
index 3d9c6d1743a5bdf353c896d924cf9b13a493ca46..79242096714e90a385e9b63a60326a41f8bd983d 100644 (file)
@@ -29,7 +29,7 @@ in-depth introduction.
 After you mastered the basic concepts, you can come back to this
 page to learn what commands Git offers.  You can learn more about
 individual Git commands with "git help command".  linkgit:gitcli[7]
-manual page gives you an overview of the command line command syntax.
+manual page gives you an overview of the command-line command syntax.
 
 Formatted and hyperlinked version of the latest Git documentation
 can be viewed at `http://git-htmldocs.googlecode.com/git/git.html`.
@@ -39,7 +39,7 @@ ifdef::stalenotes[]
 ============
 
 You are reading the documentation for the latest (possibly
-unreleased) version of Git, that is available from 'master'
+unreleased) version of Git, that is available from the 'master'
 branch of the `git.git` repository.
 Documentation for older releases are available here:
 
@@ -756,7 +756,7 @@ Git so take care if using Cogito etc.
 
 'GIT_WORK_TREE'::
        Set the path to the root of the working tree.
-       This can also be controlled by the '--work-tree' command line
+       This can also be controlled by the '--work-tree' command-line
        option and the core.worktree configuration variable.
 
 'GIT_NAMESPACE'::
@@ -881,7 +881,7 @@ for further details.
 'GIT_ASKPASS'::
        If this environment variable is set, then Git commands which need to
        acquire passwords or passphrases (e.g. for HTTP or IMAP authentication)
-       will call this program with a suitable prompt as command line argument
+       will call this program with a suitable prompt as command-line argument
        and read the password from its STDOUT. See also the 'core.askpass'
        option in linkgit:git-config[1].
 
index 1c3e109cb3d30e69121f9b6681e870a66cf04609..dfe7d8372723c7a4970b8a7100764d1becc7f830 100644 (file)
@@ -3,7 +3,7 @@ gitcli(7)
 
 NAME
 ----
-gitcli - Git command line interface and conventions
+gitcli - Git command-line interface and conventions
 
 SYNOPSIS
 --------
@@ -66,13 +66,13 @@ you will.
 Here are the rules regarding the "flags" that you should follow when you are
 scripting Git:
 
- * it's preferred to use the non dashed form of Git commands, which means that
+ * it's preferred to use the non-dashed form of Git commands, which means that
    you should prefer `git foo` to `git-foo`.
 
  * splitting short options to separate words (prefer `git foo -a -b`
    to `git foo -ab`, the latter may not even work).
 
- * when a command line option takes an argument, use the 'stuck' form.  In
+ * when a command-line option takes an argument, use the 'stuck' form.  In
    other words, write `git foo -oArg` instead of `git foo -o Arg` for short
    options, and `git foo --long-opt=Arg` instead of `git foo --long-opt Arg`
    for long options.  An option that takes optional option-argument must be
@@ -103,7 +103,7 @@ Here is a list of the facilities provided by this option parser.
 Magic Options
 ~~~~~~~~~~~~~
 Commands which have the enhanced option parser activated all understand a
-couple of magic command line options:
+couple of magic command-line options:
 
 -h::
        gives a pretty printed usage of the command.
index 7e03fcc62d1a388552cdd1e92f75183c0278cf28..7ae50aa26aff26cb9dd619abc7c29372c4156bcc 100644 (file)
@@ -27,7 +27,7 @@ gitk-specific options.
 
 gitk generally only understands options with arguments in the
 'sticked' form (see linkgit:gitcli[7]) due to limitations in the
-command line parser.
+command-line parser.
 
 rev-list options and arguments
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
index 17d2ea6c1e48733d85a8caa49f6143c76edb09aa..79653f313474fa658f072c97d8744e5afccb77d7 100644 (file)
@@ -155,6 +155,10 @@ index::
        The current index file for the repository.  It is
        usually not found in a bare repository.
 
+sharedindex.<SHA-1>::
+       The shared index part, to be referenced by $GIT_DIR/index and
+       other temporary index files. Only valid in split index mode.
+
 info::
        Additional information about the repository is recorded
        in this directory.
index 952f503afb6dd8e65ffeaf09425a0968593f39b5..ebe7a6c24cfef75441906a3e4de550b9fd296c0b 100644 (file)
@@ -904,7 +904,7 @@ the following in your GITWEB_CONFIG file:
        $feature{'snapshot'}{'override'} = 1;
 
 If you allow overriding for the snapshot feature, you can specify which
-snapshot formats are globally disabled. You can also add any command line
+snapshot formats are globally disabled. You can also add any command-line
 options you want (such as setting the compression level). For instance, you
 can disable Zip compressed snapshots and set *gzip*(1) to run at level 6 by
 adding the following lines to your gitweb configuration file:
index be0858c188184eb510688ffc0598664541c1d10c..4e0b971824f698841a6395588c2b53b0e1cf988d 100644 (file)
@@ -1,7 +1,7 @@
 [[def_alternate_object_database]]alternate object database::
        Via the alternates mechanism, a <<def_repository,repository>>
        can inherit part of its <<def_object_database,object database>>
-       from another object database, which is called "alternate".
+       from another object database, which is called an "alternate".
 
 [[def_bare_repository]]bare repository::
        A bare repository is normally an appropriately
diff --git a/Documentation/howto/keep-canonical-history-correct.txt b/Documentation/howto/keep-canonical-history-correct.txt
new file mode 100644 (file)
index 0000000..35d48ef
--- /dev/null
@@ -0,0 +1,216 @@
+From: Junio C Hamano <gitster@pobox.com>
+Date: Wed, 07 May 2014 13:15:39 -0700
+Subject: Beginner question on "Pull is mostly evil"
+Abstract: This how-to explains a method for keeping a
+ project's history correct when using git pull.
+Content-type: text/asciidoc
+
+Keep authoritative canonical history correct with git pull
+==========================================================
+
+Sometimes a new project integrator will end up with project history
+that appears to be "backwards" from what other project developers
+expect. This howto presents a suggested integration workflow for
+maintaining a central repository.
+
+Suppose that that central repository has this history:
+
+------------
+    ---o---o---A
+------------
+
+which ends at commit `A` (time flows from left to right and each node
+in the graph is a commit, lines between them indicating parent-child
+relationship).
+
+Then you clone it and work on your own commits, which leads you to
+have this history in *your* repository:
+
+------------
+    ---o---o---A---B---C
+------------
+
+Imagine your coworker did the same and built on top of `A` in *his*
+repository in the meantime, and then pushed it to the
+central repository:
+
+------------
+    ---o---o---A---X---Y---Z
+------------
+
+Now, if you `git push` at this point, because your history that leads
+to `C` lacks `X`, `Y` and `Z`, it will fail.  You need to somehow make
+the tip of your history a descendant of `Z`.
+
+One suggested way to solve the problem is "fetch and then merge", aka
+`git pull`. When you fetch, your repository will have a history like
+this:
+
+------------
+    ---o---o---A---B---C
+               \
+                X---Y---Z
+------------
+
+Once you run merge after that, while still on *your* branch, i.e. `C`,
+you will create a merge `M` and make the history look like this:
+
+------------
+    ---o---o---A---B---C---M
+               \         /
+                X---Y---Z
+------------
+
+`M` is a descendant of `Z`, so you can push to update the central
+repository.  Such a merge `M` does not lose any commit in both
+histories, so in that sense it may not be wrong, but when people want
+to talk about "the authoritative canonical history that is shared
+among the project participants", i.e. "the trunk", they often view
+it as "commits you see by following the first-parent chain", and use
+this command to view it:
+
+------------
+    $ git log --first-parent
+------------
+
+For all other people who observed the central repository after your
+coworker pushed `Z` but before you pushed `M`, the commit on the trunk
+used to be `o-o-A-X-Y-Z`.  But because you made `M` while you were on
+`C`, `M`'s first parent is `C`, so by pushing `M` to advance the
+central repository, you made `X-Y-Z` a side branch, not on the trunk.
+
+You would rather want to have a history of this shape:
+
+------------
+    ---o---o---A---X---Y---Z---M'
+               \             /
+                B-----------C
+------------
+
+so that in the first-parent chain, it is clear that the project first
+did `X` and then `Y` and then `Z` and merged a change that consists of
+two commits `B` and `C` that achieves a single goal.  You may have
+worked on fixing the bug #12345 with these two patches, and the merge
+`M'` with swapped parents can say in its log message "Merge
+fix-bug-12345". Having a way to tell `git pull` to create a merge
+but record the parents in reverse order may be a way to do so.
+
+Note that I said "achieves a single goal" above, because this is
+important.  "Swapping the merge order" only covers a special case
+where the project does not care too much about having unrelated
+things done on a single merge but cares a lot about first-parent
+chain.
+
+There are multiple schools of thought about the "trunk" management.
+
+ 1. Some projects want to keep a completely linear history without any
+    merges.  Obviously, swapping the merge order would not match their
+    taste.  You would need to flatten your history on top of the
+    updated upstream to result in a history of this shape instead:
++
+------------
+    ---o---o---A---X---Y---Z---B---C
+------------
++
+with `git pull --rebase` or something.
+
+ 2. Some projects tolerate merges in their history, but do not worry
+    too much about the first-parent order, and allow fast-forward
+    merges.  To them, swapping the merge order does not hurt, but
+    it is unnecessary.
+
+ 3. Some projects want each commit on the "trunk" to do one single
+    thing.  The output of `git log --first-parent` in such a project
+    would show either a merge of a side branch that completes a single
+    theme, or a single commit that completes a single theme by itself.
+    If your two commits `B` and `C` (or they may even be two groups of
+    commits) were solving two independent issues, then the merge `M'`
+    we made in the earlier example by swapping the merge order is
+    still not up to the project standard.  It merges two unrelated
+    efforts `B` and `C` at the same time.
+
+For projects in the last category (Git itself is one of them),
+individual developers would want to prepare a history more like
+this:
+
+------------
+                C0--C1--C2     topic-c
+               /
+    ---o---o---A                master
+               \
+                B0--B1--B2     topic-b
+------------
+
+That is, keeping separate topics on separate branches, perhaps like
+so:
+
+------------
+    $ git clone $URL work && cd work
+    $ git checkout -b topic-b master
+    $ ... work to create B0, B1 and B2 to complete one theme
+    $ git checkout -b topic-c master
+    $ ... same for the theme of topic-c
+------------
+
+And then
+
+------------
+    $ git checkout master
+    $ git pull --ff-only
+------------
+
+would grab `X`, `Y` and `Z` from the upstream and advance your master
+branch:
+
+------------
+                C0--C1--C2     topic-c
+               /
+    ---o---o---A---X---Y---Z    master
+               \
+                B0--B1--B2     topic-b
+------------
+
+And then you would merge these two branches separately:
+
+------------
+    $ git merge topic-b
+    $ git merge topic-c
+------------
+
+to result in
+
+------------
+                C0--C1---------C2
+               /                 \
+    ---o---o---A---X---Y---Z---M---N
+               \             /
+                B0--B1-----B2
+------------
+
+and push it back to the central repository.
+
+It is very much possible that while you are merging topic-b and
+topic-c, somebody again advanced the history in the central repository
+to put `W` on top of `Z`, and make your `git push` fail.
+
+In such a case, you would rewind to discard `M` and `N`, update the
+tip of your 'master' again and redo the two merges:
+
+------------
+    $ git reset --hard origin/master
+    $ git pull --ff-only
+    $ git merge topic-b
+    $ git merge topic-c
+------------
+
+The procedure will result in a history that looks like this:
+
+------------
+                C0--C1--------------C2
+               /                     \
+    ---o---o---A---X---Y---Z---W---M'--N'
+               \                 /
+                B0--B1---------B2
+------------
+
+See also http://git-blame.blogspot.com/2013/09/fun-with-first-parent-history.html
index 6de4f3c4875e3d9607754d5ca76a17e00c8f5841..f44e5e9458592a0554e4e2e163a6b029c1435f80 100644 (file)
@@ -181,7 +181,7 @@ On Debian:
 
    Most tests should pass.
 
-A command line tool to test WebDAV is cadaver. If you prefer GUIs, for
+A command-line tool to test WebDAV is cadaver. If you prefer GUIs, for
 example, konqueror can open WebDAV URLs as "webdav://..." or
 "webdavs://...".
 
index 18cffc25b809fa3695b0cc60c732d058e8843ed6..1ebbf1d738403204b77a6b18547de25e94ab28be 100644 (file)
@@ -12,9 +12,23 @@ ifndef::git-pull[]
 endif::git-pull[]
 
 <refspec>::
-       The format of a <refspec> parameter is an optional plus
-       `+`, followed by the source ref <src>, followed
-       by a colon `:`, followed by the destination ref <dst>.
+       Specifies which refs to fetch and which local refs to update.
+       When no <refspec>s appear on the command line, the refs to fetch
+       are read from `remote.<repository>.fetch` variables instead
+ifndef::git-pull[]
+       (see <<CRTB,CONFIGURED REMOTE-TRACKING BRANCHES>> below).
+endif::git-pull[]
+ifdef::git-pull[]
+       (see linkgit:git-fetch[1]).
+endif::git-pull[]
++
+The format of a <refspec> parameter is an optional plus
+`+`, followed by the source ref <src>, followed
+by a colon `:`, followed by the destination ref <dst>.
+The colon can be omitted when <dst> is empty.
++
+`tag <tag>` means the same as `refs/tags/<tag>:refs/tags/<tag>`;
+it requests fetching everything up to the given tag.
 +
 The remote ref that matches <src>
 is fetched, and if <dst> is not empty string, the local
@@ -24,55 +38,34 @@ is updated even if it does not result in a fast-forward
 update.
 +
 [NOTE]
-If the remote branch from which you want to pull is
-modified in non-linear ways such as being rewound and
-rebased frequently, then a pull will attempt a merge with
-an older version of itself, likely conflict, and fail.
-It is under these conditions that you would want to use
-the `+` sign to indicate non-fast-forward updates will
-be needed.  There is currently no easy way to determine
-or declare that a branch will be made available in a
-repository with this behavior; the pulling user simply
+When the remote branch you want to fetch is known to
+be rewound and rebased regularly, it is expected that
+its new tip will not be descendant of its previous tip
+(as stored in your remote-tracking branch the last time
+you fetched).  You would want
+to use the `+` sign to indicate non-fast-forward updates
+will be needed for such branches.  There is no way to
+determine or declare that a branch will be made available
+in a repository with this behavior; the pulling user simply
 must know this is the expected usage pattern for a branch.
-+
-[NOTE]
-You never do your own development on branches that appear
-on the right hand side of a <refspec> colon on `Pull:` lines;
-they are to be updated by 'git fetch'.  If you intend to do
-development derived from a remote branch `B`, have a `Pull:`
-line to track it (i.e. `Pull: B:remote-B`), and have a separate
-branch `my-B` to do your development on top of it.  The latter
-is created by `git branch my-B remote-B` (or its equivalent `git
-checkout -b my-B remote-B`).  Run `git fetch` to keep track of
-the progress of the remote side, and when you see something new
-on the remote branch, merge it into your development branch with
-`git pull . remote-B`, while you are on `my-B` branch.
+ifdef::git-pull[]
 +
 [NOTE]
 There is a difference between listing multiple <refspec>
 directly on 'git pull' command line and having multiple
-`Pull:` <refspec> lines for a <repository> and running
+`remote.<repository>.fetch` entries in your configuration
+for a <repository> and running a
 'git pull' command without any explicit <refspec> parameters.
-<refspec> listed explicitly on the command line are always
+<refspec>s listed explicitly on the command line are always
 merged into the current branch after fetching.  In other words,
-if you list more than one remote refs, you would be making
-an Octopus.  While 'git pull' run without any explicit <refspec>
-parameter takes default <refspec>s from `Pull:` lines, it
-merges only the first <refspec> found into the current branch,
-after fetching all the remote refs.  This is because making an
+if you list more than one remote ref, 'git pull' will create
+an Octopus merge.  On the other hand, if you do not list any
+explicit <refspec> parameter on the command line, 'git pull'
+will fetch all the <refspec>s it finds in the
+`remote.<repository>.fetch` configuration and merge
+only the first <refspec> found into the current branch.
+This is because making an
 Octopus from remote refs is rarely done, while keeping track
 of multiple remote heads in one-go by fetching more than one
 is often useful.
-+
-Some short-cut notations are also supported.
-+
-* `tag <tag>` means the same as `refs/tags/<tag>:refs/tags/<tag>`;
-  it requests fetching everything up to the given tag.
-ifndef::git-pull[]
-* A parameter <ref> without a colon fetches that ref into FETCH_HEAD,
-endif::git-pull[]
-ifdef::git-pull[]
-* A parameter <ref> without a colon merges <ref> into the current
-  branch,
 endif::git-pull[]
-  and updates the remote-tracking branches (if any).
index 5a286d0d61ffc5b3daa00d7d550d5931a91b35ec..07961185fe0cddf78822aee75b43f206cbcd4579 100644 (file)
@@ -94,7 +94,9 @@ some output processing may assume ref names in UTF-8.
 '<branchname>@\{upstream\}', e.g. 'master@\{upstream\}', '@\{u\}'::
   The suffix '@\{upstream\}' to a branchname (short form '<branchname>@\{u\}')
   refers to the branch that the branch specified by branchname is set to build on
-  top of.  A missing branchname defaults to the current one.
+  top of (configured with `branch.<name>.remote` and
+  `branch.<name>.merge`).  A missing branchname defaults to the
+  current one.
 
 '<rev>{caret}', e.g. 'HEAD{caret}, v1.5.1{caret}0'::
   A suffix '{caret}' to a revision parameter means the first parent of
index a6b7d83a8eb05086cb88a9168117aa54cf018551..1a797812fb426189b03a814498dd7019c96607b4 100644 (file)
@@ -53,11 +53,3 @@ Functions
 `argv_array_clear`::
        Free all memory associated with the array and return it to the
        initial, empty state.
-
-`argv_array_detach`::
-       Detach the argv array from the `struct argv_array`, transferring
-       ownership of the allocated array and strings.
-
-`argv_array_free_detached`::
-       Free the memory allocated by a `struct argv_array` that was later
-       detached and is now no longer needed.
index e3d6e7a79a6c2136a796c5409d16feb8058e96d2..22a39b929932b78653d1d0b1a59fe35e5d5e75f5 100644 (file)
@@ -22,11 +22,14 @@ Git:
 where options is the bitwise-or of:
 
 `RUN_SETUP`::
-
-       Make sure there is a Git directory to work on, and if there is a
-       work tree, chdir to the top of it if the command was invoked
-       in a subdirectory.  If there is no work tree, no chdir() is
-       done.
+       If there is not a Git directory to work on, abort.  If there
+       is a work tree, chdir to the top of it if the command was
+       invoked in a subdirectory.  If there is no work tree, no
+       chdir() is done.
+
+`RUN_SETUP_GENTLY`::
+       If there is a Git directory, chdir as per RUN_SETUP, otherwise,
+       don't chdir anywhere.
 
 `USE_PAGER`::
 
index 5d7d7f2d32f58f8682ca5efb2fd98fe7e74247dd..69510ae57afcedbe13334160c6a26c52c42e8d54 100644 (file)
@@ -109,6 +109,13 @@ terminated), of which .argv[0] is the program name to run (usually
 without a path). If the command to run is a git command, set argv[0] to
 the command name without the 'git-' prefix and set .git_cmd = 1.
 
+Note that the ownership of the memory pointed to by .argv stays with the
+caller, but it should survive until `finish_command` completes. If the
+.argv member is NULL, `start_command` will point it at the .args
+`argv_array` (so you may use one or the other, but you must use exactly
+one). The memory in .args will be cleaned up automatically during
+`finish_command` (or during `start_command` when it is unsuccessful).
+
 The members .in, .out, .err are used to redirect stdin, stdout,
 stderr as follows:
 
index 3350d97dda2408f92dc44c1e3216facc50257a50..f9c06a7573e9294a967d641cdfc2723b86c1c864 100644 (file)
@@ -7,10 +7,10 @@ use the mem* functions than a str* one (memchr vs. strchr e.g.).
 Though, one has to be careful about the fact that str* functions often
 stop on NULs and that strbufs may have embedded NULs.
 
-An strbuf is NUL terminated for convenience, but no function in the
+A strbuf is NUL terminated for convenience, but no function in the
 strbuf API actually relies on the string being free of NULs.
 
-strbufs has some invariants that are very important to keep in mind:
+strbufs have some invariants that are very important to keep in mind:
 
 . The `buf` member is never NULL, so it can be used in any usual C
 string operations safely. strbuf's _have_ to be initialized either by
@@ -56,8 +56,8 @@ Data structures
 * `struct strbuf`
 
 This is the string buffer structure. The `len` member can be used to
-determine the current length of the string, and `buf` member provides access to
-the string itself.
+determine the current length of the string, and `buf` member provides
+access to the string itself.
 
 Functions
 ---------
@@ -121,10 +121,28 @@ Functions
 
 * Related to the contents of the buffer
 
+`strbuf_trim`::
+
+       Strip whitespace from the beginning and end of a string.
+       Equivalent to performing `strbuf_rtrim()` followed by `strbuf_ltrim()`.
+
 `strbuf_rtrim`::
 
        Strip whitespace from the end of a string.
 
+`strbuf_ltrim`::
+
+       Strip whitespace from the beginning of a string.
+
+`strbuf_reencode`::
+
+       Replace the contents of the strbuf with a reencoded form.  Returns -1
+       on error, 0 on success.
+
+`strbuf_tolower`::
+
+       Lowercase each character in the buffer using `tolower`.
+
 `strbuf_cmp`::
 
        Compare two buffers. Returns an integer less than, equal to, or greater
@@ -184,7 +202,7 @@ strbuf_addstr(sb, "immediate string");
 
 `strbuf_addbuf`::
 
-       Copy the contents of an other buffer at the end of the current one.
+       Copy the contents of another buffer at the end of the current one.
 
 `strbuf_adddup`::
 
index 20be3488349c2ddbafbd90c0200f2a7d3862a12f..f1add51efeefb31e1da96a5ee62871e239819ebf 100644 (file)
@@ -200,3 +200,5 @@ Represents the list itself.
   You should not tamper with it.
 . Setting the `strdup_strings` member to 1 will strdup() the strings
   before adding them, see above.
+. The `compare_strings_fn` member is used to specify a custom compare
+  function, otherwise `strcmp()` is used as the default function.
index 20525d98bb67cd3710c9738f99020c01f2d1d885..229f845dfa67b9c2e74b2eb1de80a224ea757b53 100644 (file)
@@ -60,7 +60,7 @@ Because Git repositories are accessed by standard path components
 server administrators MAY use directory based permissions within
 their HTTP server to control repository access.
 
-Clients SHOULD support Basic authentication as described by RFC 2616.
+Clients SHOULD support Basic authentication as described by RFC 2617.
 Servers SHOULD support Basic authentication by relying upon the
 HTTP server placed in front of the Git server software.
 
@@ -374,7 +374,7 @@ C: Send one `$GIT_URL/git-upload-pack` request:
    C: 0000
 
 The stream is organized into "commands", with each command
-appearing by itself in a pkt-line.  Within a command line
+appearing by itself in a pkt-line.  Within a command line,
 the text leading up to the first space is the command name,
 and the remainder of the line to the first LF is the value.
 Command lines are terminated with an LF as the last byte of
index f352a9b22e3138fa674c393d99d420de4f2ff144..fe6f31667d7d5eba34c57e322b557ab29d618011 100644 (file)
@@ -129,6 +129,9 @@ Git index format
   (Version 4) In version 4, the padding after the pathname does not
   exist.
 
+  Interpretation of index entries in split index mode is completely
+  different. See below for details.
+
 == Extensions
 
 === Cached tree
@@ -198,3 +201,35 @@ Git index format
   - At most three 160-bit object names of the entry in stages from 1 to 3
     (nothing is written for a missing stage).
 
+=== Split index
+
+  In split index mode, the majority of index entries could be stored
+  in a separate file. This extension records the changes to be made on
+  top of that to produce the final index.
+
+  The signature for this extension is { 'l', 'i, 'n', 'k' }.
+
+  The extension consists of:
+
+  - 160-bit SHA-1 of the shared index file. The shared index file path
+    is $GIT_DIR/sharedindex.<SHA-1>. If all 160 bits are zero, the
+    index does not require a shared index file.
+
+  - An ewah-encoded delete bitmap, each bit represents an entry in the
+    shared index. If a bit is set, its corresponding entry in the
+    shared index will be removed from the final index.  Note, because
+    a delete operation changes index entry positions, but we do need
+    original positions in replace phase, it's best to just mark
+    entries for removal, then do a mass deletion after replacement.
+
+  - An ewah-encoded replace bitmap, each bit represents an entry in
+    the shared index. If a bit is set, its corresponding entry in the
+    shared index will be replaced with an entry in this index
+    file. All replaced entries are stored in sorted order in this
+    index. The first "1" bit in the replace bitmap corresponds to the
+    first index entry, the second "1" bit to the second entry and so
+    on. Replaced entries may have empty path names to save space.
+
+  The remaining index entries after replaced ones will be added to the
+  final index. These added entries are also sorted by entry namme then
+  stage.
index 022e74e616400664e7cf59ace487c8b53d6f5cab..7330d880f373fcb067c1dec954ddd60cda370c5d 100644 (file)
@@ -416,12 +416,11 @@ REVISIONS" section of linkgit:gitrevisions[7].
 Updating a repository with git fetch
 ------------------------------------
 
-Eventually the developer cloned from will do additional work in her
-repository, creating new commits and advancing the branches to point
-at the new commits.
+After you clone a repository and commit a few changes of your own, you
+may wish to check the original repository for updates.
 
-The command `git fetch`, with no arguments, will update all of the
-remote-tracking branches to the latest version found in her
+The `git-fetch` command, with no arguments, will update all of the
+remote-tracking branches to the latest version found in the original
 repository.  It will not touch any of your own branches--not even the
 "master" branch that was created for you on clone.
 
@@ -1811,8 +1810,8 @@ manner.
 You can then import these into your mail client and send them by
 hand.  However, if you have a lot to send at once, you may prefer to
 use the linkgit:git-send-email[1] script to automate the process.
-Consult the mailing list for your project first to determine how they
-prefer such patches be handled.
+Consult the mailing list for your project first to determine
+their requirements for submitting patches.
 
 [[importing-patches]]
 Importing patches to a project
@@ -2255,7 +2254,7 @@ $ git checkout test && git merge speed-up-spinlocks
 It is unlikely that you would have any conflicts here ... but you might if you
 spent a while on this step and had also pulled new versions from upstream.
 
-Some time later when enough time has passed and testing done, you can pull the
+Sometime later when enough time has passed and testing done, you can pull the
 same branch into the `release` tree ready to go upstream.  This is where you
 see the value of keeping each patch (or patch series) in its own branch.  It
 means that the patches can be moved into the `release` tree in any order.
@@ -4231,9 +4230,9 @@ Most of what `git rev-list` did is contained in `revision.c` and
 controls how and what revisions are walked, and more.
 
 The original job of `git rev-parse` is now taken by the function
-`setup_revisions()`, which parses the revisions and the common command line
+`setup_revisions()`, which parses the revisions and the common command-line
 options for the revision walker. This information is stored in the struct
-`rev_info` for later consumption. You can do your own command line option
+`rev_info` for later consumption. You can do your own command-line option
 parsing after calling `setup_revisions()`. After that, you have to call
 `prepare_revision_walk()` for initialization, and then you can get the
 commits one by one with the function `get_revision()`.
index 0986062473fa3a4948db06bf8a284f574649cf6f..40adbf7bf79ad7d7800b71d2ca79418cdbddd3ed 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 
 GVF=GIT-VERSION-FILE
-DEF_VER=v2.0.1
+DEF_VER=v2.0.0.GIT
 
 LF='
 '
index e0caec3f679089b6643e129fbdb2423dfd8f6d94..840057cba7ebd5fea25d84af367e49f0fcfc41c7 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -30,6 +30,8 @@ all::
 # Define LIBPCREDIR=/foo/bar if your libpcre header and library files are in
 # /foo/bar/include and /foo/bar/lib directories.
 #
+# Define HAVE_ALLOCA_H if you have working alloca(3) defined in that header.
+#
 # Define NO_CURL if you do not have libcurl installed.  git-http-fetch and
 # git-http-push are not built, and you cannot use http:// and https://
 # transports (neither smart nor dumb).
@@ -550,6 +552,7 @@ TEST_PROGRAMS_NEED_X += test-ctype
 TEST_PROGRAMS_NEED_X += test-date
 TEST_PROGRAMS_NEED_X += test-delta
 TEST_PROGRAMS_NEED_X += test-dump-cache-tree
+TEST_PROGRAMS_NEED_X += test-dump-split-index
 TEST_PROGRAMS_NEED_X += test-genrandom
 TEST_PROGRAMS_NEED_X += test-hashmap
 TEST_PROGRAMS_NEED_X += test-index-version
@@ -727,6 +730,7 @@ LIB_H += transport.h
 LIB_H += tree-walk.h
 LIB_H += tree.h
 LIB_H += unpack-trees.h
+LIB_H += unicode_width.h
 LIB_H += url.h
 LIB_H += urlmatch.h
 LIB_H += userdiff.h
@@ -872,6 +876,7 @@ LIB_OBJS += sha1_name.o
 LIB_OBJS += shallow.o
 LIB_OBJS += sideband.o
 LIB_OBJS += sigchain.o
+LIB_OBJS += split-index.o
 LIB_OBJS += strbuf.o
 LIB_OBJS += streaming.o
 LIB_OBJS += string-list.o
@@ -996,6 +1001,7 @@ BUILTIN_OBJS += builtin/update-ref.o
 BUILTIN_OBJS += builtin/update-server-info.o
 BUILTIN_OBJS += builtin/upload-archive.o
 BUILTIN_OBJS += builtin/var.o
+BUILTIN_OBJS += builtin/verify-commit.o
 BUILTIN_OBJS += builtin/verify-pack.o
 BUILTIN_OBJS += builtin/verify-tag.o
 BUILTIN_OBJS += builtin/write-tree.o
@@ -1108,6 +1114,10 @@ ifdef USE_LIBPCRE
        EXTLIBS += -lpcre
 endif
 
+ifdef HAVE_ALLOCA_H
+       BASIC_CFLAGS += -DHAVE_ALLOCA_H
+endif
+
 ifdef NO_CURL
        BASIC_CFLAGS += -DNO_CURL
        REMOTE_CURL_PRIMARY =
index 7879c7dc372705f06decbd745dec7fe1fad1b428..bf760914010786c830233effc8b96ddacfb114fd 120000 (symlink)
--- a/RelNotes
+++ b/RelNotes
@@ -1 +1 @@
-Documentation/RelNotes/2.0.1.txt
\ No newline at end of file
+Documentation/RelNotes/2.1.0.txt
\ No newline at end of file
index 486f823c78118212080a48e74debd7adae241cda..9b420331926c6bf1aa371f973d6a96886f419b06 100644 (file)
--- a/advice.c
+++ b/advice.c
@@ -61,9 +61,12 @@ void advise(const char *advice, ...)
 
 int git_default_advice_config(const char *var, const char *value)
 {
-       const char *k = skip_prefix(var, "advice.");
+       const char *k;
        int i;
 
+       if (!skip_prefix(var, "advice.", &k))
+               return 0;
+
        for (i = 0; i < ARRAY_SIZE(advice_config); i++) {
                if (strcmp(k, advice_config[i].name))
                        continue;
@@ -76,16 +79,15 @@ int git_default_advice_config(const char *var, const char *value)
 
 int error_resolve_conflict(const char *me)
 {
-       error("'%s' is not possible because you have unmerged files.", me);
+       error("%s is not possible because you have unmerged files.", me);
        if (advice_resolve_conflict)
                /*
                 * Message used both when 'git commit' fails and when
                 * other commands doing a merge do.
                 */
-               advise(_("Fix them up in the work tree,\n"
-                        "and then use 'git add/rm <file>' as\n"
-                        "appropriate to mark resolution and make a commit,\n"
-                        "or use 'git commit -a'."));
+               advise(_("Fix them up in the work tree, and then use 'git add/rm <file>'\n"
+                        "as appropriate to mark resolution and make a commit, or use\n"
+                        "'git commit -a'."));
        return -1;
 }
 
diff --git a/alias.c b/alias.c
index 5efc3d69866731d0f56464c522b00f253f84c187..758c8671494ad003a6e7e33f8a14b5450311bf54 100644 (file)
--- a/alias.c
+++ b/alias.c
@@ -5,7 +5,8 @@ static char *alias_val;
 
 static int alias_lookup_cb(const char *k, const char *v, void *cb)
 {
-       if (starts_with(k, "alias.") && !strcmp(k + 6, alias_key)) {
+       const char *name;
+       if (skip_prefix(k, "alias.", &name) && !strcmp(name, alias_key)) {
                if (!v)
                        return config_error_nonbool(k);
                alias_val = xstrdup(v);
diff --git a/alloc.c b/alloc.c
index f3ee745695643c00f175288a9592ab073dd589b0..eb22a45c9d0acf08a6024094bd0a2090a7307945 100644 (file)
--- a/alloc.c
+++ b/alloc.c
@@ -47,23 +47,32 @@ union any_object {
 
 DEFINE_ALLOCATOR(blob, struct blob)
 DEFINE_ALLOCATOR(tree, struct tree)
-DEFINE_ALLOCATOR(commit, struct commit)
+DEFINE_ALLOCATOR(raw_commit, struct commit)
 DEFINE_ALLOCATOR(tag, struct tag)
 DEFINE_ALLOCATOR(object, union any_object)
 
+void *alloc_commit_node(void)
+{
+       static int commit_count;
+       struct commit *c = alloc_raw_commit_node();
+       c->index = commit_count++;
+       return c;
+}
+
 static void report(const char *name, unsigned int count, size_t size)
 {
        fprintf(stderr, "%10s: %8u (%"PRIuMAX" kB)\n",
                        name, count, (uintmax_t) size);
 }
 
-#define REPORT(name)   \
-    report(#name, name##_allocs, name##_allocs * sizeof(struct name) >> 10)
+#define REPORT(name, type)     \
+    report(#name, name##_allocs, name##_allocs * sizeof(type) >> 10)
 
 void alloc_report(void)
 {
-       REPORT(blob);
-       REPORT(tree);
-       REPORT(commit);
-       REPORT(tag);
+       REPORT(blob, struct blob);
+       REPORT(tree, struct tree);
+       REPORT(raw_commit, struct commit);
+       REPORT(tag, struct tag);
+       REPORT(object, union any_object);
 }
index 9e960d549c158a4c761942bb17824c1d5e075d49..256741d2262b237c56b6730bea9d52c9b39b7ee3 100644 (file)
@@ -68,23 +68,3 @@ void argv_array_clear(struct argv_array *array)
        }
        argv_array_init(array);
 }
-
-const char **argv_array_detach(struct argv_array *array, int *argc)
-{
-       const char **argv =
-               array->argv == empty_argv || array->argc == 0 ? NULL : array->argv;
-       if (argc)
-               *argc = array->argc;
-       argv_array_init(array);
-       return argv;
-}
-
-void argv_array_free_detached(const char **argv)
-{
-       if (argv) {
-               int i;
-               for (i = 0; argv[i]; i++)
-                       free((char **)argv[i]);
-               free(argv);
-       }
-}
index 85ba438ac1e877fa865e5b4d2301733735fa5d03..c65e6e825a96efca6111184e5c50d2406064631f 100644 (file)
@@ -19,7 +19,5 @@ LAST_ARG_MUST_BE_NULL
 void argv_array_pushl(struct argv_array *, ...);
 void argv_array_pop(struct argv_array *);
 void argv_array_clear(struct argv_array *);
-const char **argv_array_detach(struct argv_array *array, int *argc);
-void argv_array_free_detached(const char **argv);
 
 #endif /* ARGV_ARRAY_H */
index 660097bc29a682c4481308ba245e5e02f0661681..46e8aa86df1811ff19899869a33ecb48cacb107f 100644 (file)
--- a/branch.c
+++ b/branch.c
@@ -50,11 +50,11 @@ static int should_setup_rebase(const char *origin)
 
 void install_branch_config(int flag, const char *local, const char *origin, const char *remote)
 {
-       const char *shortname = skip_prefix(remote, "refs/heads/");
+       const char *shortname = NULL;
        struct strbuf key = STRBUF_INIT;
        int rebasing = should_setup_rebase(origin);
 
-       if (shortname
+       if (skip_prefix(remote, "refs/heads/", &shortname)
            && !strcmp(local, shortname)
            && !origin) {
                warning(_("Not setting branch %s as its own upstream."),
index c47c110e0f18f3183d54c9afb63cffef686a21db..5d91f31ca25e0c16fca0e8c23d83706840bf6c57 100644 (file)
--- a/builtin.h
+++ b/builtin.h
@@ -128,6 +128,7 @@ extern int cmd_update_server_info(int argc, const char **argv, const char *prefi
 extern int cmd_upload_archive(int argc, const char **argv, const char *prefix);
 extern int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix);
 extern int cmd_var(int argc, const char **argv, const char *prefix);
+extern int cmd_verify_commit(int argc, const char **argv, const char *prefix);
 extern int cmd_verify_tag(int argc, const char **argv, const char *prefix);
 extern int cmd_version(int argc, const char **argv, const char *prefix);
 extern int cmd_whatchanged(int argc, const char **argv, const char *prefix);
index 459208a326cd4cebfa813168d81a06c27fc54fc5..4baf3a563510b10e592ff06ae62df2f405413f6c 100644 (file)
@@ -299,7 +299,6 @@ static int add_files(struct dir_struct *dir, int flags)
 int cmd_add(int argc, const char **argv, const char *prefix)
 {
        int exit_status = 0;
-       int newfd;
        struct pathspec pathspec;
        struct dir_struct dir;
        int flags;
@@ -345,7 +344,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
        add_new_files = !take_worktree_changes && !refresh_only;
        require_pathspec = !take_worktree_changes;
 
-       newfd = hold_locked_index(&lock_file, 1);
+       hold_locked_index(&lock_file, 1);
 
        flags = ((verbose ? ADD_CACHE_VERBOSE : 0) |
                 (show_only ? ADD_CACHE_PRETEND : 0) |
@@ -443,8 +442,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
 
 finish:
        if (active_cache_changed) {
-               if (write_cache(newfd, active_cache, active_nr) ||
-                   commit_locked_index(&lock_file))
+               if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
                        die(_("Unable to write new index file"));
        }
 
index 9c5724eaccfaee62ff10eb097adc39ace351cade..5fd099ed40859ddfd838ea99191921d63e6eed12 100644 (file)
@@ -1281,9 +1281,7 @@ static int parse_git_header(const char *line, int len, unsigned int size, struct
         */
        patch->def_name = git_header_name(line, len);
        if (patch->def_name && root) {
-               char *s = xmalloc(root_len + strlen(patch->def_name) + 1);
-               strcpy(s, root);
-               strcpy(s + root_len, patch->def_name);
+               char *s = xstrfmt("%s%s", root, patch->def_name);
                free(patch->def_name);
                patch->def_name = s;
        }
@@ -3086,13 +3084,15 @@ static void prepare_fn_table(struct patch *patch)
        }
 }
 
-static int checkout_target(struct cache_entry *ce, struct stat *st)
+static int checkout_target(struct index_state *istate,
+                          struct cache_entry *ce, struct stat *st)
 {
        struct checkout costate;
 
        memset(&costate, 0, sizeof(costate));
        costate.base_dir = "";
        costate.refresh_cache = 1;
+       costate.istate = istate;
        if (checkout_entry(ce, &costate, NULL) || lstat(ce->name, st))
                return error(_("cannot checkout %s"), ce->name);
        return 0;
@@ -3259,7 +3259,7 @@ static int load_current(struct image *image, struct patch *patch)
        if (lstat(name, &st)) {
                if (errno != ENOENT)
                        return error(_("%s: %s"), name, strerror(errno));
-               if (checkout_target(ce, &st))
+               if (checkout_target(&the_index, ce, &st))
                        return -1;
        }
        if (verify_index_match(ce, &st))
@@ -3413,7 +3413,7 @@ static int check_preimage(struct patch *patch, struct cache_entry **ce, struct s
                }
                *ce = active_cache[pos];
                if (stat_ret < 0) {
-                       if (checkout_target(*ce, st))
+                       if (checkout_target(&the_index, *ce, st))
                                return -1;
                }
                if (!cached && verify_index_match(*ce, st))
@@ -3646,7 +3646,7 @@ static void build_fake_ancestor(struct patch *list, const char *filename)
 {
        struct patch *patch;
        struct index_state result = { NULL };
-       int fd;
+       static struct lock_file lock;
 
        /* Once we start supporting the reverse patch, it may be
         * worth showing the new sha1 prefix, but until then...
@@ -3684,8 +3684,8 @@ static void build_fake_ancestor(struct patch *list, const char *filename)
                        die ("Could not add %s to temporary index", name);
        }
 
-       fd = open(filename, O_WRONLY | O_CREAT, 0666);
-       if (fd < 0 || write_index(&result, fd) || close(fd))
+       hold_lock_file_for_update(&lock, filename, LOCK_DIE_ON_ERROR);
+       if (write_locked_index(&result, &lock, COMMIT_LOCK))
                die ("Could not write temporary index to %s", filename);
 
        discard_index(&result);
@@ -3847,9 +3847,10 @@ static void add_index_file(const char *path, unsigned mode, void *buf, unsigned
        ce->ce_flags = create_ce_flags(0);
        ce->ce_namelen = namelen;
        if (S_ISGITLINK(mode)) {
-               const char *s = buf;
+               const char *s;
 
-               if (get_sha1_hex(s + strlen("Subproject commit "), ce->sha1))
+               if (!skip_prefix(buf, "Subproject commit ", &s) ||
+                   get_sha1_hex(s, ce->sha1))
                        die(_("corrupt patch for submodule %s"), path);
        } else {
                if (!cached) {
@@ -4503,8 +4504,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix_)
        }
 
        if (update_index) {
-               if (write_cache(newfd, active_cache, active_nr) ||
-                   commit_locked_index(&lock_file))
+               if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
                        die(_("Unable to write new index file"));
        }
 
index d8b276048eee8b557a7d3dc0294587913cd66a45..c59e70202175fc89992c23b48ea5f0738664a2f6 100644 (file)
@@ -1,7 +1,8 @@
 /*
  * Blame
  *
- * Copyright (c) 2006, Junio C Hamano
+ * Copyright (c) 2006, 2014 by its authors
+ * See COPYING for licensing conditions
  */
 
 #include "cache.h"
@@ -18,7 +19,9 @@
 #include "cache-tree.h"
 #include "string-list.h"
 #include "mailmap.h"
+#include "mergesort.h"
 #include "parse-options.h"
+#include "prio-queue.h"
 #include "utf8.h"
 #include "userdiff.h"
 #include "line-range.h"
@@ -83,11 +86,42 @@ static unsigned blame_copy_score;
  */
 struct origin {
        int refcnt;
+       /* Record preceding blame record for this blob */
        struct origin *previous;
+       /* origins are put in a list linked via `next' hanging off the
+        * corresponding commit's util field in order to make finding
+        * them fast.  The presence in this chain does not count
+        * towards the origin's reference count.  It is tempting to
+        * let it count as long as the commit is pending examination,
+        * but even under circumstances where the commit will be
+        * present multiple times in the priority queue of unexamined
+        * commits, processing the first instance will not leave any
+        * work requiring the origin data for the second instance.  An
+        * interspersed commit changing that would have to be
+        * preexisting with a different ancestry and with the same
+        * commit date in order to wedge itself between two instances
+        * of the same commit in the priority queue _and_ produce
+        * blame entries relevant for it.  While we don't want to let
+        * us get tripped up by this case, it certainly does not seem
+        * worth optimizing for.
+        */
+       struct origin *next;
        struct commit *commit;
+       /* `suspects' contains blame entries that may be attributed to
+        * this origin's commit or to parent commits.  When a commit
+        * is being processed, all suspects will be moved, either by
+        * assigning them to an origin in a different commit, or by
+        * shipping them to the scoreboard's ent list because they
+        * cannot be attributed to a different commit.
+        */
+       struct blame_entry *suspects;
        mmfile_t file;
        unsigned char blob_sha1[20];
        unsigned mode;
+       /* guilty gets set when shipping any suspects to the final
+        * blame list instead of other commits
+        */
+       char guilty;
        char path[FLEX_ARRAY];
 };
 
@@ -176,10 +210,22 @@ static inline struct origin *origin_incref(struct origin *o)
 static void origin_decref(struct origin *o)
 {
        if (o && --o->refcnt <= 0) {
+               struct origin *p, *l = NULL;
                if (o->previous)
                        origin_decref(o->previous);
                free(o->file.ptr);
-               free(o);
+               /* Should be present exactly once in commit chain */
+               for (p = o->commit->util; p; l = p, p = p->next) {
+                       if (p == o) {
+                               if (l)
+                                       l->next = p->next;
+                               else
+                                       o->commit->util = p->next;
+                               free(o);
+                               return;
+                       }
+               }
+               die("internal error in blame::origin_decref");
        }
 }
 
@@ -193,8 +239,12 @@ static void drop_origin_blob(struct origin *o)
 
 /*
  * Each group of lines is described by a blame_entry; it can be split
- * as we pass blame to the parents.  They form a linked list in the
- * scoreboard structure, sorted by the target line number.
+ * as we pass blame to the parents.  They are arranged in linked lists
+ * kept as `suspects' of some unprocessed origin, or entered (when the
+ * blame origin has been finalized) into the scoreboard structure.
+ * While the scoreboard structure is only sorted at the end of
+ * processing (according to final image line number), the lists
+ * attached to an origin are sorted by the target line number.
  */
 struct blame_entry {
        struct blame_entry *next;
@@ -210,15 +260,6 @@ struct blame_entry {
        /* the commit that introduced this group into the final image */
        struct origin *suspect;
 
-       /* true if the suspect is truly guilty; false while we have not
-        * checked if the group came from one of its parents.
-        */
-       char guilty;
-
-       /* true if the entry has been scanned for copies in the current parent
-        */
-       char scanned;
-
        /* the line number of the first line of this group in the
         * suspect's file; internally all line numbers are 0 based.
         */
@@ -230,12 +271,113 @@ struct blame_entry {
        unsigned score;
 };
 
+/*
+ * Any merge of blames happens on lists of blames that arrived via
+ * different parents in a single suspect.  In this case, we want to
+ * sort according to the suspect line numbers as opposed to the final
+ * image line numbers.  The function body is somewhat longish because
+ * it avoids unnecessary writes.
+ */
+
+static struct blame_entry *blame_merge(struct blame_entry *list1,
+                                      struct blame_entry *list2)
+{
+       struct blame_entry *p1 = list1, *p2 = list2,
+               **tail = &list1;
+
+       if (!p1)
+               return p2;
+       if (!p2)
+               return p1;
+
+       if (p1->s_lno <= p2->s_lno) {
+               do {
+                       tail = &p1->next;
+                       if ((p1 = *tail) == NULL) {
+                               *tail = p2;
+                               return list1;
+                       }
+               } while (p1->s_lno <= p2->s_lno);
+       }
+       for (;;) {
+               *tail = p2;
+               do {
+                       tail = &p2->next;
+                       if ((p2 = *tail) == NULL)  {
+                               *tail = p1;
+                               return list1;
+                       }
+               } while (p1->s_lno > p2->s_lno);
+               *tail = p1;
+               do {
+                       tail = &p1->next;
+                       if ((p1 = *tail) == NULL) {
+                               *tail = p2;
+                               return list1;
+                       }
+               } while (p1->s_lno <= p2->s_lno);
+       }
+}
+
+static void *get_next_blame(const void *p)
+{
+       return ((struct blame_entry *)p)->next;
+}
+
+static void set_next_blame(void *p1, void *p2)
+{
+       ((struct blame_entry *)p1)->next = p2;
+}
+
+/*
+ * Final image line numbers are all different, so we don't need a
+ * three-way comparison here.
+ */
+
+static int compare_blame_final(const void *p1, const void *p2)
+{
+       return ((struct blame_entry *)p1)->lno > ((struct blame_entry *)p2)->lno
+               ? 1 : -1;
+}
+
+static int compare_blame_suspect(const void *p1, const void *p2)
+{
+       const struct blame_entry *s1 = p1, *s2 = p2;
+       /*
+        * to allow for collating suspects, we sort according to the
+        * respective pointer value as the primary sorting criterion.
+        * The actual relation is pretty unimportant as long as it
+        * establishes a total order.  Comparing as integers gives us
+        * that.
+        */
+       if (s1->suspect != s2->suspect)
+               return (intptr_t)s1->suspect > (intptr_t)s2->suspect ? 1 : -1;
+       if (s1->s_lno == s2->s_lno)
+               return 0;
+       return s1->s_lno > s2->s_lno ? 1 : -1;
+}
+
+static struct blame_entry *blame_sort(struct blame_entry *head,
+                                     int (*compare_fn)(const void *, const void *))
+{
+       return llist_mergesort (head, get_next_blame, set_next_blame, compare_fn);
+}
+
+static int compare_commits_by_reverse_commit_date(const void *a,
+                                                 const void *b,
+                                                 void *c)
+{
+       return -compare_commits_by_commit_date(a, b, c);
+}
+
 /*
  * The current state of the blame assignment.
  */
 struct scoreboard {
        /* the final commit (i.e. where we started digging from) */
        struct commit *final;
+       /* Priority queue for commits with unassigned blame records */
+       struct prio_queue commits;
        struct rev_info *revs;
        const char *path;
 
@@ -268,7 +410,6 @@ static void coalesce(struct scoreboard *sb)
 
        for (ent = sb->ent; ent && (next = ent->next); ent = next) {
                if (ent->suspect == next->suspect &&
-                   ent->guilty == next->guilty &&
                    ent->s_lno + ent->num_lines == next->s_lno) {
                        ent->num_lines += next->num_lines;
                        ent->next = next->next;
@@ -283,6 +424,30 @@ static void coalesce(struct scoreboard *sb)
                sanity_check_refcnt(sb);
 }
 
+/*
+ * Merge the given sorted list of blames into a preexisting origin.
+ * If there were no previous blames to that commit, it is entered into
+ * the commit priority queue of the score board.
+ */
+
+static void queue_blames(struct scoreboard *sb, struct origin *porigin,
+                        struct blame_entry *sorted)
+{
+       if (porigin->suspects)
+               porigin->suspects = blame_merge(porigin->suspects, sorted);
+       else {
+               struct origin *o;
+               for (o = porigin->commit->util; o; o = o->next) {
+                       if (o->suspects) {
+                               porigin->suspects = sorted;
+                               return;
+                       }
+               }
+               porigin->suspects = sorted;
+               prio_queue_put(&sb->commits, porigin->commit);
+       }
+}
+
 /*
  * Given a commit and a path in it, create a new origin structure.
  * The callers that add blame to the scoreboard should use
@@ -295,23 +460,32 @@ static struct origin *make_origin(struct commit *commit, const char *path)
        o = xcalloc(1, sizeof(*o) + strlen(path) + 1);
        o->commit = commit;
        o->refcnt = 1;
+       o->next = commit->util;
+       commit->util = o;
        strcpy(o->path, path);
        return o;
 }
 
 /*
  * Locate an existing origin or create a new one.
+ * This moves the origin to front position in the commit util list.
  */
 static struct origin *get_origin(struct scoreboard *sb,
                                 struct commit *commit,
                                 const char *path)
 {
-       struct blame_entry *e;
+       struct origin *o, *l;
 
-       for (e = sb->ent; e; e = e->next) {
-               if (e->suspect->commit == commit &&
-                   !strcmp(e->suspect->path, path))
-                       return origin_incref(e->suspect);
+       for (o = commit->util, l = NULL; o; l = o, o = o->next) {
+               if (!strcmp(o->path, path)) {
+                       /* bump to front */
+                       if (l) {
+                               l->next = o->next;
+                               o->next = commit->util;
+                               commit->util = o;
+                       }
+                       return origin_incref(o);
+               }
        }
        return make_origin(commit, path);
 }
@@ -350,41 +524,19 @@ static struct origin *find_origin(struct scoreboard *sb,
                                  struct commit *parent,
                                  struct origin *origin)
 {
-       struct origin *porigin = NULL;
+       struct origin *porigin;
        struct diff_options diff_opts;
        const char *paths[2];
 
-       if (parent->util) {
-               /*
-                * Each commit object can cache one origin in that
-                * commit.  This is a freestanding copy of origin and
-                * not refcounted.
-                */
-               struct origin *cached = parent->util;
-               if (!strcmp(cached->path, origin->path)) {
+       /* First check any existing origins */
+       for (porigin = parent->util; porigin; porigin = porigin->next)
+               if (!strcmp(porigin->path, origin->path)) {
                        /*
                         * The same path between origin and its parent
                         * without renaming -- the most common case.
                         */
-                       porigin = get_origin(sb, parent, cached->path);
-
-                       /*
-                        * If the origin was newly created (i.e. get_origin
-                        * would call make_origin if none is found in the
-                        * scoreboard), it does not know the blob_sha1/mode,
-                        * so copy it.  Otherwise porigin was in the
-                        * scoreboard and already knows blob_sha1/mode.
-                        */
-                       if (porigin->refcnt == 1) {
-                               hashcpy(porigin->blob_sha1, cached->blob_sha1);
-                               porigin->mode = cached->mode;
-                       }
-                       return porigin;
+                       return origin_incref (porigin);
                }
-               /* otherwise it was not very useful; free it */
-               free(parent->util);
-               parent->util = NULL;
-       }
 
        /* See if the origin->path is different between parent
         * and origin first.  Most of the time they are the
@@ -450,19 +602,6 @@ static struct origin *find_origin(struct scoreboard *sb,
        }
        diff_flush(&diff_opts);
        free_pathspec(&diff_opts.pathspec);
-       if (porigin) {
-               /*
-                * Create a freestanding copy that is not part of
-                * the refcounted origin found in the scoreboard, and
-                * cache it in the commit.
-                */
-               struct origin *cached;
-
-               cached = make_origin(porigin->commit, porigin->path);
-               hashcpy(cached->blob_sha1, porigin->blob_sha1);
-               cached->mode = porigin->mode;
-               parent->util = cached;
-       }
        return porigin;
 }
 
@@ -509,46 +648,31 @@ static struct origin *find_rename(struct scoreboard *sb,
 }
 
 /*
- * Link in a new blame entry to the scoreboard.  Entries that cover the
- * same line range have been removed from the scoreboard previously.
+ * Append a new blame entry to a given output queue.
  */
-static void add_blame_entry(struct scoreboard *sb, struct blame_entry *e)
+static void add_blame_entry(struct blame_entry ***queue, struct blame_entry *e)
 {
-       struct blame_entry *ent, *prev = NULL;
-
        origin_incref(e->suspect);
 
-       for (ent = sb->ent; ent && ent->lno < e->lno; ent = ent->next)
-               prev = ent;
-
-       /* prev, if not NULL, is the last one that is below e */
-
-       if (prev) {
-               e->next = prev->next;
-               prev->next = e;
-       }
-       else {
-               e->next = sb->ent;
-               sb->ent = e;
-       }
+       e->next = **queue;
+       **queue = e;
+       *queue = &e->next;
 }
 
 /*
  * src typically is on-stack; we want to copy the information in it to
- * a malloced blame_entry that is already on the linked list of the
- * scoreboard.  The origin of dst loses a refcnt while the origin of src
- * gains one.
+ * a malloced blame_entry that gets added to the given queue.  The
+ * origin of dst loses a refcnt.
  */
-static void dup_entry(struct blame_entry *dst, struct blame_entry *src)
+static void dup_entry(struct blame_entry ***queue,
+                     struct blame_entry *dst, struct blame_entry *src)
 {
-       struct blame_entry *n;
-
-       n = dst->next;
        origin_incref(src->suspect);
        origin_decref(dst->suspect);
        memcpy(dst, src, sizeof(*src));
-       dst->next = n;
-       dst->score = 0;
+       dst->next = **queue;
+       **queue = dst;
+       *queue = &dst->next;
 }
 
 static const char *nth_line(struct scoreboard *sb, long lno)
@@ -620,10 +744,11 @@ static void split_overlap(struct blame_entry *split,
 
 /*
  * split_overlap() divided an existing blame e into up to three parts
- * in split.  Adjust the linked list of blames in the scoreboard to
+ * in split.  Any assigned blame is moved to queue to
  * reflect the split.
  */
-static void split_blame(struct scoreboard *sb,
+static void split_blame(struct blame_entry ***blamed,
+                       struct blame_entry ***unblamed,
                        struct blame_entry *split,
                        struct blame_entry *e)
 {
@@ -631,61 +756,39 @@ static void split_blame(struct scoreboard *sb,
 
        if (split[0].suspect && split[2].suspect) {
                /* The first part (reuse storage for the existing entry e) */
-               dup_entry(e, &split[0]);
+               dup_entry(unblamed, e, &split[0]);
 
                /* The last part -- me */
                new_entry = xmalloc(sizeof(*new_entry));
                memcpy(new_entry, &(split[2]), sizeof(struct blame_entry));
-               add_blame_entry(sb, new_entry);
+               add_blame_entry(unblamed, new_entry);
 
                /* ... and the middle part -- parent */
                new_entry = xmalloc(sizeof(*new_entry));
                memcpy(new_entry, &(split[1]), sizeof(struct blame_entry));
-               add_blame_entry(sb, new_entry);
+               add_blame_entry(blamed, new_entry);
        }
        else if (!split[0].suspect && !split[2].suspect)
                /*
                 * The parent covers the entire area; reuse storage for
                 * e and replace it with the parent.
                 */
-               dup_entry(e, &split[1]);
+               dup_entry(blamed, e, &split[1]);
        else if (split[0].suspect) {
                /* me and then parent */
-               dup_entry(e, &split[0]);
+               dup_entry(unblamed, e, &split[0]);
 
                new_entry = xmalloc(sizeof(*new_entry));
                memcpy(new_entry, &(split[1]), sizeof(struct blame_entry));
-               add_blame_entry(sb, new_entry);
+               add_blame_entry(blamed, new_entry);
        }
        else {
                /* parent and then me */
-               dup_entry(e, &split[1]);
+               dup_entry(blamed, e, &split[1]);
 
                new_entry = xmalloc(sizeof(*new_entry));
                memcpy(new_entry, &(split[2]), sizeof(struct blame_entry));
-               add_blame_entry(sb, new_entry);
-       }
-
-       if (DEBUG) { /* sanity */
-               struct blame_entry *ent;
-               int lno = sb->ent->lno, corrupt = 0;
-
-               for (ent = sb->ent; ent; ent = ent->next) {
-                       if (lno != ent->lno)
-                               corrupt = 1;
-                       if (ent->s_lno < 0)
-                               corrupt = 1;
-                       lno += ent->num_lines;
-               }
-               if (corrupt) {
-                       lno = sb->ent->lno;
-                       for (ent = sb->ent; ent; ent = ent->next) {
-                               printf("L %8d l %8d n %8d\n",
-                                      lno, ent->lno, ent->num_lines);
-                               lno = ent->lno + ent->num_lines;
-                       }
-                       die("oops");
-               }
+               add_blame_entry(unblamed, new_entry);
        }
 }
 
@@ -702,74 +805,146 @@ static void decref_split(struct blame_entry *split)
 }
 
 /*
- * Helper for blame_chunk().  blame_entry e is known to overlap with
- * the patch hunk; split it and pass blame to the parent.
+ * reverse_blame reverses the list given in head, appending tail.
+ * That allows us to build lists in reverse order, then reverse them
+ * afterwards.  This can be faster than building the list in proper
+ * order right away.  The reason is that building in proper order
+ * requires writing a link in the _previous_ element, while building
+ * in reverse order just requires placing the list head into the
+ * _current_ element.
  */
-static void blame_overlap(struct scoreboard *sb, struct blame_entry *e,
-                         int tlno, int plno, int same,
-                         struct origin *parent)
-{
-       struct blame_entry split[3];
-
-       split_overlap(split, e, tlno, plno, same, parent);
-       if (split[1].suspect)
-               split_blame(sb, split, e);
-       decref_split(split);
-}
 
-/*
- * Find the line number of the last line the target is suspected for.
- */
-static int find_last_in_target(struct scoreboard *sb, struct origin *target)
+static struct blame_entry *reverse_blame(struct blame_entry *head,
+                                        struct blame_entry *tail)
 {
-       struct blame_entry *e;
-       int last_in_target = -1;
-
-       for (e = sb->ent; e; e = e->next) {
-               if (e->guilty || e->suspect != target)
-                       continue;
-               if (last_in_target < e->s_lno + e->num_lines)
-                       last_in_target = e->s_lno + e->num_lines;
+       while (head) {
+               struct blame_entry *next = head->next;
+               head->next = tail;
+               tail = head;
+               head = next;
        }
-       return last_in_target;
+       return tail;
 }
 
 /*
  * Process one hunk from the patch between the current suspect for
- * blame_entry e and its parent.  Find and split the overlap, and
- * pass blame to the overlapping part to the parent.
+ * blame_entry e and its parent.  This first blames any unfinished
+ * entries before the chunk (which is where target and parent start
+ * differing) on the parent, and then splits blame entries at the
+ * start and at the end of the difference region.  Since use of -M and
+ * -C options may lead to overlapping/duplicate source line number
+ * ranges, all we can rely on from sorting/merging is the order of the
+ * first suspect line number.
  */
-static void blame_chunk(struct scoreboard *sb,
-                       int tlno, int plno, int same,
-                       struct origin *target, struct origin *parent)
+static void blame_chunk(struct blame_entry ***dstq, struct blame_entry ***srcq,
+                       int tlno, int offset, int same,
+                       struct origin *parent)
 {
-       struct blame_entry *e;
+       struct blame_entry *e = **srcq;
+       struct blame_entry *samep = NULL, *diffp = NULL;
 
-       for (e = sb->ent; e; e = e->next) {
-               if (e->guilty || e->suspect != target)
-                       continue;
-               if (same <= e->s_lno)
-                       continue;
-               if (tlno < e->s_lno + e->num_lines)
-                       blame_overlap(sb, e, tlno, plno, same, parent);
+       while (e && e->s_lno < tlno) {
+               struct blame_entry *next = e->next;
+               /*
+                * current record starts before differing portion.  If
+                * it reaches into it, we need to split it up and
+                * examine the second part separately.
+                */
+               if (e->s_lno + e->num_lines > tlno) {
+                       /* Move second half to a new record */
+                       int len = tlno - e->s_lno;
+                       struct blame_entry *n = xcalloc(1, sizeof (struct blame_entry));
+                       n->suspect = e->suspect;
+                       n->lno = e->lno + len;
+                       n->s_lno = e->s_lno + len;
+                       n->num_lines = e->num_lines - len;
+                       e->num_lines = len;
+                       e->score = 0;
+                       /* Push new record to diffp */
+                       n->next = diffp;
+                       diffp = n;
+               } else
+                       origin_decref(e->suspect);
+               /* Pass blame for everything before the differing
+                * chunk to the parent */
+               e->suspect = origin_incref(parent);
+               e->s_lno += offset;
+               e->next = samep;
+               samep = e;
+               e = next;
+       }
+       /*
+        * As we don't know how much of a common stretch after this
+        * diff will occur, the currently blamed parts are all that we
+        * can assign to the parent for now.
+        */
+
+       if (samep) {
+               **dstq = reverse_blame(samep, **dstq);
+               *dstq = &samep->next;
+       }
+       /*
+        * Prepend the split off portions: everything after e starts
+        * after the blameable portion.
+        */
+       e = reverse_blame(diffp, e);
+
+       /*
+        * Now retain records on the target while parts are different
+        * from the parent.
+        */
+       samep = NULL;
+       diffp = NULL;
+       while (e && e->s_lno < same) {
+               struct blame_entry *next = e->next;
+
+               /*
+                * If current record extends into sameness, need to split.
+                */
+               if (e->s_lno + e->num_lines > same) {
+                       /*
+                        * Move second half to a new record to be
+                        * processed by later chunks
+                        */
+                       int len = same - e->s_lno;
+                       struct blame_entry *n = xcalloc(1, sizeof (struct blame_entry));
+                       n->suspect = origin_incref(e->suspect);
+                       n->lno = e->lno + len;
+                       n->s_lno = e->s_lno + len;
+                       n->num_lines = e->num_lines - len;
+                       e->num_lines = len;
+                       e->score = 0;
+                       /* Push new record to samep */
+                       n->next = samep;
+                       samep = n;
+               }
+               e->next = diffp;
+               diffp = e;
+               e = next;
        }
+       **srcq = reverse_blame(diffp, reverse_blame(samep, e));
+       /* Move across elements that are in the unblamable portion */
+       if (diffp)
+               *srcq = &diffp->next;
 }
 
 struct blame_chunk_cb_data {
-       struct scoreboard *sb;
-       struct origin *target;
        struct origin *parent;
-       long plno;
-       long tlno;
+       long offset;
+       struct blame_entry **dstq;
+       struct blame_entry **srcq;
 };
 
+/* diff chunks are from parent to target */
 static int blame_chunk_cb(long start_a, long count_a,
                          long start_b, long count_b, void *data)
 {
        struct blame_chunk_cb_data *d = data;
-       blame_chunk(d->sb, d->tlno, d->plno, start_b, d->target, d->parent);
-       d->plno = start_a + count_a;
-       d->tlno = start_b + count_b;
+       if (start_a - start_b != d->offset)
+               die("internal error in blame::blame_chunk_cb");
+       blame_chunk(&d->dstq, &d->srcq, start_b, start_a - start_b,
+                   start_b + count_b, d->parent);
+       d->offset = start_a + count_a - (start_b + count_b);
        return 0;
 }
 
@@ -778,29 +953,32 @@ static int blame_chunk_cb(long start_a, long count_a,
  * for the lines it is suspected to its parent.  Run diff to find
  * which lines came from parent and pass blame for them.
  */
-static int pass_blame_to_parent(struct scoreboard *sb,
-                               struct origin *target,
-                               struct origin *parent)
+static void pass_blame_to_parent(struct scoreboard *sb,
+                                struct origin *target,
+                                struct origin *parent)
 {
-       int last_in_target;
        mmfile_t file_p, file_o;
        struct blame_chunk_cb_data d;
+       struct blame_entry *newdest = NULL;
 
-       memset(&d, 0, sizeof(d));
-       d.sb = sb; d.target = target; d.parent = parent;
-       last_in_target = find_last_in_target(sb, target);
-       if (last_in_target < 0)
-               return 1; /* nothing remains for this target */
+       if (!target->suspects)
+               return; /* nothing remains for this target */
+
+       d.parent = parent;
+       d.offset = 0;
+       d.dstq = &newdest; d.srcq = &target->suspects;
 
        fill_origin_blob(&sb->revs->diffopt, parent, &file_p);
        fill_origin_blob(&sb->revs->diffopt, target, &file_o);
        num_get_patch++;
 
        diff_hunks(&file_p, &file_o, 0, blame_chunk_cb, &d);
-       /* The rest (i.e. anything after tlno) are the same as the parent */
-       blame_chunk(sb, d.tlno, d.plno, last_in_target, target, parent);
+       /* The rest are the same as the parent */
+       blame_chunk(&d.dstq, &d.srcq, INT_MAX, d.offset, INT_MAX, parent);
+       *d.dstq = NULL;
+       queue_blames(sb, parent, newdest);
 
-       return 0;
+       return;
 }
 
 /*
@@ -945,43 +1123,80 @@ static void find_copy_in_blob(struct scoreboard *sb,
        handle_split(sb, ent, d.tlno, d.plno, ent->num_lines, parent, split);
 }
 
+/* Move all blame entries from list *source that have a score smaller
+ * than score_min to the front of list *small.
+ * Returns a pointer to the link pointing to the old head of the small list.
+ */
+
+static struct blame_entry **filter_small(struct scoreboard *sb,
+                                        struct blame_entry **small,
+                                        struct blame_entry **source,
+                                        unsigned score_min)
+{
+       struct blame_entry *p = *source;
+       struct blame_entry *oldsmall = *small;
+       while (p) {
+               if (ent_score(sb, p) <= score_min) {
+                       *small = p;
+                       small = &p->next;
+                       p = *small;
+               } else {
+                       *source = p;
+                       source = &p->next;
+                       p = *source;
+               }
+       }
+       *small = oldsmall;
+       *source = NULL;
+       return small;
+}
+
 /*
  * See if lines currently target is suspected for can be attributed to
  * parent.
  */
-static int find_move_in_parent(struct scoreboard *sb,
-                              struct origin *target,
-                              struct origin *parent)
+static void find_move_in_parent(struct scoreboard *sb,
+                               struct blame_entry ***blamed,
+                               struct blame_entry **toosmall,
+                               struct origin *target,
+                               struct origin *parent)
 {
-       int last_in_target, made_progress;
        struct blame_entry *e, split[3];
+       struct blame_entry *unblamed = target->suspects;
+       struct blame_entry *leftover = NULL;
        mmfile_t file_p;
 
-       last_in_target = find_last_in_target(sb, target);
-       if (last_in_target < 0)
-               return 1; /* nothing remains for this target */
+       if (!unblamed)
+               return; /* nothing remains for this target */
 
        fill_origin_blob(&sb->revs->diffopt, parent, &file_p);
        if (!file_p.ptr)
-               return 0;
+               return;
 
-       made_progress = 1;
-       while (made_progress) {
-               made_progress = 0;
-               for (e = sb->ent; e; e = e->next) {
-                       if (e->guilty || e->suspect != target ||
-                           ent_score(sb, e) < blame_move_score)
-                               continue;
+       /* At each iteration, unblamed has a NULL-terminated list of
+        * entries that have not yet been tested for blame.  leftover
+        * contains the reversed list of entries that have been tested
+        * without being assignable to the parent.
+        */
+       do {
+               struct blame_entry **unblamedtail = &unblamed;
+               struct blame_entry *next;
+               for (e = unblamed; e; e = next) {
+                       next = e->next;
                        find_copy_in_blob(sb, e, parent, split, &file_p);
                        if (split[1].suspect &&
                            blame_move_score < ent_score(sb, &split[1])) {
-                               split_blame(sb, split, e);
-                               made_progress = 1;
+                               split_blame(blamed, &unblamedtail, split, e);
+                       } else {
+                               e->next = leftover;
+                               leftover = e;
                        }
                        decref_split(split);
                }
-       }
-       return 0;
+               *unblamedtail = NULL;
+               toosmall = filter_small(sb, toosmall, &unblamed, blame_move_score);
+       } while (unblamed);
+       target->suspects = reverse_blame(leftover, NULL);
 }
 
 struct blame_list {
@@ -993,62 +1208,46 @@ struct blame_list {
  * Count the number of entries the target is suspected for,
  * and prepare a list of entry and the best split.
  */
-static struct blame_list *setup_blame_list(struct scoreboard *sb,
-                                          struct origin *target,
-                                          int min_score,
+static struct blame_list *setup_blame_list(struct blame_entry *unblamed,
                                           int *num_ents_p)
 {
        struct blame_entry *e;
        int num_ents, i;
        struct blame_list *blame_list = NULL;
 
-       for (e = sb->ent, num_ents = 0; e; e = e->next)
-               if (!e->scanned && !e->guilty &&
-                   e->suspect == target &&
-                   min_score < ent_score(sb, e))
-                       num_ents++;
+       for (e = unblamed, num_ents = 0; e; e = e->next)
+               num_ents++;
        if (num_ents) {
                blame_list = xcalloc(num_ents, sizeof(struct blame_list));
-               for (e = sb->ent, i = 0; e; e = e->next)
-                       if (!e->scanned && !e->guilty &&
-                           e->suspect == target &&
-                           min_score < ent_score(sb, e))
-                               blame_list[i++].ent = e;
+               for (e = unblamed, i = 0; e; e = e->next)
+                       blame_list[i++].ent = e;
        }
        *num_ents_p = num_ents;
        return blame_list;
 }
 
-/*
- * Reset the scanned status on all entries.
- */
-static void reset_scanned_flag(struct scoreboard *sb)
-{
-       struct blame_entry *e;
-       for (e = sb->ent; e; e = e->next)
-               e->scanned = 0;
-}
-
 /*
  * For lines target is suspected for, see if we can find code movement
  * across file boundary from the parent commit.  porigin is the path
  * in the parent we already tried.
  */
-static int find_copy_in_parent(struct scoreboard *sb,
-                              struct origin *target,
-                              struct commit *parent,
-                              struct origin *porigin,
-                              int opt)
+static void find_copy_in_parent(struct scoreboard *sb,
+                               struct blame_entry ***blamed,
+                               struct blame_entry **toosmall,
+                               struct origin *target,
+                               struct commit *parent,
+                               struct origin *porigin,
+                               int opt)
 {
        struct diff_options diff_opts;
        int i, j;
-       int retval;
        struct blame_list *blame_list;
        int num_ents;
+       struct blame_entry *unblamed = target->suspects;
+       struct blame_entry *leftover = NULL;
 
-       blame_list = setup_blame_list(sb, target, blame_copy_score, &num_ents);
-       if (!blame_list)
-               return 1; /* nothing remains for this target */
+       if (!unblamed)
+               return; /* nothing remains for this target */
 
        diff_setup(&diff_opts);
        DIFF_OPT_SET(&diff_opts, RECURSIVE);
@@ -1078,9 +1277,9 @@ static int find_copy_in_parent(struct scoreboard *sb,
        if (!DIFF_OPT_TST(&diff_opts, FIND_COPIES_HARDER))
                diffcore_std(&diff_opts);
 
-       retval = 0;
-       while (1) {
-               int made_progress = 0;
+       do {
+               struct blame_entry **unblamedtail = &unblamed;
+               blame_list = setup_blame_list(unblamed, &num_ents);
 
                for (i = 0; i < diff_queued_diff.nr; i++) {
                        struct diff_filepair *p = diff_queued_diff.queue[i];
@@ -1117,27 +1316,21 @@ static int find_copy_in_parent(struct scoreboard *sb,
                        struct blame_entry *split = blame_list[j].split;
                        if (split[1].suspect &&
                            blame_copy_score < ent_score(sb, &split[1])) {
-                               split_blame(sb, split, blame_list[j].ent);
-                               made_progress = 1;
+                               split_blame(blamed, &unblamedtail, split,
+                                           blame_list[j].ent);
+                       } else {
+                               blame_list[j].ent->next = leftover;
+                               leftover = blame_list[j].ent;
                        }
-                       else
-                               blame_list[j].ent->scanned = 1;
                        decref_split(split);
                }
                free(blame_list);
-
-               if (!made_progress)
-                       break;
-               blame_list = setup_blame_list(sb, target, blame_copy_score, &num_ents);
-               if (!blame_list) {
-                       retval = 1;
-                       break;
-               }
-       }
-       reset_scanned_flag(sb);
+               *unblamedtail = NULL;
+               toosmall = filter_small(sb, toosmall, &unblamed, blame_copy_score);
+       } while (unblamed);
+       target->suspects = reverse_blame(leftover, NULL);
        diff_flush(&diff_opts);
        free_pathspec(&diff_opts.pathspec);
-       return retval;
 }
 
 /*
@@ -1147,20 +1340,21 @@ static int find_copy_in_parent(struct scoreboard *sb,
 static void pass_whole_blame(struct scoreboard *sb,
                             struct origin *origin, struct origin *porigin)
 {
-       struct blame_entry *e;
+       struct blame_entry *e, *suspects;
 
        if (!porigin->file.ptr && origin->file.ptr) {
                /* Steal its file */
                porigin->file = origin->file;
                origin->file.ptr = NULL;
        }
-       for (e = sb->ent; e; e = e->next) {
-               if (e->suspect != origin)
-                       continue;
+       suspects = origin->suspects;
+       origin->suspects = NULL;
+       for (e = suspects; e; e = e->next) {
                origin_incref(porigin);
                origin_decref(e->suspect);
                e->suspect = porigin;
        }
+       queue_blames(sb, porigin, suspects);
 }
 
 /*
@@ -1184,6 +1378,27 @@ static int num_scapegoats(struct rev_info *revs, struct commit *commit)
        return cnt;
 }
 
+/* Distribute collected unsorted blames to the respected sorted lists
+ * in the various origins.
+ */
+static void distribute_blame(struct scoreboard *sb, struct blame_entry *blamed)
+{
+       blamed = blame_sort(blamed, compare_blame_suspect);
+       while (blamed)
+       {
+               struct origin *porigin = blamed->suspect;
+               struct blame_entry *suspects = NULL;
+               do {
+                       struct blame_entry *next = blamed->next;
+                       blamed->next = suspects;
+                       suspects = blamed;
+                       blamed = next;
+               } while (blamed && blamed->suspect == porigin);
+               suspects = reverse_blame(suspects, NULL);
+               queue_blames(sb, porigin, suspects);
+       }
+}
+
 #define MAXSG 16
 
 static void pass_blame(struct scoreboard *sb, struct origin *origin, int opt)
@@ -1194,6 +1409,8 @@ static void pass_blame(struct scoreboard *sb, struct origin *origin, int opt)
        struct commit_list *sg;
        struct origin *sg_buf[MAXSG];
        struct origin *porigin, **sg_origin = sg_buf;
+       struct blame_entry *toosmall = NULL;
+       struct blame_entry *blames, **blametail = &blames;
 
        num_sg = num_scapegoats(revs, commit);
        if (!num_sg)
@@ -1255,38 +1472,71 @@ static void pass_blame(struct scoreboard *sb, struct origin *origin, int opt)
                        origin_incref(porigin);
                        origin->previous = porigin;
                }
-               if (pass_blame_to_parent(sb, origin, porigin))
+               pass_blame_to_parent(sb, origin, porigin);
+               if (!origin->suspects)
                        goto finish;
        }
 
        /*
         * Optionally find moves in parents' files.
         */
-       if (opt & PICKAXE_BLAME_MOVE)
-               for (i = 0, sg = first_scapegoat(revs, commit);
-                    i < num_sg && sg;
-                    sg = sg->next, i++) {
-                       struct origin *porigin = sg_origin[i];
-                       if (!porigin)
-                               continue;
-                       if (find_move_in_parent(sb, origin, porigin))
-                               goto finish;
+       if (opt & PICKAXE_BLAME_MOVE) {
+               filter_small(sb, &toosmall, &origin->suspects, blame_move_score);
+               if (origin->suspects) {
+                       for (i = 0, sg = first_scapegoat(revs, commit);
+                            i < num_sg && sg;
+                            sg = sg->next, i++) {
+                               struct origin *porigin = sg_origin[i];
+                               if (!porigin)
+                                       continue;
+                               find_move_in_parent(sb, &blametail, &toosmall, origin, porigin);
+                               if (!origin->suspects)
+                                       break;
+                       }
                }
+       }
 
        /*
         * Optionally find copies from parents' files.
         */
-       if (opt & PICKAXE_BLAME_COPY)
+       if (opt & PICKAXE_BLAME_COPY) {
+               if (blame_copy_score > blame_move_score)
+                       filter_small(sb, &toosmall, &origin->suspects, blame_copy_score);
+               else if (blame_copy_score < blame_move_score) {
+                       origin->suspects = blame_merge(origin->suspects, toosmall);
+                       toosmall = NULL;
+                       filter_small(sb, &toosmall, &origin->suspects, blame_copy_score);
+               }
+               if (!origin->suspects)
+                       goto finish;
+
                for (i = 0, sg = first_scapegoat(revs, commit);
                     i < num_sg && sg;
                     sg = sg->next, i++) {
                        struct origin *porigin = sg_origin[i];
-                       if (find_copy_in_parent(sb, origin, sg->item,
-                                               porigin, opt))
+                       find_copy_in_parent(sb, &blametail, &toosmall,
+                                           origin, sg->item, porigin, opt);
+                       if (!origin->suspects)
                                goto finish;
                }
+       }
 
- finish:
+finish:
+       *blametail = NULL;
+       distribute_blame(sb, blames);
+       /*
+        * prepend toosmall to origin->suspects
+        *
+        * There is no point in sorting: this ends up on a big
+        * unsorted list in the caller anyway.
+        */
+       if (toosmall) {
+               struct blame_entry **tail = &toosmall;
+               while (*tail)
+                       tail = &(*tail)->next;
+               *tail = origin->suspects;
+               origin->suspects = toosmall;
+       }
        for (i = 0; i < num_sg; i++) {
                if (sg_origin[i]) {
                        drop_origin_blob(sg_origin[i]);
@@ -1405,7 +1655,7 @@ static void get_commit_info(struct commit *commit,
 {
        int len;
        const char *subject, *encoding;
-       char *message;
+       const char *message;
 
        commit_info_init(ret);
 
@@ -1416,7 +1666,7 @@ static void get_commit_info(struct commit *commit,
                    &ret->author_time, &ret->author_tz);
 
        if (!detailed) {
-               logmsg_free(message, commit);
+               unuse_commit_buffer(commit, message);
                return;
        }
 
@@ -1430,7 +1680,7 @@ static void get_commit_info(struct commit *commit,
        else
                strbuf_addf(&ret->summary, "(%s)", sha1_to_hex(commit->object.sha1));
 
-       logmsg_free(message, commit);
+       unuse_commit_buffer(commit, message);
 }
 
 /*
@@ -1481,14 +1731,11 @@ static int emit_one_suspect_detail(struct origin *suspect, int repeat)
 }
 
 /*
- * The blame_entry is found to be guilty for the range.  Mark it
- * as such, and show it in incremental output.
+ * The blame_entry is found to be guilty for the range.
+ * Show it in incremental output.
  */
 static void found_guilty_entry(struct blame_entry *ent)
 {
-       if (ent->guilty)
-               return;
-       ent->guilty = 1;
        if (incremental) {
                struct origin *suspect = ent->suspect;
 
@@ -1502,32 +1749,34 @@ static void found_guilty_entry(struct blame_entry *ent)
 }
 
 /*
- * The main loop -- while the scoreboard has lines whose true origin
- * is still unknown, pick one blame_entry, and allow its current
- * suspect to pass blames to its parents.
- */
+ * The main loop -- while we have blobs with lines whose true origin
+ * is still unknown, pick one blob, and allow its lines to pass blames
+ * to its parents. */
 static void assign_blame(struct scoreboard *sb, int opt)
 {
        struct rev_info *revs = sb->revs;
+       struct commit *commit = prio_queue_get(&sb->commits);
 
-       while (1) {
+       while (commit) {
                struct blame_entry *ent;
-               struct commit *commit;
-               struct origin *suspect = NULL;
+               struct origin *suspect = commit->util;
 
                /* find one suspect to break down */
-               for (ent = sb->ent; !suspect && ent; ent = ent->next)
-                       if (!ent->guilty)
-                               suspect = ent->suspect;
-               if (!suspect)
-                       return; /* all done */
+               while (suspect && !suspect->suspects)
+                       suspect = suspect->next;
+
+               if (!suspect) {
+                       commit = prio_queue_get(&sb->commits);
+                       continue;
+               }
+
+               assert(commit == suspect->commit);
 
                /*
                 * We will use this suspect later in the loop,
                 * so hold onto it in the meantime.
                 */
                origin_incref(suspect);
-               commit = suspect->commit;
                parse_commit(commit);
                if (reverse ||
                    (!(commit->object.flags & UNINTERESTING) &&
@@ -1543,9 +1792,22 @@ static void assign_blame(struct scoreboard *sb, int opt)
                        commit->object.flags |= UNINTERESTING;
 
                /* Take responsibility for the remaining entries */
-               for (ent = sb->ent; ent; ent = ent->next)
-                       if (ent->suspect == suspect)
+               ent = suspect->suspects;
+               if (ent) {
+                       suspect->guilty = 1;
+                       for (;;) {
+                               struct blame_entry *next = ent->next;
                                found_guilty_entry(ent);
+                               if (next) {
+                                       ent = next;
+                                       continue;
+                               }
+                               ent->next = sb->ent;
+                               sb->ent = suspect->suspects;
+                               suspect->suspects = NULL;
+                               break;
+                       }
+               }
                origin_decref(suspect);
 
                if (DEBUG) /* sanity */
@@ -1609,9 +1871,8 @@ static void emit_porcelain(struct scoreboard *sb, struct blame_entry *ent,
        char hex[41];
 
        strcpy(hex, sha1_to_hex(suspect->commit->object.sha1));
-       printf("%s%c%d %d %d\n",
+       printf("%s %d %d %d\n",
               hex,
-              ent->guilty ? ' ' : '*', /* purely for debugging */
               ent->s_lno + 1,
               ent->lno + 1,
               ent->num_lines);
@@ -1724,17 +1985,16 @@ static void output(struct scoreboard *sb, int option)
 
        if (option & OUTPUT_PORCELAIN) {
                for (ent = sb->ent; ent; ent = ent->next) {
-                       struct blame_entry *oth;
-                       struct origin *suspect = ent->suspect;
-                       struct commit *commit = suspect->commit;
+                       int count = 0;
+                       struct origin *suspect;
+                       struct commit *commit = ent->suspect->commit;
                        if (commit->object.flags & MORE_THAN_ONE_PATH)
                                continue;
-                       for (oth = ent->next; oth; oth = oth->next) {
-                               if ((oth->suspect->commit != commit) ||
-                                   !strcmp(oth->suspect->path, suspect->path))
-                                       continue;
-                               commit->object.flags |= MORE_THAN_ONE_PATH;
-                               break;
+                       for (suspect = commit->util; suspect; suspect = suspect->next) {
+                               if (suspect->guilty && count++) {
+                                       commit->object.flags |= MORE_THAN_ONE_PATH;
+                                       break;
+                               }
                        }
                }
        }
@@ -1748,6 +2008,12 @@ static void output(struct scoreboard *sb, int option)
        }
 }
 
+static const char *get_next_line(const char *start, const char *end)
+{
+       const char *nl = memchr(start, '\n', end - start);
+       return nl ? nl + 1 : end;
+}
+
 /*
  * To allow quick access to the contents of nth line in the
  * final image, prepare an index in the scoreboard.
@@ -1759,39 +2025,19 @@ static int prepare_lines(struct scoreboard *sb)
        const char *end = buf + len;
        const char *p;
        int *lineno;
-       int num = 0, incomplete = 0;
+       int num = 0;
 
-       for (p = buf;;) {
-               p = memchr(p, '\n', end - p);
-               if (p) {
-                       p++;
-                       num++;
-                       continue;
-               }
-               break;
-       }
+       for (p = buf; p < end; p = get_next_line(p, end))
+               num++;
 
-       if (len && end[-1] != '\n')
-               incomplete++; /* incomplete line at the end */
+       sb->lineno = lineno = xmalloc(sizeof(*sb->lineno) * (num + 1));
 
-       sb->lineno = xmalloc(sizeof(*sb->lineno) * (num + incomplete + 1));
-       lineno = sb->lineno;
+       for (p = buf; p < end; p = get_next_line(p, end))
+               *lineno++ = p - buf;
 
-       *lineno++ = 0;
-       for (p = buf;;) {
-               p = memchr(p, '\n', end - p);
-               if (p) {
-                       p++;
-                       *lineno++ = p - buf;
-                       continue;
-               }
-               break;
-       }
+       *lineno = len;
 
-       if (incomplete)
-               *lineno++ = len;
-
-       sb->num_lines = num + incomplete;
+       sb->num_lines = num;
        return sb->num_lines;
 }
 
@@ -2005,6 +2251,18 @@ static void append_merge_parents(struct commit_list **tail)
        strbuf_release(&line);
 }
 
+/*
+ * This isn't as simple as passing sb->buf and sb->len, because we
+ * want to transfer ownership of the buffer to the commit (so we
+ * must use detach).
+ */
+static void set_commit_buffer_from_strbuf(struct commit *c, struct strbuf *sb)
+{
+       size_t len;
+       void *buf = strbuf_detach(sb, &len);
+       set_commit_buffer(c, buf, len);
+}
+
 /*
  * Prepare a dummy commit that represents the work tree (or staged) item.
  * Note that annotating work tree item never works in the reverse.
@@ -2026,7 +2284,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
        struct strbuf msg = STRBUF_INIT;
 
        time(&now);
-       commit = xcalloc(1, sizeof(*commit));
+       commit = alloc_commit_node();
        commit->object.parsed = 1;
        commit->date = now;
        commit->object.type = OBJ_COMMIT;
@@ -2053,7 +2311,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
                    ident, ident, path,
                    (!contents_from ? path :
                     (!strcmp(contents_from, "-") ? "standard input" : contents_from)));
-       commit->buffer = strbuf_detach(&msg, NULL);
+       set_commit_buffer_from_strbuf(commit, &msg);
 
        if (!contents_from || strcmp("-", contents_from)) {
                struct stat st;
@@ -2098,7 +2356,6 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
        origin->file.ptr = buf.buf;
        origin->file.size = buf.len;
        pretend_sha1_file(buf.buf, buf.len, OBJ_BLOB, origin->blob_sha1);
-       commit->util = origin;
 
        /*
         * Read the current index, replace the path entry with
@@ -2132,7 +2389,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
         * right now, but someday we might optimize diff-index --cached
         * with cache-tree information.
         */
-       cache_tree_invalidate_path(active_cache_tree, path);
+       cache_tree_invalidate_path(&the_index, path);
 
        return commit;
 }
@@ -2416,12 +2673,16 @@ parse_done:
        memset(&sb, 0, sizeof(sb));
 
        sb.revs = &revs;
-       if (!reverse)
+       if (!reverse) {
                final_commit_name = prepare_final(&sb);
+               sb.commits.compare = compare_commits_by_commit_date;
+       }
        else if (contents_from)
                die("--contents and --children do not blend well.");
-       else
+       else {
                final_commit_name = prepare_initial(&sb);
+               sb.commits.compare = compare_commits_by_reverse_commit_date;
+       }
 
        if (!sb.final) {
                /*
@@ -2510,12 +2771,16 @@ parse_done:
                ent->next = next;
                origin_incref(o);
        }
+
+       o->suspects = ent;
+       prio_queue_put(&sb.commits, o->commit);
+
        origin_decref(o);
 
        range_set_release(&ranges);
        string_list_clear(&range_list, 0);
 
-       sb.ent = ent;
+       sb.ent = NULL;
        sb.path = path;
 
        read_mailmap(&mailmap, NULL);
@@ -2528,6 +2793,8 @@ parse_done:
        if (incremental)
                return 0;
 
+       sb.ent = blame_sort(sb.ent, compare_blame_final);
+
        coalesce(&sb);
 
        if (!(output_option & OUTPUT_PORCELAIN))
index 652b1d2d1484032fab51165f1d0b0a41426d114f..0591b22a483619ac9a7d889a49e45ffa9d68ab72 100644 (file)
@@ -294,13 +294,13 @@ static char *resolve_symref(const char *src, const char *prefix)
 {
        unsigned char sha1[20];
        int flag;
-       const char *dst, *cp;
+       const char *dst;
 
        dst = resolve_ref_unsafe(src, sha1, 0, &flag);
        if (!(dst && (flag & REF_ISSYMREF)))
                return NULL;
-       if (prefix && (cp = skip_prefix(dst, prefix)))
-               dst = cp;
+       if (prefix)
+               skip_prefix(dst, prefix, &dst);
        return xstrdup(dst);
 }
 
index 61e75eb60c992e38ddf195abad564a76cbf934cb..05edd9e1df52e63a1644cddc0fb0e6a0d764d90b 100644 (file)
@@ -135,6 +135,7 @@ static int option_parse_u(const struct option *opt,
        int *newfd = opt->value;
 
        state.refresh_cache = 1;
+       state.istate = &the_index;
        if (*newfd < 0)
                *newfd = hold_locked_index(&lock_file, 1);
        return 0;
@@ -279,8 +280,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
                checkout_all(prefix, prefix_length);
 
        if (0 <= newfd &&
-           (write_cache(newfd, active_cache, active_nr) ||
-            commit_locked_index(&lock_file)))
+           write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
                die("Unable to write new index file");
        return 0;
 }
index 07cf55530918e8de6ae45e1c9b7e16707c32f844..f71e74531d2a7d195ff2987f6dca3c69c636aa7c 100644 (file)
@@ -225,7 +225,6 @@ static int checkout_paths(const struct checkout_opts *opts,
        int flag;
        struct commit *head;
        int errs = 0;
-       int newfd;
        struct lock_file *lock_file;
 
        if (opts->track != BRANCH_TRACK_UNSPECIFIED)
@@ -256,7 +255,7 @@ static int checkout_paths(const struct checkout_opts *opts,
 
        lock_file = xcalloc(1, sizeof(struct lock_file));
 
-       newfd = hold_locked_index(lock_file, 1);
+       hold_locked_index(lock_file, 1);
        if (read_cache_preload(&opts->pathspec) < 0)
                return error(_("corrupt index file"));
 
@@ -337,6 +336,7 @@ static int checkout_paths(const struct checkout_opts *opts,
        memset(&state, 0, sizeof(state));
        state.force = 1;
        state.refresh_cache = 1;
+       state.istate = &the_index;
        for (pos = 0; pos < active_nr; pos++) {
                struct cache_entry *ce = active_cache[pos];
                if (ce->ce_flags & CE_MATCHED) {
@@ -352,8 +352,7 @@ static int checkout_paths(const struct checkout_opts *opts,
                }
        }
 
-       if (write_cache(newfd, active_cache, active_nr) ||
-           commit_locked_index(lock_file))
+       if (write_locked_index(&the_index, lock_file, COMMIT_LOCK))
                die(_("unable to write new index file"));
 
        read_ref_full("HEAD", rev, 0, &flag);
@@ -444,8 +443,8 @@ static int merge_working_tree(const struct checkout_opts *opts,
 {
        int ret;
        struct lock_file *lock_file = xcalloc(1, sizeof(struct lock_file));
-       int newfd = hold_locked_index(lock_file, 1);
 
+       hold_locked_index(lock_file, 1);
        if (read_cache_preload(NULL) < 0)
                return error(_("corrupt index file"));
 
@@ -553,8 +552,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
                }
        }
 
-       if (write_cache(newfd, active_cache, active_nr) ||
-           commit_locked_index(lock_file))
+       if (write_locked_index(&the_index, lock_file, COMMIT_LOCK))
                die(_("unable to write new index file"));
 
        if (!opts->force && !opts->quiet)
@@ -624,7 +622,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
                /* Nothing to do. */
        } else if (opts->force_detach || !new->path) {  /* No longer on any branch. */
                update_ref(msg.buf, "HEAD", new->commit->object.sha1, NULL,
-                          REF_NODEREF, DIE_ON_ERR);
+                          REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
                if (!opts->quiet) {
                        if (old->path && advice_detached_head)
                                detach_advice(new->name);
@@ -651,12 +649,8 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
                        }
                }
                if (old->path && old->name) {
-                       char log_file[PATH_MAX], ref_file[PATH_MAX];
-
-                       git_snpath(log_file, sizeof(log_file), "logs/%s", old->path);
-                       git_snpath(ref_file, sizeof(ref_file), "%s", old->path);
-                       if (!file_exists(ref_file) && file_exists(log_file))
-                               remove_path(log_file);
+                       if (!ref_exists(old->path) && reflog_exists(old->path))
+                               delete_reflog(old->path);
                }
        }
        remove_branch_state();
@@ -780,8 +774,8 @@ static int switch_branches(const struct checkout_opts *opts,
        if (!(flag & REF_ISSYMREF))
                old.path = NULL;
 
-       if (old.path && starts_with(old.path, "refs/heads/"))
-               old.name = old.path + strlen("refs/heads/");
+       if (old.path)
+               skip_prefix(old.path, "refs/heads/", &old.name);
 
        if (!new->name) {
                new->name = "HEAD";
index 9b3c04d914b3d318f723c2d3ded403fca9503c07..f0dabecca88d8f16528fb68489e5b7a7700e2a47 100644 (file)
@@ -521,7 +521,7 @@ static void write_followtags(const struct ref *refs, const char *msg)
                if (!has_sha1_file(ref->old_sha1))
                        continue;
                update_ref(msg, ref->name, ref->old_sha1,
-                          NULL, 0, DIE_ON_ERR);
+                          NULL, 0, UPDATE_REFS_DIE_ON_ERR);
        }
 }
 
@@ -584,19 +584,20 @@ static void update_remote_refs(const struct ref *refs,
 static void update_head(const struct ref *our, const struct ref *remote,
                        const char *msg)
 {
-       if (our && starts_with(our->name, "refs/heads/")) {
+       const char *head;
+       if (our && skip_prefix(our->name, "refs/heads/", &head)) {
                /* Local default branch link */
                create_symref("HEAD", our->name, NULL);
                if (!option_bare) {
-                       const char *head = skip_prefix(our->name, "refs/heads/");
-                       update_ref(msg, "HEAD", our->old_sha1, NULL, 0, DIE_ON_ERR);
+                       update_ref(msg, "HEAD", our->old_sha1, NULL, 0,
+                                  UPDATE_REFS_DIE_ON_ERR);
                        install_branch_config(0, head, option_origin, our->name);
                }
        } else if (our) {
                struct commit *c = lookup_commit_reference(our->old_sha1);
                /* --branch specifies a non-branch (i.e. tags), detach HEAD */
                update_ref(msg, "HEAD", c->object.sha1,
-                          NULL, REF_NODEREF, DIE_ON_ERR);
+                          NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
        } else if (remote) {
                /*
                 * We know remote HEAD points to a non-branch, or
@@ -604,7 +605,7 @@ static void update_head(const struct ref *our, const struct ref *remote,
                 * Detach HEAD in all these cases.
                 */
                update_ref(msg, "HEAD", remote->old_sha1,
-                          NULL, REF_NODEREF, DIE_ON_ERR);
+                          NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
        }
 }
 
@@ -616,7 +617,7 @@ static int checkout(void)
        struct unpack_trees_options opts;
        struct tree *tree;
        struct tree_desc t;
-       int err = 0, fd;
+       int err = 0;
 
        if (option_no_checkout)
                return 0;
@@ -640,7 +641,7 @@ static int checkout(void)
        setup_work_tree();
 
        lock_file = xcalloc(1, sizeof(struct lock_file));
-       fd = hold_locked_index(lock_file, 1);
+       hold_locked_index(lock_file, 1);
 
        memset(&opts, 0, sizeof opts);
        opts.update = 1;
@@ -656,8 +657,7 @@ static int checkout(void)
        if (unpack_trees(1, &t, &opts) < 0)
                die(_("unable to checkout working tree"));
 
-       if (write_cache(fd, active_cache, active_nr) ||
-           commit_locked_index(lock_file))
+       if (write_locked_index(&the_index, lock_file, COMMIT_LOCK))
                die(_("unable to write new index file"));
 
        err |= run_hook_le(NULL, "post-checkout", sha1_to_hex(null_sha1),
@@ -695,16 +695,19 @@ static void write_refspec_config(const char* src_ref_prefix,
        if (option_mirror || !option_bare) {
                if (option_single_branch && !option_mirror) {
                        if (option_branch) {
-                               if (strstr(our_head_points_at->name, "refs/tags/"))
+                               if (starts_with(our_head_points_at->name, "refs/tags/"))
                                        strbuf_addf(&value, "+%s:%s", our_head_points_at->name,
                                                our_head_points_at->name);
                                else
                                        strbuf_addf(&value, "+%s:%s%s", our_head_points_at->name,
                                                branch_top->buf, option_branch);
                        } else if (remote_head_points_at) {
+                               const char *head = remote_head_points_at->name;
+                               if (!skip_prefix(head, "refs/heads/", &head))
+                                       die("BUG: remote HEAD points at non-head?");
+
                                strbuf_addf(&value, "+%s:%s%s", remote_head_points_at->name,
-                                               branch_top->buf,
-                                               skip_prefix(remote_head_points_at->name, "refs/heads/"));
+                                               branch_top->buf, head);
                        }
                        /*
                         * otherwise, the next "git fetch" will
index 987a4c3d731d7cf01f61e4fddec208b4cb51a4af..8a66c74e0fd405a06e6c767d385013ff7150db04 100644 (file)
@@ -123,8 +123,8 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
                        die_errno("git commit-tree: failed to read");
        }
 
-       if (commit_tree(&buffer, tree_sha1, parents, commit_sha1,
-                       NULL, sign_commit)) {
+       if (commit_tree(buffer.buf, buffer.len, tree_sha1, parents,
+                       commit_sha1, NULL, sign_commit)) {
                strbuf_release(&buffer);
                return 1;
        }
index 12afc42d197bfaffc950e7f44acb5d75517f1fc2..72eb3beb36cd06f6e41d80d5761a953a1c3a1d56 100644 (file)
@@ -305,7 +305,6 @@ static void refresh_cache_or_die(int refresh_flags)
 static char *prepare_index(int argc, const char **argv, const char *prefix,
                           const struct commit *current_head, int is_status)
 {
-       int fd;
        struct string_list partial;
        struct pathspec pathspec;
        int refresh_flags = REFRESH_QUIET;
@@ -321,12 +320,11 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
 
        if (interactive) {
                char *old_index_env = NULL;
-               fd = hold_locked_index(&index_lock, 1);
+               hold_locked_index(&index_lock, 1);
 
                refresh_cache_or_die(refresh_flags);
 
-               if (write_cache(fd, active_cache, active_nr) ||
-                   close_lock_file(&index_lock))
+               if (write_locked_index(&the_index, &index_lock, CLOSE_LOCK))
                        die(_("unable to create temporary index"));
 
                old_index_env = getenv(INDEX_ENVIRONMENT);
@@ -360,12 +358,11 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
         * (B) on failure, rollback the real index.
         */
        if (all || (also && pathspec.nr)) {
-               fd = hold_locked_index(&index_lock, 1);
+               hold_locked_index(&index_lock, 1);
                add_files_to_cache(also ? prefix : NULL, &pathspec, 0);
                refresh_cache_or_die(refresh_flags);
                update_main_cache_tree(WRITE_TREE_SILENT);
-               if (write_cache(fd, active_cache, active_nr) ||
-                   close_lock_file(&index_lock))
+               if (write_locked_index(&the_index, &index_lock, CLOSE_LOCK))
                        die(_("unable to write new_index file"));
                commit_style = COMMIT_NORMAL;
                return index_lock.filename;
@@ -381,12 +378,12 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
         * We still need to refresh the index here.
         */
        if (!only && !pathspec.nr) {
-               fd = hold_locked_index(&index_lock, 1);
+               hold_locked_index(&index_lock, 1);
                refresh_cache_or_die(refresh_flags);
                if (active_cache_changed) {
                        update_main_cache_tree(WRITE_TREE_SILENT);
-                       if (write_cache(fd, active_cache, active_nr) ||
-                           commit_locked_index(&index_lock))
+                       if (write_locked_index(&the_index, &index_lock,
+                                              COMMIT_LOCK))
                                die(_("unable to write new_index file"));
                } else {
                        rollback_lock_file(&index_lock);
@@ -432,24 +429,22 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
        if (read_cache() < 0)
                die(_("cannot read the index"));
 
-       fd = hold_locked_index(&index_lock, 1);
+       hold_locked_index(&index_lock, 1);
        add_remove_files(&partial);
        refresh_cache(REFRESH_QUIET);
-       if (write_cache(fd, active_cache, active_nr) ||
-           close_lock_file(&index_lock))
+       if (write_locked_index(&the_index, &index_lock, CLOSE_LOCK))
                die(_("unable to write new_index file"));
 
-       fd = hold_lock_file_for_update(&false_lock,
-                                      git_path("next-index-%"PRIuMAX,
-                                               (uintmax_t) getpid()),
-                                      LOCK_DIE_ON_ERROR);
+       hold_lock_file_for_update(&false_lock,
+                                 git_path("next-index-%"PRIuMAX,
+                                          (uintmax_t) getpid()),
+                                 LOCK_DIE_ON_ERROR);
 
        create_base_index(current_head);
        add_remove_files(&partial);
        refresh_cache(REFRESH_QUIET);
 
-       if (write_cache(fd, active_cache, active_nr) ||
-           close_lock_file(&false_lock))
+       if (write_locked_index(&the_index, &false_lock, CLOSE_LOCK))
                die(_("unable to write temporary index file"));
 
        discard_cache();
@@ -526,10 +521,29 @@ static int sane_ident_split(struct ident_split *person)
        return 1;
 }
 
+static int parse_force_date(const char *in, char *out, int len)
+{
+       if (len < 1)
+               return -1;
+       *out++ = '@';
+       len--;
+
+       if (parse_date(in, out, len) < 0) {
+               int errors = 0;
+               unsigned long t = approxidate_careful(in, &errors);
+               if (errors)
+                       return -1;
+               snprintf(out, len, "%lu", t);
+       }
+
+       return 0;
+}
+
 static void determine_author_info(struct strbuf *author_ident)
 {
        char *name, *email, *date;
        struct ident_split author;
+       char date_buf[64];
 
        name = getenv("GIT_AUTHOR_NAME");
        email = getenv("GIT_AUTHOR_EMAIL");
@@ -574,8 +588,12 @@ static void determine_author_info(struct strbuf *author_ident)
                email = xstrndup(lb + 2, rb - (lb + 2));
        }
 
-       if (force_date)
-               date = force_date;
+       if (force_date) {
+               if (parse_force_date(force_date, date_buf, sizeof(date_buf)))
+                       die(_("invalid date format: %s"), force_date);
+               date = date_buf;
+       }
+
        strbuf_addstr(author_ident, fmt_ident(name, email, date, IDENT_STRICT));
        if (!split_ident_line(&author, author_ident->buf, author_ident->len) &&
            sane_ident_split(&author)) {
@@ -585,13 +603,46 @@ static void determine_author_info(struct strbuf *author_ident)
        }
 }
 
-static char *cut_ident_timestamp_part(char *string)
+static void split_ident_or_die(struct ident_split *id, const struct strbuf *buf)
 {
-       char *ket = strrchr(string, '>');
-       if (!ket || ket[1] != ' ')
-               die(_("Malformed ident string: '%s'"), string);
-       *++ket = '\0';
-       return ket;
+       if (split_ident_line(id, buf->buf, buf->len) ||
+           !sane_ident_split(id))
+               die(_("Malformed ident string: '%s'"), buf->buf);
+}
+
+static int author_date_is_interesting(void)
+{
+       return author_message || force_date;
+}
+
+static void adjust_comment_line_char(const struct strbuf *sb)
+{
+       char candidates[] = "#;@!$%^&|:";
+       char *candidate;
+       const char *p;
+
+       comment_line_char = candidates[0];
+       if (!memchr(sb->buf, comment_line_char, sb->len))
+               return;
+
+       p = sb->buf;
+       candidate = strchr(candidates, *p);
+       if (candidate)
+               *candidate = ' ';
+       for (p = sb->buf; *p; p++) {
+               if ((p[0] == '\n' || p[0] == '\r') && p[1]) {
+                       candidate = strchr(candidates, p[1]);
+                       if (candidate)
+                               *candidate = ' ';
+               }
+       }
+
+       for (p = candidates; *p == ' '; p++)
+               ;
+       if (!*p)
+               die(_("unable to select a comment character that is not used\n"
+                     "in the current commit message"));
+       comment_line_char = *p;
 }
 
 static int prepare_to_commit(const char *index_file, const char *prefix,
@@ -747,6 +798,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
        if (fwrite(sb.buf, 1, sb.len, s->fp) < sb.len)
                die_errno(_("could not write commit template"));
 
+       if (auto_comment_line_char)
+               adjust_comment_line_char(&sb);
        strbuf_release(&sb);
 
        /* This checks if committer ident is explicitly given */
@@ -754,7 +807,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
        if (use_editor && include_status) {
                int ident_shown = 0;
                int saved_color_setting;
-               char *ai_tmp, *ci_tmp;
+               struct ident_split ci, ai;
+
                if (whence != FROM_COMMIT) {
                        if (cleanup_mode == CLEANUP_SCISSORS)
                                wt_status_add_cut_line(s->fp);
@@ -794,32 +848,39 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
                        status_printf_ln(s, GIT_COLOR_NORMAL,
                                        "%s", only_include_assumed);
 
-               ai_tmp = cut_ident_timestamp_part(author_ident->buf);
-               ci_tmp = cut_ident_timestamp_part(committer_ident.buf);
-               if (strcmp(author_ident->buf, committer_ident.buf))
+               split_ident_or_die(&ai, author_ident);
+               split_ident_or_die(&ci, &committer_ident);
+
+               if (ident_cmp(&ai, &ci))
                        status_printf_ln(s, GIT_COLOR_NORMAL,
                                _("%s"
-                               "Author:    %s"),
+                               "Author:    %.*s <%.*s>"),
                                ident_shown++ ? "" : "\n",
-                               author_ident->buf);
+                               (int)(ai.name_end - ai.name_begin), ai.name_begin,
+                               (int)(ai.mail_end - ai.mail_begin), ai.mail_begin);
+
+               if (author_date_is_interesting())
+                       status_printf_ln(s, GIT_COLOR_NORMAL,
+                               _("%s"
+                               "Date:      %s"),
+                               ident_shown++ ? "" : "\n",
+                               show_ident_date(&ai, DATE_NORMAL));
 
                if (!committer_ident_sufficiently_given())
                        status_printf_ln(s, GIT_COLOR_NORMAL,
                                _("%s"
-                               "Committer: %s"),
+                               "Committer: %.*s <%.*s>"),
                                ident_shown++ ? "" : "\n",
-                               committer_ident.buf);
+                               (int)(ci.name_end - ci.name_begin), ci.name_begin,
+                               (int)(ci.mail_end - ci.mail_begin), ci.mail_begin);
 
                if (ident_shown)
-                       status_printf_ln(s, GIT_COLOR_NORMAL, "");
+                       status_printf_ln(s, GIT_COLOR_NORMAL, "%s", "");
 
                saved_color_setting = s->use_color;
                s->use_color = 0;
                commitable = run_status(s->fp, index_file, prefix, 1, s);
                s->use_color = saved_color_setting;
-
-               *ai_tmp = ' ';
-               *ci_tmp = ' ';
        } else {
                unsigned char sha1[20];
                const char *parent = "HEAD";
@@ -954,7 +1015,7 @@ static int message_is_empty(struct strbuf *sb)
 static int template_untouched(struct strbuf *sb)
 {
        struct strbuf tmpl = STRBUF_INIT;
-       char *start;
+       const char *start;
 
        if (cleanup_mode == CLEANUP_NONE && sb->len)
                return 0;
@@ -963,8 +1024,7 @@ static int template_untouched(struct strbuf *sb)
                return 0;
 
        stripspace(&tmpl, cleanup_mode == CLEANUP_ALL);
-       start = (char *)skip_prefix(sb->buf, tmpl.buf);
-       if (!start)
+       if (!skip_prefix(sb->buf, tmpl.buf, &start))
                start = sb->buf;
        strbuf_release(&tmpl);
        return rest_is_empty(sb, start - sb->buf);
@@ -1369,6 +1429,13 @@ static void print_summary(const char *prefix, const unsigned char *sha1,
                strbuf_addstr(&format, "\n Author: ");
                strbuf_addbuf_percentquote(&format, &author_ident);
        }
+       if (author_date_is_interesting()) {
+               struct strbuf date = STRBUF_INIT;
+               format_commit_message(commit, "%ad", &date, &pctx);
+               strbuf_addstr(&format, "\n Date: ");
+               strbuf_addbuf_percentquote(&format, &date);
+               strbuf_release(&date);
+       }
        if (!committer_ident_sufficiently_given()) {
                strbuf_addstr(&format, "\n Committer: ");
                strbuf_addbuf_percentquote(&format, &committer_ident);
@@ -1672,8 +1739,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
                append_merge_tag_headers(parents, &tail);
        }
 
-       if (commit_tree_extended(&sb, active_cache_tree->sha1, parents, sha1,
-                                author_ident.buf, sign_commit, extra)) {
+       if (commit_tree_extended(sb.buf, sb.len, active_cache_tree->sha1,
+                        parents, sha1, author_ident.buf, sign_commit, extra)) {
                rollback_index_files();
                die(_("failed to write commit object"));
        }
@@ -1685,6 +1752,10 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
                                           ? NULL
                                           : current_head->object.sha1,
                                           0, NULL);
+       if (!ref_lock) {
+               rollback_index_files();
+               die(_("cannot lock HEAD ref"));
+       }
 
        nl = strchr(sb.buf, '\n');
        if (nl)
@@ -1694,10 +1765,6 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
        strbuf_insert(&sb, 0, reflog_msg, strlen(reflog_msg));
        strbuf_insert(&sb, strlen(reflog_msg), ": ", 2);
 
-       if (!ref_lock) {
-               rollback_index_files();
-               die(_("cannot lock HEAD ref"));
-       }
        if (write_ref_sha1(ref_lock, sha1, sb.buf) < 0) {
                rollback_index_files();
                die(_("cannot update HEAD ref"));
index 5677c942b6936f3332b1b4ed12541f45c4228dfb..fcd84747015a3d0a1da048612f5ac119a7e161d1 100644 (file)
@@ -395,19 +395,6 @@ static int urlmatch_collect_fn(const char *var, const char *value, void *cb)
        return 0;
 }
 
-static char *dup_downcase(const char *string)
-{
-       char *result;
-       size_t len, i;
-
-       len = strlen(string);
-       result = xmalloc(len + 1);
-       for (i = 0; i < len; i++)
-               result[i] = tolower(string[i]);
-       result[i] = '\0';
-       return result;
-}
-
 static int get_urlmatch(const char *var, const char *url)
 {
        char *section_tail;
@@ -422,7 +409,7 @@ static int get_urlmatch(const char *var, const char *url)
        if (!url_normalize(url, &config.url))
                die("%s", config.url.err);
 
-       config.section = dup_downcase(var);
+       config.section = xstrdup_tolower(var);
        section_tail = strchr(config.section, '.');
        if (section_tail) {
                *section_tail = '\0';
index be6417d166abf428d379a70b9d67f894da4641d1..ce0e019e0caa358e1f5e39e5ed51bec3945197e0 100644 (file)
@@ -22,14 +22,10 @@ static int stdin_diff_commit(struct commit *commit, char *line, int len)
        if (isspace(line[40]) && !get_sha1_hex(line+41, sha1)) {
                /* Graft the fake parents locally to the commit */
                int pos = 41;
-               struct commit_list **pptr, *parents;
+               struct commit_list **pptr;
 
                /* Free the real parent list */
-               for (parents = commit->parents; parents; ) {
-                       struct commit_list *tmp = parents->next;
-                       free(parents);
-                       parents = tmp;
-               }
+               free_commit_list(commit->parents);
                commit->parents = NULL;
                pptr = &(commit->parents);
                while (line[pos] && !get_sha1_hex(line + pos, sha1)) {
index b8d8a3aaf9ee8294be9a78956a70b476d327ee05..92b4624a4b93ff50c661e44242d508aed31877eb 100644 (file)
@@ -17,6 +17,7 @@
 #include "utf8.h"
 #include "parse-options.h"
 #include "quote.h"
+#include "remote.h"
 
 static const char *fast_export_usage[] = {
        N_("git fast-export [rev-list-opts]"),
@@ -31,6 +32,8 @@ static int use_done_feature;
 static int no_data;
 static int full_tree;
 static struct string_list extra_refs = STRING_LIST_INIT_NODUP;
+static struct refspec *refspecs;
+static int refspecs_nr;
 
 static int parse_opt_signed_tag_mode(const struct option *opt,
                                     const char *arg, int unset)
@@ -279,6 +282,7 @@ static const char *find_encoding(const char *begin, const char *end)
 static void handle_commit(struct commit *commit, struct rev_info *rev)
 {
        int saved_output_format = rev->diffopt.output_format;
+       const char *commit_buffer;
        const char *author, *author_end, *committer, *committer_end;
        const char *encoding, *message;
        char *reencoded = NULL;
@@ -288,7 +292,8 @@ static void handle_commit(struct commit *commit, struct rev_info *rev)
        rev->diffopt.output_format = DIFF_FORMAT_CALLBACK;
 
        parse_commit_or_die(commit);
-       author = strstr(commit->buffer, "\nauthor ");
+       commit_buffer = get_commit_buffer(commit, NULL);
+       author = strstr(commit_buffer, "\nauthor ");
        if (!author)
                die ("Could not find author in commit %s",
                     sha1_to_hex(commit->object.sha1));
@@ -335,6 +340,7 @@ static void handle_commit(struct commit *commit, struct rev_info *rev)
                          ? strlen(message) : 0),
               reencoded ? reencoded : message ? message : "");
        free(reencoded);
+       unuse_commit_buffer(commit, commit_buffer);
 
        for (i = 0, p = commit->parents; p; p = p->next) {
                int mark = get_object_mark(&p->item->object);
@@ -525,6 +531,15 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)
                if (dwim_ref(e->name, strlen(e->name), sha1, &full_name) != 1)
                        continue;
 
+               if (refspecs) {
+                       char *private;
+                       private = apply_refspecs(refspecs, refspecs_nr, full_name);
+                       if (private) {
+                               free(full_name);
+                               full_name = private;
+                       }
+               }
+
                commit = get_commit(e, full_name);
                if (!commit) {
                        warning("%s: Unexpected object of type %s, skipping.",
@@ -661,6 +676,19 @@ static void import_marks(char *input_file)
        fclose(f);
 }
 
+static void handle_deletes(void)
+{
+       int i;
+       for (i = 0; i < refspecs_nr; i++) {
+               struct refspec *refspec = &refspecs[i];
+               if (*refspec->src)
+                       continue;
+
+               printf("reset %s\nfrom %s\n\n",
+                               refspec->dst, sha1_to_hex(null_sha1));
+       }
+}
+
 int cmd_fast_export(int argc, const char **argv, const char *prefix)
 {
        struct rev_info revs;
@@ -668,6 +696,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
        struct commit *commit;
        char *export_filename = NULL, *import_filename = NULL;
        uint32_t lastimportid;
+       struct string_list refspecs_list = STRING_LIST_INIT_NODUP;
        struct option options[] = {
                OPT_INTEGER(0, "progress", &progress,
                            N_("show progress after <n> objects")),
@@ -688,6 +717,8 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
                OPT_BOOL(0, "use-done-feature", &use_done_feature,
                             N_("Use the done feature to terminate the stream")),
                OPT_BOOL(0, "no-data", &no_data, N_("Skip output of blob data")),
+               OPT_STRING_LIST(0, "refspec", &refspecs_list, N_("refspec"),
+                            N_("Apply refspec to exported refs")),
                OPT_END()
        };
 
@@ -701,11 +732,27 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
        revs.topo_order = 1;
        revs.show_source = 1;
        revs.rewrite_parents = 1;
+       argc = parse_options(argc, argv, prefix, options, fast_export_usage,
+                       PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN);
        argc = setup_revisions(argc, argv, &revs, NULL);
-       argc = parse_options(argc, argv, prefix, options, fast_export_usage, 0);
        if (argc > 1)
                usage_with_options (fast_export_usage, options);
 
+       if (refspecs_list.nr) {
+               const char **refspecs_str;
+               int i;
+
+               refspecs_str = xmalloc(sizeof(*refspecs_str) * refspecs_list.nr);
+               for (i = 0; i < refspecs_list.nr; i++)
+                       refspecs_str[i] = refspecs_list.items[i].string;
+
+               refspecs_nr = refspecs_list.nr;
+               refspecs = parse_fetch_refspec(refspecs_nr, refspecs_str);
+
+               string_list_clear(&refspecs_list, 1);
+               free(refspecs_str);
+       }
+
        if (use_done_feature)
                printf("feature done\n");
 
@@ -733,6 +780,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
        }
 
        handle_tags_and_duplicates();
+       handle_deletes();
 
        if (export_filename && lastimportid != last_idnum)
                export_marks(export_filename);
@@ -740,5 +788,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
        if (use_done_feature)
                printf("done\n");
 
+       free_refspec(refspecs_nr, refspecs);
+
        return 0;
 }
index 55f457c04f5c72ca31ab4fbc28e62ea48b6cb471..e8d0cca3e4110e1ae6db82f21c899c44460cb849 100644 (file)
@@ -45,6 +45,8 @@ static struct transport *gsecondary;
 static const char *submodule_prefix = "";
 static const char *recurse_submodules_default;
 static int shown_url = 0;
+static int refmap_alloc, refmap_nr;
+static const char **refmap_array;
 
 static int option_parse_recurse_submodules(const struct option *opt,
                                   const char *arg, int unset)
@@ -69,6 +71,19 @@ static int git_fetch_config(const char *k, const char *v, void *cb)
        return 0;
 }
 
+static int parse_refmap_arg(const struct option *opt, const char *arg, int unset)
+{
+       ALLOC_GROW(refmap_array, refmap_nr + 1, refmap_alloc);
+
+       /*
+        * "git fetch --refmap='' origin foo"
+        * can be used to tell the command not to store anywhere
+        */
+       if (*arg)
+               refmap_array[refmap_nr++] = arg;
+       return 0;
+}
+
 static struct option builtin_fetch_options[] = {
        OPT__VERBOSITY(&verbosity),
        OPT_BOOL(0, "all", &all,
@@ -107,6 +122,8 @@ static struct option builtin_fetch_options[] = {
                   N_("default mode for recursion"), PARSE_OPT_HIDDEN },
        OPT_BOOL(0, "update-shallow", &update_shallow,
                 N_("accept refs that update .git/shallow")),
+       { OPTION_CALLBACK, 0, "refmap", NULL, N_("refmap"),
+         N_("specify fetch refmap"), PARSE_OPT_NONEG, parse_refmap_arg },
        OPT_END()
 };
 
@@ -278,6 +295,9 @@ static struct ref *get_ref_map(struct transport *transport,
        const struct ref *remote_refs = transport_get_remote_refs(transport);
 
        if (refspec_count) {
+               struct refspec *fetch_refspec;
+               int fetch_refspec_nr;
+
                for (i = 0; i < refspec_count; i++) {
                        get_fetch_map(remote_refs, &refspecs[i], &tail, 0);
                        if (refspecs[i].dst && refspecs[i].dst[0])
@@ -307,12 +327,21 @@ static struct ref *get_ref_map(struct transport *transport,
                 * by ref_remove_duplicates() in favor of one of these
                 * opportunistic entries with FETCH_HEAD_IGNORE.
                 */
-               for (i = 0; i < transport->remote->fetch_refspec_nr; i++)
-                       get_fetch_map(ref_map, &transport->remote->fetch[i],
-                                     &oref_tail, 1);
+               if (refmap_array) {
+                       fetch_refspec = parse_fetch_refspec(refmap_nr, refmap_array);
+                       fetch_refspec_nr = refmap_nr;
+               } else {
+                       fetch_refspec = transport->remote->fetch;
+                       fetch_refspec_nr = transport->remote->fetch_refspec_nr;
+               }
+
+               for (i = 0; i < fetch_refspec_nr; i++)
+                       get_fetch_map(ref_map, &fetch_refspec[i], &oref_tail, 1);
 
                if (tags == TAGS_SET)
                        get_fetch_map(remote_refs, tag_refspec, &tail, 0);
+       } else if (refmap_array) {
+               die("--refmap option is only meaningful with command-line refspec(s).");
        } else {
                /* Use the defaults */
                struct remote *remote = transport->remote;
@@ -1053,16 +1082,11 @@ static int fetch_one(struct remote *remote, int argc, const char **argv)
                refs = xcalloc(argc + 1, sizeof(const char *));
                for (i = 0; i < argc; i++) {
                        if (!strcmp(argv[i], "tag")) {
-                               char *ref;
                                i++;
                                if (i >= argc)
                                        die(_("You need to specify a tag name."));
-                               ref = xmalloc(strlen(argv[i]) * 2 + 22);
-                               strcpy(ref, "refs/tags/");
-                               strcat(ref, argv[i]);
-                               strcat(ref, ":refs/tags/");
-                               strcat(ref, argv[i]);
-                               refs[j++] = ref;
+                               refs[j++] = xstrfmt("refs/tags/%s:refs/tags/%s",
+                                                   argv[i], argv[i]);
                        } else
                                refs[j++] = argv[i];
                }
index 3906eda87712ea099e0e5876fff1fe28fc5716be..79df05ef526bcd1a3be2971c9d467a930001639d 100644 (file)
@@ -100,7 +100,8 @@ static int handle_line(char *line, struct merge_parents *merge_parents)
 {
        int i, len = strlen(line);
        struct origin_data *origin_data;
-       char *src, *origin;
+       char *src;
+       const char *origin;
        struct src_data *src_data;
        struct string_list_item *item;
        int pulling_head = 0;
@@ -164,8 +165,7 @@ static int handle_line(char *line, struct merge_parents *merge_parents)
                origin = line;
                string_list_append(&src_data->tag, origin + 4);
                src_data->head_status |= 2;
-       } else if (starts_with(line, "remote-tracking branch ")) {
-               origin = line + strlen("remote-tracking branch ");
+       } else if (skip_prefix(line, "remote-tracking branch ", &origin)) {
                string_list_append(&src_data->r_branch, origin);
                src_data->head_status |= 2;
        } else {
@@ -178,11 +178,8 @@ static int handle_line(char *line, struct merge_parents *merge_parents)
                int len = strlen(origin);
                if (origin[0] == '\'' && origin[len - 1] == '\'')
                        origin = xmemdupz(origin + 1, len - 2);
-       } else {
-               char *new_origin = xmalloc(strlen(origin) + strlen(src) + 5);
-               sprintf(new_origin, "%s of %s", origin, src);
-               origin = new_origin;
-       }
+       } else
+               origin = xstrfmt("%s of %s", origin, src);
        if (strcmp(".", src))
                origin_data->is_local_branch = 0;
        string_list_append(&origins, origin)->util = origin_data;
@@ -230,12 +227,14 @@ static void add_branch_desc(struct strbuf *out, const char *name)
 static void record_person(int which, struct string_list *people,
                          struct commit *commit)
 {
+       const char *buffer;
        char *name_buf, *name, *name_end;
        struct string_list_item *elem;
        const char *field;
 
        field = (which == 'a') ? "\nauthor " : "\ncommitter ";
-       name = strstr(commit->buffer, field);
+       buffer = get_commit_buffer(commit, NULL);
+       name = strstr(buffer, field);
        if (!name)
                return;
        name += strlen(field);
@@ -247,6 +246,7 @@ static void record_person(int which, struct string_list *people,
        if (name_end < name)
                return;
        name_buf = xmemdupz(name, name_end - name + 1);
+       unuse_commit_buffer(commit, buffer);
 
        elem = string_list_lookup(people, name_buf);
        if (!elem) {
@@ -297,8 +297,8 @@ static void credit_people(struct strbuf *out,
        if (!them->nr ||
            (them->nr == 1 &&
             me &&
-            (me = skip_prefix(me, them->items->string)) != NULL &&
-            skip_prefix(me, " <")))
+            skip_prefix(me, them->items->string, &me) &&
+            starts_with(me, " <")))
                return;
        strbuf_addf(out, "\n%c %s ", comment_line_char, label);
        add_people_count(out, them);
index 3e1d5c3334e50035fdbf835cfdafbb39c0bacfd0..4135980f20786ef3320e334c4001fd67fc169056 100644 (file)
@@ -193,7 +193,7 @@ static int verify_format(const char *format)
                at = parse_atom(sp + 2, ep);
                cp = ep + 1;
 
-               if (!memcmp(used_atom[at], "color:", 6))
+               if (starts_with(used_atom[at], "color:"))
                        need_color_reset_at_eol = !!strcmp(used_atom[at], color_reset);
        }
        return 0;
index fc150c882122c53965fd246ad862e3a75d8768e2..8aadca160e857be8a87ec1f152e51eb6f51c90b5 100644 (file)
@@ -310,8 +310,7 @@ static int fsck_obj(struct object *obj)
        if (obj->type == OBJ_COMMIT) {
                struct commit *commit = (struct commit *) obj;
 
-               free(commit->buffer);
-               commit->buffer = NULL;
+               free_commit_buffer(commit);
 
                if (!commit->parents && show_root)
                        printf("root %s\n", sha1_to_hex(commit->object.sha1));
index b8d440d0e099543d1b05de0dbb13cb4f8d32da29..c86a142f308d614daefd459fd9f9ddebe03f4cb8 100644 (file)
@@ -361,9 +361,7 @@ static void run_pager(struct grep_opt *opt, const char *prefix)
                argv[i] = path_list->items[i].string;
        argv[path_list->nr] = NULL;
 
-       if (prefix && chdir(prefix))
-               die(_("Failed to chdir: %s"), prefix);
-       status = run_command_v_opt(argv, RUN_USING_SHELL);
+       status = run_command_v_opt_cd_env(argv, RUN_USING_SHELL, prefix, NULL);
        if (status)
                exit(status);
        free(argv);
index 18f57de58b02de33909a40ea9720e6602cc9dcb5..fc40411892f13da7e739bc4801bbace3021c0e2b 100644 (file)
@@ -786,7 +786,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
                        }
                        if (obj->type == OBJ_COMMIT) {
                                struct commit *commit = (struct commit *) obj;
-                               commit->buffer = NULL;
+                               if (detach_commit_buffer(commit, NULL) != data)
+                                       die("BUG: parse_object_buffer transmogrified our buffer");
                        }
                        obj->flags |= FLAG_CHECKED;
                }
@@ -1505,7 +1506,8 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
        const char *curr_index;
        const char *index_name = NULL, *pack_name = NULL;
        const char *keep_name = NULL, *keep_msg = NULL;
-       char *index_name_buf = NULL, *keep_name_buf = NULL;
+       struct strbuf index_name_buf = STRBUF_INIT,
+                     keep_name_buf = STRBUF_INIT;
        struct pack_idx_entry **idx_objects;
        struct pack_idx_option opts;
        unsigned char pack_sha1[20];
@@ -1602,24 +1604,22 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
        if (fix_thin_pack && !from_stdin)
                die(_("--fix-thin cannot be used without --stdin"));
        if (!index_name && pack_name) {
-               int len = strlen(pack_name);
-               if (!has_extension(pack_name, ".pack"))
+               size_t len;
+               if (!strip_suffix(pack_name, ".pack", &len))
                        die(_("packfile name '%s' does not end with '.pack'"),
                            pack_name);
-               index_name_buf = xmalloc(len);
-               memcpy(index_name_buf, pack_name, len - 5);
-               strcpy(index_name_buf + len - 5, ".idx");
-               index_name = index_name_buf;
+               strbuf_add(&index_name_buf, pack_name, len);
+               strbuf_addstr(&index_name_buf, ".idx");
+               index_name = index_name_buf.buf;
        }
        if (keep_msg && !keep_name && pack_name) {
-               int len = strlen(pack_name);
-               if (!has_extension(pack_name, ".pack"))
+               size_t len;
+               if (!strip_suffix(pack_name, ".pack", &len))
                        die(_("packfile name '%s' does not end with '.pack'"),
                            pack_name);
-               keep_name_buf = xmalloc(len);
-               memcpy(keep_name_buf, pack_name, len - 5);
-               strcpy(keep_name_buf + len - 5, ".keep");
-               keep_name = keep_name_buf;
+               strbuf_add(&keep_name_buf, pack_name, len);
+               strbuf_addstr(&keep_name_buf, ".idx");
+               keep_name = keep_name_buf.buf;
        }
        if (verify) {
                if (!index_name)
@@ -1667,8 +1667,8 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
        else
                close(input_fd);
        free(objects);
-       free(index_name_buf);
-       free(keep_name_buf);
+       strbuf_release(&index_name_buf);
+       strbuf_release(&keep_name_buf);
        if (pack_name == NULL)
                free((void *) curr_pack);
        if (index_name == NULL)
index 3b6a6bbaddc8795c148763bb6d71136900a8fbb4..27c1b65db46bb1bead9045b7b6be08a1ee199835 100644 (file)
@@ -63,6 +63,8 @@ static int parse_decoration_style(const char *var, const char *value)
                return DECORATE_FULL_REFS;
        else if (!strcmp(value, "short"))
                return DECORATE_SHORT_REFS;
+       else if (!strcmp(value, "auto"))
+               return (isatty(1) || pager_in_use()) ? DECORATE_SHORT_REFS : 0;
        return -1;
 }
 
@@ -345,8 +347,7 @@ static int cmd_log_walk(struct rev_info *rev)
                        rev->max_count++;
                if (!rev->reflog_info) {
                        /* we allow cycles in reflog ancestry */
-                       free(commit->buffer);
-                       commit->buffer = NULL;
+                       free_commit_buffer(commit);
                }
                free_commit_list(commit->parents);
                commit->parents = NULL;
@@ -669,6 +670,7 @@ static void add_header(const char *value)
 static int thread;
 static int do_signoff;
 static const char *signature = git_version_string;
+static const char *signature_file;
 static int config_cover_letter;
 
 enum {
@@ -738,6 +740,8 @@ static int git_format_config(const char *var, const char *value, void *cb)
        }
        if (!strcmp(var, "format.signature"))
                return git_config_string(&signature, var, value);
+       if (!strcmp(var, "format.signaturefile"))
+               return git_config_pathname(&signature_file, var, value);
        if (!strcmp(var, "format.coverletter")) {
                if (value && !strcasecmp(value, "auto")) {
                        config_cover_letter = COVER_AUTO;
@@ -840,8 +844,13 @@ static void gen_message_id(struct rev_info *info, char *base)
 
 static void print_signature(void)
 {
-       if (signature && *signature)
-               printf("-- \n%s\n\n", signature);
+       if (!signature || !*signature)
+               return;
+
+       printf("-- \n%s", signature);
+       if (signature[strlen(signature)-1] != '\n')
+               putchar('\n');
+       putchar('\n');
 }
 
 static void add_branch_description(struct strbuf *buf, const char *branch_name)
@@ -862,7 +871,7 @@ static char *find_branch_name(struct rev_info *rev)
        int i, positive = -1;
        unsigned char branch_sha1[20];
        const unsigned char *tip_sha1;
-       const char *ref;
+       const char *ref, *v;
        char *full_ref, *branch = NULL;
 
        for (i = 0; i < rev->cmdline.nr; i++) {
@@ -878,9 +887,9 @@ static char *find_branch_name(struct rev_info *rev)
        ref = rev->cmdline.rev[positive].name;
        tip_sha1 = rev->cmdline.rev[positive].item->sha1;
        if (dwim_ref(ref, strlen(ref), branch_sha1, &full_ref) &&
-           starts_with(full_ref, "refs/heads/") &&
+           skip_prefix(full_ref, "refs/heads/", &v) &&
            !hashcmp(tip_sha1, branch_sha1))
-               branch = xstrdup(full_ref + strlen("refs/heads/"));
+               branch = xstrdup(v);
        free(full_ref);
        return branch;
 }
@@ -915,9 +924,12 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
        log_write_email_headers(rev, head, &pp.subject, &pp.after_subject,
                                &need_8bit_cte);
 
-       for (i = 0; !need_8bit_cte && i < nr; i++)
-               if (has_non_ascii(list[i]->buffer))
+       for (i = 0; !need_8bit_cte && i < nr; i++) {
+               const char *buf = get_commit_buffer(list[i], NULL);
+               if (has_non_ascii(buf))
                        need_8bit_cte = 1;
+               unuse_commit_buffer(list[i], buf);
+       }
 
        if (!branch_name)
                branch_name = find_branch_name(rev);
@@ -1226,6 +1238,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                            PARSE_OPT_OPTARG, thread_callback },
                OPT_STRING(0, "signature", &signature, N_("signature"),
                            N_("add a signature")),
+               OPT_FILENAME(0, "signature-file", &signature_file,
+                               N_("add a signature from a file")),
                OPT__QUIET(&quiet, N_("don't print the patch filenames")),
                OPT_END()
        };
@@ -1382,10 +1396,10 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 
                if (check_head) {
                        unsigned char sha1[20];
-                       const char *ref;
+                       const char *ref, *v;
                        ref = resolve_ref_unsafe("HEAD", sha1, 1, NULL);
-                       if (ref && starts_with(ref, "refs/heads/"))
-                               branch_name = xstrdup(ref + strlen("refs/heads/"));
+                       if (ref && skip_prefix(ref, "refs/heads/", &v))
+                               branch_name = xstrdup(v);
                        else
                                branch_name = xstrdup(""); /* no branch */
                }
@@ -1443,6 +1457,18 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                        cover_letter = (config_cover_letter == COVER_ON);
        }
 
+       if (!signature) {
+               ; /* --no-signature inhibits all signatures */
+       } else if (signature && signature != git_version_string) {
+               ; /* non-default signature already set */
+       } else if (signature_file) {
+               struct strbuf buf = STRBUF_INIT;
+
+               if (strbuf_read_file(&buf, signature_file, 128) < 0)
+                       die_errno(_("unable to read signature file '%s'"), signature_file);
+               signature = strbuf_detach(&buf, NULL);
+       }
+
        if (in_reply_to || thread || cover_letter)
                rev.ref_message_ids = xcalloc(1, sizeof(struct string_list));
        if (in_reply_to) {
@@ -1504,8 +1530,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                    reopen_stdout(rev.numbered_files ? NULL : commit, NULL, &rev, quiet))
                        die(_("Failed to create output files"));
                shown = log_tree_commit(&rev, commit);
-               free(commit->buffer);
-               commit->buffer = NULL;
+               free_commit_buffer(commit);
 
                /* We put one extra blank line between formatted
                 * patches and this flag is used by log-tree code
index 3e9eefb0915a4496ead9ddbf3836a4455351dba0..b2a4b92992748ab52fc6fd3f31041dd88dca54f8 100644 (file)
@@ -92,7 +92,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 
        if (argv[i]) {
                int j;
-               pattern = xcalloc(sizeof(const char *), argc - i + 1);
+               pattern = xcalloc(argc - i + 1, sizeof(const char *));
                for (j = i; j < argc; j++) {
                        int len = strlen(argv[j]);
                        char *p = xmalloc(len + 3);
index 66d8843301b22a6a89d9d765e9d3020942e6f672..22491a1c2b906f4e4ae607cda8925b1254b202b3 100644 (file)
@@ -63,7 +63,7 @@ static int verbosity;
 static int allow_rerere_auto;
 static int abort_current_merge;
 static int show_progress = -1;
-static int default_to_upstream;
+static int default_to_upstream = 1;
 static const char *sign_commit;
 
 static struct strategy all_strategy[] = {
@@ -398,7 +398,7 @@ static void finish(struct commit *head_commit,
                        const char *argv_gc_auto[] = { "gc", "--auto", NULL };
                        update_ref(reflog_message.buf, "HEAD",
                                new_head, head, 0,
-                               DIE_ON_ERR);
+                               UPDATE_REFS_DIE_ON_ERR);
                        /*
                         * We ignore errors in 'gc --auto', since the
                         * user should see them.
@@ -657,14 +657,12 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
                              struct commit_list *remoteheads,
                              struct commit *head, const char *head_arg)
 {
-       int index_fd;
        struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
 
-       index_fd = hold_locked_index(lock, 1);
+       hold_locked_index(lock, 1);
        refresh_cache(REFRESH_QUIET);
        if (active_cache_changed &&
-                       (write_cache(index_fd, active_cache, active_nr) ||
-                        commit_locked_index(lock)))
+           write_locked_index(&the_index, lock, COMMIT_LOCK))
                return error(_("Unable to write index."));
        rollback_lock_file(lock);
 
@@ -672,7 +670,6 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
                int clean, x;
                struct commit *result;
                struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
-               int index_fd;
                struct commit_list *reversed = NULL;
                struct merge_options o;
                struct commit_list *j;
@@ -700,12 +697,11 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
                for (j = common; j; j = j->next)
                        commit_list_insert(j->item, &reversed);
 
-               index_fd = hold_locked_index(lock, 1);
+               hold_locked_index(lock, 1);
                clean = merge_recursive(&o, head,
                                remoteheads->item, reversed, &result);
                if (active_cache_changed &&
-                               (write_cache(index_fd, active_cache, active_nr) ||
-                                commit_locked_index(lock)))
+                   write_locked_index(&the_index, lock, COMMIT_LOCK))
                        die (_("unable to write %s"), get_index_file());
                rollback_lock_file(lock);
                return clean ? 0 : 1;
@@ -852,8 +848,8 @@ static int merge_trivial(struct commit *head, struct commit_list *remoteheads)
        parent->next->item = remoteheads->item;
        parent->next->next = NULL;
        prepare_to_commit(remoteheads);
-       if (commit_tree(&merge_msg, result_tree, parent, result_commit, NULL,
-                       sign_commit))
+       if (commit_tree(merge_msg.buf, merge_msg.len, result_tree, parent,
+                       result_commit, NULL, sign_commit))
                die(_("failed to write commit object"));
        finish(head, remoteheads, result_commit, "In-index merge");
        drop_save();
@@ -877,8 +873,8 @@ static int finish_automerge(struct commit *head,
                commit_list_insert(head, &parents);
        strbuf_addch(&merge_msg, '\n');
        prepare_to_commit(remoteheads);
-       if (commit_tree(&merge_msg, result_tree, parents, result_commit,
-                       NULL, sign_commit))
+       if (commit_tree(merge_msg.buf, merge_msg.len, result_tree, parents,
+                       result_commit, NULL, sign_commit))
                die(_("failed to write commit object"));
        strbuf_addf(&buf, "Merge made by the '%s' strategy.", wt_strategy);
        finish(head, remoteheads, result_commit, buf.buf);
@@ -1222,7 +1218,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
                        die(_("%s - not something we can merge"), argv[0]);
                read_empty(remote_head->object.sha1, 0);
                update_ref("initial pull", "HEAD", remote_head->object.sha1,
-                          NULL, 0, DIE_ON_ERR);
+                          NULL, 0, UPDATE_REFS_DIE_ON_ERR);
                goto done;
        } else {
                struct strbuf merge_names = STRBUF_INIT;
@@ -1282,10 +1278,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
                                printf(_("Commit %s has a good GPG signature by %s\n"),
                                       hex, signature_check.signer);
 
-                       free(signature_check.gpg_output);
-                       free(signature_check.gpg_status);
-                       free(signature_check.signer);
-                       free(signature_check.key);
+                       signature_check_clear(&signature_check);
                }
        }
 
@@ -1339,7 +1332,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
        }
 
        update_ref("updating ORIG_HEAD", "ORIG_HEAD", head_commit->object.sha1,
-                  NULL, 0, DIE_ON_ERR);
+                  NULL, 0, UPDATE_REFS_DIE_ON_ERR);
 
        if (remoteheads && !common)
                ; /* No common ancestors found. We need a real merge. */
index 180ef99127d47d0e8fe9f12a590fd9ba9e524f08..6ffe540c202f69a41fcf40d443f73073d3ba08bd 100644 (file)
@@ -63,7 +63,7 @@ static struct lock_file lock_file;
 
 int cmd_mv(int argc, const char **argv, const char *prefix)
 {
-       int i, newfd, gitmodules_modified = 0;
+       int i, gitmodules_modified = 0;
        int verbose = 0, show_only = 0, force = 0, ignore_errors = 0;
        struct option builtin_mv_options[] = {
                OPT__VERBOSE(&verbose, N_("be verbose")),
@@ -85,7 +85,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
        if (--argc < 1)
                usage_with_options(builtin_mv_usage, builtin_mv_options);
 
-       newfd = hold_locked_index(&lock_file, 1);
+       hold_locked_index(&lock_file, 1);
        if (read_cache() < 0)
                die(_("index file corrupt"));
 
@@ -276,8 +276,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
                stage_updated_gitmodules();
 
        if (active_cache_changed) {
-               if (write_cache(newfd, active_cache, active_nr) ||
-                   commit_locked_index(&lock_file))
+               if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
                        die(_("Unable to write new index file"));
        }
 
index c824d4ec5f1c076e4833c690dad378125dde6da9..3c8f319be675d14a6ee60d303335190b7bdce9c8 100644 (file)
@@ -33,10 +33,7 @@ static void name_rev(struct commit *commit,
                return;
 
        if (deref) {
-               char *new_name = xmalloc(strlen(tip_name)+3);
-               strcpy(new_name, tip_name);
-               strcat(new_name, "^0");
-               tip_name = new_name;
+               tip_name = xstrfmt("%s^0", tip_name);
 
                if (generation)
                        die("generation: %d, but deref?", generation);
index 39c8573cde00bc15e673ae549fcd0f22ea67d29f..820c34135cab439e2168dd08947bd79d7ed7ae71 100644 (file)
@@ -717,7 +717,7 @@ static int merge_commit(struct notes_merge_options *o)
        strbuf_insert(&msg, 0, "notes: ", 7);
        update_ref(msg.buf, o->local_ref, sha1,
                   is_null_sha1(parent_sha1) ? NULL : parent_sha1,
-                  0, DIE_ON_ERR);
+                  0, UPDATE_REFS_DIE_ON_ERR);
 
        free_notes(t);
        strbuf_release(&msg);
@@ -812,11 +812,11 @@ static int merge(int argc, const char **argv, const char *prefix)
        if (result >= 0) /* Merge resulted (trivially) in result_sha1 */
                /* Update default notes ref with new commit */
                update_ref(msg.buf, default_notes_ref(), result_sha1, NULL,
-                          0, DIE_ON_ERR);
+                          0, UPDATE_REFS_DIE_ON_ERR);
        else { /* Merge has unresolved conflicts */
                /* Update .git/NOTES_MERGE_PARTIAL with partial merge result */
                update_ref(msg.buf, "NOTES_MERGE_PARTIAL", result_sha1, NULL,
-                          0, DIE_ON_ERR);
+                          0, UPDATE_REFS_DIE_ON_ERR);
                /* Store ref-to-be-updated into .git/NOTES_MERGE_REF */
                if (create_symref("NOTES_MERGE_REF", default_notes_ref(), NULL))
                        die("Failed to store link to current notes ref (%s)",
index de36c60ca11d248013c2de42d196f1aff8a2937b..238b5021eb105007a42061d5f8febc455530da45 100644 (file)
@@ -2214,10 +2214,6 @@ static int git_pack_config(const char *k, const char *v, void *cb)
                cache_max_small_delta_size = git_config_int(k, v);
                return 0;
        }
-       if (!strcmp(k, "pack.writebitmaps")) {
-               write_bitmap_index = git_config_bool(k, v);
-               return 0;
-       }
        if (!strcmp(k, "pack.writebitmaphashcache")) {
                if (git_config_bool(k, v))
                        write_bitmap_options |= BITMAP_OPT_HASH_CACHE;
index 3cfe02d5a5716de1a3aaa5edc1ca0e3d74c03b03..77db8739b5165f15a437651b0803711f6e019839 100644 (file)
@@ -1,17 +1,14 @@
 #include "builtin.h"
 
-static void flush_current_id(int patchlen, unsigned char *id, git_SHA_CTX *c)
+static void flush_current_id(int patchlen, unsigned char *id, unsigned char *result)
 {
-       unsigned char result[20];
        char name[50];
 
        if (!patchlen)
                return;
 
-       git_SHA1_Final(result, c);
        memcpy(name, sha1_to_hex(id), 41);
        printf("%s %s\n", sha1_to_hex(result), name);
-       git_SHA1_Init(c);
 }
 
 static int remove_space(char *line)
@@ -56,10 +53,31 @@ static int scan_hunk_header(const char *p, int *p_before, int *p_after)
        return 1;
 }
 
-static int get_one_patchid(unsigned char *next_sha1, git_SHA_CTX *ctx, struct strbuf *line_buf)
+static void flush_one_hunk(unsigned char *result, git_SHA_CTX *ctx)
+{
+       unsigned char hash[20];
+       unsigned short carry = 0;
+       int i;
+
+       git_SHA1_Final(hash, ctx);
+       git_SHA1_Init(ctx);
+       /* 20-byte sum, with carry */
+       for (i = 0; i < 20; ++i) {
+               carry += result[i] + hash[i];
+               result[i] = carry;
+               carry >>= 8;
+       }
+}
+
+static int get_one_patchid(unsigned char *next_sha1, unsigned char *result,
+                          struct strbuf *line_buf, int stable)
 {
        int patchlen = 0, found_next = 0;
        int before = -1, after = -1;
+       git_SHA_CTX ctx;
+
+       git_SHA1_Init(&ctx);
+       hashclr(result);
 
        while (strbuf_getwholeline(line_buf, stdin, '\n') != EOF) {
                char *line = line_buf->buf;
@@ -107,6 +125,8 @@ static int get_one_patchid(unsigned char *next_sha1, git_SHA_CTX *ctx, struct st
                                break;
 
                        /* Else we're parsing another header.  */
+                       if (stable)
+                               flush_one_hunk(result, &ctx);
                        before = after = -1;
                }
 
@@ -119,39 +139,63 @@ static int get_one_patchid(unsigned char *next_sha1, git_SHA_CTX *ctx, struct st
                /* Compute the sha without whitespace */
                len = remove_space(line);
                patchlen += len;
-               git_SHA1_Update(ctx, line, len);
+               git_SHA1_Update(&ctx, line, len);
        }
 
        if (!found_next)
                hashclr(next_sha1);
 
+       flush_one_hunk(result, &ctx);
+
        return patchlen;
 }
 
-static void generate_id_list(void)
+static void generate_id_list(int stable)
 {
-       unsigned char sha1[20], n[20];
-       git_SHA_CTX ctx;
+       unsigned char sha1[20], n[20], result[20];
        int patchlen;
        struct strbuf line_buf = STRBUF_INIT;
 
-       git_SHA1_Init(&ctx);
        hashclr(sha1);
        while (!feof(stdin)) {
-               patchlen = get_one_patchid(n, &ctx, &line_buf);
-               flush_current_id(patchlen, sha1, &ctx);
+               patchlen = get_one_patchid(n, result, &line_buf, stable);
+               flush_current_id(patchlen, sha1, result);
                hashcpy(sha1, n);
        }
        strbuf_release(&line_buf);
 }
 
-static const char patch_id_usage[] = "git patch-id < patch";
+static const char patch_id_usage[] = "git patch-id [--stable | --unstable] < patch";
+
+static int git_patch_id_config(const char *var, const char *value, void *cb)
+{
+       int *stable = cb;
+
+       if (!strcmp(var, "patchid.stable")) {
+               *stable = git_config_bool(var, value);
+               return 0;
+       }
+
+       return git_default_config(var, value, cb);
+}
 
 int cmd_patch_id(int argc, const char **argv, const char *prefix)
 {
-       if (argc != 1)
+       int stable = -1;
+
+       git_config(git_patch_id_config, &stable);
+
+       /* If nothing is set, default to unstable. */
+       if (stable < 0)
+               stable = 0;
+
+       if (argc == 2 && !strcmp(argv[1], "--stable"))
+               stable = 1;
+       else if (argc == 2 && !strcmp(argv[1], "--unstable"))
+               stable = 0;
+       else if (argc != 1)
                usage(patch_id_usage);
 
-       generate_id_list();
+       generate_id_list(stable);
        return 0;
 }
index f8dfea41e1ad8b6d888c1a2adc13eee87083491e..f50e3d5e77db6842ff3450560aad330f6a4bd91d 100644 (file)
@@ -127,11 +127,10 @@ static NORETURN int die_push_simple(struct branch *branch, struct remote *remote
         * them the big ugly fully qualified ref.
         */
        const char *advice_maybe = "";
-       const char *short_upstream =
-               skip_prefix(branch->merge[0]->src, "refs/heads/");
+       const char *short_upstream = branch->merge[0]->src;
+
+       skip_prefix(short_upstream, "refs/heads/", &short_upstream);
 
-       if (!short_upstream)
-               short_upstream = branch->merge[0]->src;
        /*
         * Don't show advice for people who explicitly set
         * push.default.
index 0d7ef847a70581214fb88c3a981581670f7decbe..e7e1c33a7fb1f1eb7828f4d632fb492f128f66fe 100644 (file)
@@ -99,7 +99,7 @@ static struct lock_file lock_file;
 
 int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
 {
-       int i, newfd, stage = 0;
+       int i, stage = 0;
        unsigned char sha1[20];
        struct tree_desc t[MAX_UNPACK_TREES];
        struct unpack_trees_options opts;
@@ -149,12 +149,21 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
        argc = parse_options(argc, argv, unused_prefix, read_tree_options,
                             read_tree_usage, 0);
 
-       newfd = hold_locked_index(&lock_file, 1);
+       hold_locked_index(&lock_file, 1);
 
        prefix_set = opts.prefix ? 1 : 0;
        if (1 < opts.merge + opts.reset + prefix_set)
                die("Which one? -m, --reset, or --prefix?");
 
+       /*
+        * NEEDSWORK
+        *
+        * The old index should be read anyway even if we're going to
+        * destroy all index entries because we still need to preserve
+        * certain information such as index version or split-index
+        * mode.
+        */
+
        if (opts.reset || opts.merge || opts.prefix) {
                if (read_cache_unmerged() && (opts.prefix || opts.merge))
                        die("You need to resolve your current index first");
@@ -231,10 +240,9 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
         * what came from the tree.
         */
        if (nr_trees == 1 && !opts.prefix)
-               prime_cache_tree(&active_cache_tree, trees[0]);
+               prime_cache_tree(&the_index, trees[0]);
 
-       if (write_cache(newfd, active_cache, active_nr) ||
-           commit_locked_index(&lock_file))
+       if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
                die("unable to write new index file");
        return 0;
 }
index c3230817db4a7676eb74335b254f30597e66edd9..18458e81c6351d53afe1a50efff183889e5ab81b 100644 (file)
@@ -614,12 +614,9 @@ static void run_update_post_hook(struct command *commands)
        argv[0] = hook;
 
        for (argc = 1, cmd = commands; cmd; cmd = cmd->next) {
-               char *p;
                if (cmd->error_string || cmd->did_not_exist)
                        continue;
-               p = xmalloc(strlen(cmd->ref_name) + 1);
-               strcpy(p, cmd->ref_name);
-               argv[argc] = p;
+               argv[argc] = xstrdup(cmd->ref_name);
                argc++;
        }
        argv[argc] = NULL;
index c12a9784e6b45d50129b786a45bb5f4e4dd0801a..e8a8fb13b9ffc8d3276048131e33e9874bc3bdea 100644 (file)
@@ -369,7 +369,7 @@ static int expire_reflog(const char *ref, const unsigned char *sha1, int unused,
        if (!lock)
                return error("cannot lock ref '%s'", ref);
        log_file = git_pathdup("logs/%s", ref);
-       if (!file_exists(log_file))
+       if (!reflog_exists(ref))
                goto finish;
        if (!cmd->dry_run) {
                newlog_path = git_pathdup("logs/%s.lock", ref);
index 9b3e368983570be72a5c4b8476f69dc39522d192..8e1dc39162681503505c9c3897e046514ce2e6a8 100644 (file)
@@ -250,9 +250,7 @@ static struct string_list branch_list;
 
 static const char *abbrev_ref(const char *name, const char *prefix)
 {
-       const char *abbrev = skip_prefix(name, prefix);
-       if (abbrev)
-               return abbrev;
+       skip_prefix(name, prefix, &name);
        return name;
 }
 #define abbrev_branch(name) abbrev_ref((name), "refs/heads/")
@@ -265,16 +263,17 @@ static int config_read_branches(const char *key, const char *value, void *cb)
                struct string_list_item *item;
                struct branch_info *info;
                enum { REMOTE, MERGE, REBASE } type;
+               size_t key_len;
 
                key += 7;
-               if (ends_with(key, ".remote")) {
-                       name = xstrndup(key, strlen(key) - 7);
+               if (strip_suffix(key, ".remote", &key_len)) {
+                       name = xmemdupz(key, key_len);
                        type = REMOTE;
-               } else if (ends_with(key, ".merge")) {
-                       name = xstrndup(key, strlen(key) - 6);
+               } else if (strip_suffix(key, ".merge", &key_len)) {
+                       name = xmemdupz(key, key_len);
                        type = MERGE;
-               } else if (ends_with(key, ".rebase")) {
-                       name = xstrndup(key, strlen(key) - 7);
+               } else if (strip_suffix(key, ".rebase", &key_len)) {
+                       name = xmemdupz(key, key_len);
                        type = REBASE;
                } else
                        return 0;
@@ -282,7 +281,7 @@ static int config_read_branches(const char *key, const char *value, void *cb)
                item = string_list_insert(&branch_list, name);
 
                if (!item->util)
-                       item->util = xcalloc(sizeof(struct branch_info), 1);
+                       item->util = xcalloc(1, sizeof(struct branch_info));
                info = item->util;
                if (type == REMOTE) {
                        if (info->remote_name)
@@ -398,7 +397,7 @@ static int get_push_ref_states(const struct ref *remote_refs,
 
                item = string_list_append(&states->push,
                                          abbrev_branch(ref->peer_ref->name));
-               item->util = xcalloc(sizeof(struct push_info), 1);
+               item->util = xcalloc(1, sizeof(struct push_info));
                info = item->util;
                info->forced = ref->force;
                info->dest = xstrdup(abbrev_branch(ref->name));
@@ -433,7 +432,7 @@ static int get_push_ref_states_noquery(struct ref_states *states)
        states->push.strdup_strings = 1;
        if (!remote->push_refspec_nr) {
                item = string_list_append(&states->push, _("(matching)"));
-               info = item->util = xcalloc(sizeof(struct push_info), 1);
+               info = item->util = xcalloc(1, sizeof(struct push_info));
                info->status = PUSH_STATUS_NOTQUERIED;
                info->dest = xstrdup(item->string);
        }
@@ -446,7 +445,7 @@ static int get_push_ref_states_noquery(struct ref_states *states)
                else
                        item = string_list_append(&states->push, _("(delete)"));
 
-               info = item->util = xcalloc(sizeof(struct push_info), 1);
+               info = item->util = xcalloc(1, sizeof(struct push_info));
                info->forced = spec->force;
                info->status = PUSH_STATUS_NOTQUERIED;
                info->dest = xstrdup(spec->dst ? spec->dst : item->string);
index 6b0b62dcb2687e78ec433e7de1103f0c0f74a1fc..a77e743b94036b2d856e6b3f74999170e39b5f17 100644 (file)
@@ -10,6 +10,7 @@
 
 static int delta_base_offset = 1;
 static int pack_kept_objects = -1;
+static int write_bitmaps;
 static char *packdir, *packtmp;
 
 static const char *const git_repack_usage[] = {
@@ -27,6 +28,11 @@ static int repack_config(const char *var, const char *value, void *cb)
                pack_kept_objects = git_config_bool(var, value);
                return 0;
        }
+       if (!strcmp(var, "repack.writebitmaps") ||
+           !strcmp(var, "pack.writebitmaps")) {
+               write_bitmaps = git_config_bool(var, value);
+               return 0;
+       }
        return git_default_config(var, value, cb);
 }
 
@@ -77,16 +83,15 @@ static void get_non_kept_pack_filenames(struct string_list *fname_list)
        DIR *dir;
        struct dirent *e;
        char *fname;
-       size_t len;
 
        if (!(dir = opendir(packdir)))
                return;
 
        while ((e = readdir(dir)) != NULL) {
-               if (!ends_with(e->d_name, ".pack"))
+               size_t len;
+               if (!strip_suffix(e->d_name, ".pack", &len))
                        continue;
 
-               len = strlen(e->d_name) - strlen(".pack");
                fname = xmemdupz(e->d_name, len);
 
                if (!file_exists(mkpath("%s/%s.keep", packdir, fname)))
@@ -149,7 +154,6 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
        int no_update_server_info = 0;
        int quiet = 0;
        int local = 0;
-       int write_bitmap = -1;
 
        struct option builtin_repack_options[] = {
                OPT_BIT('a', NULL, &pack_everything,
@@ -168,7 +172,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
                OPT__QUIET(&quiet, N_("be quiet")),
                OPT_BOOL('l', "local", &local,
                                N_("pass --local to git-pack-objects")),
-               OPT_BOOL('b', "write-bitmap-index", &write_bitmap,
+               OPT_BOOL('b', "write-bitmap-index", &write_bitmaps,
                                N_("write bitmap index")),
                OPT_STRING(0, "unpack-unreachable", &unpack_unreachable, N_("approxidate"),
                                N_("with -A, do not loosen objects older than this")),
@@ -191,7 +195,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
                                git_repack_usage, 0);
 
        if (pack_kept_objects < 0)
-               pack_kept_objects = write_bitmap;
+               pack_kept_objects = write_bitmaps;
 
        packdir = mkpathdup("%s/pack", get_object_directory());
        packtmp = mkpathdup("%s/.tmp-%d-pack", packdir, (int)getpid());
@@ -217,9 +221,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
                argv_array_pushf(&cmd_args, "--no-reuse-delta");
        if (no_reuse_object)
                argv_array_pushf(&cmd_args, "--no-reuse-object");
-       if (write_bitmap >= 0)
-               argv_array_pushf(&cmd_args, "--%swrite-bitmap-index",
-                                write_bitmap ? "" : "no-");
+       if (write_bitmaps)
+               argv_array_push(&cmd_args, "--write-bitmap-index");
 
        if (pack_everything & ALL_INTO_ONE) {
                get_non_kept_pack_filenames(&existing_packs);
index b62420a01af820225f23d08b4d0e885505640c77..d1ea2c2e5606f2091efb487dc1599ec0a9116a6e 100644 (file)
 #include "builtin.h"
 #include "refs.h"
 #include "parse-options.h"
+#include "run-command.h"
 
 static const char * const git_replace_usage[] = {
        N_("git replace [-f] <object> <replacement>"),
+       N_("git replace [-f] --edit <object>"),
        N_("git replace -d <object>..."),
        N_("git replace [--format=<format>] [-l [<pattern>]]"),
        NULL
 };
 
 enum replace_format {
-      REPLACE_FORMAT_SHORT,
-      REPLACE_FORMAT_MEDIUM,
-      REPLACE_FORMAT_LONG
+       REPLACE_FORMAT_SHORT,
+       REPLACE_FORMAT_MEDIUM,
+       REPLACE_FORMAT_LONG
 };
 
 struct show_data {
@@ -123,26 +125,36 @@ static int delete_replace_ref(const char *name, const char *ref,
        return 0;
 }
 
-static int replace_object(const char *object_ref, const char *replace_ref,
-                         int force)
+static void check_ref_valid(unsigned char object[20],
+                           unsigned char prev[20],
+                           char *ref,
+                           int ref_size,
+                           int force)
 {
-       unsigned char object[20], prev[20], repl[20];
-       enum object_type obj_type, repl_type;
-       char ref[PATH_MAX];
-       struct ref_lock *lock;
-
-       if (get_sha1(object_ref, object))
-               die("Failed to resolve '%s' as a valid ref.", object_ref);
-       if (get_sha1(replace_ref, repl))
-               die("Failed to resolve '%s' as a valid ref.", replace_ref);
-
-       if (snprintf(ref, sizeof(ref),
+       if (snprintf(ref, ref_size,
                     "refs/replace/%s",
-                    sha1_to_hex(object)) > sizeof(ref) - 1)
+                    sha1_to_hex(object)) > ref_size - 1)
                die("replace ref name too long: %.*s...", 50, ref);
        if (check_refname_format(ref, 0))
                die("'%s' is not a valid ref name.", ref);
 
+       if (read_ref(ref, prev))
+               hashclr(prev);
+       else if (!force)
+               die("replace ref '%s' already exists", ref);
+}
+
+static int replace_object_sha1(const char *object_ref,
+                              unsigned char object[20],
+                              const char *replace_ref,
+                              unsigned char repl[20],
+                              int force)
+{
+       unsigned char prev[20];
+       enum object_type obj_type, repl_type;
+       char ref[PATH_MAX];
+       struct ref_lock *lock;
+
        obj_type = sha1_object_info(object, NULL);
        repl_type = sha1_object_info(repl, NULL);
        if (!force && obj_type != repl_type)
@@ -152,10 +164,7 @@ static int replace_object(const char *object_ref, const char *replace_ref,
                    object_ref, typename(obj_type),
                    replace_ref, typename(repl_type));
 
-       if (read_ref(ref, prev))
-               hashclr(prev);
-       else if (!force)
-               die("replace ref '%s' already exists", ref);
+       check_ref_valid(object, prev, ref, sizeof(ref), force);
 
        lock = lock_any_ref_for_update(ref, prev, 0, NULL);
        if (!lock)
@@ -166,14 +175,148 @@ static int replace_object(const char *object_ref, const char *replace_ref,
        return 0;
 }
 
+static int replace_object(const char *object_ref, const char *replace_ref, int force)
+{
+       unsigned char object[20], repl[20];
+
+       if (get_sha1(object_ref, object))
+               die("Failed to resolve '%s' as a valid ref.", object_ref);
+       if (get_sha1(replace_ref, repl))
+               die("Failed to resolve '%s' as a valid ref.", replace_ref);
+
+       return replace_object_sha1(object_ref, object, replace_ref, repl, force);
+}
+
+/*
+ * Write the contents of the object named by "sha1" to the file "filename".
+ * If "raw" is true, then the object's raw contents are printed according to
+ * "type". Otherwise, we pretty-print the contents for human editing.
+ */
+static void export_object(const unsigned char *sha1, enum object_type type,
+                         int raw, const char *filename)
+{
+       struct child_process cmd = { NULL };
+       int fd;
+
+       fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
+       if (fd < 0)
+               die_errno("unable to open %s for writing", filename);
+
+       argv_array_push(&cmd.args, "--no-replace-objects");
+       argv_array_push(&cmd.args, "cat-file");
+       if (raw)
+               argv_array_push(&cmd.args, typename(type));
+       else
+               argv_array_push(&cmd.args, "-p");
+       argv_array_push(&cmd.args, sha1_to_hex(sha1));
+       cmd.git_cmd = 1;
+       cmd.out = fd;
+
+       if (run_command(&cmd))
+               die("cat-file reported failure");
+}
+
+/*
+ * Read a previously-exported (and possibly edited) object back from "filename",
+ * interpreting it as "type", and writing the result to the object database.
+ * The sha1 of the written object is returned via sha1.
+ */
+static void import_object(unsigned char *sha1, enum object_type type,
+                         int raw, const char *filename)
+{
+       int fd;
+
+       fd = open(filename, O_RDONLY);
+       if (fd < 0)
+               die_errno("unable to open %s for reading", filename);
+
+       if (!raw && type == OBJ_TREE) {
+               const char *argv[] = { "mktree", NULL };
+               struct child_process cmd = { argv };
+               struct strbuf result = STRBUF_INIT;
+
+               cmd.argv = argv;
+               cmd.git_cmd = 1;
+               cmd.in = fd;
+               cmd.out = -1;
+
+               if (start_command(&cmd))
+                       die("unable to spawn mktree");
+
+               if (strbuf_read(&result, cmd.out, 41) < 0)
+                       die_errno("unable to read from mktree");
+               close(cmd.out);
+
+               if (finish_command(&cmd))
+                       die("mktree reported failure");
+               if (get_sha1_hex(result.buf, sha1) < 0)
+                       die("mktree did not return an object name");
+
+               strbuf_release(&result);
+       } else {
+               struct stat st;
+               int flags = HASH_FORMAT_CHECK | HASH_WRITE_OBJECT;
+
+               if (fstat(fd, &st) < 0)
+                       die_errno("unable to fstat %s", filename);
+               if (index_fd(sha1, fd, &st, type, NULL, flags) < 0)
+                       die("unable to write object to database");
+               /* index_fd close()s fd for us */
+       }
+
+       /*
+        * No need to close(fd) here; both run-command and index-fd
+        * will have done it for us.
+        */
+}
+
+static int edit_and_replace(const char *object_ref, int force, int raw)
+{
+       char *tmpfile = git_pathdup("REPLACE_EDITOBJ");
+       enum object_type type;
+       unsigned char old[20], new[20], prev[20];
+       char ref[PATH_MAX];
+
+       if (get_sha1(object_ref, old) < 0)
+               die("Not a valid object name: '%s'", object_ref);
+
+       type = sha1_object_info(old, NULL);
+       if (type < 0)
+               die("unable to get object type for %s", sha1_to_hex(old));
+
+       check_ref_valid(old, prev, ref, sizeof(ref), force);
+
+       export_object(old, type, raw, tmpfile);
+       if (launch_editor(tmpfile, NULL, NULL) < 0)
+               die("editing object file failed");
+       import_object(new, type, raw, tmpfile);
+
+       free(tmpfile);
+
+       if (!hashcmp(old, new))
+               return error("new object is the same as the old one: '%s'", sha1_to_hex(old));
+
+       return replace_object_sha1(object_ref, old, "replacement", new, force);
+}
+
 int cmd_replace(int argc, const char **argv, const char *prefix)
 {
-       int list = 0, delete = 0, force = 0;
+       int force = 0;
+       int raw = 0;
        const char *format = NULL;
+       enum {
+               MODE_UNSPECIFIED = 0,
+               MODE_LIST,
+               MODE_DELETE,
+               MODE_EDIT,
+               MODE_REPLACE
+       } cmdmode = MODE_UNSPECIFIED;
        struct option options[] = {
-               OPT_BOOL('l', "list", &list, N_("list replace refs")),
-               OPT_BOOL('d', "delete", &delete, N_("delete replace refs")),
+               OPT_CMDMODE('l', "list", &cmdmode, N_("list replace refs"), MODE_LIST),
+               OPT_CMDMODE('d', "delete", &cmdmode, N_("delete replace refs"), MODE_DELETE),
+               OPT_CMDMODE('e', "edit", &cmdmode, N_("edit existing object"), MODE_EDIT),
                OPT_BOOL('f', "force", &force, N_("replace the ref if it exists")),
+               OPT_BOOL(0, "raw", &raw, N_("do not pretty-print contents for --edit")),
                OPT_STRING(0, "format", &format, N_("format"), N_("use this format")),
                OPT_END()
        };
@@ -182,44 +325,47 @@ int cmd_replace(int argc, const char **argv, const char *prefix)
 
        argc = parse_options(argc, argv, prefix, options, git_replace_usage, 0);
 
-       if (list && delete)
-               usage_msg_opt("-l and -d cannot be used together",
+       if (!cmdmode)
+               cmdmode = argc ? MODE_REPLACE : MODE_LIST;
+
+       if (format && cmdmode != MODE_LIST)
+               usage_msg_opt("--format cannot be used when not listing",
                              git_replace_usage, options);
 
-       if (format && delete)
-               usage_msg_opt("--format and -d cannot be used together",
+       if (force && cmdmode != MODE_REPLACE && cmdmode != MODE_EDIT)
+               usage_msg_opt("-f only makes sense when writing a replacement",
                              git_replace_usage, options);
 
-       if (force && (list || delete))
-               usage_msg_opt("-f cannot be used with -d or -l",
+       if (raw && cmdmode != MODE_EDIT)
+               usage_msg_opt("--raw only makes sense with --edit",
                              git_replace_usage, options);
 
-       /* Delete refs */
-       if (delete) {
+       switch (cmdmode) {
+       case MODE_DELETE:
                if (argc < 1)
                        usage_msg_opt("-d needs at least one argument",
                                      git_replace_usage, options);
                return for_each_replace_name(argv, delete_replace_ref);
-       }
 
-       /* Replace object */
-       if (!list && argc) {
+       case MODE_REPLACE:
                if (argc != 2)
                        usage_msg_opt("bad number of arguments",
                                      git_replace_usage, options);
-               if (format)
-                       usage_msg_opt("--format cannot be used when not listing",
-                                     git_replace_usage, options);
                return replace_object(argv[0], argv[1], force);
-       }
 
-       /* List refs, even if "list" is not set */
-       if (argc > 1)
-               usage_msg_opt("only one pattern can be given with -l",
-                             git_replace_usage, options);
-       if (force)
-               usage_msg_opt("-f needs some arguments",
-                             git_replace_usage, options);
+       case MODE_EDIT:
+               if (argc != 1)
+                       usage_msg_opt("-e needs exactly one argument",
+                                     git_replace_usage, options);
+               return edit_and_replace(argv[0], force, raw);
+
+       case MODE_LIST:
+               if (argc > 1)
+                       usage_msg_opt("only one pattern can be given with -l",
+                                     git_replace_usage, options);
+               return list_replace_refs(argv[0], format);
 
-       return list_replace_refs(argv[0], format);
+       default:
+               die("BUG: invalid cmdmode %d", (int)cmdmode);
+       }
 }
index f4e087596b6337d2306af4cf45119752b4a049ea..855d478e3b9d2a815ecdcfbf39c261f98ad0994b 100644 (file)
@@ -84,7 +84,7 @@ static int reset_index(const unsigned char *sha1, int reset_type, int quiet)
 
        if (reset_type == MIXED || reset_type == HARD) {
                tree = parse_tree_indirect(sha1);
-               prime_cache_tree(&active_cache_tree, tree);
+               prime_cache_tree(&the_index, tree);
        }
 
        return 0;
@@ -93,7 +93,7 @@ static int reset_index(const unsigned char *sha1, int reset_type, int quiet)
 static void print_new_head_line(struct commit *commit)
 {
        const char *hex, *body;
-       char *msg;
+       const char *msg;
 
        hex = find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV);
        printf(_("HEAD is now at %s"), hex);
@@ -109,7 +109,7 @@ static void print_new_head_line(struct commit *commit)
        }
        else
                printf("\n");
-       logmsg_free(msg, commit);
+       unuse_commit_buffer(commit, msg);
 }
 
 static void update_index_from_diff(struct diff_queue_struct *q,
@@ -252,11 +252,13 @@ static int reset_refs(const char *rev, const unsigned char *sha1)
        if (!get_sha1("HEAD", sha1_orig)) {
                orig = sha1_orig;
                set_reflog_message(&msg, "updating ORIG_HEAD", NULL);
-               update_ref(msg.buf, "ORIG_HEAD", orig, old_orig, 0, MSG_ON_ERR);
+               update_ref(msg.buf, "ORIG_HEAD", orig, old_orig, 0,
+                          UPDATE_REFS_MSG_ON_ERR);
        } else if (old_orig)
                delete_ref("ORIG_HEAD", old_orig, 0);
        set_reflog_message(&msg, "updating HEAD", rev);
-       update_ref_status = update_ref(msg.buf, "HEAD", sha1, orig, 0, MSG_ON_ERR);
+       update_ref_status = update_ref(msg.buf, "HEAD", sha1, orig, 0,
+                                      UPDATE_REFS_MSG_ON_ERR);
        strbuf_release(&msg);
        return update_ref_status;
 }
@@ -351,7 +353,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
 
        if (reset_type != SOFT) {
                struct lock_file *lock = xcalloc(1, sizeof(*lock));
-               int newfd = hold_locked_index(lock, 1);
+               hold_locked_index(lock, 1);
                if (reset_type == MIXED) {
                        int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN;
                        if (read_from_tree(&pathspec, sha1, intent_to_add))
@@ -367,8 +369,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
                                die(_("Could not reset index file to revision '%s'."), rev);
                }
 
-               if (write_cache(newfd, active_cache, active_nr) ||
-                   commit_locked_index(lock))
+               if (write_locked_index(&the_index, lock, COMMIT_LOCK))
                        die(_("Could not write new index file."));
        }
 
index 9f92905379d1801a35bfad87bc05002d76dc23f4..ff84a825ff776abc01087f37782223ee26a1af7a 100644 (file)
@@ -106,7 +106,7 @@ static void show_commit(struct commit *commit, void *data)
        else
                putchar('\n');
 
-       if (revs->verbose_header && commit->buffer) {
+       if (revs->verbose_header && get_cached_commit_buffer(commit, NULL)) {
                struct strbuf buf = STRBUF_INIT;
                struct pretty_print_context ctx = {0};
                ctx.abbrev = revs->abbrev;
@@ -173,8 +173,7 @@ static void finish_commit(struct commit *commit, void *data)
                free_commit_list(commit->parents);
                commit->parents = NULL;
        }
-       free(commit->buffer);
-       commit->buffer = NULL;
+       free_commit_buffer(commit);
 }
 
 static void finish_object(struct object *obj,
index 1a6122d3ae29609c30c26959fbb1ff799e13a4b2..8102aaa9248d55055761f9899903cac2a2c7cc1e 100644 (file)
@@ -11,6 +11,7 @@
 #include "parse-options.h"
 #include "diff.h"
 #include "revision.h"
+#include "split-index.h"
 
 #define DO_REVS                1
 #define DO_NOREV       2
@@ -775,6 +776,15 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
                                                : "false");
                                continue;
                        }
+                       if (!strcmp(arg, "--shared-index-path")) {
+                               if (read_cache() < 0)
+                                       die(_("Could not read the index"));
+                               if (the_index.split_index) {
+                                       const unsigned char *sha1 = the_index.split_index->base_sha1;
+                                       puts(git_path("sharedindex.%s", sha1_to_hex(sha1)));
+                               }
+                               continue;
+                       }
                        if (starts_with(arg, "--since=")) {
                                show_datestring("--max-age=", arg+8);
                                continue;
index 960634dd0c52f1da689e8a54980e5e81cf2d2f36..bc6490b8bca554c568973997568543e206ffdb3e 100644 (file)
@@ -278,7 +278,7 @@ static struct option builtin_rm_options[] = {
 
 int cmd_rm(int argc, const char **argv, const char *prefix)
 {
-       int i, newfd;
+       int i;
        struct pathspec pathspec;
        char *seen;
 
@@ -293,7 +293,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
        if (!index_only)
                setup_work_tree();
 
-       newfd = hold_locked_index(&lock_file, 1);
+       hold_locked_index(&lock_file, 1);
 
        if (read_cache() < 0)
                die(_("index file corrupt"));
@@ -427,8 +427,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
        }
 
        if (active_cache_changed) {
-               if (write_cache(newfd, active_cache, active_nr) ||
-                   commit_locked_index(&lock_file))
+               if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
                        die(_("Unable to write new index file"));
        }
 
index d87317290c0bbfffb7ac66fb7cff5c608f092d93..5fd4e4e48839a9dc2998d3fba0e48008b902b12a 100644 (file)
@@ -755,7 +755,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
                }
 
                for (i = 0; i < reflog; i++) {
-                       char *logmsg, *m;
+                       char *logmsg;
                        const char *msg;
                        unsigned long timestamp;
                        int tz;
@@ -770,11 +770,9 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
                                msg = "(none)";
                        else
                                msg++;
-                       m = xmalloc(strlen(msg) + 200);
-                       sprintf(m, "(%s) %s",
-                               show_date(timestamp, tz, 1),
-                               msg);
-                       reflog_msg[i] = m;
+                       reflog_msg[i] = xstrfmt("(%s) %s",
+                                               show_date(timestamp, tz, 1),
+                                               msg);
                        free(logmsg);
                        sprintf(nth_desc, "%s@{%d}", *av, base+i);
                        append_ref(nth_desc, sha1, 1);
index 6c7c6bde9de9cbc0ace94aa75df30b7b88b43aca..ef765563388c384a127d27eaf7ee6fd1badfe84f 100644 (file)
@@ -80,11 +80,19 @@ static int in_commit_list(const struct commit_list *want, struct commit *c)
        return 0;
 }
 
-static int contains_recurse(struct commit *candidate,
+enum contains_result {
+       CONTAINS_UNKNOWN = -1,
+       CONTAINS_NO = 0,
+       CONTAINS_YES = 1
+};
+
+/*
+ * Test whether the candidate or one of its parents is contained in the list.
+ * Do not recurse to find out, though, but return -1 if inconclusive.
+ */
+static enum contains_result contains_test(struct commit *candidate,
                            const struct commit_list *want)
 {
-       struct commit_list *p;
-
        /* was it previously marked as containing a want commit? */
        if (candidate->object.flags & TMP_MARK)
                return 1;
@@ -92,26 +100,78 @@ static int contains_recurse(struct commit *candidate,
        if (candidate->object.flags & UNINTERESTING)
                return 0;
        /* or are we it? */
-       if (in_commit_list(want, candidate))
+       if (in_commit_list(want, candidate)) {
+               candidate->object.flags |= TMP_MARK;
                return 1;
+       }
 
        if (parse_commit(candidate) < 0)
                return 0;
 
-       /* Otherwise recurse and mark ourselves for future traversals. */
-       for (p = candidate->parents; p; p = p->next) {
-               if (contains_recurse(p->item, want)) {
-                       candidate->object.flags |= TMP_MARK;
-                       return 1;
-               }
-       }
-       candidate->object.flags |= UNINTERESTING;
-       return 0;
+       return -1;
 }
 
-static int contains(struct commit *candidate, const struct commit_list *want)
+/*
+ * Mimicking the real stack, this stack lives on the heap, avoiding stack
+ * overflows.
+ *
+ * At each recursion step, the stack items points to the commits whose
+ * ancestors are to be inspected.
+ */
+struct stack {
+       int nr, alloc;
+       struct stack_entry {
+               struct commit *commit;
+               struct commit_list *parents;
+       } *stack;
+};
+
+static void push_to_stack(struct commit *candidate, struct stack *stack)
+{
+       int index = stack->nr++;
+       ALLOC_GROW(stack->stack, stack->nr, stack->alloc);
+       stack->stack[index].commit = candidate;
+       stack->stack[index].parents = candidate->parents;
+}
+
+static enum contains_result contains(struct commit *candidate,
+               const struct commit_list *want)
 {
-       return contains_recurse(candidate, want);
+       struct stack stack = { 0, 0, NULL };
+       int result = contains_test(candidate, want);
+
+       if (result != CONTAINS_UNKNOWN)
+               return result;
+
+       push_to_stack(candidate, &stack);
+       while (stack.nr) {
+               struct stack_entry *entry = &stack.stack[stack.nr - 1];
+               struct commit *commit = entry->commit;
+               struct commit_list *parents = entry->parents;
+
+               if (!parents) {
+                       commit->object.flags |= UNINTERESTING;
+                       stack.nr--;
+               }
+               /*
+                * If we just popped the stack, parents->item has been marked,
+                * therefore contains_test will return a meaningful 0 or 1.
+                */
+               else switch (contains_test(parents->item, want)) {
+               case CONTAINS_YES:
+                       commit->object.flags |= TMP_MARK;
+                       stack.nr--;
+                       break;
+               case CONTAINS_NO:
+                       entry->parents = parents->next;
+                       break;
+               case CONTAINS_UNKNOWN:
+                       push_to_stack(parents->item, &stack);
+                       break;
+               }
+       }
+       free(stack.stack);
+       return contains_test(candidate, want);
 }
 
 static void show_tag_lines(const unsigned char *sha1, int lines)
@@ -278,11 +338,11 @@ static int do_sign(struct strbuf *buffer)
 }
 
 static const char tag_template[] =
-       N_("\nWrite a tag message\n"
+       N_("\nWrite a message for tag:\n  %s\n"
        "Lines starting with '%c' will be ignored.\n");
 
 static const char tag_template_nocleanup[] =
-       N_("\nWrite a tag message\n"
+       N_("\nWrite a message for tag:\n  %s\n"
        "Lines starting with '%c' will be kept; you may remove them"
        " yourself if you want to.\n");
 
@@ -378,9 +438,9 @@ static void create_tag(const unsigned char *object, const char *tag,
                        struct strbuf buf = STRBUF_INIT;
                        strbuf_addch(&buf, '\n');
                        if (opt->cleanup_mode == CLEANUP_ALL)
-                               strbuf_commented_addf(&buf, _(tag_template), comment_line_char);
+                               strbuf_commented_addf(&buf, _(tag_template), tag, comment_line_char);
                        else
-                               strbuf_commented_addf(&buf, _(tag_template_nocleanup), comment_line_char);
+                               strbuf_commented_addf(&buf, _(tag_template_nocleanup), tag, comment_line_char);
                        write_or_die(fd, buf.buf, buf.len);
                        strbuf_release(&buf);
                }
index ebea285e1b6863bdb8e4b2a30d1487d18ecc5084..e8c7fd4d4957b83de42e7af2ef9f2676bfc294b2 100644 (file)
@@ -13,6 +13,7 @@
 #include "parse-options.h"
 #include "pathspec.h"
 #include "dir.h"
+#include "split-index.h"
 
 /*
  * Default to not allowing changes to the list of files. The
@@ -55,8 +56,9 @@ static int mark_ce_flags(const char *path, int flag, int mark)
                        active_cache[pos]->ce_flags |= flag;
                else
                        active_cache[pos]->ce_flags &= ~flag;
-               cache_tree_invalidate_path(active_cache_tree, path);
-               active_cache_changed = 1;
+               active_cache[pos]->ce_flags |= CE_UPDATE_IN_BASE;
+               cache_tree_invalidate_path(&the_index, path);
+               active_cache_changed |= CE_ENTRY_CHANGED;
                return 0;
        }
        return -1;
@@ -267,8 +269,9 @@ static void chmod_path(int flip, const char *path)
        default:
                goto fail;
        }
-       cache_tree_invalidate_path(active_cache_tree, path);
-       active_cache_changed = 1;
+       cache_tree_invalidate_path(&the_index, path);
+       ce->ce_flags |= CE_UPDATE_IN_BASE;
+       active_cache_changed |= CE_ENTRY_CHANGED;
        report("chmod %cx '%s'", flip, path);
        return;
  fail:
@@ -743,6 +746,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
        char set_executable_bit = 0;
        struct refresh_params refresh_args = {0, &has_errors};
        int lock_error = 0;
+       int split_index = -1;
        struct lock_file *lock_file;
        struct parse_opt_ctx_t ctx;
        int parseopt_state = PARSE_OPT_UNKNOWN;
@@ -825,6 +829,8 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
                        resolve_undo_clear_callback},
                OPT_INTEGER(0, "index-version", &preferred_index_format,
                        N_("write index in this format")),
+               OPT_BOOL(0, "split-index", &split_index,
+                       N_("enable or disable split index")),
                OPT_END()
        };
 
@@ -892,7 +898,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
                            INDEX_FORMAT_LB, INDEX_FORMAT_UB);
 
                if (the_index.version != preferred_index_format)
-                       active_cache_changed = 1;
+                       active_cache_changed |= SOMETHING_CHANGED;
                the_index.version = preferred_index_format;
        }
 
@@ -918,14 +924,27 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
                strbuf_release(&buf);
        }
 
+       if (split_index > 0) {
+               init_split_index(&the_index);
+               the_index.cache_changed |= SPLIT_INDEX_ORDERED;
+       } else if (!split_index && the_index.split_index) {
+               /*
+                * can't discard_split_index(&the_index); because that
+                * will destroy split_index->base->cache[], which may
+                * be shared with the_index.cache[]. So yeah we're
+                * leaking a bit here.
+                */
+               the_index.split_index = NULL;
+               the_index.cache_changed |= SOMETHING_CHANGED;
+       }
+
        if (active_cache_changed) {
                if (newfd < 0) {
                        if (refresh_args.flags & REFRESH_QUIET)
                                exit(128);
                        unable_to_lock_index_die(get_index_file(), lock_error);
                }
-               if (write_cache(newfd, active_cache, active_nr) ||
-                   commit_locked_index(lock_file))
+               if (write_locked_index(&the_index, lock_file, COMMIT_LOCK))
                        die("Unable to write new index file");
        }
 
index 5c208bb1fc4f6c467842b37157435e87fe1415cd..405267f6e2776b3b2bf5c91c1102e090f5ac68f0 100644 (file)
@@ -12,238 +12,329 @@ static const char * const git_update_ref_usage[] = {
        NULL
 };
 
-static int updates_alloc;
-static int updates_count;
-static const struct ref_update **updates;
+static struct ref_transaction *transaction;
 
 static char line_termination = '\n';
 static int update_flags;
 
-static struct ref_update *update_alloc(void)
-{
-       struct ref_update *update;
-
-       /* Allocate and zero-init a struct ref_update */
-       update = xcalloc(1, sizeof(*update));
-       ALLOC_GROW(updates, updates_count + 1, updates_alloc);
-       updates[updates_count++] = update;
-
-       /* Store and reset accumulated options */
-       update->flags = update_flags;
-       update_flags = 0;
-
-       return update;
-}
-
-static void update_store_ref_name(struct ref_update *update,
-                                 const char *ref_name)
-{
-       if (check_refname_format(ref_name, REFNAME_ALLOW_ONELEVEL))
-               die("invalid ref format: %s", ref_name);
-       update->ref_name = xstrdup(ref_name);
-}
-
-static void update_store_new_sha1(struct ref_update *update,
-                                 const char *newvalue)
-{
-       if (*newvalue && get_sha1(newvalue, update->new_sha1))
-               die("invalid new value for ref %s: %s",
-                   update->ref_name, newvalue);
-}
-
-static void update_store_old_sha1(struct ref_update *update,
-                                 const char *oldvalue)
-{
-       if (*oldvalue && get_sha1(oldvalue, update->old_sha1))
-               die("invalid old value for ref %s: %s",
-                   update->ref_name, oldvalue);
-
-       /* We have an old value if non-empty, or if empty without -z */
-       update->have_old = *oldvalue || line_termination;
-}
-
+/*
+ * Parse one whitespace- or NUL-terminated, possibly C-quoted argument
+ * and append the result to arg.  Return a pointer to the terminator.
+ * Die if there is an error in how the argument is C-quoted.  This
+ * function is only used if not -z.
+ */
 static const char *parse_arg(const char *next, struct strbuf *arg)
 {
-       /* Parse SP-terminated, possibly C-quoted argument */
-       if (*next != '"')
+       if (*next == '"') {
+               const char *orig = next;
+
+               if (unquote_c_style(arg, next, &next))
+                       die("badly quoted argument: %s", orig);
+               if (*next && !isspace(*next))
+                       die("unexpected character after quoted argument: %s", orig);
+       } else {
                while (*next && !isspace(*next))
                        strbuf_addch(arg, *next++);
-       else if (unquote_c_style(arg, next, &next))
-               die("badly quoted argument: %s", next);
+       }
 
-       /* Return position after the argument */
        return next;
 }
 
-static const char *parse_first_arg(const char *next, struct strbuf *arg)
+/*
+ * Parse the reference name immediately after "command SP".  If not
+ * -z, then handle C-quoting.  Return a pointer to a newly allocated
+ * string containing the name of the reference, or NULL if there was
+ * an error.  Update *next to point at the character that terminates
+ * the argument.  Die if C-quoting is malformed or the reference name
+ * is invalid.
+ */
+static char *parse_refname(struct strbuf *input, const char **next)
 {
-       /* Parse argument immediately after "command SP" */
-       strbuf_reset(arg);
+       struct strbuf ref = STRBUF_INIT;
+
        if (line_termination) {
                /* Without -z, use the next argument */
-               next = parse_arg(next, arg);
+               *next = parse_arg(*next, &ref);
        } else {
-               /* With -z, use rest of first NUL-terminated line */
-               strbuf_addstr(arg, next);
-               next = next + arg->len;
+               /* With -z, use everything up to the next NUL */
+               strbuf_addstr(&ref, *next);
+               *next += ref.len;
        }
-       return next;
+
+       if (!ref.len) {
+               strbuf_release(&ref);
+               return NULL;
+       }
+
+       if (check_refname_format(ref.buf, REFNAME_ALLOW_ONELEVEL))
+               die("invalid ref format: %s", ref.buf);
+
+       return strbuf_detach(&ref, NULL);
 }
 
-static const char *parse_next_arg(const char *next, struct strbuf *arg)
+/*
+ * The value being parsed is <oldvalue> (as opposed to <newvalue>; the
+ * difference affects which error messages are generated):
+ */
+#define PARSE_SHA1_OLD 0x01
+
+/*
+ * For backwards compatibility, accept an empty string for update's
+ * <newvalue> in binary mode to be equivalent to specifying zeros.
+ */
+#define PARSE_SHA1_ALLOW_EMPTY 0x02
+
+/*
+ * Parse an argument separator followed by the next argument, if any.
+ * If there is an argument, convert it to a SHA-1, write it to sha1,
+ * set *next to point at the character terminating the argument, and
+ * return 0.  If there is no argument at all (not even the empty
+ * string), return 1 and leave *next unchanged.  If the value is
+ * provided but cannot be converted to a SHA-1, die.  flags can
+ * include PARSE_SHA1_OLD and/or PARSE_SHA1_ALLOW_EMPTY.
+ */
+static int parse_next_sha1(struct strbuf *input, const char **next,
+                          unsigned char *sha1,
+                          const char *command, const char *refname,
+                          int flags)
 {
-       /* Parse next SP-terminated or NUL-terminated argument, if any */
-       strbuf_reset(arg);
+       struct strbuf arg = STRBUF_INIT;
+       int ret = 0;
+
+       if (*next == input->buf + input->len)
+               goto eof;
+
        if (line_termination) {
                /* Without -z, consume SP and use next argument */
-               if (!*next)
-                       return NULL;
-               if (*next != ' ')
-                       die("expected SP but got: %s", next);
-               next = parse_arg(next + 1, arg);
+               if (!**next || **next == line_termination)
+                       return 1;
+               if (**next != ' ')
+                       die("%s %s: expected SP but got: %s",
+                           command, refname, *next);
+               (*next)++;
+               *next = parse_arg(*next, &arg);
+               if (arg.len) {
+                       if (get_sha1(arg.buf, sha1))
+                               goto invalid;
+               } else {
+                       /* Without -z, an empty value means all zeros: */
+                       hashclr(sha1);
+               }
        } else {
                /* With -z, read the next NUL-terminated line */
-               if (*next)
-                       die("expected NUL but got: %s", next);
-               if (strbuf_getline(arg, stdin, '\0') == EOF)
-                       return NULL;
-               next = arg->buf + arg->len;
+               if (**next)
+                       die("%s %s: expected NUL but got: %s",
+                           command, refname, *next);
+               (*next)++;
+               if (*next == input->buf + input->len)
+                       goto eof;
+               strbuf_addstr(&arg, *next);
+               *next += arg.len;
+
+               if (arg.len) {
+                       if (get_sha1(arg.buf, sha1))
+                               goto invalid;
+               } else if (flags & PARSE_SHA1_ALLOW_EMPTY) {
+                       /* With -z, treat an empty value as all zeros: */
+                       warning("%s %s: missing <newvalue>, treating as zero",
+                               command, refname);
+                       hashclr(sha1);
+               } else {
+                       /*
+                        * With -z, an empty non-required value means
+                        * unspecified:
+                        */
+                       ret = 1;
+               }
        }
-       return next;
+
+       strbuf_release(&arg);
+
+       return ret;
+
+ invalid:
+       die(flags & PARSE_SHA1_OLD ?
+           "%s %s: invalid <oldvalue>: %s" :
+           "%s %s: invalid <newvalue>: %s",
+           command, refname, arg.buf);
+
+ eof:
+       die(flags & PARSE_SHA1_OLD ?
+           "%s %s: unexpected end of input when reading <oldvalue>" :
+           "%s %s: unexpected end of input when reading <newvalue>",
+           command, refname);
 }
 
-static void parse_cmd_update(const char *next)
+
+/*
+ * The following five parse_cmd_*() functions parse the corresponding
+ * command.  In each case, next points at the character following the
+ * command name and the following space.  They each return a pointer
+ * to the character terminating the command, and die with an
+ * explanatory message if there are any parsing problems.  All of
+ * these functions handle either text or binary format input,
+ * depending on how line_termination is set.
+ */
+
+static const char *parse_cmd_update(struct strbuf *input, const char *next)
 {
-       struct strbuf ref = STRBUF_INIT;
-       struct strbuf newvalue = STRBUF_INIT;
-       struct strbuf oldvalue = STRBUF_INIT;
-       struct ref_update *update;
+       char *refname;
+       unsigned char new_sha1[20];
+       unsigned char old_sha1[20];
+       int have_old;
 
-       update = update_alloc();
+       refname = parse_refname(input, &next);
+       if (!refname)
+               die("update: missing <ref>");
 
-       if ((next = parse_first_arg(next, &ref)) != NULL && ref.buf[0])
-               update_store_ref_name(update, ref.buf);
-       else
-               die("update line missing <ref>");
+       if (parse_next_sha1(input, &next, new_sha1, "update", refname,
+                           PARSE_SHA1_ALLOW_EMPTY))
+               die("update %s: missing <newvalue>", refname);
 
-       if ((next = parse_next_arg(next, &newvalue)) != NULL)
-               update_store_new_sha1(update, newvalue.buf);
-       else
-               die("update %s missing <newvalue>", ref.buf);
+       have_old = !parse_next_sha1(input, &next, old_sha1, "update", refname,
+                                   PARSE_SHA1_OLD);
 
-       if ((next = parse_next_arg(next, &oldvalue)) != NULL)
-               update_store_old_sha1(update, oldvalue.buf);
-       else if(!line_termination)
-               die("update %s missing [<oldvalue>] NUL", ref.buf);
+       if (*next != line_termination)
+               die("update %s: extra input: %s", refname, next);
 
-       if (next && *next)
-               die("update %s has extra input: %s", ref.buf, next);
+       ref_transaction_update(transaction, refname, new_sha1, old_sha1,
+                              update_flags, have_old);
+
+       update_flags = 0;
+       free(refname);
+
+       return next;
 }
 
-static void parse_cmd_create(const char *next)
+static const char *parse_cmd_create(struct strbuf *input, const char *next)
 {
-       struct strbuf ref = STRBUF_INIT;
-       struct strbuf newvalue = STRBUF_INIT;
-       struct ref_update *update;
+       char *refname;
+       unsigned char new_sha1[20];
 
-       update = update_alloc();
-       update->have_old = 1;
+       refname = parse_refname(input, &next);
+       if (!refname)
+               die("create: missing <ref>");
 
-       if ((next = parse_first_arg(next, &ref)) != NULL && ref.buf[0])
-               update_store_ref_name(update, ref.buf);
-       else
-               die("create line missing <ref>");
+       if (parse_next_sha1(input, &next, new_sha1, "create", refname, 0))
+               die("create %s: missing <newvalue>", refname);
 
-       if ((next = parse_next_arg(next, &newvalue)) != NULL)
-               update_store_new_sha1(update, newvalue.buf);
-       else
-               die("create %s missing <newvalue>", ref.buf);
-       if (is_null_sha1(update->new_sha1))
-               die("create %s given zero new value", ref.buf);
+       if (is_null_sha1(new_sha1))
+               die("create %s: zero <newvalue>", refname);
+
+       if (*next != line_termination)
+               die("create %s: extra input: %s", refname, next);
 
-       if (next && *next)
-               die("create %s has extra input: %s", ref.buf, next);
+       ref_transaction_create(transaction, refname, new_sha1, update_flags);
+
+       update_flags = 0;
+       free(refname);
+
+       return next;
 }
 
-static void parse_cmd_delete(const char *next)
+static const char *parse_cmd_delete(struct strbuf *input, const char *next)
 {
-       struct strbuf ref = STRBUF_INIT;
-       struct strbuf oldvalue = STRBUF_INIT;
-       struct ref_update *update;
+       char *refname;
+       unsigned char old_sha1[20];
+       int have_old;
 
-       update = update_alloc();
+       refname = parse_refname(input, &next);
+       if (!refname)
+               die("delete: missing <ref>");
 
-       if ((next = parse_first_arg(next, &ref)) != NULL && ref.buf[0])
-               update_store_ref_name(update, ref.buf);
-       else
-               die("delete line missing <ref>");
+       if (parse_next_sha1(input, &next, old_sha1, "delete", refname,
+                           PARSE_SHA1_OLD)) {
+               have_old = 0;
+       } else {
+               if (is_null_sha1(old_sha1))
+                       die("delete %s: zero <oldvalue>", refname);
+               have_old = 1;
+       }
+
+       if (*next != line_termination)
+               die("delete %s: extra input: %s", refname, next);
 
-       if ((next = parse_next_arg(next, &oldvalue)) != NULL)
-               update_store_old_sha1(update, oldvalue.buf);
-       else if(!line_termination)
-               die("delete %s missing [<oldvalue>] NUL", ref.buf);
-       if (update->have_old && is_null_sha1(update->old_sha1))
-               die("delete %s given zero old value", ref.buf);
+       ref_transaction_delete(transaction, refname, old_sha1,
+                              update_flags, have_old);
 
-       if (next && *next)
-               die("delete %s has extra input: %s", ref.buf, next);
+       update_flags = 0;
+       free(refname);
+
+       return next;
 }
 
-static void parse_cmd_verify(const char *next)
+static const char *parse_cmd_verify(struct strbuf *input, const char *next)
 {
-       struct strbuf ref = STRBUF_INIT;
-       struct strbuf value = STRBUF_INIT;
-       struct ref_update *update;
+       char *refname;
+       unsigned char new_sha1[20];
+       unsigned char old_sha1[20];
+       int have_old;
+
+       refname = parse_refname(input, &next);
+       if (!refname)
+               die("verify: missing <ref>");
+
+       if (parse_next_sha1(input, &next, old_sha1, "verify", refname,
+                           PARSE_SHA1_OLD)) {
+               hashclr(new_sha1);
+               have_old = 0;
+       } else {
+               hashcpy(new_sha1, old_sha1);
+               have_old = 1;
+       }
 
-       update = update_alloc();
+       if (*next != line_termination)
+               die("verify %s: extra input: %s", refname, next);
 
-       if ((next = parse_first_arg(next, &ref)) != NULL && ref.buf[0])
-               update_store_ref_name(update, ref.buf);
-       else
-               die("verify line missing <ref>");
+       ref_transaction_update(transaction, refname, new_sha1, old_sha1,
+                              update_flags, have_old);
 
-       if ((next = parse_next_arg(next, &value)) != NULL) {
-               update_store_old_sha1(update, value.buf);
-               update_store_new_sha1(update, value.buf);
-       } else if(!line_termination)
-               die("verify %s missing [<oldvalue>] NUL", ref.buf);
+       update_flags = 0;
+       free(refname);
 
-       if (next && *next)
-               die("verify %s has extra input: %s", ref.buf, next);
+       return next;
 }
 
-static void parse_cmd_option(const char *next)
+static const char *parse_cmd_option(struct strbuf *input, const char *next)
 {
-       if (!strcmp(next, "no-deref"))
+       if (!strncmp(next, "no-deref", 8) && next[8] == line_termination)
                update_flags |= REF_NODEREF;
        else
                die("option unknown: %s", next);
+       return next + 8;
 }
 
 static void update_refs_stdin(void)
 {
-       struct strbuf cmd = STRBUF_INIT;
+       struct strbuf input = STRBUF_INIT;
+       const char *next;
 
+       if (strbuf_read(&input, 0, 1000) < 0)
+               die_errno("could not read from stdin");
+       next = input.buf;
        /* Read each line dispatch its command */
-       while (strbuf_getline(&cmd, stdin, line_termination) != EOF)
-               if (!cmd.buf[0])
+       while (next < input.buf + input.len) {
+               if (*next == line_termination)
                        die("empty command in input");
-               else if (isspace(*cmd.buf))
-                       die("whitespace before command: %s", cmd.buf);
-               else if (starts_with(cmd.buf, "update "))
-                       parse_cmd_update(cmd.buf + 7);
-               else if (starts_with(cmd.buf, "create "))
-                       parse_cmd_create(cmd.buf + 7);
-               else if (starts_with(cmd.buf, "delete "))
-                       parse_cmd_delete(cmd.buf + 7);
-               else if (starts_with(cmd.buf, "verify "))
-                       parse_cmd_verify(cmd.buf + 7);
-               else if (starts_with(cmd.buf, "option "))
-                       parse_cmd_option(cmd.buf + 7);
+               else if (isspace(*next))
+                       die("whitespace before command: %s", next);
+               else if (starts_with(next, "update "))
+                       next = parse_cmd_update(&input, next + 7);
+               else if (starts_with(next, "create "))
+                       next = parse_cmd_create(&input, next + 7);
+               else if (starts_with(next, "delete "))
+                       next = parse_cmd_delete(&input, next + 7);
+               else if (starts_with(next, "verify "))
+                       next = parse_cmd_verify(&input, next + 7);
+               else if (starts_with(next, "option "))
+                       next = parse_cmd_option(&input, next + 7);
                else
-                       die("unknown command: %s", cmd.buf);
+                       die("unknown command: %s", next);
+
+               next++;
+       }
 
-       strbuf_release(&cmd);
+       strbuf_release(&input);
 }
 
 int cmd_update_ref(int argc, const char **argv, const char *prefix)
@@ -268,12 +359,17 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
                die("Refusing to perform update with empty message.");
 
        if (read_stdin) {
+               int ret;
+               transaction = ref_transaction_begin();
+
                if (delete || no_deref || argc > 0)
                        usage_with_options(git_update_ref_usage, options);
                if (end_null)
                        line_termination = '\0';
                update_refs_stdin();
-               return update_refs(msg, updates, updates_count, DIE_ON_ERR);
+               ret = ref_transaction_commit(transaction, msg,
+                                            UPDATE_REFS_DIE_ON_ERR);
+               return ret;
        }
 
        if (end_null)
@@ -305,5 +401,5 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
                return delete_ref(refname, oldval ? oldsha1 : NULL, flags);
        else
                return update_ref(msg, refname, sha1, oldval ? oldsha1 : NULL,
-                                 flags, DIE_ON_ERR);
+                                 flags, UPDATE_REFS_DIE_ON_ERR);
 }
diff --git a/builtin/verify-commit.c b/builtin/verify-commit.c
new file mode 100644 (file)
index 0000000..b0f8504
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * Builtin "git commit-commit"
+ *
+ * Copyright (c) 2014 Michael J Gruber <git@drmicha.warpmail.net>
+ *
+ * Based on git-verify-tag
+ */
+#include "cache.h"
+#include "builtin.h"
+#include "commit.h"
+#include "run-command.h"
+#include <signal.h>
+#include "parse-options.h"
+#include "gpg-interface.h"
+
+static const char * const verify_commit_usage[] = {
+               N_("git verify-commit [-v|--verbose] <commit>..."),
+               NULL
+};
+
+static int run_gpg_verify(const unsigned char *sha1, const char *buf, unsigned long size, int verbose)
+{
+       struct signature_check signature_check;
+
+       memset(&signature_check, 0, sizeof(signature_check));
+
+       check_commit_signature(lookup_commit(sha1), &signature_check);
+
+       if (verbose && signature_check.payload)
+               fputs(signature_check.payload, stdout);
+
+       if (signature_check.gpg_output)
+               fputs(signature_check.gpg_output, stderr);
+
+       signature_check_clear(&signature_check);
+       return signature_check.result != 'G';
+}
+
+static int verify_commit(const char *name, int verbose)
+{
+       enum object_type type;
+       unsigned char sha1[20];
+       char *buf;
+       unsigned long size;
+       int ret;
+
+       if (get_sha1(name, sha1))
+               return error("commit '%s' not found.", name);
+
+       buf = read_sha1_file(sha1, &type, &size);
+       if (!buf)
+               return error("%s: unable to read file.", name);
+       if (type != OBJ_COMMIT)
+               return error("%s: cannot verify a non-commit object of type %s.",
+                               name, typename(type));
+
+       ret = run_gpg_verify(sha1, buf, size, verbose);
+
+       free(buf);
+       return ret;
+}
+
+static int git_verify_commit_config(const char *var, const char *value, void *cb)
+{
+       int status = git_gpg_config(var, value, cb);
+       if (status)
+               return status;
+       return git_default_config(var, value, cb);
+}
+
+int cmd_verify_commit(int argc, const char **argv, const char *prefix)
+{
+       int i = 1, verbose = 0, had_error = 0;
+       const struct option verify_commit_options[] = {
+               OPT__VERBOSE(&verbose, N_("print commit contents")),
+               OPT_END()
+       };
+
+       git_config(git_verify_commit_config, NULL);
+
+       argc = parse_options(argc, argv, prefix, verify_commit_options,
+                            verify_commit_usage, PARSE_OPT_KEEP_ARGV0);
+       if (argc <= i)
+               usage_with_options(verify_commit_usage, verify_commit_options);
+
+       /* sometimes the program was terminated because this signal
+        * was received in the process of writing the gpg input: */
+       signal(SIGPIPE, SIG_IGN);
+       while (i < argc)
+               if (verify_commit(argv[i++], verbose))
+                       had_error = 1;
+       return had_error;
+}
index 66cd2df0f878d362a86e8dbc3fcd49b0c2f64c0c..972579f33c4b0adfb2240ef90b22980dc042c70a 100644 (file)
@@ -27,10 +27,9 @@ static int verify_one_pack(const char *path, unsigned int flags)
         * normalize these forms to "foo.pack" for "index-pack --verify".
         */
        strbuf_addstr(&arg, path);
-       if (has_extension(arg.buf, ".idx"))
-               strbuf_splice(&arg, arg.len - 3, 3, "pack", 4);
-       else if (!has_extension(arg.buf, ".pack"))
-               strbuf_add(&arg, ".pack", 5);
+       if (strbuf_strip_suffix(&arg, ".idx") ||
+           !ends_with(arg.buf, ".pack"))
+               strbuf_addstr(&arg, ".pack");
        argv[2] = arg.buf;
 
        memset(&index_pack, 0, sizeof(index_pack));
index 7fa524a11323621d24c352b0a1108ae953a60cf5..c53f7de2b13acfc1b97c60b04552e57791377442 100644 (file)
@@ -98,7 +98,7 @@ struct cache_tree_sub *cache_tree_sub(struct cache_tree *it, const char *path)
        return find_subtree(it, path, pathlen, 1);
 }
 
-void cache_tree_invalidate_path(struct cache_tree *it, const char *path)
+static int do_invalidate_path(struct cache_tree *it, const char *path)
 {
        /* a/b/c
         * ==> invalidate self
@@ -116,7 +116,7 @@ void cache_tree_invalidate_path(struct cache_tree *it, const char *path)
 #endif
 
        if (!it)
-               return;
+               return 0;
        slash = strchrnul(path, '/');
        namelen = slash - path;
        it->entry_count = -1;
@@ -137,14 +137,21 @@ void cache_tree_invalidate_path(struct cache_tree *it, const char *path)
                                (it->subtree_nr - pos - 1));
                        it->subtree_nr--;
                }
-               return;
+               return 1;
        }
        down = find_subtree(it, path, namelen, 0);
        if (down)
-               cache_tree_invalidate_path(down->cache_tree, slash + 1);
+               do_invalidate_path(down->cache_tree, slash + 1);
+       return 1;
 }
 
-static int verify_cache(const struct cache_entry * const *cache,
+void cache_tree_invalidate_path(struct index_state *istate, const char *path)
+{
+       if (do_invalidate_path(istate->cache_tree, path))
+               istate->cache_changed |= CACHE_TREE_CHANGED;
+}
+
+static int verify_cache(struct cache_entry **cache,
                        int entries, int flags)
 {
        int i, funny;
@@ -229,7 +236,7 @@ int cache_tree_fully_valid(struct cache_tree *it)
 }
 
 static int update_one(struct cache_tree *it,
-                     const struct cache_entry * const *cache,
+                     struct cache_entry **cache,
                      int entries,
                      const char *base,
                      int baselen,
@@ -391,18 +398,19 @@ static int update_one(struct cache_tree *it,
        return i;
 }
 
-int cache_tree_update(struct cache_tree *it,
-                     const struct cache_entry * const *cache,
-                     int entries,
-                     int flags)
+int cache_tree_update(struct index_state *istate, int flags)
 {
-       int i, skip;
-       i = verify_cache(cache, entries, flags);
+       struct cache_tree *it = istate->cache_tree;
+       struct cache_entry **cache = istate->cache;
+       int entries = istate->cache_nr;
+       int skip, i = verify_cache(cache, entries, flags);
+
        if (i)
                return i;
        i = update_one(it, cache, entries, "", 0, &skip, flags);
        if (i < 0)
                return i;
+       istate->cache_changed |= CACHE_TREE_CHANGED;
        return 0;
 }
 
@@ -590,13 +598,10 @@ int write_cache_as_tree(unsigned char *sha1, int flags, const char *prefix)
 
        was_valid = cache_tree_fully_valid(active_cache_tree);
        if (!was_valid) {
-               if (cache_tree_update(active_cache_tree,
-                                     (const struct cache_entry * const *)active_cache,
-                                     active_nr, flags) < 0)
+               if (cache_tree_update(&the_index, flags) < 0)
                        return WRITE_TREE_UNMERGED_INDEX;
                if (0 <= newfd) {
-                       if (!write_cache(newfd, active_cache, active_nr) &&
-                           !commit_lock_file(lock_file))
+                       if (!write_locked_index(&the_index, lock_file, COMMIT_LOCK))
                                newfd = -1;
                }
                /* Not being able to write is fine -- we are only interested
@@ -649,11 +654,12 @@ static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
        it->entry_count = cnt;
 }
 
-void prime_cache_tree(struct cache_tree **it, struct tree *tree)
+void prime_cache_tree(struct index_state *istate, struct tree *tree)
 {
-       cache_tree_free(it);
-       *it = cache_tree();
-       prime_cache_tree_rec(*it, tree);
+       cache_tree_free(&istate->cache_tree);
+       istate->cache_tree = cache_tree();
+       prime_cache_tree_rec(istate->cache_tree, tree);
+       istate->cache_changed |= CACHE_TREE_CHANGED;
 }
 
 /*
@@ -692,7 +698,5 @@ int update_main_cache_tree(int flags)
 {
        if (!the_index.cache_tree)
                the_index.cache_tree = cache_tree();
-       return cache_tree_update(the_index.cache_tree,
-                                (const struct cache_entry * const *)the_index.cache,
-                                the_index.cache_nr, flags);
+       return cache_tree_update(&the_index, flags);
 }
index f1923ad1e9ddd3ad9b77a436e66ad083843094a0..b47ccec7f626d7cda34ed17661c1dc3e4f035d6a 100644 (file)
@@ -23,14 +23,14 @@ struct cache_tree {
 
 struct cache_tree *cache_tree(void);
 void cache_tree_free(struct cache_tree **);
-void cache_tree_invalidate_path(struct cache_tree *, const char *);
+void cache_tree_invalidate_path(struct index_state *, const char *);
 struct cache_tree_sub *cache_tree_sub(struct cache_tree *, const char *);
 
 void cache_tree_write(struct strbuf *, struct cache_tree *root);
 struct cache_tree *cache_tree_read(const char *buffer, unsigned long size);
 
 int cache_tree_fully_valid(struct cache_tree *);
-int cache_tree_update(struct cache_tree *, const struct cache_entry * const *, int, int);
+int cache_tree_update(struct index_state *, int);
 
 int update_main_cache_tree(int);
 
@@ -46,7 +46,7 @@ int update_main_cache_tree(int);
 #define WRITE_TREE_PREFIX_ERROR (-3)
 
 int write_cache_as_tree(unsigned char *sha1, int flags, const char *prefix);
-void prime_cache_tree(struct cache_tree **, struct tree *);
+void prime_cache_tree(struct index_state *, struct tree *);
 
 extern int cache_tree_matches_traversal(struct cache_tree *, struct name_entry *ent, struct traverse_info *info);
 
diff --git a/cache.h b/cache.h
index f505ffbcf4169c6fef59e31845a081453d6304aa..92fc9f1121776fbebf180b5e9d958982e8a98014 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -74,6 +74,21 @@ unsigned long git_deflate_bound(git_zstream *, unsigned long);
 #define S_IFGITLINK    0160000
 #define S_ISGITLINK(m) (((m) & S_IFMT) == S_IFGITLINK)
 
+/*
+ * Some mode bits are also used internally for computations.
+ *
+ * They *must* not overlap with any valid modes, and they *must* not be emitted
+ * to outside world - i.e. appear on disk or network. In other words, it's just
+ * temporary fields, which we internally use, but they have to stay in-house.
+ *
+ * ( such approach is valid, as standard S_IF* fits into 16 bits, and in Git
+ *   codebase mode is `unsigned int` which is assumed to be at least 32 bits )
+ */
+
+/* used internally in tree-diff */
+#define S_DIFFTREE_IFXMIN_NEQ  0x80000000
+
+
 /*
  * Intensive research over the course of many years has shown that
  * port 9418 is totally unused by anything else. Or
@@ -135,6 +150,7 @@ struct cache_entry {
        unsigned int ce_mode;
        unsigned int ce_flags;
        unsigned int ce_namelen;
+       unsigned int index;     /* for link extension */
        unsigned char sha1[20];
        char name[FLEX_ARRAY]; /* more */
 };
@@ -145,7 +161,7 @@ struct cache_entry {
 #define CE_STAGESHIFT 12
 
 /*
- * Range 0xFFFF0000 in ce_flags is divided into
+ * Range 0xFFFF0FFF in ce_flags is divided into
  * two parts: in-memory flags and on-disk ones.
  * Flags in CE_EXTENDED_FLAGS will get saved on-disk
  * if you want to save a new flag, add it in
@@ -168,6 +184,9 @@ struct cache_entry {
 /* used to temporarily mark paths matched by pathspecs */
 #define CE_MATCHED           (1 << 26)
 
+#define CE_UPDATE_IN_BASE    (1 << 27)
+#define CE_STRIP_NAME        (1 << 28)
+
 /*
  * Extended on-disk flags
  */
@@ -268,12 +287,22 @@ static inline unsigned int canon_mode(unsigned int mode)
 
 #define cache_entry_size(len) (offsetof(struct cache_entry,name) + (len) + 1)
 
+#define SOMETHING_CHANGED      (1 << 0) /* unclassified changes go here */
+#define CE_ENTRY_CHANGED       (1 << 1)
+#define CE_ENTRY_REMOVED       (1 << 2)
+#define CE_ENTRY_ADDED         (1 << 3)
+#define RESOLVE_UNDO_CHANGED   (1 << 4)
+#define CACHE_TREE_CHANGED     (1 << 5)
+#define SPLIT_INDEX_ORDERED    (1 << 6)
+
+struct split_index;
 struct index_state {
        struct cache_entry **cache;
        unsigned int version;
        unsigned int cache_nr, cache_alloc, cache_changed;
        struct string_list *resolve_undo;
        struct cache_tree *cache_tree;
+       struct split_index *split_index;
        struct cache_time timestamp;
        unsigned name_hash_initialized : 1,
                 initialized : 1;
@@ -302,7 +331,6 @@ extern void free_name_hash(struct index_state *istate);
 #define read_cache_preload(pathspec) read_index_preload(&the_index, (pathspec))
 #define is_cache_unborn() is_index_unborn(&the_index)
 #define read_cache_unmerged() read_index_unmerged(&the_index)
-#define write_cache(newfd, cache, entries) write_index(&the_index, (newfd))
 #define discard_cache() discard_index(&the_index)
 #define unmerged_cache() unmerged_index(&the_index)
 #define cache_name_pos(name, namelen) index_name_pos(&the_index,(name),(namelen))
@@ -457,12 +485,17 @@ extern int daemonize(void);
        } while (0)
 
 /* Initialize and use the cache information */
+struct lock_file;
 extern int read_index(struct index_state *);
 extern int read_index_preload(struct index_state *, const struct pathspec *pathspec);
+extern int do_read_index(struct index_state *istate, const char *path,
+                        int must_exist); /* for testting only! */
 extern int read_index_from(struct index_state *, const char *path);
 extern int is_index_unborn(struct index_state *);
 extern int read_index_unmerged(struct index_state *);
-extern int write_index(struct index_state *, int newfd);
+#define COMMIT_LOCK            (1 << 0)
+#define CLOSE_LOCK             (1 << 1)
+extern int write_locked_index(struct index_state *, struct lock_file *lock, unsigned flags);
 extern int discard_index(struct index_state *);
 extern int unmerged_index(const struct index_state *);
 extern int verify_path(const char *path);
@@ -474,6 +507,7 @@ extern int index_name_pos(const struct index_state *, const char *name, int name
 #define ADD_CACHE_SKIP_DFCHECK 4       /* Ok to skip DF conflict checks */
 #define ADD_CACHE_JUST_APPEND 8                /* Append only; tree.c::read_tree() */
 #define ADD_CACHE_NEW_ONLY 16          /* Do not replace existing ones */
+#define ADD_CACHE_KEEP_CACHE_TREE 32   /* Do not invalidate cache-tree */
 extern int add_index_entry(struct index_state *, struct cache_entry *ce, int option);
 extern void rename_index_entry_at(struct index_state *, int pos, const char *new_name);
 extern int remove_index_entry_at(struct index_state *, int pos);
@@ -551,7 +585,6 @@ extern int commit_lock_file(struct lock_file *);
 extern void update_index_if_able(struct index_state *, struct lock_file *);
 
 extern int hold_locked_index(struct lock_file *, int);
-extern int commit_locked_index(struct lock_file *);
 extern void set_alternate_index_output(const char *);
 extern int close_lock_file(struct lock_file *);
 extern void rollback_lock_file(struct lock_file *);
@@ -603,6 +636,7 @@ extern int precomposed_unicode;
  * that is subject to stripspace.
  */
 extern char comment_line_char;
+extern int auto_comment_line_char;
 
 enum branch_track {
        BRANCH_TRACK_UNSPECIFIED = -1,
@@ -810,7 +844,6 @@ int normalize_path_copy(char *dst, const char *src);
 int longest_ancestor_length(const char *path, struct string_list *prefixes);
 char *strip_path_suffix(const char *path, const char *suffix);
 int daemon_avoid_alias(const char *path);
-int offset_1st_component(const char *path);
 
 /* object replacement */
 #define LOOKUP_REPLACE_OBJECT 1
@@ -984,7 +1017,7 @@ extern int validate_headref(const char *ref);
 
 extern int base_name_compare(const char *name1, int len1, int mode1, const char *name2, int len2, int mode2);
 extern int df_name_compare(const char *name1, int len1, int mode1, const char *name2, int len2, int mode2);
-extern int cache_name_compare(const char *name1, int len1, const char *name2, int len2);
+extern int name_compare(const char *name1, size_t len1, const char *name2, size_t len2);
 extern int cache_name_stage_compare(const char *name1, int len1, int stage1, const char *name2, int len2, int stage2);
 
 extern void *read_object_with_reference(const unsigned char *sha1,
@@ -1046,6 +1079,13 @@ struct ident_split {
  */
 extern int split_ident_line(struct ident_split *, const char *, int);
 
+/*
+ * Like show_date, but pull the timestamp and tz parameters from
+ * the ident_split. It will also sanity-check the values and produce
+ * a well-known sentinel date if they appear bogus.
+ */
+const char *show_ident_date(const struct ident_split *id, enum date_mode mode);
+
 /*
  * Compare split idents for equality or strict ordering. Note that we
  * compare only the ident part of the line, ignoring any timestamp.
@@ -1056,6 +1096,7 @@ extern int split_ident_line(struct ident_split *, const char *, int);
 extern int ident_cmp(const struct ident_split *, const struct ident_split *);
 
 struct checkout {
+       struct index_state *istate;
        const char *base_dir;
        int base_dir_len;
        unsigned force:1,
@@ -1276,8 +1317,8 @@ extern int check_repository_format_version(const char *var, const char *value, v
 extern int git_env_bool(const char *, int);
 extern int git_config_system(void);
 extern int config_error_nonbool(const char *);
-#if defined(__GNUC__) && ! defined(__clang__)
-#define config_error_nonbool(s) (config_error_nonbool(s), -1)
+#if defined(__GNUC__)
+#define config_error_nonbool(s) (config_error_nonbool(s), const_error())
 #endif
 extern const char *get_log_output_encoding(void);
 extern const char *get_commit_output_encoding(void);
index a1c4c3e8d845e8e791d7df0c1387e1b2262b5ecf..623eadcbb7dd2b7f58be0ef070b8c805a8101add 100755 (executable)
@@ -2,7 +2,7 @@
 bindir="$1"
 gitexecdir="$2"
 gitcmd="$3"
-if test "$bindir" != "$gitexecdir" -a -x "$gitcmd"
+if test "$bindir" != "$gitexecdir" && test -x "$gitcmd"
 then
        echo
        echo "!! You have installed git-* commands to new gitexecdir."
index 8d1ce88d1493cf18436b03f843c6d90190d47bb2..ca878bcea7a42476a7c2b03e74897a2af87bec3f 100644 (file)
--- a/column.c
+++ b/column.c
@@ -336,8 +336,9 @@ static int column_config(const char *var, const char *value,
 int git_column_config(const char *var, const char *value,
                      const char *command, unsigned int *colopts)
 {
-       const char *it = skip_prefix(var, "column.");
-       if (!it)
+       const char *it;
+
+       if (!skip_prefix(var, "column.", &it))
                return 0;
 
        if (!strcmp(it, "ui"))
@@ -370,46 +371,29 @@ static struct child_process column_process;
 
 int run_column_filter(int colopts, const struct column_options *opts)
 {
-       const char *av[10];
-       int ret, ac = 0;
-       struct strbuf sb_colopt  = STRBUF_INIT;
-       struct strbuf sb_width   = STRBUF_INIT;
-       struct strbuf sb_padding = STRBUF_INIT;
+       struct argv_array *argv;
 
        if (fd_out != -1)
                return -1;
 
-       av[ac++] = "column";
-       strbuf_addf(&sb_colopt, "--raw-mode=%d", colopts);
-       av[ac++] = sb_colopt.buf;
-       if (opts && opts->width) {
-               strbuf_addf(&sb_width, "--width=%d", opts->width);
-               av[ac++] = sb_width.buf;
-       }
-       if (opts && opts->indent) {
-               av[ac++] = "--indent";
-               av[ac++] = opts->indent;
-       }
-       if (opts && opts->padding) {
-               strbuf_addf(&sb_padding, "--padding=%d", opts->padding);
-               av[ac++] = sb_padding.buf;
-       }
-       av[ac] = NULL;
+       memset(&column_process, 0, sizeof(column_process));
+       argv = &column_process.args;
+
+       argv_array_push(argv, "column");
+       argv_array_pushf(argv, "--raw-mode=%d", colopts);
+       if (opts && opts->width)
+               argv_array_pushf(argv, "--width=%d", opts->width);
+       if (opts && opts->indent)
+               argv_array_pushf(argv, "--indent=%s", opts->indent);
+       if (opts && opts->padding)
+               argv_array_pushf(argv, "--padding=%d", opts->padding);
 
        fflush(stdout);
-       memset(&column_process, 0, sizeof(column_process));
        column_process.in = -1;
        column_process.out = dup(1);
        column_process.git_cmd = 1;
-       column_process.argv = av;
-
-       ret = start_command(&column_process);
-
-       strbuf_release(&sb_colopt);
-       strbuf_release(&sb_width);
-       strbuf_release(&sb_padding);
 
-       if (ret)
+       if (start_command(&column_process))
                return -2;
 
        fd_out = dup(1);
index fd6d63c703062e00ff77ce4de53e35a93e1e6e4d..f9975d2c2ebc83e8ecfc953c8df907fbff7858f5 100644 (file)
@@ -1301,6 +1301,81 @@ static const char *path_path(void *obj)
        return path->path;
 }
 
+
+/* find set of paths that every parent touches */
+static struct combine_diff_path *find_paths_generic(const unsigned char *sha1,
+       const struct sha1_array *parents, struct diff_options *opt)
+{
+       struct combine_diff_path *paths = NULL;
+       int i, num_parent = parents->nr;
+
+       int output_format = opt->output_format;
+       const char *orderfile = opt->orderfile;
+
+       opt->output_format = DIFF_FORMAT_NO_OUTPUT;
+       /* tell diff_tree to emit paths in sorted (=tree) order */
+       opt->orderfile = NULL;
+
+       /* D(A,P1...Pn) = D(A,P1) ^ ... ^ D(A,Pn)  (wrt paths) */
+       for (i = 0; i < num_parent; i++) {
+               /*
+                * show stat against the first parent even when doing
+                * combined diff.
+                */
+               int stat_opt = (output_format &
+                               (DIFF_FORMAT_NUMSTAT|DIFF_FORMAT_DIFFSTAT));
+               if (i == 0 && stat_opt)
+                       opt->output_format = stat_opt;
+               else
+                       opt->output_format = DIFF_FORMAT_NO_OUTPUT;
+               diff_tree_sha1(parents->sha1[i], sha1, "", opt);
+               diffcore_std(opt);
+               paths = intersect_paths(paths, i, num_parent);
+
+               /* if showing diff, show it in requested order */
+               if (opt->output_format != DIFF_FORMAT_NO_OUTPUT &&
+                   orderfile) {
+                       diffcore_order(orderfile);
+               }
+
+               diff_flush(opt);
+       }
+
+       opt->output_format = output_format;
+       opt->orderfile = orderfile;
+       return paths;
+}
+
+
+/*
+ * find set of paths that everybody touches, assuming diff is run without
+ * rename/copy detection, etc, comparing all trees simultaneously (= faster).
+ */
+static struct combine_diff_path *find_paths_multitree(
+       const unsigned char *sha1, const struct sha1_array *parents,
+       struct diff_options *opt)
+{
+       int i, nparent = parents->nr;
+       const unsigned char **parents_sha1;
+       struct combine_diff_path paths_head;
+       struct strbuf base;
+
+       parents_sha1 = xmalloc(nparent * sizeof(parents_sha1[0]));
+       for (i = 0; i < nparent; i++)
+               parents_sha1[i] = parents->sha1[i];
+
+       /* fake list head, so worker can assume it is non-NULL */
+       paths_head.next = NULL;
+
+       strbuf_init(&base, PATH_MAX);
+       diff_tree_paths(&paths_head, sha1, parents_sha1, nparent, &base, opt);
+
+       strbuf_release(&base);
+       free(parents_sha1);
+       return paths_head.next;
+}
+
+
 void diff_tree_combined(const unsigned char *sha1,
                        const struct sha1_array *parents,
                        int dense,
@@ -1308,50 +1383,83 @@ void diff_tree_combined(const unsigned char *sha1,
 {
        struct diff_options *opt = &rev->diffopt;
        struct diff_options diffopts;
-       struct combine_diff_path *p, *paths = NULL;
+       struct combine_diff_path *p, *paths;
        int i, num_paths, needsep, show_log_first, num_parent = parents->nr;
+       int need_generic_pathscan;
+
+       /* nothing to do, if no parents */
+       if (!num_parent)
+               return;
+
+       show_log_first = !!rev->loginfo && !rev->no_commit_id;
+       needsep = 0;
+       if (show_log_first) {
+               show_log(rev);
+
+               if (rev->verbose_header && opt->output_format &&
+                   opt->output_format != DIFF_FORMAT_NO_OUTPUT)
+                       printf("%s%c", diff_line_prefix(opt),
+                              opt->line_termination);
+       }
 
        diffopts = *opt;
        copy_pathspec(&diffopts.pathspec, &opt->pathspec);
-       diffopts.output_format = DIFF_FORMAT_NO_OUTPUT;
        DIFF_OPT_SET(&diffopts, RECURSIVE);
        DIFF_OPT_CLR(&diffopts, ALLOW_EXTERNAL);
-       /* tell diff_tree to emit paths in sorted (=tree) order */
-       diffopts.orderfile = NULL;
 
-       show_log_first = !!rev->loginfo && !rev->no_commit_id;
-       needsep = 0;
-       /* find set of paths that everybody touches */
-       for (i = 0; i < num_parent; i++) {
-               /* show stat against the first parent even
+       /* find set of paths that everybody touches
+        *
+        * NOTE
+        *
+        * Diffcore transformations are bound to diff_filespec and logic
+        * comparing two entries - i.e. they do not apply directly to combine
+        * diff.
+        *
+        * If some of such transformations is requested - we launch generic
+        * path scanning, which works significantly slower compared to
+        * simultaneous all-trees-in-one-go scan in find_paths_multitree().
+        *
+        * TODO some of the filters could be ported to work on
+        * combine_diff_paths - i.e. all functionality that skips paths, so in
+        * theory, we could end up having only multitree path scanning.
+        *
+        * NOTE please keep this semantically in sync with diffcore_std()
+        */
+       need_generic_pathscan = opt->skip_stat_unmatch  ||
+                       DIFF_OPT_TST(opt, FOLLOW_RENAMES)       ||
+                       opt->break_opt != -1    ||
+                       opt->detect_rename      ||
+                       opt->pickaxe            ||
+                       opt->filter;
+
+
+       if (need_generic_pathscan) {
+               /*
+                * NOTE generic case also handles --stat, as it computes
+                * diff(sha1,parent_i) for all i to do the job, specifically
+                * for parent0.
+                */
+               paths = find_paths_generic(sha1, parents, &diffopts);
+       }
+       else {
+               int stat_opt;
+               paths = find_paths_multitree(sha1, parents, &diffopts);
+
+               /*
+                * show stat against the first parent even
                 * when doing combined diff.
                 */
-               int stat_opt = (opt->output_format &
+               stat_opt = (opt->output_format &
                                (DIFF_FORMAT_NUMSTAT|DIFF_FORMAT_DIFFSTAT));
-               if (i == 0 && stat_opt)
+               if (stat_opt) {
                        diffopts.output_format = stat_opt;
-               else
-                       diffopts.output_format = DIFF_FORMAT_NO_OUTPUT;
-               diff_tree_sha1(parents->sha1[i], sha1, "", &diffopts);
-               diffcore_std(&diffopts);
-               paths = intersect_paths(paths, i, num_parent);
 
-               if (show_log_first && i == 0) {
-                       show_log(rev);
-
-                       if (rev->verbose_header && opt->output_format &&
-                           opt->output_format != DIFF_FORMAT_NO_OUTPUT)
-                               printf("%s%c", diff_line_prefix(opt),
-                                      opt->line_termination);
+                       diff_tree_sha1(parents->sha1[0], sha1, "", &diffopts);
+                       diffcore_std(&diffopts);
+                       if (opt->orderfile)
+                               diffcore_order(opt->orderfile);
+                       diff_flush(&diffopts);
                }
-
-               /* if showing diff, show it in requested order */
-               if (diffopts.output_format != DIFF_FORMAT_NO_OUTPUT &&
-                   opt->orderfile) {
-                       diffcore_order(opt->orderfile);
-               }
-
-               diff_flush(&diffopts);
        }
 
        /* find out number of surviving paths */
index cf36c3d71e3b8fc3382162ef939f3ed1f7d20775..a3ff0c9e60148e6dc98a6bd0d71d98cba4a7eae2 100644 (file)
@@ -132,6 +132,7 @@ git-update-server-info                  synchingrepositories
 git-upload-archive                      synchelpers
 git-upload-pack                         synchelpers
 git-var                                 plumbinginterrogators
+git-verify-commit                       ancillaryinterrogators
 git-verify-pack                         plumbinginterrogators
 git-verify-tag                          ancillaryinterrogators
 gitweb                                  ancillaryinterrogators
index cc114b53b096c6fc8574629b86659a639fdfed61..375c9c751adbf165c757832667102b761e1358c3 100644 (file)
@@ -117,4 +117,16 @@ static int stat_ ##slabname## realloc
  * catch because GCC silently parses it by default.
  */
 
+/*
+ * Statically initialize a commit slab named "var". Note that this
+ * evaluates "stride" multiple times! Example:
+ *
+ *   struct indegree indegrees = COMMIT_SLAB_INIT(1, indegrees);
+ *
+ */
+#define COMMIT_SLAB_INIT(stride, var) { \
+       COMMIT_SLAB_SIZE / sizeof(**((var).slab)) / (stride), \
+       (stride), 0, NULL \
+}
+
 #endif /* COMMIT_SLAB_H */
index f4793316a21fe5f3ee1932f7e24cf4ab0920b04c..acb74b55d4ee72ddf626754535a9febeb05ba945 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -17,7 +17,6 @@ static struct commit_extra_header *read_commit_extra_header_lines(const char *bu
 int save_commit_buffer = 1;
 
 const char *commit_type = "commit";
-static int commit_count;
 
 static struct commit *check_commit(struct object *obj,
                                   const unsigned char *sha1,
@@ -64,7 +63,6 @@ struct commit *lookup_commit(const unsigned char *sha1)
        struct object *obj = lookup_object(sha1);
        if (!obj) {
                struct commit *c = alloc_commit_node();
-               c->index = commit_count++;
                return create_object(sha1, OBJ_COMMIT, c);
        }
        if (!obj->type)
@@ -247,6 +245,76 @@ int unregister_shallow(const unsigned char *sha1)
        return 0;
 }
 
+struct commit_buffer {
+       void *buffer;
+       unsigned long size;
+};
+define_commit_slab(buffer_slab, struct commit_buffer);
+static struct buffer_slab buffer_slab = COMMIT_SLAB_INIT(1, buffer_slab);
+
+void set_commit_buffer(struct commit *commit, void *buffer, unsigned long size)
+{
+       struct commit_buffer *v = buffer_slab_at(&buffer_slab, commit);
+       v->buffer = buffer;
+       v->size = size;
+}
+
+const void *get_cached_commit_buffer(const struct commit *commit, unsigned long *sizep)
+{
+       struct commit_buffer *v = buffer_slab_at(&buffer_slab, commit);
+       if (sizep)
+               *sizep = v->size;
+       return v->buffer;
+}
+
+const void *get_commit_buffer(const struct commit *commit, unsigned long *sizep)
+{
+       const void *ret = get_cached_commit_buffer(commit, sizep);
+       if (!ret) {
+               enum object_type type;
+               unsigned long size;
+               ret = read_sha1_file(commit->object.sha1, &type, &size);
+               if (!ret)
+                       die("cannot read commit object %s",
+                           sha1_to_hex(commit->object.sha1));
+               if (type != OBJ_COMMIT)
+                       die("expected commit for %s, got %s",
+                           sha1_to_hex(commit->object.sha1), typename(type));
+               if (sizep)
+                       *sizep = size;
+       }
+       return ret;
+}
+
+void unuse_commit_buffer(const struct commit *commit, const void *buffer)
+{
+       struct commit_buffer *v = buffer_slab_at(&buffer_slab, commit);
+       if (v->buffer != buffer)
+               free((void *)buffer);
+}
+
+void free_commit_buffer(struct commit *commit)
+{
+       struct commit_buffer *v = buffer_slab_at(&buffer_slab, commit);
+       free(v->buffer);
+       v->buffer = NULL;
+       v->size = 0;
+}
+
+const void *detach_commit_buffer(struct commit *commit, unsigned long *sizep)
+{
+       struct commit_buffer *v = buffer_slab_at(&buffer_slab, commit);
+       void *ret;
+
+       ret = v->buffer;
+       if (sizep)
+               *sizep = v->size;
+
+       v->buffer = NULL;
+       v->size = 0;
+       return ret;
+}
+
 int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long size)
 {
        const char *tail = buffer;
@@ -324,7 +392,7 @@ int parse_commit(struct commit *item)
        }
        ret = parse_commit_buffer(item, buffer, size);
        if (save_commit_buffer && !ret) {
-               item->buffer = buffer;
+               set_commit_buffer(item, buffer, size);
                return 0;
        }
        free(buffer);
@@ -539,25 +607,14 @@ static void record_author_date(struct author_date_slab *author_date,
                               struct commit *commit)
 {
        const char *buf, *line_end, *ident_line;
-       char *buffer = NULL;
+       const char *buffer = get_commit_buffer(commit, NULL);
        struct ident_split ident;
        char *date_end;
        unsigned long date;
 
-       if (!commit->buffer) {
-               unsigned long size;
-               enum object_type type;
-               buffer = read_sha1_file(commit->object.sha1, &type, &size);
-               if (!buffer)
-                       return;
-       }
-
-       for (buf = commit->buffer ? commit->buffer : buffer;
-            buf;
-            buf = line_end + 1) {
+       for (buf = buffer; buf; buf = line_end + 1) {
                line_end = strchrnul(buf, '\n');
-               ident_line = skip_prefix(buf, "author ");
-               if (!ident_line) {
+               if (!skip_prefix(buf, "author ", &ident_line)) {
                        if (!line_end[0] || line_end[1] == '\n')
                                return; /* end of header */
                        continue;
@@ -575,7 +632,7 @@ static void record_author_date(struct author_date_slab *author_date,
        *(author_date_slab_at(author_date, commit)) = date;
 
 fail_exit:
-       free(buffer);
+       unuse_commit_buffer(commit, buffer);
 }
 
 static int compare_commits_by_author_date(const void *a_, const void *b_,
@@ -1031,7 +1088,7 @@ struct commit_list *reduce_heads(struct commit_list *heads)
                p->item->object.flags |= STALE;
                num_head++;
        }
-       array = xcalloc(sizeof(*array), num_head);
+       array = xcalloc(num_head, sizeof(*array));
        for (p = heads, i = 0; p; p = p->next) {
                if (p->item->object.flags & STALE) {
                        array[i++] = p->item;
@@ -1080,17 +1137,14 @@ static int do_sign_commit(struct strbuf *buf, const char *keyid)
        return 0;
 }
 
-int parse_signed_commit(const unsigned char *sha1,
+int parse_signed_commit(const struct commit *commit,
                        struct strbuf *payload, struct strbuf *signature)
 {
+
        unsigned long size;
-       enum object_type type;
-       char *buffer = read_sha1_file(sha1, &type, &size);
+       const char *buffer = get_commit_buffer(commit, &size);
        int in_signature, saw_signature = -1;
-       char *line, *tail;
-
-       if (!buffer || type != OBJ_COMMIT)
-               goto cleanup;
+       const char *line, *tail;
 
        line = buffer;
        tail = buffer + size;
@@ -1098,7 +1152,7 @@ int parse_signed_commit(const unsigned char *sha1,
        saw_signature = 0;
        while (line < tail) {
                const char *sig = NULL;
-               char *next = memchr(line, '\n', tail - line);
+               const char *next = memchr(line, '\n', tail - line);
 
                next = next ? next + 1 : tail;
                if (in_signature && line[0] == ' ')
@@ -1119,8 +1173,7 @@ int parse_signed_commit(const unsigned char *sha1,
                }
                line = next;
        }
- cleanup:
-       free(buffer);
+       unuse_commit_buffer(commit, buffer);
        return saw_signature;
 }
 
@@ -1183,8 +1236,7 @@ static void parse_gpg_output(struct signature_check *sigc)
        for (i = 0; i < ARRAY_SIZE(sigcheck_gpg_status); i++) {
                const char *found, *next;
 
-               found = skip_prefix(buf, sigcheck_gpg_status[i].check + 1);
-               if (!found) {
+               if (!skip_prefix(buf, sigcheck_gpg_status[i].check + 1, &found)) {
                        found = strstr(buf, sigcheck_gpg_status[i].check);
                        if (!found)
                                continue;
@@ -1211,14 +1263,14 @@ void check_commit_signature(const struct commit* commit, struct signature_check
 
        sigc->result = 'N';
 
-       if (parse_signed_commit(commit->object.sha1,
-                               &payload, &signature) <= 0)
+       if (parse_signed_commit(commit, &payload, &signature) <= 0)
                goto out;
        status = verify_signed_buffer(payload.buf, payload.len,
                                      signature.buf, signature.len,
                                      &gpg_output, &gpg_status);
        if (status && !gpg_output.len)
                goto out;
+       sigc->payload = strbuf_detach(&payload, NULL);
        sigc->gpg_output = strbuf_detach(&gpg_output, NULL);
        sigc->gpg_status = strbuf_detach(&gpg_status, NULL);
        parse_gpg_output(sigc);
@@ -1257,11 +1309,9 @@ struct commit_extra_header *read_commit_extra_headers(struct commit *commit,
 {
        struct commit_extra_header *extra = NULL;
        unsigned long size;
-       enum object_type type;
-       char *buffer = read_sha1_file(commit->object.sha1, &type, &size);
-       if (buffer && type == OBJ_COMMIT)
-               extra = read_commit_extra_header_lines(buffer, size, exclude);
-       free(buffer);
+       const char *buffer = get_commit_buffer(commit, &size);
+       extra = read_commit_extra_header_lines(buffer, size, exclude);
+       unuse_commit_buffer(commit, buffer);
        return extra;
 }
 
@@ -1344,7 +1394,8 @@ void free_commit_extra_headers(struct commit_extra_header *extra)
        }
 }
 
-int commit_tree(const struct strbuf *msg, const unsigned char *tree,
+int commit_tree(const char *msg, size_t msg_len,
+               const unsigned char *tree,
                struct commit_list *parents, unsigned char *ret,
                const char *author, const char *sign_commit)
 {
@@ -1352,7 +1403,7 @@ int commit_tree(const struct strbuf *msg, const unsigned char *tree,
        int result;
 
        append_merge_tag_headers(parents, &tail);
-       result = commit_tree_extended(msg, tree, parents, ret,
+       result = commit_tree_extended(msg, msg_len, tree, parents, ret,
                                      author, sign_commit, extra);
        free_commit_extra_headers(extra);
        return result;
@@ -1473,7 +1524,8 @@ static const char commit_utf8_warn[] =
 "You may want to amend it after fixing the message, or set the config\n"
 "variable i18n.commitencoding to the encoding your project uses.\n";
 
-int commit_tree_extended(const struct strbuf *msg, const unsigned char *tree,
+int commit_tree_extended(const char *msg, size_t msg_len,
+                        const unsigned char *tree,
                         struct commit_list *parents, unsigned char *ret,
                         const char *author, const char *sign_commit,
                         struct commit_extra_header *extra)
@@ -1484,7 +1536,7 @@ int commit_tree_extended(const struct strbuf *msg, const unsigned char *tree,
 
        assert_sha1_type(tree, OBJ_TREE);
 
-       if (memchr(msg->buf, '\0', msg->len))
+       if (memchr(msg, '\0', msg_len))
                return error("a NUL byte in commit log message not allowed.");
 
        /* Not having i18n.commitencoding is the same as having utf-8 */
@@ -1523,7 +1575,7 @@ int commit_tree_extended(const struct strbuf *msg, const unsigned char *tree,
        strbuf_addch(&buffer, '\n');
 
        /* And add the comment */
-       strbuf_addbuf(&buffer, msg);
+       strbuf_add(&buffer, msg, msg_len);
 
        /* And check the encoding */
        if (encoding_is_utf8 && !verify_utf8(&buffer))
index a9f177ba488a7002409eb2cdee1f7e9c3673529f..2e1492a6e4d1c5fc5bea3a48180f128601c3461e 100644 (file)
--- a/commit.h
+++ b/commit.h
@@ -20,7 +20,6 @@ struct commit {
        unsigned long date;
        struct commit_list *parents;
        struct tree *tree;
-       char *buffer;
 };
 
 extern int save_commit_buffer;
@@ -51,6 +50,44 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
 int parse_commit(struct commit *item);
 void parse_commit_or_die(struct commit *item);
 
+/*
+ * Associate an object buffer with the commit. The ownership of the
+ * memory is handed over to the commit, and must be free()-able.
+ */
+void set_commit_buffer(struct commit *, void *buffer, unsigned long size);
+
+/*
+ * Get any cached object buffer associated with the commit. Returns NULL
+ * if none. The resulting memory should not be freed.
+ */
+const void *get_cached_commit_buffer(const struct commit *, unsigned long *size);
+
+/*
+ * Get the commit's object contents, either from cache or by reading the object
+ * from disk. The resulting memory should not be modified, and must be given
+ * to unuse_commit_buffer when the caller is done.
+ */
+const void *get_commit_buffer(const struct commit *, unsigned long *size);
+
+/*
+ * Tell the commit subsytem that we are done with a particular commit buffer.
+ * The commit and buffer should be the input and return value, respectively,
+ * from an earlier call to get_commit_buffer.  The buffer may or may not be
+ * freed by this call; callers should not access the memory afterwards.
+ */
+void unuse_commit_buffer(const struct commit *, const void *buffer);
+
+/*
+ * Free any cached object buffer associated with the commit.
+ */
+void free_commit_buffer(struct commit *);
+
+/*
+ * Disassociate any cached object buffer from the commit, but do not free it.
+ * The buffer (or NULL, if none) is returned.
+ */
+const void *detach_commit_buffer(struct commit *, unsigned long *sizep);
+
 /* Find beginning and length of commit subject. */
 int find_commit_subject(const char *commit_buffer, const char **subject);
 
@@ -115,10 +152,9 @@ struct userformat_want {
 
 extern int has_non_ascii(const char *text);
 struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */
-extern char *logmsg_reencode(const struct commit *commit,
-                            char **commit_encoding,
-                            const char *output_encoding);
-extern void logmsg_free(char *msg, const struct commit *commit);
+extern const char *logmsg_reencode(const struct commit *commit,
+                                  char **commit_encoding,
+                                  const char *output_encoding);
 extern void get_commit_format(const char *arg, struct rev_info *);
 extern const char *format_subject(struct strbuf *sb, const char *msg,
                                  const char *line_separator);
@@ -261,11 +297,13 @@ struct commit_extra_header {
 extern void append_merge_tag_headers(struct commit_list *parents,
                                     struct commit_extra_header ***tail);
 
-extern int commit_tree(const struct strbuf *msg, const unsigned char *tree,
+extern int commit_tree(const char *msg, size_t msg_len,
+                      const unsigned char *tree,
                       struct commit_list *parents, unsigned char *ret,
                       const char *author, const char *sign_commit);
 
-extern int commit_tree_extended(const struct strbuf *msg, const unsigned char *tree,
+extern int commit_tree_extended(const char *msg, size_t msg_len,
+                               const unsigned char *tree,
                                struct commit_list *parents, unsigned char *ret,
                                const char *author, const char *sign_commit,
                                struct commit_extra_header *);
@@ -287,7 +325,7 @@ struct merge_remote_desc {
  */
 struct commit *get_merge_parent(const char *name);
 
-extern int parse_signed_commit(const unsigned char *sha1,
+extern int parse_signed_commit(const struct commit *commit,
                               struct strbuf *message, struct strbuf *signature);
 extern void print_commit_list(struct commit_list *list,
                              const char *format_cur,
index 120c6c1d3755963285651423cf4b5c791ae64be0..f6fd9a6a6cfdcd723cb5e04efc3af257977e5db5 100644 (file)
@@ -101,19 +101,34 @@ static inline uint64_t git_bswap64(uint64_t x)
 #undef ntohll
 #undef htonll
 
-#if !defined(__BYTE_ORDER)
-# if defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN)
-#  define __BYTE_ORDER BYTE_ORDER
-#  define __LITTLE_ENDIAN LITTLE_ENDIAN
-#  define __BIG_ENDIAN BIG_ENDIAN
+#if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && defined(__BIG_ENDIAN)
+
+# define GIT_BYTE_ORDER __BYTE_ORDER
+# define GIT_LITTLE_ENDIAN __LITTLE_ENDIAN
+# define GIT_BIG_ENDIAN __BIG_ENDIAN
+
+#elif defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN)
+
+# define GIT_BYTE_ORDER BYTE_ORDER
+# define GIT_LITTLE_ENDIAN LITTLE_ENDIAN
+# define GIT_BIG_ENDIAN BIG_ENDIAN
+
+#else
+
+# define GIT_BIG_ENDIAN 4321
+# define GIT_LITTLE_ENDIAN 1234
+
+# if defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)
+#  define GIT_BYTE_ORDER GIT_BIG_ENDIAN
+# elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)
+#  define GIT_BYTE_ORDER GIT_LITTLE_ENDIAN
+# else
+#  error "Cannot determine endianness"
 # endif
-#endif
 
-#if !defined(__BYTE_ORDER)
-# error "Cannot determine endianness"
 #endif
 
-#if __BYTE_ORDER == __BIG_ENDIAN
+#if GIT_BYTE_ORDER == GIT_BIG_ENDIAN
 # define ntohll(n) (n)
 # define htonll(n) (n)
 #else
index e9892f8ee48db4739321d37726cff63dec8c0f13..3baaa4dfaedd1e451f810a6bead28b2f7e9aa95d 100644 (file)
@@ -441,7 +441,7 @@ static int do_lstat(int follow, const char *file_name, struct stat *buf)
 static int do_stat_internal(int follow, const char *file_name, struct stat *buf)
 {
        int namelen;
-       static char alt_name[PATH_MAX];
+       char alt_name[PATH_MAX];
 
        if (!do_lstat(follow, file_name, buf))
                return 0;
@@ -831,9 +831,10 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
                              const char *dir,
                              int prepend_cmd, int fhin, int fhout, int fherr)
 {
-       STARTUPINFO si;
+       STARTUPINFOW si;
        PROCESS_INFORMATION pi;
        struct strbuf envblk, args;
+       wchar_t wcmd[MAX_PATH], wdir[MAX_PATH], *wargs;
        unsigned flags;
        BOOL ret;
 
@@ -865,9 +866,14 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
        memset(&si, 0, sizeof(si));
        si.cb = sizeof(si);
        si.dwFlags = STARTF_USESTDHANDLES;
-       si.hStdInput = (HANDLE) _get_osfhandle(fhin);
-       si.hStdOutput = (HANDLE) _get_osfhandle(fhout);
-       si.hStdError = (HANDLE) _get_osfhandle(fherr);
+       si.hStdInput = winansi_get_osfhandle(fhin);
+       si.hStdOutput = winansi_get_osfhandle(fhout);
+       si.hStdError = winansi_get_osfhandle(fherr);
+
+       if (xutftowcs_path(wcmd, cmd) < 0)
+               return -1;
+       if (dir && xutftowcs_path(wdir, dir) < 0)
+               return -1;
 
        /* concatenate argv, quoting args as we go */
        strbuf_init(&args, 0);
@@ -886,6 +892,10 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
                        free(quoted);
        }
 
+       wargs = xmalloc((2 * args.len + 1) * sizeof(wchar_t));
+       xutftowcs(wargs, args.buf, 2 * args.len + 1);
+       strbuf_release(&args);
+
        if (env) {
                int count = 0;
                char **e, **sorted_env;
@@ -907,12 +917,12 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
        }
 
        memset(&pi, 0, sizeof(pi));
-       ret = CreateProcess(cmd, args.buf, NULL, NULL, TRUE, flags,
-               env ? envblk.buf : NULL, dir, &si, &pi);
+       ret = CreateProcessW(wcmd, wargs, NULL, NULL, TRUE, flags,
+               env ? envblk.buf : NULL, dir ? wdir : NULL, &si, &pi);
 
        if (env)
                strbuf_release(&envblk);
-       strbuf_release(&args);
+       free(wargs);
 
        if (!ret) {
                errno = ENOENT;
@@ -941,10 +951,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
        return (pid_t)pi.dwProcessId;
 }
 
-static pid_t mingw_spawnve(const char *cmd, const char **argv, char **env,
-                          int prepend_cmd)
+static pid_t mingw_spawnv(const char *cmd, const char **argv, int prepend_cmd)
 {
-       return mingw_spawnve_fd(cmd, argv, env, NULL, prepend_cmd, 0, 1, 2);
+       return mingw_spawnve_fd(cmd, argv, environ, NULL, prepend_cmd, 0, 1, 2);
 }
 
 pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **env,
@@ -986,7 +995,7 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **env,
        return pid;
 }
 
-static int try_shell_exec(const char *cmd, char *const *argv, char **env)
+static int try_shell_exec(const char *cmd, char *const *argv)
 {
        const char *interpr = parse_interpreter(cmd);
        char **path;
@@ -1004,7 +1013,7 @@ static int try_shell_exec(const char *cmd, char *const *argv, char **env)
                argv2 = xmalloc(sizeof(*argv) * (argc+1));
                argv2[0] = (char *)cmd; /* full path to the script file */
                memcpy(&argv2[1], &argv[1], sizeof(*argv) * argc);
-               pid = mingw_spawnve(prog, argv2, env, 1);
+               pid = mingw_spawnv(prog, argv2, 1);
                if (pid >= 0) {
                        int status;
                        if (waitpid(pid, &status, 0) < 0)
@@ -1019,19 +1028,20 @@ static int try_shell_exec(const char *cmd, char *const *argv, char **env)
        return pid;
 }
 
-static void mingw_execve(const char *cmd, char *const *argv, char *const *env)
+int mingw_execv(const char *cmd, char *const *argv)
 {
        /* check if git_command is a shell script */
-       if (!try_shell_exec(cmd, argv, (char **)env)) {
+       if (!try_shell_exec(cmd, argv)) {
                int pid, status;
 
-               pid = mingw_spawnve(cmd, (const char **)argv, (char **)env, 0);
+               pid = mingw_spawnv(cmd, (const char **)argv, 0);
                if (pid < 0)
-                       return;
+                       return -1;
                if (waitpid(pid, &status, 0) < 0)
                        status = 255;
                exit(status);
        }
+       return -1;
 }
 
 int mingw_execvp(const char *cmd, char *const *argv)
@@ -1040,7 +1050,7 @@ int mingw_execvp(const char *cmd, char *const *argv)
        char *prog = path_lookup(cmd, path, 0);
 
        if (prog) {
-               mingw_execve(prog, argv, environ);
+               mingw_execv(prog, argv);
                free(prog);
        } else
                errno = ENOENT;
@@ -1049,12 +1059,6 @@ int mingw_execvp(const char *cmd, char *const *argv)
        return -1;
 }
 
-int mingw_execv(const char *cmd, char *const *argv)
-{
-       mingw_execve(cmd, argv, environ);
-       return -1;
-}
-
 int mingw_kill(pid_t pid, int sig)
 {
        if (pid > 0 && sig == SIGTERM) {
@@ -1823,3 +1827,174 @@ pid_t waitpid(pid_t pid, int *status, int options)
        errno = EINVAL;
        return -1;
 }
+
+int mingw_offset_1st_component(const char *path)
+{
+       int offset = 0;
+       if (has_dos_drive_prefix(path))
+               offset = 2;
+
+       /* unc paths */
+       else if (is_dir_sep(path[0]) && is_dir_sep(path[1])) {
+
+               /* skip server name */
+               char *pos = strpbrk(path + 2, "\\/");
+               if (!pos)
+                       return 0; /* Error: malformed unc path */
+
+               do {
+                       pos++;
+               } while (*pos && !is_dir_sep(*pos));
+
+               offset = pos - path;
+       }
+
+       return offset + is_dir_sep(path[offset]);
+}
+
+int xutftowcsn(wchar_t *wcs, const char *utfs, size_t wcslen, int utflen)
+{
+       int upos = 0, wpos = 0;
+       const unsigned char *utf = (const unsigned char*) utfs;
+       if (!utf || !wcs || wcslen < 1) {
+               errno = EINVAL;
+               return -1;
+       }
+       /* reserve space for \0 */
+       wcslen--;
+       if (utflen < 0)
+               utflen = INT_MAX;
+
+       while (upos < utflen) {
+               int c = utf[upos++] & 0xff;
+               if (utflen == INT_MAX && c == 0)
+                       break;
+
+               if (wpos >= wcslen) {
+                       wcs[wpos] = 0;
+                       errno = ERANGE;
+                       return -1;
+               }
+
+               if (c < 0x80) {
+                       /* ASCII */
+                       wcs[wpos++] = c;
+               } else if (c >= 0xc2 && c < 0xe0 && upos < utflen &&
+                               (utf[upos] & 0xc0) == 0x80) {
+                       /* 2-byte utf-8 */
+                       c = ((c & 0x1f) << 6);
+                       c |= (utf[upos++] & 0x3f);
+                       wcs[wpos++] = c;
+               } else if (c >= 0xe0 && c < 0xf0 && upos + 1 < utflen &&
+                               !(c == 0xe0 && utf[upos] < 0xa0) && /* over-long encoding */
+                               (utf[upos] & 0xc0) == 0x80 &&
+                               (utf[upos + 1] & 0xc0) == 0x80) {
+                       /* 3-byte utf-8 */
+                       c = ((c & 0x0f) << 12);
+                       c |= ((utf[upos++] & 0x3f) << 6);
+                       c |= (utf[upos++] & 0x3f);
+                       wcs[wpos++] = c;
+               } else if (c >= 0xf0 && c < 0xf5 && upos + 2 < utflen &&
+                               wpos + 1 < wcslen &&
+                               !(c == 0xf0 && utf[upos] < 0x90) && /* over-long encoding */
+                               !(c == 0xf4 && utf[upos] >= 0x90) && /* > \u10ffff */
+                               (utf[upos] & 0xc0) == 0x80 &&
+                               (utf[upos + 1] & 0xc0) == 0x80 &&
+                               (utf[upos + 2] & 0xc0) == 0x80) {
+                       /* 4-byte utf-8: convert to \ud8xx \udcxx surrogate pair */
+                       c = ((c & 0x07) << 18);
+                       c |= ((utf[upos++] & 0x3f) << 12);
+                       c |= ((utf[upos++] & 0x3f) << 6);
+                       c |= (utf[upos++] & 0x3f);
+                       c -= 0x10000;
+                       wcs[wpos++] = 0xd800 | (c >> 10);
+                       wcs[wpos++] = 0xdc00 | (c & 0x3ff);
+               } else if (c >= 0xa0) {
+                       /* invalid utf-8 byte, printable unicode char: convert 1:1 */
+                       wcs[wpos++] = c;
+               } else {
+                       /* invalid utf-8 byte, non-printable unicode: convert to hex */
+                       static const char *hex = "0123456789abcdef";
+                       wcs[wpos++] = hex[c >> 4];
+                       if (wpos < wcslen)
+                               wcs[wpos++] = hex[c & 0x0f];
+               }
+       }
+       wcs[wpos] = 0;
+       return wpos;
+}
+
+int xwcstoutf(char *utf, const wchar_t *wcs, size_t utflen)
+{
+       if (!wcs || !utf || utflen < 1) {
+               errno = EINVAL;
+               return -1;
+       }
+       utflen = WideCharToMultiByte(CP_UTF8, 0, wcs, -1, utf, utflen, NULL, NULL);
+       if (utflen)
+               return utflen - 1;
+       errno = ERANGE;
+       return -1;
+}
+
+/*
+ * Disable MSVCRT command line wildcard expansion (__getmainargs called from
+ * mingw startup code, see init.c in mingw runtime).
+ */
+int _CRT_glob = 0;
+
+typedef struct {
+       int newmode;
+} _startupinfo;
+
+extern int __wgetmainargs(int *argc, wchar_t ***argv, wchar_t ***env, int glob,
+               _startupinfo *si);
+
+static NORETURN void die_startup()
+{
+       fputs("fatal: not enough memory for initialization", stderr);
+       exit(128);
+}
+
+void mingw_startup()
+{
+       int i, len, maxlen, argc;
+       char *buffer;
+       wchar_t **wenv, **wargv;
+       _startupinfo si;
+
+       /* get wide char arguments and environment */
+       si.newmode = 0;
+       if (__wgetmainargs(&argc, &wargv, &wenv, _CRT_glob, &si) < 0)
+               die_startup();
+
+       /* determine size of argv and environ conversion buffer */
+       maxlen = wcslen(_wpgmptr);
+       for (i = 1; i < argc; i++)
+               maxlen = max(maxlen, wcslen(wargv[i]));
+
+       /* allocate buffer (wchar_t encodes to max 3 UTF-8 bytes) */
+       maxlen = 3 * maxlen + 1;
+       buffer = xmalloc(maxlen);
+
+       /* convert command line arguments and environment to UTF-8 */
+       len = xwcstoutf(buffer, _wpgmptr, maxlen);
+       __argv[0] = xmemdupz(buffer, len);
+       for (i = 1; i < argc; i++) {
+               len = xwcstoutf(buffer, wargv[i], maxlen);
+               __argv[i] = xmemdupz(buffer, len);
+       }
+       free(buffer);
+
+       /* initialize critical section for waitpid pinfo_t list */
+       InitializeCriticalSection(&pinfo_cs);
+
+       /* set up default file mode and file modes for stdin/out/err */
+       _fmode = _O_BINARY;
+       _setmode(_fileno(stdin), _O_BINARY);
+       _setmode(_fileno(stdout), _O_BINARY);
+       _setmode(_fileno(stderr), _O_BINARY);
+
+       /* initialize Unicode console */
+       winansi_init();
+}
index e033e720c900c430a0a74b0223522c396cb66629..7ff2376335dea7a092c626f74f52413be1c81e74 100644 (file)
@@ -35,6 +35,9 @@ typedef int socklen_t;
 #ifndef EWOULDBLOCK
 #define EWOULDBLOCK EAGAIN
 #endif
+#ifndef ELOOP
+#define ELOOP EMLINK
+#endif
 #define SHUT_WR SD_SEND
 
 #define SIGHUP 1
@@ -317,12 +320,8 @@ int mingw_raise(int sig);
  * ANSI emulation wrappers
  */
 
-int winansi_fputs(const char *str, FILE *stream);
-int winansi_printf(const char *format, ...) __attribute__((format (printf, 1, 2)));
-int winansi_fprintf(FILE *stream, const char *format, ...) __attribute__((format (printf, 2, 3)));
-#define fputs winansi_fputs
-#define printf(...) winansi_printf(__VA_ARGS__)
-#define fprintf(...) winansi_fprintf(__VA_ARGS__)
+void winansi_init(void);
+HANDLE winansi_get_osfhandle(int fd);
 
 /*
  * git specific compatibility
@@ -339,6 +338,8 @@ static inline char *mingw_find_last_dir_sep(const char *path)
        return ret;
 }
 #define find_last_dir_sep mingw_find_last_dir_sep
+int mingw_offset_1st_component(const char *path);
+#define offset_1st_component mingw_offset_1st_component
 #define PATH_SEP ';'
 #define PRIuMAX "I64u"
 #define PRId64 "I64d"
@@ -353,6 +354,110 @@ void mingw_open_html(const char *path);
 char **make_augmented_environ(const char *const *vars);
 void free_environ(char **env);
 
+/**
+ * Converts UTF-8 encoded string to UTF-16LE.
+ *
+ * To support repositories with legacy-encoded file names, invalid UTF-8 bytes
+ * 0xa0 - 0xff are converted to corresponding printable Unicode chars \u00a0 -
+ * \u00ff, and invalid UTF-8 bytes 0x80 - 0x9f (which would make non-printable
+ * Unicode) are converted to hex-code.
+ *
+ * Lead-bytes not followed by an appropriate number of trail-bytes, over-long
+ * encodings and 4-byte encodings > \u10ffff are detected as invalid UTF-8.
+ *
+ * Maximum space requirement for the target buffer is two wide chars per UTF-8
+ * char (((strlen(utf) * 2) + 1) [* sizeof(wchar_t)]).
+ *
+ * The maximum space is needed only if the entire input string consists of
+ * invalid UTF-8 bytes in range 0x80-0x9f, as per the following table:
+ *
+ *               |                   | UTF-8 | UTF-16 |
+ *   Code point  |  UTF-8 sequence   | bytes | words  | ratio
+ * --------------+-------------------+-------+--------+-------
+ * 000000-00007f | 0-7f              |   1   |   1    |  1
+ * 000080-0007ff | c2-df + 80-bf     |   2   |   1    |  0.5
+ * 000800-00ffff | e0-ef + 2 * 80-bf |   3   |   1    |  0.33
+ * 010000-10ffff | f0-f4 + 3 * 80-bf |   4   |  2 (a) |  0.5
+ * invalid       | 80-9f             |   1   |  2 (b) |  2
+ * invalid       | a0-ff             |   1   |   1    |  1
+ *
+ * (a) encoded as UTF-16 surrogate pair
+ * (b) encoded as two hex digits
+ *
+ * Note that, while the UTF-8 encoding scheme can be extended to 5-byte, 6-byte
+ * or even indefinite-byte sequences, the largest valid code point \u10ffff
+ * encodes as only 4 UTF-8 bytes.
+ *
+ * Parameters:
+ * wcs: wide char target buffer
+ * utf: string to convert
+ * wcslen: size of target buffer (in wchar_t's)
+ * utflen: size of string to convert, or -1 if 0-terminated
+ *
+ * Returns:
+ * length of converted string (_wcslen(wcs)), or -1 on failure
+ *
+ * Errors:
+ * EINVAL: one of the input parameters is invalid (e.g. NULL)
+ * ERANGE: the output buffer is too small
+ */
+int xutftowcsn(wchar_t *wcs, const char *utf, size_t wcslen, int utflen);
+
+/**
+ * Simplified variant of xutftowcsn, assumes input string is \0-terminated.
+ */
+static inline int xutftowcs(wchar_t *wcs, const char *utf, size_t wcslen)
+{
+       return xutftowcsn(wcs, utf, wcslen, -1);
+}
+
+/**
+ * Simplified file system specific variant of xutftowcsn, assumes output
+ * buffer size is MAX_PATH wide chars and input string is \0-terminated,
+ * fails with ENAMETOOLONG if input string is too long.
+ */
+static inline int xutftowcs_path(wchar_t *wcs, const char *utf)
+{
+       int result = xutftowcsn(wcs, utf, MAX_PATH, -1);
+       if (result < 0 && errno == ERANGE)
+               errno = ENAMETOOLONG;
+       return result;
+}
+
+/**
+ * Converts UTF-16LE encoded string to UTF-8.
+ *
+ * Maximum space requirement for the target buffer is three UTF-8 chars per
+ * wide char ((_wcslen(wcs) * 3) + 1).
+ *
+ * The maximum space is needed only if the entire input string consists of
+ * UTF-16 words in range 0x0800-0xd7ff or 0xe000-0xffff (i.e. \u0800-\uffff
+ * modulo surrogate pairs), as per the following table:
+ *
+ *               |                       | UTF-16 | UTF-8 |
+ *   Code point  |  UTF-16 sequence      | words  | bytes | ratio
+ * --------------+-----------------------+--------+-------+-------
+ * 000000-00007f | 0000-007f             |   1    |   1   |  1
+ * 000080-0007ff | 0080-07ff             |   1    |   2   |  2
+ * 000800-00ffff | 0800-d7ff / e000-ffff |   1    |   3   |  3
+ * 010000-10ffff | d800-dbff + dc00-dfff |   2    |   4   |  2
+ *
+ * Note that invalid code points > 10ffff cannot be represented in UTF-16.
+ *
+ * Parameters:
+ * utf: target buffer
+ * wcs: wide string to convert
+ * utflen: size of target buffer
+ *
+ * Returns:
+ * length of converted string, or -1 on failure
+ *
+ * Errors:
+ * EINVAL: one of the input parameters is invalid (e.g. NULL)
+ * ERANGE: the output buffer is too small
+ */
+int xwcstoutf(char *utf, const wchar_t *wcs, size_t utflen);
+
 /*
  * A critical section used in the implementation of the spawn
  * functions (mingw_spawnv[p]e()) and waitpid(). Intialised in
@@ -361,22 +466,16 @@ void free_environ(char **env);
 extern CRITICAL_SECTION pinfo_cs;
 
 /*
- * A replacement of main() that ensures that argv[0] has a path
- * and that default fmode and std(in|out|err) are in binary mode
+ * A replacement of main() that adds win32 specific initialization.
  */
 
+void mingw_startup();
 #define main(c,v) dummy_decl_mingw_main(); \
 static int mingw_main(c,v); \
 int main(int argc, char **argv) \
 { \
-       extern CRITICAL_SECTION pinfo_cs; \
-       _fmode = _O_BINARY; \
-       _setmode(_fileno(stdin), _O_BINARY); \
-       _setmode(_fileno(stdout), _O_BINARY); \
-       _setmode(_fileno(stderr), _O_BINARY); \
-       argv[0] = xstrdup(_pgmptr); \
-       InitializeCriticalSection(&pinfo_cs); \
-       return mingw_main(argc, argv); \
+       mingw_startup(); \
+       return mingw_main(__argc, (void *)__argv); \
 } \
 static int mingw_main(c,v)
 
index 31163f2ae7b71857889f561dea0b3ffecff61989..a9b41d89f465208b6f0e417672077403bf30898f 100644 (file)
@@ -605,7 +605,7 @@ restart:
 
   if (!rc && timeout == INFTIM)
     {
-      SwitchToThread();
+      SleepEx (1, TRUE);
       goto restart;
     }
 
index 7a0debe51bcad9f8d46c9c675aa3a6bbaaf7f537..82a515c21b322a0e50c7b5dbdd12e74341b20e98 100644 (file)
@@ -1,96 +1,91 @@
-#include "../git-compat-util.h"
-#include "dirent.h"
+#include "../../git-compat-util.h"
 
 struct DIR {
        struct dirent dd_dir; /* includes d_type */
        HANDLE dd_handle;     /* FindFirstFile handle */
        int dd_stat;          /* 0-based index */
-       char dd_name[1];      /* extend struct */
 };
 
+static inline void finddata2dirent(struct dirent *ent, WIN32_FIND_DATAA *fdata)
+{
+       /* copy file name from WIN32_FIND_DATA to dirent */
+       memcpy(ent->d_name, fdata->cFileName, sizeof(ent->d_name));
+
+       /* Set file type, based on WIN32_FIND_DATA */
+       if (fdata->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+               ent->d_type = DT_DIR;
+       else
+               ent->d_type = DT_REG;
+}
+
 DIR *opendir(const char *name)
 {
-       DWORD attrs = GetFileAttributesA(name);
+       char pattern[MAX_PATH];
+       WIN32_FIND_DATAA fdata;
+       HANDLE h;
        int len;
-       DIR *p;
+       DIR *dir;
 
-       /* check for valid path */
-       if (attrs == INVALID_FILE_ATTRIBUTES) {
-               errno = ENOENT;
+       /* check that name is not NULL */
+       if (!name) {
+               errno = EINVAL;
                return NULL;
        }
-
-       /* check if it's a directory */
-       if (!(attrs & FILE_ATTRIBUTE_DIRECTORY)) {
-               errno = ENOTDIR;
-               return NULL;
-       }
-
        /* check that the pattern won't be too long for FindFirstFileA */
        len = strlen(name);
-       if (is_dir_sep(name[len - 1]))
-               len--;
        if (len + 2 >= MAX_PATH) {
                errno = ENAMETOOLONG;
                return NULL;
        }
-
-       p = malloc(sizeof(DIR) + len + 2);
-       if (!p)
+       /* copy name to temp buffer */
+       memcpy(pattern, name, len + 1);
+
+       /* append optional '/' and wildcard '*' */
+       if (len && !is_dir_sep(pattern[len - 1]))
+               pattern[len++] = '/';
+       pattern[len++] = '*';
+       pattern[len] = 0;
+
+       /* open find handle */
+       h = FindFirstFileA(pattern, &fdata);
+       if (h == INVALID_HANDLE_VALUE) {
+               DWORD err = GetLastError();
+               errno = (err == ERROR_DIRECTORY) ? ENOTDIR : err_win_to_posix(err);
                return NULL;
+       }
 
-       memset(p, 0, sizeof(DIR) + len + 2);
-       strcpy(p->dd_name, name);
-       p->dd_name[len] = '/';
-       p->dd_name[len+1] = '*';
-
-       p->dd_handle = INVALID_HANDLE_VALUE;
-       return p;
+       /* initialize DIR structure and copy first dir entry */
+       dir = xmalloc(sizeof(DIR));
+       dir->dd_handle = h;
+       dir->dd_stat = 0;
+       finddata2dirent(&dir->dd_dir, &fdata);
+       return dir;
 }
 
 struct dirent *readdir(DIR *dir)
 {
-       WIN32_FIND_DATAA buf;
-       HANDLE handle;
-
-       if (!dir || !dir->dd_handle) {
+       if (!dir) {
                errno = EBADF; /* No set_errno for mingw */
                return NULL;
        }
 
-       if (dir->dd_handle == INVALID_HANDLE_VALUE && dir->dd_stat == 0) {
-               DWORD lasterr;
-               handle = FindFirstFileA(dir->dd_name, &buf);
-               lasterr = GetLastError();
-               dir->dd_handle = handle;
-               if (handle == INVALID_HANDLE_VALUE && (lasterr != ERROR_NO_MORE_FILES)) {
-                       errno = err_win_to_posix(lasterr);
+       /* if first entry, dirent has already been set up by opendir */
+       if (dir->dd_stat) {
+               /* get next entry and convert from WIN32_FIND_DATA to dirent */
+               WIN32_FIND_DATAA fdata;
+               if (FindNextFileA(dir->dd_handle, &fdata)) {
+                       finddata2dirent(&dir->dd_dir, &fdata);
+               } else {
+                       DWORD lasterr = GetLastError();
+                       /* POSIX says you shouldn't set errno when readdir can't
+                          find any more files; so, if another error we leave it set. */
+                       if (lasterr != ERROR_NO_MORE_FILES)
+                               errno = err_win_to_posix(lasterr);
                        return NULL;
                }
-       } else if (dir->dd_handle == INVALID_HANDLE_VALUE) {
-               return NULL;
-       } else if (!FindNextFileA(dir->dd_handle, &buf)) {
-               DWORD lasterr = GetLastError();
-               FindClose(dir->dd_handle);
-               dir->dd_handle = INVALID_HANDLE_VALUE;
-               /* POSIX says you shouldn't set errno when readdir can't
-                  find any more files; so, if another error we leave it set. */
-               if (lasterr != ERROR_NO_MORE_FILES)
-                       errno = err_win_to_posix(lasterr);
-               return NULL;
        }
 
-       /* We get here if `buf' contains valid data.  */
-       strcpy(dir->dd_dir.d_name, buf.cFileName);
        ++dir->dd_stat;
-
-       /* Set file type, based on WIN32_FIND_DATA */
-       dir->dd_dir.d_type = 0;
-       if (buf.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
-               dir->dd_dir.d_type |= DT_DIR;
-       else
-               dir->dd_dir.d_type |= DT_REG;
-
        return &dir->dd_dir;
 }
 
@@ -101,8 +96,7 @@ int closedir(DIR *dir)
                return -1;
        }
 
-       if (dir->dd_handle != INVALID_HANDLE_VALUE)
-               FindClose(dir->dd_handle);
+       FindClose(dir->dd_handle);
        free(dir);
        return 0;
 }
index 927a25ca765ef4f393ba28d54e2478b29fca878e..8838cd61fc282b3713db76e088130f82b6c6fe33 100644 (file)
@@ -9,12 +9,8 @@ typedef struct DIR DIR;
 #define DT_LNK     3
 
 struct dirent {
-       long d_ino;                      /* Always zero. */
-       char d_name[FILENAME_MAX];       /* File name. */
-       union {
-               unsigned short d_reclen; /* Always zero. */
-               unsigned char  d_type;   /* Reimplementation adds this */
-       };
+       unsigned char d_type;      /* file type to prevent lstat after readdir */
+       char d_name[MAX_PATH];     /* file name */
 };
 
 DIR *opendir(const char *dirname);
index dedce2104eaf5cefbb1abef1b7921eb99c67a75e..efc5bb3a4b63166eccb33f6ec6a8ad57e4c9ac36 100644 (file)
@@ -2,15 +2,10 @@
  * Copyright 2008 Peter Harris <git@peter.is-a-geek.org>
  */
 
+#undef NOGDI
 #include "../git-compat-util.h"
-
-/*
- Functions to be wrapped:
-*/
-#undef printf
-#undef fprintf
-#undef fputs
-/* TODO: write */
+#include <wingdi.h>
+#include <winreg.h>
 
 /*
  ANSI codes used by git: m, K
@@ -23,29 +18,114 @@ static HANDLE console;
 static WORD plain_attr;
 static WORD attr;
 static int negative;
+static int non_ascii_used = 0;
+static HANDLE hthread, hread, hwrite;
+static HANDLE hconsole1, hconsole2;
+
+#ifdef __MINGW32__
+typedef struct _CONSOLE_FONT_INFOEX {
+       ULONG cbSize;
+       DWORD nFont;
+       COORD dwFontSize;
+       UINT FontFamily;
+       UINT FontWeight;
+       WCHAR FaceName[LF_FACESIZE];
+} CONSOLE_FONT_INFOEX, *PCONSOLE_FONT_INFOEX;
+#endif
+
+typedef BOOL (WINAPI *PGETCURRENTCONSOLEFONTEX)(HANDLE, BOOL,
+               PCONSOLE_FONT_INFOEX);
+
+static void warn_if_raster_font(void)
+{
+       DWORD fontFamily = 0;
+       PGETCURRENTCONSOLEFONTEX pGetCurrentConsoleFontEx;
+
+       /* don't bother if output was ascii only */
+       if (!non_ascii_used)
+               return;
+
+       /* GetCurrentConsoleFontEx is available since Vista */
+       pGetCurrentConsoleFontEx = (PGETCURRENTCONSOLEFONTEX) GetProcAddress(
+                       GetModuleHandle("kernel32.dll"),
+                       "GetCurrentConsoleFontEx");
+       if (pGetCurrentConsoleFontEx) {
+               CONSOLE_FONT_INFOEX cfi;
+               cfi.cbSize = sizeof(cfi);
+               if (pGetCurrentConsoleFontEx(console, 0, &cfi))
+                       fontFamily = cfi.FontFamily;
+       } else {
+               /* pre-Vista: check default console font in registry */
+               HKEY hkey;
+               if (ERROR_SUCCESS == RegOpenKeyExA(HKEY_CURRENT_USER, "Console",
+                               0, KEY_READ, &hkey)) {
+                       DWORD size = sizeof(fontFamily);
+                       RegQueryValueExA(hkey, "FontFamily", NULL, NULL,
+                                       (LPVOID) &fontFamily, &size);
+                       RegCloseKey(hkey);
+               }
+       }
+
+       if (!(fontFamily & TMPF_TRUETYPE)) {
+               const wchar_t *msg = L"\nWarning: Your console font probably "
+                       L"doesn\'t support Unicode. If you experience strange "
+                       L"characters in the output, consider switching to a "
+                       L"TrueType font such as Consolas!\n";
+               DWORD dummy;
+               WriteConsoleW(console, msg, wcslen(msg), &dummy, NULL);
+       }
+}
 
-static void init(void)
+static int is_console(int fd)
 {
        CONSOLE_SCREEN_BUFFER_INFO sbi;
+       HANDLE hcon;
 
        static int initialized = 0;
-       if (initialized)
-               return;
 
-       console = GetStdHandle(STD_OUTPUT_HANDLE);
-       if (console == INVALID_HANDLE_VALUE)
-               console = NULL;
+       /* get OS handle of the file descriptor */
+       hcon = (HANDLE) _get_osfhandle(fd);
+       if (hcon == INVALID_HANDLE_VALUE)
+               return 0;
 
-       if (!console)
-               return;
+       /* check if its a device (i.e. console, printer, serial port) */
+       if (GetFileType(hcon) != FILE_TYPE_CHAR)
+               return 0;
 
-       GetConsoleScreenBufferInfo(console, &sbi);
-       attr = plain_attr = sbi.wAttributes;
-       negative = 0;
+       /* check if its a handle to a console output screen buffer */
+       if (!GetConsoleScreenBufferInfo(hcon, &sbi))
+               return 0;
+
+       /* initialize attributes */
+       if (!initialized) {
+               console = hcon;
+               attr = plain_attr = sbi.wAttributes;
+               negative = 0;
+               initialized = 1;
+       }
 
-       initialized = 1;
+       return 1;
 }
 
+#define BUFFER_SIZE 4096
+#define MAX_PARAMS 16
+
+static void write_console(unsigned char *str, size_t len)
+{
+       /* only called from console_thread, so a static buffer will do */
+       static wchar_t wbuf[2 * BUFFER_SIZE + 1];
+       DWORD dummy;
+
+       /* convert utf-8 to utf-16 */
+       int wlen = xutftowcsn(wbuf, (char*) str, ARRAY_SIZE(wbuf), len);
+
+       /* write directly to console */
+       WriteConsoleW(console, wbuf, wlen, &dummy, NULL);
+
+       /* remember if non-ascii characters are printed */
+       if (wlen != len)
+               non_ascii_used = 1;
+}
 
 #define FOREGROUND_ALL (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE)
 #define BACKGROUND_ALL (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE)
@@ -90,18 +170,13 @@ static void erase_in_line(void)
                &dummy);
 }
 
-
-static const char *set_attr(const char *str)
+static void set_attr(char func, const int *params, int paramlen)
 {
-       const char *func;
-       size_t len = strspn(str, "0123456789;");
-       func = str + len;
-
-       switch (*func) {
+       int i;
+       switch (func) {
        case 'm':
-               do {
-                       long val = strtol(str, (char **)&str, 10);
-                       switch (val) {
+               for (i = 0; i < paramlen; i++) {
+                       switch (params[i]) {
                        case 0: /* reset */
                                attr = plain_attr;
                                negative = 0;
@@ -224,9 +299,7 @@ static const char *set_attr(const char *str)
                                /* Unsupported code */
                                break;
                        }
-                       str++;
-               } while (*(str-1) == ';');
-
+               }
                set_console_attr();
                break;
        case 'K':
@@ -236,122 +309,271 @@ static const char *set_attr(const char *str)
                /* Unsupported code */
                break;
        }
-
-       return func + 1;
 }
 
-static int ansi_emulate(const char *str, FILE *stream)
+enum {
+       TEXT = 0, ESCAPE = 033, BRACKET = '['
+};
+
+static DWORD WINAPI console_thread(LPVOID unused)
 {
-       int rv = 0;
-       const char *pos = str;
-
-       while (*pos) {
-               pos = strstr(str, "\033[");
-               if (pos) {
-                       size_t len = pos - str;
-
-                       if (len) {
-                               size_t out_len = fwrite(str, 1, len, stream);
-                               rv += out_len;
-                               if (out_len < len)
-                                       return rv;
+       unsigned char buffer[BUFFER_SIZE];
+       DWORD bytes;
+       int start, end = 0, c, parampos = 0, state = TEXT;
+       int params[MAX_PARAMS];
+
+       while (1) {
+               /* read next chunk of bytes from the pipe */
+               if (!ReadFile(hread, buffer + end, BUFFER_SIZE - end, &bytes,
+                               NULL)) {
+                       /* exit if pipe has been closed or disconnected */
+                       if (GetLastError() == ERROR_PIPE_NOT_CONNECTED ||
+                                       GetLastError() == ERROR_BROKEN_PIPE)
+                               break;
+                       /* ignore other errors */
+                       continue;
+               }
+
+               /* scan the bytes and handle ANSI control codes */
+               bytes += end;
+               start = end = 0;
+               while (end < bytes) {
+                       c = buffer[end++];
+                       switch (state) {
+                       case TEXT:
+                               if (c == ESCAPE) {
+                                       /* print text seen so far */
+                                       if (end - 1 > start)
+                                               write_console(buffer + start,
+                                                       end - 1 - start);
+
+                                       /* then start parsing escape sequence */
+                                       start = end - 1;
+                                       memset(params, 0, sizeof(params));
+                                       parampos = 0;
+                                       state = ESCAPE;
+                               }
+                               break;
+
+                       case ESCAPE:
+                               /* continue if "\033[", otherwise bail out */
+                               state = (c == BRACKET) ? BRACKET : TEXT;
+                               break;
+
+                       case BRACKET:
+                               /* parse [0-9;]* into array of parameters */
+                               if (c >= '0' && c <= '9') {
+                                       params[parampos] *= 10;
+                                       params[parampos] += c - '0';
+                               } else if (c == ';') {
+                                       /*
+                                        * next parameter, bail out if out of
+                                        * bounds
+                                        */
+                                       parampos++;
+                                       if (parampos >= MAX_PARAMS)
+                                               state = TEXT;
+                               } else {
+                                       /*
+                                        * end of escape sequence, change
+                                        * console attributes
+                                        */
+                                       set_attr(c, params, parampos + 1);
+                                       start = end;
+                                       state = TEXT;
+                               }
+                               break;
                        }
+               }
 
-                       str = pos + 2;
-                       rv += 2;
+               /* print remaining text unless parsing an escape sequence */
+               if (state == TEXT && end > start) {
+                       /* check for incomplete UTF-8 sequences and fix end */
+                       if (buffer[end - 1] >= 0x80) {
+                               if (buffer[end -1] >= 0xc0)
+                                       end--;
+                               else if (end - 1 > start &&
+                                               buffer[end - 2] >= 0xe0)
+                                       end -= 2;
+                               else if (end - 2 > start &&
+                                               buffer[end - 3] >= 0xf0)
+                                       end -= 3;
+                       }
 
-                       fflush(stream);
+                       /* print remaining complete UTF-8 sequences */
+                       if (end > start)
+                               write_console(buffer + start, end - start);
 
-                       pos = set_attr(str);
-                       rv += pos - str;
-                       str = pos;
+                       /* move remaining bytes to the front */
+                       if (end < bytes)
+                               memmove(buffer, buffer + end, bytes - end);
+                       end = bytes - end;
                } else {
-                       rv += strlen(str);
-                       fputs(str, stream);
-                       return rv;
+                       /* all data has been consumed, mark buffer empty */
+                       end = 0;
                }
        }
-       return rv;
+
+       /* check if the console font supports unicode */
+       warn_if_raster_font();
+
+       CloseHandle(hread);
+       return 0;
 }
 
-int winansi_fputs(const char *str, FILE *stream)
+static void winansi_exit(void)
 {
-       int rv;
-
-       if (!isatty(fileno(stream)))
-               return fputs(str, stream);
+       /* flush all streams */
+       _flushall();
 
-       init();
+       /* signal console thread to exit */
+       FlushFileBuffers(hwrite);
+       DisconnectNamedPipe(hwrite);
 
-       if (!console)
-               return fputs(str, stream);
+       /* wait for console thread to copy remaining data */
+       WaitForSingleObject(hthread, INFINITE);
 
-       rv = ansi_emulate(str, stream);
+       /* cleanup handles... */
+       CloseHandle(hwrite);
+       CloseHandle(hthread);
+}
 
-       if (rv >= 0)
-               return 0;
-       else
-               return EOF;
+static void die_lasterr(const char *fmt, ...)
+{
+       va_list params;
+       va_start(params, fmt);
+       errno = err_win_to_posix(GetLastError());
+       die_errno(fmt, params);
+       va_end(params);
 }
 
-static int winansi_vfprintf(FILE *stream, const char *format, va_list list)
+static HANDLE duplicate_handle(HANDLE hnd)
 {
-       int len, rv;
-       char small_buf[256];
-       char *buf = small_buf;
-       va_list cp;
+       HANDLE hresult, hproc = GetCurrentProcess();
+       if (!DuplicateHandle(hproc, hnd, hproc, &hresult, 0, TRUE,
+                       DUPLICATE_SAME_ACCESS))
+               die_lasterr("DuplicateHandle(%li) failed", (long) hnd);
+       return hresult;
+}
 
-       if (!isatty(fileno(stream)))
-               goto abort;
 
-       init();
+/*
+ * Make MSVCRT's internal file descriptor control structure accessible
+ * so that we can tweak OS handles and flags directly (we need MSVCRT
+ * to treat our pipe handle as if it were a console).
+ *
+ * We assume that the ioinfo structure (exposed by MSVCRT.dll via
+ * __pioinfo) starts with the OS handle and the flags. The exact size
+ * varies between MSVCRT versions, so we try different sizes until
+ * toggling the FDEV bit of _pioinfo(1)->osflags is reflected in
+ * isatty(1).
+ */
+typedef struct {
+       HANDLE osfhnd;
+       char osflags;
+} ioinfo;
 
-       if (!console)
-               goto abort;
+extern __declspec(dllimport) ioinfo *__pioinfo[];
 
-       va_copy(cp, list);
-       len = vsnprintf(small_buf, sizeof(small_buf), format, cp);
-       va_end(cp);
+static size_t sizeof_ioinfo = 0;
 
-       if (len > sizeof(small_buf) - 1) {
-               buf = malloc(len + 1);
-               if (!buf)
-                       goto abort;
+#define IOINFO_L2E 5
+#define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
 
-               len = vsnprintf(buf, len + 1, format, list);
-       }
+#define FDEV  0x40
 
-       rv = ansi_emulate(buf, stream);
+static inline ioinfo* _pioinfo(int fd)
+{
+       return (ioinfo*)((char*)__pioinfo[fd >> IOINFO_L2E] +
+                       (fd & (IOINFO_ARRAY_ELTS - 1)) * sizeof_ioinfo);
+}
 
-       if (buf != small_buf)
-               free(buf);
-       return rv;
+static int init_sizeof_ioinfo()
+{
+       int istty, wastty;
+       /* don't init twice */
+       if (sizeof_ioinfo)
+               return sizeof_ioinfo >= 256;
+
+       sizeof_ioinfo = sizeof(ioinfo);
+       wastty = isatty(1);
+       while (sizeof_ioinfo < 256) {
+               /* toggle FDEV flag, check isatty, then toggle back */
+               _pioinfo(1)->osflags ^= FDEV;
+               istty = isatty(1);
+               _pioinfo(1)->osflags ^= FDEV;
+               /* return if we found the correct size */
+               if (istty != wastty)
+                       return 0;
+               sizeof_ioinfo += sizeof(void*);
+       }
+       error("Tweaking file descriptors doesn't work with this MSVCRT.dll");
+       return 1;
+}
 
-abort:
-       rv = vfprintf(stream, format, list);
-       return rv;
+static HANDLE swap_osfhnd(int fd, HANDLE new_handle)
+{
+       ioinfo *pioinfo;
+       HANDLE old_handle;
+
+       /* init ioinfo size if we haven't done so */
+       if (init_sizeof_ioinfo())
+               return INVALID_HANDLE_VALUE;
+
+       /* get ioinfo pointer and change the handles */
+       pioinfo = _pioinfo(fd);
+       old_handle = pioinfo->osfhnd;
+       pioinfo->osfhnd = new_handle;
+       return old_handle;
 }
 
-int winansi_fprintf(FILE *stream, const char *format, ...)
+void winansi_init(void)
 {
-       va_list list;
-       int rv;
+       int con1, con2;
+       char name[32];
 
-       va_start(list, format);
-       rv = winansi_vfprintf(stream, format, list);
-       va_end(list);
+       /* check if either stdout or stderr is a console output screen buffer */
+       con1 = is_console(1);
+       con2 = is_console(2);
+       if (!con1 && !con2)
+               return;
 
-       return rv;
+       /* create a named pipe to communicate with the console thread */
+       sprintf(name, "\\\\.\\pipe\\winansi%lu", GetCurrentProcessId());
+       hwrite = CreateNamedPipe(name, PIPE_ACCESS_OUTBOUND,
+               PIPE_TYPE_BYTE | PIPE_WAIT, 1, BUFFER_SIZE, 0, 0, NULL);
+       if (hwrite == INVALID_HANDLE_VALUE)
+               die_lasterr("CreateNamedPipe failed");
+
+       hread = CreateFile(name, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
+       if (hread == INVALID_HANDLE_VALUE)
+               die_lasterr("CreateFile for named pipe failed");
+
+       /* start console spool thread on the pipe's read end */
+       hthread = CreateThread(NULL, 0, console_thread, NULL, 0, NULL);
+       if (hthread == INVALID_HANDLE_VALUE)
+               die_lasterr("CreateThread(console_thread) failed");
+
+       /* schedule cleanup routine */
+       if (atexit(winansi_exit))
+               die_errno("atexit(winansi_exit) failed");
+
+       /* redirect stdout / stderr to the pipe */
+       if (con1)
+               hconsole1 = swap_osfhnd(1, duplicate_handle(hwrite));
+       if (con2)
+               hconsole2 = swap_osfhnd(2, duplicate_handle(hwrite));
 }
 
-int winansi_printf(const char *format, ...)
+/*
+ * Returns the real console handle if stdout / stderr is a pipe redirecting
+ * to the console. Allows spawn / exec to pass the console to the next process.
+ */
+HANDLE winansi_get_osfhandle(int fd)
 {
-       va_list list;
-       int rv;
-
-       va_start(list, format);
-       rv = winansi_vfprintf(stdout, format, list);
-       va_end(list);
-
-       return rv;
+       HANDLE hnd = (HANDLE) _get_osfhandle(fd);
+       if ((fd == 1 || fd == 2) && isatty(fd)
+           && GetFileType(hnd) == FILE_TYPE_PIPE)
+               return (fd == 1) ? hconsole1 : hconsole2;
+       return hnd;
 }
index 5272fc6f0b0c3825650c8b0fcca91415af62f43e..ba882a1f51de347dc52fa8c52623dbc376f36d80 100644 (file)
--- a/config.c
+++ b/config.c
@@ -138,8 +138,7 @@ int git_config_include(const char *var, const char *value, void *data)
        if (ret < 0)
                return ret;
 
-       type = skip_prefix(var, "include.");
-       if (!type)
+       if (!skip_prefix(var, "include.", &type))
                return ret;
 
        if (!strcmp(type, "path"))
@@ -147,12 +146,6 @@ int git_config_include(const char *var, const char *value, void *data)
        return ret;
 }
 
-static void lowercase(char *p)
-{
-       for (; *p; p++)
-               *p = tolower(*p);
-}
-
 void git_config_push_parameter(const char *text)
 {
        struct strbuf env = STRBUF_INIT;
@@ -180,7 +173,7 @@ int git_config_parse_parameter(const char *text,
                strbuf_list_free(pair);
                return error("bogus config parameter: %s", text);
        }
-       lowercase(pair[0]->buf);
+       strbuf_tolower(pair[0]);
        if (fn(pair[0]->buf, pair[1] ? pair[1]->buf : NULL, data) < 0) {
                strbuf_list_free(pair);
                return -1;
@@ -826,9 +819,16 @@ static int git_default_core_config(const char *var, const char *value)
        if (!strcmp(var, "core.commentchar")) {
                const char *comment;
                int ret = git_config_string(&comment, var, value);
-               if (!ret)
+               if (ret)
+                       return ret;
+               else if (!strcasecmp(comment, "auto"))
+                       auto_comment_line_char = 1;
+               else if (comment[0] && !comment[1]) {
                        comment_line_char = comment[0];
-               return ret;
+                       auto_comment_line_char = 0;
+               } else
+                       return error("core.commentChar should only be one character");
+               return 0;
        }
 
        if (!strcmp(var, "core.askpass"))
@@ -1538,7 +1538,7 @@ int git_config_set_multivar_in_file(const char *config_filename,
         * The lock serves a purpose in addition to locking: the new
         * contents of .git/config will be written into it.
         */
-       lock = xcalloc(sizeof(struct lock_file), 1);
+       lock = xcalloc(1, sizeof(struct lock_file));
        fd = hold_lock_file_for_update(lock, config_filename, 0);
        if (fd < 0) {
                error("could not lock config file %s: %s", config_filename, strerror(errno));
@@ -1636,6 +1636,13 @@ int git_config_set_multivar_in_file(const char *config_filename,
                        MAP_PRIVATE, in_fd, 0);
                close(in_fd);
 
+               if (fchmod(fd, st.st_mode & 07777) < 0) {
+                       error("fchmod on %s failed: %s",
+                               lock->filename, strerror(errno));
+                       ret = CONFIG_NO_WRITE;
+                       goto out_free;
+               }
+
                if (store.seen == 0)
                        store.seen = 1;
 
@@ -1784,6 +1791,7 @@ int git_config_rename_section_in_file(const char *config_filename,
        int out_fd;
        char buf[1024];
        FILE *config_file;
+       struct stat st;
 
        if (new_name && !section_name_is_ok(new_name)) {
                ret = error("invalid section name: %s", new_name);
@@ -1793,7 +1801,7 @@ int git_config_rename_section_in_file(const char *config_filename,
        if (!config_filename)
                config_filename = filename_buf = git_pathdup("config");
 
-       lock = xcalloc(sizeof(struct lock_file), 1);
+       lock = xcalloc(1, sizeof(struct lock_file));
        out_fd = hold_lock_file_for_update(lock, config_filename, 0);
        if (out_fd < 0) {
                ret = error("could not lock config file %s", config_filename);
@@ -1805,6 +1813,14 @@ int git_config_rename_section_in_file(const char *config_filename,
                goto unlock_and_out;
        }
 
+       fstat(fileno(config_file), &st);
+
+       if (fchmod(out_fd, st.st_mode & 07777) < 0) {
+               ret = error("fchmod on %s failed: %s",
+                               lock->filename, strerror(errno));
+               goto out;
+       }
+
        while (fgets(buf, sizeof(buf), config_file)) {
                int i;
                int length;
index 7846bd76573fe2513f08a824e89938deae6543de..8131c81985d97c23d19c7ef489f0db988f6fbbc7 100644 (file)
@@ -28,6 +28,7 @@ ifeq ($(uname_S),OSF1)
        NO_NSEC = YesPlease
 endif
 ifeq ($(uname_S),Linux)
+       HAVE_ALLOCA_H = YesPlease
        NO_STRLCPY = YesPlease
        NO_MKSTEMPS = YesPlease
        HAVE_PATHS_H = YesPlease
@@ -35,6 +36,7 @@ ifeq ($(uname_S),Linux)
        HAVE_DEV_TTY = YesPlease
 endif
 ifeq ($(uname_S),GNU/kFreeBSD)
+       HAVE_ALLOCA_H = YesPlease
        NO_STRLCPY = YesPlease
        NO_MKSTEMPS = YesPlease
        HAVE_PATHS_H = YesPlease
@@ -103,6 +105,7 @@ ifeq ($(uname_S),SunOS)
        NEEDS_NSL = YesPlease
        SHELL_PATH = /bin/bash
        SANE_TOOL_PATH = /usr/xpg6/bin:/usr/xpg4/bin
+       HAVE_ALLOCA_H = YesPlease
        NO_STRCASESTR = YesPlease
        NO_MEMMEM = YesPlease
        NO_MKDTEMP = YesPlease
@@ -145,7 +148,7 @@ ifeq ($(uname_S),SunOS)
        endif
        INSTALL = /usr/ucb/install
        TAR = gtar
-       BASIC_CFLAGS += -D__EXTENSIONS__ -D__sun__ -DHAVE_ALLOCA_H
+       BASIC_CFLAGS += -D__EXTENSIONS__ -D__sun__
 endif
 ifeq ($(uname_O),Cygwin)
        ifeq ($(shell expr "$(uname_R)" : '1\.[1-6]\.'),4)
@@ -164,6 +167,7 @@ ifeq ($(uname_O),Cygwin)
        else
                NO_REGEX = UnfortunatelyYes
        endif
+       HAVE_ALLOCA_H = YesPlease
        NEEDS_LIBICONV = YesPlease
        NO_FAST_WORKING_DIRECTORY = UnfortunatelyYes
        NO_ST_BLOCKS_IN_STRUCT_STAT = YesPlease
@@ -238,6 +242,7 @@ ifeq ($(uname_S),AIX)
 endif
 ifeq ($(uname_S),GNU)
        # GNU/Hurd
+       HAVE_ALLOCA_H = YesPlease
        NO_STRLCPY = YesPlease
        NO_MKSTEMPS = YesPlease
        HAVE_PATHS_H = YesPlease
@@ -312,6 +317,7 @@ endif
 ifeq ($(uname_S),Windows)
        GIT_VERSION := $(GIT_VERSION).MSVC
        pathsep = ;
+       HAVE_ALLOCA_H = YesPlease
        NO_PREAD = YesPlease
        NEEDS_CRYPTO_WITH_SSL = YesPlease
        NO_LIBGEN_H = YesPlease
@@ -348,6 +354,7 @@ ifeq ($(uname_S),Windows)
        NO_POSIX_GOODIES = UnfortunatelyYes
        NATIVE_CRLF = YesPlease
        DEFAULT_HELP_FORMAT = html
+       NO_D_INO_IN_DIRENT = YesPlease
 
        CC = compat/vcbuild/scripts/clink.pl
        AR = compat/vcbuild/scripts/lib.pl
@@ -356,17 +363,17 @@ ifeq ($(uname_S),Windows)
        COMPAT_OBJS = compat/msvc.o compat/winansi.o \
                compat/win32/pthread.o compat/win32/syslog.o \
                compat/win32/dirent.o
-       COMPAT_CFLAGS = -D__USE_MINGW_ACCESS -DNOGDI -DHAVE_STRING_H -DHAVE_ALLOCA_H -Icompat -Icompat/regex -Icompat/win32 -DSTRIP_EXTENSION=\".exe\"
-       BASIC_LDFLAGS = -IGNORE:4217 -IGNORE:4049 -NOLOGO -SUBSYSTEM:CONSOLE -NODEFAULTLIB:MSVCRT.lib
+       COMPAT_CFLAGS = -D__USE_MINGW_ACCESS -DNOGDI -DHAVE_STRING_H -Icompat -Icompat/regex -Icompat/win32 -DSTRIP_EXTENSION=\".exe\"
+       BASIC_LDFLAGS = -IGNORE:4217 -IGNORE:4049 -NOLOGO -SUBSYSTEM:CONSOLE
        EXTLIBS = user32.lib advapi32.lib shell32.lib wininet.lib ws2_32.lib invalidcontinue.obj
        PTHREAD_LIBS =
        lib =
 ifndef DEBUG
-       BASIC_CFLAGS += -GL -Os -MT
+       BASIC_CFLAGS += -GL -Os -MD
        BASIC_LDFLAGS += -LTCG
        AR += -LTCG
 else
-       BASIC_CFLAGS += -Zi -MTd
+       BASIC_CFLAGS += -Zi -MDd
 endif
        X = .exe
 endif
@@ -464,6 +471,7 @@ ifeq ($(uname_S),NONSTOP_KERNEL)
 endif
 ifneq (,$(findstring MINGW,$(uname_S)))
        pathsep = ;
+       HAVE_ALLOCA_H = YesPlease
        NO_PREAD = YesPlease
        NEEDS_CRYPTO_WITH_SSL = YesPlease
        NO_LIBGEN_H = YesPlease
@@ -496,6 +504,7 @@ ifneq (,$(findstring MINGW,$(uname_S)))
        NO_INET_NTOP = YesPlease
        NO_POSIX_GOODIES = UnfortunatelyYes
        DEFAULT_HELP_FORMAT = html
+       NO_D_INO_IN_DIRENT = YesPlease
        COMPAT_CFLAGS += -D__USE_MINGW_ACCESS -D_USE_32BIT_TIME_T -DNOGDI -Icompat -Icompat/win32
        COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\"
        COMPAT_OBJS += compat/mingw.o compat/winansi.o \
index b7112542b4b62fbbf0235c923f75803edc149e5c..4b1ae7c3c9f5ff5080dc026a6eb835d579d29949 100644 (file)
@@ -272,6 +272,14 @@ AS_HELP_STRING([],           [ARG can be also prefix for libpcre library and hea
        GIT_CONF_SUBST([LIBPCREDIR])
     fi)
 #
+# Define HAVE_ALLOCA_H if you have working alloca(3) defined in that header.
+AC_FUNC_ALLOCA
+case $ac_cv_working_alloca_h in
+    yes)    HAVE_ALLOCA_H=YesPlease;;
+    *)      HAVE_ALLOCA_H='';;
+esac
+GIT_CONF_SUBST([HAVE_ALLOCA_H])
+#
 # Define NO_CURL if you do not have curl installed.  git-http-pull and
 # git-http-push are not built, and you cannot use http:// and https://
 # transports.
index a983d061a90f0b720afa1a9b50247da299164d79..37ff018f13f6f8f3137a9aec973b85848a8138eb 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -129,6 +129,7 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
                char *name;
                int len, name_len;
                char *buffer = packet_buffer;
+               const char *arg;
 
                len = packet_read(in, &src_buf, &src_len,
                                  packet_buffer, sizeof(packet_buffer),
@@ -140,12 +141,12 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
                if (!len)
                        break;
 
-               if (len > 4 && starts_with(buffer, "ERR "))
-                       die("remote error: %s", buffer + 4);
+               if (len > 4 && skip_prefix(buffer, "ERR ", &arg))
+                       die("remote error: %s", arg);
 
-               if (len == 48 && starts_with(buffer, "shallow ")) {
-                       if (get_sha1_hex(buffer + 8, old_sha1))
-                               die("protocol error: expected shallow sha-1, got '%s'", buffer + 8);
+               if (len == 48 && skip_prefix(buffer, "shallow ", &arg)) {
+                       if (get_sha1_hex(arg, old_sha1))
+                               die("protocol error: expected shallow sha-1, got '%s'", arg);
                        if (!shallow_points)
                                die("repository on the other end cannot be shallow");
                        sha1_array_append(shallow_points, old_sha1);
@@ -534,22 +535,18 @@ static int git_use_proxy(const char *host)
 static struct child_process *git_proxy_connect(int fd[2], char *host)
 {
        const char *port = STR(DEFAULT_GIT_PORT);
-       const char **argv;
        struct child_process *proxy;
 
        get_host_and_port(&host, &port);
 
-       argv = xmalloc(sizeof(*argv) * 4);
-       argv[0] = git_proxy_command;
-       argv[1] = host;
-       argv[2] = port;
-       argv[3] = NULL;
        proxy = xcalloc(1, sizeof(*proxy));
-       proxy->argv = argv;
+       argv_array_push(&proxy->args, git_proxy_command);
+       argv_array_push(&proxy->args, host);
+       argv_array_push(&proxy->args, port);
        proxy->in = -1;
        proxy->out = -1;
        if (start_command(proxy))
-               die("cannot start proxy %s", argv[0]);
+               die("cannot start proxy %s", git_proxy_command);
        fd[0] = proxy->out; /* read from proxy stdout */
        fd[1] = proxy->in;  /* write to proxy stdin */
        return proxy;
@@ -663,7 +660,6 @@ struct child_process *git_connect(int fd[2], const char *url,
        char *hostandport, *path;
        struct child_process *conn = &no_fork;
        enum protocol protocol;
-       const char **arg;
        struct strbuf cmd = STRBUF_INIT;
 
        /* Without this we cannot rely on waitpid() to tell
@@ -707,7 +703,6 @@ struct child_process *git_connect(int fd[2], const char *url,
                sq_quote_buf(&cmd, path);
 
                conn->in = conn->out = -1;
-               conn->argv = arg = xcalloc(7, sizeof(*arg));
                if (protocol == PROTO_SSH) {
                        const char *ssh = getenv("GIT_SSH");
                        int putty = ssh && strcasestr(ssh, "plink");
@@ -718,22 +713,21 @@ struct child_process *git_connect(int fd[2], const char *url,
 
                        if (!ssh) ssh = "ssh";
 
-                       *arg++ = ssh;
+                       argv_array_push(&conn->args, ssh);
                        if (putty && !strcasestr(ssh, "tortoiseplink"))
-                               *arg++ = "-batch";
+                               argv_array_push(&conn->args, "-batch");
                        if (port) {
                                /* P is for PuTTY, p is for OpenSSH */
-                               *arg++ = putty ? "-P" : "-p";
-                               *arg++ = port;
+                               argv_array_push(&conn->args, putty ? "-P" : "-p");
+                               argv_array_push(&conn->args, port);
                        }
-                       *arg++ = ssh_host;
+                       argv_array_push(&conn->args, ssh_host);
                } else {
                        /* remove repo-local variables from the environment */
                        conn->env = local_repo_env;
                        conn->use_shell = 1;
                }
-               *arg++ = cmd.buf;
-               *arg = NULL;
+               argv_array_push(&conn->args, cmd.buf);
 
                if (start_command(conn))
                        die("unable to fork");
@@ -759,7 +753,6 @@ int finish_connect(struct child_process *conn)
                return 0;
 
        code = finish_command(conn);
-       free(conn->argv);
        free(conn);
        return code;
 }
index be0253e21bec3617ad3a7f1b0afc7d2049efc4fd..dae9c9972eb3485bd20494efd78d09f1189667cb 100644 (file)
@@ -31,6 +31,7 @@ static int check_everything_connected_real(sha1_iterate_fn fn,
        unsigned char sha1[20];
        int err = 0, ac = 0;
        struct packed_git *new_pack = NULL;
+       size_t base_len;
 
        if (fn(cb_data, sha1))
                return err;
@@ -38,10 +39,9 @@ static int check_everything_connected_real(sha1_iterate_fn fn,
        if (transport && transport->smart_options &&
            transport->smart_options->self_contained_and_connected &&
            transport->pack_lockfile &&
-           ends_with(transport->pack_lockfile, ".keep")) {
+           strip_suffix(transport->pack_lockfile, ".keep", &base_len)) {
                struct strbuf idx_file = STRBUF_INIT;
-               strbuf_addstr(&idx_file, transport->pack_lockfile);
-               strbuf_setlen(&idx_file, idx_file.len - 5); /* ".keep" */
+               strbuf_add(&idx_file, transport->pack_lockfile, base_len);
                strbuf_addstr(&idx_file, ".idx");
                new_pack = add_packed_git(idx_file.buf, idx_file.len, 1);
                strbuf_release(&idx_file);
index 019026efcbc5876d7aa3890eab5078a8bfbe2f7c..7a6e1d797a1ec95a17ad2a759acb85cbe25e9f10 100644 (file)
 #        source ~/.git-completion.sh
 #    3) Consider changing your PS1 to also show the current branch,
 #       see git-prompt.sh for details.
+#
+# If you use complex aliases of form '!f() { ... }; f', you can use the null
+# command ':' as the first command in the function body to declare the desired
+# completion style.  For example '!f() { : git commit ; ... }; f' will
+# tell the completion to use commit completion.  This also works with aliases
+# of form "!sh -c '...'".  For example, "!sh -c ': git commit ; ... '".
 
 case "$COMP_WORDBREAKS" in
 *:*) : great ;;
@@ -781,6 +787,10 @@ __git_aliased_command ()
                -*)     : option ;;
                *=*)    : setting env ;;
                git)    : git itself ;;
+               \(\))   : skip parens of shell function definition ;;
+               {)      : skip start of shell helper function ;;
+               :)      : skip null command ;;
+               \'*)    : skip opening quote after sh -c ;;
                *)
                        echo "$word"
                        return
index bad45ca47a2379a9226da1ae886e23dff01ca8f4..6e992c08667d0b2b6a3c2d42314e3f500eb7502a 100644 (file)
@@ -1,14 +1,22 @@
 all: git-credential-wincred.exe
 
-CC = gcc
-RM = rm -f
-CFLAGS = -O2 -Wall
-
 -include ../../../config.mak.autogen
 -include ../../../config.mak
 
+CC ?= gcc
+RM ?= rm -f
+CFLAGS ?= -O2 -Wall
+
+prefix ?= /usr/local
+libexecdir ?= $(prefix)/libexec/git-core
+
+INSTALL ?= install
+
 git-credential-wincred.exe : git-credential-wincred.c
        $(LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o $@
 
+install: git-credential-wincred.exe
+       $(INSTALL) -m 755 $^ $(libexecdir)
+
 clean:
        $(RM) git-credential-wincred.exe
diff --git a/contrib/diffall/README b/contrib/diffall/README
deleted file mode 100644 (file)
index 507f17d..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-The git-diffall script provides a directory based diff mechanism
-for git.
-
-To determine what diff viewer is used, the script requires either
-the 'diff.tool' or 'merge.tool' configuration option to be set.
-
-This script is compatible with most common forms used to specify a
-range of revisions to diff:
-
-  1. git diffall: shows diff between working tree and staged changes
-  2. git diffall --cached [<commit>]: shows diff between staged
-     changes and HEAD (or other named commit)
-  3. git diffall <commit>: shows diff between working tree and named
-     commit
-  4. git diffall <commit> <commit>: show diff between two named commits
-  5. git diffall <commit>..<commit>: same as above
-  6. git diffall <commit>...<commit>: show the changes on the branch
-     containing and up to the second, starting at a common ancestor
-     of both <commit>
-
-Note: all forms take an optional path limiter [-- <path>*]
-
-The '--extcmd=<command>' option allows the user to specify a custom
-command for viewing diffs.  When given, configured defaults are
-ignored and the script runs $command $LOCAL $REMOTE.  Additionally,
-$BASE is set in the environment.
-
-This script is based on an example provided by Thomas Rast on the
-Git list [1]:
-
-[1] http://thread.gmane.org/gmane.comp.version-control.git/124807
diff --git a/contrib/diffall/git-diffall b/contrib/diffall/git-diffall
deleted file mode 100755 (executable)
index 84f2b65..0000000
+++ /dev/null
@@ -1,257 +0,0 @@
-#!/bin/sh
-# Copyright 2010 - 2012, Tim Henigan <tim.henigan@gmail.com>
-#
-# Perform a directory diff between commits in the repository using
-# the external diff or merge tool specified in the user's config.
-
-USAGE='[--cached] [--copy-back] [-x|--extcmd=<command>] <commit>{0,2} [-- <path>*]
-
-    --cached     Compare to the index rather than the working tree.
-
-    --copy-back  Copy files back to the working tree when the diff
-                 tool exits (in case they were modified by the
-                 user).  This option is only valid if the diff
-                 compared with the working tree.
-
-    -x=<command>
-    --extcmd=<command>  Specify a custom command for viewing diffs.
-                 git-diffall ignores the configured defaults and
-                 runs $command $LOCAL $REMOTE when this option is
-                 specified. Additionally, $BASE is set in the
-                 environment.
-'
-
-SUBDIRECTORY_OK=1
-. "$(git --exec-path)/git-sh-setup"
-
-TOOL_MODE=diff
-. "$(git --exec-path)/git-mergetool--lib"
-
-merge_tool="$(get_merge_tool)"
-if test -z "$merge_tool"
-then
-       echo "Error: Either the 'diff.tool' or 'merge.tool' option must be set."
-       usage
-fi
-
-start_dir=$(pwd)
-
-# All the file paths returned by the diff command are relative to the root
-# of the working copy. So if the script is called from a subdirectory, it
-# must switch to the root of working copy before trying to use those paths.
-cdup=$(git rev-parse --show-cdup) &&
-cd "$cdup" || {
-       echo >&2 "Cannot chdir to $cdup, the toplevel of the working tree"
-       exit 1
-}
-
-# set up temp dir
-tmp=$(perl -e 'use File::Temp qw(tempdir);
-       $t=tempdir("/tmp/git-diffall.XXXXX") or exit(1);
-       print $t') || exit 1
-trap 'rm -rf "$tmp"' EXIT
-
-left=
-right=
-paths=
-dashdash_seen=
-compare_staged=
-merge_base=
-left_dir=
-right_dir=
-diff_tool=
-copy_back=
-
-while test $# != 0
-do
-       case "$1" in
-       -h|--h|--he|--hel|--help)
-               usage
-               ;;
-       --cached)
-               compare_staged=1
-               ;;
-       --copy-back)
-               copy_back=1
-               ;;
-       -x|--e|--ex|--ext|--extc|--extcm|--extcmd)
-               if test $# = 1
-               then
-                       echo You must specify the tool for use with --extcmd
-                       usage
-               else
-                       diff_tool=$2
-                       shift
-               fi
-               ;;
-       --)
-               dashdash_seen=1
-               ;;
-       -*)
-               echo Invalid option: "$1"
-               usage
-               ;;
-       *)
-               # could be commit, commit range or path limiter
-               case "$1" in
-               *...*)
-                       left=${1%...*}
-                       right=${1#*...}
-                       merge_base=1
-                       ;;
-               *..*)
-                       left=${1%..*}
-                       right=${1#*..}
-                       ;;
-               *)
-                       if test -n "$dashdash_seen"
-                       then
-                               paths="$paths$1 "
-                       elif test -z "$left"
-                       then
-                               left=$1
-                       elif test -z "$right"
-                       then
-                               right=$1
-                       else
-                               paths="$paths$1 "
-                       fi
-                       ;;
-               esac
-               ;;
-       esac
-       shift
-done
-
-# Determine the set of files which changed
-if test -n "$left" && test -n "$right"
-then
-       left_dir="cmt-$(git rev-parse --short $left)"
-       right_dir="cmt-$(git rev-parse --short $right)"
-
-       if test -n "$compare_staged"
-       then
-               usage
-       elif test -n "$merge_base"
-       then
-               git diff --name-only "$left"..."$right" -- $paths >"$tmp/filelist"
-       else
-               git diff --name-only "$left" "$right" -- $paths >"$tmp/filelist"
-       fi
-elif test -n "$left"
-then
-       left_dir="cmt-$(git rev-parse --short $left)"
-
-       if test -n "$compare_staged"
-       then
-               right_dir="staged"
-               git diff --name-only --cached "$left" -- $paths >"$tmp/filelist"
-       else
-               right_dir="working_tree"
-               git diff --name-only "$left" -- $paths >"$tmp/filelist"
-       fi
-else
-       left_dir="HEAD"
-
-       if test -n "$compare_staged"
-       then
-               right_dir="staged"
-               git diff --name-only --cached -- $paths >"$tmp/filelist"
-       else
-               right_dir="working_tree"
-               git diff --name-only -- $paths >"$tmp/filelist"
-       fi
-fi
-
-# Exit immediately if there are no diffs
-if test ! -s "$tmp/filelist"
-then
-       exit 0
-fi
-
-if test -n "$copy_back" && test "$right_dir" != "working_tree"
-then
-       echo "--copy-back is only valid when diff includes the working tree."
-       exit 1
-fi
-
-# Create the named tmp directories that will hold the files to be compared
-mkdir -p "$tmp/$left_dir" "$tmp/$right_dir"
-
-# Populate the tmp/right_dir directory with the files to be compared
-while read name
-do
-       if test -n "$right"
-       then
-               ls_list=$(git ls-tree $right "$name")
-               if test -n "$ls_list"
-               then
-                       mkdir -p "$tmp/$right_dir/$(dirname "$name")"
-                       git show "$right":"$name" >"$tmp/$right_dir/$name" || true
-               fi
-       elif test -n "$compare_staged"
-       then
-               ls_list=$(git ls-files -- "$name")
-               if test -n "$ls_list"
-               then
-                       mkdir -p "$tmp/$right_dir/$(dirname "$name")"
-                       git show :"$name" >"$tmp/$right_dir/$name"
-               fi
-       else
-               if test -e "$name"
-               then
-                       mkdir -p "$tmp/$right_dir/$(dirname "$name")"
-                       cp "$name" "$tmp/$right_dir/$name"
-               fi
-       fi
-done < "$tmp/filelist"
-
-# Populate the tmp/left_dir directory with the files to be compared
-while read name
-do
-       if test -n "$left"
-       then
-               ls_list=$(git ls-tree $left "$name")
-               if test -n "$ls_list"
-               then
-                       mkdir -p "$tmp/$left_dir/$(dirname "$name")"
-                       git show "$left":"$name" >"$tmp/$left_dir/$name" || true
-               fi
-       else
-               if test -n "$compare_staged"
-               then
-                       ls_list=$(git ls-tree HEAD "$name")
-                       if test -n "$ls_list"
-                       then
-                               mkdir -p "$tmp/$left_dir/$(dirname "$name")"
-                               git show HEAD:"$name" >"$tmp/$left_dir/$name"
-                       fi
-               else
-                       mkdir -p "$tmp/$left_dir/$(dirname "$name")"
-                       git show :"$name" >"$tmp/$left_dir/$name"
-               fi
-       fi
-done < "$tmp/filelist"
-
-LOCAL="$tmp/$left_dir"
-REMOTE="$tmp/$right_dir"
-
-if test -n "$diff_tool"
-then
-       export BASE
-       eval $diff_tool '"$LOCAL"' '"$REMOTE"'
-else
-       run_merge_tool "$merge_tool" false
-fi
-
-# Copy files back to the working dir, if requested
-if test -n "$copy_back" && test "$right_dir" = "working_tree"
-then
-       cd "$start_dir"
-       git_top_dir=$(git rev-parse --show-toplevel)
-       find "$tmp/$right_dir" -type f |
-       while read file
-       do
-               cp "$file" "$git_top_dir/${file#$tmp/$right_dir/}"
-       done
-fi
index 8bc8c7533a8678e2a43d3ddd49bc9aa8d670897d..ee1916641e46c1adfaac31e27c78c11b023d6ffa 100644 (file)
@@ -31,7 +31,8 @@ static int update_ref_env(const char *action,
                rla = "(reflog update)";
        if (snprintf(msg, sizeof(msg), "%s: %s", rla, action) >= sizeof(msg))
                warning("reflog message too long: %.*s...", 50, msg);
-       return update_ref(msg, refname, sha1, oldval, 0, QUIET_ON_ERR);
+       return update_ref(msg, refname, sha1, oldval, 0,
+                         UPDATE_REFS_QUIET_ON_ERR);
 }
 
 static int update_local_ref(const char *name,
index b4c9376a2cf1611d777e3f995cae9f20e6616e4d..08cf246bbb1c8306c20cd396ae6e6e80c3b8cbe7 100755 (executable)
@@ -516,7 +516,7 @@ then
 
        case "$no_checkout" in
        '')
-               test "z$quiet" = z -a "z$no_progress" = z && v=-v || v=
+               test "z$quiet" = z && test "z$no_progress" = z && v=-v || v=
                git read-tree -m -u $v HEAD HEAD
        esac
 fi
index 5cafe2eb7715123ba0d748be308f35731ea89ddb..934505bab9e6cf04a3536010ac31b1795c852c9f 100755 (executable)
@@ -51,7 +51,7 @@ run_status () {
                export GIT_INDEX_FILE
        fi
 
-       if test "$status_only" = "t" -o "$use_status_color" = "t"; then
+       if test "$status_only" = "t" || test "$use_status_color" = "t"; then
                color=
        else
                color=--nocolor
@@ -296,7 +296,7 @@ t,,,[1-9]*)
        die "No paths with -i does not make sense." ;;
 esac
 
-if test ! -z "$templatefile" -a -z "$log_given"
+if test ! -z "$templatefile" && test -z "$log_given"
 then
        if test ! -f "$templatefile"
        then
index 7e40f40c78e2b040ae5b85adb27ebd4828f42b4d..52f2aafb9d720723c1dc08e870f38ef495198fa3 100755 (executable)
@@ -161,7 +161,7 @@ merge_name () {
                        return
                fi
        fi
-       if test "$remote" = "FETCH_HEAD" -a -r "$GIT_DIR/FETCH_HEAD"
+       if test "$remote" = "FETCH_HEAD" && test -r "$GIT_DIR/FETCH_HEAD"
        then
                sed -e 's/      not-for-merge   /               /' -e 1q \
                        "$GIT_DIR/FETCH_HEAD"
@@ -527,7 +527,7 @@ do
                git diff-files --name-only
                git ls-files --unmerged
            } | wc -l`
-           if test $best_cnt -le 0 -o $cnt -le $best_cnt
+           if test $best_cnt -le 0 || test $cnt -le $best_cnt
            then
                best_strategy=$strategy
                best_cnt=$cnt
index f312405a251ddc42f0483fb3d1ccc92d8a266fd1..96e3fed326abeb293e9ef398989bce1054cbf855 100755 (executable)
@@ -76,8 +76,8 @@ case ",$all_into_one," in
                                existing="$existing $e"
                        fi
                done
-               if test -n "$existing" -a -n "$unpack_unreachable" -a \
-                       -n "$remove_redundant"
+               if test -n "$existing" && test -n "$unpack_unreachable" && \
+                       test -n "$remove_redundant"
                then
                        # This may have arbitrary user arguments, so we
                        # have to protect it against whitespace splitting
index 48d0fc971f9e7ec3b4b15608950217ad71c5ba94..70fdc27b724f28793c6a4bff713957a22689b78b 100755 (executable)
@@ -76,7 +76,7 @@ case "$common" in
                        2>/dev/null || continue
                # Count the paths that are unmerged.
                cnt=$(GIT_INDEX_FILE=$G git ls-files --unmerged | wc -l)
-               if test $best_cnt -le 0 -o $cnt -le $best_cnt
+               if test $best_cnt -le 0 || test $cnt -le $best_cnt
                then
                        best=$c
                        best_cnt=$cnt
index 3f8d993afaca53024aa75b4118da9ee80e6a6313..8dd74a9a406e9cfd685ea1af3947e4bea4c82f90 100755 (executable)
@@ -461,7 +461,12 @@ sub download_mw_mediafile {
 
        my $response = $mediawiki->{ua}->get($download_url);
        if ($response->code == HTTP_CODE_OK) {
-               return $response->decoded_content;
+               # It is tempting to return
+               # $response->decoded_content({charset => "none"}), but
+               # when doing so, utf8::downgrade($content) fails with
+               # "Wide character in subroutine entry".
+               $response->decode();
+               return $response->content();
        } else {
                print {*STDERR} "Error downloading mediafile from :\n";
                print {*STDERR} "URL: ${download_url}\n";
index 70a53f67fd06bd2ce6f2f544655b03b99c6b2ee9..c215213c4bfddb583fb3de0eb624e0cffdb8cc7c 100755 (executable)
@@ -20,6 +20,8 @@ usage () {
        echo "          install | -i :  Install a wiki on your computer."
        echo "          delete | -d : Delete the wiki and all its pages and "
        echo "                  content."
+       echo "          start  | -s : Start the previously configured lighttpd daemon"
+       echo "          stop        : Stop lighttpd daemon."
 }
 
 
@@ -33,6 +35,14 @@ case "$1" in
                wiki_delete
                exit 0
                ;;
+       "start" | "-s")
+               start_lighttpd
+               exit
+               ;;
+       "stop")
+               stop_lighttpd
+               exit
+               ;;
        "--help" | "-h")
                usage
                exit 0
index 5a0373935f1f4b66c4521158e4b3c41508c908ea..3ff3a095670ecdf578dc9f4d51841c102c5a10fd 100755 (executable)
@@ -58,6 +58,25 @@ test_expect_success 'git clone works on previously created wiki with media files
        test_cmp mw_dir_clone/Foo.txt mw_dir/Foo.txt
 '
 
+test_expect_success 'git push can upload media (File:) files containing valid UTF-8' '
+       wiki_reset &&
+       git clone mediawiki::'"$WIKI_URL"' mw_dir &&
+       (
+               cd mw_dir &&
+               "$PERL_PATH" -e "print STDOUT \"UTF-8 content: éèàéê€.\";" >Bar.txt &&
+               git add Bar.txt &&
+               git commit -m "add a text file with UTF-8 content" &&
+               git push
+       )
+'
+
+test_expect_success 'git clone works on previously created wiki with media files containing valid UTF-8' '
+       test_when_finished "rm -rf mw_dir mw_dir_clone" &&
+       git clone -c remote.origin.mediaimport=true \
+               mediawiki::'"$WIKI_URL"' mw_dir_clone &&
+       test_cmp mw_dir_clone/Bar.txt mw_dir/Bar.txt
+'
+
 test_expect_success 'git push & pull work with locally renamed media files' '
        wiki_reset &&
        git clone mediawiki::'"$WIKI_URL"' mw_dir &&
index 27e267f532974914d1b214920bcfb8e2d4e3de6c..016454749f8dfa8539c7af1ca7fe4338414ab661 100755 (executable)
@@ -9,7 +9,7 @@ test_check_precond
 
 test_expect_success 'creating page w/ >500 revisions' '
        wiki_reset &&
-       for i in `test_seq 501`
+       for i in $(test_seq 501)
        do
                echo "creating revision $i" &&
                wiki_editpage foo "revision $i<br/>" true
index 3372b2af346ac23a73a7723ac6d0c81fb8c5e705..6546294f159e940eb8f7adc3e695f16d9395eebc 100755 (executable)
@@ -90,7 +90,7 @@ test_diff_directories () {
 #
 # Check that <dir> contains exactly <N> files
 test_contains_N_files () {
-       if test `ls -- "$1" | wc -l` -ne "$2"; then
+       if test $(ls -- "$1" | wc -l) -ne "$2"; then
                echo "directory $1 should contain $2 files"
                echo "it contains these files:"
                ls "$1"
@@ -289,7 +289,6 @@ start_lighttpd () {
 # Kill daemon lighttpd and removes files and folders associated.
 stop_lighttpd () {
        test -f "$WEB_TMP/pid" && kill $(cat "$WEB_TMP/pid")
-       rm -rf "$WEB"
 }
 
 # Create the SQLite database of the MediaWiki. If the database file already
@@ -341,10 +340,10 @@ wiki_install () {
                        "http://download.wikimedia.org/mediawiki/$MW_VERSION_MAJOR/"\
                        "$MW_FILENAME. "\
                        "Please fix your connection and launch the script again."
-               echo "$MW_FILENAME downloaded in `pwd`. "\
+               echo "$MW_FILENAME downloaded in $(pwd). "\
                        "You can delete it later if you want."
        else
-               echo "Reusing existing $MW_FILENAME downloaded in `pwd`."
+               echo "Reusing existing $MW_FILENAME downloaded in $(pwd)."
        fi
        archive_abs_path=$(pwd)/$MW_FILENAME
        cd "$WIKI_DIR_INST/$WIKI_DIR_NAME/" ||
@@ -415,6 +414,7 @@ wiki_reset () {
 wiki_delete () {
        if test $LIGHTTPD = "true"; then
                stop_lighttpd
+               rm -fr "$WEB"
        else
                # Delete the wiki's directory.
                rm -rf "$WIKI_DIR_INST/$WIKI_DIR_NAME" ||
index 4030a168986d29bdbb2cd982a2e819ce009580f6..d888d4516114c719e46ab7f2aeb24e63618b7fac 100644 (file)
@@ -3,17 +3,23 @@
 
 prefix ?= /usr/local
 mandir ?= $(prefix)/share/man
-libexecdir ?= $(prefix)/libexec/git-core
-gitdir ?= $(shell git --exec-path)
+gitexecdir ?= $(prefix)/libexec/git-core
 man1dir ?= $(mandir)/man1
 
-gitver ?= $(word 3,$(shell git --version))
+../../GIT-VERSION-FILE: FORCE
+       $(MAKE) -C ../../ GIT-VERSION-FILE
+
+-include ../../GIT-VERSION-FILE
 
 # this should be set to a 'standard' bsd-type install program
-INSTALL ?= install
+INSTALL  ?= install
+RM       ?= rm -f
+
+ASCIIDOC = asciidoc
+XMLTO    = xmlto
 
-ASCIIDOC_CONF      = ../../Documentation/asciidoc.conf
-MANPAGE_NORMAL_XSL =  ../../Documentation/manpage-normal.xsl
+ASCIIDOC_CONF = ../../Documentation/asciidoc.conf
+MANPAGE_XSL   = ../../Documentation/manpage-normal.xsl
 
 GIT_SUBTREE_SH := git-subtree.sh
 GIT_SUBTREE    := git-subtree
@@ -31,8 +37,8 @@ $(GIT_SUBTREE): $(GIT_SUBTREE_SH)
 doc: $(GIT_SUBTREE_DOC) $(GIT_SUBTREE_HTML)
 
 install: $(GIT_SUBTREE)
-       $(INSTALL) -d -m 755 $(DESTDIR)$(libexecdir)
-       $(INSTALL) -m 755 $(GIT_SUBTREE) $(DESTDIR)$(libexecdir)
+       $(INSTALL) -d -m 755 $(DESTDIR)$(gitexecdir)
+       $(INSTALL) -m 755 $(GIT_SUBTREE) $(DESTDIR)$(gitexecdir)
 
 install-doc: install-man
 
@@ -41,19 +47,21 @@ install-man: $(GIT_SUBTREE_DOC)
        $(INSTALL) -m 644 $^ $(DESTDIR)$(man1dir)
 
 $(GIT_SUBTREE_DOC): $(GIT_SUBTREE_XML)
-       xmlto -m $(MANPAGE_NORMAL_XSL)  man $^
+       $(XMLTO) -m $(MANPAGE_XSL) man $^
 
 $(GIT_SUBTREE_XML): $(GIT_SUBTREE_TXT)
-       asciidoc -b docbook -d manpage -f $(ASCIIDOC_CONF) \
-               -agit_version=$(gitver) $^
+       $(ASCIIDOC) -b docbook -d manpage -f $(ASCIIDOC_CONF) \
+               -agit_version=$(GIT_VERSION) $^
 
 $(GIT_SUBTREE_HTML): $(GIT_SUBTREE_TXT)
-       asciidoc -b xhtml11 -d manpage -f $(ASCIIDOC_CONF) \
-               -agit_version=$(gitver) $^
+       $(ASCIIDOC) -b xhtml11 -d manpage -f $(ASCIIDOC_CONF) \
+               -agit_version=$(GIT_VERSION) $^
 
 test:
        $(MAKE) -C t/ test
 
 clean:
-       rm -f *~ *.xml *.html *.1
-       rm -rf subproj mainline
+       $(RM) $(GIT_SUBTREE)
+       $(RM) *.xml *.html *.1
+
+.PHONY: FORCE
index db925ca76991c635ea53fe7f38d6608d08dfc4d5..fa1a5839af2d0c423adb51238fb330f555dc4dff 100755 (executable)
@@ -558,8 +558,9 @@ cmd_add_commit()
                commit=$(add_squashed_msg "$rev" "$dir" |
                         git commit-tree $tree $headp -p "$rev") || exit $?
        else
+               revp=$(peel_committish "$rev") &&
                commit=$(add_msg "$dir" "$headrev" "$rev" |
-                        git commit-tree $tree $headp -p "$rev") || exit $?
+                        git commit-tree $tree $headp -p "$revp") || exit $?
        fi
        git reset "$commit" || exit $?
        
index 66ce4b07c2dc2d2d56dc260883f86d8672d2ac69..6309d124ca2c97b2b1b9262c7b9470c576870069 100755 (executable)
@@ -8,7 +8,8 @@ This test verifies the basic operation of the merge, pull, add
 and split subcommands of git subtree.
 '
 
-export TEST_DIRECTORY=$(pwd)/../../../t
+TEST_DIRECTORY=$(pwd)/../../../t
+export TEST_DIRECTORY
 
 . ../../../t/test-lib.sh
 
@@ -76,7 +77,7 @@ test_expect_success 'add sub1' '
 
 # Save this hash for testing later.
 
-subdir_hash=`git rev-parse HEAD`
+subdir_hash=$(git rev-parse HEAD)
 
 test_expect_success 'add sub2' '
         create sub2 &&
index 4e78a1c3cda15659256c7aa64eb98cab7737c61f..11ac6f692733fbfde96a44cc553002ad748065db 100755 (executable)
@@ -5,53 +5,64 @@ of the specified revision range.
 To simulate incremental imports the environment variable SVNRMAX can be set
 to the highest revision that should be available.
 """
-import sys, os
+import sys
+import os
 
 if sys.hexversion < 0x02040000:
-        # The limiter is the ValueError() calls. This may be too conservative
-        sys.stderr.write("svnrdump-sim.py: requires Python 2.4 or later.\n")
-        sys.exit(1)
+    # The limiter is the ValueError() calls. This may be too conservative
+    sys.stderr.write("svnrdump-sim.py: requires Python 2.4 or later.\n")
+    sys.exit(1)
+
 
 def getrevlimit():
-        var = 'SVNRMAX'
-        if var in os.environ:
-                return os.environ[var]
-        return None
+    var = 'SVNRMAX'
+    if var in os.environ:
+        return os.environ[var]
+    return None
+
 
 def writedump(url, lower, upper):
-        if url.startswith('sim://'):
-                filename = url[6:]
-                if filename[-1] == '/': filename = filename[:-1] #remove terminating slash
-        else:
-                raise ValueError('sim:// url required')
-        f = open(filename, 'r');
-        state = 'header'
-        wroterev = False
-        while(True):
-                l = f.readline()
-                if l == '': break
-                if state == 'header' and l.startswith('Revision-number: '):
-                        state = 'prefix'
-                if state == 'prefix' and l == 'Revision-number: %s\n' % lower:
-                        state = 'selection'
-                if not upper == 'HEAD' and state == 'selection' and l == 'Revision-number: %s\n' % upper:
-                        break;
+    if url.startswith('sim://'):
+        filename = url[6:]
+        if filename[-1] == '/':
+            filename = filename[:-1]  # remove terminating slash
+    else:
+        raise ValueError('sim:// url required')
+    f = open(filename, 'r')
+    state = 'header'
+    wroterev = False
+    while(True):
+        l = f.readline()
+        if l == '':
+            break
+        if state == 'header' and l.startswith('Revision-number: '):
+            state = 'prefix'
+        if state == 'prefix' and l == 'Revision-number: %s\n' % lower:
+            state = 'selection'
+        if not upper == 'HEAD' and state == 'selection' and \
+                l == 'Revision-number: %s\n' % upper:
+            break
 
-                if state == 'header' or state == 'selection':
-                        if state == 'selection': wroterev = True
-                        sys.stdout.write(l)
-        return wroterev
+        if state == 'header' or state == 'selection':
+            if state == 'selection':
+                wroterev = True
+            sys.stdout.write(l)
+    return wroterev
 
 if __name__ == "__main__":
-        if not (len(sys.argv) in (3, 4, 5)):
-                print("usage: %s dump URL -rLOWER:UPPER")
-                sys.exit(1)
-        if not sys.argv[1] == 'dump': raise NotImplementedError('only "dump" is suppported.')
-        url = sys.argv[2]
-        r = ('0', 'HEAD')
-        if len(sys.argv) == 4 and sys.argv[3][0:2] == '-r':
-                r = sys.argv[3][2:].lstrip().split(':')
-        if not getrevlimit() is None: r[1] = getrevlimit()
-        if writedump(url, r[0], r[1]): ret = 0
-        else: ret = 1
-        sys.exit(ret)
+    if not (len(sys.argv) in (3, 4, 5)):
+        print("usage: %s dump URL -rLOWER:UPPER")
+        sys.exit(1)
+    if not sys.argv[1] == 'dump':
+        raise NotImplementedError('only "dump" is suppported.')
+    url = sys.argv[2]
+    r = ('0', 'HEAD')
+    if len(sys.argv) == 4 and sys.argv[3][0:2] == '-r':
+        r = sys.argv[3][2:].lstrip().split(':')
+    if not getrevlimit() is None:
+        r[1] = getrevlimit()
+    if writedump(url, r[0], r[1]):
+        ret = 0
+    else:
+        ret = 1
+    sys.exit(ret)
index 5eb4a5164397e3a34be10690025a9cd472261db9..8dc73ece15a075bb60971da577d2da272c8f7c14 100755 (executable)
@@ -10,7 +10,7 @@ CONFFILE=~/.appprc
 
 SEP="-=-=-=-=-=-=-=-=-=# Don't remove this line #=-=-=-=-=-=-=-=-=-"
 if [ -e "$CONFFILE" ] ; then
-       LAST_DIR=`grep -m 1 "^LAST_DIR=" "${CONFFILE}"|sed -e 's/^LAST_DIR=//'`
+       LAST_DIR=$(grep -m 1 "^LAST_DIR=" "${CONFFILE}"|sed -e 's/^LAST_DIR=//')
        cd "${LAST_DIR}"
 else
        cd > /dev/null
@@ -25,11 +25,11 @@ fi
 
 cd - > /dev/null
 
-SUBJECT=`sed -n -e '/^Subject: /p' "${PATCH}"`
-HEADERS=`sed -e '/^'"${SEP}"'$/,$d' $1`
-BODY=`sed -e "1,/${SEP}/d" $1`
-CMT_MSG=`sed -e '1,/^$/d' -e '/^---$/,$d' "${PATCH}"`
-DIFF=`sed -e '1,/^---$/d' "${PATCH}"`
+SUBJECT=$(sed -n -e '/^Subject: /p' "${PATCH}")
+HEADERS=$(sed -e '/^'"${SEP}"'$/,$d' $1)
+BODY=$(sed -e "1,/${SEP}/d" $1)
+CMT_MSG=$(sed -e '1,/^$/d' -e '/^---$/,$d' "${PATCH}")
+DIFF=$(sed -e '1,/^---$/d' "${PATCH}")
 
 CCS=`echo -e "$CMT_MSG\n$HEADERS" | sed -n -e 's/^Cc: \(.*\)$/\1,/gp' \
        -e 's/^Signed-off-by: \(.*\)/\1,/gp'`
@@ -48,7 +48,7 @@ if [ "x${BODY}x" != "xx" ] ; then
 fi
 echo "$DIFF" >> $1
 
-LAST_DIR=`dirname "${PATCH}"`
+LAST_DIR=$(dirname "${PATCH}")
 
 grep -v "^LAST_DIR=" "${CONFFILE}" > "${CONFFILE}_"
 echo "LAST_DIR=${LAST_DIR}" >> "${CONFFILE}_"
diff --git a/contrib/vim/README b/contrib/vim/README
deleted file mode 100644 (file)
index 8f16d06..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-Syntax highlighting for git commit messages, config files, etc. is
-included with the vim distribution as of vim 7.2, and should work
-automatically.
-
-If you have an older version of vim, you can get the latest syntax
-files from the vim project:
-
-  http://ftp.vim.org/pub/vim/runtime/syntax/git.vim
-  http://ftp.vim.org/pub/vim/runtime/syntax/gitcommit.vim
-  http://ftp.vim.org/pub/vim/runtime/syntax/gitconfig.vim
-  http://ftp.vim.org/pub/vim/runtime/syntax/gitrebase.vim
-  http://ftp.vim.org/pub/vim/runtime/syntax/gitsendemail.vim
-
-These files are also available via FTP at the same location.
-
-To install:
-
-  1. Copy these files to vim's syntax directory $HOME/.vim/syntax
-  2. To auto-detect the editing of various git-related filetypes:
-
-       $ curl http://ftp.vim.org/pub/vim/runtime/filetype.vim |
-               sed -ne '/^" Git$/, /^$/ p' >>$HOME/.vim/filetype.vim
index ab80b723574ff88b6c9c4a7c98c8821600f3e6bc..cb5fbb45ea04cead65316ecf6b44730b17108122 100644 (file)
--- a/convert.c
+++ b/convert.c
@@ -1121,9 +1121,9 @@ static int is_foreign_ident(const char *str)
 {
        int i;
 
-       if (!starts_with(str, "$Id: "))
+       if (!skip_prefix(str, "$Id: ", &str))
                return 0;
-       for (i = 5; str[i]; i++) {
+       for (i = 0; str[i]; i++) {
                if (isspace(str[i]) && str[i+1] != '$')
                        return 1;
        }
index 390f194252cc6d7c0c9f43e2a48692324bf0b665..3b370ca5e529c74e17e0f39da5c689ebc4ccfc25 100644 (file)
@@ -109,14 +109,12 @@ static int read_request(FILE *fh, struct credential *c,
        const char *p;
 
        strbuf_getline(&item, fh, '\n');
-       p = skip_prefix(item.buf, "action=");
-       if (!p)
+       if (!skip_prefix(item.buf, "action=", &p))
                return error("client sent bogus action line: %s", item.buf);
        strbuf_addstr(action, p);
 
        strbuf_getline(&item, fh, '\n');
-       p = skip_prefix(item.buf, "timeout=");
-       if (!p)
+       if (!skip_prefix(item.buf, "timeout=", &p))
                return error("client sent bogus timeout line: %s", item.buf);
        *timeout = atoi(p);
 
index e54753c75d1c2abf7916f1aa7075d4ada3cfc61f..4d79d320f89e956aa9233a170120f05b2473ca59 100644 (file)
@@ -40,8 +40,7 @@ static int credential_config_callback(const char *var, const char *value,
        struct credential *c = data;
        const char *key, *dot;
 
-       key = skip_prefix(var, "credential.");
-       if (!key)
+       if (!skip_prefix(var, "credential.", &key))
                return 0;
 
        if (!value)
index eba12556848e975cd6f1a55ae25760823e90cdc8..e6b51ed9981f2e4084504a2a092a3f28fc7d4c8a 100644 (file)
--- a/daemon.c
+++ b/daemon.c
@@ -39,8 +39,8 @@ static int strict_paths;
 static int export_all_trees;
 
 /* Take all paths relative to this one if non-NULL */
-static char *base_path;
-static char *interpolated_path;
+static const char *base_path;
+static const char *interpolated_path;
 static int base_path_relaxed;
 
 /* Flag indicating client sent extra args. */
@@ -106,12 +106,12 @@ static void NORETURN daemon_die(const char *err, va_list params)
        exit(1);
 }
 
-static const char *path_ok(char *directory)
+static const char *path_ok(const char *directory)
 {
        static char rpath[PATH_MAX];
        static char interp_path[PATH_MAX];
        const char *path;
-       char *dir;
+       const char *dir;
 
        dir = directory;
 
@@ -131,7 +131,7 @@ static const char *path_ok(char *directory)
                         * "~alice/%s/foo".
                         */
                        int namlen, restlen = strlen(dir);
-                       char *slash = strchr(dir, '/');
+                       const char *slash = strchr(dir, '/');
                        if (!slash)
                                slash = dir + restlen;
                        namlen = slash - dir;
@@ -235,8 +235,10 @@ static int service_enabled;
 
 static int git_daemon_config(const char *var, const char *value, void *cb)
 {
-       if (starts_with(var, "daemon.") &&
-           !strcmp(var + 7, service_looking_at->config_name)) {
+       const char *service;
+
+       if (skip_prefix(var, "daemon.", &service) &&
+           !strcmp(service, service_looking_at->config_name)) {
                service_enabled = git_config_bool(var, value);
                return 0;
        }
@@ -253,7 +255,7 @@ static int daemon_error(const char *dir, const char *msg)
        return -1;
 }
 
-static char *access_hook;
+static const char *access_hook;
 
 static int run_access_hook(struct daemon_service *service, const char *dir, const char *path)
 {
@@ -318,7 +320,7 @@ error_return:
        return -1;
 }
 
-static int run_service(char *dir, struct daemon_service *service)
+static int run_service(const char *dir, struct daemon_service *service)
 {
        const char *path;
        int enabled = service->enabled;
@@ -475,14 +477,6 @@ static void make_service_overridable(const char *name, int ena)
        die("No such service %s", name);
 }
 
-static char *xstrdup_tolower(const char *str)
-{
-       char *p, *dup = xstrdup(str);
-       for (p = dup; *p; p++)
-               *p = tolower(*p);
-       return dup;
-}
-
 static void parse_host_and_port(char *hostport, char **host,
        char **port)
 {
@@ -632,15 +626,16 @@ static int execute(void)
 
        for (i = 0; i < ARRAY_SIZE(daemon_service); i++) {
                struct daemon_service *s = &(daemon_service[i]);
-               int namelen = strlen(s->name);
-               if (starts_with(line, "git-") &&
-                   !strncmp(s->name, line + 4, namelen) &&
-                   line[namelen + 4] == ' ') {
+               const char *arg;
+
+               if (skip_prefix(line, "git-", &arg) &&
+                   skip_prefix(arg, s->name, &arg) &&
+                   *arg++ == ' ') {
                        /*
                         * Note: The directory here is probably context sensitive,
                         * and might depend on the actual service being performed.
                         */
-                       return run_service(line + namelen + 5, s);
+                       return run_service(arg, s);
                }
        }
 
@@ -783,7 +778,6 @@ static void handle(int incoming, struct sockaddr *addr, socklen_t addrlen)
                logerror("unable to fork");
        else
                add_child(&cld, addr, addrlen);
-       close(incoming);
 }
 
 static void child_handler(int signo)
@@ -1141,16 +1135,17 @@ int main(int argc, char **argv)
 
        for (i = 1; i < argc; i++) {
                char *arg = argv[i];
+               const char *v;
 
-               if (starts_with(arg, "--listen=")) {
-                       string_list_append(&listen_addr, xstrdup_tolower(arg + 9));
+               if (skip_prefix(arg, "--listen=", &v)) {
+                       string_list_append(&listen_addr, xstrdup_tolower(v));
                        continue;
                }
-               if (starts_with(arg, "--port=")) {
+               if (skip_prefix(arg, "--port=", &v)) {
                        char *end;
                        unsigned long n;
-                       n = strtoul(arg+7, &end, 0);
-                       if (arg[7] && !*end) {
+                       n = strtoul(v, &end, 0);
+                       if (*v && !*end) {
                                listen_port = n;
                                continue;
                        }
@@ -1176,20 +1171,20 @@ int main(int argc, char **argv)
                        export_all_trees = 1;
                        continue;
                }
-               if (starts_with(arg, "--access-hook=")) {
-                       access_hook = arg + 14;
+               if (skip_prefix(arg, "--access-hook=", &v)) {
+                       access_hook = v;
                        continue;
                }
-               if (starts_with(arg, "--timeout=")) {
-                       timeout = atoi(arg+10);
+               if (skip_prefix(arg, "--timeout=", &v)) {
+                       timeout = atoi(v);
                        continue;
                }
-               if (starts_with(arg, "--init-timeout=")) {
-                       init_timeout = atoi(arg+15);
+               if (skip_prefix(arg, "--init-timeout=", &v)) {
+                       init_timeout = atoi(v);
                        continue;
                }
-               if (starts_with(arg, "--max-connections=")) {
-                       max_connections = atoi(arg+18);
+               if (skip_prefix(arg, "--max-connections=", &v)) {
+                       max_connections = atoi(v);
                        if (max_connections < 0)
                                max_connections = 0;            /* unlimited */
                        continue;
@@ -1198,16 +1193,16 @@ int main(int argc, char **argv)
                        strict_paths = 1;
                        continue;
                }
-               if (starts_with(arg, "--base-path=")) {
-                       base_path = arg+12;
+               if (skip_prefix(arg, "--base-path=", &v)) {
+                       base_path = v;
                        continue;
                }
                if (!strcmp(arg, "--base-path-relaxed")) {
                        base_path_relaxed = 1;
                        continue;
                }
-               if (starts_with(arg, "--interpolated-path=")) {
-                       interpolated_path = arg+20;
+               if (skip_prefix(arg, "--interpolated-path=", &v)) {
+                       interpolated_path = v;
                        continue;
                }
                if (!strcmp(arg, "--reuseaddr")) {
@@ -1218,12 +1213,12 @@ int main(int argc, char **argv)
                        user_path = "";
                        continue;
                }
-               if (starts_with(arg, "--user-path=")) {
-                       user_path = arg + 12;
+               if (skip_prefix(arg, "--user-path=", &v)) {
+                       user_path = v;
                        continue;
                }
-               if (starts_with(arg, "--pid-file=")) {
-                       pid_file = arg + 11;
+               if (skip_prefix(arg, "--pid-file=", &v)) {
+                       pid_file = v;
                        continue;
                }
                if (!strcmp(arg, "--detach")) {
@@ -1231,28 +1226,28 @@ int main(int argc, char **argv)
                        log_syslog = 1;
                        continue;
                }
-               if (starts_with(arg, "--user=")) {
-                       user_name = arg + 7;
+               if (skip_prefix(arg, "--user=", &v)) {
+                       user_name = v;
                        continue;
                }
-               if (starts_with(arg, "--group=")) {
-                       group_name = arg + 8;
+               if (skip_prefix(arg, "--group=", &v)) {
+                       group_name = v;
                        continue;
                }
-               if (starts_with(arg, "--enable=")) {
-                       enable_service(arg + 9, 1);
+               if (skip_prefix(arg, "--enable=", &v)) {
+                       enable_service(v, 1);
                        continue;
                }
-               if (starts_with(arg, "--disable=")) {
-                       enable_service(arg + 10, 0);
+               if (skip_prefix(arg, "--disable=", &v)) {
+                       enable_service(v, 0);
                        continue;
                }
-               if (starts_with(arg, "--allow-override=")) {
-                       make_service_overridable(arg + 17, 1);
+               if (skip_prefix(arg, "--allow-override=", &v)) {
+                       make_service_overridable(v, 1);
                        continue;
                }
-               if (starts_with(arg, "--forbid-override=")) {
-                       make_service_overridable(arg + 18, 0);
+               if (skip_prefix(arg, "--forbid-override=", &v)) {
+                       make_service_overridable(v, 0);
                        continue;
                }
                if (!strcmp(arg, "--informative-errors")) {
diff --git a/diff.c b/diff.c
index 68bb8c5a8493500b127ccac7327133d09acdcdcb..06bdfb8ae5acab2c6090ca4154a26fca6da8b74c 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -52,23 +52,23 @@ static char diff_colors[][COLOR_MAXLEN] = {
        GIT_COLOR_NORMAL,       /* FUNCINFO */
 };
 
-static int parse_diff_color_slot(const char *var, int ofs)
+static int parse_diff_color_slot(const char *var)
 {
-       if (!strcasecmp(var+ofs, "plain"))
+       if (!strcasecmp(var, "plain"))
                return DIFF_PLAIN;
-       if (!strcasecmp(var+ofs, "meta"))
+       if (!strcasecmp(var, "meta"))
                return DIFF_METAINFO;
-       if (!strcasecmp(var+ofs, "frag"))
+       if (!strcasecmp(var, "frag"))
                return DIFF_FRAGINFO;
-       if (!strcasecmp(var+ofs, "old"))
+       if (!strcasecmp(var, "old"))
                return DIFF_FILE_OLD;
-       if (!strcasecmp(var+ofs, "new"))
+       if (!strcasecmp(var, "new"))
                return DIFF_FILE_NEW;
-       if (!strcasecmp(var+ofs, "commit"))
+       if (!strcasecmp(var, "commit"))
                return DIFF_COMMIT;
-       if (!strcasecmp(var+ofs, "whitespace"))
+       if (!strcasecmp(var, "whitespace"))
                return DIFF_WHITESPACE;
-       if (!strcasecmp(var+ofs, "func"))
+       if (!strcasecmp(var, "func"))
                return DIFF_FUNCINFO;
        return -1;
 }
@@ -231,6 +231,8 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
 
 int git_diff_basic_config(const char *var, const char *value, void *cb)
 {
+       const char *name;
+
        if (!strcmp(var, "diff.renamelimit")) {
                diff_rename_limit_default = git_config_int(var, value);
                return 0;
@@ -239,8 +241,9 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)
        if (userdiff_config(var, value) < 0)
                return -1;
 
-       if (starts_with(var, "diff.color.") || starts_with(var, "color.diff.")) {
-               int slot = parse_diff_color_slot(var, 11);
+       if (skip_prefix(var, "diff.color.", &name) ||
+           skip_prefix(var, "color.diff.", &name)) {
+               int slot = parse_diff_color_slot(name);
                if (slot < 0)
                        return 0;
                if (!value)
@@ -1361,7 +1364,7 @@ static struct diffstat_file *diffstat_add(struct diffstat_t *diffstat,
                                          const char *name_b)
 {
        struct diffstat_file *x;
-       x = xcalloc(sizeof (*x), 1);
+       x = xcalloc(1, sizeof(*x));
        ALLOC_GROW(diffstat->files, diffstat->nr + 1, diffstat->alloc);
        diffstat->files[diffstat->nr++] = x;
        if (name_b) {
@@ -2341,6 +2344,7 @@ static void builtin_diff(const char *name_a,
        } else {
                /* Crazy xdl interfaces.. */
                const char *diffopts = getenv("GIT_DIFF_OPTS");
+               const char *v;
                xpparam_t xpp;
                xdemitconf_t xecfg;
                struct emit_callback ecbdata;
@@ -2379,10 +2383,10 @@ static void builtin_diff(const char *name_a,
                        xdiff_set_find_func(&xecfg, pe->pattern, pe->cflags);
                if (!diffopts)
                        ;
-               else if (starts_with(diffopts, "--unified="))
-                       xecfg.ctxlen = strtoul(diffopts + 10, NULL, 10);
-               else if (starts_with(diffopts, "-u"))
-                       xecfg.ctxlen = strtoul(diffopts + 2, NULL, 10);
+               else if (skip_prefix(diffopts, "--unified=", &v))
+                       xecfg.ctxlen = strtoul(v, NULL, 10);
+               else if (skip_prefix(diffopts, "-u", &v))
+                       xecfg.ctxlen = strtoul(v, NULL, 10);
                if (o->word_diff)
                        init_diff_words_data(&ecbdata, o, one, two);
                xdi_diff_outf(&mf1, &mf2, fn_out_consume, &ecbdata,
@@ -2880,6 +2884,16 @@ static struct diff_tempfile *prepare_temp_file(const char *name,
        return temp;
 }
 
+static void add_external_diff_name(struct argv_array *argv,
+                                  const char *name,
+                                  struct diff_filespec *df)
+{
+       struct diff_tempfile *temp = prepare_temp_file(name, df);
+       argv_array_push(argv, temp->name);
+       argv_array_push(argv, temp->hex);
+       argv_array_push(argv, temp->mode);
+}
+
 /* An external diff command takes:
  *
  * diff-cmd name infile1 infile1-sha1 infile1-mode \
@@ -2896,48 +2910,32 @@ static void run_external_diff(const char *pgm,
                              struct diff_options *o)
 {
        struct argv_array argv = ARGV_ARRAY_INIT;
-       int retval;
+       struct argv_array env = ARGV_ARRAY_INIT;
        struct diff_queue_struct *q = &diff_queued_diff;
-       const char *env[3] = { NULL };
-       char env_counter[50];
-       char env_total[50];
+
+       argv_array_push(&argv, pgm);
+       argv_array_push(&argv, name);
 
        if (one && two) {
-               struct diff_tempfile *temp_one, *temp_two;
-               const char *othername = (other ? other : name);
-               temp_one = prepare_temp_file(name, one);
-               temp_two = prepare_temp_file(othername, two);
-               argv_array_push(&argv, pgm);
-               argv_array_push(&argv, name);
-               argv_array_push(&argv, temp_one->name);
-               argv_array_push(&argv, temp_one->hex);
-               argv_array_push(&argv, temp_one->mode);
-               argv_array_push(&argv, temp_two->name);
-               argv_array_push(&argv, temp_two->hex);
-               argv_array_push(&argv, temp_two->mode);
-               if (other) {
+               add_external_diff_name(&argv, name, one);
+               if (!other)
+                       add_external_diff_name(&argv, name, two);
+               else {
+                       add_external_diff_name(&argv, other, two);
                        argv_array_push(&argv, other);
                        argv_array_push(&argv, xfrm_msg);
                }
-       } else {
-               argv_array_push(&argv, pgm);
-               argv_array_push(&argv, name);
        }
-       fflush(NULL);
 
-       env[0] = env_counter;
-       snprintf(env_counter, sizeof(env_counter), "GIT_DIFF_PATH_COUNTER=%d",
-                ++o->diff_path_counter);
-       env[1] = env_total;
-       snprintf(env_total, sizeof(env_total), "GIT_DIFF_PATH_TOTAL=%d", q->nr);
+       argv_array_pushf(&env, "GIT_DIFF_PATH_COUNTER=%d", ++o->diff_path_counter);
+       argv_array_pushf(&env, "GIT_DIFF_PATH_TOTAL=%d", q->nr);
+
+       if (run_command_v_opt_cd_env(argv.argv, RUN_USING_SHELL, NULL, env.argv))
+               die(_("external diff died, stopping at %s"), name);
 
-       retval = run_command_v_opt_cd_env(argv.argv, RUN_USING_SHELL, NULL, env);
        remove_tempfile();
        argv_array_clear(&argv);
-       if (retval) {
-               fprintf(stderr, "external diff died, stopping at %s.\n", name);
-               exit(1);
-       }
+       argv_array_clear(&env);
 }
 
 static int similarity_index(struct diff_filepair *p)
@@ -3205,6 +3203,7 @@ void diff_setup(struct diff_options *options)
        options->context = diff_context_default;
        DIFF_OPT_SET(options, RENAME_EMPTY);
 
+       /* pathchange left =NULL by default */
        options->change = diff_change;
        options->add_remove = diff_addremove;
        options->use_color = diff_use_color_default;
@@ -3396,12 +3395,10 @@ int parse_long_opt(const char *opt, const char **argv,
                   const char **optarg)
 {
        const char *arg = argv[0];
-       if (arg[0] != '-' || arg[1] != '-')
+       if (!skip_prefix(arg, "--", &arg))
                return 0;
-       arg += strlen("--");
-       if (!starts_with(arg, opt))
+       if (!skip_prefix(arg, opt, &arg))
                return 0;
-       arg += strlen(opt);
        if (*arg == '=') { /* stuck form: --option=value */
                *optarg = arg + 1;
                return 1;
@@ -3425,13 +3422,13 @@ static int stat_opt(struct diff_options *options, const char **av)
        int count = options->stat_count;
        int argcount = 1;
 
-       arg += strlen("--stat");
+       if (!skip_prefix(arg, "--stat", &arg))
+               die("BUG: stat option does not begin with --stat: %s", arg);
        end = (char *)arg;
 
        switch (*arg) {
        case '-':
-               if (starts_with(arg, "-width")) {
-                       arg += strlen("-width");
+               if (skip_prefix(arg, "-width", &arg)) {
                        if (*arg == '=')
                                width = strtoul(arg + 1, &end, 10);
                        else if (!*arg && !av[1])
@@ -3440,8 +3437,7 @@ static int stat_opt(struct diff_options *options, const char **av)
                                width = strtoul(av[1], &end, 10);
                                argcount = 2;
                        }
-               } else if (starts_with(arg, "-name-width")) {
-                       arg += strlen("-name-width");
+               } else if (skip_prefix(arg, "-name-width", &arg)) {
                        if (*arg == '=')
                                name_width = strtoul(arg + 1, &end, 10);
                        else if (!*arg && !av[1])
@@ -3450,8 +3446,7 @@ static int stat_opt(struct diff_options *options, const char **av)
                                name_width = strtoul(av[1], &end, 10);
                                argcount = 2;
                        }
-               } else if (starts_with(arg, "-graph-width")) {
-                       arg += strlen("-graph-width");
+               } else if (skip_prefix(arg, "-graph-width", &arg)) {
                        if (*arg == '=')
                                graph_width = strtoul(arg + 1, &end, 10);
                        else if (!*arg && !av[1])
@@ -3460,8 +3455,7 @@ static int stat_opt(struct diff_options *options, const char **av)
                                graph_width = strtoul(av[1], &end, 10);
                                argcount = 2;
                        }
-               } else if (starts_with(arg, "-count")) {
-                       arg += strlen("-count");
+               } else if (skip_prefix(arg, "-count", &arg)) {
                        if (*arg == '=')
                                count = strtoul(arg + 1, &end, 10);
                        else if (!*arg && !av[1])
@@ -3614,17 +3608,17 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
                options->output_format |= DIFF_FORMAT_SHORTSTAT;
        else if (!strcmp(arg, "-X") || !strcmp(arg, "--dirstat"))
                return parse_dirstat_opt(options, "");
-       else if (starts_with(arg, "-X"))
-               return parse_dirstat_opt(options, arg + 2);
-       else if (starts_with(arg, "--dirstat="))
-               return parse_dirstat_opt(options, arg + 10);
+       else if (skip_prefix(arg, "-X", &arg))
+               return parse_dirstat_opt(options, arg);
+       else if (skip_prefix(arg, "--dirstat=", &arg))
+               return parse_dirstat_opt(options, arg);
        else if (!strcmp(arg, "--cumulative"))
                return parse_dirstat_opt(options, "cumulative");
        else if (!strcmp(arg, "--dirstat-by-file"))
                return parse_dirstat_opt(options, "files");
-       else if (starts_with(arg, "--dirstat-by-file=")) {
+       else if (skip_prefix(arg, "--dirstat-by-file=", &arg)) {
                parse_dirstat_opt(options, "files");
-               return parse_dirstat_opt(options, arg + 18);
+               return parse_dirstat_opt(options, arg);
        }
        else if (!strcmp(arg, "--check"))
                options->output_format |= DIFF_FORMAT_CHECKDIFF;
@@ -3674,9 +3668,9 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
                DIFF_OPT_CLR(options, RENAME_EMPTY);
        else if (!strcmp(arg, "--relative"))
                DIFF_OPT_SET(options, RELATIVE_NAME);
-       else if (starts_with(arg, "--relative=")) {
+       else if (skip_prefix(arg, "--relative=", &arg)) {
                DIFF_OPT_SET(options, RELATIVE_NAME);
-               options->prefix = arg + 11;
+               options->prefix = arg;
        }
 
        /* xdiff options */
@@ -3727,8 +3721,8 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
                DIFF_OPT_CLR(options, FOLLOW_RENAMES);
        else if (!strcmp(arg, "--color"))
                options->use_color = 1;
-       else if (starts_with(arg, "--color=")) {
-               int value = git_config_colorbool(NULL, arg+8);
+       else if (skip_prefix(arg, "--color=", &arg)) {
+               int value = git_config_colorbool(NULL, arg);
                if (value < 0)
                        return error("option `color' expects \"always\", \"auto\", or \"never\"");
                options->use_color = value;
@@ -3739,29 +3733,28 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
                options->use_color = 1;
                options->word_diff = DIFF_WORDS_COLOR;
        }
-       else if (starts_with(arg, "--color-words=")) {
+       else if (skip_prefix(arg, "--color-words=", &arg)) {
                options->use_color = 1;
                options->word_diff = DIFF_WORDS_COLOR;
-               options->word_regex = arg + 14;
+               options->word_regex = arg;
        }
        else if (!strcmp(arg, "--word-diff")) {
                if (options->word_diff == DIFF_WORDS_NONE)
                        options->word_diff = DIFF_WORDS_PLAIN;
        }
-       else if (starts_with(arg, "--word-diff=")) {
-               const char *type = arg + 12;
-               if (!strcmp(type, "plain"))
+       else if (skip_prefix(arg, "--word-diff=", &arg)) {
+               if (!strcmp(arg, "plain"))
                        options->word_diff = DIFF_WORDS_PLAIN;
-               else if (!strcmp(type, "color")) {
+               else if (!strcmp(arg, "color")) {
                        options->use_color = 1;
                        options->word_diff = DIFF_WORDS_COLOR;
                }
-               else if (!strcmp(type, "porcelain"))
+               else if (!strcmp(arg, "porcelain"))
                        options->word_diff = DIFF_WORDS_PORCELAIN;
-               else if (!strcmp(type, "none"))
+               else if (!strcmp(arg, "none"))
                        options->word_diff = DIFF_WORDS_NONE;
                else
-                       die("bad --word-diff argument: %s", type);
+                       die("bad --word-diff argument: %s", arg);
        }
        else if ((argcount = parse_long_opt("word-diff-regex", av, &optarg))) {
                if (options->word_diff == DIFF_WORDS_NONE)
@@ -3784,13 +3777,13 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
        else if (!strcmp(arg, "--ignore-submodules")) {
                DIFF_OPT_SET(options, OVERRIDE_SUBMODULE_CONFIG);
                handle_ignore_submodules_arg(options, "all");
-       } else if (starts_with(arg, "--ignore-submodules=")) {
+       } else if (skip_prefix(arg, "--ignore-submodules=", &arg)) {
                DIFF_OPT_SET(options, OVERRIDE_SUBMODULE_CONFIG);
-               handle_ignore_submodules_arg(options, arg + 20);
+               handle_ignore_submodules_arg(options, arg);
        } else if (!strcmp(arg, "--submodule"))
                DIFF_OPT_SET(options, SUBMODULE_LOG);
-       else if (starts_with(arg, "--submodule="))
-               return parse_submodule_opt(options, arg + 12);
+       else if (skip_prefix(arg, "--submodule=", &arg))
+               return parse_submodule_opt(options, arg);
 
        /* misc options */
        else if (!strcmp(arg, "-z"))
@@ -3825,8 +3818,8 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
        }
        else if (!strcmp(arg, "--abbrev"))
                options->abbrev = DEFAULT_ABBREV;
-       else if (starts_with(arg, "--abbrev=")) {
-               options->abbrev = strtoul(arg + 9, NULL, 10);
+       else if (skip_prefix(arg, "--abbrev=", &arg)) {
+               options->abbrev = strtoul(arg, NULL, 10);
                if (options->abbrev < MINIMUM_ABBREV)
                        options->abbrev = MINIMUM_ABBREV;
                else if (40 < options->abbrev)
@@ -3907,16 +3900,13 @@ static int diff_scoreopt_parse(const char *opt)
        cmd = *opt++;
        if (cmd == '-') {
                /* convert the long-form arguments into short-form versions */
-               if (starts_with(opt, "break-rewrites")) {
-                       opt += strlen("break-rewrites");
+               if (skip_prefix(opt, "break-rewrites", &opt)) {
                        if (*opt == 0 || *opt++ == '=')
                                cmd = 'B';
-               } else if (starts_with(opt, "find-copies")) {
-                       opt += strlen("find-copies");
+               } else if (skip_prefix(opt, "find-copies", &opt)) {
                        if (*opt == 0 || *opt++ == '=')
                                cmd = 'C';
-               } else if (starts_with(opt, "find-renames")) {
-                       opt += strlen("find-renames");
+               } else if (skip_prefix(opt, "find-renames", &opt)) {
                        if (*opt == 0 || *opt++ == '=')
                                cmd = 'M';
                }
@@ -4752,6 +4742,7 @@ void diffcore_fix_diff_index(struct diff_options *options)
 
 void diffcore_std(struct diff_options *options)
 {
+       /* NOTE please keep the following in sync with diff_tree_combined() */
        if (options->skip_stat_unmatch)
                diffcore_skip_stat_unmatch(options);
        if (!options->found_follow) {
diff --git a/diff.h b/diff.h
index a24a767db78d8e864175cf342f03fc48e159e06e..b4a624d235748bf13be44e7479f086880dcf574f 100644 (file)
--- a/diff.h
+++ b/diff.h
@@ -15,6 +15,10 @@ struct diff_filespec;
 struct userdiff_driver;
 struct sha1_array;
 struct commit;
+struct combine_diff_path;
+
+typedef int (*pathchange_fn_t)(struct diff_options *options,
+                struct combine_diff_path *path);
 
 typedef void (*change_fn_t)(struct diff_options *options,
                 unsigned old_mode, unsigned new_mode,
@@ -157,6 +161,7 @@ struct diff_options {
        int close_file;
 
        struct pathspec pathspec;
+       pathchange_fn_t pathchange;
        change_fn_t change;
        add_remove_fn_t add_remove;
        diff_format_fn_t format_callback;
@@ -189,8 +194,10 @@ const char *diff_line_prefix(struct diff_options *);
 
 extern const char mime_boundary_leader[];
 
-extern int diff_tree(struct tree_desc *t1, struct tree_desc *t2,
-                    const char *base, struct diff_options *opt);
+extern struct combine_diff_path *diff_tree_paths(
+       struct combine_diff_path *p, const unsigned char *sha1,
+       const unsigned char **parent_sha1, int nparent,
+       struct strbuf *base, struct diff_options *opt);
 extern int diff_tree_sha1(const unsigned char *old, const unsigned char *new,
                          const char *base, struct diff_options *opt);
 extern int diff_root_tree_sha1(const unsigned char *new, const char *base,
diff --git a/dir.c b/dir.c
index eb6f581270f81a2e844e3396f966e67d06d27f41..e65888dfad187960bf77904708e60f532ef19e1a 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -508,21 +508,25 @@ void clear_exclude_list(struct exclude_list *el)
 
 static void trim_trailing_spaces(char *buf)
 {
-       int i, last_space = -1, nr_spaces, len = strlen(buf);
-       for (i = 0; i < len; i++)
-               if (buf[i] == '\\')
-                       i++;
-               else if (buf[i] == ' ') {
-                       if (last_space == -1) {
-                               last_space = i;
-                               nr_spaces = 1;
-                       } else
-                               nr_spaces++;
-               } else
-                       last_space = -1;
-
-       if (last_space != -1 && last_space + nr_spaces == len)
-               buf[last_space] = '\0';
+       char *p, *last_space = NULL;
+
+       for (p = buf; *p; p++)
+               switch (*p) {
+               case ' ':
+                       if (!last_space)
+                               last_space = p;
+                       break;
+               case '\\':
+                       p++;
+                       if (!*p)
+                               return;
+                       /* fallthrough */
+               default:
+                       last_space = NULL;
+               }
+
+       if (last_space)
+               *last_space = '\0';
 }
 
 int add_excludes_from_file_to_list(const char *fname,
@@ -1350,8 +1354,7 @@ static int cmp_name(const void *p1, const void *p2)
        const struct dir_entry *e1 = *(const struct dir_entry **)p1;
        const struct dir_entry *e2 = *(const struct dir_entry **)p2;
 
-       return cache_name_compare(e1->name, e1->len,
-                                 e2->name, e2->len);
+       return name_compare(e1->name, e1->len, e2->name, e2->len);
 }
 
 static struct path_simplify *create_simplify(const char **pathspec)
diff --git a/entry.c b/entry.c
index 77c688262477e783b4bcbc237ef281eecab0661d..1eda8e94714bbd6020d61b4b627f721b1042673c 100644 (file)
--- a/entry.c
+++ b/entry.c
@@ -210,9 +210,12 @@ static int write_entry(struct cache_entry *ce,
 
 finish:
        if (state->refresh_cache) {
+               assert(state->istate);
                if (!fstat_done)
                        lstat(ce->name, &st);
                fill_stat_cache_info(ce, &st);
+               ce->ce_flags |= CE_UPDATE_IN_BASE;
+               state->istate->cache_changed |= CE_ENTRY_CHANGED;
        }
        return 0;
 }
index 5c4815dbe132fc358aa55eeb20d86d867c97c37f..565f65293bb25ebdcb6ada262bcca9164c3ea113 100644 (file)
@@ -37,7 +37,7 @@ int core_compression_seen;
 int fsync_object_files;
 size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE;
 size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT;
-size_t delta_base_cache_limit = 16 * 1024 * 1024;
+size_t delta_base_cache_limit = 96 * 1024 * 1024;
 unsigned long big_file_threshold = 512 * 1024 * 1024;
 const char *pager_program;
 int pager_use_color = 1;
@@ -69,9 +69,10 @@ unsigned long pack_size_limit_cfg;
  * that is subject to stripspace.
  */
 char comment_line_char = '#';
+int auto_comment_line_char;
 
 /* Parallel index stat data preload? */
-int core_preload_index = 0;
+int core_preload_index = 1;
 
 /* This is set by setup_git_dir_gently() and/or git_default_config() */
 char *git_work_tree_cfg;
@@ -123,6 +124,12 @@ static char *expand_namespace(const char *raw_namespace)
        return strbuf_detach(&buf, NULL);
 }
 
+static char *git_path_from_env(const char *envvar, const char *path)
+{
+       const char *value = getenv(envvar);
+       return value ? xstrdup(value) : git_pathdup("%s", path);
+}
+
 static void setup_git_env(void)
 {
        const char *gitfile;
@@ -133,19 +140,9 @@ static void setup_git_env(void)
                git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
        gitfile = read_gitfile(git_dir);
        git_dir = xstrdup(gitfile ? gitfile : git_dir);
-       git_object_dir = getenv(DB_ENVIRONMENT);
-       if (!git_object_dir) {
-               git_object_dir = xmalloc(strlen(git_dir) + 9);
-               sprintf(git_object_dir, "%s/objects", git_dir);
-       }
-       git_index_file = getenv(INDEX_ENVIRONMENT);
-       if (!git_index_file) {
-               git_index_file = xmalloc(strlen(git_dir) + 7);
-               sprintf(git_index_file, "%s/index", git_dir);
-       }
-       git_graft_file = getenv(GRAFT_ENVIRONMENT);
-       if (!git_graft_file)
-               git_graft_file = git_pathdup("info/grafts");
+       git_object_dir = git_path_from_env(DB_ENVIRONMENT, "objects");
+       git_index_file = git_path_from_env(INDEX_ENVIRONMENT, "index");
+       git_graft_file = git_path_from_env(GRAFT_ENVIRONMENT, "info/grafts");
        if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT))
                check_replace_refs = 0;
        namespace = expand_namespace(getenv(GIT_NAMESPACE_ENVIRONMENT));
index f7f700ef516eea2fe908f66b1518b5e3a1d9fd33..1c2d7afd4cb9b70a324d355c3d69b732b181012b 100644 (file)
@@ -110,9 +110,9 @@ int ewah_serialize(struct ewah_bitmap *self, int fd)
        return ewah_serialize_to(self, write_helper, (void *)(intptr_t)fd);
 }
 
-int ewah_read_mmap(struct ewah_bitmap *self, void *map, size_t len)
+int ewah_read_mmap(struct ewah_bitmap *self, const void *map, size_t len)
 {
-       uint8_t *ptr = map;
+       const uint8_t *ptr = map;
        size_t i;
 
        self->bit_size = get_be32(ptr);
index 43adeb5c6893381918ea948efa70b4756f831583..f6ad190a038a55e39a0b8b135c995413192f80e3 100644 (file)
@@ -99,8 +99,7 @@ int ewah_serialize(struct ewah_bitmap *self, int fd);
 int ewah_serialize_native(struct ewah_bitmap *self, int fd);
 
 int ewah_deserialize(struct ewah_bitmap *self, int fd);
-int ewah_read_mmap(struct ewah_bitmap *self, void *map, size_t len);
-int ewah_read_mmap_native(struct ewah_bitmap *self, void *map, size_t len);
+int ewah_read_mmap(struct ewah_bitmap *self, const void *map, size_t len);
 
 uint32_t ewah_checksum(struct ewah_bitmap *self);
 
index fb4738d373a5a1048c2ff388a729e6088515ca9b..fa635f75c328354f7a4b44ca1e22461b1eb16de1 100644 (file)
@@ -248,6 +248,7 @@ struct branch {
        uintmax_t last_commit;
        uintmax_t num_notes;
        unsigned active : 1;
+       unsigned delete : 1;
        unsigned pack_id : PACK_ID_BITS;
        unsigned char sha1[20];
 };
@@ -370,8 +371,8 @@ static volatile sig_atomic_t checkpoint_requested;
 static int cat_blob_fd = STDOUT_FILENO;
 
 static void parse_argv(void);
-static void parse_cat_blob(void);
-static void parse_ls(struct branch *b);
+static void parse_cat_blob(const char *p);
+static void parse_ls(const char *p, struct branch *b);
 
 static void write_branch_report(FILE *rpt, struct branch *b)
 {
@@ -1681,10 +1682,13 @@ static int update_branch(struct branch *b)
        struct ref_lock *lock;
        unsigned char old_sha1[20];
 
-       if (is_null_sha1(b->sha1))
-               return 0;
        if (read_ref(b->name, old_sha1))
                hashclr(old_sha1);
+       if (is_null_sha1(b->sha1)) {
+               if (b->delete)
+                       delete_ref(b->name, old_sha1, 0);
+               return 0;
+       }
        lock = lock_any_ref_for_update(b->name, old_sha1, 0, NULL);
        if (!lock)
                return error("Unable to lock %s", b->name);
@@ -1857,6 +1861,8 @@ static int read_next_command(void)
        }
 
        for (;;) {
+               const char *p;
+
                if (unread_command_buf) {
                        unread_command_buf = 0;
                } else {
@@ -1889,8 +1895,8 @@ static int read_next_command(void)
                        rc->prev->next = rc;
                        cmd_tail = rc;
                }
-               if (starts_with(command_buf.buf, "cat-blob ")) {
-                       parse_cat_blob();
+               if (skip_prefix(command_buf.buf, "cat-blob ", &p)) {
+                       parse_cat_blob(p);
                        continue;
                }
                if (command_buf.buf[0] == '#')
@@ -1908,8 +1914,9 @@ static void skip_optional_lf(void)
 
 static void parse_mark(void)
 {
-       if (starts_with(command_buf.buf, "mark :")) {
-               next_mark = strtoumax(command_buf.buf + 6, NULL, 10);
+       const char *v;
+       if (skip_prefix(command_buf.buf, "mark :", &v)) {
+               next_mark = strtoumax(v, NULL, 10);
                read_next_command();
        }
        else
@@ -1918,14 +1925,15 @@ static void parse_mark(void)
 
 static int parse_data(struct strbuf *sb, uintmax_t limit, uintmax_t *len_res)
 {
+       const char *data;
        strbuf_reset(sb);
 
-       if (!starts_with(command_buf.buf, "data "))
+       if (!skip_prefix(command_buf.buf, "data ", &data))
                die("Expected 'data n' command, found: %s", command_buf.buf);
 
-       if (starts_with(command_buf.buf + 5, "<<")) {
-               char *term = xstrdup(command_buf.buf + 5 + 2);
-               size_t term_len = command_buf.len - 5 - 2;
+       if (skip_prefix(data, "<<", &data)) {
+               char *term = xstrdup(data);
+               size_t term_len = command_buf.len - (data - command_buf.buf);
 
                strbuf_detach(&command_buf, NULL);
                for (;;) {
@@ -1940,7 +1948,7 @@ static int parse_data(struct strbuf *sb, uintmax_t limit, uintmax_t *len_res)
                free(term);
        }
        else {
-               uintmax_t len = strtoumax(command_buf.buf + 5, NULL, 10);
+               uintmax_t len = strtoumax(data, NULL, 10);
                size_t n = 0, length = (size_t)len;
 
                if (limit && limit < len) {
@@ -2261,15 +2269,14 @@ static uintmax_t parse_mark_ref_space(const char **p)
        char *end;
 
        mark = parse_mark_ref(*p, &end);
-       if (*end != ' ')
+       if (*end++ != ' ')
                die("Missing space after mark: %s", command_buf.buf);
        *p = end;
        return mark;
 }
 
-static void file_change_m(struct branch *b)
+static void file_change_m(const char *p, struct branch *b)
 {
-       const char *p = command_buf.buf + 2;
        static struct strbuf uq = STRBUF_INIT;
        const char *endp;
        struct object_entry *oe;
@@ -2297,20 +2304,17 @@ static void file_change_m(struct branch *b)
        if (*p == ':') {
                oe = find_mark(parse_mark_ref_space(&p));
                hashcpy(sha1, oe->idx.sha1);
-       } else if (starts_with(p, "inline ")) {
+       } else if (skip_prefix(p, "inline ", &p)) {
                inline_data = 1;
                oe = NULL; /* not used with inline_data, but makes gcc happy */
-               p += strlen("inline");  /* advance to space */
        } else {
                if (get_sha1_hex(p, sha1))
                        die("Invalid dataref: %s", command_buf.buf);
                oe = find_object(sha1);
                p += 40;
-               if (*p != ' ')
+               if (*p++ != ' ')
                        die("Missing space after SHA1: %s", command_buf.buf);
        }
-       assert(*p == ' ');
-       p++;  /* skip space */
 
        strbuf_reset(&uq);
        if (!unquote_c_style(&uq, p, &endp)) {
@@ -2370,9 +2374,8 @@ static void file_change_m(struct branch *b)
        tree_content_set(&b->branch_tree, p, sha1, mode, NULL);
 }
 
-static void file_change_d(struct branch *b)
+static void file_change_d(const char *p, struct branch *b)
 {
-       const char *p = command_buf.buf + 2;
        static struct strbuf uq = STRBUF_INIT;
        const char *endp;
 
@@ -2385,15 +2388,14 @@ static void file_change_d(struct branch *b)
        tree_content_remove(&b->branch_tree, p, NULL, 1);
 }
 
-static void file_change_cr(struct branch *b, int rename)
+static void file_change_cr(const char *s, struct branch *b, int rename)
 {
-       const char *s, *d;
+       const char *d;
        static struct strbuf s_uq = STRBUF_INIT;
        static struct strbuf d_uq = STRBUF_INIT;
        const char *endp;
        struct tree_entry leaf;
 
-       s = command_buf.buf + 2;
        strbuf_reset(&s_uq);
        if (!unquote_c_style(&s_uq, s, &endp)) {
                if (*endp != ' ')
@@ -2438,9 +2440,8 @@ static void file_change_cr(struct branch *b, int rename)
                leaf.tree);
 }
 
-static void note_change_n(struct branch *b, unsigned char *old_fanout)
+static void note_change_n(const char *p, struct branch *b, unsigned char *old_fanout)
 {
-       const char *p = command_buf.buf + 2;
        static struct strbuf uq = STRBUF_INIT;
        struct object_entry *oe;
        struct branch *s;
@@ -2470,20 +2471,17 @@ static void note_change_n(struct branch *b, unsigned char *old_fanout)
        if (*p == ':') {
                oe = find_mark(parse_mark_ref_space(&p));
                hashcpy(sha1, oe->idx.sha1);
-       } else if (starts_with(p, "inline ")) {
+       } else if (skip_prefix(p, "inline ", &p)) {
                inline_data = 1;
                oe = NULL; /* not used with inline_data, but makes gcc happy */
-               p += strlen("inline");  /* advance to space */
        } else {
                if (get_sha1_hex(p, sha1))
                        die("Invalid dataref: %s", command_buf.buf);
                oe = find_object(sha1);
                p += 40;
-               if (*p != ' ')
+               if (*p++ != ' ')
                        die("Missing space after SHA1: %s", command_buf.buf);
        }
-       assert(*p == ' ');
-       p++;  /* skip space */
 
        /* <commit-ish> */
        s = lookup_branch(p);
@@ -2581,7 +2579,7 @@ static int parse_from(struct branch *b)
        const char *from;
        struct branch *s;
 
-       if (!starts_with(command_buf.buf, "from "))
+       if (!skip_prefix(command_buf.buf, "from ", &from))
                return 0;
 
        if (b->branch_tree.tree) {
@@ -2589,7 +2587,6 @@ static int parse_from(struct branch *b)
                b->branch_tree.tree = NULL;
        }
 
-       from = strchr(command_buf.buf, ' ') + 1;
        s = lookup_branch(from);
        if (b == s)
                die("Can't create a branch from itself: %s", b->name);
@@ -2611,8 +2608,11 @@ static int parse_from(struct branch *b)
                        free(buf);
                } else
                        parse_from_existing(b);
-       } else if (!get_sha1(from, b->sha1))
+       } else if (!get_sha1(from, b->sha1)) {
                parse_from_existing(b);
+               if (is_null_sha1(b->sha1))
+                       b->delete = 1;
+       }
        else
                die("Invalid ref name or SHA1 expression: %s", from);
 
@@ -2627,8 +2627,7 @@ static struct hash_list *parse_merge(unsigned int *count)
        struct branch *s;
 
        *count = 0;
-       while (starts_with(command_buf.buf, "merge ")) {
-               from = strchr(command_buf.buf, ' ') + 1;
+       while (skip_prefix(command_buf.buf, "merge ", &from)) {
                n = xmalloc(sizeof(*n));
                s = lookup_branch(from);
                if (s)
@@ -2659,31 +2658,29 @@ static struct hash_list *parse_merge(unsigned int *count)
        return list;
 }
 
-static void parse_new_commit(void)
+static void parse_new_commit(const char *arg)
 {
        static struct strbuf msg = STRBUF_INIT;
        struct branch *b;
-       char *sp;
        char *author = NULL;
        char *committer = NULL;
        struct hash_list *merge_list = NULL;
        unsigned int merge_count;
        unsigned char prev_fanout, new_fanout;
+       const char *v;
 
-       /* Obtain the branch name from the rest of our command */
-       sp = strchr(command_buf.buf, ' ') + 1;
-       b = lookup_branch(sp);
+       b = lookup_branch(arg);
        if (!b)
-               b = new_branch(sp);
+               b = new_branch(arg);
 
        read_next_command();
        parse_mark();
-       if (starts_with(command_buf.buf, "author ")) {
-               author = parse_ident(command_buf.buf + 7);
+       if (skip_prefix(command_buf.buf, "author ", &v)) {
+               author = parse_ident(v);
                read_next_command();
        }
-       if (starts_with(command_buf.buf, "committer ")) {
-               committer = parse_ident(command_buf.buf + 10);
+       if (skip_prefix(command_buf.buf, "committer ", &v)) {
+               committer = parse_ident(v);
                read_next_command();
        }
        if (!committer)
@@ -2703,20 +2700,20 @@ static void parse_new_commit(void)
 
        /* file_change* */
        while (command_buf.len > 0) {
-               if (starts_with(command_buf.buf, "M "))
-                       file_change_m(b);
-               else if (starts_with(command_buf.buf, "D "))
-                       file_change_d(b);
-               else if (starts_with(command_buf.buf, "R "))
-                       file_change_cr(b, 1);
-               else if (starts_with(command_buf.buf, "C "))
-                       file_change_cr(b, 0);
-               else if (starts_with(command_buf.buf, "N "))
-                       note_change_n(b, &prev_fanout);
+               if (skip_prefix(command_buf.buf, "M ", &v))
+                       file_change_m(v, b);
+               else if (skip_prefix(command_buf.buf, "D ", &v))
+                       file_change_d(v, b);
+               else if (skip_prefix(command_buf.buf, "R ", &v))
+                       file_change_cr(v, b, 1);
+               else if (skip_prefix(command_buf.buf, "C ", &v))
+                       file_change_cr(v, b, 0);
+               else if (skip_prefix(command_buf.buf, "N ", &v))
+                       note_change_n(v, b, &prev_fanout);
                else if (!strcmp("deleteall", command_buf.buf))
                        file_change_deleteall(b);
-               else if (starts_with(command_buf.buf, "ls "))
-                       parse_ls(b);
+               else if (skip_prefix(command_buf.buf, "ls ", &v))
+                       parse_ls(v, b);
                else {
                        unread_command_buf = 1;
                        break;
@@ -2759,10 +2756,9 @@ static void parse_new_commit(void)
        b->last_commit = object_count_by_type[OBJ_COMMIT];
 }
 
-static void parse_new_tag(void)
+static void parse_new_tag(const char *arg)
 {
        static struct strbuf msg = STRBUF_INIT;
-       char *sp;
        const char *from;
        char *tagger;
        struct branch *s;
@@ -2770,12 +2766,11 @@ static void parse_new_tag(void)
        uintmax_t from_mark = 0;
        unsigned char sha1[20];
        enum object_type type;
+       const char *v;
 
-       /* Obtain the new tag name from the rest of our command */
-       sp = strchr(command_buf.buf, ' ') + 1;
        t = pool_alloc(sizeof(struct tag));
        memset(t, 0, sizeof(struct tag));
-       t->name = pool_strdup(sp);
+       t->name = pool_strdup(arg);
        if (last_tag)
                last_tag->next_tag = t;
        else
@@ -2784,9 +2779,8 @@ static void parse_new_tag(void)
        read_next_command();
 
        /* from ... */
-       if (!starts_with(command_buf.buf, "from "))
+       if (!skip_prefix(command_buf.buf, "from ", &from))
                die("Expected from command, got %s", command_buf.buf);
-       from = strchr(command_buf.buf, ' ') + 1;
        s = lookup_branch(from);
        if (s) {
                if (is_null_sha1(s->sha1))
@@ -2812,8 +2806,8 @@ static void parse_new_tag(void)
        read_next_command();
 
        /* tagger ... */
-       if (starts_with(command_buf.buf, "tagger ")) {
-               tagger = parse_ident(command_buf.buf + 7);
+       if (skip_prefix(command_buf.buf, "tagger ", &v)) {
+               tagger = parse_ident(v);
                read_next_command();
        } else
                tagger = NULL;
@@ -2842,14 +2836,11 @@ static void parse_new_tag(void)
                t->pack_id = pack_id;
 }
 
-static void parse_reset_branch(void)
+static void parse_reset_branch(const char *arg)
 {
        struct branch *b;
-       char *sp;
 
-       /* Obtain the branch name from the rest of our command */
-       sp = strchr(command_buf.buf, ' ') + 1;
-       b = lookup_branch(sp);
+       b = lookup_branch(arg);
        if (b) {
                hashclr(b->sha1);
                hashclr(b->branch_tree.versions[0].sha1);
@@ -2860,7 +2851,7 @@ static void parse_reset_branch(void)
                }
        }
        else
-               b = new_branch(sp);
+               b = new_branch(arg);
        read_next_command();
        parse_from(b);
        if (command_buf.len > 0)
@@ -2918,14 +2909,12 @@ static void cat_blob(struct object_entry *oe, unsigned char sha1[20])
                free(buf);
 }
 
-static void parse_cat_blob(void)
+static void parse_cat_blob(const char *p)
 {
-       const char *p;
        struct object_entry *oe = oe;
        unsigned char sha1[20];
 
        /* cat-blob SP <object> LF */
-       p = command_buf.buf + strlen("cat-blob ");
        if (*p == ':') {
                oe = find_mark(parse_mark_ref_eol(p));
                if (!oe)
@@ -3008,6 +2997,8 @@ static struct object_entry *parse_treeish_dataref(const char **p)
                        die("Invalid dataref: %s", command_buf.buf);
                e = find_object(sha1);
                *p += 40;
+               if (*(*p)++ != ' ')
+                       die("Missing space after tree-ish: %s", command_buf.buf);
        }
 
        while (!e || e->type != OBJ_TREE)
@@ -3042,14 +3033,12 @@ static void print_ls(int mode, const unsigned char *sha1, const char *path)
        cat_blob_write(line.buf, line.len);
 }
 
-static void parse_ls(struct branch *b)
+static void parse_ls(const char *p, struct branch *b)
 {
-       const char *p;
        struct tree_entry *root = NULL;
        struct tree_entry leaf = {NULL};
 
        /* ls SP (<tree-ish> SP)? <path> */
-       p = command_buf.buf + strlen("ls ");
        if (*p == '"') {
                if (!b)
                        die("Not in a commit: %s", command_buf.buf);
@@ -3061,8 +3050,6 @@ static void parse_ls(struct branch *b)
                if (!is_null_sha1(root->versions[1].sha1))
                        root->versions[1].mode = S_IFDIR;
                load_tree(root);
-               if (*p++ != ' ')
-                       die("Missing space after tree-ish: %s", command_buf.buf);
        }
        if (*p == '"') {
                static struct strbuf uq = STRBUF_INIT;
@@ -3200,9 +3187,9 @@ static void option_export_pack_edges(const char *edges)
 
 static int parse_one_option(const char *option)
 {
-       if (starts_with(option, "max-pack-size=")) {
+       if (skip_prefix(option, "max-pack-size=", &option)) {
                unsigned long v;
-               if (!git_parse_ulong(option + 14, &v))
+               if (!git_parse_ulong(option, &v))
                        return 0;
                if (v < 8192) {
                        warning("max-pack-size is now in bytes, assuming --max-pack-size=%lum", v);
@@ -3212,17 +3199,17 @@ static int parse_one_option(const char *option)
                        v = 1024 * 1024;
                }
                max_packsize = v;
-       } else if (starts_with(option, "big-file-threshold=")) {
+       } else if (skip_prefix(option, "big-file-threshold=", &option)) {
                unsigned long v;
-               if (!git_parse_ulong(option + 19, &v))
+               if (!git_parse_ulong(option, &v))
                        return 0;
                big_file_threshold = v;
-       } else if (starts_with(option, "depth=")) {
-               option_depth(option + 6);
-       } else if (starts_with(option, "active-branches=")) {
-               option_active_branches(option + 16);
-       } else if (starts_with(option, "export-pack-edges=")) {
-               option_export_pack_edges(option + 18);
+       } else if (skip_prefix(option, "depth=", &option)) {
+               option_depth(option);
+       } else if (skip_prefix(option, "active-branches=", &option)) {
+               option_active_branches(option);
+       } else if (skip_prefix(option, "export-pack-edges=", &option)) {
+               option_export_pack_edges(option);
        } else if (starts_with(option, "quiet")) {
                show_stats = 0;
        } else if (starts_with(option, "stats")) {
@@ -3236,15 +3223,16 @@ static int parse_one_option(const char *option)
 
 static int parse_one_feature(const char *feature, int from_stream)
 {
-       if (starts_with(feature, "date-format=")) {
-               option_date_format(feature + 12);
-       } else if (starts_with(feature, "import-marks=")) {
-               option_import_marks(feature + 13, from_stream, 0);
-       } else if (starts_with(feature, "import-marks-if-exists=")) {
-               option_import_marks(feature + strlen("import-marks-if-exists="),
-                                       from_stream, 1);
-       } else if (starts_with(feature, "export-marks=")) {
-               option_export_marks(feature + 13);
+       const char *arg;
+
+       if (skip_prefix(feature, "date-format=", &arg)) {
+               option_date_format(arg);
+       } else if (skip_prefix(feature, "import-marks=", &arg)) {
+               option_import_marks(arg, from_stream, 0);
+       } else if (skip_prefix(feature, "import-marks-if-exists=", &arg)) {
+               option_import_marks(arg, from_stream, 1);
+       } else if (skip_prefix(feature, "export-marks=", &arg)) {
+               option_export_marks(arg);
        } else if (!strcmp(feature, "cat-blob")) {
                ; /* Don't die - this feature is supported */
        } else if (!strcmp(feature, "relative-marks")) {
@@ -3264,10 +3252,8 @@ static int parse_one_feature(const char *feature, int from_stream)
        return 1;
 }
 
-static void parse_feature(void)
+static void parse_feature(const char *feature)
 {
-       char *feature = command_buf.buf + 8;
-
        if (seen_data_command)
                die("Got feature command '%s' after data command", feature);
 
@@ -3277,10 +3263,8 @@ static void parse_feature(void)
        die("This version of fast-import does not support feature %s.", feature);
 }
 
-static void parse_option(void)
+static void parse_option(const char *option)
 {
-       char *option = command_buf.buf + 11;
-
        if (seen_data_command)
                die("Got option command '%s' after data command", option);
 
@@ -3335,18 +3319,21 @@ static void parse_argv(void)
                if (*a != '-' || !strcmp(a, "--"))
                        break;
 
-               if (parse_one_option(a + 2))
+               if (!skip_prefix(a, "--", &a))
+                       die("unknown option %s", a);
+
+               if (parse_one_option(a))
                        continue;
 
-               if (parse_one_feature(a + 2, 0))
+               if (parse_one_feature(a, 0))
                        continue;
 
-               if (starts_with(a + 2, "cat-blob-fd=")) {
-                       option_cat_blob_fd(a + 2 + strlen("cat-blob-fd="));
+               if (skip_prefix(a, "cat-blob-fd=", &a)) {
+                       option_cat_blob_fd(a);
                        continue;
                }
 
-               die("unknown option %s", a);
+               die("unknown option --%s", a);
        }
        if (i != global_argc)
                usage(fast_import_usage);
@@ -3393,26 +3380,27 @@ int main(int argc, char **argv)
        set_die_routine(die_nicely);
        set_checkpoint_signal();
        while (read_next_command() != EOF) {
+               const char *v;
                if (!strcmp("blob", command_buf.buf))
                        parse_new_blob();
-               else if (starts_with(command_buf.buf, "ls "))
-                       parse_ls(NULL);
-               else if (starts_with(command_buf.buf, "commit "))
-                       parse_new_commit();
-               else if (starts_with(command_buf.buf, "tag "))
-                       parse_new_tag();
-               else if (starts_with(command_buf.buf, "reset "))
-                       parse_reset_branch();
+               else if (skip_prefix(command_buf.buf, "ls ", &v))
+                       parse_ls(v, NULL);
+               else if (skip_prefix(command_buf.buf, "commit ", &v))
+                       parse_new_commit(v);
+               else if (skip_prefix(command_buf.buf, "tag ", &v))
+                       parse_new_tag(v);
+               else if (skip_prefix(command_buf.buf, "reset ", &v))
+                       parse_reset_branch(v);
                else if (!strcmp("checkpoint", command_buf.buf))
                        parse_checkpoint();
                else if (!strcmp("done", command_buf.buf))
                        break;
                else if (starts_with(command_buf.buf, "progress "))
                        parse_progress();
-               else if (starts_with(command_buf.buf, "feature "))
-                       parse_feature();
-               else if (starts_with(command_buf.buf, "option git "))
-                       parse_option();
+               else if (skip_prefix(command_buf.buf, "feature ", &v))
+                       parse_feature(v);
+               else if (skip_prefix(command_buf.buf, "option git ", &v))
+                       parse_option(v);
                else if (starts_with(command_buf.buf, "option "))
                        /* ignore non-git options*/;
                else
index eeee2bb7e08a21dfe091a30c8378da6d488228f5..b8a58fa7a542fe166ad71c9b17a4908c81d24a4f 100644 (file)
@@ -189,20 +189,23 @@ static enum ack_type get_ack(int fd, unsigned char *result_sha1)
 {
        int len;
        char *line = packet_read_line(fd, &len);
+       const char *arg;
 
        if (!len)
                die("git fetch-pack: expected ACK/NAK, got EOF");
        if (!strcmp(line, "NAK"))
                return NAK;
-       if (starts_with(line, "ACK ")) {
-               if (!get_sha1_hex(line+4, result_sha1)) {
-                       if (len < 45)
+       if (skip_prefix(line, "ACK ", &arg)) {
+               if (!get_sha1_hex(arg, result_sha1)) {
+                       arg += 40;
+                       len -= arg - line;
+                       if (len < 1)
                                return ACK;
-                       if (strstr(line+45, "continue"))
+                       if (strstr(arg, "continue"))
                                return ACK_continue;
-                       if (strstr(line+45, "common"))
+                       if (strstr(arg, "common"))
                                return ACK_common;
-                       if (strstr(line+45, "ready"))
+                       if (strstr(arg, "ready"))
                                return ACK_ready;
                        return ACK;
                }
@@ -319,18 +322,19 @@ static int find_common(struct fetch_pack_args *args,
 
        if (args->depth > 0) {
                char *line;
+               const char *arg;
                unsigned char sha1[20];
 
                send_request(args, fd[1], &req_buf);
                while ((line = packet_read_line(fd[0], NULL))) {
-                       if (starts_with(line, "shallow ")) {
-                               if (get_sha1_hex(line + 8, sha1))
+                       if (skip_prefix(line, "shallow ", &arg)) {
+                               if (get_sha1_hex(arg, sha1))
                                        die("invalid shallow line: %s", line);
                                register_shallow(sha1);
                                continue;
                        }
-                       if (starts_with(line, "unshallow ")) {
-                               if (get_sha1_hex(line + 10, sha1))
+                       if (skip_prefix(line, "unshallow ", &arg)) {
+                               if (get_sha1_hex(arg, sha1))
                                        die("invalid unshallow line: %s", line);
                                if (!lookup_object(sha1))
                                        die("object not found: %s", line);
@@ -507,7 +511,7 @@ static void filter_refs(struct fetch_pack_args *args,
                int keep = 0;
                next = ref->next;
 
-               if (!memcmp(ref->name, "refs/", 5) &&
+               if (starts_with(ref->name, "refs/") &&
                    check_refname_format(ref->name, 0))
                        ; /* trash */
                else {
diff --git a/fsck.c b/fsck.c
index abed62bac77c67e7c7447a18fea75f228406baac..a4e8593e78c85c244d2dc8bac0cca838c14bbd4a 100644 (file)
--- a/fsck.c
+++ b/fsck.c
@@ -276,22 +276,20 @@ static int fsck_ident(const char **ident, struct object *obj, fsck_error error_f
        return 0;
 }
 
-static int fsck_commit(struct commit *commit, fsck_error error_func)
+static int fsck_commit_buffer(struct commit *commit, const char *buffer,
+                             fsck_error error_func)
 {
-       const char *buffer = commit->buffer, *tmp;
        unsigned char tree_sha1[20], sha1[20];
        struct commit_graft *graft;
        int parents = 0;
        int err;
 
-       buffer = skip_prefix(buffer, "tree ");
-       if (!buffer)
+       if (!skip_prefix(buffer, "tree ", &buffer))
                return error_func(&commit->object, FSCK_ERROR, "invalid format - expected 'tree' line");
        if (get_sha1_hex(buffer, tree_sha1) || buffer[40] != '\n')
                return error_func(&commit->object, FSCK_ERROR, "invalid 'tree' line format - bad sha1");
        buffer += 41;
-       while ((tmp = skip_prefix(buffer, "parent "))) {
-               buffer = tmp;
+       while (skip_prefix(buffer, "parent ", &buffer)) {
                if (get_sha1_hex(buffer, sha1) || buffer[40] != '\n')
                        return error_func(&commit->object, FSCK_ERROR, "invalid 'parent' line format - bad sha1");
                buffer += 41;
@@ -318,14 +316,12 @@ static int fsck_commit(struct commit *commit, fsck_error error_func)
                if (p || parents)
                        return error_func(&commit->object, FSCK_ERROR, "parent objects missing");
        }
-       buffer = skip_prefix(buffer, "author ");
-       if (!buffer)
+       if (!skip_prefix(buffer, "author ", &buffer))
                return error_func(&commit->object, FSCK_ERROR, "invalid format - expected 'author' line");
        err = fsck_ident(&buffer, &commit->object, error_func);
        if (err)
                return err;
-       buffer = skip_prefix(buffer, "committer ");
-       if (!buffer)
+       if (!skip_prefix(buffer, "committer ", &buffer))
                return error_func(&commit->object, FSCK_ERROR, "invalid format - expected 'committer' line");
        err = fsck_ident(&buffer, &commit->object, error_func);
        if (err)
@@ -336,6 +332,14 @@ static int fsck_commit(struct commit *commit, fsck_error error_func)
        return 0;
 }
 
+static int fsck_commit(struct commit *commit, fsck_error error_func)
+{
+       const char *buffer = get_commit_buffer(commit, NULL);
+       int ret = fsck_commit_buffer(commit, buffer, error_func);
+       unuse_commit_buffer(commit, buffer);
+       return ret;
+}
+
 static int fsck_tag(struct tag *tag, fsck_error error_func)
 {
        struct object *tagged = tag->tagged;
index af4d04c3be87423d3c9ef6078766fff679411766..1e0d602f4b156929b74d10546cf5a5ba0f8518dd 100755 (executable)
@@ -408,7 +408,7 @@ bisect_replay () {
        bisect_reset
        while read git bisect command rev
        do
-               test "$git $bisect" = "git bisect" -o "$git" = "git-bisect" || continue
+               test "$git $bisect" = "git bisect" || test "$git" = "git-bisect" || continue
                if test "$git" = "git-bisect"
                then
                        rev="$command"
index e6a4159a25ea2c4f98840b86994425e898cf134c..0b53c9a4af3c7e1d5611065b35ef38f3f1f5e5be 100644 (file)
@@ -267,6 +267,10 @@ extern char *gitbasename(char *);
 #define has_dos_drive_prefix(path) 0
 #endif
 
+#ifndef offset_1st_component
+#define offset_1st_component(path) (is_dir_sep((path)[0]))
+#endif
+
 #ifndef is_dir_sep
 #define is_dir_sep(c) ((c) == '/')
 #endif
@@ -330,8 +334,12 @@ extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)))
  * trying to help gcc, anyway, it's OK; other compilers will fall back to
  * using the function as usual.
  */
-#if defined(__GNUC__) && ! defined(__clang__)
-#define error(...) (error(__VA_ARGS__), -1)
+#if defined(__GNUC__)
+static inline int const_error(void)
+{
+       return -1;
+}
+#define error(...) (error(__VA_ARGS__), const_error())
 #endif
 
 extern void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_list params));
@@ -339,15 +347,66 @@ extern void set_error_routine(void (*routine)(const char *err, va_list params));
 extern void set_die_is_recursing_routine(int (*routine)(void));
 
 extern int starts_with(const char *str, const char *prefix);
-extern int ends_with(const char *str, const char *suffix);
 
-static inline const char *skip_prefix(const char *str, const char *prefix)
+/*
+ * If the string "str" begins with the string found in "prefix", return 1.
+ * The "out" parameter is set to "str + strlen(prefix)" (i.e., to the point in
+ * the string right after the prefix).
+ *
+ * Otherwise, return 0 and leave "out" untouched.
+ *
+ * Examples:
+ *
+ *   [extract branch name, fail if not a branch]
+ *   if (!skip_prefix(ref, "refs/heads/", &branch)
+ *     return -1;
+ *
+ *   [skip prefix if present, otherwise use whole string]
+ *   skip_prefix(name, "refs/heads/", &name);
+ */
+static inline int skip_prefix(const char *str, const char *prefix,
+                             const char **out)
 {
        do {
-               if (!*prefix)
-                       return str;
+               if (!*prefix) {
+                       *out = str;
+                       return 1;
+               }
        } while (*str++ == *prefix++);
-       return NULL;
+       return 0;
+}
+
+/*
+ * If buf ends with suffix, return 1 and subtract the length of the suffix
+ * from *len. Otherwise, return 0 and leave *len untouched.
+ */
+static inline int strip_suffix_mem(const char *buf, size_t *len,
+                                  const char *suffix)
+{
+       size_t suflen = strlen(suffix);
+       if (*len < suflen || memcmp(buf + (*len - suflen), suffix, suflen))
+               return 0;
+       *len -= suflen;
+       return 1;
+}
+
+/*
+ * If str ends with suffix, return 1 and set *len to the size of the string
+ * without the suffix. Otherwise, return 0 and set *len to the size of the
+ * string.
+ *
+ * Note that we do _not_ NUL-terminate str to the new length.
+ */
+static inline int strip_suffix(const char *str, const char *suffix, size_t *len)
+{
+       *len = strlen(str);
+       return strip_suffix_mem(str, len, suffix);
+}
+
+static inline int ends_with(const char *str, const char *suffix)
+{
+       size_t len;
+       return strip_suffix(str, suffix, &len);
 }
 
 #if defined(NO_MMAP) || defined(USE_WIN32_MMAP)
@@ -521,6 +580,14 @@ extern void release_pack_memory(size_t);
 typedef void (*try_to_free_t)(size_t);
 extern try_to_free_t set_try_to_free_routine(try_to_free_t);
 
+#ifdef HAVE_ALLOCA_H
+# include <alloca.h>
+# define xalloca(size)      (alloca(size))
+# define xalloca_free(p)    do {} while (0)
+#else
+# define xalloca(size)      (xmalloc(size))
+# define xalloca_free(p)    (free(p))
+#endif
 extern char *xstrdup(const char *str);
 extern void *xmalloc(size_t size);
 extern void *xmallocz(size_t size);
@@ -546,13 +613,6 @@ static inline size_t xsize_t(off_t len)
        return (size_t)len;
 }
 
-static inline int has_extension(const char *filename, const char *ext)
-{
-       size_t len = strlen(filename);
-       size_t extlen = strlen(ext);
-       return len > extlen && !memcmp(filename + len - extlen, ext, extlen);
-}
-
 /* in ctype.c, for kwset users */
 extern const char tolower_trans_tbl[256];
 
@@ -669,6 +729,17 @@ void git_qsort(void *base, size_t nmemb, size_t size,
 #endif
 #endif
 
+#if defined(__GNUC__) && defined(__x86_64__)
+#include <emmintrin.h>
+/*
+ * This is the system memory page size; it's used so that we can read
+ * outside the bounds of an allocation without segfaulting.
+ */
+#ifndef PAGE_SIZE
+#define PAGE_SIZE 4096
+#endif
+#endif
+
 #ifdef UNRELIABLE_FSTAT
 #define fstat_is_reliable() 0
 #else
index 86d6994619151fb63327848e6763b07971017ad7..e6e99f5bb5102d394a25f156dbcba956f246054b 100755 (executable)
@@ -332,7 +332,13 @@ while read commit parents; do
        parentstr=
        for parent in $parents; do
                for reparent in $(map "$parent"); do
-                       parentstr="$parentstr -p $reparent"
+                       case "$parentstr " in
+                       *" -p $reparent "*)
+                               ;;
+                       *)
+                               parentstr="$parentstr -p $reparent"
+                               ;;
+                       esac
                done
        done
        if [ "$filter_parent" ]; then
index 6a8907e7b327d066c616f8f77c2bc2096d618e06..b186329d28c07825992fad039746df8563a92c3b 100755 (executable)
@@ -1558,7 +1558,11 @@ proc rescan_stage2 {fd after} {
 
        set rescan_active 2
        ui_status [mc "Scanning for modified files ..."]
-       set fd_di [git_read diff-index --cached -z [PARENT]]
+       if {[git-version >= "1.7.2"]} {
+               set fd_di [git_read diff-index --cached --ignore-submodules=dirty -z [PARENT]]
+       } else {
+               set fd_di [git_read diff-index --cached -z [PARENT]]
+       }
        set fd_df [git_read diff-files -z]
 
        fconfigure $fd_di -blocking 0 -translation binary -encoding binary
index 30d9a797769b49cdd9d42fba925d8fa8ecbffb21..b0a5180af71ac04c58d2dd44664df98b67d3a770 100644 (file)
@@ -287,6 +287,9 @@ proc start_show_diff {cont_info {add_opts {}}} {
        if {$w eq $ui_index} {
                lappend cmd diff-index
                lappend cmd --cached
+               if {[git-version >= "1.7.2"]} {
+                       lappend cmd --ignore-submodules=dirty
+               }
        } elseif {$w eq $ui_workdir} {
                if {[string first {U} $m] >= 0} {
                        lappend cmd diff
index 4aa3eb80fd25a803d291631965d009a49cfe79dc..513efa662e86cb157b8690bfb025556fa0c836f0 100755 (executable)
@@ -345,7 +345,17 @@ PidFile "$fqgitdir/pid"
 Listen $bind$port
 EOF
 
-       for mod in mime dir env log_config
+       for mod in mpm_event mpm_prefork mpm_worker
+       do
+               if test -e $module_path/mod_${mod}.so
+               then
+                       echo "LoadModule ${mod}_module " \
+                            "$module_path/mod_${mod}.so" >> "$conf"
+                       # only one mpm module permitted
+                       break
+               fi
+       done
+       for mod in mime dir env log_config authz_core
        do
                if test -e $module_path/mod_${mod}.so
                then
index 332528ff4556116f9ff22c257e49825954a183fb..9a046b75d1dd810202d784d3fffe8afe6dd1963c 100755 (executable)
@@ -205,7 +205,7 @@ checkout_staged_file () {
                "$(git checkout-index --temp --stage="$1" "$2" 2>/dev/null)" \
                : '\([^ ]*\)    ')
 
-       if test $? -eq 0 -a -n "$tmpfile"
+       if test $? -eq 0 && test -n "$tmpfile"
        then
                mv -- "$(git rev-parse --show-cdup)$tmpfile" "$3"
        else
@@ -256,7 +256,7 @@ merge_file () {
        checkout_staged_file 2 "$MERGED" "$LOCAL"
        checkout_staged_file 3 "$MERGED" "$REMOTE"
 
-       if test -z "$local_mode" -o -z "$remote_mode"
+       if test -z "$local_mode" || test -z "$remote_mode"
        then
                echo "Deleted merge conflict for '$MERGED':"
                describe_file "$local_mode" "local" "$LOCAL"
@@ -277,7 +277,7 @@ merge_file () {
        echo "Normal merge conflict for '$MERGED':"
        describe_file "$local_mode" "local" "$LOCAL"
        describe_file "$remote_mode" "remote" "$REMOTE"
-       if "$prompt" = true
+       if test "$guessed_merge_tool" = true || test "$prompt" = true
        then
                printf "Hit return to start merge resolution tool (%s): " "$merge_tool"
                read ans || return 1
@@ -315,7 +315,8 @@ merge_file () {
        return 0
 }
 
-prompt=$(git config --bool mergetool.prompt || echo true)
+prompt=$(git config --bool mergetool.prompt)
+guessed_merge_tool=false
 
 while test $# != 0
 do
@@ -373,7 +374,14 @@ prompt_after_failed_merge () {
 
 if test -z "$merge_tool"
 then
-       merge_tool=$(get_merge_tool "$merge_tool") || exit
+       # Check if a merge tool has been configured
+       merge_tool=$(get_configured_merge_tool)
+       # Try to guess an appropriate merge tool if no tool has been set.
+       if test -z "$merge_tool"
+       then
+               merge_tool=$(guess_merge_tool) || exit
+               guessed_merge_tool=true
+       fi
 fi
 merge_keep_backup="$(git config --bool mergetool.keepBackup || echo true)"
 merge_keep_temporaries="$(git config --bool mergetool.keepTemporaries || echo false)"
index 773cafcd89b6cd89d413e3d51056c4aaf53c1f2c..ff132b2117c5ed7529d6b1237a9f26069cb4ef8a 100755 (executable)
--- a/git-p4.py
+++ b/git-p4.py
@@ -1238,6 +1238,28 @@ class P4Submit(Command, P4UserMap):
             if response == 'n':
                 return False
 
+    def get_diff_description(self, editedFiles, filesToAdd):
+        # diff
+        if os.environ.has_key("P4DIFF"):
+            del(os.environ["P4DIFF"])
+        diff = ""
+        for editedFile in editedFiles:
+            diff += p4_read_pipe(['diff', '-du',
+                                  wildcard_encode(editedFile)])
+
+        # new file diff
+        newdiff = ""
+        for newFile in filesToAdd:
+            newdiff += "==== new file ====\n"
+            newdiff += "--- /dev/null\n"
+            newdiff += "+++ %s\n" % newFile
+            f = open(newFile, "r")
+            for line in f.readlines():
+                newdiff += "+" + line
+            f.close()
+
+        return (diff + newdiff).replace('\r\n', '\n')
+
     def applyCommit(self, id):
         """Apply one commit, return True if it succeeded."""
 
@@ -1398,34 +1420,15 @@ class P4Submit(Command, P4UserMap):
             submitTemplate += "######## Variable git-p4.skipUserNameCheck hides this message.\n"
 
         separatorLine = "######## everything below this line is just the diff #######\n"
+        if not self.prepare_p4_only:
+            submitTemplate += separatorLine
+            submitTemplate += self.get_diff_description(editedFiles, filesToAdd)
 
-        # diff
-        if os.environ.has_key("P4DIFF"):
-            del(os.environ["P4DIFF"])
-        diff = ""
-        for editedFile in editedFiles:
-            diff += p4_read_pipe(['diff', '-du',
-                                  wildcard_encode(editedFile)])
-
-        # new file diff
-        newdiff = ""
-        for newFile in filesToAdd:
-            newdiff += "==== new file ====\n"
-            newdiff += "--- /dev/null\n"
-            newdiff += "+++ %s\n" % newFile
-            f = open(newFile, "r")
-            for line in f.readlines():
-                newdiff += "+" + line
-            f.close()
-
-        # change description file: submitTemplate, separatorLine, diff, newdiff
         (handle, fileName) = tempfile.mkstemp()
-        tmpFile = os.fdopen(handle, "w+")
+        tmpFile = os.fdopen(handle, "w+b")
         if self.isWindows:
             submitTemplate = submitTemplate.replace("\n", "\r\n")
-            separatorLine = separatorLine.replace("\n", "\r\n")
-            newdiff = newdiff.replace("\n", "\r\n")
-        tmpFile.write(submitTemplate + separatorLine + diff + newdiff)
+        tmpFile.write(submitTemplate)
         tmpFile.close()
 
         if self.prepare_p4_only:
@@ -1472,9 +1475,9 @@ class P4Submit(Command, P4UserMap):
             tmpFile = open(fileName, "rb")
             message = tmpFile.read()
             tmpFile.close()
-            submitTemplate = message[:message.index(separatorLine)]
             if self.isWindows:
-                submitTemplate = submitTemplate.replace("\r\n", "\n")
+                message = message.replace("\r\n", "\n")
+            submitTemplate = message[:message.index(separatorLine)]
             p4_write_pipe(['submit', '-i'], submitTemplate)
 
             if self.preserveUser:
index 7358fac86433b61a35ad332d680ba9b4a9d300b2..18a394fcc4e704621c8b5e8bc92b7cbee2fd21fe 100755 (executable)
@@ -106,7 +106,7 @@ do
        -s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy)
                case "$#,$1" in
                *,*=*)
-                       strategy=`expr "z$1" : 'z-[^=]*=\(.*\)'` ;;
+                       strategy=$(expr "z$1" : 'z-[^=]*=\(.*\)') ;;
                1,*)
                        usage ;;
                *)
index f267d8b6c3eea5c557e63814e40a9ef38b776354..7e1eda008815cca80561d6013d41479ea8c90f4a 100644 (file)
@@ -1013,7 +1013,7 @@ then
        git rev-list $revisions |
        while read rev
        do
-               if test -f "$rewritten"/$rev -a "$(sane_grep "$rev" "$state_dir"/not-cherry-picks)" = ""
+               if test -f "$rewritten"/$rev && test "$(sane_grep "$rev" "$state_dir"/not-cherry-picks)" = ""
                then
                        # Use -f2 because if rev-list is telling us this commit is
                        # not worthwhile, we don't want to track its multiple heads,
index 71429fd74373f3f804fc841b5dd60faca2baaec6..d3fb67d75bd3cdfebd048594cdb67eb179b1c435 100644 (file)
@@ -24,7 +24,7 @@ continue_merge () {
                die "$resolvemsg"
        fi
 
-       cmt=`cat "$state_dir/current"`
+       cmt=$(cat "$state_dir/current")
        if ! git diff-index --quiet --ignore-submodules HEAD --
        then
                if ! git commit ${gpg_sign_opt:+"$gpg_sign_opt"} --no-verify -C "$cmt"
@@ -53,11 +53,12 @@ continue_merge () {
 }
 
 call_merge () {
-       cmt="$(cat "$state_dir/cmt.$1")"
+       msgnum="$1"
+       echo "$msgnum" >"$state_dir/msgnum"
+       cmt="$(cat "$state_dir/cmt.$msgnum")"
        echo "$cmt" > "$state_dir/current"
        hd=$(git rev-parse --verify HEAD)
        cmt_name=$(git symbolic-ref HEAD 2> /dev/null || echo HEAD)
-       msgnum=$(cat "$state_dir/msgnum")
        eval GITHEAD_$cmt='"${cmt_name##refs/heads/}~$(($end - $msgnum))"'
        eval GITHEAD_$hd='$onto_name'
        export GITHEAD_$cmt GITHEAD_$hd
@@ -143,7 +144,7 @@ echo "$onto_name" > "$state_dir/onto_name"
 write_basic_state
 
 msgnum=0
-for cmt in `git rev-list --reverse --no-merges "$revisions"`
+for cmt in $(git rev-list --reverse --no-merges "$revisions")
 do
        msgnum=$(($msgnum + 1))
        echo "$cmt" > "$state_dir/cmt.$msgnum"
index 47ca3b990ba38cf45de793d5c3186b36fa728e33..06c810b64fe04d3675820e38d7eeabe7589dab56 100755 (executable)
@@ -466,8 +466,8 @@ then
 else
        if test -z "$onto"
        then
-               empty_tree=`git hash-object -t tree /dev/null`
-               onto=`git commit-tree $empty_tree </dev/null`
+               empty_tree=$(git hash-object -t tree /dev/null)
+               onto=$(git commit-tree $empty_tree </dev/null)
                squash_onto="$onto"
        fi
        unset upstream_name
@@ -525,10 +525,10 @@ case "$#" in
        ;;
 0)
        # Do not need to switch branches, we are already on it.
-       if branch_name=`git symbolic-ref -q HEAD`
+       if branch_name=$(git symbolic-ref -q HEAD)
        then
                head_name=$branch_name
-               branch_name=`expr "z$branch_name" : 'zrefs/heads/\(.*\)'`
+               branch_name=$(expr "z$branch_name" : 'zrefs/heads/\(.*\)')
        else
                head_name="detached HEAD"
                branch_name=HEAD ;# detached
index 1c006a0518e247d58759df98602f6dae3935caf6..a9c75a2360fec7a9ce5f22877a471f70bc405ff1 100755 (executable)
@@ -13,7 +13,8 @@ refspec="${GIT_REMOTE_TESTGIT_REFSPEC-$default_refspec}"
 
 test -z "$refspec" && prefix="refs"
 
-export GIT_DIR="$url/.git"
+GIT_DIR="$url/.git"
+export GIT_DIR
 
 force=
 
index fdb0029b597898559376b1b28d692450794251f3..9949db01e11959c81fae75fa018551601e6d5c3b 100755 (executable)
@@ -80,6 +80,8 @@ git send-email [options] <file | directory | rev-list options >
     --to-cmd                <str>  * Email To: via `<str> \$patch_path`
     --cc-cmd                <str>  * Email Cc: via `<str> \$patch_path`
     --suppress-cc           <str>  * author, self, sob, cc, cccmd, body, bodycc, all.
+    --[no-]cc-cover                * Email Cc: addresses in the cover letter.
+    --[no-]to-cover                * Email To: addresses in the cover letter.
     --[no-]signed-off-by-cc        * Send to Signed-off-by: addresses. Default on.
     --[no-]suppress-from           * Send to self. Default off.
     --[no-]chain-reply-to          * Chain In-Reply-To: fields. Default off.
@@ -195,6 +197,7 @@ sub do_edit {
 
 # Variables with corresponding config settings
 my ($thread, $chain_reply_to, $suppress_from, $signed_off_by_cc);
+my ($cover_cc, $cover_to);
 my ($to_cmd, $cc_cmd);
 my ($smtp_server, $smtp_server_port, @smtp_server_options);
 my ($smtp_authuser, $smtp_encryption, $smtp_ssl_cert_path);
@@ -211,6 +214,8 @@ my %config_bool_settings = (
     "chainreplyto" => [\$chain_reply_to, 0],
     "suppressfrom" => [\$suppress_from, undef],
     "signedoffbycc" => [\$signed_off_by_cc, undef],
+    "cccover" => [\$cover_cc, undef],
+    "tocover" => [\$cover_to, undef],
     "signedoffcc" => [\$signed_off_by_cc, undef],      # Deprecated
     "validate" => [\$validate, 1],
     "multiedit" => [\$multiedit, undef],
@@ -302,6 +307,8 @@ my $rc = GetOptions("h" => \$help,
                    "suppress-from!" => \$suppress_from,
                    "suppress-cc=s" => \@suppress_cc,
                    "signed-off-cc|signed-off-by-cc!" => \$signed_off_by_cc,
+                   "cc-cover|cc-cover!" => \$cover_cc,
+                   "to-cover|to-cover!" => \$cover_to,
                    "confirm=s" => \$confirm,
                    "dry-run" => \$dry_run,
                    "envelope-sender=s" => \$envelope_sender,
@@ -1113,6 +1120,18 @@ sub ssl_verify_params {
        }
 }
 
+sub file_name_is_absolute {
+       my ($path) = @_;
+
+       # msys does not grok DOS drive-prefixes
+       if ($^O eq 'msys') {
+               return ($path =~ m#^/# || $path =~ m#^[a-zA-Z]\:#)
+       }
+
+       require File::Spec::Functions;
+       return File::Spec::Functions::file_name_is_absolute($path);
+}
+
 # Returns 1 if the message was sent, and 0 otherwise.
 # In actuality, the whole program dies when there
 # is an error sending a message.
@@ -1197,7 +1216,7 @@ X-Mailer: git-send-email $gitversion
 
        if ($dry_run) {
                # We don't want to send the email.
-       } elsif ($smtp_server =~ m#^/#) {
+       } elsif (file_name_is_absolute($smtp_server)) {
                my $pid = open my $sm, '|-';
                defined $pid or die $!;
                if (!$pid) {
@@ -1271,7 +1290,7 @@ X-Mailer: git-send-email $gitversion
                printf (($dry_run ? "Dry-" : "")."Sent %s\n", $subject);
        } else {
                print (($dry_run ? "Dry-" : "")."OK. Log says:\n");
-               if ($smtp_server !~ m#^/#) {
+               if (!file_name_is_absolute($smtp_server)) {
                        print "Server: $smtp_server\n";
                        print "MAIL FROM:<$raw_from>\n";
                        foreach my $entry (@recipients) {
@@ -1469,6 +1488,15 @@ foreach my $t (@files) {
        @to = (@initial_to, @to);
        @cc = (@initial_cc, @cc);
 
+       if ($message_num == 1) {
+               if (defined $cover_cc and $cover_cc) {
+                       @initial_cc = @cc;
+               }
+               if (defined $cover_to and $cover_to) {
+                       @initial_to = @to;
+               }
+       }
+
        my $message_was_sent = send_message();
 
        # set up for the next message
index 5f28b32dc7ff75830bde919b2f4776f7a9b017e2..9447980330ce7892757f9b11fa45cfeb3e6fcb34 100644 (file)
@@ -160,7 +160,7 @@ git_pager() {
        else
                GIT_PAGER=cat
        fi
-       : ${LESS=-FRSX}
+       : ${LESS=-FRX}
        : ${LV=-c}
        export LESS LV
 
index 4798bcf0e51b705005215e9a6339310defe16d03..bcc757b3900b02595e5b432edcfd590e312b48ce 100755 (executable)
@@ -13,7 +13,7 @@ USAGE="list [<options>]
 
 SUBDIRECTORY_OK=Yes
 OPTIONS_SPEC=
-START_DIR=`pwd`
+START_DIR=$(pwd)
 . git-sh-setup
 . git-sh-i18n
 require_work_tree
@@ -94,7 +94,8 @@ create_stash () {
                # ease of unpacking later.
                u_commit=$(
                        untracked_files | (
-                               export GIT_INDEX_FILE="$TMPindex"
+                               GIT_INDEX_FILE="$TMPindex" &&
+                               export GIT_INDEX_FILE &&
                                rm -f "$TMPindex" &&
                                git update-index -z --add --remove --stdin &&
                                u_tree=$(git write-tree) &&
index b55d83ac46a96ba15fb7ac8cb43b8c279b40d119..9245abfd4263881bdd6d0f21f648b46201b52a2d 100755 (executable)
@@ -235,7 +235,7 @@ module_name()
                sed -n -e 's|^submodule\.\(.*\)\.path '"$re"'$|\1|p' )
        test -z "$name" &&
        die "$(eval_gettext "No submodule mapping found in .gitmodules for path '\$sm_path'")"
-       echo "$name"
+       printf '%s\n' "$name"
 }
 
 #
@@ -291,9 +291,6 @@ module_clone()
        # resolve any symlinks that might be present in $PWD
        a=$(cd_to_toplevel && cd "$gitdir" && pwd)/
        b=$(cd_to_toplevel && cd "$sm_path" && pwd)/
-       # normalize Windows-style absolute paths to POSIX-style absolute paths
-       case $a in [a-zA-Z]:/*) a=/${a%%:*}${a#*:} ;; esac
-       case $b in [a-zA-Z]:/*) b=/${b%%:*}${b#*:} ;; esac
        # Remove all common leading directories after a sanity check
        if test "${a#$b}" != "$a" || test "${b#$a}" != "$b"; then
                die "$(eval_gettext "Gitdir '\$a' is part of the submodule path '\$b' or vice versa")"
@@ -308,10 +305,10 @@ module_clone()
        b=${b%/}
 
        # Turn each leading "*/" component into "../"
-       rel=$(echo $b | sed -e 's|[^/][^/]*|..|g')
-       echo "gitdir: $rel/$a" >"$sm_path/.git"
+       rel=$(printf '%s\n' "$b" | sed -e 's|[^/][^/]*|..|g')
+       printf '%s\n' "gitdir: $rel/$a" >"$sm_path/.git"
 
-       rel=$(echo $a | sed -e 's|[^/][^/]*|..|g')
+       rel=$(printf '%s\n' "$a" | sed -e 's|[^/][^/]*|..|g')
        (clear_local_git_env; cd "$sm_path" && GIT_WORK_TREE=. git config core.worktree "$rel/$b")
 }
 
@@ -392,11 +389,11 @@ cmd_add()
        sm_path=$2
 
        if test -z "$sm_path"; then
-               sm_path=$(echo "$repo" |
+               sm_path=$(printf '%s\n' "$repo" |
                        sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g')
        fi
 
-       if test -z "$repo" -o -z "$sm_path"; then
+       if test -z "$repo" || test -z "$sm_path"; then
                usage
        fi
 
@@ -453,7 +450,7 @@ Use -f if you really want to add it." >&2
        # perhaps the path exists and is already a git repo, else clone it
        if test -e "$sm_path"
        then
-               if test -d "$sm_path"/.git -o -f "$sm_path"/.git
+               if test -d "$sm_path"/.git || test -f "$sm_path"/.git
                then
                        eval_gettextln "Adding existing repo at '\$sm_path' to the index"
                else
@@ -835,7 +832,7 @@ Maybe you want to use 'update --init'?")"
                        continue
                fi
 
-               if ! test -d "$sm_path"/.git -o -f "$sm_path"/.git
+               if ! test -d "$sm_path"/.git && ! test -f "$sm_path"/.git
                then
                        module_clone "$sm_path" "$name" "$url" "$reference" "$depth" || exit
                        cloned_modules="$cloned_modules;$name"
@@ -860,11 +857,11 @@ Maybe you want to use 'update --init'?")"
                        die "$(eval_gettext "Unable to find current ${remote_name}/${branch} revision in submodule path '\$sm_path'")"
                fi
 
-               if test "$subsha1" != "$sha1" -o -n "$force"
+               if test "$subsha1" != "$sha1" || test -n "$force"
                then
                        subforce=$force
                        # If we don't already have a -f flag and the submodule has never been checked out
-                       if test -z "$subsha1" -a -z "$force"
+                       if test -z "$subsha1" && test -z "$force"
                        then
                                subforce="-f"
                        fi
@@ -1034,7 +1031,7 @@ cmd_summary() {
        then
                head=$rev
                test $# = 0 || shift
-       elif test -z "$1" -o "$1" = "HEAD"
+       elif test -z "$1" || test "$1" = "HEAD"
        then
                # before the first commit: compare with an empty tree
                head=$(git hash-object -w -t tree --stdin </dev/null)
@@ -1059,17 +1056,21 @@ cmd_summary() {
                while read mod_src mod_dst sha1_src sha1_dst status sm_path
                do
                        # Always show modules deleted or type-changed (blob<->module)
-                       test $status = D -o $status = T && echo "$sm_path" && continue
+                       if test "$status" = D || test "$status" = T
+                       then
+                               printf '%s\n' "$sm_path"
+                               continue
+                       fi
                        # Respect the ignore setting for --for-status.
                        if test -n "$for_status"
                        then
                                name=$(module_name "$sm_path")
                                ignore_config=$(get_submodule_config "$name" ignore none)
-                               test $status != A -a $ignore_config = all && continue
+                               test $status != A && test $ignore_config = all && continue
                        fi
                        # Also show added or modified modules which are checked out
                        GIT_DIR="$sm_path/.git" git-rev-parse --git-dir >/dev/null 2>&1 &&
-                       echo "$sm_path"
+                       printf '%s\n' "$sm_path"
                done
        )
 
@@ -1125,7 +1126,7 @@ cmd_summary() {
                *)
                        errmsg=
                        total_commits=$(
-                       if test $mod_src = 160000 -a $mod_dst = 160000
+                       if test $mod_src = 160000 && test $mod_dst = 160000
                        then
                                range="$sha1_src...$sha1_dst"
                        elif test $mod_src = 160000
@@ -1162,7 +1163,7 @@ cmd_summary() {
                        # i.e. deleted or changed to blob
                        test $mod_dst = 160000 && echo "$errmsg"
                else
-                       if test $mod_src = 160000 -a $mod_dst = 160000
+                       if test $mod_src = 160000 && test $mod_dst = 160000
                        then
                                limit=
                                test $summary_limit -gt 0 && limit="-$summary_limit"
@@ -1233,7 +1234,11 @@ cmd_status()
                        say "U$sha1 $displaypath"
                        continue
                fi
-               if test -z "$url" || ! test -d "$sm_path"/.git -o -f "$sm_path"/.git
+               if test -z "$url" ||
+               {
+                       ! test -d "$sm_path"/.git &&
+                       ! test -f "$sm_path"/.git
+               }
                then
                        say "-$sha1 $displaypath"
                        continue;
@@ -1306,7 +1311,7 @@ cmd_sync()
                ./*|../*)
                        # rewrite foo/bar as ../.. to find path from
                        # submodule work tree to superproject work tree
-                       up_path="$(echo "$sm_path" | sed "s/[^/][^/]*/../g")" &&
+                       up_path="$(printf '%s\n' "$sm_path" | sed "s/[^/][^/]*/../g")" &&
                        # guarantee a trailing /
                        up_path=${up_path%/}/ &&
                        # path from submodule work tree to submodule origin repo
@@ -1402,7 +1407,7 @@ then
 fi
 
 # "--cached" is accepted only by "status" and "summary"
-if test -n "$cached" && test "$command" != status -a "$command" != summary
+if test -n "$cached" && test "$command" != status && test "$command" != summary
 then
        usage
 fi
index ebdfba6c94db947f66add0c1b4840319c12252ea..ae152534f5026d50fa32b568d1bdd591629bc59d 100755 (executable)
@@ -59,7 +59,7 @@ do
        -b|--browser*|-t|--tool*)
                case "$#,$1" in
                *,*=*)
-                       browser=`expr "z$1" : 'z-[^=]*=\(.*\)'`
+                       browser=$(expr "z$1" : 'z-[^=]*=\(.*\)')
                        ;;
                1,*)
                        usage ;;
@@ -71,7 +71,7 @@ do
        -c|--config*)
                case "$#,$1" in
                *,*=*)
-                       conf=`expr "z$1" : 'z-[^=]*=\(.*\)'`
+                       conf=$(expr "z$1" : 'z-[^=]*=\(.*\)')
                        ;;
                1,*)
                        usage ;;
@@ -100,7 +100,7 @@ then
        for opt in "$conf" "web.browser"
        do
                test -z "$opt" && continue
-               browser="`git config $opt`"
+               browser="$(git config $opt)"
                test -z "$browser" || break
        done
        if test -n "$browser" && ! valid_tool "$browser"; then
diff --git a/git.c b/git.c
index 9efd1a3ec1f2af63fe575f9c755dff685d9b1e51..5b6c7611be93c535491bbc9ba027e3acbad0db8f 100644 (file)
--- a/git.c
+++ b/git.c
@@ -20,6 +20,43 @@ const char git_more_info_string[] =
 
 static struct startup_info git_startup_info;
 static int use_pager = -1;
+static char orig_cwd[PATH_MAX];
+static const char *env_names[] = {
+       GIT_DIR_ENVIRONMENT,
+       GIT_WORK_TREE_ENVIRONMENT,
+       GIT_IMPLICIT_WORK_TREE_ENVIRONMENT,
+       GIT_PREFIX_ENVIRONMENT
+};
+static char *orig_env[4];
+static int saved_environment;
+
+static void save_env(void)
+{
+       int i;
+       if (saved_environment)
+               return;
+       saved_environment = 1;
+       if (!getcwd(orig_cwd, sizeof(orig_cwd)))
+               die_errno("cannot getcwd");
+       for (i = 0; i < ARRAY_SIZE(env_names); i++) {
+               orig_env[i] = getenv(env_names[i]);
+               if (orig_env[i])
+                       orig_env[i] = xstrdup(orig_env[i]);
+       }
+}
+
+static void restore_env(void)
+{
+       int i;
+       if (*orig_cwd && chdir(orig_cwd))
+               die_errno("could not move to %s", orig_cwd);
+       for (i = 0; i < ARRAY_SIZE(env_names); i++) {
+               if (orig_env[i])
+                       setenv(env_names[i], orig_env[i], 1);
+               else
+                       unsetenv(env_names[i]);
+       }
+}
 
 static void commit_pager_choice(void) {
        switch (use_pager) {
@@ -54,8 +91,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
                /*
                 * Check remaining flags.
                 */
-               if (starts_with(cmd, "--exec-path")) {
-                       cmd += 11;
+               if (skip_prefix(cmd, "--exec-path", &cmd)) {
                        if (*cmd == '=')
                                git_set_argv_exec_path(cmd + 1);
                        else {
@@ -92,8 +128,8 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
                                *envchanged = 1;
                        (*argv)++;
                        (*argc)--;
-               } else if (starts_with(cmd, "--git-dir=")) {
-                       setenv(GIT_DIR_ENVIRONMENT, cmd + 10, 1);
+               } else if (skip_prefix(cmd, "--git-dir=", &cmd)) {
+                       setenv(GIT_DIR_ENVIRONMENT, cmd, 1);
                        if (envchanged)
                                *envchanged = 1;
                } else if (!strcmp(cmd, "--namespace")) {
@@ -106,8 +142,8 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
                                *envchanged = 1;
                        (*argv)++;
                        (*argc)--;
-               } else if (starts_with(cmd, "--namespace=")) {
-                       setenv(GIT_NAMESPACE_ENVIRONMENT, cmd + 12, 1);
+               } else if (skip_prefix(cmd, "--namespace=", &cmd)) {
+                       setenv(GIT_NAMESPACE_ENVIRONMENT, cmd, 1);
                        if (envchanged)
                                *envchanged = 1;
                } else if (!strcmp(cmd, "--work-tree")) {
@@ -120,8 +156,8 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
                                *envchanged = 1;
                        (*argv)++;
                        (*argc)--;
-               } else if (starts_with(cmd, "--work-tree=")) {
-                       setenv(GIT_WORK_TREE_ENVIRONMENT, cmd + 12, 1);
+               } else if (skip_prefix(cmd, "--work-tree=", &cmd)) {
+                       setenv(GIT_WORK_TREE_ENVIRONMENT, cmd, 1);
                        if (envchanged)
                                *envchanged = 1;
                } else if (!strcmp(cmd, "--bare")) {
@@ -272,6 +308,7 @@ static int handle_alias(int *argcp, const char ***argv)
  * RUN_SETUP for reading from the configuration file.
  */
 #define NEED_WORK_TREE         (1<<3)
+#define NO_SETUP               (1<<4)
 
 struct cmd_struct {
        const char *cmd;
@@ -290,7 +327,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
        if (!help) {
                if (p->option & RUN_SETUP)
                        prefix = setup_git_directory();
-               if (p->option & RUN_SETUP_GENTLY) {
+               else if (p->option & RUN_SETUP_GENTLY) {
                        int nongit_ok;
                        prefix = setup_git_directory_gently(&nongit_ok);
                }
@@ -352,7 +389,7 @@ static struct cmd_struct commands[] = {
        { "cherry", cmd_cherry, RUN_SETUP },
        { "cherry-pick", cmd_cherry_pick, RUN_SETUP | NEED_WORK_TREE },
        { "clean", cmd_clean, RUN_SETUP | NEED_WORK_TREE },
-       { "clone", cmd_clone },
+       { "clone", cmd_clone, NO_SETUP },
        { "column", cmd_column, RUN_SETUP_GENTLY },
        { "commit", cmd_commit, RUN_SETUP | NEED_WORK_TREE },
        { "commit-tree", cmd_commit_tree, RUN_SETUP },
@@ -378,8 +415,8 @@ static struct cmd_struct commands[] = {
        { "hash-object", cmd_hash_object },
        { "help", cmd_help },
        { "index-pack", cmd_index_pack, RUN_SETUP_GENTLY },
-       { "init", cmd_init_db },
-       { "init-db", cmd_init_db },
+       { "init", cmd_init_db, NO_SETUP },
+       { "init-db", cmd_init_db, NO_SETUP },
        { "log", cmd_log, RUN_SETUP },
        { "ls-files", cmd_ls_files, RUN_SETUP },
        { "ls-remote", cmd_ls_remote, RUN_SETUP_GENTLY },
@@ -441,6 +478,7 @@ static struct cmd_struct commands[] = {
        { "upload-archive", cmd_upload_archive },
        { "upload-archive--writer", cmd_upload_archive_writer },
        { "var", cmd_var, RUN_SETUP_GENTLY },
+       { "verify-commit", cmd_verify_commit, RUN_SETUP },
        { "verify-pack", cmd_verify_pack },
        { "verify-tag", cmd_verify_tag, RUN_SETUP },
        { "version", cmd_version },
@@ -484,6 +522,10 @@ static void handle_builtin(int argc, const char **argv)
                struct cmd_struct *p = commands+i;
                if (strcmp(p->cmd, cmd))
                        continue;
+               if (saved_environment && (p->option & NO_SETUP)) {
+                       restore_env();
+                       break;
+               }
                exit(run_builtin(p, argc, argv));
        }
 }
@@ -539,7 +581,10 @@ static int run_argv(int *argcp, const char ***argv)
                 * of overriding "git log" with "git show" by having
                 * alias.log = show
                 */
-               if (done_alias || !handle_alias(argcp, argv))
+               if (done_alias)
+                       break;
+               save_env();
+               if (!handle_alias(argcp, argv))
                        break;
                done_alias = 1;
        }
@@ -578,8 +623,7 @@ int main(int argc, char **av)
         * So we just directly call the builtin handler, and die if
         * that one cannot handle it.
         */
-       if (starts_with(cmd, "git-")) {
-               cmd += 4;
+       if (skip_prefix(cmd, "git-", &cmd)) {
                argv[0] = cmd;
                handle_builtin(argc, argv);
                die("cannot handle %s as a builtin", cmd);
@@ -590,8 +634,8 @@ int main(int argc, char **av)
        argc--;
        handle_options(&argv, &argc, NULL);
        if (argc > 0) {
-               if (starts_with(argv[0], "--"))
-                       argv[0] += 2;
+               /* translate --help and --version into commands */
+               skip_prefix(argv[0], "--", &argv[0]);
        } else {
                /* The user didn't specify a command; give them help */
                commit_pager_choice();
index 90764e8948f1f95aaddfb381664ecede328bc863..c8df35dee58aed6ba652ee9ab998f405539991eb 100755 (executable)
@@ -2585,6 +2585,7 @@ proc makewindow {} {
     bind $fstring <Key-Return> {dofind 1 1}
     bind $sha1entry <Key-Return> {gotocommit; break}
     bind $sha1entry <<PasteSelection>> clearsha1
+    bind $sha1entry <<Paste>> clearsha1
     bind $cflist <1> {sel_flist %W %x %y; break}
     bind $cflist <B1-Motion> {sel_flist %W %x %y; break}
     bind $cflist <ButtonRelease-1> {treeclick %W %x %y}
@@ -2786,7 +2787,7 @@ proc savestuff {w} {
     global mainheadcirclecolor workingfilescirclecolor indexcirclecolor
     global linkfgcolor circleoutlinecolor
     global autoselect autosellen extdifftool perfile_attrs markbgcolor use_ttk
-    global hideremotes want_ttk maxrefs
+    global hideremotes want_ttk maxrefs visiblerefs
     global config_file config_file_tmp
 
     if {$stuffsaved} return
@@ -2812,6 +2813,7 @@ proc savestuff {w} {
        puts $f [list set autosellen $autosellen]
        puts $f [list set showneartags $showneartags]
        puts $f [list set maxrefs $maxrefs]
+       puts $f [list set visiblerefs $visiblerefs]
        puts $f [list set hideremotes $hideremotes]
        puts $f [list set showlocalchanges $showlocalchanges]
        puts $f [list set datetimeformat $datetimeformat]
@@ -3492,10 +3494,20 @@ proc flist_hl {only} {
 }
 
 proc gitknewtmpdir {} {
-    global diffnum gitktmpdir gitdir
+    global diffnum gitktmpdir gitdir env
 
     if {![info exists gitktmpdir]} {
-       set gitktmpdir [file join $gitdir [format ".gitk-tmp.%s" [pid]]]
+       if {[info exists env(GITK_TMPDIR)]} {
+           set tmpdir $env(GITK_TMPDIR)
+       } elseif {[info exists env(TMPDIR)]} {
+           set tmpdir $env(TMPDIR)
+       } else {
+           set tmpdir $gitdir
+       }
+       set gitktmpformat [file join $tmpdir ".gitk-tmp.XXXXXX"]
+       if {[catch {set gitktmpdir [exec mktemp -d $gitktmpformat]}]} {
+           set gitktmpdir [file join $gitdir [format ".gitk-tmp.%s" [pid]]]
+       }
        if {[catch {file mkdir $gitktmpdir} err]} {
            error_popup "[mc "Error creating temporary directory %s:" $gitktmpdir] $err"
            unset gitktmpdir
@@ -3870,7 +3882,7 @@ proc read_line_source {fd inst} {
            set id $nullid2
        }
        if {[commitinview $id $curview]} {
-           selectline [rowofcommit $id] 1 [list $fname $lnum]
+           selectline [rowofcommit $id] 1 [list $fname $lnum] 1
        } else {
            error_popup [mc "That line comes from commit %s, \
                             which is not in this view" [shortids $id]]
@@ -5205,11 +5217,15 @@ proc dohidelocalchanges {} {
 # spawn off a process to do git diff-index --cached HEAD
 proc dodiffindex {} {
     global lserial showlocalchanges vfilelimit curview
-    global hasworktree
+    global hasworktree git_version
 
     if {!$showlocalchanges || !$hasworktree} return
     incr lserial
-    set cmd "|git diff-index --cached HEAD"
+    if {[package vcompare $git_version "1.7.2"] >= 0} {
+       set cmd "|git diff-index --cached --ignore-submodules=dirty HEAD"
+    } else {
+       set cmd "|git diff-index --cached HEAD"
+    }
     if {$vfilelimit($curview) ne {}} {
        set cmd [concat $cmd -- $vfilelimit($curview)]
     }
@@ -7020,7 +7036,7 @@ proc viewnextline {dir} {
 # add a list of tag or branch names at position pos
 # returns the number of names inserted
 proc appendrefs {pos ids var} {
-    global ctext linknum curview $var maxrefs mainheadid
+    global ctext linknum curview $var maxrefs visiblerefs mainheadid
 
     if {[catch {$ctext index $pos}]} {
        return 0
@@ -7041,14 +7057,14 @@ proc appendrefs {pos ids var} {
     if {[llength $tags] > $maxrefs} {
        # If we are displaying heads, and there are too many,
        # see if there are some important heads to display.
-       # Currently this means "master" and the current head.
+       # Currently that are the current head and heads listed in $visiblerefs option
        set itags {}
        if {$var eq "idheads"} {
            set utags {}
            foreach ti $tags {
                set hname [lindex $ti 0]
                set id [lindex $ti 1]
-               if {($hname eq "master" || $id eq $mainheadid) &&
+               if {([lsearch -exact $visiblerefs $hname] != -1 || $id eq $mainheadid) &&
                    [llength $itags] < $maxrefs} {
                    lappend itags $ti
                } else {
@@ -7161,7 +7177,7 @@ proc make_idmark {id} {
     $canv raise $t
 }
 
-proc selectline {l isnew {desired_loc {}}} {
+proc selectline {l isnew {desired_loc {}} {switch_to_patch 0}} {
     global canv ctext commitinfo selectedline
     global canvy0 linespc parents children curview
     global currentid sha1entry
@@ -7187,6 +7203,10 @@ proc selectline {l isnew {desired_loc {}}} {
        setcanvscroll
     }
 
+    if {$cmitmode ne "patch" && $switch_to_patch} {
+        set cmitmode "patch"
+    }
+
     set y [expr {$canvy0 + $l * $linespc}]
     set ymax [lindex [$canv cget -scrollregion] 3]
     set ytop [expr {$y - $linespc - 1}]
@@ -7705,7 +7725,7 @@ proc addtocflist {ids} {
 }
 
 proc diffcmd {ids flags} {
-    global log_showroot nullid nullid2
+    global log_showroot nullid nullid2 git_version
 
     set i [lsearch -exact $ids $nullid]
     set j [lsearch -exact $ids $nullid2]
@@ -7726,6 +7746,9 @@ proc diffcmd {ids flags} {
            }
        }
     } elseif {$j >= 0} {
+       if {[package vcompare $git_version "1.7.2"] >= 0} {
+           set flags "$flags --ignore-submodules=dirty"
+       }
        set cmd [concat | git diff-index --cached $flags]
        if {[llength $ids] > 1} {
            # comparing index with specific revision
@@ -11575,7 +11598,29 @@ proc prefsok {} {
 proc formatdate {d} {
     global datetimeformat
     if {$d ne {}} {
-       set d [clock format [lindex $d 0] -format $datetimeformat]
+       # If $datetimeformat includes a timezone, display in the
+       # timezone of the argument.  Otherwise, display in local time.
+       if {[string match {*%[zZ]*} $datetimeformat]} {
+           if {[catch {set d [clock format [lindex $d 0] -timezone [lindex $d 1] -format $datetimeformat]}]} {
+               # Tcl < 8.5 does not support -timezone.  Emulate it by
+               # setting TZ (e.g. TZ=<-0430>+04:30).
+               global env
+               if {[info exists env(TZ)]} {
+                   set savedTZ $env(TZ)
+               }
+               set zone [lindex $d 1]
+               set sign [string map {+ - - +} [string index $zone 0]]
+               set env(TZ) <$zone>$sign[string range $zone 1 2]:[string range $zone 3 4]
+               set d [clock format [lindex $d 0] -format $datetimeformat]
+               if {[info exists savedTZ]} {
+                   set env(TZ) $savedTZ
+               } else {
+                   unset env(TZ)
+               }
+           }
+       } else {
+           set d [clock format [lindex $d 0] -format $datetimeformat]
+       }
     }
     return $d
 }
@@ -12001,6 +12046,7 @@ set wrapcomment "none"
 set showneartags 1
 set hideremotes 0
 set maxrefs 20
+set visiblerefs {"master"}
 set maxlinelen 200
 set showlocalchanges 1
 set limitdiffs 1
diff --git a/gitk-git/po/vi.po b/gitk-git/po/vi.po
new file mode 100644 (file)
index 0000000..4dfe125
--- /dev/null
@@ -0,0 +1,1351 @@
+# Vietnamese translations for gitk package.
+# Bản dịch tiếng Việt cho gói gitk.
+# This file is distributed under the same license as the gitk package.
+# Trần Ngọc Quân <vnwildman@gmail.com>, 2013.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: gitk @@GIT_VERSION@@\n"
+"Report-Msgid-Bugs-To: Paul Mackerras <paulus@samba.org>\n"
+"POT-Creation-Date: 2013-12-14 09:24+0700\n"
+"PO-Revision-Date: 2013-12-14 14:40+0700\n"
+"Last-Translator: Trần Ngọc Quân <vnwildman@gmail.com>\n"
+"Language-Team: Vietnamese <translation-team-vi@lists.sourceforge.net>\n"
+"Language: vi\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=1; plural=0;\n"
+
+#: gitk:140
+msgid "Couldn't get list of unmerged files:"
+msgstr "Không thể lấy danh sách các tập-tin chưa được hòa trộn:"
+
+#: gitk:212 gitk:2353
+msgid "Color words"
+msgstr "Tô màu chữ"
+
+#: gitk:217 gitk:2353 gitk:8103 gitk:8136
+msgid "Markup words"
+msgstr "Đánh dấu chữ"
+
+#: gitk:322
+msgid "Error parsing revisions:"
+msgstr "Gặp lỗi khi phân tích điểm xét duyệt:"
+
+#: gitk:378
+msgid "Error executing --argscmd command:"
+msgstr "Gặp lỗi khi thực hiện lệnh --argscmd:"
+
+#: gitk:391
+msgid "No files selected: --merge specified but no files are unmerged."
+msgstr ""
+"Chưa chọn tập tin: --merge đã chỉ định nhưng không có tập tin chưa hòa trộn."
+
+#: gitk:394
+msgid ""
+"No files selected: --merge specified but no unmerged files are within file "
+"limit."
+msgstr ""
+"Chưa chọn tập tin: --merge đã chỉ định nhưng không có tập tin chưa hòa trộn "
+"trong giới hạn tập tin."
+
+#: gitk:416 gitk:564
+msgid "Error executing git log:"
+msgstr "Gặp lỗi khi thực hiện lệnh git log:"
+
+#: gitk:434 gitk:580
+msgid "Reading"
+msgstr "Đang đọc"
+
+#: gitk:494 gitk:4429
+msgid "Reading commits..."
+msgstr "Đang đọc các lần chuyển giao..."
+
+#: gitk:497 gitk:1635 gitk:4432
+msgid "No commits selected"
+msgstr "Chưa chọn các lần chuyển giao"
+
+#: gitk:1509
+msgid "Can't parse git log output:"
+msgstr "Không thể phân tích kết xuất từ lệnh git log:"
+
+#: gitk:1738
+msgid "No commit information available"
+msgstr "Không có thông tin về lần chuyển giao nào"
+
+#: gitk:1895
+msgid "mc"
+msgstr "mc"
+
+#: gitk:1930 gitk:4222 gitk:9552 gitk:11122 gitk:11401
+msgid "OK"
+msgstr "Đồng ý"
+
+#: gitk:1932 gitk:4224 gitk:9079 gitk:9158 gitk:9274 gitk:9323 gitk:9554
+#: gitk:11123 gitk:11402
+msgid "Cancel"
+msgstr "Thôi"
+
+#: gitk:2067
+msgid "Update"
+msgstr "Cập nhật"
+
+#: gitk:2068
+msgid "Reload"
+msgstr "Tải lại"
+
+#: gitk:2069
+msgid "Reread references"
+msgstr "Đọc lại tham chiếu"
+
+#: gitk:2070
+msgid "List references"
+msgstr "Liệt kê các tham chiếu"
+
+#: gitk:2072
+msgid "Start git gui"
+msgstr "Khởi chạy git gui"
+
+#: gitk:2074
+msgid "Quit"
+msgstr "Thoát"
+
+#: gitk:2066
+msgid "File"
+msgstr "Chính"
+
+#: gitk:2078
+msgid "Preferences"
+msgstr "Cá nhân hóa"
+
+#: gitk:2077
+msgid "Edit"
+msgstr "Chỉnh sửa"
+
+#: gitk:2082
+msgid "New view..."
+msgstr "Thêm trình bày mới..."
+
+#: gitk:2083
+msgid "Edit view..."
+msgstr "Sửa cách trình bày..."
+
+#: gitk:2084
+msgid "Delete view"
+msgstr "Xóa cách trình bày"
+
+#: gitk:2086
+msgid "All files"
+msgstr "Mọi tập tin"
+
+#: gitk:2081 gitk:3975
+msgid "View"
+msgstr "Trình bày"
+
+#: gitk:2091 gitk:2101 gitk:2945
+msgid "About gitk"
+msgstr "Giới thiệu về gitk"
+
+#: gitk:2092 gitk:2106
+msgid "Key bindings"
+msgstr "Tổ hợp phím"
+
+#: gitk:2090 gitk:2105
+msgid "Help"
+msgstr "Trợ giúp"
+
+#: gitk:2183 gitk:8535
+msgid "SHA1 ID:"
+msgstr "SHA1 ID:"
+
+#: gitk:2227
+msgid "Row"
+msgstr "Hàng"
+
+#: gitk:2265
+msgid "Find"
+msgstr "Tìm"
+
+#: gitk:2266
+msgid "next"
+msgstr "tiếp"
+
+#: gitk:2267
+msgid "prev"
+msgstr "trước"
+
+#: gitk:2268
+msgid "commit"
+msgstr "lần chuyển giao"
+
+#: gitk:2271 gitk:2273 gitk:4590 gitk:4613 gitk:4637 gitk:6653 gitk:6725
+#: gitk:6810
+msgid "containing:"
+msgstr "có chứa:"
+
+#: gitk:2274 gitk:3457 gitk:3462 gitk:4666
+msgid "touching paths:"
+msgstr "đang chạm đường dẫn:"
+
+#: gitk:2275 gitk:4680
+msgid "adding/removing string:"
+msgstr "thêm/gỡ bỏ chuỗi:"
+
+#: gitk:2276 gitk:4682
+msgid "changing lines matching:"
+msgstr "những dòng thay đổi khớp mẫu:"
+
+#: gitk:2285 gitk:2287 gitk:4669
+msgid "Exact"
+msgstr "Chính xác"
+
+#: gitk:2287 gitk:4757 gitk:6621
+msgid "IgnCase"
+msgstr "BquaHt"
+
+#: gitk:2287 gitk:4639 gitk:4755 gitk:6617
+msgid "Regexp"
+msgstr "BTCQ"
+
+#: gitk:2289 gitk:2290 gitk:4777 gitk:4807 gitk:4814 gitk:6746 gitk:6814
+msgid "All fields"
+msgstr "Mọi trường"
+
+#: gitk:2290 gitk:4774 gitk:4807 gitk:6684
+msgid "Headline"
+msgstr "Nội dung chính"
+
+#: gitk:2291 gitk:4774 gitk:6684 gitk:6814 gitk:7283
+msgid "Comments"
+msgstr "Ghi chú"
+
+#: gitk:2291 gitk:4774 gitk:4779 gitk:4814 gitk:6684 gitk:7218 gitk:8713
+#: gitk:8728
+msgid "Author"
+msgstr "Tác giả"
+
+#: gitk:2291 gitk:4774 gitk:6684 gitk:7220
+msgid "Committer"
+msgstr "Người chuyển giao"
+
+#: gitk:2322
+msgid "Search"
+msgstr "Tìm kiếm"
+
+#: gitk:2330
+msgid "Diff"
+msgstr "So sánh"
+
+#: gitk:2332
+msgid "Old version"
+msgstr "Phiên bản cũ"
+
+#: gitk:2334
+msgid "New version"
+msgstr "Phiên bản mới"
+
+#: gitk:2336
+msgid "Lines of context"
+msgstr "Các dòng của nội dung"
+
+#: gitk:2346
+msgid "Ignore space change"
+msgstr "Không xét đến thay đổi do khoảng trắng"
+
+#: gitk:2350 gitk:2352 gitk:7842 gitk:8089
+msgid "Line diff"
+msgstr "Khác biệt theo dòng"
+
+#: gitk:2417
+msgid "Patch"
+msgstr "Vá"
+
+#: gitk:2419
+msgid "Tree"
+msgstr "Cây"
+
+#: gitk:2577 gitk:2597
+msgid "Diff this -> selected"
+msgstr "So sánh cái này -> cái đã chọn"
+
+#: gitk:2578 gitk:2598
+msgid "Diff selected -> this"
+msgstr "So sánh cái đã chọn -> cái này"
+
+#: gitk:2579 gitk:2599
+msgid "Make patch"
+msgstr "Tạo miếng vá"
+
+#: gitk:2580 gitk:9137
+msgid "Create tag"
+msgstr "Tạo thẻ"
+
+#: gitk:2581 gitk:9254
+msgid "Write commit to file"
+msgstr "Ghi lần chuyển giao ra tập tin"
+
+#: gitk:2582 gitk:9311
+msgid "Create new branch"
+msgstr "Tạo nhánh mới"
+
+#: gitk:2583
+msgid "Cherry-pick this commit"
+msgstr "Cherry-pick lần chuyển giao này"
+
+#: gitk:2584
+msgid "Reset HEAD branch to here"
+msgstr "Đặt lại HEAD của nhánh vào đây"
+
+#: gitk:2585
+msgid "Mark this commit"
+msgstr "Đánh dấu lần chuyển giao này"
+
+#: gitk:2586
+msgid "Return to mark"
+msgstr "Quay lại vị trí dấu"
+
+#: gitk:2587
+msgid "Find descendant of this and mark"
+msgstr "Tìm con cháu của cái này và cái đã đánh dấu"
+
+#: gitk:2588
+msgid "Compare with marked commit"
+msgstr "So sánh với lần chuyển giao đã đánh dấu"
+
+#: gitk:2589 gitk:2600
+msgid "Diff this -> marked commit"
+msgstr "So sánh cái này -> lần chuyển giao đã đánh dấu"
+
+#: gitk:2590 gitk:2601
+msgid "Diff marked commit -> this"
+msgstr "So sánh lần chuyển giao đã đánh dấu -> cái này"
+
+#: gitk:2591
+msgid "Revert this commit"
+msgstr "Hoàn lại lần chuyển giao này"
+
+#: gitk:2607
+msgid "Check out this branch"
+msgstr "Checkout nhánh này"
+
+#: gitk:2608
+msgid "Remove this branch"
+msgstr "Gỡ bỏ nhánh này"
+
+#: gitk:2615
+msgid "Highlight this too"
+msgstr "Cũng tô sáng nó"
+
+#: gitk:2616
+msgid "Highlight this only"
+msgstr "Chỉ tô sáng cái này"
+
+#: gitk:2617
+msgid "External diff"
+msgstr "diff từ bên ngoài"
+
+#: gitk:2618
+msgid "Blame parent commit"
+msgstr "Xem công trạng lần chuyển giao cha mẹ"
+
+#: gitk:2625
+msgid "Show origin of this line"
+msgstr "Hiển thị nguyên gốc của dòng này"
+
+#: gitk:2626
+msgid "Run git gui blame on this line"
+msgstr "Chạy lệnh git gui blame cho dòng này"
+
+#: gitk:2947
+msgid ""
+"\n"
+"Gitk - a commit viewer for git\n"
+"\n"
+"Copyright © 2005-2011 Paul Mackerras\n"
+"\n"
+"Use and redistribute under the terms of the GNU General Public License"
+msgstr ""
+"\n"
+"Gitk - phần mềm xem các lần chuyển giao dành cho git\n"
+"\n"
+"Bản quyền © 2005-2011 Paul Mackerras\n"
+"\n"
+"Dùng và phân phối lại phần mềm này theo các điều khoản của Giấy Phép Công GNU"
+
+#: gitk:2955 gitk:3020 gitk:9738
+msgid "Close"
+msgstr "Đóng"
+
+#: gitk:2976
+msgid "Gitk key bindings"
+msgstr "Tổ hợp phím gitk"
+
+#: gitk:2979
+msgid "Gitk key bindings:"
+msgstr "Tổ hợp phím gitk:"
+
+#: gitk:2981
+#, tcl-format
+msgid "<%s-Q>\t\tQuit"
+msgstr "<%s-Q>\t\tThoát"
+
+#: gitk:2982
+#, tcl-format
+msgid "<%s-W>\t\tClose window"
+msgstr "<%s-W>\t\tĐóng cửa sổ"
+
+#: gitk:2983
+msgid "<Home>\t\tMove to first commit"
+msgstr "<Home>\t\tChuyển đến lần chuyển giao đầu tiên"
+
+#: gitk:2984
+msgid "<End>\t\tMove to last commit"
+msgstr "<End>\t\tChuyển đến lần chuyển giao cuối"
+
+#: gitk:2985
+msgid "<Up>, p, k\tMove up one commit"
+msgstr "<Up>, p, k\tDi chuyển lên một lần chuyển giao"
+
+#: gitk:2986
+msgid "<Down>, n, j\tMove down one commit"
+msgstr "<Down>, n, j\tDi chuyển xuống một lần chuyển giao"
+
+#: gitk:2987
+msgid "<Left>, z, h\tGo back in history list"
+msgstr "<Left>, z, h\tQuay trở lại danh sách lịch sử"
+
+#: gitk:2988
+msgid "<Right>, x, l\tGo forward in history list"
+msgstr "<Right>, x, l\tDi chuyển tiếp trong danh sách lịch sử"
+
+#: gitk:2989
+msgid "<PageUp>\tMove up one page in commit list"
+msgstr "<PageUp>\tDi chuyển lên một trang trong danh sách lần chuyển giao"
+
+#: gitk:2990
+msgid "<PageDown>\tMove down one page in commit list"
+msgstr "<PageDown>\tDi chuyển xuống một trang trong danh sách lần chuyển giao"
+
+#: gitk:2991
+#, tcl-format
+msgid "<%s-Home>\tScroll to top of commit list"
+msgstr "<%s-Home>\tCuộn lên trên cùng của danh sách lần chuyển giao"
+
+#: gitk:2992
+#, tcl-format
+msgid "<%s-End>\tScroll to bottom of commit list"
+msgstr "<%s-End>\tCuộn xuống dưới cùng của danh sách lần chuyển giao"
+
+#: gitk:2993
+#, tcl-format
+msgid "<%s-Up>\tScroll commit list up one line"
+msgstr "<%s-Up>\tCuộn danh sách lần chuyển giao lên một dòng"
+
+#: gitk:2994
+#, tcl-format
+msgid "<%s-Down>\tScroll commit list down one line"
+msgstr "<%s-Down>\tCuộn danh sách lần chuyển giao xuống một dòng"
+
+#: gitk:2995
+#, tcl-format
+msgid "<%s-PageUp>\tScroll commit list up one page"
+msgstr "<%s-PageUp>\tCuộn danh sách lần chuyển giao lên một trang"
+
+#: gitk:2996
+#, tcl-format
+msgid "<%s-PageDown>\tScroll commit list down one page"
+msgstr "<%s-PageDown>\tCuộn danh sách lần chuyển giao xuống một trang"
+
+#: gitk:2997
+msgid "<Shift-Up>\tFind backwards (upwards, later commits)"
+msgstr "<Shift-Up>\tTìm về phía sau (hướng lên trên, lần chuyển giao sau này)"
+
+#: gitk:2998
+msgid "<Shift-Down>\tFind forwards (downwards, earlier commits)"
+msgstr ""
+"<Shift-Down>\tTìm về phía trước (hướng xuống dưới, lần chuyển giao trước đây)"
+
+#: gitk:2999
+msgid "<Delete>, b\tScroll diff view up one page"
+msgstr "<Delete>, b\tCuộn phần trình bày diff lên một trang"
+
+#: gitk:3000
+msgid "<Backspace>\tScroll diff view up one page"
+msgstr "<Backspace>\tCuộn phần trình bày diff lên một trang"
+
+#: gitk:3001
+msgid "<Space>\t\tScroll diff view down one page"
+msgstr "<Space>\t\tCuộn phần trình bày diff xuống một trang"
+
+#: gitk:3002
+msgid "u\t\tScroll diff view up 18 lines"
+msgstr "u\t\tCuộn phần trình bày diff lên 18 dòng"
+
+#: gitk:3003
+msgid "d\t\tScroll diff view down 18 lines"
+msgstr "d\t\tCuộn phần trình bày diff xuống 18 dòng"
+
+#: gitk:3004
+#, tcl-format
+msgid "<%s-F>\t\tFind"
+msgstr "<%s-F>\t\tTìm kiếm"
+
+#: gitk:3005
+#, tcl-format
+msgid "<%s-G>\t\tMove to next find hit"
+msgstr "<%s-G>\t\tDi chuyển đến chỗ gặp kế tiếp"
+
+#: gitk:3006
+msgid "<Return>\tMove to next find hit"
+msgstr "<Return>\t\tDi chuyển đến chỗ gặp kế tiếp"
+
+#: gitk:3007
+msgid "/\t\tFocus the search box"
+msgstr "/\t\tĐưa con trỏ chuột vào ô tìm kiếm"
+
+#: gitk:3008
+msgid "?\t\tMove to previous find hit"
+msgstr "?\t\tDi chuyển đến chỗ gặp kế trước"
+
+#: gitk:3009
+msgid "f\t\tScroll diff view to next file"
+msgstr "f\t\tCuộn phần trình bày diff sang tập-tin kế"
+
+#: gitk:3010
+#, tcl-format
+msgid "<%s-S>\t\tSearch for next hit in diff view"
+msgstr "<%s-S>\t\tTìm đến chỗ khác biệt kế tiếp"
+
+#: gitk:3011
+#, tcl-format
+msgid "<%s-R>\t\tSearch for previous hit in diff view"
+msgstr "<%s-R>\t\tTìm đến chỗ khác biệt kế trước"
+
+#: gitk:3012
+#, tcl-format
+msgid "<%s-KP+>\tIncrease font size"
+msgstr "<%s-KP+>\tTăng cỡ chữ"
+
+#: gitk:3013
+#, tcl-format
+msgid "<%s-plus>\tIncrease font size"
+msgstr "<%s-plus>\tTăng cỡ chữ"
+
+#: gitk:3014
+#, tcl-format
+msgid "<%s-KP->\tDecrease font size"
+msgstr "<%s-KP->\tGiảm cỡ chữ"
+
+#: gitk:3015
+#, tcl-format
+msgid "<%s-minus>\tDecrease font size"
+msgstr "<%s-minus>\tGiảm cỡ chữ"
+
+#: gitk:3016
+msgid "<F5>\t\tUpdate"
+msgstr "<F5>\t\tCập nhật"
+
+#: gitk:3471 gitk:3480
+#, tcl-format
+msgid "Error creating temporary directory %s:"
+msgstr "Gặp lỗi khi tạo thư mục tạm %s:"
+
+#: gitk:3493
+#, tcl-format
+msgid "Error getting \"%s\" from %s:"
+msgstr "Lỗi chào hỏi \"%s\" từ %s:"
+
+#: gitk:3556
+msgid "command failed:"
+msgstr "lệnh gặp lỗi:"
+
+#: gitk:3705
+msgid "No such commit"
+msgstr "Không có lần chuyển giao như vậy"
+
+#: gitk:3719
+msgid "git gui blame: command failed:"
+msgstr "git gui blame: lệnh gặp lỗi:"
+
+#: gitk:3750
+#, tcl-format
+msgid "Couldn't read merge head: %s"
+msgstr "Không thể độc đầu của hòa trộn: %s"
+
+# tcl-format
+#: gitk:3758
+#, tcl-format
+msgid "Error reading index: %s"
+msgstr "Gặp lỗi khi đọc chỉ mục: %s"
+
+#: gitk:3783
+#, tcl-format
+msgid "Couldn't start git blame: %s"
+msgstr "Không thể khởi chạy git blame: %s"
+
+#: gitk:3786 gitk:6652
+msgid "Searching"
+msgstr "Đang tìm kiếm"
+
+#: gitk:3818
+#, tcl-format
+msgid "Error running git blame: %s"
+msgstr "Gặp lỗi khi chạy git blame: %s"
+
+#: gitk:3846
+#, tcl-format
+msgid "That line comes from commit %s,  which is not in this view"
+msgstr "Dòng đến từ lần chuyển giao %s, cái mà không trong trình bày này"
+
+#: gitk:3860
+msgid "External diff viewer failed:"
+msgstr "Bộ trình bày diff từ bên ngoài gặp lỗi:"
+
+#: gitk:3978
+msgid "Gitk view definition"
+msgstr "Định nghĩa cách trình bày gitk"
+
+#: gitk:3982
+msgid "Remember this view"
+msgstr "Nhớ cách trình bày này"
+
+#: gitk:3983
+msgid "References (space separated list):"
+msgstr "Tham chiếu (danh sách ngăn cách bằng dấu cách):"
+
+#: gitk:3984
+msgid "Branches & tags:"
+msgstr "Nhánh & thẻ:"
+
+#: gitk:3985
+msgid "All refs"
+msgstr "Mọi tham chiếu"
+
+#: gitk:3986
+msgid "All (local) branches"
+msgstr "Mọi nhánh (nội bộ)"
+
+#: gitk:3987
+msgid "All tags"
+msgstr "Mọi thẻ"
+
+#: gitk:3988
+msgid "All remote-tracking branches"
+msgstr "Mọi nhánh remote-tracking"
+
+#: gitk:3989
+msgid "Commit Info (regular expressions):"
+msgstr "Thông tin chuyển giao (biểu thức chính quy):"
+
+#: gitk:3990
+msgid "Author:"
+msgstr "Tác giả:"
+
+#: gitk:3991
+msgid "Committer:"
+msgstr "Người chuyển giao:"
+
+#: gitk:3992
+msgid "Commit Message:"
+msgstr "Chú thích của lần chuyển giao:"
+
+#: gitk:3993
+msgid "Matches all Commit Info criteria"
+msgstr "Khớp mọi điều kiện Thông tin Chuyển giao"
+
+#: gitk:3994
+msgid "Changes to Files:"
+msgstr "Đổi thành Tập tin:"
+
+#: gitk:3995
+msgid "Fixed String"
+msgstr "Chuỗi cố định"
+
+#: gitk:3996
+msgid "Regular Expression"
+msgstr "Biểu thức chính quy"
+
+#: gitk:3997
+msgid "Search string:"
+msgstr "Chuỗi tìm kiếm:"
+
+#: gitk:3998
+msgid ""
+"Commit Dates (\"2 weeks ago\", \"2009-03-17 15:27:38\", \"March 17, 2009 "
+"15:27:38\"):"
+msgstr ""
+"Ngày chuyển giao (\"2 weeks ago\", \"2009-03-17 15:27:38\", \"March 17, 2009 "
+"15:27:38\"):"
+
+#: gitk:3999
+msgid "Since:"
+msgstr "Kể từ:"
+
+#: gitk:4000
+msgid "Until:"
+msgstr "Đến:"
+
+#: gitk:4001
+msgid "Limit and/or skip a number of revisions (positive integer):"
+msgstr "Giới hạn và/hoặc bỏ số của điểm xét (số nguyên âm):"
+
+#: gitk:4002
+msgid "Number to show:"
+msgstr "Số lượng hiển thị:"
+
+#: gitk:4003
+msgid "Number to skip:"
+msgstr "Số lượng sẽ bỏ qua:"
+
+#: gitk:4004
+msgid "Miscellaneous options:"
+msgstr "Tuỳ chọn hỗn hợp:"
+
+#: gitk:4005
+msgid "Strictly sort by date"
+msgstr "Sắp xếp chặt chẽ theo ngày"
+
+#: gitk:4006
+msgid "Mark branch sides"
+msgstr "Đánh dấu các cạnh nhánh"
+
+#: gitk:4007
+msgid "Limit to first parent"
+msgstr "Giới hạn thành cha mẹ đầu tiên"
+
+#: gitk:4008
+msgid "Simple history"
+msgstr "Lịch sử dạng đơn giản"
+
+#: gitk:4009
+msgid "Additional arguments to git log:"
+msgstr "Đối số bổ xung cho lệnh git log:"
+
+#: gitk:4010
+msgid "Enter files and directories to include, one per line:"
+msgstr "Nhập vào các tập tin và thư mục bao gồm, mỗi dòng một cái:"
+
+#: gitk:4011
+msgid "Command to generate more commits to include:"
+msgstr "Lệnh tạo ra nhiều lần chuyển giao hơn bao gồm:"
+
+#: gitk:4135
+msgid "Gitk: edit view"
+msgstr "Gitk: sửa cách trình bày"
+
+#: gitk:4143
+msgid "-- criteria for selecting revisions"
+msgstr "-- tiêu chuẩn chọn điểm xét duyệt"
+
+#: gitk:4148
+msgid "View Name"
+msgstr "Tên cách trình bày"
+
+#: gitk:4223
+msgid "Apply (F5)"
+msgstr "Áp dụng (F5)"
+
+#: gitk:4261
+msgid "Error in commit selection arguments:"
+msgstr "Lỗi trong các đối số chọn chuyển giao:"
+
+#: gitk:4314 gitk:4366 gitk:4827 gitk:4841 gitk:6107 gitk:12184 gitk:12185
+msgid "None"
+msgstr "Không"
+
+#: gitk:4924 gitk:4929
+msgid "Descendant"
+msgstr "Con cháu"
+
+#: gitk:4925
+msgid "Not descendant"
+msgstr "Không có con cháu"
+
+#: gitk:4932 gitk:4937
+msgid "Ancestor"
+msgstr "Tổ tiên chung"
+
+#: gitk:4933
+msgid "Not ancestor"
+msgstr "Không có chung tổ tiên"
+
+#: gitk:5223
+msgid "Local changes checked in to index but not committed"
+msgstr ""
+"Có thay đổi nội bộ đã được đưa vào bảng mục lục, nhưng chưa được chuyển giao"
+
+#: gitk:5259
+msgid "Local uncommitted changes, not checked in to index"
+msgstr "Có thay đổi nội bộ, nhưng chưa được đưa vào bảng mục lục"
+
+#: gitk:7032
+msgid "and many more"
+msgstr "và nhiều nữa"
+
+#: gitk:7035
+msgid "many"
+msgstr "nhiều"
+
+#: gitk:7222
+msgid "Tags:"
+msgstr "Thẻ:"
+
+#: gitk:7239 gitk:7245 gitk:8708
+msgid "Parent"
+msgstr "Cha"
+
+#: gitk:7250
+msgid "Child"
+msgstr "Con"
+
+#: gitk:7259
+msgid "Branch"
+msgstr "Nhánh"
+
+#: gitk:7262
+msgid "Follows"
+msgstr "Đứng sau"
+
+#: gitk:7265
+msgid "Precedes"
+msgstr "Đứng trước"
+
+# tcl-format
+#: gitk:7849
+#, tcl-format
+msgid "Error getting diffs: %s"
+msgstr "Lỗi lấy diff: %s"
+
+#: gitk:8533
+msgid "Goto:"
+msgstr "Nhảy tới:"
+
+#: gitk:8554
+#, tcl-format
+msgid "Short SHA1 id %s is ambiguous"
+msgstr "Định danh SHA1 dạng ngắn %s là chưa đủ rõ ràng"
+
+#: gitk:8561
+#, tcl-format
+msgid "Revision %s is not known"
+msgstr "Không hiểu điểm xét duyệt %s"
+
+#: gitk:8571
+#, tcl-format
+msgid "SHA1 id %s is not known"
+msgstr "Không hiểu định danh SHA1 %s"
+
+#: gitk:8573
+#, tcl-format
+msgid "Revision %s is not in the current view"
+msgstr "Điểm %s không ở trong phần hiển thị hiện tại"
+
+#: gitk:8715 gitk:8730
+msgid "Date"
+msgstr "Ngày"
+
+#: gitk:8718
+msgid "Children"
+msgstr "Con cháu"
+
+#: gitk:8781
+#, tcl-format
+msgid "Reset %s branch to here"
+msgstr "Đặt lại nhánh %s tại đây"
+
+#: gitk:8783
+msgid "Detached head: can't reset"
+msgstr "Head đã bị tách rời: không thể đặt lại"
+
+#: gitk:8888 gitk:8894
+msgid "Skipping merge commit "
+msgstr "Bỏ qua lần chuyển giao hòa trộn "
+
+#: gitk:8903 gitk:8908
+msgid "Error getting patch ID for "
+msgstr "Gặp lỗi khi lấy ID miếng vá cho "
+
+#: gitk:8904 gitk:8909
+msgid " - stopping\n"
+msgstr " - dừng\n"
+
+#: gitk:8914 gitk:8917 gitk:8925 gitk:8939 gitk:8948
+msgid "Commit "
+msgstr "Commit "
+
+#: gitk:8918
+msgid ""
+" is the same patch as\n"
+"       "
+msgstr ""
+" là cùng một miếng vá với\n"
+"       "
+
+#: gitk:8926
+msgid ""
+" differs from\n"
+"       "
+msgstr ""
+" khác biệt từ\n"
+"       "
+
+#: gitk:8928
+msgid ""
+"Diff of commits:\n"
+"\n"
+msgstr ""
+"Khác biệt của lần chuyển giao (commit):\n"
+"\n"
+
+#: gitk:8940 gitk:8949
+#, tcl-format
+msgid " has %s children - stopping\n"
+msgstr " có %s con - dừng\n"
+
+#: gitk:8968
+#, tcl-format
+msgid "Error writing commit to file: %s"
+msgstr "Gặp lỗi trong quá trình ghi lần chuyển giao vào tập tin: %s"
+
+#: gitk:8974
+#, tcl-format
+msgid "Error diffing commits: %s"
+msgstr "Gặp lỗi khi so sánh sự khác biệt giữa các lần chuyển giao: %s"
+
+#: gitk:9020
+msgid "Top"
+msgstr "Đỉnh"
+
+#: gitk:9021
+msgid "From"
+msgstr "Từ"
+
+#: gitk:9026
+msgid "To"
+msgstr "Đến"
+
+#: gitk:9050
+msgid "Generate patch"
+msgstr "Tạo miếng vá"
+
+#: gitk:9052
+msgid "From:"
+msgstr "Từ:"
+
+#: gitk:9061
+msgid "To:"
+msgstr "Đến:"
+
+#: gitk:9070
+msgid "Reverse"
+msgstr "Đảo ngược"
+
+#: gitk:9072 gitk:9268
+msgid "Output file:"
+msgstr "Tập tin kết xuất:"
+
+#: gitk:9078
+msgid "Generate"
+msgstr "Tạo"
+
+#: gitk:9116
+msgid "Error creating patch:"
+msgstr "Gặp lỗi khi tạo miếng vá:"
+
+#: gitk:9139 gitk:9256 gitk:9313
+msgid "ID:"
+msgstr "ID:"
+
+#: gitk:9148
+msgid "Tag name:"
+msgstr "Tên thẻ:"
+
+#: gitk:9151
+msgid "Tag message is optional"
+msgstr "Ghi chú thẻ chỉ là tùy chọn"
+
+#: gitk:9153
+msgid "Tag message:"
+msgstr "Ghi chú cho thẻ:"
+
+#: gitk:9157 gitk:9322
+msgid "Create"
+msgstr "Tạo"
+
+#: gitk:9175
+msgid "No tag name specified"
+msgstr "Chưa chỉ ra tên của thẻ"
+
+#: gitk:9179
+#, tcl-format
+msgid "Tag \"%s\" already exists"
+msgstr "Thẻ “%s” đã có sẵn rồi"
+
+#: gitk:9189
+msgid "Error creating tag:"
+msgstr "Gặp lỗi khi tạo thẻ:"
+
+#: gitk:9265
+msgid "Command:"
+msgstr "Lệnh:"
+
+#: gitk:9273
+msgid "Write"
+msgstr "Ghi"
+
+#: gitk:9291
+msgid "Error writing commit:"
+msgstr "Gặp lỗi trong quá trình ghi chuyển giao:"
+
+#: gitk:9318
+msgid "Name:"
+msgstr "Tên:"
+
+#: gitk:9341
+msgid "Please specify a name for the new branch"
+msgstr "Vui lòng chỉ định tên cho nhánh mới"
+
+#: gitk:9346
+#, tcl-format
+msgid "Branch '%s' already exists. Overwrite?"
+msgstr "Nhánh “%s” đã có từ trước rồi. Ghi đè?"
+
+#: gitk:9413
+#, tcl-format
+msgid "Commit %s is already included in branch %s -- really re-apply it?"
+msgstr ""
+"Lần chuyển giao %s đã sẵn được bao gồm trong nhánh %s -- bạn có thực sự muốn "
+"áp dụng lại nó không?"
+
+#: gitk:9418
+msgid "Cherry-picking"
+msgstr "Đang cherry-pick"
+
+#: gitk:9427
+#, tcl-format
+msgid ""
+"Cherry-pick failed because of local changes to file '%s'.\n"
+"Please commit, reset or stash your changes and try again."
+msgstr ""
+"Cherry-pick gặp lỗi bởi vì các thay đổi nội bộ tập tin “%s”.\n"
+"Xin hãy chuyển giao, reset hay stash các thay đổi của bạn sau đó thử lại."
+
+#: gitk:9433
+msgid ""
+"Cherry-pick failed because of merge conflict.\n"
+"Do you wish to run git citool to resolve it?"
+msgstr ""
+"Cherry-pick gặp lỗi bởi vì xung đột trong hòa trộn.\n"
+"Bạn có muốn chạy lệnh “git citool” để giải quyết vấn đề này không?"
+
+#: gitk:9449 gitk:9507
+msgid "No changes committed"
+msgstr "Không có thay đổi nào cần chuyển giao"
+
+#: gitk:9476
+#, tcl-format
+msgid "Commit %s is not included in branch %s -- really revert it?"
+msgstr ""
+"Lần chuyển giao %s không được bao gồm trong nhánh %s -- bạn có thực sự muốn "
+"“revert” nó không?"
+
+#: gitk:9481
+msgid "Reverting"
+msgstr "Đang hoàn tác"
+
+#: gitk:9489
+#, tcl-format
+msgid ""
+"Revert failed because of local changes to the following files:%s Please "
+"commit, reset or stash  your changes and try again."
+msgstr ""
+"Revert gặp lỗi bởi vì tập tin sau đã được thay đổi nội bộ:%s\n"
+"Xin hãy chạy lệnh “commit”, “reset” hoặc “stash” rồi thử lại."
+
+#: gitk:9493
+msgid ""
+"Revert failed because of merge conflict.\n"
+" Do you wish to run git citool to resolve it?"
+msgstr ""
+"Revert gặp lỗi bởi vì xung đột hòa trộn.\n"
+" Bạn có muốn chạy lệnh “git citool” để phân giải nó không?"
+
+#: gitk:9536
+msgid "Confirm reset"
+msgstr "Xác nhật đặt lại"
+
+#: gitk:9538
+#, tcl-format
+msgid "Reset branch %s to %s?"
+msgstr "Đặt lại nhánh “%s” thành “%s”?"
+
+#: gitk:9540
+msgid "Reset type:"
+msgstr "Kiểu đặt lại:"
+
+#: gitk:9543
+msgid "Soft: Leave working tree and index untouched"
+msgstr "Mềm: Không động đến thư mục làm việc và bảng mục lục"
+
+#: gitk:9546
+msgid "Mixed: Leave working tree untouched, reset index"
+msgstr ""
+"Pha trộn: Không động chạm đến thư mục làm việc nhưng đặt lại bảng mục lục"
+
+#: gitk:9549
+msgid ""
+"Hard: Reset working tree and index\n"
+"(discard ALL local changes)"
+msgstr ""
+"Hard: Đặt lại cây làm việc và mục lục\n"
+"(hủy bỏ MỌI thay đổi nội bộ)"
+
+#: gitk:9566
+msgid "Resetting"
+msgstr "Đang đặt lại"
+
+#: gitk:9626
+msgid "Checking out"
+msgstr "Đang checkout"
+
+#: gitk:9679
+msgid "Cannot delete the currently checked-out branch"
+msgstr "Không thể xóa nhánh hiện tại đang được lấy ra"
+
+#: gitk:9685
+#, tcl-format
+msgid ""
+"The commits on branch %s aren't on any other branch.\n"
+"Really delete branch %s?"
+msgstr ""
+"Các lần chuyển giao trên nhánh %s không ở trên nhánh khác.\n"
+"Thực sự muốn xóa nhánh %s?"
+
+#: gitk:9716
+#, tcl-format
+msgid "Tags and heads: %s"
+msgstr "Thẻ và Đầu: %s"
+
+#: gitk:9731
+msgid "Filter"
+msgstr "Bộ lọc"
+
+#: gitk:10027
+msgid ""
+"Error reading commit topology information; branch and preceding/following "
+"tag information will be incomplete."
+msgstr ""
+"Gặp lỗi khi đọc thông tin hình học lần chuyển giao; thông tin nhánh và thẻ "
+"trước/sau sẽ không hoàn thiện."
+
+#: gitk:11004
+msgid "Tag"
+msgstr "Thẻ"
+
+#: gitk:11008
+msgid "Id"
+msgstr "Id"
+
+#: gitk:11091
+msgid "Gitk font chooser"
+msgstr "Hộp thoại chọn phông Gitk"
+
+#: gitk:11108
+msgid "B"
+msgstr "B"
+
+#: gitk:11111
+msgid "I"
+msgstr "I"
+
+#: gitk:11229
+msgid "Commit list display options"
+msgstr "Các tùy chọn về hiển thị danh sách lần chuyển giao"
+
+#: gitk:11232
+msgid "Maximum graph width (lines)"
+msgstr "Độ rộng biểu đồ tối đa (dòng)"
+
+#: gitk:11235
+#, tcl-format
+msgid "Maximum graph width (% of pane)"
+msgstr "Độ rộng biểu đồ tối đa (% của bảng)"
+
+#: gitk:11238
+msgid "Show local changes"
+msgstr "Hiển thị các thay đổi nội bộ"
+
+#: gitk:11241
+msgid "Auto-select SHA1 (length)"
+msgstr "Tự chọn SHA1 (độ dài)"
+
+#: gitk:11245
+msgid "Hide remote refs"
+msgstr "Ẩn tham chiếu đến máy chủ"
+
+#: gitk:11249
+msgid "Diff display options"
+msgstr "Các tùy chọn trình bày các khác biệt"
+
+#: gitk:11251
+msgid "Tab spacing"
+msgstr "Khoảng cách tab"
+
+#: gitk:11254
+msgid "Display nearby tags/heads"
+msgstr "Hiển thị các thẻ/đầu xung quanh"
+
+#: gitk:11257
+msgid "Maximum # tags/heads to show"
+msgstr "Số lượng thẻ/đầu tối đa sẽ hiển thị"
+
+#: gitk:11260
+msgid "Limit diffs to listed paths"
+msgstr "Giới hạn các khác biệt cho đường dẫn đã liệt kê"
+
+#: gitk:11263
+msgid "Support per-file encodings"
+msgstr "Hỗ trợ mã hóa mỗi-dòng"
+
+#: gitk:11269 gitk:11416
+msgid "External diff tool"
+msgstr "Công cụ so sánh từ bên ngoài"
+
+#: gitk:11270
+msgid "Choose..."
+msgstr "Chọn..."
+
+#: gitk:11275
+msgid "General options"
+msgstr "Các tùy chọn chung"
+
+#: gitk:11278
+msgid "Use themed widgets"
+msgstr "Dùng các widget chủ đề"
+
+#: gitk:11280
+msgid "(change requires restart)"
+msgstr "(để thay đổi cần khởi động lại)"
+
+#: gitk:11282
+msgid "(currently unavailable)"
+msgstr "(hiện tại không sẵn sàng)"
+
+#: gitk:11293
+msgid "Colors: press to choose"
+msgstr "Màu sắc: bấm vào nút phía dưới để chọn màu"
+
+#: gitk:11296
+msgid "Interface"
+msgstr "Giao diện"
+
+#: gitk:11297
+msgid "interface"
+msgstr "giao diện"
+
+#: gitk:11300
+msgid "Background"
+msgstr "Nền"
+
+#: gitk:11301 gitk:11331
+msgid "background"
+msgstr "nền"
+
+#: gitk:11304
+msgid "Foreground"
+msgstr "Tiền cảnh"
+
+#: gitk:11305
+msgid "foreground"
+msgstr "tiền cảnh"
+
+#: gitk:11308
+msgid "Diff: old lines"
+msgstr "So sánh: dòng cũ"
+
+#: gitk:11309
+msgid "diff old lines"
+msgstr "diff dòng cũ"
+
+#: gitk:11313
+msgid "Diff: new lines"
+msgstr "So sánh: dòng mới"
+
+#: gitk:11314
+msgid "diff new lines"
+msgstr "màu dòng mới"
+
+#: gitk:11318
+msgid "Diff: hunk header"
+msgstr "So sánh: phần đầu của đoạn"
+
+#: gitk:11320
+msgid "diff hunk header"
+msgstr "màu của phần đầu của đoạn khi so sánh"
+
+#: gitk:11324
+msgid "Marked line bg"
+msgstr "Nền dòng đánh dấu"
+
+#: gitk:11326
+msgid "marked line background"
+msgstr "nền dòng được đánh dấu"
+
+#: gitk:11330
+msgid "Select bg"
+msgstr "Màu nền"
+
+#: gitk:11339
+msgid "Fonts: press to choose"
+msgstr "Phông chữ: bấm vào các nút ở dưới để chọn"
+
+#: gitk:11341
+msgid "Main font"
+msgstr "Phông chữ chính"
+
+#: gitk:11342
+msgid "Diff display font"
+msgstr "Phông chữ dùng khi so sánh"
+
+#: gitk:11343
+msgid "User interface font"
+msgstr "Phông chữ giao diện"
+
+#: gitk:11365
+msgid "Gitk preferences"
+msgstr "Cá nhân hóa các cài đặt cho Gitk"
+
+#: gitk:11374
+msgid "General"
+msgstr "Chung"
+
+#: gitk:11375
+msgid "Colors"
+msgstr "Màu sắc"
+
+#: gitk:11376
+msgid "Fonts"
+msgstr "Phông chữ"
+
+#: gitk:11426
+#, tcl-format
+msgid "Gitk: choose color for %s"
+msgstr "Gitk: chọn màu cho %s"
+
+#: gitk:12080
+msgid "Cannot find a git repository here."
+msgstr "Không thể tìm thấy kho git ở đây."
+
+#: gitk:12127
+#, tcl-format
+msgid "Ambiguous argument '%s': both revision and filename"
+msgstr "Đối số “%s” chưa rõ ràng: vừa là điểm xét duyệt vừa là tên tập tin"
+
+#: gitk:12139
+msgid "Bad arguments to gitk:"
+msgstr "Đối số không hợp lệ cho gitk:"
+
+#: gitk:12242
+msgid "Command line"
+msgstr "Dòng lệnh"
index 8b0e87436b687ce26e3e4987129a2fc171069280..ff07012726ea28daa2551966d0555d2e8efa2375 100644 (file)
@@ -7,6 +7,20 @@
 static char *configured_signing_key;
 static const char *gpg_program = "gpg";
 
+void signature_check_clear(struct signature_check *sigc)
+{
+       free(sigc->payload);
+       free(sigc->gpg_output);
+       free(sigc->gpg_status);
+       free(sigc->signer);
+       free(sigc->key);
+       sigc->payload = NULL;
+       sigc->gpg_output = NULL;
+       sigc->gpg_status = NULL;
+       sigc->signer = NULL;
+       sigc->key = NULL;
+}
+
 void set_signing_key(const char *key)
 {
        free(configured_signing_key);
index a85cb5bc97cdd61000b4c48c54faa656aa3cfaca..37c23daff010b0de18fa12ff6a6167f45ff41ffc 100644 (file)
@@ -2,6 +2,7 @@
 #define GPG_INTERFACE_H
 
 struct signature_check {
+       char *payload;
        char *gpg_output;
        char *gpg_status;
        char result; /* 0 (not checked),
@@ -13,6 +14,7 @@ struct signature_check {
        char *key;
 };
 
+extern void signature_check_clear(struct signature_check *sigc);
 extern int sign_buffer(struct strbuf *buffer, struct strbuf *signature, const char *signing_key);
 extern int verify_signed_buffer(const char *payload, size_t payload_size, const char *signature, size_t signature_size, struct strbuf *gpg_output, struct strbuf *gpg_status);
 extern int git_gpg_config(const char *, const char *, void *);
diff --git a/grep.c b/grep.c
index 4aef0a69d084deee61486e43bc62ae2da6b6b440..99217dc04f5d04c761f094069f1053cb090baaf1 100644 (file)
--- a/grep.c
+++ b/grep.c
@@ -86,6 +86,11 @@ int grep_config(const char *var, const char *value, void *cb)
                return 0;
        }
 
+       if (!strcmp(var, "grep.fullname")) {
+               opt->relative = !git_config_bool(var, value);
+               return 0;
+       }
+
        if (!strcmp(var, "color.grep"))
                opt->color = git_config_colorbool(var, value);
        else if (!strcmp(var, "color.grep.context"))
diff --git a/help.c b/help.c
index b266b09320c067221eb4fffa56e4778d5f8b3a9e..7af65e205ecdf1a01dce009cbf0ada15de68c844 100644 (file)
--- a/help.c
+++ b/help.c
@@ -129,7 +129,6 @@ static void list_commands_in_dir(struct cmdnames *cmds,
                                         const char *path,
                                         const char *prefix)
 {
-       int prefix_len;
        DIR *dir = opendir(path);
        struct dirent *de;
        struct strbuf buf = STRBUF_INIT;
@@ -139,15 +138,15 @@ static void list_commands_in_dir(struct cmdnames *cmds,
                return;
        if (!prefix)
                prefix = "git-";
-       prefix_len = strlen(prefix);
 
        strbuf_addf(&buf, "%s/", path);
        len = buf.len;
 
        while ((de = readdir(dir)) != NULL) {
-               int entlen;
+               const char *ent;
+               size_t entlen;
 
-               if (!starts_with(de->d_name, prefix))
+               if (!skip_prefix(de->d_name, prefix, &ent))
                        continue;
 
                strbuf_setlen(&buf, len);
@@ -155,11 +154,10 @@ static void list_commands_in_dir(struct cmdnames *cmds,
                if (!is_executable(buf.buf))
                        continue;
 
-               entlen = strlen(de->d_name) - prefix_len;
-               if (has_extension(de->d_name, ".exe"))
-                       entlen -= 4;
+               entlen = strlen(ent);
+               strip_suffix(ent, ".exe", &entlen);
 
-               add_cmdname(cmds, de->d_name + prefix_len, entlen);
+               add_cmdname(cmds, ent, entlen);
        }
        closedir(dir);
        strbuf_release(&buf);
@@ -251,11 +249,13 @@ static struct cmdnames aliases;
 
 static int git_unknown_cmd_config(const char *var, const char *value, void *cb)
 {
+       const char *p;
+
        if (!strcmp(var, "help.autocorrect"))
                autocorrect = git_config_int(var,value);
        /* Also use aliases for command lookup */
-       if (starts_with(var, "alias."))
-               add_cmdname(&aliases, var + 6, strlen(var + 6));
+       if (skip_prefix(var, "alias.", &p))
+               add_cmdname(&aliases, p, strlen(p));
 
        return git_default_config(var, value, cb);
 }
@@ -412,11 +412,12 @@ static int append_similar_ref(const char *refname, const unsigned char *sha1,
 {
        struct similar_ref_cb *cb = (struct similar_ref_cb *)(cb_data);
        char *branch = strrchr(refname, '/') + 1;
+       const char *remote;
+
        /* A remote branch of the same name is deemed similar */
-       if (starts_with(refname, "refs/remotes/") &&
+       if (skip_prefix(refname, "refs/remotes/", &remote) &&
            !strcmp(branch, cb->base_ref))
-               string_list_append(cb->similar_refs,
-                                  refname + strlen("refs/remotes/"));
+               string_list_append(cb->similar_refs, remote);
        return 0;
 }
 
index d2c0a625cef558df252af6927cd3a86424674862..57290d9bdafc730afaac3ddf8564d85ead39eb31 100644 (file)
@@ -221,17 +221,19 @@ static void get_idx_file(char *name)
 
 static int http_config(const char *var, const char *value, void *cb)
 {
+       const char *p;
+
        if (!strcmp(var, "http.getanyfile")) {
                getanyfile = git_config_bool(var, value);
                return 0;
        }
 
-       if (starts_with(var, "http.")) {
+       if (skip_prefix(var, "http.", &p)) {
                int i;
 
                for (i = 0; i < ARRAY_SIZE(rpc_service); i++) {
                        struct rpc_service *svc = &rpc_service[i];
-                       if (!strcmp(var + 5, svc->config_name)) {
+                       if (!strcmp(p, svc->config_name)) {
                                svc->enabled = git_config_bool(var, value);
                                return 0;
                        }
@@ -244,15 +246,16 @@ static int http_config(const char *var, const char *value, void *cb)
 
 static struct rpc_service *select_service(const char *name)
 {
+       const char *svc_name;
        struct rpc_service *svc = NULL;
        int i;
 
-       if (!starts_with(name, "git-"))
+       if (!skip_prefix(name, "git-", &svc_name))
                forbidden("Unsupported service: '%s'", name);
 
        for (i = 0; i < ARRAY_SIZE(rpc_service); i++) {
                struct rpc_service *s = &rpc_service[i];
-               if (!strcmp(s->name, name + 4)) {
+               if (!strcmp(s->name, svc_name)) {
                        svc = s;
                        break;
                }
index f2c56c84544be36414686ed2e27c8b08e8946e53..6c3cc1725a9461876c7db11b9818eb553afb2fc2 100644 (file)
@@ -719,14 +719,10 @@ static int fetch_indices(void)
        return ret;
 }
 
-static void one_remote_object(const char *hex)
+static void one_remote_object(const unsigned char *sha1)
 {
-       unsigned char sha1[20];
        struct object *obj;
 
-       if (get_sha1_hex(hex, sha1) != 0)
-               return;
-
        obj = lookup_object(sha1);
        if (!obj)
                obj = parse_object(sha1);
@@ -767,15 +763,13 @@ static void handle_new_lock_ctx(struct xml_ctx *ctx, int tag_closed)
 
        if (tag_closed && ctx->cdata) {
                if (!strcmp(ctx->name, DAV_ACTIVELOCK_OWNER)) {
-                       lock->owner = xmalloc(strlen(ctx->cdata) + 1);
-                       strcpy(lock->owner, ctx->cdata);
+                       lock->owner = xstrdup(ctx->cdata);
                } else if (!strcmp(ctx->name, DAV_ACTIVELOCK_TIMEOUT)) {
-                       if (starts_with(ctx->cdata, "Second-"))
-                               lock->timeout =
-                                       strtol(ctx->cdata + 7, NULL, 10);
+                       const char *arg;
+                       if (skip_prefix(ctx->cdata, "Second-", &arg))
+                               lock->timeout = strtol(arg, NULL, 10);
                } else if (!strcmp(ctx->name, DAV_ACTIVELOCK_TOKEN)) {
-                       lock->token = xmalloc(strlen(ctx->cdata) + 1);
-                       strcpy(lock->token, ctx->cdata);
+                       lock->token = xstrdup(ctx->cdata);
 
                        git_SHA1_Init(&sha_ctx);
                        git_SHA1_Update(&sha_ctx, lock->token, strlen(lock->token));
@@ -856,8 +850,7 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
        struct xml_ctx ctx;
        char *escaped;
 
-       url = xmalloc(strlen(repo->url) + strlen(path) + 1);
-       sprintf(url, "%s%s", repo->url, path);
+       url = xstrfmt("%s%s", repo->url, path);
 
        /* Make sure leading directories exist for the remote ref */
        ep = strchr(url + strlen(repo->url) + 1, '/');
@@ -1020,26 +1013,38 @@ static void remote_ls(const char *path, int flags,
                      void (*userFunc)(struct remote_ls_ctx *ls),
                      void *userData);
 
+/* extract hex from sharded "xx/x{40}" filename */
+static int get_sha1_hex_from_objpath(const char *path, unsigned char *sha1)
+{
+       char hex[40];
+
+       if (strlen(path) != 41)
+               return -1;
+
+       memcpy(hex, path, 2);
+       path += 2;
+       path++; /* skip '/' */
+       memcpy(hex, path, 38);
+
+       return get_sha1_hex(hex, sha1);
+}
+
 static void process_ls_object(struct remote_ls_ctx *ls)
 {
        unsigned int *parent = (unsigned int *)ls->userData;
-       char *path = ls->dentry_name;
-       char *obj_hex;
+       const char *path = ls->dentry_name;
+       unsigned char sha1[20];
 
        if (!strcmp(ls->path, ls->dentry_name) && (ls->flags & IS_DIR)) {
                remote_dir_exists[*parent] = 1;
                return;
        }
 
-       if (strlen(path) != 49)
+       if (!skip_prefix(path, "objects/", &path) ||
+           get_sha1_hex_from_objpath(path, sha1))
                return;
-       path += 8;
-       obj_hex = xmalloc(strlen(path));
-       /* NB: path is not null-terminated, can not use strlcpy here */
-       memcpy(obj_hex, path, 2);
-       strcpy(obj_hex + 2, path + 3);
-       one_remote_object(obj_hex);
-       free(obj_hex);
+
+       one_remote_object(sha1);
 }
 
 static void process_ls_ref(struct remote_ls_ctx *ls)
@@ -1117,7 +1122,7 @@ static void remote_ls(const char *path, int flags,
                      void (*userFunc)(struct remote_ls_ctx *ls),
                      void *userData)
 {
-       char *url = xmalloc(strlen(repo->url) + strlen(path) + 1);
+       char *url = xstrfmt("%s%s", repo->url, path);
        struct active_request_slot *slot;
        struct slot_results results;
        struct strbuf in_buffer = STRBUF_INIT;
@@ -1133,8 +1138,6 @@ static void remote_ls(const char *path, int flags,
        ls.userData = userData;
        ls.userFunc = userFunc;
 
-       sprintf(url, "%s%s", repo->url, path);
-
        strbuf_addf(&out_buffer.buf, PROPFIND_ALL_REQUEST);
 
        dav_headers = curl_slist_append(dav_headers, "Depth: 1");
@@ -1536,10 +1539,9 @@ static void update_remote_info_refs(struct remote_lock *lock)
 
 static int remote_exists(const char *path)
 {
-       char *url = xmalloc(strlen(repo->url) + strlen(path) + 1);
+       char *url = xstrfmt("%s%s", repo->url, path);
        int ret;
 
-       sprintf(url, "%s%s", repo->url, path);
 
        switch (http_get_strbuf(url, NULL, NULL)) {
        case HTTP_OK:
@@ -1559,11 +1561,9 @@ static int remote_exists(const char *path)
 
 static void fetch_symref(const char *path, char **symref, unsigned char *sha1)
 {
-       char *url;
+       char *url = xstrfmt("%s%s", repo->url, path);
        struct strbuf buffer = STRBUF_INIT;
-
-       url = xmalloc(strlen(repo->url) + strlen(path) + 1);
-       sprintf(url, "%s%s", repo->url, path);
+       const char *name;
 
        if (http_get_strbuf(url, &buffer, NULL) != HTTP_OK)
                die("Couldn't get %s for remote symref\n%s", url,
@@ -1578,8 +1578,8 @@ static void fetch_symref(const char *path, char **symref, unsigned char *sha1)
                return;
 
        /* If it's a symref, set the refname; otherwise try for a sha1 */
-       if (starts_with((char *)buffer.buf, "ref: ")) {
-               *symref = xmemdupz((char *)buffer.buf + 5, buffer.len - 6);
+       if (skip_prefix(buffer.buf, "ref: ", &name)) {
+               *symref = xmemdupz(name, buffer.len - (name - buffer.buf));
        } else {
                get_sha1_hex(buffer.buf, sha1);
        }
@@ -1673,8 +1673,7 @@ static int delete_remote_branch(const char *pattern, int force)
        fprintf(stderr, "Removing remote branch '%s'\n", remote_ref->name);
        if (dry_run)
                return 0;
-       url = xmalloc(strlen(repo->url) + strlen(remote_ref->name) + 1);
-       sprintf(url, "%s%s", repo->url, remote_ref->name);
+       url = xstrfmt("%s%s", repo->url, remote_ref->name);
        slot = get_active_slot();
        slot->results = &results;
        curl_setup_http_get(slot->curl, url, DAV_DELETE);
@@ -1732,7 +1731,7 @@ int main(int argc, char **argv)
 
        git_extract_argv0_path(argv[0]);
 
-       repo = xcalloc(sizeof(*repo), 1);
+       repo = xcalloc(1, sizeof(*repo));
 
        argv++;
        for (i = 1; i < argc; i++, argv++) {
index 1516c5eb290746bad4551515fda7930d2f55d32b..dbddfaa1773265a2917d4715158f16845d7139e5 100644 (file)
@@ -341,8 +341,7 @@ static void fetch_alternates(struct walker *walker, const char *base)
        if (walker->get_verbosely)
                fprintf(stderr, "Getting alternates list for %s\n", base);
 
-       url = xmalloc(strlen(base) + 31);
-       sprintf(url, "%s/objects/info/http-alternates", base);
+       url = xstrfmt("%s/objects/info/http-alternates", base);
 
        /*
         * Use a callback to process the result, since another request
@@ -566,8 +565,7 @@ struct walker *get_http_walker(const char *url)
        struct walker *walker = xmalloc(sizeof(struct walker));
 
        data->alt = xmalloc(sizeof(*data->alt));
-       data->alt->base = xmalloc(strlen(url) + 1);
-       strcpy(data->alt->base, url);
+       data->alt->base = xstrdup(url);
        for (s = data->alt->base + strlen(data->alt->base) - 1; *s == '/'; --s)
                *s = 0;
 
diff --git a/http.c b/http.c
index 94e1afdee7890825dfda0946b999f524265603fc..c8cd50dd0c2b2213a86957cd4b24c03c0d85717d 100644 (file)
--- a/http.c
+++ b/http.c
@@ -906,6 +906,83 @@ static CURLcode curlinfo_strbuf(CURL *curl, CURLINFO info, struct strbuf *buf)
        return ret;
 }
 
+/*
+ * Check for and extract a content-type parameter. "raw"
+ * should be positioned at the start of the potential
+ * parameter, with any whitespace already removed.
+ *
+ * "name" is the name of the parameter. The value is appended
+ * to "out".
+ */
+static int extract_param(const char *raw, const char *name,
+                        struct strbuf *out)
+{
+       size_t len = strlen(name);
+
+       if (strncasecmp(raw, name, len))
+               return -1;
+       raw += len;
+
+       if (*raw != '=')
+               return -1;
+       raw++;
+
+       while (*raw && !isspace(*raw) && *raw != ';')
+               strbuf_addch(out, *raw++);
+       return 0;
+}
+
+/*
+ * Extract a normalized version of the content type, with any
+ * spaces suppressed, all letters lowercased, and no trailing ";"
+ * or parameters.
+ *
+ * Note that we will silently remove even invalid whitespace. For
+ * example, "text / plain" is specifically forbidden by RFC 2616,
+ * but "text/plain" is the only reasonable output, and this keeps
+ * our code simple.
+ *
+ * If the "charset" argument is not NULL, store the value of any
+ * charset parameter there.
+ *
+ * Example:
+ *   "TEXT/PLAIN; charset=utf-8" -> "text/plain", "utf-8"
+ *   "text / plain" -> "text/plain"
+ */
+static void extract_content_type(struct strbuf *raw, struct strbuf *type,
+                                struct strbuf *charset)
+{
+       const char *p;
+
+       strbuf_reset(type);
+       strbuf_grow(type, raw->len);
+       for (p = raw->buf; *p; p++) {
+               if (isspace(*p))
+                       continue;
+               if (*p == ';') {
+                       p++;
+                       break;
+               }
+               strbuf_addch(type, tolower(*p));
+       }
+
+       if (!charset)
+               return;
+
+       strbuf_reset(charset);
+       while (*p) {
+               while (isspace(*p) || *p == ';')
+                       p++;
+               if (!extract_param(p, "charset", charset))
+                       return;
+               while (*p && !isspace(*p))
+                       p++;
+       }
+
+       if (!charset->len && starts_with(type->buf, "text/"))
+               strbuf_addstr(charset, "ISO-8859-1");
+}
+
 /* http_request() targets */
 #define HTTP_REQUEST_STRBUF    0
 #define HTTP_REQUEST_FILE      1
@@ -957,9 +1034,13 @@ static int http_request(const char *url,
 
        ret = run_one_slot(slot, &results);
 
-       if (options && options->content_type)
-               curlinfo_strbuf(slot->curl, CURLINFO_CONTENT_TYPE,
-                               options->content_type);
+       if (options && options->content_type) {
+               struct strbuf raw = STRBUF_INIT;
+               curlinfo_strbuf(slot->curl, CURLINFO_CONTENT_TYPE, &raw);
+               extract_content_type(&raw, options->content_type,
+                                    options->charset);
+               strbuf_release(&raw);
+       }
 
        if (options && options->effective_url)
                curlinfo_strbuf(slot->curl, CURLINFO_EFFECTIVE_URL,
@@ -1006,11 +1087,10 @@ static int update_url_from_redirect(struct strbuf *base,
        if (!strcmp(asked, got->buf))
                return 0;
 
-       if (!starts_with(asked, base->buf))
+       if (!skip_prefix(asked, base->buf, &tail))
                die("BUG: update_url_from_redirect: %s is not a superset of %s",
                    asked, base->buf);
 
-       tail = asked + base->len;
        tail_len = strlen(tail);
 
        if (got->len < tail_len ||
diff --git a/http.h b/http.h
index e64084fe6d455652bde1b02012b52879327e2c0a..473179b14d5648635853af4c5bf425116c32b6fe 100644 (file)
--- a/http.h
+++ b/http.h
@@ -143,6 +143,13 @@ struct http_get_options {
        /* If non-NULL, returns the content-type of the response. */
        struct strbuf *content_type;
 
+       /*
+        * If non-NULL, and content_type above is non-NULL, returns
+        * the charset parameter from the content-type. If none is
+        * present, returns an empty string.
+        */
+       struct strbuf *charset;
+
        /*
         * If non-NULL, returns the URL we ended up at, including any
         * redirects we followed.
index 0bc6f7fae151ea364e9d141b30b8e68d544a4448..524fbabc96f450f1faed196c1743d2f8d697b587 100644 (file)
@@ -23,9 +23,9 @@
  */
 
 #include "cache.h"
+#include "credential.h"
 #include "exec_cmd.h"
 #include "run-command.h"
-#include "prompt.h"
 #ifdef NO_OPENSSL
 typedef void *SSL;
 #endif
@@ -946,12 +946,13 @@ static int auth_cram_md5(struct imap_store *ctx, struct imap_cmd *cmd, const cha
 
 static struct imap_store *imap_open_store(struct imap_server_conf *srvc)
 {
+       struct credential cred = CREDENTIAL_INIT;
        struct imap_store *ctx;
        struct imap *imap;
        char *arg, *rsp;
        int s = -1, preauth;
 
-       ctx = xcalloc(sizeof(*ctx), 1);
+       ctx = xcalloc(1, sizeof(*ctx));
 
        ctx->imap = imap = xcalloc(sizeof(*imap), 1);
        imap->buf.sock.fd[0] = imap->buf.sock.fd[1] = -1;
@@ -1096,25 +1097,23 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc)
                }
 #endif
                imap_info("Logging in...\n");
-               if (!srvc->user) {
-                       fprintf(stderr, "Skipping server %s, no user\n", srvc->host);
-                       goto bail;
-               }
-               if (!srvc->pass) {
-                       struct strbuf prompt = STRBUF_INIT;
-                       strbuf_addf(&prompt, "Password (%s@%s): ", srvc->user, srvc->host);
-                       arg = git_getpass(prompt.buf);
-                       strbuf_release(&prompt);
-                       if (!*arg) {
-                               fprintf(stderr, "Skipping account %s@%s, no password\n", srvc->user, srvc->host);
-                               goto bail;
-                       }
-                       /*
-                        * getpass() returns a pointer to a static buffer.  make a copy
-                        * for long term storage.
-                        */
-                       srvc->pass = xstrdup(arg);
+               if (!srvc->user || !srvc->pass) {
+                       cred.protocol = xstrdup(srvc->use_ssl ? "imaps" : "imap");
+                       cred.host = xstrdup(srvc->host);
+
+                       if (srvc->user)
+                               cred.username = xstrdup(srvc->user);
+                       if (srvc->pass)
+                               cred.password = xstrdup(srvc->pass);
+
+                       credential_fill(&cred);
+
+                       if (!srvc->user)
+                               srvc->user = xstrdup(cred.username);
+                       if (!srvc->pass)
+                               srvc->pass = xstrdup(cred.password);
                }
+
                if (CAP(NOLOGIN)) {
                        fprintf(stderr, "Skipping account %s@%s, server forbids LOGIN\n", srvc->user, srvc->host);
                        goto bail;
@@ -1153,10 +1152,18 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc)
                }
        } /* !preauth */
 
+       if (cred.username)
+               credential_approve(&cred);
+       credential_clear(&cred);
+
        ctx->prefix = "";
        return ctx;
 
 bail:
+       if (cred.username)
+               credential_reject(&cred);
+       credential_clear(&cred);
+
        imap_close_store(ctx);
        return NULL;
 }
@@ -1321,13 +1328,9 @@ static char *imap_folder;
 
 static int git_imap_config(const char *key, const char *val, void *cb)
 {
-       char imap_key[] = "imap.";
-
-       if (strncmp(key, imap_key, sizeof imap_key - 1))
+       if (!skip_prefix(key, "imap.", &key))
                return 0;
 
-       key += sizeof imap_key - 1;
-
        /* check booleans first, and barf on others */
        if (!strcmp("sslverify", key))
                server.ssl_verify = git_config_bool(key, val);
index 150010105806291180d9e6bdfcf1939fb242f2ac..afcc98db930a36358283ff199a428b6c5bbbaf8f 100644 (file)
@@ -1174,9 +1174,7 @@ static int process_ranges_merge_commit(struct rev_info *rev, struct commit *comm
                         */
                        add_line_range(rev, parents[i], cand[i]);
                        clear_commit_line_range(rev, commit);
-                       commit->parents = xmalloc(sizeof(struct commit_list));
-                       commit->parents->item = parents[i];
-                       commit->parents->next = NULL;
+                       commit_list_append(parents[i], &commit->parents);
                        free(parents);
                        free(cand);
                        free_diffqueues(nparents, diffqueues);
index 8fbcb6a98aae85b48c6f8de29c6f95af58823411..b7066143494bcfa3e629dd718daf8959af6c4b86 100644 (file)
@@ -5,7 +5,6 @@
 #include "sigchain.h"
 
 static struct lock_file *lock_file_list;
-static const char *alternate_index_output;
 
 static void remove_lock_file(void)
 {
@@ -252,25 +251,6 @@ int hold_locked_index(struct lock_file *lk, int die_on_error)
                                         : 0);
 }
 
-void set_alternate_index_output(const char *name)
-{
-       alternate_index_output = name;
-}
-
-int commit_locked_index(struct lock_file *lk)
-{
-       if (alternate_index_output) {
-               if (lk->fd >= 0 && close_lock_file(lk))
-                       return -1;
-               if (rename(lk->filename, alternate_index_output))
-                       return -1;
-               lk->filename[0] = 0;
-               return 0;
-       }
-       else
-               return commit_lock_file(lk);
-}
-
 void rollback_lock_file(struct lock_file *lk)
 {
        if (lk->filename[0]) {
index cf2f86c86632c6df8862fc065299e6cc35aa4829..10e68442b35c9bd9ca1c00c52609a4827b8bace5 100644 (file)
@@ -376,7 +376,7 @@ static void show_signature(struct rev_info *opt, struct commit *commit)
        struct strbuf gpg_output = STRBUF_INIT;
        int status;
 
-       if (parse_signed_commit(commit->object.sha1, &payload, &signature) <= 0)
+       if (parse_signed_commit(commit, &payload, &signature) <= 0)
                goto out;
 
        status = verify_signed_buffer(payload.buf, payload.len,
@@ -588,7 +588,7 @@ void show_log(struct rev_info *opt)
                show_mergetag(opt, commit);
        }
 
-       if (!commit->buffer)
+       if (!get_cached_commit_buffer(commit, NULL))
                return;
 
        if (opt->show_notes) {
index e80b4af354f87caa7a5130660e9c9c530246b8be..1ce0954a3e5915a6bcc30448c9d99fdaba32bcab 100644 (file)
@@ -140,17 +140,12 @@ static void match_trees(const unsigned char *hash1,
                        goto next;
                score = score_trees(elem, hash2);
                if (*best_score < score) {
-                       char *newpath;
-                       newpath = xmalloc(strlen(base) + strlen(path) + 1);
-                       sprintf(newpath, "%s%s", base, path);
                        free(*best_match);
-                       *best_match = newpath;
+                       *best_match = xstrfmt("%s%s", base, path);
                        *best_score = score;
                }
                if (recurse_limit) {
-                       char *newbase;
-                       newbase = xmalloc(strlen(base) + strlen(path) + 2);
-                       sprintf(newbase, "%s%s/", base, path);
+                       char *newbase = xstrfmt("%s%s/", base, path);
                        match_trees(elem, hash2, best_score, best_match,
                                    newbase, recurse_limit - 1);
                        free(newbase);
index cab16fafb5c2b7792c78d3a7fbace1f43ab099cc..8e44d7e5f3d72ee71580dc98d5e7d13c4d56779f 100644 (file)
@@ -40,7 +40,7 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two,
 
 static struct commit *make_virtual_commit(struct tree *tree, const char *comment)
 {
-       struct commit *commit = xcalloc(1, sizeof(struct commit));
+       struct commit *commit = alloc_commit_node();
        struct merge_remote_desc *desc = xmalloc(sizeof(*desc));
 
        desc->name = comment;
@@ -190,9 +190,11 @@ static void output_commit_title(struct merge_options *o, struct commit *commit)
                        printf(_("(bad commit)\n"));
                else {
                        const char *title;
-                       int len = find_commit_subject(commit->buffer, &title);
+                       const char *msg = get_commit_buffer(commit, NULL);
+                       int len = find_commit_subject(msg, &title);
                        if (len)
                                printf("%.*s\n", len, title);
+                       unuse_commit_buffer(commit, msg);
                }
        }
 }
@@ -265,9 +267,7 @@ struct tree *write_tree_from_memory(struct merge_options *o)
                active_cache_tree = cache_tree();
 
        if (!cache_tree_fully_valid(active_cache_tree) &&
-           cache_tree_update(active_cache_tree,
-                             (const struct cache_entry * const *)active_cache,
-                             active_nr, 0) < 0)
+           cache_tree_update(&the_index, 0) < 0)
                die(_("error building trees"));
 
        result = lookup_tree(active_cache_tree->sha1);
@@ -601,25 +601,36 @@ static int remove_file(struct merge_options *o, int clean,
        return 0;
 }
 
+/* add a string to a strbuf, but converting "/" to "_" */
+static void add_flattened_path(struct strbuf *out, const char *s)
+{
+       size_t i = out->len;
+       strbuf_addstr(out, s);
+       for (; i < out->len; i++)
+               if (out->buf[i] == '/')
+                       out->buf[i] = '_';
+}
+
 static char *unique_path(struct merge_options *o, const char *path, const char *branch)
 {
-       char *newpath = xmalloc(strlen(path) + 1 + strlen(branch) + 8 + 1);
+       struct strbuf newpath = STRBUF_INIT;
        int suffix = 0;
        struct stat st;
-       char *p = newpath + strlen(path);
-       strcpy(newpath, path);
-       *(p++) = '~';
-       strcpy(p, branch);
-       for (; *p; ++p)
-               if ('/' == *p)
-                       *p = '_';
-       while (string_list_has_string(&o->current_file_set, newpath) ||
-              string_list_has_string(&o->current_directory_set, newpath) ||
-              lstat(newpath, &st) == 0)
-               sprintf(p, "_%d", suffix++);
-
-       string_list_insert(&o->current_file_set, newpath);
-       return newpath;
+       size_t base_len;
+
+       strbuf_addf(&newpath, "%s~", path);
+       add_flattened_path(&newpath, branch);
+
+       base_len = newpath.len;
+       while (string_list_has_string(&o->current_file_set, newpath.buf) ||
+              string_list_has_string(&o->current_directory_set, newpath.buf) ||
+              lstat(newpath.buf, &st) == 0) {
+               strbuf_setlen(&newpath, base_len);
+               strbuf_addf(&newpath, "_%d", suffix++);
+       }
+
+       string_list_insert(&o->current_file_set, newpath.buf);
+       return strbuf_detach(&newpath, NULL);
 }
 
 static int dir_in_way(const char *path, int check_working_copy)
@@ -969,14 +980,10 @@ merge_file_special_markers(struct merge_options *o,
        char *side2 = NULL;
        struct merge_file_info mfi;
 
-       if (filename1) {
-               side1 = xmalloc(strlen(branch1) + strlen(filename1) + 2);
-               sprintf(side1, "%s:%s", branch1, filename1);
-       }
-       if (filename2) {
-               side2 = xmalloc(strlen(branch2) + strlen(filename2) + 2);
-               sprintf(side2, "%s:%s", branch2, filename2);
-       }
+       if (filename1)
+               side1 = xstrfmt("%s:%s", branch1, filename1);
+       if (filename2)
+               side2 = xstrfmt("%s:%s", branch2, filename2);
 
        mfi = merge_file_1(o, one, a, b,
                           side1 ? side1 : branch1, side2 ? side2 : branch2);
@@ -1992,7 +1999,7 @@ int merge_recursive_generic(struct merge_options *o,
                            const unsigned char **base_list,
                            struct commit **result)
 {
-       int clean, index_fd;
+       int clean;
        struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
        struct commit *head_commit = get_ref(head, o->branch1);
        struct commit *next_commit = get_ref(merge, o->branch2);
@@ -2009,12 +2016,11 @@ int merge_recursive_generic(struct merge_options *o,
                }
        }
 
-       index_fd = hold_locked_index(lock, 1);
+       hold_locked_index(lock, 1);
        clean = merge_recursive(o, head_commit, next_commit, ca,
                        result);
        if (active_cache_changed &&
-                       (write_cache(index_fd, active_cache, active_nr) ||
-                        commit_locked_index(lock)))
+           write_locked_index(&the_index, lock, COMMIT_LOCK))
                return error(_("Unable to write index."));
 
        return clean ? 0 : 1;
@@ -2063,6 +2069,8 @@ void init_merge_options(struct merge_options *o)
 
 int parse_merge_opt(struct merge_options *o, const char *s)
 {
+       const char *arg;
+
        if (!s || !*s)
                return -1;
        if (!strcmp(s, "ours"))
@@ -2071,14 +2079,14 @@ int parse_merge_opt(struct merge_options *o, const char *s)
                o->recursive_variant = MERGE_RECURSIVE_THEIRS;
        else if (!strcmp(s, "subtree"))
                o->subtree_shift = "";
-       else if (starts_with(s, "subtree="))
-               o->subtree_shift = s + strlen("subtree=");
+       else if (skip_prefix(s, "subtree=", &arg))
+               o->subtree_shift = arg;
        else if (!strcmp(s, "patience"))
                o->xdl_opts = DIFF_WITH_ALG(o, PATIENCE_DIFF);
        else if (!strcmp(s, "histogram"))
                o->xdl_opts = DIFF_WITH_ALG(o, HISTOGRAM_DIFF);
-       else if (starts_with(s, "diff-algorithm=")) {
-               long value = parse_algorithm_value(s + strlen("diff-algorithm="));
+       else if (skip_prefix(s, "diff-algorithm=", &arg)) {
+               long value = parse_algorithm_value(arg);
                if (value < 0)
                        return -1;
                /* clear out previous settings */
@@ -2096,9 +2104,8 @@ int parse_merge_opt(struct merge_options *o, const char *s)
                o->renormalize = 1;
        else if (!strcmp(s, "no-renormalize"))
                o->renormalize = 0;
-       else if (starts_with(s, "rename-threshold=")) {
-               const char *score = s + strlen("rename-threshold=");
-               if ((o->rename_score = parse_rename_score(&score)) == -1 || *score != 0)
+       else if (skip_prefix(s, "rename-threshold=", &arg)) {
+               if ((o->rename_score = parse_rename_score(&arg)) == -1 || *arg != 0)
                        return -1;
        }
        else
diff --git a/merge.c b/merge.c
index 70f1000fcbef5cb04e5b25791b482b5f40fab204..74ced7f70b5beec045c134b5719c926fc791f1e2 100644 (file)
--- a/merge.c
+++ b/merge.c
@@ -18,39 +18,23 @@ int try_merge_command(const char *strategy, size_t xopts_nr,
                      const char **xopts, struct commit_list *common,
                      const char *head_arg, struct commit_list *remotes)
 {
-       const char **args;
-       int i = 0, x = 0, ret;
+       struct argv_array args = ARGV_ARRAY_INIT;
+       int i, ret;
        struct commit_list *j;
-       struct strbuf buf = STRBUF_INIT;
 
-       args = xmalloc((4 + xopts_nr + commit_list_count(common) +
-                       commit_list_count(remotes)) * sizeof(char *));
-       strbuf_addf(&buf, "merge-%s", strategy);
-       args[i++] = buf.buf;
-       for (x = 0; x < xopts_nr; x++) {
-               char *s = xmalloc(strlen(xopts[x])+2+1);
-               strcpy(s, "--");
-               strcpy(s+2, xopts[x]);
-               args[i++] = s;
-       }
-       for (j = common; j; j = j->next)
-               args[i++] = xstrdup(merge_argument(j->item));
-       args[i++] = "--";
-       args[i++] = head_arg;
-       for (j = remotes; j; j = j->next)
-               args[i++] = xstrdup(merge_argument(j->item));
-       args[i] = NULL;
-       ret = run_command_v_opt(args, RUN_GIT_CMD);
-       strbuf_release(&buf);
-       i = 1;
-       for (x = 0; x < xopts_nr; x++)
-               free((void *)args[i++]);
+       argv_array_pushf(&args, "merge-%s", strategy);
+       for (i = 0; i < xopts_nr; i++)
+               argv_array_pushf(&args, "--%s", xopts[i]);
        for (j = common; j; j = j->next)
-               free((void *)args[i++]);
-       i += 2;
+               argv_array_push(&args, merge_argument(j->item));
+       argv_array_push(&args, "--");
+       argv_array_push(&args, head_arg);
        for (j = remotes; j; j = j->next)
-               free((void *)args[i++]);
-       free(args);
+               argv_array_push(&args, merge_argument(j->item));
+
+       ret = run_command_v_opt(args.argv, RUN_GIT_CMD);
+       argv_array_clear(&args);
+
        discard_cache();
        if (read_cache() < 0)
                die(_("failed to read the cache"));
@@ -66,13 +50,13 @@ int checkout_fast_forward(const unsigned char *head,
        struct tree *trees[MAX_UNPACK_TREES];
        struct unpack_trees_options opts;
        struct tree_desc t[MAX_UNPACK_TREES];
-       int i, fd, nr_trees = 0;
+       int i, nr_trees = 0;
        struct dir_struct dir;
        struct lock_file *lock_file = xcalloc(1, sizeof(struct lock_file));
 
        refresh_cache(REFRESH_QUIET);
 
-       fd = hold_locked_index(lock_file, 1);
+       hold_locked_index(lock_file, 1);
 
        memset(&trees, 0, sizeof(trees));
        memset(&opts, 0, sizeof(opts));
@@ -105,8 +89,7 @@ int checkout_fast_forward(const unsigned char *head,
        }
        if (unpack_trees(nr_trees, t, &opts))
                return -1;
-       if (write_cache(fd, active_cache, active_nr) ||
-               commit_locked_index(lock_file))
+       if (write_locked_index(&the_index, lock_file, COMMIT_LOCK))
                die(_("unable to write new index file"));
        return 0;
 }
diff --git a/mergetools/gvimdiff3 b/mergetools/gvimdiff3
new file mode 100644 (file)
index 0000000..04a5bb0
--- /dev/null
@@ -0,0 +1 @@
+. "$MERGE_TOOLS_DIR/vimdiff"
index 39d032771b8525253d3828fd68b2c7f6d6df8478..1ddfbfcd782d3b8d0e479cb0c5e29abce86e63c9 100644 (file)
@@ -20,16 +20,26 @@ merge_cmd () {
                "$merge_tool_path" -f -d -c 'wincmd l' \
                        "$LOCAL" "$MERGED" "$REMOTE"
                ;;
+       gvimdiff3|vimdiff3)
+               if $base_present
+               then
+                       "$merge_tool_path" -f -d -c 'hid | hid | hid' \
+                               "$LOCAL" "$REMOTE" "$BASE" "$MERGED"
+               else
+                       "$merge_tool_path" -f -d -c 'hid | hid' \
+                               "$LOCAL" "$REMOTE" "$MERGED"
+               fi
+               ;;
        esac
        check_unchanged
 }
 
 translate_merge_tool_path() {
        case "$1" in
-       gvimdiff|gvimdiff2)
+       gvimdiff|gvimdiff2|gvimdiff3)
                echo gvim
                ;;
-       vimdiff|vimdiff2)
+       vimdiff|vimdiff2|vimdiff3)
                echo vim
                ;;
        esac
diff --git a/mergetools/vimdiff3 b/mergetools/vimdiff3
new file mode 100644 (file)
index 0000000..04a5bb0
--- /dev/null
@@ -0,0 +1 @@
+. "$MERGE_TOOLS_DIR/vimdiff"
index 97444d02010e13de1eab9abe6f1fc71287658faf..49fd508317ebbde5a76f6af64318920ae237c8fd 100644 (file)
@@ -179,7 +179,7 @@ static int same_name(const struct cache_entry *ce, const char *name, int namelen
         * Always do exact compare, even if we want a case-ignoring comparison;
         * we do the quick exact one first, because it will be the common case.
         */
-       if (len == namelen && !cache_name_compare(name, namelen, ce->name, len))
+       if (len == namelen && !memcmp(name, ce->name, len))
                return 1;
 
        if (!icase)
index eabe4a0d9bf44050dba43cbd821642cdfd3fb40b..c4e9bb7f6c0bde97c7c6d34094baa5ef7e318157 100644 (file)
@@ -48,7 +48,6 @@ int notes_cache_write(struct notes_cache *c)
 {
        unsigned char tree_sha1[20];
        unsigned char commit_sha1[20];
-       struct strbuf msg = STRBUF_INIT;
 
        if (!c || !c->tree.initialized || !c->tree.ref || !*c->tree.ref)
                return -1;
@@ -57,12 +56,11 @@ int notes_cache_write(struct notes_cache *c)
 
        if (write_notes_tree(&c->tree, tree_sha1))
                return -1;
-       strbuf_attach(&msg, c->validity,
-                     strlen(c->validity), strlen(c->validity) + 1);
-       if (commit_tree(&msg, tree_sha1, NULL, commit_sha1, NULL, NULL) < 0)
+       if (commit_tree(c->validity, strlen(c->validity), tree_sha1, NULL,
+                       commit_sha1, NULL, NULL) < 0)
                return -1;
        if (update_ref("update notes cache", c->tree.ref, commit_sha1, NULL,
-                      0, QUIET_ON_ERR) < 0)
+                      0, UPDATE_REFS_QUIET_ON_ERR) < 0)
                return -1;
 
        return 0;
index 94a1a8ae466733b207ae5030f8a8894d66535f91..fd5fae255d2760d6b7895e95cee627b5e28f776e 100644 (file)
@@ -644,7 +644,8 @@ int notes_merge(struct notes_merge_options *o,
                struct commit_list *parents = NULL;
                commit_list_insert(remote, &parents); /* LIFO order */
                commit_list_insert(local, &parents);
-               create_notes_commit(local_tree, parents, &o->commit_msg,
+               create_notes_commit(local_tree, parents,
+                                   o->commit_msg.buf, o->commit_msg.len,
                                    result_sha1);
        }
 
@@ -671,8 +672,8 @@ int notes_merge_commit(struct notes_merge_options *o,
        DIR *dir;
        struct dirent *e;
        struct strbuf path = STRBUF_INIT;
-       char *msg = strstr(partial_commit->buffer, "\n\n");
-       struct strbuf sb_msg = STRBUF_INIT;
+       const char *buffer = get_commit_buffer(partial_commit, NULL);
+       const char *msg = strstr(buffer, "\n\n");
        int baselen;
 
        strbuf_addstr(&path, git_path(NOTES_MERGE_WORKTREE));
@@ -719,9 +720,9 @@ int notes_merge_commit(struct notes_merge_options *o,
                strbuf_setlen(&path, baselen);
        }
 
-       strbuf_attach(&sb_msg, msg, strlen(msg), strlen(msg) + 1);
-       create_notes_commit(partial_tree, partial_commit->parents, &sb_msg,
-                           result_sha1);
+       create_notes_commit(partial_tree, partial_commit->parents,
+                           msg, strlen(msg), result_sha1);
+       unuse_commit_buffer(partial_commit, buffer);
        if (o->verbosity >= 4)
                printf("Finalized notes merge commit: %s\n",
                        sha1_to_hex(result_sha1));
index 4aa7023903374aa3ccea23d5fc9ae82c9c67bca7..b64dc1b0219928ac149894c99a63dcc9fd419668 100644 (file)
@@ -4,7 +4,8 @@
 #include "notes-utils.h"
 
 void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
-                        const struct strbuf *msg, unsigned char *result_sha1)
+                        const char *msg, size_t msg_len,
+                        unsigned char *result_sha1)
 {
        unsigned char tree_sha1[20];
 
@@ -25,7 +26,7 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
                /* else: t->ref points to nothing, assume root/orphan commit */
        }
 
-       if (commit_tree(msg, tree_sha1, parents, result_sha1, NULL, NULL))
+       if (commit_tree(msg, msg_len, tree_sha1, parents, result_sha1, NULL, NULL))
                die("Failed to commit notes tree to database");
 }
 
@@ -46,9 +47,10 @@ void commit_notes(struct notes_tree *t, const char *msg)
        if (buf.buf[buf.len - 1] != '\n')
                strbuf_addch(&buf, '\n'); /* Make sure msg ends with newline */
 
-       create_notes_commit(t, NULL, &buf, commit_sha1);
+       create_notes_commit(t, NULL, buf.buf, buf.len, commit_sha1);
        strbuf_insert(&buf, 0, "notes: ", 7); /* commit message starts at index 7 */
-       update_ref(buf.buf, t->ref, commit_sha1, NULL, 0, DIE_ON_ERR);
+       update_ref(buf.buf, t->ref, commit_sha1, NULL, 0,
+                  UPDATE_REFS_DIE_ON_ERR);
 
        strbuf_release(&buf);
 }
index 564e30cccd550f9acbd493f43c940bab1abba427..890ddb33e13ad6b9d43887216acbe5430ed534cc 100644 (file)
@@ -15,7 +15,7 @@
  * The resulting commit SHA1 is stored in result_sha1.
  */
 void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
-                        const struct strbuf *msg, unsigned char *result_sha1);
+                        const char *msg, size_t msg_len, unsigned char *result_sha1);
 
 void commit_notes(struct notes_tree *t, const char *msg);
 
diff --git a/notes.c b/notes.c
index 5f07c0b7f28e09bd2f7969ea08b00b319a226920..5fe691dbcdfb9e3f9fa3c768f243234d5bb2e816 100644 (file)
--- a/notes.c
+++ b/notes.c
@@ -303,7 +303,7 @@ static int note_tree_insert(struct notes_tree *t, struct int_node *tree,
                free(entry);
                return 0;
        }
-       new_node = (struct int_node *) xcalloc(sizeof(struct int_node), 1);
+       new_node = (struct int_node *) xcalloc(1, sizeof(struct int_node));
        ret = note_tree_insert(t, new_node, n + 1, l, GET_PTR_TYPE(*p),
                               combine_notes);
        if (ret)
@@ -443,7 +443,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
                if (len <= 20) {
                        type = PTR_TYPE_NOTE;
                        l = (struct leaf_node *)
-                               xcalloc(sizeof(struct leaf_node), 1);
+                               xcalloc(1, sizeof(struct leaf_node));
                        hashcpy(l->key_sha1, object_sha1);
                        hashcpy(l->val_sha1, entry.sha1);
                        if (len < 20) {
@@ -1003,7 +1003,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
        if (!combine_notes)
                combine_notes = combine_notes_concatenate;
 
-       t->root = (struct int_node *) xcalloc(sizeof(struct int_node), 1);
+       t->root = (struct int_node *) xcalloc(1, sizeof(struct int_node));
        t->first_non_note = NULL;
        t->prev_non_note = NULL;
        t->ref = notes_ref ? xstrdup(notes_ref) : NULL;
index 57a0890a87b66ea493337409606e57fd44d29f90..9c31e9a5e0e0d913044501089e09037e47894f03 100644 (file)
--- a/object.c
+++ b/object.c
@@ -197,8 +197,8 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t
                if (commit) {
                        if (parse_commit_buffer(commit, buffer, size))
                                return NULL;
-                       if (!commit->buffer) {
-                               commit->buffer = buffer;
+                       if (!get_cached_commit_buffer(commit, NULL)) {
+                               set_commit_buffer(commit, buffer, size);
                                *eaten_p = 1;
                        }
                        obj = &commit->object;
index 5bd7c619803c8457a8c1a1a69a11758d34b49eac..5c8376e9789301b921188e3bf19fba85960a7967 100644 (file)
@@ -45,7 +45,7 @@ static void init_pack_revindex(void)
        if (!num)
                return;
        pack_revindex_hashsz = num * 11;
-       pack_revindex = xcalloc(sizeof(*pack_revindex), pack_revindex_hashsz);
+       pack_revindex = xcalloc(pack_revindex_hashsz, sizeof(*pack_revindex));
        for (p = packed_git; p; p = p->next) {
                num = pack_revindex_ix(p);
                num = - 1 - num;
diff --git a/pager.c b/pager.c
index 53670a63a7ae4dc3a9199671fe899c31251a916c..8b5cbc56e4fd57a1b9d2cad3e668df4c508a7b17 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -85,7 +85,7 @@ void setup_pager(void)
                int i = 0;
 
                if (!getenv("LESS"))
-                       env[i++] = "LESS=FRSX";
+                       env[i++] = "LESS=FRX";
                if (!getenv("LV"))
                        env[i++] = "LV=-c";
                env[i] = NULL;
index b536896f2689dee23afae7d3a169c065592aaabe..e7dafa80d55adb9b863c23f711389e5eaa6b2c5e 100644 (file)
@@ -231,7 +231,8 @@ static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg,
                        continue;
 
 again:
-               rest = skip_prefix(arg, long_name);
+               if (!skip_prefix(arg, long_name, &rest))
+                       rest = NULL;
                if (options->type == OPTION_ARGUMENT) {
                        if (!rest)
                                continue;
@@ -280,12 +281,13 @@ is_abbreviated:
                                continue;
                        }
                        flags |= OPT_UNSET;
-                       rest = skip_prefix(arg + 3, long_name);
-                       /* abbreviated and negated? */
-                       if (!rest && starts_with(long_name, arg + 3))
-                               goto is_abbreviated;
-                       if (!rest)
-                               continue;
+                       if (!skip_prefix(arg + 3, long_name, &rest)) {
+                               /* abbreviated and negated? */
+                               if (starts_with(long_name, arg + 3))
+                                       goto is_abbreviated;
+                               else
+                                       continue;
+                       }
                }
                if (*rest) {
                        if (*rest != '=')
index 3189676695bc173cf6475445cfb6365d08a37906..7940bc71af4c6dacd65d042091454c8fa83c53c7 100644 (file)
@@ -176,8 +176,8 @@ extern NORETURN void usage_msg_opt(const char *msg,
 
 extern int optbug(const struct option *opt, const char *reason);
 extern int opterror(const struct option *opt, const char *reason, int flags);
-#if defined(__GNUC__) && ! defined(__clang__)
-#define opterror(o,r,f) (opterror((o),(r),(f)), -1)
+#if defined(__GNUC__)
+#define opterror(o,r,f) (opterror((o),(r),(f)), const_error())
 #endif
 
 /*----- incremental advanced APIs -----*/
diff --git a/path.c b/path.c
index f9c5062427e7d8170a1e2e597fcf22ae517a865e..bc804a31b3382e689dd6ff5b4a727b109a691f7a 100644 (file)
--- a/path.c
+++ b/path.c
@@ -823,10 +823,3 @@ int daemon_avoid_alias(const char *p)
                }
        }
 }
-
-int offset_1st_component(const char *path)
-{
-       if (has_dos_drive_prefix(path))
-               return 2 + is_dir_sep(path[2]);
-       return is_dir_sep(path[0]);
-}
index a59564fb34fbedd4915da2afd7d4b8f1fd40bb49..09cff135efd98a486ff767485602d9383e7c3c23 100644 (file)
@@ -1321,7 +1321,7 @@ sub get_untracked {
 sub parse_svn_date {
        my $date = shift || return '+0000 1970-01-01 00:00:00';
        my ($Y,$m,$d,$H,$M,$S) = ($date =~ /^(\d{4})\-(\d\d)\-(\d\d)T
-                                           (\d\d)\:(\d\d)\:(\d\d)\.\d*Z$/x) or
+                                           (\d\d?)\:(\d\d)\:(\d\d)\.\d*Z$/x) or
                                         croak "Unable to parse date: $date\n";
        my $parsed_date;    # Set next.
 
index 34f2869ab5995e3f9143af8cc2c46a4717ae8be8..664105357c0031e869b3348a09d91777a42c1cdf 100644 (file)
@@ -116,7 +116,7 @@ sub run_pager {
                return;
        }
        open STDIN, '<&', $rfd or fatal "Can't redirect stdin: $!";
-       $ENV{LESS} ||= 'FRSX';
+       $ENV{LESS} ||= 'FRX';
        $ENV{LV} ||= '-c';
        exec $pager or fatal "Can't run pager: $! ($pager)";
 }
index 5c02b29cebd5b09b06d6032d9818f18ef35762b6..14357e233f3174963add310a29bb35c3de229121 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -40,10 +40,9 @@ static int git_pretty_formats_config(const char *var, const char *value, void *c
        const char *fmt;
        int i;
 
-       if (!starts_with(var, "pretty."))
+       if (!skip_prefix(var, "pretty.", &name))
                return 0;
 
-       name = var + strlen("pretty.");
        for (i = 0; i < builtin_formats_len; i++) {
                if (!strcmp(commit_formats[i].name, name))
                        return 0;
@@ -393,8 +392,8 @@ static void add_rfc2047(struct strbuf *sb, const char *line, size_t len,
        strbuf_addstr(sb, "?=");
 }
 
-static const char *show_ident_date(const struct ident_split *ident,
-                                  enum date_mode mode)
+const char *show_ident_date(const struct ident_split *ident,
+                           enum date_mode mode)
 {
        unsigned long date = 0;
        long tz = 0;
@@ -606,29 +605,16 @@ static char *replace_encoding_header(char *buf, const char *encoding)
        return strbuf_detach(&tmp, NULL);
 }
 
-char *logmsg_reencode(const struct commit *commit,
-                     char **commit_encoding,
-                     const char *output_encoding)
+const char *logmsg_reencode(const struct commit *commit,
+                           char **commit_encoding,
+                           const char *output_encoding)
 {
        static const char *utf8 = "UTF-8";
        const char *use_encoding;
        char *encoding;
-       char *msg = commit->buffer;
+       const char *msg = get_commit_buffer(commit, NULL);
        char *out;
 
-       if (!msg) {
-               enum object_type type;
-               unsigned long size;
-
-               msg = read_sha1_file(commit->object.sha1, &type, &size);
-               if (!msg)
-                       die("Cannot read commit object %s",
-                           sha1_to_hex(commit->object.sha1));
-               if (type != OBJ_COMMIT)
-                       die("Expected commit for '%s', got %s",
-                           sha1_to_hex(commit->object.sha1), typename(type));
-       }
-
        if (!output_encoding || !*output_encoding) {
                if (commit_encoding)
                        *commit_encoding =
@@ -652,12 +638,13 @@ char *logmsg_reencode(const struct commit *commit,
                 * Otherwise, we still want to munge the encoding header in the
                 * result, which will be done by modifying the buffer. If we
                 * are using a fresh copy, we can reuse it. But if we are using
-                * the cached copy from commit->buffer, we need to duplicate it
-                * to avoid munging commit->buffer.
+                * the cached copy from get_commit_buffer, we need to duplicate it
+                * to avoid munging the cached copy.
                 */
-               out = msg;
-               if (out == commit->buffer)
-                       out = xstrdup(out);
+               if (msg == get_cached_commit_buffer(commit, NULL))
+                       out = xstrdup(msg);
+               else
+                       out = (char *)msg;
        }
        else {
                /*
@@ -667,8 +654,8 @@ char *logmsg_reencode(const struct commit *commit,
                 * copy, we can free it.
                 */
                out = reencode_string(msg, output_encoding, use_encoding);
-               if (out && msg != commit->buffer)
-                       free(msg);
+               if (out)
+                       unuse_commit_buffer(commit, msg);
        }
 
        /*
@@ -687,12 +674,6 @@ char *logmsg_reencode(const struct commit *commit,
        return out ? out : msg;
 }
 
-void logmsg_free(char *msg, const struct commit *commit)
-{
-       if (msg != commit->buffer)
-               free(msg);
-}
-
 static int mailmap_name(const char **email, size_t *email_len,
                        const char **name, size_t *name_len)
 {
@@ -796,7 +777,7 @@ struct format_commit_context {
        struct signature_check signature_check;
        enum flush_type flush_type;
        enum trunc_type truncate;
-       char *message;
+       const char *message;
        char *commit_encoding;
        size_t width, indent1, indent2;
        int auto_color;
@@ -1267,6 +1248,8 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
                        if (c->signature_check.key)
                                strbuf_addstr(sb, c->signature_check.key);
                        break;
+               default:
+                       return 0;
                }
                return 2;
        }
@@ -1536,9 +1519,7 @@ void format_commit_message(const struct commit *commit,
        }
 
        free(context.commit_encoding);
-       logmsg_free(context.message, commit);
-       free(context.signature_check.gpg_output);
-       free(context.signature_check.signer);
+       unuse_commit_buffer(commit, context.message);
 }
 
 static void pp_header(struct pretty_print_context *pp,
@@ -1705,7 +1686,7 @@ void pretty_print_commit(struct pretty_print_context *pp,
        unsigned long beginning_of_body;
        int indent = 4;
        const char *msg;
-       char *reencoded;
+       const char *reencoded;
        const char *encoding;
        int need_8bit_cte = pp->need_8bit_cte;
 
@@ -1772,7 +1753,7 @@ void pretty_print_commit(struct pretty_print_context *pp,
        if (pp->fmt == CMIT_FMT_EMAIL && sb->len <= beginning_of_body)
                strbuf_addch(sb, '\n');
 
-       logmsg_free(reencoded, commit);
+       unuse_commit_buffer(commit, reencoded);
 }
 
 void pp_commit_easy(enum cmit_fmt fmt, const struct commit *commit,
index 7f5645e74546e459efdb584dbf63e1fd75857317..5d3c8bd4aaffda9915a3fd62d9d9800f4ac8baff 100644 (file)
@@ -14,6 +14,8 @@
 #include "resolve-undo.h"
 #include "strbuf.h"
 #include "varint.h"
+#include "split-index.h"
+#include "sigchain.h"
 
 static struct cache_entry *refresh_cache_entry(struct cache_entry *ce,
                                               unsigned int options);
@@ -34,8 +36,15 @@ static struct cache_entry *refresh_cache_entry(struct cache_entry *ce,
 #define CACHE_EXT(s) ( (s[0]<<24)|(s[1]<<16)|(s[2]<<8)|(s[3]) )
 #define CACHE_EXT_TREE 0x54524545      /* "TREE" */
 #define CACHE_EXT_RESOLVE_UNDO 0x52455543 /* "REUC" */
+#define CACHE_EXT_LINK 0x6c696e6b        /* "link" */
+
+/* changes that can be kept in $GIT_DIR/index (basically all extensions) */
+#define EXTMASK (RESOLVE_UNDO_CHANGED | CACHE_TREE_CHANGED | \
+                CE_ENTRY_ADDED | CE_ENTRY_REMOVED | CE_ENTRY_CHANGED | \
+                SPLIT_INDEX_ORDERED)
 
 struct index_state the_index;
+static const char *alternate_index_output;
 
 static void set_index_entry(struct index_state *istate, int nr, struct cache_entry *ce)
 {
@@ -47,10 +56,12 @@ static void replace_index_entry(struct index_state *istate, int nr, struct cache
 {
        struct cache_entry *old = istate->cache[nr];
 
+       replace_index_entry_in_base(istate, old, ce);
        remove_name_hash(istate, old);
        free(old);
        set_index_entry(istate, nr, ce);
-       istate->cache_changed = 1;
+       ce->ce_flags |= CE_UPDATE_IN_BASE;
+       istate->cache_changed |= CE_ENTRY_CHANGED;
 }
 
 void rename_index_entry_at(struct index_state *istate, int nr, const char *new_name)
@@ -62,9 +73,10 @@ void rename_index_entry_at(struct index_state *istate, int nr, const char *new_n
        copy_cache_entry(new, old);
        new->ce_flags &= ~CE_HASHED;
        new->ce_namelen = namelen;
+       new->index = 0;
        memcpy(new->name, new_name, namelen + 1);
 
-       cache_tree_invalidate_path(istate->cache_tree, old->name);
+       cache_tree_invalidate_path(istate, old->name);
        remove_index_entry_at(istate, nr);
        add_index_entry(istate, new, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE);
 }
@@ -422,18 +434,26 @@ int df_name_compare(const char *name1, int len1, int mode1,
        return c1 - c2;
 }
 
-int cache_name_stage_compare(const char *name1, int len1, int stage1, const char *name2, int len2, int stage2)
+int name_compare(const char *name1, size_t len1, const char *name2, size_t len2)
 {
-       int len = len1 < len2 ? len1 : len2;
-       int cmp;
-
-       cmp = memcmp(name1, name2, len);
+       size_t min_len = (len1 < len2) ? len1 : len2;
+       int cmp = memcmp(name1, name2, min_len);
        if (cmp)
                return cmp;
        if (len1 < len2)
                return -1;
        if (len1 > len2)
                return 1;
+       return 0;
+}
+
+int cache_name_stage_compare(const char *name1, int len1, int stage1, const char *name2, int len2, int stage2)
+{
+       int cmp;
+
+       cmp = name_compare(name1, len1, name2, len2);
+       if (cmp)
+               return cmp;
 
        if (stage1 < stage2)
                return -1;
@@ -442,11 +462,6 @@ int cache_name_stage_compare(const char *name1, int len1, int stage1, const char
        return 0;
 }
 
-int cache_name_compare(const char *name1, int len1, const char *name2, int len2)
-{
-       return cache_name_stage_compare(name1, len1, 0, name2, len2, 0);
-}
-
 static int index_name_stage_pos(const struct index_state *istate, const char *name, int namelen, int stage)
 {
        int first, last;
@@ -480,8 +495,8 @@ int remove_index_entry_at(struct index_state *istate, int pos)
 
        record_resolve_undo(istate, ce);
        remove_name_hash(istate, ce);
-       free(ce);
-       istate->cache_changed = 1;
+       save_or_free_index_entry(istate, ce);
+       istate->cache_changed |= CE_ENTRY_REMOVED;
        istate->cache_nr--;
        if (pos >= istate->cache_nr)
                return 0;
@@ -504,12 +519,14 @@ void remove_marked_cache_entries(struct index_state *istate)
        for (i = j = 0; i < istate->cache_nr; i++) {
                if (ce_array[i]->ce_flags & CE_REMOVE) {
                        remove_name_hash(istate, ce_array[i]);
-                       free(ce_array[i]);
+                       save_or_free_index_entry(istate, ce_array[i]);
                }
                else
                        ce_array[j++] = ce_array[i];
        }
-       istate->cache_changed = 1;
+       if (j == istate->cache_nr)
+               return;
+       istate->cache_changed |= CE_ENTRY_REMOVED;
        istate->cache_nr = j;
 }
 
@@ -518,7 +535,7 @@ int remove_file_from_index(struct index_state *istate, const char *path)
        int pos = index_name_pos(istate, path, strlen(path));
        if (pos < 0)
                pos = -pos-1;
-       cache_tree_invalidate_path(istate->cache_tree, path);
+       cache_tree_invalidate_path(istate, path);
        while (pos < istate->cache_nr && !strcmp(istate->cache[pos]->name, path))
                remove_index_entry_at(istate, pos);
        return 0;
@@ -567,7 +584,9 @@ static int different_name(struct cache_entry *ce, struct cache_entry *alias)
  * So we use the CE_ADDED flag to verify that the alias was an old
  * one before we accept it as
  */
-static struct cache_entry *create_alias_ce(struct cache_entry *ce, struct cache_entry *alias)
+static struct cache_entry *create_alias_ce(struct index_state *istate,
+                                          struct cache_entry *ce,
+                                          struct cache_entry *alias)
 {
        int len;
        struct cache_entry *new;
@@ -580,7 +599,7 @@ static struct cache_entry *create_alias_ce(struct cache_entry *ce, struct cache_
        new = xcalloc(1, cache_entry_size(len));
        memcpy(new->name, alias->name, len);
        copy_cache_entry(new, ce);
-       free(ce);
+       save_or_free_index_entry(istate, ce);
        return new;
 }
 
@@ -673,7 +692,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
                set_object_name_for_intent_to_add_entry(ce);
 
        if (ignore_case && alias && different_name(ce, alias))
-               ce = create_alias_ce(ce, alias);
+               ce = create_alias_ce(istate, ce, alias);
        ce->ce_flags |= CE_ADDED;
 
        /* It was suspected to be racily clean, but it turns out to be Ok */
@@ -936,7 +955,8 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_e
        int skip_df_check = option & ADD_CACHE_SKIP_DFCHECK;
        int new_only = option & ADD_CACHE_NEW_ONLY;
 
-       cache_tree_invalidate_path(istate->cache_tree, ce->name);
+       if (!(option & ADD_CACHE_KEEP_CACHE_TREE))
+               cache_tree_invalidate_path(istate, ce->name);
        pos = index_name_stage_pos(istate, ce->name, ce_namelen(ce), ce_stage(ce));
 
        /* existing match? Just replace it. */
@@ -999,7 +1019,7 @@ int add_index_entry(struct index_state *istate, struct cache_entry *ce, int opti
                        istate->cache + pos,
                        (istate->cache_nr - pos - 1) * sizeof(ce));
        set_index_entry(istate, pos, ce);
-       istate->cache_changed = 1;
+       istate->cache_changed |= CE_ENTRY_ADDED;
        return 0;
 }
 
@@ -1098,6 +1118,7 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
            !(ce->ce_flags & CE_VALID))
                updated->ce_flags &= ~CE_VALID;
 
+       /* istate->cache_changed is updated in the caller */
        return updated;
 }
 
@@ -1179,7 +1200,8 @@ int refresh_index(struct index_state *istate, unsigned int flags,
                                 * means the index is not valid anymore.
                                 */
                                ce->ce_flags &= ~CE_VALID;
-                               istate->cache_changed = 1;
+                               ce->ce_flags |= CE_UPDATE_IN_BASE;
+                               istate->cache_changed |= CE_ENTRY_CHANGED;
                        }
                        if (quiet)
                                continue;
@@ -1331,6 +1353,10 @@ static int read_index_extension(struct index_state *istate,
        case CACHE_EXT_RESOLVE_UNDO:
                istate->resolve_undo = resolve_undo_read(data, sz);
                break;
+       case CACHE_EXT_LINK:
+               if (read_link_extension(istate, data, sz))
+                       return -1;
+               break;
        default:
                if (*ext < 'A' || 'Z' < *ext)
                        return error("index uses %.4s extension, which we do not understand",
@@ -1365,6 +1391,7 @@ static struct cache_entry *cache_entry_from_ondisk(struct ondisk_cache_entry *on
        ce->ce_stat_data.sd_size  = get_be32(&ondisk->size);
        ce->ce_flags = flags & ~CE_NAMEMASK;
        ce->ce_namelen = len;
+       ce->index = 0;
        hashcpy(ce->sha1, ondisk->sha1);
        memcpy(ce->name, name, len);
        ce->name[len] = '\0';
@@ -1439,7 +1466,7 @@ static struct cache_entry *create_from_disk(struct ondisk_cache_entry *ondisk,
 }
 
 /* remember to discard_cache() before reading a different cache! */
-int read_index_from(struct index_state *istate, const char *path)
+int do_read_index(struct index_state *istate, const char *path, int must_exist)
 {
        int fd, i;
        struct stat st;
@@ -1456,9 +1483,9 @@ int read_index_from(struct index_state *istate, const char *path)
        istate->timestamp.nsec = 0;
        fd = open(path, O_RDONLY);
        if (fd < 0) {
-               if (errno == ENOENT)
+               if (!must_exist && errno == ENOENT)
                        return 0;
-               die_errno("index file open failed");
+               die_errno("%s: index file open failed", path);
        }
 
        if (fstat(fd, &st))
@@ -1477,7 +1504,7 @@ int read_index_from(struct index_state *istate, const char *path)
        if (verify_hdr(hdr, mmap_size) < 0)
                goto unmap;
 
-       hashcpy(istate->sha1, (unsigned char *)hdr + mmap_size - 20);
+       hashcpy(istate->sha1, (const unsigned char *)hdr + mmap_size - 20);
        istate->version = ntohl(hdr->hdr_version);
        istate->cache_nr = ntohl(hdr->hdr_entries);
        istate->cache_alloc = alloc_nr(istate->cache_nr);
@@ -1531,6 +1558,40 @@ unmap:
        die("index file corrupt");
 }
 
+int read_index_from(struct index_state *istate, const char *path)
+{
+       struct split_index *split_index;
+       int ret;
+
+       /* istate->initialized covers both .git/index and .git/sharedindex.xxx */
+       if (istate->initialized)
+               return istate->cache_nr;
+
+       ret = do_read_index(istate, path, 0);
+       split_index = istate->split_index;
+       if (!split_index)
+               return ret;
+
+       if (is_null_sha1(split_index->base_sha1))
+               return ret;
+
+       if (split_index->base)
+               discard_index(split_index->base);
+       else
+               split_index->base = xcalloc(1, sizeof(*split_index->base));
+       ret = do_read_index(split_index->base,
+                           git_path("sharedindex.%s",
+                                    sha1_to_hex(split_index->base_sha1)), 1);
+       if (hashcmp(split_index->base_sha1, split_index->base->sha1))
+               die("broken index, expect %s in %s, got %s",
+                   sha1_to_hex(split_index->base_sha1),
+                   git_path("sharedindex.%s",
+                                    sha1_to_hex(split_index->base_sha1)),
+                   sha1_to_hex(split_index->base->sha1));
+       merge_base_index(istate);
+       return ret;
+}
+
 int is_index_unborn(struct index_state *istate)
 {
        return (!istate->cache_nr && !istate->timestamp.sec);
@@ -1540,8 +1601,15 @@ int discard_index(struct index_state *istate)
 {
        int i;
 
-       for (i = 0; i < istate->cache_nr; i++)
+       for (i = 0; i < istate->cache_nr; i++) {
+               if (istate->cache[i]->index &&
+                   istate->split_index &&
+                   istate->split_index->base &&
+                   istate->cache[i]->index <= istate->split_index->base->cache_nr &&
+                   istate->cache[i] == istate->split_index->base->cache[istate->cache[i]->index - 1])
+                       continue;
                free(istate->cache[i]);
+       }
        resolve_undo_clear_index(istate);
        istate->cache_nr = 0;
        istate->cache_changed = 0;
@@ -1553,6 +1621,7 @@ int discard_index(struct index_state *istate)
        free(istate->cache);
        istate->cache = NULL;
        istate->cache_alloc = 0;
+       discard_split_index(istate);
        return 0;
 }
 
@@ -1613,7 +1682,7 @@ static int write_index_ext_header(git_SHA_CTX *context, int fd,
                (ce_write(context, fd, &sz, 4) < 0)) ? -1 : 0;
 }
 
-static int ce_flush(git_SHA_CTX *context, int fd)
+static int ce_flush(git_SHA_CTX *context, int fd, unsigned char *sha1)
 {
        unsigned int left = write_buffer_len;
 
@@ -1631,6 +1700,7 @@ static int ce_flush(git_SHA_CTX *context, int fd)
 
        /* Append the SHA1 signature at the end */
        git_SHA1_Final(write_buffer + left, context);
+       hashcpy(sha1, write_buffer + left);
        left += 20;
        return (write_in_full(fd, write_buffer, left) != left) ? -1 : 0;
 }
@@ -1702,7 +1772,7 @@ static char *copy_cache_entry_to_ondisk(struct ondisk_cache_entry *ondisk,
        ondisk->size = htonl(ce->ce_stat_data.sd_size);
        hashcpy(ondisk->sha1, ce->sha1);
 
-       flags = ce->ce_flags;
+       flags = ce->ce_flags & ~CE_NAMEMASK;
        flags |= (ce_namelen(ce) >= CE_NAMEMASK ? CE_NAMEMASK : ce_namelen(ce));
        ondisk->flags = htons(flags);
        if (ce->ce_flags & CE_EXTENDED) {
@@ -1721,9 +1791,15 @@ static int ce_write_entry(git_SHA_CTX *c, int fd, struct cache_entry *ce,
 {
        int size;
        struct ondisk_cache_entry *ondisk;
+       int saved_namelen = saved_namelen; /* compiler workaround */
        char *name;
        int result;
 
+       if (ce->ce_flags & CE_STRIP_NAME) {
+               saved_namelen = ce_namelen(ce);
+               ce->ce_namelen = 0;
+       }
+
        if (!previous_name) {
                size = ondisk_ce_size(ce);
                ondisk = xcalloc(1, size);
@@ -1755,6 +1831,10 @@ static int ce_write_entry(git_SHA_CTX *c, int fd, struct cache_entry *ce,
                strbuf_splice(previous_name, common, to_remove,
                              ce->name + common, ce_namelen(ce) - common);
        }
+       if (ce->ce_flags & CE_STRIP_NAME) {
+               ce->ce_namelen = saved_namelen;
+               ce->ce_flags &= ~CE_STRIP_NAME;
+       }
 
        result = ce_write(c, fd, ondisk, size);
        free(ondisk);
@@ -1824,13 +1904,13 @@ static int has_racy_timestamp(struct index_state *istate)
 void update_index_if_able(struct index_state *istate, struct lock_file *lockfile)
 {
        if ((istate->cache_changed || has_racy_timestamp(istate)) &&
-           verify_index(istate) && !write_index(istate, lockfile->fd))
-               commit_locked_index(lockfile);
-       else
+           verify_index(istate) &&
+           write_locked_index(istate, lockfile, COMMIT_LOCK))
                rollback_lock_file(lockfile);
 }
 
-int write_index(struct index_state *istate, int newfd)
+static int do_write_index(struct index_state *istate, int newfd,
+                         int strip_extensions)
 {
        git_SHA_CTX c;
        struct cache_header hdr;
@@ -1852,8 +1932,11 @@ int write_index(struct index_state *istate, int newfd)
                }
        }
 
-       if (!istate->version)
+       if (!istate->version) {
                istate->version = get_index_format_default();
+               if (getenv("GIT_TEST_SPLIT_INDEX"))
+                       init_split_index(istate);
+       }
 
        /* demote version 3 to version 2 when the latter suffices */
        if (istate->version == 3 || istate->version == 2)
@@ -1893,7 +1976,18 @@ int write_index(struct index_state *istate, int newfd)
        strbuf_release(&previous_name_buf);
 
        /* Write extension data here */
-       if (istate->cache_tree) {
+       if (!strip_extensions && istate->split_index) {
+               struct strbuf sb = STRBUF_INIT;
+
+               err = write_link_extension(&sb, istate) < 0 ||
+                       write_index_ext_header(&c, newfd, CACHE_EXT_LINK,
+                                              sb.len) < 0 ||
+                       ce_write(&c, newfd, sb.buf, sb.len) < 0;
+               strbuf_release(&sb);
+               if (err)
+                       return -1;
+       }
+       if (!strip_extensions && istate->cache_tree) {
                struct strbuf sb = STRBUF_INIT;
 
                cache_tree_write(&sb, istate->cache_tree);
@@ -1903,7 +1997,7 @@ int write_index(struct index_state *istate, int newfd)
                if (err)
                        return -1;
        }
-       if (istate->resolve_undo) {
+       if (!strip_extensions && istate->resolve_undo) {
                struct strbuf sb = STRBUF_INIT;
 
                resolve_undo_write(&sb, istate->resolve_undo);
@@ -1915,13 +2009,138 @@ int write_index(struct index_state *istate, int newfd)
                        return -1;
        }
 
-       if (ce_flush(&c, newfd) || fstat(newfd, &st))
+       if (ce_flush(&c, newfd, istate->sha1) || fstat(newfd, &st))
                return -1;
        istate->timestamp.sec = (unsigned int)st.st_mtime;
        istate->timestamp.nsec = ST_MTIME_NSEC(st);
        return 0;
 }
 
+void set_alternate_index_output(const char *name)
+{
+       alternate_index_output = name;
+}
+
+static int commit_locked_index(struct lock_file *lk)
+{
+       if (alternate_index_output) {
+               if (lk->fd >= 0 && close_lock_file(lk))
+                       return -1;
+               if (rename(lk->filename, alternate_index_output))
+                       return -1;
+               lk->filename[0] = 0;
+               return 0;
+       } else {
+               return commit_lock_file(lk);
+       }
+}
+
+static int do_write_locked_index(struct index_state *istate, struct lock_file *lock,
+                                unsigned flags)
+{
+       int ret = do_write_index(istate, lock->fd, 0);
+       if (ret)
+               return ret;
+       assert((flags & (COMMIT_LOCK | CLOSE_LOCK)) !=
+              (COMMIT_LOCK | CLOSE_LOCK));
+       if (flags & COMMIT_LOCK)
+               return commit_locked_index(lock);
+       else if (flags & CLOSE_LOCK)
+               return close_lock_file(lock);
+       else
+               return ret;
+}
+
+static int write_split_index(struct index_state *istate,
+                            struct lock_file *lock,
+                            unsigned flags)
+{
+       int ret;
+       prepare_to_write_split_index(istate);
+       ret = do_write_locked_index(istate, lock, flags);
+       finish_writing_split_index(istate);
+       return ret;
+}
+
+static char *temporary_sharedindex;
+
+static void remove_temporary_sharedindex(void)
+{
+       if (temporary_sharedindex) {
+               unlink_or_warn(temporary_sharedindex);
+               free(temporary_sharedindex);
+               temporary_sharedindex = NULL;
+       }
+}
+
+static void remove_temporary_sharedindex_on_signal(int signo)
+{
+       remove_temporary_sharedindex();
+       sigchain_pop(signo);
+       raise(signo);
+}
+
+static int write_shared_index(struct index_state *istate,
+                             struct lock_file *lock, unsigned flags)
+{
+       struct split_index *si = istate->split_index;
+       static int installed_handler;
+       int fd, ret;
+
+       temporary_sharedindex = git_pathdup("sharedindex_XXXXXX");
+       fd = mkstemp(temporary_sharedindex);
+       if (fd < 0) {
+               free(temporary_sharedindex);
+               temporary_sharedindex = NULL;
+               hashclr(si->base_sha1);
+               return do_write_locked_index(istate, lock, flags);
+       }
+       if (!installed_handler) {
+               atexit(remove_temporary_sharedindex);
+               sigchain_push_common(remove_temporary_sharedindex_on_signal);
+       }
+       move_cache_to_base_index(istate);
+       ret = do_write_index(si->base, fd, 1);
+       close(fd);
+       if (ret) {
+               remove_temporary_sharedindex();
+               return ret;
+       }
+       ret = rename(temporary_sharedindex,
+                    git_path("sharedindex.%s", sha1_to_hex(si->base->sha1)));
+       free(temporary_sharedindex);
+       temporary_sharedindex = NULL;
+       if (!ret)
+               hashcpy(si->base_sha1, si->base->sha1);
+       return ret;
+}
+
+int write_locked_index(struct index_state *istate, struct lock_file *lock,
+                      unsigned flags)
+{
+       struct split_index *si = istate->split_index;
+
+       if (!si || alternate_index_output ||
+           (istate->cache_changed & ~EXTMASK)) {
+               if (si)
+                       hashclr(si->base_sha1);
+               return do_write_locked_index(istate, lock, flags);
+       }
+
+       if (getenv("GIT_TEST_SPLIT_INDEX")) {
+               int v = si->base_sha1[0];
+               if ((v & 15) < 6)
+                       istate->cache_changed |= SPLIT_INDEX_ORDERED;
+       }
+       if (istate->cache_changed & SPLIT_INDEX_ORDERED) {
+               int ret = write_shared_index(istate, lock, flags);
+               if (ret)
+                       return ret;
+       }
+
+       return write_split_index(istate, lock, flags);
+}
+
 /*
  * Read the index file that is potentially unmerged into given
  * index_state, dropping any unmerged entries.  Returns true if
index 0dd5084fe5c80fe9504cfe4ec4bff3722b733eaf..9ce8b53ccc85abcf27d7aff8f86a350ef2cd36b2 100644 (file)
@@ -41,7 +41,7 @@ static int read_one_reflog(unsigned char *osha1, unsigned char *nsha1,
 static struct complete_reflogs *read_complete_reflog(const char *ref)
 {
        struct complete_reflogs *reflogs =
-               xcalloc(sizeof(struct complete_reflogs), 1);
+               xcalloc(1, sizeof(struct complete_reflogs));
        reflogs->ref = xstrdup(ref);
        for_each_reflog_ent(ref, read_one_reflog, reflogs);
        if (reflogs->nr == 0) {
@@ -135,7 +135,7 @@ struct reflog_walk_info {
 
 void init_reflog_walk(struct reflog_walk_info** info)
 {
-       *info = xcalloc(sizeof(struct reflog_walk_info), 1);
+       *info = xcalloc(1, sizeof(struct reflog_walk_info));
 }
 
 int add_reflog_for_walk(struct reflog_walk_info *info,
@@ -199,7 +199,7 @@ int add_reflog_for_walk(struct reflog_walk_info *info,
                        = reflogs;
        }
 
-       commit_reflog = xcalloc(sizeof(struct commit_reflog), 1);
+       commit_reflog = xcalloc(1, sizeof(struct commit_reflog));
        if (recno < 0) {
                commit_reflog->recno = get_reflog_recno_by_time(reflogs, timestamp);
                if (commit_reflog->recno < 0) {
@@ -242,7 +242,7 @@ void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit)
                return;
        }
 
-       commit->parents = xcalloc(sizeof(struct commit_list), 1);
+       commit->parents = xcalloc(1, sizeof(struct commit_list));
        commit->parents->item = commit_info->commit;
 }
 
diff --git a/refs.c b/refs.c
index 59fb70087a438a763cdbfb2c4e75de36d533aead..061d233e4b6404c57ff8d62715758b900d02e051 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -6,51 +6,71 @@
 #include "string-list.h"
 
 /*
- * Make sure "ref" is something reasonable to have under ".git/refs/";
- * We do not like it if:
+ * How to handle various characters in refnames:
+ * This table is used by both the SIMD and non-SIMD code.  It has
+ * some cases that are only useful for the SIMD; these are handled
+ * equivalently to the listed disposition in the non-SIMD code.
+ * 0: An acceptable character for refs
+ * 1: @, look for a following { to reject @{ in refs (SIMD or = 0)
+ * 2: \0: End-of-component and string
+ * 3: /: End-of-component (SIMD or = 2)
+ * 4: ., look for a preceding . to reject .. in refs
+ * 5: {, look for a preceding @ to reject @{ in refs
+ * 6: *, usually a bad character except, once as a wildcard (SIMD or = 7)
+ * 7: A bad character except * (see check_refname_component below)
+ */
+static unsigned char refname_disposition[256] = {
+       2, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+       7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+       7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 4, 3,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 7,
+       1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 7, 0,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 7, 7
+};
+
+/*
+ * Try to read one refname component from the front of refname.
+ * Return the length of the component found, or -1 if the component is
+ * not legal.  It is legal if it is something reasonable to have under
+ * ".git/refs/"; We do not like it if:
  *
  * - any path component of it begins with ".", or
  * - it has double dots "..", or
  * - it has ASCII control character, "~", "^", ":" or SP, anywhere, or
- * - it ends with a "/".
- * - it ends with ".lock"
+ * - it has pattern-matching notation "*", "?", "[", anywhere, or
+ * - it ends with a "/", or
+ * - it ends with ".lock", or
  * - it contains a "\" (backslash)
  */
-
-/* Return true iff ch is not allowed in reference names. */
-static inline int bad_ref_char(int ch)
-{
-       if (((unsigned) ch) <= ' ' || ch == 0x7f ||
-           ch == '~' || ch == '^' || ch == ':' || ch == '\\')
-               return 1;
-       /* 2.13 Pattern Matching Notation */
-       if (ch == '*' || ch == '?' || ch == '[') /* Unsupported */
-               return 1;
-       return 0;
-}
-
-/*
- * Try to read one refname component from the front of refname.  Return
- * the length of the component found, or -1 if the component is not
- * legal.
- */
 static int check_refname_component(const char *refname, int flags)
 {
        const char *cp;
        char last = '\0';
 
        for (cp = refname; ; cp++) {
-               char ch = *cp;
-               if (ch == '\0' || ch == '/')
+               int ch = *cp & 255;
+               unsigned char disp = refname_disposition[ch];
+               switch (disp) {
+               case 2: /* fall-through */
+               case 3:
+                       goto out;
+               case 4:
+                       if (last == '.')
+                               return -1; /* Refname contains "..". */
                        break;
-               if (bad_ref_char(ch))
-                       return -1; /* Illegal character in refname. */
-               if (last == '.' && ch == '.')
-                       return -1; /* Refname contains "..". */
-               if (last == '@' && ch == '{')
-                       return -1; /* Refname contains "@{". */
+               case 5:
+                       if (last == '@')
+                               return -1; /* Refname contains "@{". */
+                       break;
+               case 6: /* fall-through */
+               case 7:
+                       return -1;
+               }
                last = ch;
        }
+out:
        if (cp == refname)
                return 0; /* Component has zero length. */
        if (refname[0] == '.') {
@@ -68,7 +88,7 @@ static int check_refname_component(const char *refname, int flags)
        return cp - refname;
 }
 
-int check_refname_format(const char *refname, int flags)
+static int check_refname_format_bytewise(const char *refname, int flags)
 {
        int component_len, component_count = 0;
 
@@ -104,6 +124,196 @@ int check_refname_format(const char *refname, int flags)
        return 0;
 }
 
+#if defined(__GNUC__) && defined(__x86_64__)
+#define SSE_VECTOR_BYTES 16
+
+/* Vectorized version of check_refname_format. */
+int check_refname_format(const char *refname, int flags)
+{
+       const char *cp = refname;
+
+       const __m128i dot = _mm_set1_epi8('.');
+       const __m128i at = _mm_set1_epi8('@');
+       const __m128i curly = _mm_set1_epi8('{');
+       const __m128i slash = _mm_set1_epi8('/');
+       const __m128i zero = _mm_set1_epi8('\000');
+       const __m128i el = _mm_set1_epi8('l');
+
+       /* below '*', all characters are forbidden or rare */
+       const __m128i star_ub = _mm_set1_epi8('*' + 1);
+
+       const __m128i colon = _mm_set1_epi8(':');
+       const __m128i question = _mm_set1_epi8('?');
+
+       /* '['..'^' contains 4 characters: 3 forbidden and 1 rare */
+       const __m128i bracket_lb = _mm_set1_epi8('[' - 1);
+       const __m128i caret_ub = _mm_set1_epi8('^' + 1);
+
+       /* '~' and above are forbidden */
+       const __m128i tilde_lb = _mm_set1_epi8('~' - 1);
+
+       int component_count = 0;
+       int orig_flags = flags;
+
+       if (refname[0] == 0 || refname[0] == '/') {
+               /* entirely empty ref or initial ref component */
+               return -1;
+       }
+
+       /*
+        * Initial ref component of '.'; below we look for /. so we'll
+        * miss this.
+        */
+       if (refname[0] == '.') {
+               if (refname[1] == '/' || refname[1] == '\0')
+                       return -1;
+               if (!(flags & REFNAME_DOT_COMPONENT))
+                       return -1;
+       }
+       while(1) {
+               __m128i tmp, tmp1, result;
+               uint64_t mask;
+
+               if ((uintptr_t) cp % PAGE_SIZE > PAGE_SIZE - SSE_VECTOR_BYTES  - 1)
+                       /*
+                        * End-of-page; fall back to slow method for
+                        * this entire ref.
+                        */
+                       return check_refname_format_bytewise(refname, orig_flags);
+
+               tmp = _mm_loadu_si128((__m128i *)cp);
+               tmp1 = _mm_loadu_si128((__m128i *)(cp + 1));
+
+               /*
+                * This range (note the lt) contains some
+                * permissible-but-rare characters (including all
+                * characters >= 128), which we handle later.  It also
+                * includes \000.
+                */
+               result = _mm_cmplt_epi8(tmp, star_ub);
+
+               result = _mm_or_si128(result, _mm_cmpeq_epi8(tmp, question));
+               result = _mm_or_si128(result, _mm_cmpeq_epi8(tmp, colon));
+
+               /* This range contains the permissible ] as bycatch */
+               result = _mm_or_si128(result, _mm_and_si128(
+                                             _mm_cmpgt_epi8(tmp, bracket_lb),
+                                             _mm_cmplt_epi8(tmp, caret_ub)));
+
+               result = _mm_or_si128(result, _mm_cmpgt_epi8(tmp, tilde_lb));
+
+               /* .. */
+               result = _mm_or_si128(result, _mm_and_si128(
+                                             _mm_cmpeq_epi8(tmp, dot),
+                                             _mm_cmpeq_epi8(tmp1, dot)));
+               /* @{ */
+               result = _mm_or_si128(result, _mm_and_si128(
+                                             _mm_cmpeq_epi8(tmp, at),
+                                             _mm_cmpeq_epi8(tmp1, curly)));
+               /* // */
+               result = _mm_or_si128(result, _mm_and_si128(
+                                             _mm_cmpeq_epi8(tmp, slash),
+                                             _mm_cmpeq_epi8(tmp1, slash)));
+               /* trailing / */
+               result = _mm_or_si128(result, _mm_and_si128(
+                                             _mm_cmpeq_epi8(tmp, slash),
+                                             _mm_cmpeq_epi8(tmp1, zero)));
+               /* .l, beginning of .lock */
+               result = _mm_or_si128(result, _mm_and_si128(
+                                             _mm_cmpeq_epi8(tmp, dot),
+                                             _mm_cmpeq_epi8(tmp1, el)));
+               /*
+                * Even though /. is not necessarily an error, we flag
+                * it anyway. If we find it, we'll check if it's valid
+                * and if so we'll advance just past it.
+                */
+               result = _mm_or_si128(result, _mm_and_si128(
+                                             _mm_cmpeq_epi8(tmp, slash),
+                                             _mm_cmpeq_epi8(tmp1, dot)));
+
+               mask = _mm_movemask_epi8(result);
+               if (mask) {
+                       /*
+                        * We've found either end-of-string, or some
+                        * probably-bad character or substring.
+                        */
+                       int i = __builtin_ctz(mask);
+                       switch (refname_disposition[cp[i] & 255]) {
+                       case 0: /* fall-through */
+                       case 5:
+                               /*
+                                * bycatch: a good character that's in
+                                * one of the ranges of mostly-forbidden
+                                * characters
+                                */
+                               cp += i + 1;
+                               break;
+                       case 1:
+                               if (cp[i + 1] == '{')
+                                       return -1;
+                               cp += i + 1;
+                               break;
+                       case 2:
+                               if (!(flags & REFNAME_ALLOW_ONELEVEL)
+                                   && !component_count && !strchr(refname, '/'))
+                                       /* Refname has only one component. */
+                                       return -1;
+                               return 0;
+                       case 3:
+                               component_count ++;
+                               /*
+                                * Even if leading dots are allowed, don't
+                                * allow "." as a component (".." is
+                                * prevented by case 4 below).
+                                */
+                               if (cp[i + 1] == '.') {
+                                       if (cp[i + 2] == '\0')
+                                               return -1;
+                                       if (flags & REFNAME_DOT_COMPONENT) {
+                                               /* skip to just after the /. */
+                                               cp += i + 2;
+                                               break;
+                                       }
+                                       return -1;
+                               } else if (cp[i + 1] == '/' || cp[i + 1] == '\0')
+                                       return -1;
+                               break;
+                       case 4:
+                               if (cp[i + 1] == '.' || cp[i + 1] == '\0')
+                                       return -1;
+                               /* .lock as end-of-component or end-of-string */
+                               if ((!strncmp(cp + i, ".lock", 5))
+                                   && (cp[i + 5] == '/' || cp[i + 5] == 0))
+                                       return -1;
+                               cp += 1;
+                               break;
+                       case 6:
+                               if (((cp == refname + i) || cp[i - 1] == '/')
+                                   && (cp[i + 1] == '/' || cp[i + 1] == 0))
+                                       if (flags & REFNAME_REFSPEC_PATTERN) {
+                                               flags &= ~REFNAME_REFSPEC_PATTERN;
+                                               /* restart after the * */
+                                               cp += i + 1;
+                                               continue;
+                                       }
+                               /* fall-through */
+                       case 7:
+                               return -1;
+                       }
+               } else
+                       cp += SSE_VECTOR_BYTES;
+       }
+}
+
+#else
+
+int check_refname_format (const char *refname, int flags)
+{
+       return check_refname_format_bytewise(refname, flags);
+}
+
+#endif
+
 struct ref_entry;
 
 /*
@@ -1151,7 +1361,7 @@ static void read_loose_refs(const char *dirname, struct ref_dir *dir)
 
                if (de->d_name[0] == '.')
                        continue;
-               if (has_extension(de->d_name, ".lock"))
+               if (ends_with(de->d_name, ".lock"))
                        continue;
                strbuf_addstr(&refname, de->d_name);
                refdir = *refs->name
@@ -2016,7 +2226,6 @@ int dwim_log(const char *str, int len, unsigned char *sha1, char **log)
 
        *log = NULL;
        for (p = ref_rev_parse_rules; *p; p++) {
-               struct stat st;
                unsigned char hash[20];
                char path[PATH_MAX];
                const char *ref, *it;
@@ -2025,12 +2234,9 @@ int dwim_log(const char *str, int len, unsigned char *sha1, char **log)
                ref = resolve_ref_unsafe(path, hash, 1, NULL);
                if (!ref)
                        continue;
-               if (!stat(git_path("logs/%s", path), &st) &&
-                   S_ISREG(st.st_mode))
+               if (reflog_exists(path))
                        it = path;
-               else if (strcmp(ref, path) &&
-                        !stat(git_path("logs/%s", ref), &st) &&
-                        S_ISREG(st.st_mode))
+               else if (strcmp(ref, path) && reflog_exists(ref))
                        it = ref;
                else
                        continue;
@@ -2947,122 +3153,133 @@ int create_symref(const char *ref_target, const char *refs_heads_master,
        return 0;
 }
 
-static char *ref_msg(const char *line, const char *endp)
-{
-       const char *ep;
-       line += 82;
-       ep = memchr(line, '\n', endp - line);
-       if (!ep)
-               ep = endp;
-       return xmemdupz(line, ep - line);
+struct read_ref_at_cb {
+       const char *refname;
+       unsigned long at_time;
+       int cnt;
+       int reccnt;
+       unsigned char *sha1;
+       int found_it;
+
+       unsigned char osha1[20];
+       unsigned char nsha1[20];
+       int tz;
+       unsigned long date;
+       char **msg;
+       unsigned long *cutoff_time;
+       int *cutoff_tz;
+       int *cutoff_cnt;
+};
+
+static int read_ref_at_ent(unsigned char *osha1, unsigned char *nsha1,
+               const char *email, unsigned long timestamp, int tz,
+               const char *message, void *cb_data)
+{
+       struct read_ref_at_cb *cb = cb_data;
+
+       cb->reccnt++;
+       cb->tz = tz;
+       cb->date = timestamp;
+
+       if (timestamp <= cb->at_time || cb->cnt == 0) {
+               if (cb->msg)
+                       *cb->msg = xstrdup(message);
+               if (cb->cutoff_time)
+                       *cb->cutoff_time = timestamp;
+               if (cb->cutoff_tz)
+                       *cb->cutoff_tz = tz;
+               if (cb->cutoff_cnt)
+                       *cb->cutoff_cnt = cb->reccnt - 1;
+               /*
+                * we have not yet updated cb->[n|o]sha1 so they still
+                * hold the values for the previous record.
+                */
+               if (!is_null_sha1(cb->osha1)) {
+                       hashcpy(cb->sha1, nsha1);
+                       if (hashcmp(cb->osha1, nsha1))
+                               warning("Log for ref %s has gap after %s.",
+                                       cb->refname, show_date(cb->date, cb->tz, DATE_RFC2822));
+               }
+               else if (cb->date == cb->at_time)
+                       hashcpy(cb->sha1, nsha1);
+               else if (hashcmp(nsha1, cb->sha1))
+                       warning("Log for ref %s unexpectedly ended on %s.",
+                               cb->refname, show_date(cb->date, cb->tz,
+                                                  DATE_RFC2822));
+               hashcpy(cb->osha1, osha1);
+               hashcpy(cb->nsha1, nsha1);
+               cb->found_it = 1;
+               return 1;
+       }
+       hashcpy(cb->osha1, osha1);
+       hashcpy(cb->nsha1, nsha1);
+       if (cb->cnt > 0)
+               cb->cnt--;
+       return 0;
+}
+
+static int read_ref_at_ent_oldest(unsigned char *osha1, unsigned char *nsha1,
+                                 const char *email, unsigned long timestamp,
+                                 int tz, const char *message, void *cb_data)
+{
+       struct read_ref_at_cb *cb = cb_data;
+
+       if (cb->msg)
+               *cb->msg = xstrdup(message);
+       if (cb->cutoff_time)
+               *cb->cutoff_time = timestamp;
+       if (cb->cutoff_tz)
+               *cb->cutoff_tz = tz;
+       if (cb->cutoff_cnt)
+               *cb->cutoff_cnt = cb->reccnt;
+       hashcpy(cb->sha1, osha1);
+       if (is_null_sha1(cb->sha1))
+               hashcpy(cb->sha1, nsha1);
+       /* We just want the first entry */
+       return 1;
 }
 
 int read_ref_at(const char *refname, unsigned long at_time, int cnt,
                unsigned char *sha1, char **msg,
                unsigned long *cutoff_time, int *cutoff_tz, int *cutoff_cnt)
 {
-       const char *logfile, *logdata, *logend, *rec, *lastgt, *lastrec;
-       char *tz_c;
-       int logfd, tz, reccnt = 0;
-       struct stat st;
-       unsigned long date;
-       unsigned char logged_sha1[20];
-       void *log_mapped;
-       size_t mapsz;
+       struct read_ref_at_cb cb;
 
-       logfile = git_path("logs/%s", refname);
-       logfd = open(logfile, O_RDONLY, 0);
-       if (logfd < 0)
-               die_errno("Unable to read log '%s'", logfile);
-       fstat(logfd, &st);
-       if (!st.st_size)
-               die("Log %s is empty.", logfile);
-       mapsz = xsize_t(st.st_size);
-       log_mapped = xmmap(NULL, mapsz, PROT_READ, MAP_PRIVATE, logfd, 0);
-       logdata = log_mapped;
-       close(logfd);
+       memset(&cb, 0, sizeof(cb));
+       cb.refname = refname;
+       cb.at_time = at_time;
+       cb.cnt = cnt;
+       cb.msg = msg;
+       cb.cutoff_time = cutoff_time;
+       cb.cutoff_tz = cutoff_tz;
+       cb.cutoff_cnt = cutoff_cnt;
+       cb.sha1 = sha1;
+
+       for_each_reflog_ent_reverse(refname, read_ref_at_ent, &cb);
+
+       if (!cb.reccnt)
+               die("Log for %s is empty.", refname);
+       if (cb.found_it)
+               return 0;
+
+       for_each_reflog_ent(refname, read_ref_at_ent_oldest, &cb);
 
-       lastrec = NULL;
-       rec = logend = logdata + st.st_size;
-       while (logdata < rec) {
-               reccnt++;
-               if (logdata < rec && *(rec-1) == '\n')
-                       rec--;
-               lastgt = NULL;
-               while (logdata < rec && *(rec-1) != '\n') {
-                       rec--;
-                       if (*rec == '>')
-                               lastgt = rec;
-               }
-               if (!lastgt)
-                       die("Log %s is corrupt.", logfile);
-               date = strtoul(lastgt + 1, &tz_c, 10);
-               if (date <= at_time || cnt == 0) {
-                       tz = strtoul(tz_c, NULL, 10);
-                       if (msg)
-                               *msg = ref_msg(rec, logend);
-                       if (cutoff_time)
-                               *cutoff_time = date;
-                       if (cutoff_tz)
-                               *cutoff_tz = tz;
-                       if (cutoff_cnt)
-                               *cutoff_cnt = reccnt - 1;
-                       if (lastrec) {
-                               if (get_sha1_hex(lastrec, logged_sha1))
-                                       die("Log %s is corrupt.", logfile);
-                               if (get_sha1_hex(rec + 41, sha1))
-                                       die("Log %s is corrupt.", logfile);
-                               if (hashcmp(logged_sha1, sha1)) {
-                                       warning("Log %s has gap after %s.",
-                                               logfile, show_date(date, tz, DATE_RFC2822));
-                               }
-                       }
-                       else if (date == at_time) {
-                               if (get_sha1_hex(rec + 41, sha1))
-                                       die("Log %s is corrupt.", logfile);
-                       }
-                       else {
-                               if (get_sha1_hex(rec + 41, logged_sha1))
-                                       die("Log %s is corrupt.", logfile);
-                               if (hashcmp(logged_sha1, sha1)) {
-                                       warning("Log %s unexpectedly ended on %s.",
-                                               logfile, show_date(date, tz, DATE_RFC2822));
-                               }
-                       }
-                       munmap(log_mapped, mapsz);
-                       return 0;
-               }
-               lastrec = rec;
-               if (cnt > 0)
-                       cnt--;
-       }
-
-       rec = logdata;
-       while (rec < logend && *rec != '>' && *rec != '\n')
-               rec++;
-       if (rec == logend || *rec == '\n')
-               die("Log %s is corrupt.", logfile);
-       date = strtoul(rec + 1, &tz_c, 10);
-       tz = strtoul(tz_c, NULL, 10);
-       if (get_sha1_hex(logdata, sha1))
-               die("Log %s is corrupt.", logfile);
-       if (is_null_sha1(sha1)) {
-               if (get_sha1_hex(logdata + 41, sha1))
-                       die("Log %s is corrupt.", logfile);
-       }
-       if (msg)
-               *msg = ref_msg(logdata, logend);
-       munmap(log_mapped, mapsz);
-
-       if (cutoff_time)
-               *cutoff_time = date;
-       if (cutoff_tz)
-               *cutoff_tz = tz;
-       if (cutoff_cnt)
-               *cutoff_cnt = reccnt;
        return 1;
 }
 
+int reflog_exists(const char *refname)
+{
+       struct stat st;
+
+       return !lstat(git_path("logs/%s", refname), &st) &&
+               S_ISREG(st.st_mode);
+}
+
+int delete_reflog(const char *refname)
+{
+       return remove_path(git_path("logs/%s", refname));
+}
+
 static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *cb_data)
 {
        unsigned char osha1[20], nsha1[20];
@@ -3215,7 +3432,7 @@ static int do_for_each_reflog(struct strbuf *name, each_ref_fn fn, void *cb_data
 
                if (de->d_name[0] == '.')
                        continue;
-               if (has_extension(de->d_name, ".lock"))
+               if (ends_with(de->d_name, ".lock"))
                        continue;
                strbuf_addstr(name, de->d_name);
                if (stat(git_path("logs/%s", name->buf), &st) < 0) {
@@ -3260,9 +3477,9 @@ static struct ref_lock *update_ref_lock(const char *refname,
        if (!lock) {
                const char *str = "Cannot lock the ref '%s'.";
                switch (onerr) {
-               case MSG_ON_ERR: error(str, refname); break;
-               case DIE_ON_ERR: die(str, refname); break;
-               case QUIET_ON_ERR: break;
+               case UPDATE_REFS_MSG_ON_ERR: error(str, refname); break;
+               case UPDATE_REFS_DIE_ON_ERR: die(str, refname); break;
+               case UPDATE_REFS_QUIET_ON_ERR: break;
                }
        }
        return lock;
@@ -3275,15 +3492,118 @@ static int update_ref_write(const char *action, const char *refname,
        if (write_ref_sha1(lock, sha1, action) < 0) {
                const char *str = "Cannot update the ref '%s'.";
                switch (onerr) {
-               case MSG_ON_ERR: error(str, refname); break;
-               case DIE_ON_ERR: die(str, refname); break;
-               case QUIET_ON_ERR: break;
+               case UPDATE_REFS_MSG_ON_ERR: error(str, refname); break;
+               case UPDATE_REFS_DIE_ON_ERR: die(str, refname); break;
+               case UPDATE_REFS_QUIET_ON_ERR: break;
                }
                return 1;
        }
        return 0;
 }
 
+/**
+ * Information needed for a single ref update.  Set new_sha1 to the
+ * new value or to zero to delete the ref.  To check the old value
+ * while locking the ref, set have_old to 1 and set old_sha1 to the
+ * value or to zero to ensure the ref does not exist before update.
+ */
+struct ref_update {
+       unsigned char new_sha1[20];
+       unsigned char old_sha1[20];
+       int flags; /* REF_NODEREF? */
+       int have_old; /* 1 if old_sha1 is valid, 0 otherwise */
+       struct ref_lock *lock;
+       int type;
+       const char refname[FLEX_ARRAY];
+};
+
+/*
+ * Data structure for holding a reference transaction, which can
+ * consist of checks and updates to multiple references, carried out
+ * as atomically as possible.  This structure is opaque to callers.
+ */
+struct ref_transaction {
+       struct ref_update **updates;
+       size_t alloc;
+       size_t nr;
+};
+
+struct ref_transaction *ref_transaction_begin(void)
+{
+       return xcalloc(1, sizeof(struct ref_transaction));
+}
+
+static void ref_transaction_free(struct ref_transaction *transaction)
+{
+       int i;
+
+       for (i = 0; i < transaction->nr; i++)
+               free(transaction->updates[i]);
+
+       free(transaction->updates);
+       free(transaction);
+}
+
+void ref_transaction_rollback(struct ref_transaction *transaction)
+{
+       ref_transaction_free(transaction);
+}
+
+static struct ref_update *add_update(struct ref_transaction *transaction,
+                                    const char *refname)
+{
+       size_t len = strlen(refname);
+       struct ref_update *update = xcalloc(1, sizeof(*update) + len + 1);
+
+       strcpy((char *)update->refname, refname);
+       ALLOC_GROW(transaction->updates, transaction->nr + 1, transaction->alloc);
+       transaction->updates[transaction->nr++] = update;
+       return update;
+}
+
+void ref_transaction_update(struct ref_transaction *transaction,
+                           const char *refname,
+                           unsigned char *new_sha1, unsigned char *old_sha1,
+                           int flags, int have_old)
+{
+       struct ref_update *update = add_update(transaction, refname);
+
+       hashcpy(update->new_sha1, new_sha1);
+       update->flags = flags;
+       update->have_old = have_old;
+       if (have_old)
+               hashcpy(update->old_sha1, old_sha1);
+}
+
+void ref_transaction_create(struct ref_transaction *transaction,
+                           const char *refname,
+                           unsigned char *new_sha1,
+                           int flags)
+{
+       struct ref_update *update = add_update(transaction, refname);
+
+       assert(!is_null_sha1(new_sha1));
+       hashcpy(update->new_sha1, new_sha1);
+       hashclr(update->old_sha1);
+       update->flags = flags;
+       update->have_old = 1;
+}
+
+void ref_transaction_delete(struct ref_transaction *transaction,
+                           const char *refname,
+                           unsigned char *old_sha1,
+                           int flags, int have_old)
+{
+       struct ref_update *update = add_update(transaction, refname);
+
+       update->flags = flags;
+       update->have_old = have_old;
+       if (have_old) {
+               assert(!is_null_sha1(old_sha1));
+               hashcpy(update->old_sha1, old_sha1);
+       }
+}
+
 int update_ref(const char *action, const char *refname,
               const unsigned char *sha1, const unsigned char *oldval,
               int flags, enum action_on_err onerr)
@@ -3299,7 +3619,7 @@ static int ref_update_compare(const void *r1, const void *r2)
 {
        const struct ref_update * const *u1 = r1;
        const struct ref_update * const *u2 = r2;
-       return strcmp((*u1)->ref_name, (*u2)->ref_name);
+       return strcmp((*u1)->refname, (*u2)->refname);
 }
 
 static int ref_update_reject_duplicates(struct ref_update **updates, int n,
@@ -3307,15 +3627,15 @@ static int ref_update_reject_duplicates(struct ref_update **updates, int n,
 {
        int i;
        for (i = 1; i < n; i++)
-               if (!strcmp(updates[i - 1]->ref_name, updates[i]->ref_name)) {
+               if (!strcmp(updates[i - 1]->refname, updates[i]->refname)) {
                        const char *str =
                                "Multiple updates for ref '%s' not allowed.";
                        switch (onerr) {
-                       case MSG_ON_ERR:
-                               error(str, updates[i]->ref_name); break;
-                       case DIE_ON_ERR:
-                               die(str, updates[i]->ref_name); break;
-                       case QUIET_ON_ERR:
+                       case UPDATE_REFS_MSG_ON_ERR:
+                               error(str, updates[i]->refname); break;
+                       case UPDATE_REFS_DIE_ON_ERR:
+                               die(str, updates[i]->refname); break;
+                       case UPDATE_REFS_QUIET_ON_ERR:
                                break;
                        }
                        return 1;
@@ -3323,26 +3643,21 @@ static int ref_update_reject_duplicates(struct ref_update **updates, int n,
        return 0;
 }
 
-int update_refs(const char *action, const struct ref_update **updates_orig,
-               int n, enum action_on_err onerr)
+int ref_transaction_commit(struct ref_transaction *transaction,
+                          const char *msg, enum action_on_err onerr)
 {
        int ret = 0, delnum = 0, i;
-       struct ref_update **updates;
-       int *types;
-       struct ref_lock **locks;
        const char **delnames;
+       int n = transaction->nr;
+       struct ref_update **updates = transaction->updates;
 
-       if (!updates_orig || !n)
+       if (!n)
                return 0;
 
        /* Allocate work space */
-       updates = xmalloc(sizeof(*updates) * n);
-       types = xmalloc(sizeof(*types) * n);
-       locks = xcalloc(n, sizeof(*locks));
        delnames = xmalloc(sizeof(*delnames) * n);
 
        /* Copy, sort, and reject duplicate refs */
-       memcpy(updates, updates_orig, sizeof(*updates) * n);
        qsort(updates, n, sizeof(*updates), ref_update_compare);
        ret = ref_update_reject_duplicates(updates, n, onerr);
        if (ret)
@@ -3350,35 +3665,44 @@ int update_refs(const char *action, const struct ref_update **updates_orig,
 
        /* Acquire all locks while verifying old values */
        for (i = 0; i < n; i++) {
-               locks[i] = update_ref_lock(updates[i]->ref_name,
-                                          (updates[i]->have_old ?
-                                           updates[i]->old_sha1 : NULL),
-                                          updates[i]->flags,
-                                          &types[i], onerr);
-               if (!locks[i]) {
+               struct ref_update *update = updates[i];
+
+               update->lock = update_ref_lock(update->refname,
+                                              (update->have_old ?
+                                               update->old_sha1 : NULL),
+                                              update->flags,
+                                              &update->type, onerr);
+               if (!update->lock) {
                        ret = 1;
                        goto cleanup;
                }
        }
 
        /* Perform updates first so live commits remain referenced */
-       for (i = 0; i < n; i++)
-               if (!is_null_sha1(updates[i]->new_sha1)) {
-                       ret = update_ref_write(action,
-                                              updates[i]->ref_name,
-                                              updates[i]->new_sha1,
-                                              locks[i], onerr);
-                       locks[i] = NULL; /* freed by update_ref_write */
+       for (i = 0; i < n; i++) {
+               struct ref_update *update = updates[i];
+
+               if (!is_null_sha1(update->new_sha1)) {
+                       ret = update_ref_write(msg,
+                                              update->refname,
+                                              update->new_sha1,
+                                              update->lock, onerr);
+                       update->lock = NULL; /* freed by update_ref_write */
                        if (ret)
                                goto cleanup;
                }
+       }
 
        /* Perform deletes now that updates are safely completed */
-       for (i = 0; i < n; i++)
-               if (locks[i]) {
-                       delnames[delnum++] = locks[i]->ref_name;
-                       ret |= delete_ref_loose(locks[i], types[i]);
+       for (i = 0; i < n; i++) {
+               struct ref_update *update = updates[i];
+
+               if (update->lock) {
+                       delnames[delnum++] = update->lock->ref_name;
+                       ret |= delete_ref_loose(update->lock, update->type);
                }
+       }
+
        ret |= repack_without_refs(delnames, delnum);
        for (i = 0; i < delnum; i++)
                unlink_or_warn(git_path("logs/%s", delnames[i]));
@@ -3386,12 +3710,10 @@ int update_refs(const char *action, const struct ref_update **updates_orig,
 
 cleanup:
        for (i = 0; i < n; i++)
-               if (locks[i])
-                       unlock_ref(locks[i]);
-       free(updates);
-       free(types);
-       free(locks);
+               if (updates[i]->lock)
+                       unlock_ref(updates[i]->lock);
        free(delnames);
+       ref_transaction_free(transaction);
        return ret;
 }
 
diff --git a/refs.h b/refs.h
index 1440acc06ce59f35d23719adef18774731efe5a4..4e3050d976dcdae2e98a50b75e065ea086b9cb25 100644 (file)
--- a/refs.h
+++ b/refs.h
@@ -10,19 +10,7 @@ struct ref_lock {
        int force_write;
 };
 
-/**
- * Information needed for a single ref update.  Set new_sha1 to the
- * new value or to zero to delete the ref.  To check the old value
- * while locking the ref, set have_old to 1 and set old_sha1 to the
- * value or to zero to ensure the ref does not exist before update.
- */
-struct ref_update {
-       const char *ref_name;
-       unsigned char new_sha1[20];
-       unsigned char old_sha1[20];
-       int flags; /* REF_NODEREF? */
-       int have_old; /* 1 if old_sha1 is valid, 0 otherwise */
-};
+struct ref_transaction;
 
 /*
  * Bit values set in the flags argument passed to each_ref_fn():
@@ -169,13 +157,19 @@ extern void unlock_ref(struct ref_lock *lock);
 extern int write_ref_sha1(struct ref_lock *lock, const unsigned char *sha1, const char *msg);
 
 /** Setup reflog before using. **/
-int log_ref_setup(const char *ref_name, char *logfile, int bufsize);
+int log_ref_setup(const char *refname, char *logfile, int bufsize);
 
 /** Reads log for the value of ref during at_time. **/
 extern int read_ref_at(const char *refname, unsigned long at_time, int cnt,
                       unsigned char *sha1, char **msg,
                       unsigned long *cutoff_time, int *cutoff_tz, int *cutoff_cnt);
 
+/** Check if a particular reflog exists */
+extern int reflog_exists(const char *refname);
+
+/** Delete a reflog */
+extern int delete_reflog(const char *refname);
+
 /* iterate over reflog entries */
 typedef int each_reflog_ent_fn(unsigned char *osha1, unsigned char *nsha1, const char *, unsigned long, int, const char *, void *);
 int for_each_reflog_ent(const char *refname, each_reflog_ent_fn fn, void *cb_data);
@@ -217,18 +211,80 @@ extern int rename_ref(const char *oldref, const char *newref, const char *logmsg
  */
 extern int resolve_gitlink_ref(const char *path, const char *refname, unsigned char *sha1);
 
-/** lock a ref and then write its file */
-enum action_on_err { MSG_ON_ERR, DIE_ON_ERR, QUIET_ON_ERR };
+enum action_on_err {
+       UPDATE_REFS_MSG_ON_ERR,
+       UPDATE_REFS_DIE_ON_ERR,
+       UPDATE_REFS_QUIET_ON_ERR
+};
+
+/*
+ * Begin a reference transaction.  The reference transaction must
+ * eventually be commited using ref_transaction_commit() or rolled
+ * back using ref_transaction_rollback().
+ */
+struct ref_transaction *ref_transaction_begin(void);
+
+/*
+ * Roll back a ref_transaction and free all associated data.
+ */
+void ref_transaction_rollback(struct ref_transaction *transaction);
+
+
+/*
+ * The following functions add a reference check or update to a
+ * ref_transaction.  In all of them, refname is the name of the
+ * reference to be affected.  The functions make internal copies of
+ * refname, so the caller retains ownership of the parameter.  flags
+ * can be REF_NODEREF; it is passed to update_ref_lock().
+ */
+
+
+/*
+ * Add a reference update to transaction.  new_sha1 is the value that
+ * the reference should have after the update, or zeros if it should
+ * be deleted.  If have_old is true, then old_sha1 holds the value
+ * that the reference should have had before the update, or zeros if
+ * it must not have existed beforehand.
+ */
+void ref_transaction_update(struct ref_transaction *transaction,
+                           const char *refname,
+                           unsigned char *new_sha1, unsigned char *old_sha1,
+                           int flags, int have_old);
+
+/*
+ * Add a reference creation to transaction.  new_sha1 is the value
+ * that the reference should have after the update; it must not be the
+ * null SHA-1.  It is verified that the reference does not exist
+ * already.
+ */
+void ref_transaction_create(struct ref_transaction *transaction,
+                           const char *refname,
+                           unsigned char *new_sha1,
+                           int flags);
+
+/*
+ * Add a reference deletion to transaction.  If have_old is true, then
+ * old_sha1 holds the value that the reference should have had before
+ * the update (which must not be the null SHA-1).
+ */
+void ref_transaction_delete(struct ref_transaction *transaction,
+                           const char *refname,
+                           unsigned char *old_sha1,
+                           int flags, int have_old);
+
+/*
+ * Commit all of the changes that have been queued in transaction, as
+ * atomically as possible.  Return a nonzero value if there is a
+ * problem.  The ref_transaction is freed by this function.
+ */
+int ref_transaction_commit(struct ref_transaction *transaction,
+                          const char *msg, enum action_on_err onerr);
+
+/** Lock a ref and then write its file */
 int update_ref(const char *action, const char *refname,
                const unsigned char *sha1, const unsigned char *oldval,
                int flags, enum action_on_err onerr);
 
-/**
- * Lock all refs and then perform all modifications.
- */
-int update_refs(const char *action, const struct ref_update **updates,
-               int n, enum action_on_err onerr);
-
 extern int parse_hide_refs_config(const char *var, const char *value, const char *);
 extern int ref_is_hidden(const char *);
 
index 52c2d96ce6183ca8b3498794304fa8dc98f8f42a..cdcca2903b100c775d4e004312086581f5839ad4 100644 (file)
@@ -194,19 +194,19 @@ static void free_discovery(struct discovery *d)
        }
 }
 
-static int show_http_message(struct strbuf *type, struct strbuf *msg)
+static int show_http_message(struct strbuf *type, struct strbuf *charset,
+                            struct strbuf *msg)
 {
        const char *p, *eol;
 
        /*
         * We only show text/plain parts, as other types are likely
         * to be ugly to look at on the user's terminal.
-        *
-        * TODO should handle "; charset=XXX", and re-encode into
-        * logoutputencoding
         */
-       if (strcasecmp(type->buf, "text/plain"))
+       if (strcmp(type->buf, "text/plain"))
                return -1;
+       if (charset->len)
+               strbuf_reencode(msg, charset->buf, get_log_output_encoding());
 
        strbuf_trim(msg);
        if (!msg->len)
@@ -225,6 +225,7 @@ static struct discovery* discover_refs(const char *service, int for_push)
 {
        struct strbuf exp = STRBUF_INIT;
        struct strbuf type = STRBUF_INIT;
+       struct strbuf charset = STRBUF_INIT;
        struct strbuf buffer = STRBUF_INIT;
        struct strbuf refs_url = STRBUF_INIT;
        struct strbuf effective_url = STRBUF_INIT;
@@ -249,6 +250,7 @@ static struct discovery* discover_refs(const char *service, int for_push)
 
        memset(&options, 0, sizeof(options));
        options.content_type = &type;
+       options.charset = &charset;
        options.effective_url = &effective_url;
        options.base_url = &url;
        options.no_cache = 1;
@@ -259,13 +261,13 @@ static struct discovery* discover_refs(const char *service, int for_push)
        case HTTP_OK:
                break;
        case HTTP_MISSING_TARGET:
-               show_http_message(&type, &buffer);
+               show_http_message(&type, &charset, &buffer);
                die("repository '%s' not found", url.buf);
        case HTTP_NOAUTH:
-               show_http_message(&type, &buffer);
+               show_http_message(&type, &charset, &buffer);
                die("Authentication failed for '%s'", url.buf);
        default:
-               show_http_message(&type, &buffer);
+               show_http_message(&type, &charset, &buffer);
                die("unable to access '%s': %s", url.buf, curl_errorstr);
        }
 
@@ -310,6 +312,7 @@ static struct discovery* discover_refs(const char *service, int for_push)
        strbuf_release(&refs_url);
        strbuf_release(&exp);
        strbuf_release(&type);
+       strbuf_release(&charset);
        strbuf_release(&effective_url);
        strbuf_release(&buffer);
        last_discovery = last;
@@ -788,9 +791,9 @@ static void parse_fetch(struct strbuf *buf)
        int alloc_heads = 0, nr_heads = 0;
 
        do {
-               if (starts_with(buf->buf, "fetch ")) {
-                       char *p = buf->buf + strlen("fetch ");
-                       char *name;
+               const char *p;
+               if (skip_prefix(buf->buf, "fetch ", &p)) {
+                       const char *name;
                        struct ref *ref;
                        unsigned char old_sha1[20];
 
@@ -965,6 +968,8 @@ int main(int argc, const char **argv)
        http_init(remote, url.buf, 0);
 
        do {
+               const char *arg;
+
                if (strbuf_getline(&buf, stdin, '\n') == EOF) {
                        if (ferror(stdin))
                                fprintf(stderr, "Error reading command stream\n");
@@ -986,9 +991,8 @@ int main(int argc, const char **argv)
                } else if (starts_with(buf.buf, "push ")) {
                        parse_push(&buf);
 
-               } else if (starts_with(buf.buf, "option ")) {
-                       char *name = buf.buf + strlen("option ");
-                       char *value = strchr(name, ' ');
+               } else if (skip_prefix(buf.buf, "option ", &arg)) {
+                       char *value = strchr(arg, ' ');
                        int result;
 
                        if (value)
@@ -996,7 +1000,7 @@ int main(int argc, const char **argv)
                        else
                                value = "true";
 
-                       result = set_option(name, value);
+                       result = set_option(arg, value);
                        if (!result)
                                printf("ok\n");
                        else if (result < 0)
index eea2c8de45052e3e3a59fb150eef3f54c6086800..3d6c86a36f26406305d58505b10db3f747a2546c 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -170,7 +170,6 @@ static struct branch *make_branch(const char *name, int len)
 {
        struct branch *ret;
        int i;
-       char *refname;
 
        for (i = 0; i < branches_nr; i++) {
                if (len ? (!strncmp(name, branches[i]->name, len) &&
@@ -186,10 +185,7 @@ static struct branch *make_branch(const char *name, int len)
                ret->name = xstrndup(name, len);
        else
                ret->name = xstrdup(name);
-       refname = xmalloc(strlen(name) + strlen("refs/heads/") + 1);
-       strcpy(refname, "refs/heads/");
-       strcpy(refname + strlen("refs/heads/"), ret->name);
-       ret->refname = refname;
+       ret->refname = xstrfmt("refs/heads/%s", ret->name);
 
        return ret;
 }
@@ -488,9 +484,8 @@ static void read_config(void)
        current_branch = NULL;
        head_ref = resolve_ref_unsafe("HEAD", sha1, 0, &flag);
        if (head_ref && (flag & REF_ISSYMREF) &&
-           starts_with(head_ref, "refs/heads/")) {
-               current_branch =
-                       make_branch(head_ref + strlen("refs/heads/"), 0);
+           skip_prefix(head_ref, "refs/heads/", &head_ref)) {
+               current_branch = make_branch(head_ref, 0);
        }
        git_config(handle_config, NULL);
        if (branch_pushremote_name) {
@@ -523,7 +518,7 @@ static void free_refspecs(struct refspec *refspec, int nr_refspec)
 static struct refspec *parse_refspec_internal(int nr_refspec, const char **refspec, int fetch, int verify)
 {
        int i;
-       struct refspec *rs = xcalloc(sizeof(*rs), nr_refspec);
+       struct refspec *rs = xcalloc(nr_refspec, sizeof(*rs));
 
        for (i = 0; i < nr_refspec; i++) {
                size_t llen;
@@ -1194,7 +1189,7 @@ static int match_explicit(struct ref *src, struct ref *dst,
        case 1:
                break;
        case 0:
-               if (!memcmp(dst_value, "refs/", 5))
+               if (starts_with(dst_value, "refs/"))
                        matched_dst = make_linked_ref(dst_value, dst_tail);
                else if (is_null_sha1(matched_src->new_sha1))
                        error("unable to delete '%s': remote ref does not exist",
index d55aa8a01b4a4f200f24972795f2887644a06d43..ffc6a5b168304726b5fe326211f26dafa460c7fa 100644 (file)
--- a/rerere.c
+++ b/rerere.c
@@ -492,8 +492,7 @@ static int update_paths(struct string_list *update)
        }
 
        if (!status && active_cache_changed) {
-               if (write_cache(fd, active_cache, active_nr) ||
-                   commit_locked_index(&index_lock))
+               if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK))
                        die("Unable to write new index file");
        } else if (fd >= 0)
                rollback_lock_file(&index_lock);
index 44c697c36d0b406330aeb084db1d6a4be715d6c6..468a2eb92c6d72c519faf5c8203d3d41d520c12d 100644 (file)
@@ -110,7 +110,7 @@ void resolve_undo_clear_index(struct index_state *istate)
        string_list_clear(resolve_undo, 1);
        free(resolve_undo);
        istate->resolve_undo = NULL;
-       istate->cache_changed = 1;
+       istate->cache_changed |= RESOLVE_UNDO_CHANGED;
 }
 
 int unmerge_index_entry_at(struct index_state *istate, int pos)
index 8351e794df943ea6ea7acde40c01c97c20be4576..2571ada6bf66ce6e945c539be4b0123e5b9648a9 100644 (file)
@@ -2791,7 +2791,7 @@ static int commit_match(struct commit *commit, struct rev_info *opt)
 {
        int retval;
        const char *encoding;
-       char *message;
+       const char *message;
        struct strbuf buf = STRBUF_INIT;
 
        if (!opt->grep_filter.pattern_list && !opt->grep_filter.header_list)
@@ -2833,14 +2833,21 @@ static int commit_match(struct commit *commit, struct rev_info *opt)
                format_display_notes(commit->object.sha1, &buf, encoding, 1);
        }
 
-       /* Find either in the original commit message, or in the temporary */
+       /*
+        * Find either in the original commit message, or in the temporary.
+        * Note that we cast away the constness of "message" here. It is
+        * const because it may come from the cached commit buffer. That's OK,
+        * because we know that it is modifiable heap memory, and that while
+        * grep_buffer may modify it for speed, it will restore any
+        * changes before returning.
+        */
        if (buf.len)
                retval = grep_buffer(&opt->grep_filter, buf.buf, buf.len);
        else
                retval = grep_buffer(&opt->grep_filter,
-                                    message, strlen(message));
+                                    (char *)message, strlen(message));
        strbuf_release(&buf);
-       logmsg_free(message, commit);
+       unuse_commit_buffer(commit, message);
        return retval;
 }
 
index 75abc478c6da75471e5fdbb55c74efdfcf3ad160..be07d4ad335ba6df4653239b7ccd6930c91c9879 100644 (file)
@@ -279,6 +279,9 @@ int start_command(struct child_process *cmd)
        int failed_errno;
        char *str;
 
+       if (!cmd->argv)
+               cmd->argv = cmd->args.argv;
+
        /*
         * In case of errors we must keep the promise to close FDs
         * that have been passed in via ->in and ->out.
@@ -328,6 +331,7 @@ int start_command(struct child_process *cmd)
 fail_pipe:
                        error("cannot create %s pipe for %s: %s",
                                str, cmd->argv[0], strerror(failed_errno));
+                       argv_array_clear(&cmd->args);
                        errno = failed_errno;
                        return -1;
                }
@@ -519,6 +523,7 @@ fail_pipe:
                        close_pair(fderr);
                else if (cmd->err)
                        close(cmd->err);
+               argv_array_clear(&cmd->args);
                errno = failed_errno;
                return -1;
        }
@@ -543,7 +548,9 @@ fail_pipe:
 
 int finish_command(struct child_process *cmd)
 {
-       return wait_or_whine(cmd->pid, cmd->argv[0]);
+       int ret = wait_or_whine(cmd->pid, cmd->argv[0]);
+       argv_array_clear(&cmd->args);
+       return ret;
 }
 
 int run_command(struct child_process *cmd)
index 3653bfa6e123ca8497571a2ca1c47200c1b544a2..ea73de309bc65c3d00bb34ad84824ba72d85cbfe 100644 (file)
@@ -5,8 +5,11 @@
 #include <pthread.h>
 #endif
 
+#include "argv-array.h"
+
 struct child_process {
        const char **argv;
+       struct argv_array args;
        pid_t pid;
        /*
         * Using .in, .out, .err:
index bde5f047b01376e05255a55516d3bdd261f497ea..3c060e054720b7b17f9a868cabb1a0ef62aa1b50 100644 (file)
@@ -116,39 +116,23 @@ static const char *action_name(const struct replay_opts *opts)
        return opts->action == REPLAY_REVERT ? "revert" : "cherry-pick";
 }
 
-static char *get_encoding(const char *message);
-
 struct commit_message {
        char *parent_label;
        const char *label;
        const char *subject;
-       char *reencoded_message;
        const char *message;
 };
 
 static int get_message(struct commit *commit, struct commit_message *out)
 {
-       const char *encoding;
        const char *abbrev, *subject;
        int abbrev_len, subject_len;
        char *q;
 
-       if (!commit->buffer)
-               return -1;
-       encoding = get_encoding(commit->buffer);
-       if (!encoding)
-               encoding = "UTF-8";
        if (!git_commit_encoding)
                git_commit_encoding = "UTF-8";
 
-       out->reencoded_message = NULL;
-       out->message = commit->buffer;
-       if (same_encoding(encoding, git_commit_encoding))
-               out->reencoded_message = reencode_string(commit->buffer,
-                                       git_commit_encoding, encoding);
-       if (out->reencoded_message)
-               out->message = out->reencoded_message;
-
+       out->message = logmsg_reencode(commit, NULL, git_commit_encoding);
        abbrev = find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV);
        abbrev_len = strlen(abbrev);
 
@@ -167,29 +151,10 @@ static int get_message(struct commit *commit, struct commit_message *out)
        return 0;
 }
 
-static void free_message(struct commit_message *msg)
+static void free_message(struct commit *commit, struct commit_message *msg)
 {
        free(msg->parent_label);
-       free(msg->reencoded_message);
-}
-
-static char *get_encoding(const char *message)
-{
-       const char *p = message, *eol;
-
-       while (*p && *p != '\n') {
-               for (eol = p + 1; *eol && *eol != '\n'; eol++)
-                       ; /* do nothing */
-               if (starts_with(p, "encoding ")) {
-                       char *result = xmalloc(eol - 8 - p);
-                       strlcpy(result, p + 9, eol - 8 - p);
-                       return result;
-               }
-               p = eol;
-               if (*p == '\n')
-                       p++;
-       }
-       return NULL;
+       unuse_commit_buffer(commit, msg->message);
 }
 
 static void write_cherry_pick_head(struct commit *commit, const char *pseudoref)
@@ -278,11 +243,15 @@ static int fast_forward_to(const unsigned char *to, const unsigned char *from,
 
        read_cache();
        if (checkout_fast_forward(from, to, 1))
-               exit(1); /* the callee should have complained already */
+               exit(128); /* the callee should have complained already */
        ref_lock = lock_any_ref_for_update("HEAD", unborn ? null_sha1 : from,
                                           0, NULL);
+       if (!ref_lock)
+               return error(_("Failed to lock HEAD during fast_forward_to"));
+
        strbuf_addf(&sb, "%s: fast-forward", action_name(opts));
        ret = write_ref_sha1(ref_lock, to, sb.buf);
+
        strbuf_release(&sb);
        return ret;
 }
@@ -294,11 +263,11 @@ static int do_recursive_merge(struct commit *base, struct commit *next,
 {
        struct merge_options o;
        struct tree *result, *next_tree, *base_tree, *head_tree;
-       int clean, index_fd;
+       int clean;
        const char **xopt;
        static struct lock_file index_lock;
 
-       index_fd = hold_locked_index(&index_lock, 1);
+       hold_locked_index(&index_lock, 1);
 
        read_cache();
 
@@ -319,8 +288,7 @@ static int do_recursive_merge(struct commit *base, struct commit *next,
                            next_tree, base_tree, &result);
 
        if (active_cache_changed &&
-           (write_cache(index_fd, active_cache, active_nr) ||
-            commit_locked_index(&index_lock)))
+           write_locked_index(&the_index, &index_lock, COMMIT_LOCK))
                /* TRANSLATORS: %s will be "revert" or "cherry-pick" */
                die(_("%s: Unable to write new index file"), action_name(opts));
        rollback_lock_file(&index_lock);
@@ -372,9 +340,7 @@ static int is_index_unchanged(void)
                active_cache_tree = cache_tree();
 
        if (!cache_tree_fully_valid(active_cache_tree))
-               if (cache_tree_update(active_cache_tree,
-                                     (const struct cache_entry * const *)active_cache,
-                                     active_nr, 0))
+               if (cache_tree_update(&the_index, 0))
                        return error(_("Unable to update cache tree\n"));
 
        return !hashcmp(active_cache_tree->sha1, head_commit->tree->object.sha1);
@@ -392,18 +358,13 @@ static int run_git_commit(const char *defmsg, struct replay_opts *opts,
 {
        struct argv_array array;
        int rc;
-       char *gpg_sign;
 
        argv_array_init(&array);
        argv_array_push(&array, "commit");
        argv_array_push(&array, "-n");
 
-       if (opts->gpg_sign) {
-               gpg_sign = xmalloc(3 + strlen(opts->gpg_sign));
-               sprintf(gpg_sign, "-S%s", opts->gpg_sign);
-               argv_array_push(&array, gpg_sign);
-               free(gpg_sign);
-       }
+       if (opts->gpg_sign)
+               argv_array_pushf(&array, "-S%s", opts->gpg_sign);
        if (opts->signoff)
                argv_array_push(&array, "-s");
        if (!opts->edit) {
@@ -485,7 +446,7 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts)
        unsigned char head[20];
        struct commit *base, *next, *parent;
        const char *base_label, *next_label;
-       struct commit_message msg = { NULL, NULL, NULL, NULL, NULL };
+       struct commit_message msg = { NULL, NULL, NULL, NULL };
        char *defmsg = NULL;
        struct strbuf msgbuf = STRBUF_INIT;
        int res, unborn = 0, allow;
@@ -650,7 +611,7 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts)
                res = run_git_commit(defmsg, opts, allow);
 
 leave:
-       free_message(&msg);
+       free_message(commit, &msg);
        free(defmsg);
 
        return res;
@@ -679,9 +640,8 @@ static void read_and_refresh_cache(struct replay_opts *opts)
        if (read_index_preload(&the_index, NULL) < 0)
                die(_("git %s: failed to read the index"), action_name(opts));
        refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL, NULL);
-       if (the_index.cache_changed) {
-               if (write_index(&the_index, index_fd) ||
-                   commit_locked_index(&index_lock))
+       if (the_index.cache_changed && index_fd >= 0) {
+               if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK))
                        die(_("git %s: failed to refresh the index"), action_name(opts));
        }
        rollback_lock_file(&index_lock);
@@ -697,10 +657,12 @@ static int format_todo(struct strbuf *buf, struct commit_list *todo_list,
        int subject_len;
 
        for (cur = todo_list; cur; cur = cur->next) {
+               const char *commit_buffer = get_commit_buffer(cur->item, NULL);
                sha1_abbrev = find_unique_abbrev(cur->item->object.sha1, DEFAULT_ABBREV);
-               subject_len = find_commit_subject(cur->item->buffer, &subject);
+               subject_len = find_commit_subject(commit_buffer, &subject);
                strbuf_addf(buf, "%s %s %.*s\n", action_str, sha1_abbrev,
                        subject_len, subject);
+               unuse_commit_buffer(cur->item, commit_buffer);
        }
        return 0;
 }
index 34d527f6708fe242f75b7fa0fa98e36a5c96a3be..4127ae138de6bb002645aa83af00681b1805d982 100644 (file)
@@ -315,7 +315,8 @@ static int link_alt_odb_entry(const char *entry, const char *relative_base, int
         * thing twice, or object directory itself.
         */
        for (alt = alt_odb_list; alt; alt = alt->next) {
-               if (!memcmp(ent->base, alt->base, pfxlen)) {
+               if (pfxlen == alt->name - alt->base - 1 &&
+                   !memcmp(ent->base, alt->base, pfxlen)) {
                        free(ent);
                        return -1;
                }
@@ -1177,48 +1178,42 @@ static void report_pack_garbage(struct string_list *list)
 
 static void prepare_packed_git_one(char *objdir, int local)
 {
-       /* Ensure that this buffer is large enough so that we can
-          append "/pack/" without clobbering the stack even if
-          strlen(objdir) were PATH_MAX.  */
-       char path[PATH_MAX + 1 + 4 + 1 + 1];
-       int len;
+       struct strbuf path = STRBUF_INIT;
+       size_t dirnamelen;
        DIR *dir;
        struct dirent *de;
        struct string_list garbage = STRING_LIST_INIT_DUP;
 
-       sprintf(path, "%s/pack", objdir);
-       len = strlen(path);
-       dir = opendir(path);
+       strbuf_addstr(&path, objdir);
+       strbuf_addstr(&path, "/pack");
+       dir = opendir(path.buf);
        if (!dir) {
                if (errno != ENOENT)
                        error("unable to open object pack directory: %s: %s",
-                             path, strerror(errno));
+                             path.buf, strerror(errno));
+               strbuf_release(&path);
                return;
        }
-       path[len++] = '/';
+       strbuf_addch(&path, '/');
+       dirnamelen = path.len;
        while ((de = readdir(dir)) != NULL) {
-               int namelen = strlen(de->d_name);
                struct packed_git *p;
-
-               if (len + namelen + 1 > sizeof(path)) {
-                       if (report_garbage) {
-                               struct strbuf sb = STRBUF_INIT;
-                               strbuf_addf(&sb, "%.*s/%s", len - 1, path, de->d_name);
-                               report_garbage("path too long", sb.buf);
-                               strbuf_release(&sb);
-                       }
-                       continue;
-               }
+               size_t base_len;
 
                if (is_dot_or_dotdot(de->d_name))
                        continue;
 
-               strcpy(path + len, de->d_name);
+               strbuf_setlen(&path, dirnamelen);
+               strbuf_addstr(&path, de->d_name);
 
-               if (has_extension(de->d_name, ".idx")) {
+               base_len = path.len;
+               if (strip_suffix_mem(path.buf, &base_len, ".idx")) {
                        /* Don't reopen a pack we already have. */
                        for (p = packed_git; p; p = p->next) {
-                               if (!memcmp(path, p->pack_name, len + namelen - 4))
+                               size_t len;
+                               if (strip_suffix(p->pack_name, ".pack", &len) &&
+                                   len == base_len &&
+                                   !memcmp(p->pack_name, path.buf, len))
                                        break;
                        }
                        if (p == NULL &&
@@ -1226,24 +1221,25 @@ static void prepare_packed_git_one(char *objdir, int local)
                             * See if it really is a valid .idx file with
                             * corresponding .pack file that we can map.
                             */
-                           (p = add_packed_git(path, len + namelen, local)) != NULL)
+                           (p = add_packed_git(path.buf, path.len, local)) != NULL)
                                install_packed_git(p);
                }
 
                if (!report_garbage)
                        continue;
 
-               if (has_extension(de->d_name, ".idx") ||
-                   has_extension(de->d_name, ".pack") ||
-                   has_extension(de->d_name, ".bitmap") ||
-                   has_extension(de->d_name, ".keep"))
-                       string_list_append(&garbage, path);
+               if (ends_with(de->d_name, ".idx") ||
+                   ends_with(de->d_name, ".pack") ||
+                   ends_with(de->d_name, ".bitmap") ||
+                   ends_with(de->d_name, ".keep"))
+                       string_list_append(&garbage, path.buf);
                else
-                       report_garbage("garbage found", path);
+                       report_garbage("garbage found", path.buf);
        }
        closedir(dir);
        report_pack_garbage(&garbage);
        string_list_clear(&garbage, 0);
+       strbuf_release(&path);
 }
 
 static int sort_pack(const void *a_, const void *b_)
index 2b6322fad064845f4c782286fe9764f6b958f30d..5bfa8416999d35d6bb5c615d86763f013b7df748 100644 (file)
@@ -862,27 +862,17 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1,
                commit_list_insert(l->item, &backup);
        }
        while (list) {
-               char *p, *to_free = NULL;
+               const char *p, *buf;
                struct commit *commit;
-               enum object_type type;
-               unsigned long size;
                int matches;
 
                commit = pop_most_recent_commit(&list, ONELINE_SEEN);
                if (!parse_object(commit->object.sha1))
                        continue;
-               if (commit->buffer)
-                       p = commit->buffer;
-               else {
-                       p = read_sha1_file(commit->object.sha1, &type, &size);
-                       if (!p)
-                               continue;
-                       to_free = p;
-               }
-
-               p = strstr(p, "\n\n");
+               buf = get_commit_buffer(commit, NULL);
+               p = strstr(buf, "\n\n");
                matches = p && !regexec(&regex, p + 2, 0, NULL, 0);
-               free(to_free);
+               unuse_commit_buffer(commit, buf);
 
                if (matches) {
                        hashcpy(sha1, commit->object.sha1);
@@ -911,10 +901,8 @@ static int grab_nth_branch_switch(unsigned char *osha1, unsigned char *nsha1,
        const char *match = NULL, *target = NULL;
        size_t len;
 
-       if (starts_with(message, "checkout: moving from ")) {
-               match = message + strlen("checkout: moving from ");
+       if (skip_prefix(message, "checkout: moving from ", &match))
                target = strstr(match, " to ");
-       }
 
        if (!match || !target)
                return 0;
@@ -1252,10 +1240,7 @@ static void diagnose_invalid_sha1_path(const char *prefix,
                die("Path '%s' exists on disk, but not in '%.*s'.",
                    filename, object_name_len, object_name);
        if (errno == ENOENT || errno == ENOTDIR) {
-               char *fullname = xmalloc(strlen(filename)
-                                            + strlen(prefix) + 1);
-               strcpy(fullname, prefix);
-               strcat(fullname, filename);
+               char *fullname = xstrfmt("%s%s", prefix, filename);
 
                if (!get_tree_entry(tree_sha1, fullname,
                                    sha1, &mode)) {
diff --git a/shell.c b/shell.c
index 5c0d47a5cc1ae85a03e40321e97ddfa859ff7e1a..ace62e4b6503d821962242f9cf3bd9af22bc39b9 100644 (file)
--- a/shell.c
+++ b/shell.c
@@ -46,11 +46,7 @@ static int is_valid_cmd_name(const char *cmd)
 
 static char *make_cmd(const char *prog)
 {
-       char *prefix = xmalloc((strlen(prog) + strlen(COMMAND_DIR) + 2));
-       strcpy(prefix, COMMAND_DIR);
-       strcat(prefix, "/");
-       strcat(prefix, prog);
-       return prefix;
+       return xstrfmt("%s/%s", COMMAND_DIR, prog);
 }
 
 static void cd_to_homedir(void)
diff --git a/split-index.c b/split-index.c
new file mode 100644 (file)
index 0000000..21485e2
--- /dev/null
@@ -0,0 +1,328 @@
+#include "cache.h"
+#include "split-index.h"
+#include "ewah/ewok.h"
+
+struct split_index *init_split_index(struct index_state *istate)
+{
+       if (!istate->split_index) {
+               istate->split_index = xcalloc(1, sizeof(*istate->split_index));
+               istate->split_index->refcount = 1;
+       }
+       return istate->split_index;
+}
+
+int read_link_extension(struct index_state *istate,
+                        const void *data_, unsigned long sz)
+{
+       const unsigned char *data = data_;
+       struct split_index *si;
+       int ret;
+
+       if (sz < 20)
+               return error("corrupt link extension (too short)");
+       si = init_split_index(istate);
+       hashcpy(si->base_sha1, data);
+       data += 20;
+       sz -= 20;
+       if (!sz)
+               return 0;
+       si->delete_bitmap = ewah_new();
+       ret = ewah_read_mmap(si->delete_bitmap, data, sz);
+       if (ret < 0)
+               return error("corrupt delete bitmap in link extension");
+       data += ret;
+       sz -= ret;
+       si->replace_bitmap = ewah_new();
+       ret = ewah_read_mmap(si->replace_bitmap, data, sz);
+       if (ret < 0)
+               return error("corrupt replace bitmap in link extension");
+       if (ret != sz)
+               return error("garbage at the end of link extension");
+       return 0;
+}
+
+static int write_strbuf(void *user_data, const void *data, size_t len)
+{
+       struct strbuf *sb = user_data;
+       strbuf_add(sb, data, len);
+       return len;
+}
+
+int write_link_extension(struct strbuf *sb,
+                        struct index_state *istate)
+{
+       struct split_index *si = istate->split_index;
+       strbuf_add(sb, si->base_sha1, 20);
+       if (!si->delete_bitmap && !si->replace_bitmap)
+               return 0;
+       ewah_serialize_to(si->delete_bitmap, write_strbuf, sb);
+       ewah_serialize_to(si->replace_bitmap, write_strbuf, sb);
+       return 0;
+}
+
+static void mark_base_index_entries(struct index_state *base)
+{
+       int i;
+       /*
+        * To keep track of the shared entries between
+        * istate->base->cache[] and istate->cache[], base entry
+        * position is stored in each base entry. All positions start
+        * from 1 instead of 0, which is resrved to say "this is a new
+        * entry".
+        */
+       for (i = 0; i < base->cache_nr; i++)
+               base->cache[i]->index = i + 1;
+}
+
+void move_cache_to_base_index(struct index_state *istate)
+{
+       struct split_index *si = istate->split_index;
+       int i;
+
+       /*
+        * do not delete old si->base, its index entries may be shared
+        * with istate->cache[]. Accept a bit of leaking here because
+        * this code is only used by short-lived update-index.
+        */
+       si->base = xcalloc(1, sizeof(*si->base));
+       si->base->version = istate->version;
+       /* zero timestamp disables racy test in ce_write_index() */
+       si->base->timestamp = istate->timestamp;
+       ALLOC_GROW(si->base->cache, istate->cache_nr, si->base->cache_alloc);
+       si->base->cache_nr = istate->cache_nr;
+       memcpy(si->base->cache, istate->cache,
+              sizeof(*istate->cache) * istate->cache_nr);
+       mark_base_index_entries(si->base);
+       for (i = 0; i < si->base->cache_nr; i++)
+               si->base->cache[i]->ce_flags &= ~CE_UPDATE_IN_BASE;
+}
+
+static void mark_entry_for_delete(size_t pos, void *data)
+{
+       struct index_state *istate = data;
+       if (pos >= istate->cache_nr)
+               die("position for delete %d exceeds base index size %d",
+                   (int)pos, istate->cache_nr);
+       istate->cache[pos]->ce_flags |= CE_REMOVE;
+       istate->split_index->nr_deletions = 1;
+}
+
+static void replace_entry(size_t pos, void *data)
+{
+       struct index_state *istate = data;
+       struct split_index *si = istate->split_index;
+       struct cache_entry *dst, *src;
+
+       if (pos >= istate->cache_nr)
+               die("position for replacement %d exceeds base index size %d",
+                   (int)pos, istate->cache_nr);
+       if (si->nr_replacements >= si->saved_cache_nr)
+               die("too many replacements (%d vs %d)",
+                   si->nr_replacements, si->saved_cache_nr);
+       dst = istate->cache[pos];
+       if (dst->ce_flags & CE_REMOVE)
+               die("entry %d is marked as both replaced and deleted",
+                   (int)pos);
+       src = si->saved_cache[si->nr_replacements];
+       if (ce_namelen(src))
+               die("corrupt link extension, entry %d should have "
+                   "zero length name", (int)pos);
+       src->index = pos + 1;
+       src->ce_flags |= CE_UPDATE_IN_BASE;
+       src->ce_namelen = dst->ce_namelen;
+       copy_cache_entry(dst, src);
+       free(src);
+       si->nr_replacements++;
+}
+
+void merge_base_index(struct index_state *istate)
+{
+       struct split_index *si = istate->split_index;
+       unsigned int i;
+
+       mark_base_index_entries(si->base);
+
+       si->saved_cache     = istate->cache;
+       si->saved_cache_nr  = istate->cache_nr;
+       istate->cache_nr    = si->base->cache_nr;
+       istate->cache       = NULL;
+       istate->cache_alloc = 0;
+       ALLOC_GROW(istate->cache, istate->cache_nr, istate->cache_alloc);
+       memcpy(istate->cache, si->base->cache,
+              sizeof(*istate->cache) * istate->cache_nr);
+
+       si->nr_deletions = 0;
+       si->nr_replacements = 0;
+       ewah_each_bit(si->replace_bitmap, replace_entry, istate);
+       ewah_each_bit(si->delete_bitmap, mark_entry_for_delete, istate);
+       if (si->nr_deletions)
+               remove_marked_cache_entries(istate);
+
+       for (i = si->nr_replacements; i < si->saved_cache_nr; i++) {
+               if (!ce_namelen(si->saved_cache[i]))
+                       die("corrupt link extension, entry %d should "
+                           "have non-zero length name", i);
+               add_index_entry(istate, si->saved_cache[i],
+                               ADD_CACHE_OK_TO_ADD |
+                               ADD_CACHE_KEEP_CACHE_TREE |
+                               /*
+                                * we may have to replay what
+                                * merge-recursive.c:update_stages()
+                                * does, which has this flag on
+                                */
+                               ADD_CACHE_SKIP_DFCHECK);
+               si->saved_cache[i] = NULL;
+       }
+
+       ewah_free(si->delete_bitmap);
+       ewah_free(si->replace_bitmap);
+       free(si->saved_cache);
+       si->delete_bitmap  = NULL;
+       si->replace_bitmap = NULL;
+       si->saved_cache    = NULL;
+       si->saved_cache_nr = 0;
+}
+
+void prepare_to_write_split_index(struct index_state *istate)
+{
+       struct split_index *si = init_split_index(istate);
+       struct cache_entry **entries = NULL, *ce;
+       int i, nr_entries = 0, nr_alloc = 0;
+
+       si->delete_bitmap = ewah_new();
+       si->replace_bitmap = ewah_new();
+
+       if (si->base) {
+               /* Go through istate->cache[] and mark CE_MATCHED to
+                * entry with positive index. We'll go through
+                * base->cache[] later to delete all entries in base
+                * that are not marked eith either CE_MATCHED or
+                * CE_UPDATE_IN_BASE. If istate->cache[i] is a
+                * duplicate, deduplicate it.
+                */
+               for (i = 0; i < istate->cache_nr; i++) {
+                       struct cache_entry *base;
+                       /* namelen is checked separately */
+                       const unsigned int ondisk_flags =
+                               CE_STAGEMASK | CE_VALID | CE_EXTENDED_FLAGS;
+                       unsigned int ce_flags, base_flags, ret;
+                       ce = istate->cache[i];
+                       if (!ce->index)
+                               continue;
+                       if (ce->index > si->base->cache_nr) {
+                               ce->index = 0;
+                               continue;
+                       }
+                       ce->ce_flags |= CE_MATCHED; /* or "shared" */
+                       base = si->base->cache[ce->index - 1];
+                       if (ce == base)
+                               continue;
+                       if (ce->ce_namelen != base->ce_namelen ||
+                           strcmp(ce->name, base->name)) {
+                               ce->index = 0;
+                               continue;
+                       }
+                       ce_flags = ce->ce_flags;
+                       base_flags = base->ce_flags;
+                       /* only on-disk flags matter */
+                       ce->ce_flags   &= ondisk_flags;
+                       base->ce_flags &= ondisk_flags;
+                       ret = memcmp(&ce->ce_stat_data, &base->ce_stat_data,
+                                    offsetof(struct cache_entry, name) -
+                                    offsetof(struct cache_entry, ce_stat_data));
+                       ce->ce_flags = ce_flags;
+                       base->ce_flags = base_flags;
+                       if (ret)
+                               ce->ce_flags |= CE_UPDATE_IN_BASE;
+                       free(base);
+                       si->base->cache[ce->index - 1] = ce;
+               }
+               for (i = 0; i < si->base->cache_nr; i++) {
+                       ce = si->base->cache[i];
+                       if ((ce->ce_flags & CE_REMOVE) ||
+                           !(ce->ce_flags & CE_MATCHED))
+                               ewah_set(si->delete_bitmap, i);
+                       else if (ce->ce_flags & CE_UPDATE_IN_BASE) {
+                               ewah_set(si->replace_bitmap, i);
+                               ce->ce_flags |= CE_STRIP_NAME;
+                               ALLOC_GROW(entries, nr_entries+1, nr_alloc);
+                               entries[nr_entries++] = ce;
+                       }
+               }
+       }
+
+       for (i = 0; i < istate->cache_nr; i++) {
+               ce = istate->cache[i];
+               if ((!si->base || !ce->index) && !(ce->ce_flags & CE_REMOVE)) {
+                       assert(!(ce->ce_flags & CE_STRIP_NAME));
+                       ALLOC_GROW(entries, nr_entries+1, nr_alloc);
+                       entries[nr_entries++] = ce;
+               }
+               ce->ce_flags &= ~CE_MATCHED;
+       }
+
+       /*
+        * take cache[] out temporarily, put entries[] in its place
+        * for writing
+        */
+       si->saved_cache = istate->cache;
+       si->saved_cache_nr = istate->cache_nr;
+       istate->cache = entries;
+       istate->cache_nr = nr_entries;
+}
+
+void finish_writing_split_index(struct index_state *istate)
+{
+       struct split_index *si = init_split_index(istate);
+
+       ewah_free(si->delete_bitmap);
+       ewah_free(si->replace_bitmap);
+       si->delete_bitmap = NULL;
+       si->replace_bitmap = NULL;
+       free(istate->cache);
+       istate->cache = si->saved_cache;
+       istate->cache_nr = si->saved_cache_nr;
+}
+
+void discard_split_index(struct index_state *istate)
+{
+       struct split_index *si = istate->split_index;
+       if (!si)
+               return;
+       istate->split_index = NULL;
+       si->refcount--;
+       if (si->refcount)
+               return;
+       if (si->base) {
+               discard_index(si->base);
+               free(si->base);
+       }
+       free(si);
+}
+
+void save_or_free_index_entry(struct index_state *istate, struct cache_entry *ce)
+{
+       if (ce->index &&
+           istate->split_index &&
+           istate->split_index->base &&
+           ce->index <= istate->split_index->base->cache_nr &&
+           ce == istate->split_index->base->cache[ce->index - 1])
+               ce->ce_flags |= CE_REMOVE;
+       else
+               free(ce);
+}
+
+void replace_index_entry_in_base(struct index_state *istate,
+                                struct cache_entry *old,
+                                struct cache_entry *new)
+{
+       if (old->index &&
+           istate->split_index &&
+           istate->split_index->base &&
+           old->index <= istate->split_index->base->cache_nr) {
+               new->index = old->index;
+               if (old != istate->split_index->base->cache[new->index - 1])
+                       free(istate->split_index->base->cache[new->index - 1]);
+               istate->split_index->base->cache[new->index - 1] = new;
+       }
+}
diff --git a/split-index.h b/split-index.h
new file mode 100644 (file)
index 0000000..c1324f5
--- /dev/null
@@ -0,0 +1,35 @@
+#ifndef SPLIT_INDEX_H
+#define SPLIT_INDEX_H
+
+struct index_state;
+struct strbuf;
+struct ewah_bitmap;
+
+struct split_index {
+       unsigned char base_sha1[20];
+       struct index_state *base;
+       struct ewah_bitmap *delete_bitmap;
+       struct ewah_bitmap *replace_bitmap;
+       struct cache_entry **saved_cache;
+       unsigned int saved_cache_nr;
+       unsigned int nr_deletions;
+       unsigned int nr_replacements;
+       int refcount;
+};
+
+struct split_index *init_split_index(struct index_state *istate);
+void save_or_free_index_entry(struct index_state *istate, struct cache_entry *ce);
+void replace_index_entry_in_base(struct index_state *istate,
+                                struct cache_entry *old,
+                                struct cache_entry *new);
+int read_link_extension(struct index_state *istate,
+                       const void *data, unsigned long sz);
+int write_link_extension(struct strbuf *sb,
+                        struct index_state *istate);
+void move_cache_to_base_index(struct index_state *istate);
+void merge_base_index(struct index_state *istate);
+void prepare_to_write_split_index(struct index_state *istate);
+void finish_writing_split_index(struct index_state *istate);
+void discard_split_index(struct index_state *istate);
+
+#endif
index ee96dcfb816625436582833d812a7156513d5d39..33018d847f08424211c02cff8002680f5a2f02e9 100644 (file)
--- a/strbuf.c
+++ b/strbuf.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "refs.h"
+#include "utf8.h"
 
 int starts_with(const char *str, const char *prefix)
 {
@@ -10,15 +11,6 @@ int starts_with(const char *str, const char *prefix)
                        return 0;
 }
 
-int ends_with(const char *str, const char *suffix)
-{
-       int len = strlen(str), suflen = strlen(suffix);
-       if (len < suflen)
-               return 0;
-       else
-               return !strcmp(str + len - suflen, suffix);
-}
-
 /*
  * Used as the default ->buf value, so that people can always assume
  * buf is non NULL and ->buf is NUL terminated even for a freshly
@@ -78,15 +70,8 @@ void strbuf_grow(struct strbuf *sb, size_t extra)
 
 void strbuf_trim(struct strbuf *sb)
 {
-       char *b = sb->buf;
-       while (sb->len > 0 && isspace((unsigned char)sb->buf[sb->len - 1]))
-               sb->len--;
-       while (sb->len > 0 && isspace(*b)) {
-               b++;
-               sb->len--;
-       }
-       memmove(sb->buf, b, sb->len);
-       sb->buf[sb->len] = '\0';
+       strbuf_rtrim(sb);
+       strbuf_ltrim(sb);
 }
 void strbuf_rtrim(struct strbuf *sb)
 {
@@ -106,6 +91,29 @@ void strbuf_ltrim(struct strbuf *sb)
        sb->buf[sb->len] = '\0';
 }
 
+int strbuf_reencode(struct strbuf *sb, const char *from, const char *to)
+{
+       char *out;
+       int len;
+
+       if (same_encoding(from, to))
+               return 0;
+
+       out = reencode_string_len(sb->buf, sb->len, to, from, &len);
+       if (!out)
+               return -1;
+
+       strbuf_attach(sb, out, len, len);
+       return 0;
+}
+
+void strbuf_tolower(struct strbuf *sb)
+{
+       char *p = sb->buf, *end = sb->buf + sb->len;
+       for (; p < end; p++)
+               *p = tolower(*p);
+}
+
 struct strbuf **strbuf_split_buf(const char *str, size_t slen,
                                 int terminator, int max)
 {
@@ -570,3 +578,35 @@ int fprintf_ln(FILE *fp, const char *fmt, ...)
                return -1;
        return ret + 1;
 }
+
+char *xstrdup_tolower(const char *string)
+{
+       char *result;
+       size_t len, i;
+
+       len = strlen(string);
+       result = xmalloc(len + 1);
+       for (i = 0; i < len; i++)
+               result[i] = tolower(string[i]);
+       result[i] = '\0';
+       return result;
+}
+
+char *xstrvfmt(const char *fmt, va_list ap)
+{
+       struct strbuf buf = STRBUF_INIT;
+       strbuf_vaddf(&buf, fmt, ap);
+       return strbuf_detach(&buf, NULL);
+}
+
+char *xstrfmt(const char *fmt, ...)
+{
+       va_list ap;
+       char *ret;
+
+       va_start(ap, fmt);
+       ret = xstrvfmt(fmt, ap);
+       va_end(ap);
+
+       return ret;
+}
index 39c14cfa384c5154abd96899a7c02417295f8555..a7c0192e9ee392bd232b325692a9111b3e160e84 100644 (file)
--- a/strbuf.h
+++ b/strbuf.h
@@ -45,8 +45,19 @@ static inline void strbuf_setlen(struct strbuf *sb, size_t len)
 extern void strbuf_trim(struct strbuf *);
 extern void strbuf_rtrim(struct strbuf *);
 extern void strbuf_ltrim(struct strbuf *);
+extern int strbuf_reencode(struct strbuf *sb, const char *from, const char *to);
+extern void strbuf_tolower(struct strbuf *sb);
 extern int strbuf_cmp(const struct strbuf *, const struct strbuf *);
 
+static inline int strbuf_strip_suffix(struct strbuf *sb, const char *suffix)
+{
+       if (strip_suffix_mem(sb->buf, &sb->len, suffix)) {
+               strbuf_setlen(sb, sb->len);
+               return 1;
+       } else
+               return 0;
+}
+
 /*
  * Split str (of length slen) at the specified terminator character.
  * Return a null-terminated array of pointers to strbuf objects
@@ -183,4 +194,15 @@ extern int printf_ln(const char *fmt, ...);
 __attribute__((format (printf,2,3)))
 extern int fprintf_ln(FILE *fp, const char *fmt, ...);
 
+char *xstrdup_tolower(const char *);
+
+/*
+ * Create a newly allocated string using printf format. You can do this easily
+ * with a strbuf, but this provides a shortcut to save a few lines.
+ */
+__attribute__((format (printf, 1, 0)))
+char *xstrvfmt(const char *fmt, va_list ap);
+__attribute__((format (printf, 1, 2)))
+char *xstrfmt(const char *fmt, ...);
+
 #endif /* STRBUF_H */
index de6769c92dd109791c872b8d320c2caeee9f2b8d..dd5e2944658cce2428cef34a6f920d63a4bd3628 100644 (file)
@@ -15,8 +15,8 @@ struct string_list {
        compare_strings_fn cmp; /* NULL uses strcmp() */
 };
 
-#define STRING_LIST_INIT_NODUP { NULL, 0, 0, 0 }
-#define STRING_LIST_INIT_DUP   { NULL, 0, 0, 1 }
+#define STRING_LIST_INIT_NODUP { NULL, 0, 0, 0, NULL }
+#define STRING_LIST_INIT_DUP   { NULL, 0, 0, 1, NULL }
 
 void print_string_list(const struct string_list *p, const char *text);
 void string_list_clear(struct string_list *list, int free_util);
index b80ecacf60dc87025336b6b6d6a51acc9321f429..48e3b44e219dffec6f435f0f25f1b74409fa29a9 100644 (file)
@@ -965,7 +965,7 @@ static int find_first_merges(struct object_array *result, const char *path,
                        sha1_to_hex(a->object.sha1));
        init_revisions(&revs, NULL);
        rev_opts.submodule = path;
-       setup_revisions(sizeof(rev_args)/sizeof(char *)-1, rev_args, &revs, &rev_opts);
+       setup_revisions(ARRAY_SIZE(rev_args)-1, rev_args, &revs, &rev_opts);
 
        /* save all revisions from the above list that contain b */
        if (prepare_revision_walk(&revs))
index caeeb9dedc46940132dceb65f2ea976709945e2d..52c77ae936d9cb3ecc4ff42a2c4667fca4373577 100644 (file)
--- a/t/README
+++ b/t/README
@@ -71,6 +71,7 @@ You can pass --verbose (or -v), --debug (or -d), and --immediate
 (or -i) command line argument to the test, or by setting GIT_TEST_OPTS
 appropriately before running "make".
 
+-v::
 --verbose::
        This makes the test more verbose.  Specifically, the
        command being run and their output if any are also
@@ -81,6 +82,7 @@ appropriately before running "make".
        numbers matching <pattern>.  The number matched against is
        simply the running count of the test within the file.
 
+-d::
 --debug::
        This may help the person who is developing a new test.
        It causes the command defined with test_debug to run.
@@ -89,6 +91,7 @@ appropriately before running "make".
        failed tests so that you can inspect its contents after
        the test finished.
 
+-i::
 --immediate::
        This causes the test to immediately exit upon the first
        failed test. Cleanup commands requested with
@@ -96,10 +99,17 @@ appropriately before running "make".
        in order to keep the state for inspection by the tester
        to diagnose the bug.
 
+-l::
 --long-tests::
        This causes additional long-running tests to be run (where
        available), for more exhaustive testing.
 
+-r::
+--run=<test-selector>::
+       Run only the subset of tests indicated by
+       <test-selector>.  See section "Skipping Tests" below for
+       <test-selector> syntax.
+
 --valgrind=<tool>::
        Execute all Git binaries under valgrind tool <tool> and exit
        with status 126 on errors (just like regular tests, this will
@@ -187,10 +197,77 @@ and either can match the "t[0-9]{4}" part to skip the whole
 test, or t[0-9]{4} followed by ".$number" to say which
 particular test to skip.
 
-Note that some tests in the existing test suite rely on previous
-test item, so you cannot arbitrarily disable one and expect the
-remainder of test to check what the test originally was intended
-to check.
+For an individual test suite --run could be used to specify that
+only some tests should be run or that some tests should be
+excluded from a run.
+
+The argument for --run is a list of individual test numbers or
+ranges with an optional negation prefix that define what tests in
+a test suite to include in the run.  A range is two numbers
+separated with a dash and matches a range of tests with both ends
+been included.  You may omit the first or the second number to
+mean "from the first test" or "up to the very last test"
+respectively.
+
+Optional prefix of '!' means that the test or a range of tests
+should be excluded from the run.
+
+If --run starts with an unprefixed number or range the initial
+set of tests to run is empty. If the first item starts with '!'
+all the tests are added to the initial set.  After initial set is
+determined every test number or range is added or excluded from
+the set one by one, from left to right.
+
+Individual numbers or ranges could be separated either by a space
+or a comma.
+
+For example, to run only tests up to a specific test (21), one
+could do this:
+
+    $ sh ./t9200-git-cvsexport-commit.sh --run='1-21'
+
+or this:
+
+    $ sh ./t9200-git-cvsexport-commit.sh --run='-21'
+
+Common case is to run several setup tests (1, 2, 3) and then a
+specific test (21) that relies on that setup:
+
+    $ sh ./t9200-git-cvsexport-commit.sh --run='1 2 3 21'
+
+or:
+
+    $ sh ./t9200-git-cvsexport-commit.sh --run=1,2,3,21
+
+or:
+
+    $ sh ./t9200-git-cvsexport-commit.sh --run='-3 21'
+
+As noted above, the test set is built going though items left to
+right, so this:
+
+    $ sh ./t9200-git-cvsexport-commit.sh --run='1-4 !3'
+
+will run tests 1, 2, and 4.  Items that comes later have higher
+precendence.  It means that this:
+
+    $ sh ./t9200-git-cvsexport-commit.sh --run='!3 1-4'
+
+would just run tests from 1 to 4, including 3.
+
+You may use negation with ranges.  The following will run all
+test in the test suite except from 7 up to 11:
+
+    $ sh ./t9200-git-cvsexport-commit.sh --run='!7-11'
+
+Some tests in a test suite rely on the previous tests performing
+certain actions, specifically some tests are designated as
+"setup" test, so you cannot _arbitrarily_ disable one test and
+expect the rest to function correctly.
+
+--run is mostly useful when you want to focus on a specific test
+and know what setup is needed for it.  Or when you want to run
+everything up to a certain test.
 
 
 Naming Tests
@@ -596,6 +673,27 @@ library for your script to use.
                ...
        '
 
+ - test_write_lines <lines>
+
+   Write <lines> on standard output, one line per argument.
+   Useful to prepare multi-line files in a compact form.
+
+   Example:
+
+       test_write_lines a b c d e f g >foo
+
+   Is a more compact equivalent of:
+       cat >foo <<-EOF
+       a
+       b
+       c
+       d
+       e
+       f
+       g
+       EOF
+
+
  - test_pause
 
        This command is useful for writing and debugging tests and must be
index 45971f43b77142fe1bb90262974c83c786cfe43d..b170cbc0452ca1b5a624f5cf330d420c397cb760 100755 (executable)
@@ -16,12 +16,12 @@ sub err {
 
 while (<>) {
        chomp;
-       /^\s*sed\s+-i/ and err 'sed -i is not portable';
-       /^\s*echo\s+-n/ and err 'echo -n is not portable (please use printf)';
+       /\bsed\s+-i/ and err 'sed -i is not portable';
+       /\becho\s+-n/ and err 'echo -n is not portable (please use printf)';
        /^\s*declare\s+/ and err 'arrays/declare not portable';
        /^\s*[^#]\s*which\s/ and err 'which is not portable (please use type)';
-       /test\s+[^=]*==/ and err '"test a == b" is not portable (please use =)';
-       /^\s*export\s+[^=]*=/ and err '"export FOO=bar" is not portable (please use FOO=bar && export FOO)';
+       /\btest\s+[^=]*==/ and err '"test a == b" is not portable (please use =)';
+       /\bexport\s+[A-Za-z0-9_]*=/ and err '"export FOO=bar" is not portable (please use FOO=bar && export FOO)';
        # this resets our $. for each file
        close ARGV if eof;
 }
index 957ae936e8b785f8b1afbffd9a5918a3260d213f..9e7d7962b0678dceefb93e3706b742cbfdc5b45e 100755 (executable)
@@ -281,7 +281,7 @@ helper_test_timeout() {
 cat >askpass <<\EOF
 #!/bin/sh
 echo >&2 askpass: $*
-what=`echo $1 | cut -d" " -f1 | tr A-Z a-z | tr -cd a-z`
+what=$(echo $1 | cut -d" " -f1 | tr A-Z a-z | tr -cd a-z)
 echo "askpass-$what"
 EOF
 chmod +x askpass
index 5076718916388d6abf483220cd35f9f61394abc4..9b2bcfb1b0e38ec75e4d6d772e530a69eaaad874 100644 (file)
@@ -13,7 +13,7 @@ fi
 CVS="cvs -f"
 export CVS
 
-cvsps_version=`cvsps -h 2>&1 | sed -ne 's/cvsps version //p'`
+cvsps_version=$(cvsps -h 2>&1 | sed -ne 's/cvsps version //p')
 case "$cvsps_version" in
 2.1 | 2.2*)
        ;;
index 05824fa8e4d18252f74c51531d6504039986c078..fd499e7c498449834992e67645f098d49c6290b8 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-gpg_version=`gpg --version 2>&1`
+gpg_version=$(gpg --version 2>&1)
 if test $? = 127; then
        say "You do not seem to have gpg installed"
 else
index 252cbf163bcff90aabe39a48219e00565f577ffe..fd53b5718780e25f03924e38438706acc54598db 100644 (file)
@@ -37,6 +37,11 @@ then
        test_done
 fi
 
+if ! test_have_prereq SANITY; then
+       test_skip_or_die $GIT_TEST_HTTPD \
+               "Cannot run httpd tests as root"
+fi
+
 HTTPD_PARA=""
 
 for DEFAULT_HTTPD_PATH in '/usr/sbin/httpd' '/usr/sbin/apache2'
@@ -105,10 +110,15 @@ else
                "Could not identify web server at '$LIB_HTTPD_PATH'"
 fi
 
+install_script () {
+       write_script "$HTTPD_ROOT_PATH/$1" <"$TEST_PATH/$1"
+}
+
 prepare_httpd() {
        mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH"
        cp "$TEST_PATH"/passwd "$HTTPD_ROOT_PATH"
-       cp "$TEST_PATH"/broken-smart-http.sh "$HTTPD_ROOT_PATH"
+       install_script broken-smart-http.sh
+       install_script error.sh
 
        ln -s "$LIB_HTTPD_MODULE_PATH" "$HTTPD_ROOT_PATH/modules"
 
@@ -132,7 +142,7 @@ prepare_httpd() {
        HTTPD_URL_USER=$HTTPD_PROTO://user%40host@$HTTPD_DEST
        HTTPD_URL_USER_PASS=$HTTPD_PROTO://user%40host:pass%40host@$HTTPD_DEST
 
-       if test -n "$LIB_HTTPD_DAV" -o -n "$LIB_HTTPD_SVN"
+       if test -n "$LIB_HTTPD_DAV" || test -n "$LIB_HTTPD_SVN"
        then
                HTTPD_PARA="$HTTPD_PARA -DDAV"
 
index 3a03e8263db7e1c632bf0552ec94ae6834de4bf9..b384d7993545365c17f3c8bded756b4e74faf794 100644 (file)
@@ -97,12 +97,16 @@ Alias /auth/dumb/ www/auth/dumb/
 </LocationMatch>
 ScriptAliasMatch /smart_*[^/]*/(.*) ${GIT_EXEC_PATH}/git-http-backend/$1
 ScriptAlias /broken_smart/ broken-smart-http.sh/
+ScriptAlias /error/ error.sh/
 <Directory ${GIT_EXEC_PATH}>
        Options FollowSymlinks
 </Directory>
 <Files broken-smart-http.sh>
        Options ExecCGI
 </Files>
+<Files error.sh>
+  Options ExecCGI
+</Files>
 <Files ${GIT_EXEC_PATH}/git-http-backend>
        Options ExecCGI
 </Files>
old mode 100755 (executable)
new mode 100644 (file)
index f7ebfff..82cc610
@@ -1,4 +1,3 @@
-#!/bin/sh
 printf "Content-Type: text/%s\n" "html"
 echo
 printf "%s\n" "001e# service=git-upload-pack"
diff --git a/t/lib-httpd/error.sh b/t/lib-httpd/error.sh
new file mode 100755 (executable)
index 0000000..a77b8e5
--- /dev/null
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+printf "Status: 500 Intentional Breakage\n"
+
+printf "Content-Type: "
+charset=iso-8859-1
+case "$PATH_INFO" in
+*html*)
+       printf "text/html"
+       ;;
+*text*)
+       printf "text/plain"
+       ;;
+*charset*)
+       printf "text/plain; charset=utf-8"
+       charset=utf-8
+       ;;
+*utf16*)
+       printf "text/plain; charset=utf-16"
+       charset=utf-16
+       ;;
+*odd-spacing*)
+       printf "text/plain; foo=bar ;charset=utf-16; other=nonsense"
+       charset=utf-16
+       ;;
+esac
+printf "\n"
+
+printf "\n"
+printf "this is the error message\n" |
+iconv -f us-ascii -t $charset
index 6cb5b0d55b6d6ed4a91f6d0674c210d98b962b66..5ee9211f988dce1f334d796623feccda85641bbe 100755 (executable)
@@ -8,7 +8,7 @@ test_perf_large_repo
 
 test_expect_success 'repack' '
        git repack -ad &&
-       PACK=`ls .git/objects/pack/*.pack | head -n1` &&
+       PACK=$(ls .git/objects/pack/*.pack | head -n1) &&
        test -f "$PACK" &&
        export PACK
 '
index 685d46f8b75ae105d41e1b462c69f980fe1f61a8..f8ed8573b728e82f7f4afaee677758b736048ebe 100755 (executable)
@@ -8,6 +8,9 @@ test_perf_large_repo
 # note that we do everything through config,
 # since we want to be able to compare bitmap-aware
 # git versus non-bitmap git
+#
+# We intentionally use the deprecated pack.writebitmaps
+# config so that we can test against older versions of git.
 test_expect_success 'setup bitmap config' '
        git config pack.writebitmaps true &&
        git config pack.writebitmaphashcache true
index a2bb63ce8e5e5586691affb51f9cff1f4d1e327a..f10ba4a01e7e9468b9656ee54486209151ecfd4f 100755 (executable)
@@ -42,9 +42,9 @@ test_expect_success 'success is reported like this' '
        :
 '
 
-run_sub_test_lib_test () {
-       name="$1" descr="$2" # stdin is the body of the test code
-       shift 2
+_run_sub_test_lib_test_common () {
+       neg="$1" name="$2" descr="$3" # stdin is the body of the test code
+       shift 3
        mkdir "$name" &&
        (
                # Pretend we're not running under a test harness, whether we
@@ -70,10 +70,23 @@ run_sub_test_lib_test () {
                export TEST_DIRECTORY &&
                TEST_OUTPUT_DIRECTORY=$(pwd) &&
                export TEST_OUTPUT_DIRECTORY &&
-               ./"$name.sh" "$@" >out 2>err
+               if test -z "$neg"
+               then
+                       ./"$name.sh" "$@" >out 2>err
+               else
+                       !  ./"$name.sh" "$@" >out 2>err
+               fi
        )
 }
 
+run_sub_test_lib_test () {
+       _run_sub_test_lib_test_common '' "$@"
+}
+
+run_sub_test_lib_test_err () {
+       _run_sub_test_lib_test_common '!' "$@"
+}
+
 check_sub_test_lib_test () {
        name="$1" # stdin is the expected output from the test
        (
@@ -84,6 +97,18 @@ check_sub_test_lib_test () {
        )
 }
 
+check_sub_test_lib_test_err () {
+       name="$1" # stdin is the expected output output from the test
+       # expected error output is in descriptior 3
+       (
+               cd "$name" &&
+               sed -e 's/^> //' -e 's/Z$//' >expect.out &&
+               test_cmp expect.out out &&
+               sed -e 's/^> //' -e 's/Z$//' <&3 >expect.err &&
+               test_cmp expect.err err
+       )
+}
+
 test_expect_success 'pretend we have a fully passing test suite' "
        run_sub_test_lib_test full-pass '3 passing tests' <<-\\EOF &&
        for i in 1 2 3
@@ -270,6 +295,398 @@ test_expect_success 'test --verbose-only' '
        EOF
 '
 
+test_expect_success 'GIT_SKIP_TESTS' "
+       (
+               GIT_SKIP_TESTS='git.2' && export GIT_SKIP_TESTS &&
+               run_sub_test_lib_test git-skip-tests-basic \
+                       'GIT_SKIP_TESTS' <<-\\EOF &&
+               for i in 1 2 3
+               do
+                       test_expect_success \"passing test #\$i\" 'true'
+               done
+               test_done
+               EOF
+               check_sub_test_lib_test git-skip-tests-basic <<-\\EOF
+               > ok 1 - passing test #1
+               > ok 2 # skip passing test #2 (GIT_SKIP_TESTS)
+               > ok 3 - passing test #3
+               > # passed all 3 test(s)
+               > 1..3
+               EOF
+       )
+"
+
+test_expect_success 'GIT_SKIP_TESTS several tests' "
+       (
+               GIT_SKIP_TESTS='git.2 git.5' && export GIT_SKIP_TESTS &&
+               run_sub_test_lib_test git-skip-tests-several \
+                       'GIT_SKIP_TESTS several tests' <<-\\EOF &&
+               for i in 1 2 3 4 5 6
+               do
+                       test_expect_success \"passing test #\$i\" 'true'
+               done
+               test_done
+               EOF
+               check_sub_test_lib_test git-skip-tests-several <<-\\EOF
+               > ok 1 - passing test #1
+               > ok 2 # skip passing test #2 (GIT_SKIP_TESTS)
+               > ok 3 - passing test #3
+               > ok 4 - passing test #4
+               > ok 5 # skip passing test #5 (GIT_SKIP_TESTS)
+               > ok 6 - passing test #6
+               > # passed all 6 test(s)
+               > 1..6
+               EOF
+       )
+"
+
+test_expect_success 'GIT_SKIP_TESTS sh pattern' "
+       (
+               GIT_SKIP_TESTS='git.[2-5]' && export GIT_SKIP_TESTS &&
+               run_sub_test_lib_test git-skip-tests-sh-pattern \
+                       'GIT_SKIP_TESTS sh pattern' <<-\\EOF &&
+               for i in 1 2 3 4 5 6
+               do
+                       test_expect_success \"passing test #\$i\" 'true'
+               done
+               test_done
+               EOF
+               check_sub_test_lib_test git-skip-tests-sh-pattern <<-\\EOF
+               > ok 1 - passing test #1
+               > ok 2 # skip passing test #2 (GIT_SKIP_TESTS)
+               > ok 3 # skip passing test #3 (GIT_SKIP_TESTS)
+               > ok 4 # skip passing test #4 (GIT_SKIP_TESTS)
+               > ok 5 # skip passing test #5 (GIT_SKIP_TESTS)
+               > ok 6 - passing test #6
+               > # passed all 6 test(s)
+               > 1..6
+               EOF
+       )
+"
+
+test_expect_success '--run basic' "
+       run_sub_test_lib_test run-basic \
+               '--run basic' --run='1 3 5' <<-\\EOF &&
+       for i in 1 2 3 4 5 6
+       do
+               test_expect_success \"passing test #\$i\" 'true'
+       done
+       test_done
+       EOF
+       check_sub_test_lib_test run-basic <<-\\EOF
+       > ok 1 - passing test #1
+       > ok 2 # skip passing test #2 (--run)
+       > ok 3 - passing test #3
+       > ok 4 # skip passing test #4 (--run)
+       > ok 5 - passing test #5
+       > ok 6 # skip passing test #6 (--run)
+       > # passed all 6 test(s)
+       > 1..6
+       EOF
+"
+
+test_expect_success '--run with a range' "
+       run_sub_test_lib_test run-range \
+               '--run with a range' --run='1-3' <<-\\EOF &&
+       for i in 1 2 3 4 5 6
+       do
+               test_expect_success \"passing test #\$i\" 'true'
+       done
+       test_done
+       EOF
+       check_sub_test_lib_test run-range <<-\\EOF
+       > ok 1 - passing test #1
+       > ok 2 - passing test #2
+       > ok 3 - passing test #3
+       > ok 4 # skip passing test #4 (--run)
+       > ok 5 # skip passing test #5 (--run)
+       > ok 6 # skip passing test #6 (--run)
+       > # passed all 6 test(s)
+       > 1..6
+       EOF
+"
+
+test_expect_success '--run with two ranges' "
+       run_sub_test_lib_test run-two-ranges \
+               '--run with two ranges' --run='1-2 5-6' <<-\\EOF &&
+       for i in 1 2 3 4 5 6
+       do
+               test_expect_success \"passing test #\$i\" 'true'
+       done
+       test_done
+       EOF
+       check_sub_test_lib_test run-two-ranges <<-\\EOF
+       > ok 1 - passing test #1
+       > ok 2 - passing test #2
+       > ok 3 # skip passing test #3 (--run)
+       > ok 4 # skip passing test #4 (--run)
+       > ok 5 - passing test #5
+       > ok 6 - passing test #6
+       > # passed all 6 test(s)
+       > 1..6
+       EOF
+"
+
+test_expect_success '--run with a left open range' "
+       run_sub_test_lib_test run-left-open-range \
+               '--run with a left open range' --run='-3' <<-\\EOF &&
+       for i in 1 2 3 4 5 6
+       do
+               test_expect_success \"passing test #\$i\" 'true'
+       done
+       test_done
+       EOF
+       check_sub_test_lib_test run-left-open-range <<-\\EOF
+       > ok 1 - passing test #1
+       > ok 2 - passing test #2
+       > ok 3 - passing test #3
+       > ok 4 # skip passing test #4 (--run)
+       > ok 5 # skip passing test #5 (--run)
+       > ok 6 # skip passing test #6 (--run)
+       > # passed all 6 test(s)
+       > 1..6
+       EOF
+"
+
+test_expect_success '--run with a right open range' "
+       run_sub_test_lib_test run-right-open-range \
+               '--run with a right open range' --run='4-' <<-\\EOF &&
+       for i in 1 2 3 4 5 6
+       do
+               test_expect_success \"passing test #\$i\" 'true'
+       done
+       test_done
+       EOF
+       check_sub_test_lib_test run-right-open-range <<-\\EOF
+       > ok 1 # skip passing test #1 (--run)
+       > ok 2 # skip passing test #2 (--run)
+       > ok 3 # skip passing test #3 (--run)
+       > ok 4 - passing test #4
+       > ok 5 - passing test #5
+       > ok 6 - passing test #6
+       > # passed all 6 test(s)
+       > 1..6
+       EOF
+"
+
+test_expect_success '--run with basic negation' "
+       run_sub_test_lib_test run-basic-neg \
+               '--run with basic negation' --run='"'!3'"' <<-\\EOF &&
+       for i in 1 2 3 4 5 6
+       do
+               test_expect_success \"passing test #\$i\" 'true'
+       done
+       test_done
+       EOF
+       check_sub_test_lib_test run-basic-neg <<-\\EOF
+       > ok 1 - passing test #1
+       > ok 2 - passing test #2
+       > ok 3 # skip passing test #3 (--run)
+       > ok 4 - passing test #4
+       > ok 5 - passing test #5
+       > ok 6 - passing test #6
+       > # passed all 6 test(s)
+       > 1..6
+       EOF
+"
+
+test_expect_success '--run with two negations' "
+       run_sub_test_lib_test run-two-neg \
+               '--run with two negations' --run='"'!3 !6'"' <<-\\EOF &&
+       for i in 1 2 3 4 5 6
+       do
+               test_expect_success \"passing test #\$i\" 'true'
+       done
+       test_done
+       EOF
+       check_sub_test_lib_test run-two-neg <<-\\EOF
+       > ok 1 - passing test #1
+       > ok 2 - passing test #2
+       > ok 3 # skip passing test #3 (--run)
+       > ok 4 - passing test #4
+       > ok 5 - passing test #5
+       > ok 6 # skip passing test #6 (--run)
+       > # passed all 6 test(s)
+       > 1..6
+       EOF
+"
+
+test_expect_success '--run a range and negation' "
+       run_sub_test_lib_test run-range-and-neg \
+               '--run a range and negation' --run='"'-4 !2'"' <<-\\EOF &&
+       for i in 1 2 3 4 5 6
+       do
+               test_expect_success \"passing test #\$i\" 'true'
+       done
+       test_done
+       EOF
+       check_sub_test_lib_test run-range-and-neg <<-\\EOF
+       > ok 1 - passing test #1
+       > ok 2 # skip passing test #2 (--run)
+       > ok 3 - passing test #3
+       > ok 4 - passing test #4
+       > ok 5 # skip passing test #5 (--run)
+       > ok 6 # skip passing test #6 (--run)
+       > # passed all 6 test(s)
+       > 1..6
+       EOF
+"
+
+test_expect_success '--run range negation' "
+       run_sub_test_lib_test run-range-neg \
+               '--run range negation' --run='"'!1-3'"' <<-\\EOF &&
+       for i in 1 2 3 4 5 6
+       do
+               test_expect_success \"passing test #\$i\" 'true'
+       done
+       test_done
+       EOF
+       check_sub_test_lib_test run-range-neg <<-\\EOF
+       > ok 1 # skip passing test #1 (--run)
+       > ok 2 # skip passing test #2 (--run)
+       > ok 3 # skip passing test #3 (--run)
+       > ok 4 - passing test #4
+       > ok 5 - passing test #5
+       > ok 6 - passing test #6
+       > # passed all 6 test(s)
+       > 1..6
+       EOF
+"
+
+test_expect_success '--run include, exclude and include' "
+       run_sub_test_lib_test run-inc-neg-inc \
+               '--run include, exclude and include' \
+               --run='"'1-5 !1-3 2'"' <<-\\EOF &&
+       for i in 1 2 3 4 5 6
+       do
+               test_expect_success \"passing test #\$i\" 'true'
+       done
+       test_done
+       EOF
+       check_sub_test_lib_test run-inc-neg-inc <<-\\EOF
+       > ok 1 # skip passing test #1 (--run)
+       > ok 2 - passing test #2
+       > ok 3 # skip passing test #3 (--run)
+       > ok 4 - passing test #4
+       > ok 5 - passing test #5
+       > ok 6 # skip passing test #6 (--run)
+       > # passed all 6 test(s)
+       > 1..6
+       EOF
+"
+
+test_expect_success '--run include, exclude and include, comma separated' "
+       run_sub_test_lib_test run-inc-neg-inc-comma \
+               '--run include, exclude and include, comma separated' \
+               --run=1-5,\!1-3,2 <<-\\EOF &&
+       for i in 1 2 3 4 5 6
+       do
+               test_expect_success \"passing test #\$i\" 'true'
+       done
+       test_done
+       EOF
+       check_sub_test_lib_test run-inc-neg-inc-comma <<-\\EOF
+       > ok 1 # skip passing test #1 (--run)
+       > ok 2 - passing test #2
+       > ok 3 # skip passing test #3 (--run)
+       > ok 4 - passing test #4
+       > ok 5 - passing test #5
+       > ok 6 # skip passing test #6 (--run)
+       > # passed all 6 test(s)
+       > 1..6
+       EOF
+"
+
+test_expect_success '--run exclude and include' "
+       run_sub_test_lib_test run-neg-inc \
+               '--run exclude and include' \
+               --run='"'!3- 5'"' <<-\\EOF &&
+       for i in 1 2 3 4 5 6
+       do
+               test_expect_success \"passing test #\$i\" 'true'
+       done
+       test_done
+       EOF
+       check_sub_test_lib_test run-neg-inc <<-\\EOF
+       > ok 1 - passing test #1
+       > ok 2 - passing test #2
+       > ok 3 # skip passing test #3 (--run)
+       > ok 4 # skip passing test #4 (--run)
+       > ok 5 - passing test #5
+       > ok 6 # skip passing test #6 (--run)
+       > # passed all 6 test(s)
+       > 1..6
+       EOF
+"
+
+test_expect_success '--run empty selectors' "
+       run_sub_test_lib_test run-empty-sel \
+               '--run empty selectors' \
+               --run='1,,3,,,5' <<-\\EOF &&
+       for i in 1 2 3 4 5 6
+       do
+               test_expect_success \"passing test #\$i\" 'true'
+       done
+       test_done
+       EOF
+       check_sub_test_lib_test run-empty-sel <<-\\EOF
+       > ok 1 - passing test #1
+       > ok 2 # skip passing test #2 (--run)
+       > ok 3 - passing test #3
+       > ok 4 # skip passing test #4 (--run)
+       > ok 5 - passing test #5
+       > ok 6 # skip passing test #6 (--run)
+       > # passed all 6 test(s)
+       > 1..6
+       EOF
+"
+
+test_expect_success '--run invalid range start' "
+       run_sub_test_lib_test_err run-inv-range-start \
+               '--run invalid range start' \
+               --run='a-5' <<-\\EOF &&
+       test_expect_success \"passing test #1\" 'true'
+       test_done
+       EOF
+       check_sub_test_lib_test_err run-inv-range-start \
+               <<-\\EOF_OUT 3<<-\\EOF_ERR
+       > FATAL: Unexpected exit with code 1
+       EOF_OUT
+       > error: --run: invalid non-numeric in range start: 'a-5'
+       EOF_ERR
+"
+
+test_expect_success '--run invalid range end' "
+       run_sub_test_lib_test_err run-inv-range-end \
+               '--run invalid range end' \
+               --run='1-z' <<-\\EOF &&
+       test_expect_success \"passing test #1\" 'true'
+       test_done
+       EOF
+       check_sub_test_lib_test_err run-inv-range-end \
+               <<-\\EOF_OUT 3<<-\\EOF_ERR
+       > FATAL: Unexpected exit with code 1
+       EOF_OUT
+       > error: --run: invalid non-numeric in range end: '1-z'
+       EOF_ERR
+"
+
+test_expect_success '--run invalid selector' "
+       run_sub_test_lib_test_err run-inv-selector \
+               '--run invalid selector' \
+               --run='1?' <<-\\EOF &&
+       test_expect_success \"passing test #1\" 'true'
+       test_done
+       EOF
+       check_sub_test_lib_test_err run-inv-selector \
+               <<-\\EOF_OUT 3<<-\\EOF_ERR
+       > FATAL: Unexpected exit with code 1
+       EOF_OUT
+       > error: --run: invalid non-numeric in test selector: '1?'
+       EOF_ERR
+"
+
+
 test_set_prereq HAVEIT
 haveit=no
 test_expect_success HAVEIT 'test runs if prerequisite is satisfied' '
index bbc9cb60ddea49f1ce3f0b0d124f704c30a61346..e62c0ffbc22cffffd9c29254a96222bfb5b85633 100755 (executable)
@@ -56,7 +56,7 @@ test_expect_success 'plain through aliased command, outside any git repo' '
        check_config plain-aliased/.git false unset
 '
 
-test_expect_failure 'plain nested through aliased command' '
+test_expect_success 'plain nested through aliased command' '
        (
                git init plain-ancestor-aliased &&
                cd plain-ancestor-aliased &&
@@ -68,7 +68,7 @@ test_expect_failure 'plain nested through aliased command' '
        check_config plain-ancestor-aliased/plain-nested/.git false unset
 '
 
-test_expect_failure 'plain nested in bare through aliased command' '
+test_expect_success 'plain nested in bare through aliased command' '
        (
                git init --bare bare-ancestor-aliased.git &&
                cd bare-ancestor-aliased.git &&
@@ -185,14 +185,14 @@ test_expect_success 'init --bare/--shared overrides system/global config' '
        git init --bare --shared=0666 init-bare-shared-override &&
        check_config init-bare-shared-override true unset &&
        test x0666 = \
-       x`git config -f init-bare-shared-override/config core.sharedRepository`
+       x$(git config -f init-bare-shared-override/config core.sharedRepository)
 '
 
 test_expect_success 'init honors global core.sharedRepository' '
        test_config_global core.sharedRepository 0666 &&
        git init shared-honor-global &&
        test x0666 = \
-       x`git config -f shared-honor-global/.git/config core.sharedRepository`
+       x$(git config -f shared-honor-global/.git/config core.sharedRepository)
 '
 
 test_expect_success 'init rejects insanely long --template' '
@@ -285,7 +285,7 @@ test_expect_success 'init prefers command line to GIT_DIR' '
 test_expect_success 'init with separate gitdir' '
        rm -rf newdir &&
        git init --separate-git-dir realgitdir newdir &&
-       echo "gitdir: `pwd`/realgitdir" >expected &&
+       echo "gitdir: $(pwd)/realgitdir" >expected &&
        test_cmp expected newdir/.git &&
        test_path_is_dir realgitdir/refs
 '
@@ -299,7 +299,7 @@ test_expect_success 're-init to update git link' '
        cd newdir &&
        git init --separate-git-dir ../surrealgitdir
        ) &&
-       echo "gitdir: `pwd`/surrealgitdir" >expected &&
+       echo "gitdir: $(pwd)/surrealgitdir" >expected &&
        test_cmp expected newdir/.git &&
        test_path_is_dir surrealgitdir/refs &&
        test_path_is_missing realgitdir/refs
@@ -312,7 +312,7 @@ test_expect_success 're-init to move gitdir' '
        cd newdir &&
        git init --separate-git-dir ../realgitdir
        ) &&
-       echo "gitdir: `pwd`/realgitdir" >expected &&
+       echo "gitdir: $(pwd)/realgitdir" >expected &&
        test_cmp expected newdir/.git &&
        test_path_is_dir realgitdir/refs
 '
@@ -326,7 +326,7 @@ test_expect_success SYMLINKS 're-init to move gitdir symlink' '
        ln -s here .git &&
        git init --separate-git-dir ../realgitdir
        ) &&
-       echo "gitdir: `pwd`/realgitdir" >expected &&
+       echo "gitdir: $(pwd)/realgitdir" >expected &&
        test_cmp expected newdir/.git &&
        test_cmp expected newdir/here &&
        test_path_is_dir realgitdir/refs
index 63beb99828cc17d2ec8218a6470b62c02a78806b..39e55a13c885399150094f9a2774f85e0acd63a6 100755 (executable)
@@ -806,4 +806,29 @@ test_expect_success !MINGW 'quoting allows trailing whitespace' '
        test_cmp err.expect err
 '
 
+test_expect_success NOT_MINGW,NOT_CYGWIN 'correct handling of backslashes' '
+       rm -rf whitespace &&
+       mkdir whitespace &&
+       >"whitespace/trailing 1  " &&
+       >"whitespace/trailing 2 \\\\" &&
+       >"whitespace/trailing 3 \\\\" &&
+       >"whitespace/trailing 4   \\ " &&
+       >"whitespace/trailing 5 \\ \\ " &&
+       >"whitespace/trailing 6 \\a\\" &&
+       >whitespace/untracked &&
+       sed -e "s/Z$//" >ignore <<-\EOF &&
+       whitespace/trailing 1 \    Z
+       whitespace/trailing 2 \\\\Z
+       whitespace/trailing 3 \\\\ Z
+       whitespace/trailing 4   \\\    Z
+       whitespace/trailing 5 \\ \\\   Z
+       whitespace/trailing 6 \\a\\Z
+       EOF
+       echo whitespace/untracked >expect &&
+       >err.expect &&
+       git ls-files -o -X ignore whitespace >actual 2>err &&
+       test_cmp expect actual &&
+       test_cmp err.expect err
+'
+
 test_done
index e45a9e40e432524454e94a041599b201a092879a..5657c5a87b6e253b8c8ca7d18dfa7535c295dc83 100755 (executable)
@@ -14,7 +14,7 @@ do
        git update-index --add infocom
        echo xyzzy >infocom
 
-       files=`git diff-files -p`
+       files=$(git diff-files -p)
        test_expect_success \
        "Racy GIT trial #$trial part A" \
        'test "" != "$files"'
@@ -23,7 +23,7 @@ do
        echo xyzzy >cornerstone
        git update-index --add cornerstone
 
-       files=`git diff-files -p`
+       files=$(git diff-files -p)
        test_expect_success \
        "Racy GIT trial #$trial part B" \
        'test "" != "$files"'
index e526184a0bfa3c8ad2171d0c41a7bee22cf9a04e..d2e51a81bc0897b19f8f087894187ed705ce29e3 100755 (executable)
@@ -20,14 +20,14 @@ test_expect_success setup '
 
        git commit -m initial &&
 
-       one=`git rev-parse HEAD:one` &&
-       dir=`git rev-parse HEAD:dir` &&
-       two=`git rev-parse HEAD:dir/two` &&
-       three=`git rev-parse HEAD:three` &&
+       one=$(git rev-parse HEAD:one) &&
+       dir=$(git rev-parse HEAD:dir) &&
+       two=$(git rev-parse HEAD:dir/two) &&
+       three=$(git rev-parse HEAD:three) &&
 
        for w in Some extra lines here; do echo $w; done >>one &&
        git diff >patch.file &&
-       patched=`git hash-object --stdin <one` &&
+       patched=$(git hash-object --stdin <one) &&
        git read-tree --reset -u HEAD &&
 
        echo happy.
@@ -111,7 +111,7 @@ test_expect_success 'update with autocrlf=input' '
                }
        done &&
 
-       differs=`git diff-index --cached HEAD` &&
+       differs=$(git diff-index --cached HEAD) &&
        test -z "$differs" || {
                echo Oops "$differs"
                false
@@ -135,7 +135,7 @@ test_expect_success 'update with autocrlf=true' '
                }
        done &&
 
-       differs=`git diff-index --cached HEAD` &&
+       differs=$(git diff-index --cached HEAD) &&
        test -z "$differs" || {
                echo Oops "$differs"
                false
@@ -158,9 +158,9 @@ test_expect_success 'checkout with autocrlf=true' '
                        break
                }
        done &&
-       test "$one" = `git hash-object --stdin <one` &&
-       test "$two" = `git hash-object --stdin <dir/two` &&
-       differs=`git diff-index --cached HEAD` &&
+       test "$one" = $(git hash-object --stdin <one) &&
+       test "$two" = $(git hash-object --stdin <dir/two) &&
+       differs=$(git diff-index --cached HEAD) &&
        test -z "$differs" || {
                echo Oops "$differs"
                false
@@ -184,9 +184,9 @@ test_expect_success 'checkout with autocrlf=input' '
                        git update-index -- $f
                fi
        done &&
-       test "$one" = `git hash-object --stdin <one` &&
-       test "$two" = `git hash-object --stdin <dir/two` &&
-       differs=`git diff-index --cached HEAD` &&
+       test "$one" = $(git hash-object --stdin <one) &&
+       test "$two" = $(git hash-object --stdin <dir/two) &&
+       differs=$(git diff-index --cached HEAD) &&
        test -z "$differs" || {
                echo Oops "$differs"
                false
@@ -200,7 +200,7 @@ test_expect_success 'apply patch (autocrlf=input)' '
        git read-tree --reset -u HEAD &&
 
        git apply patch.file &&
-       test "$patched" = "`git hash-object --stdin <one`" || {
+       test "$patched" = "$(git hash-object --stdin <one)" || {
                echo "Eh?  apply without index"
                false
        }
@@ -213,7 +213,7 @@ test_expect_success 'apply patch --cached (autocrlf=input)' '
        git read-tree --reset -u HEAD &&
 
        git apply --cached patch.file &&
-       test "$patched" = `git rev-parse :one` || {
+       test "$patched" = $(git rev-parse :one) || {
                echo "Eh?  apply with --cached"
                false
        }
@@ -226,8 +226,8 @@ test_expect_success 'apply patch --index (autocrlf=input)' '
        git read-tree --reset -u HEAD &&
 
        git apply --index patch.file &&
-       test "$patched" = `git rev-parse :one` &&
-       test "$patched" = `git hash-object --stdin <one` || {
+       test "$patched" = $(git rev-parse :one) &&
+       test "$patched" = $(git hash-object --stdin <one) || {
                echo "Eh?  apply with --index"
                false
        }
@@ -240,7 +240,7 @@ test_expect_success 'apply patch (autocrlf=true)' '
        git read-tree --reset -u HEAD &&
 
        git apply patch.file &&
-       test "$patched" = "`remove_cr <one | git hash-object --stdin`" || {
+       test "$patched" = "$(remove_cr <one | git hash-object --stdin)" || {
                echo "Eh?  apply without index"
                false
        }
@@ -253,7 +253,7 @@ test_expect_success 'apply patch --cached (autocrlf=true)' '
        git read-tree --reset -u HEAD &&
 
        git apply --cached patch.file &&
-       test "$patched" = `git rev-parse :one` || {
+       test "$patched" = $(git rev-parse :one) || {
                echo "Eh?  apply without index"
                false
        }
@@ -266,8 +266,8 @@ test_expect_success 'apply patch --index (autocrlf=true)' '
        git read-tree --reset -u HEAD &&
 
        git apply --index patch.file &&
-       test "$patched" = `git rev-parse :one` &&
-       test "$patched" = "`remove_cr <one | git hash-object --stdin`" || {
+       test "$patched" = $(git rev-parse :one) &&
+       test "$patched" = "$(remove_cr <one | git hash-object --stdin)" || {
                echo "Eh?  apply with --index"
                false
        }
index b92e6cb0469ebb2e328c490cba9b8aaa7c1dbb84..f890c54d137aab021e6d6a61c5741af872555c1f 100755 (executable)
@@ -190,8 +190,6 @@ test_expect_success 'required filter clean failure' '
        test_must_fail git add test.fc
 '
 
-test -n "$GIT_TEST_LONG" && test_set_prereq EXPENSIVE
-
 test_expect_success EXPENSIVE 'filter large file' '
        git config filter.largefile.smudge cat &&
        git config filter.largefile.clean cat &&
index f5f67a6337320c11a285b78be299fa955663991d..c164b4662a06d26bc23b58287f88023ed0a588a2 100755 (executable)
@@ -12,144 +12,144 @@ test_expect_success setup '
 
        git config core.autocrlf false &&
 
-       for w in Hello world how are you; do echo $w; done >one &&
-       for w in I am very very fine thank you; do echo ${w}Q; done | q_to_cr >two &&
-       for w in Oh here is a QNUL byte how alarming; do echo ${w}; done | q_to_nul >three &&
+       for w in Hello world how are you; do echo $w; done >LFonly &&
+       for w in I am very very fine thank you; do echo ${w}Q; done | q_to_cr >CRLFonly &&
+       for w in Oh here is a QNUL byte how alarming; do echo ${w}; done | q_to_nul >LFwithNUL &&
        git add . &&
 
        git commit -m initial &&
 
-       one=`git rev-parse HEAD:one` &&
-       two=`git rev-parse HEAD:two` &&
-       three=`git rev-parse HEAD:three` &&
+       LFonly=$(git rev-parse HEAD:LFonly) &&
+       CRLFonly=$(git rev-parse HEAD:CRLFonly) &&
+       LFwithNUL=$(git rev-parse HEAD:LFwithNUL) &&
 
        echo happy.
 '
 
 test_expect_success 'default settings cause no changes' '
 
-       rm -f .gitattributes tmp one two three &&
+       rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
        git read-tree --reset -u HEAD &&
 
-       ! has_cr one &&
-       has_cr two &&
-       onediff=`git diff one` &&
-       twodiff=`git diff two` &&
-       threediff=`git diff three` &&
-       test -z "$onediff" -a -z "$twodiff" -a -z "$threediff"
+       ! has_cr LFonly &&
+       has_cr CRLFonly &&
+       LFonlydiff=$(git diff LFonly) &&
+       CRLFonlydiff=$(git diff CRLFonly) &&
+       LFwithNULdiff=$(git diff LFwithNUL) &&
+       test -z "$LFonlydiff" -a -z "$CRLFonlydiff" -a -z "$LFwithNULdiff"
 '
 
 test_expect_success 'crlf=true causes a CRLF file to be normalized' '
 
        # Backwards compatibility check
-       rm -f .gitattributes tmp one two three &&
-       echo "two crlf" > .gitattributes &&
+       rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
+       echo "CRLFonly crlf" > .gitattributes &&
        git read-tree --reset -u HEAD &&
 
        # Note, "normalized" means that git will normalize it if added
-       has_cr two &&
-       twodiff=`git diff two` &&
-       test -n "$twodiff"
+       has_cr CRLFonly &&
+       CRLFonlydiff=$(git diff CRLFonly) &&
+       test -n "$CRLFonlydiff"
 '
 
 test_expect_success 'text=true causes a CRLF file to be normalized' '
 
-       rm -f .gitattributes tmp one two three &&
-       echo "two text" > .gitattributes &&
+       rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
+       echo "CRLFonly text" > .gitattributes &&
        git read-tree --reset -u HEAD &&
 
        # Note, "normalized" means that git will normalize it if added
-       has_cr two &&
-       twodiff=`git diff two` &&
-       test -n "$twodiff"
+       has_cr CRLFonly &&
+       CRLFonlydiff=$(git diff CRLFonly) &&
+       test -n "$CRLFonlydiff"
 '
 
 test_expect_success 'eol=crlf gives a normalized file CRLFs with autocrlf=false' '
 
-       rm -f .gitattributes tmp one two three &&
+       rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
        git config core.autocrlf false &&
-       echo "one eol=crlf" > .gitattributes &&
+       echo "LFonly eol=crlf" > .gitattributes &&
        git read-tree --reset -u HEAD &&
 
-       has_cr one &&
-       onediff=`git diff one` &&
-       test -z "$onediff"
+       has_cr LFonly &&
+       LFonlydiff=$(git diff LFonly) &&
+       test -z "$LFonlydiff"
 '
 
 test_expect_success 'eol=crlf gives a normalized file CRLFs with autocrlf=input' '
 
-       rm -f .gitattributes tmp one two three &&
+       rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
        git config core.autocrlf input &&
-       echo "one eol=crlf" > .gitattributes &&
+       echo "LFonly eol=crlf" > .gitattributes &&
        git read-tree --reset -u HEAD &&
 
-       has_cr one &&
-       onediff=`git diff one` &&
-       test -z "$onediff"
+       has_cr LFonly &&
+       LFonlydiff=$(git diff LFonly) &&
+       test -z "$LFonlydiff"
 '
 
 test_expect_success 'eol=lf gives a normalized file LFs with autocrlf=true' '
 
-       rm -f .gitattributes tmp one two three &&
+       rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
        git config core.autocrlf true &&
-       echo "one eol=lf" > .gitattributes &&
+       echo "LFonly eol=lf" > .gitattributes &&
        git read-tree --reset -u HEAD &&
 
-       ! has_cr one &&
-       onediff=`git diff one` &&
-       test -z "$onediff"
+       ! has_cr LFonly &&
+       LFonlydiff=$(git diff LFonly) &&
+       test -z "$LFonlydiff"
 '
 
 test_expect_success 'autocrlf=true does not normalize CRLF files' '
 
-       rm -f .gitattributes tmp one two three &&
+       rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
        git config core.autocrlf true &&
        git read-tree --reset -u HEAD &&
 
-       has_cr one &&
-       has_cr two &&
-       onediff=`git diff one` &&
-       twodiff=`git diff two` &&
-       threediff=`git diff three` &&
-       test -z "$onediff" -a -z "$twodiff" -a -z "$threediff"
+       has_cr LFonly &&
+       has_cr CRLFonly &&
+       LFonlydiff=$(git diff LFonly) &&
+       CRLFonlydiff=$(git diff CRLFonly) &&
+       LFwithNULdiff=$(git diff LFwithNUL) &&
+       test -z "$LFonlydiff" -a -z "$CRLFonlydiff" -a -z "$LFwithNULdiff"
 '
 
 test_expect_success 'text=auto, autocrlf=true _does_ normalize CRLF files' '
 
-       rm -f .gitattributes tmp one two three &&
+       rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
        git config core.autocrlf true &&
        echo "* text=auto" > .gitattributes &&
        git read-tree --reset -u HEAD &&
 
-       has_cr one &&
-       has_cr two &&
-       onediff=`git diff one` &&
-       twodiff=`git diff two` &&
-       threediff=`git diff three` &&
-       test -z "$onediff" -a -n "$twodiff" -a -z "$threediff"
+       has_cr LFonly &&
+       has_cr CRLFonly &&
+       LFonlydiff=$(git diff LFonly) &&
+       CRLFonlydiff=$(git diff CRLFonly) &&
+       LFwithNULdiff=$(git diff LFwithNUL) &&
+       test -z "$LFonlydiff" -a -n "$CRLFonlydiff" -a -z "$LFwithNULdiff"
 '
 
 test_expect_success 'text=auto, autocrlf=true does not normalize binary files' '
 
-       rm -f .gitattributes tmp one two three &&
+       rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
        git config core.autocrlf true &&
        echo "* text=auto" > .gitattributes &&
        git read-tree --reset -u HEAD &&
 
-       ! has_cr three &&
-       threediff=`git diff three` &&
-       test -z "$threediff"
+       ! has_cr LFwithNUL &&
+       LFwithNULdiff=$(git diff LFwithNUL) &&
+       test -z "$LFwithNULdiff"
 '
 
 test_expect_success 'eol=crlf _does_ normalize binary files' '
 
-       rm -f .gitattributes tmp one two three &&
-       echo "three eol=crlf" > .gitattributes &&
+       rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
+       echo "LFwithNUL eol=crlf" > .gitattributes &&
        git read-tree --reset -u HEAD &&
 
-       has_cr three &&
-       threediff=`git diff three` &&
-       test -z "$threediff"
+       has_cr LFwithNUL &&
+       LFwithNULdiff=$(git diff LFwithNUL) &&
+       test -z "$LFwithNULdiff"
 '
 
 test_done
index fe0164be62ad9ae7a2ea426c6e576cd1133f3d67..4807b0f015d4b87aa762c0f7585d863a1dc34514 100755 (executable)
@@ -20,8 +20,8 @@ test_expect_success setup '
 
        git commit -m initial &&
 
-       one=`git rev-parse HEAD:one` &&
-       two=`git rev-parse HEAD:two` &&
+       one=$(git rev-parse HEAD:one) &&
+       two=$(git rev-parse HEAD:two) &&
 
        echo happy.
 '
@@ -34,9 +34,9 @@ test_expect_success 'eol=lf puts LFs in normalized file' '
 
        ! has_cr one &&
        ! has_cr two &&
-       onediff=`git diff one` &&
-       twodiff=`git diff two` &&
-       test -z "$onediff" -a -z "$twodiff"
+       onediff=$(git diff one) &&
+       twodiff=$(git diff two) &&
+       test -z "$onediff" && test -z "$twodiff"
 '
 
 test_expect_success 'eol=crlf puts CRLFs in normalized file' '
@@ -47,9 +47,9 @@ test_expect_success 'eol=crlf puts CRLFs in normalized file' '
 
        has_cr one &&
        ! has_cr two &&
-       onediff=`git diff one` &&
-       twodiff=`git diff two` &&
-       test -z "$onediff" -a -z "$twodiff"
+       onediff=$(git diff one) &&
+       twodiff=$(git diff two) &&
+       test -z "$onediff" && test -z "$twodiff"
 '
 
 test_expect_success 'autocrlf=true overrides eol=lf' '
@@ -61,9 +61,9 @@ test_expect_success 'autocrlf=true overrides eol=lf' '
 
        has_cr one &&
        has_cr two &&
-       onediff=`git diff one` &&
-       twodiff=`git diff two` &&
-       test -z "$onediff" -a -z "$twodiff"
+       onediff=$(git diff one) &&
+       twodiff=$(git diff two) &&
+       test -z "$onediff" && test -z "$twodiff"
 '
 
 test_expect_success 'autocrlf=true overrides unset eol' '
@@ -75,9 +75,9 @@ test_expect_success 'autocrlf=true overrides unset eol' '
 
        has_cr one &&
        has_cr two &&
-       onediff=`git diff one` &&
-       twodiff=`git diff two` &&
-       test -z "$onediff" -a -z "$twodiff"
+       onediff=$(git diff one) &&
+       twodiff=$(git diff two) &&
+       test -z "$onediff" && test -z "$twodiff"
 '
 
 test_done
diff --git a/t/t0027-auto-crlf.sh b/t/t0027-auto-crlf.sh
new file mode 100755 (executable)
index 0000000..72dd3e8
--- /dev/null
@@ -0,0 +1,265 @@
+#!/bin/sh
+
+test_description='CRLF conversion all combinations'
+
+. ./test-lib.sh
+
+if ! test_have_prereq EXPENSIVE
+then
+       skip_all="EXPENSIVE not set"
+       test_done
+fi
+
+
+compare_files()
+{
+       od -c <"$1" >"$1".expect &&
+       od -c <"$2" >"$2".actual &&
+       test_cmp "$1".expect "$2".actual &&
+       rm "$1".expect "$2".actual
+}
+
+compare_ws_file()
+{
+       pfx=$1
+       exp=$2.expect
+       act=$pfx.actual.$3
+       od -c <"$2" >"$exp" &&
+       od -c <"$3" >"$act" &&
+       test_cmp $exp $act &&
+       rm $exp $act
+}
+
+create_gitattributes()
+{
+       txtbin=$1
+       case "$txtbin" in
+               auto)
+               echo "*.txt text=auto" >.gitattributes
+               ;;
+               text)
+               echo "*.txt text" >.gitattributes
+               ;;
+               -text)
+               echo "*.txt -text" >.gitattributes
+               ;;
+               *)
+               echo >.gitattributes
+               ;;
+       esac
+}
+
+create_file_in_repo()
+{
+       crlf=$1
+       txtbin=$2
+       create_gitattributes "$txtbin" &&
+       for f in LF CRLF LF_mix_CR CRLF_mix_LF CRLF_nul
+       do
+               pfx=crlf_${crlf}_attr_${txtbin}_$f.txt &&
+               cp $f $pfx && git -c core.autocrlf=$crlf add $pfx
+       done &&
+       git commit -m "core.autocrlf $crlf"
+}
+
+check_files_in_repo()
+{
+       crlf=$1
+       txtbin=$2
+       lfname=$3
+       crlfname=$4
+       lfmixcrlf=$5
+       lfmixcr=$6
+       crlfnul=$7
+       pfx=crlf_${crlf}_attr_${txtbin}_ &&
+       compare_files $lfname ${pfx}LF.txt &&
+       compare_files $crlfname ${pfx}CRLF.txt &&
+       compare_files $lfmixcrlf ${pfx}CRLF_mix_LF.txt &&
+       compare_files $lfmixcr ${pfx}LF_mix_CR.txt &&
+       compare_files $crlfnul ${pfx}CRLF_nul.txt
+}
+
+
+check_files_in_ws()
+{
+       eol=$1
+       crlf=$2
+       txtbin=$3
+       lfname=$4
+       crlfname=$5
+       lfmixcrlf=$6
+       lfmixcr=$7
+       crlfnul=$8
+       create_gitattributes $txtbin &&
+       git config core.autocrlf $crlf &&
+       pfx=eol_${eol}_crlf_${crlf}_attr_${txtbin}_ &&
+       src=crlf_false_attr__ &&
+       for f in LF CRLF LF_mix_CR CRLF_mix_LF CRLF_nul
+       do
+               rm $src$f.txt &&
+               if test -z "$eol"; then
+                       git checkout $src$f.txt
+               else
+                       git -c core.eol=$eol checkout $src$f.txt
+               fi
+       done
+
+
+       test_expect_success "checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$txtbin file=LF" "
+               compare_ws_file $pfx $lfname    ${src}LF.txt
+       "
+       test_expect_success "checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$txtbin file=CRLF" "
+               compare_ws_file $pfx $crlfname  ${src}CRLF.txt
+       "
+       test_expect_success "checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$txtbin file=CRLF_mix_LF" "
+               compare_ws_file $pfx $lfmixcrlf ${src}CRLF_mix_LF.txt
+       "
+       test_expect_success "checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$txtbin file=LF_mix_CR" "
+               compare_ws_file $pfx $lfmixcr   ${src}LF_mix_CR.txt
+       "
+       test_expect_success "checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$txtbin file=CRLF_nul" "
+               compare_ws_file $pfx $crlfnul   ${src}CRLF_nul.txt
+       "
+}
+
+#######
+(
+       type od >/dev/null &&
+       printf "line1Q\r\nline2\r\nline3" | q_to_nul >CRLF_nul &&
+       cat >expect <<-EOF &&
+       0000000 l i n e 1 \0 \r \n l i n e 2 \r \n l
+       0000020 i n e 3
+       0000024
+EOF
+       od -c CRLF_nul | sed -e "s/[    ][       ]*/ /g" -e "s/ *$//" >actual
+       test_cmp expect actual &&
+       rm expect actual
+) || {
+               skip_all="od not found or od -c not usable"
+               exit 0
+               test_done
+}
+
+test_expect_success 'setup master' '
+       echo >.gitattributes &&
+       git checkout -b master &&
+       git add .gitattributes &&
+       git commit -m "add .gitattributes" "" &&
+       printf "line1\nline2\nline3"     >LF &&
+       printf "line1\r\nline2\r\nline3" >CRLF &&
+       printf "line1\r\nline2\nline3"   >CRLF_mix_LF &&
+       printf "line1\nline2\rline3"     >LF_mix_CR &&
+       printf "line1\r\nline2\rline3"   >CRLF_mix_CR &&
+       printf "line1Q\nline2\nline3" | q_to_nul >LF_nul
+'
+#  CRLF_nul had been created above
+
+test_expect_success 'create files' '
+       create_file_in_repo false "" &&
+       create_file_in_repo true  "" &&
+       create_file_in_repo input "" &&
+
+       create_file_in_repo false "auto" &&
+       create_file_in_repo true  "auto" &&
+       create_file_in_repo input "auto" &&
+
+       create_file_in_repo false "text" &&
+       create_file_in_repo true  "text" &&
+       create_file_in_repo input "text" &&
+
+       create_file_in_repo false "-text" &&
+       create_file_in_repo true  "-text" &&
+       create_file_in_repo input "-text" &&
+       rm -f *.txt &&
+       git reset --hard
+'
+
+test_expect_success 'commit empty gitattribues' '
+       check_files_in_repo false ""      LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul &&
+       check_files_in_repo true  ""      LF LF   LF          LF_mix_CR CRLF_nul &&
+       check_files_in_repo input ""      LF LF   LF          LF_mix_CR CRLF_nul
+'
+
+test_expect_success 'commit text=auto' '
+       check_files_in_repo false "auto"  LF LF   LF          LF_mix_CR CRLF_nul &&
+       check_files_in_repo true  "auto"  LF LF   LF          LF_mix_CR CRLF_nul &&
+       check_files_in_repo input "auto"  LF LF   LF          LF_mix_CR CRLF_nul
+'
+
+test_expect_success 'commit text' '
+       check_files_in_repo false "text"  LF LF   LF          LF_mix_CR LF_nul &&
+       check_files_in_repo true  "text"  LF LF   LF          LF_mix_CR LF_nul &&
+       check_files_in_repo input "text"  LF LF   LF          LF_mix_CR LF_nul
+'
+
+test_expect_success 'commit -text' '
+       check_files_in_repo false "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul &&
+       check_files_in_repo true  "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul &&
+       check_files_in_repo input "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
+'
+
+################################################################################
+# Check how files in the repo are changed when they are checked out
+# How to read the table below:
+# - check_files_in_ws will check multiple files, see below
+# - parameter $1 : core.eol               lf | crlf
+# - parameter $2 : core.autocrlf          false | true | input
+# - parameter $3 : text in .gitattributs  "" (empty) | auto | text | -text
+# - parameter $4 : reference for a file with only LF in the repo
+# - parameter $5 : reference for a file with only CRLF in the repo
+# - parameter $6 : reference for a file with mixed LF and CRLF in the repo
+# - parameter $7 : reference for a file with LF and CR in the repo (does somebody uses this ?)
+# - parameter $8 : reference for a file with CRLF and a NUL (should be handled as binary when auto)
+
+check_files_in_ws lf      false  ""       LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
+check_files_in_ws lf      true   ""       CRLF  CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
+check_files_in_ws lf      input  ""       LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
+
+check_files_in_ws lf      false "auto"    LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
+check_files_in_ws lf      true  "auto"    CRLF  CRLF  CRLF         LF_mix_CR    CRLF_nul
+check_files_in_ws lf      input "auto"    LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
+
+check_files_in_ws lf      false "text"    LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
+check_files_in_ws lf      true  "text"    CRLF  CRLF  CRLF         CRLF_mix_CR  CRLF_nul
+check_files_in_ws lf      input "text"    LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
+
+check_files_in_ws lf      false "-text"   LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
+check_files_in_ws lf      true  "-text"   LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
+check_files_in_ws lf      input "-text"   LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
+
+###########
+#core.autocrlf=input is forbidden with core.eol=crlf
+check_files_in_ws crlf    false ""        LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
+check_files_in_ws crlf    true  ""        CRLF  CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
+
+check_files_in_ws crlf    false "auto"    CRLF  CRLF  CRLF         LF_mix_CR    CRLF_nul
+check_files_in_ws crlf    true  "auto"    CRLF  CRLF  CRLF         LF_mix_CR    CRLF_nul
+
+check_files_in_ws crlf    false "text"    CRLF  CRLF  CRLF         CRLF_mix_CR  CRLF_nul
+check_files_in_ws crlf    true  "text"    CRLF  CRLF  CRLF         CRLF_mix_CR  CRLF_nul
+
+check_files_in_ws crlf    false "-text"   LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
+check_files_in_ws crlf    true  "-text"   LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
+
+if test_have_prereq MINGW
+then
+check_files_in_ws ""      false ""        LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
+check_files_in_ws ""      true  ""        CRLF  CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
+check_files_in_ws ""      false "auto"    LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
+check_files_in_ws ""      true  "auto"    CRLF  CRLF  CRLF         LF_mix_CR    CRLF_nul
+check_files_in_ws ""      false "text"    LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
+check_files_in_ws ""      true  "text"    CRLF  CRLF  CRLF         CRLF_mix_CR  CRLF_nul
+check_files_in_ws ""      false "-text"   LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
+check_files_in_ws ""      true  "-text"   LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
+
+check_files_in_ws native  false ""        LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
+check_files_in_ws native  true  ""        CRLF  CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
+check_files_in_ws native  false "auto"    LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
+check_files_in_ws native  true  "auto"    CRLF  CRLF  CRLF         LF_mix_CR    CRLF_nul
+check_files_in_ws native  false "text"    LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
+check_files_in_ws native  true  "text"    CRLF  CRLF  CRLF         CRLF_mix_CR  CRLF_nul
+check_files_in_ws native  false "-text"   LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
+check_files_in_ws native  true  "-text"   LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
+fi
+
+test_done
index a8e84d854636178224b1bbd52272d47fc686ece9..0333dd9875af9fbbad04cf05eb9f0e9fe37ae182 100755 (executable)
@@ -225,22 +225,22 @@ test_expect_success \
 
 test_expect_success \
     'text without newline at end should end with newline' '
-    test `printf "$ttt" | git stripspace | wc -l` -gt 0 &&
-    test `printf "$ttt$ttt" | git stripspace | wc -l` -gt 0 &&
-    test `printf "$ttt$ttt$ttt" | git stripspace | wc -l` -gt 0 &&
-    test `printf "$ttt$ttt$ttt$ttt" | git stripspace | wc -l` -gt 0
+    test $(printf "$ttt" | git stripspace | wc -l) -gt 0 &&
+    test $(printf "$ttt$ttt" | git stripspace | wc -l) -gt 0 &&
+    test $(printf "$ttt$ttt$ttt" | git stripspace | wc -l) -gt 0 &&
+    test $(printf "$ttt$ttt$ttt$ttt" | git stripspace | wc -l) -gt 0
 '
 
 # text plus spaces at the end:
 
 test_expect_success \
     'text plus spaces without newline at end should end with newline' '
-    test `printf "$ttt$sss" | git stripspace | wc -l` -gt 0 &&
-    test `printf "$ttt$ttt$sss" | git stripspace | wc -l` -gt 0 &&
-    test `printf "$ttt$ttt$ttt$sss" | git stripspace | wc -l` -gt 0 &&
-    test `printf "$ttt$sss$sss" | git stripspace | wc -l` -gt 0 &&
-    test `printf "$ttt$ttt$sss$sss" | git stripspace | wc -l` -gt 0 &&
-    test `printf "$ttt$sss$sss$sss" | git stripspace | wc -l` -gt 0
+    test $(printf "$ttt$sss" | git stripspace | wc -l) -gt 0 &&
+    test $(printf "$ttt$ttt$sss" | git stripspace | wc -l) -gt 0 &&
+    test $(printf "$ttt$ttt$ttt$sss" | git stripspace | wc -l) -gt 0 &&
+    test $(printf "$ttt$sss$sss" | git stripspace | wc -l) -gt 0 &&
+    test $(printf "$ttt$ttt$sss$sss" | git stripspace | wc -l) -gt 0 &&
+    test $(printf "$ttt$sss$sss$sss" | git stripspace | wc -l) -gt 0
 '
 
 test_expect_success \
index 538ea5fb1c27bf5e4f9c4a0268f219f5d6d6e9c5..57ea5a10c5c716f52a8c8c7335ac7f68fe9dd92d 100755 (executable)
@@ -6,7 +6,7 @@ test_description='basic credential helper tests'
 
 test_expect_success 'setup helper scripts' '
        cat >dump <<-\EOF &&
-       whoami=`echo $0 | sed s/.*git-credential-//`
+       whoami=$(echo $0 | sed s/.*git-credential-//)
        echo >&2 "$whoami: $*"
        OIFS=$IFS
        IFS==
index babcdd23433348cd0e2397b2fb6968f7cfae4b0a..a0b79b4839fb21a96bf8aca769542d93b21bb90f 100755 (executable)
@@ -519,10 +519,10 @@ test_expect_success \
     'rm -f .git/index F16 &&
     echo F16 >F16 &&
     git update-index --add F16 &&
-    tree0=`git write-tree` &&
+    tree0=$(git write-tree) &&
     echo E16 >F16 &&
     git update-index F16 &&
-    tree1=`git write-tree` &&
+    tree1=$(git write-tree) &&
     read_tree_must_succeed -m $tree0 $tree1 $tree1 $tree0 &&
     git ls-files --stage'
 
index 3a24abf5496c76862e772907442dc24bdcb4d78a..db1b6f5cf4dd8c7932946a53bc2e1c30b09b762b 100755 (executable)
@@ -36,7 +36,7 @@ compare_change () {
 }
 
 check_cache_at () {
-       clean_if_empty=`git diff-files -- "$1"`
+       clean_if_empty=$(git diff-files -- "$1")
        case "$clean_if_empty" in
        '')  echo "$1: clean" ;;
        ?*)  echo "$1: dirty" ;;
@@ -68,14 +68,14 @@ test_expect_success \
      echo rezrov >rezrov &&
      echo yomin >yomin &&
      git update-index --add nitfol bozbar rezrov &&
-     treeH=`git write-tree` &&
+     treeH=$(git write-tree) &&
      echo treeH $treeH &&
      git ls-tree $treeH &&
 
      cat bozbar-new >bozbar &&
      git update-index --add frotz bozbar --force-remove rezrov &&
      git ls-files --stage >M.out &&
-     treeM=`git write-tree` &&
+     treeM=$(git write-tree) &&
      echo treeM $treeM &&
      git ls-tree $treeM &&
      git diff-tree $treeH $treeM'
@@ -315,7 +315,7 @@ test_expect_success \
     'rm -f .git/index &&
      echo DF >DF &&
      git update-index --add DF &&
-     treeDF=`git write-tree` &&
+     treeDF=$(git write-tree) &&
      echo treeDF $treeDF &&
      git ls-tree $treeDF &&
 
@@ -323,7 +323,7 @@ test_expect_success \
      mkdir DF &&
      echo DF/DF >DF/DF &&
      git update-index --add --remove DF DF/DF &&
-     treeDFDF=`git write-tree` &&
+     treeDFDF=$(git write-tree) &&
      echo treeDFDF $treeDFDF &&
      git ls-tree $treeDFDF &&
      git ls-files --stage >DFDF.out'
@@ -345,7 +345,7 @@ test_expect_success \
     'rm -f .git/index &&
      : >a &&
      git update-index --add a &&
-     treeM=`git write-tree` &&
+     treeM=$(git write-tree) &&
      echo treeM $treeM &&
      git ls-tree $treeM &&
      git ls-files --stage >treeM.out &&
@@ -354,7 +354,7 @@ test_expect_success \
      git update-index --remove a &&
      mkdir a &&
      : >a/b &&
-     treeH=`git write-tree` &&
+     treeH=$(git write-tree) &&
      echo treeH $treeH &&
      git ls-tree $treeH'
 
@@ -372,7 +372,7 @@ test_expect_success \
      mkdir c &&
      : >c/d &&
      git update-index --add a c/d &&
-     treeM=`git write-tree` &&
+     treeM=$(git write-tree) &&
      echo treeM $treeM &&
      git ls-tree $treeM &&
      git ls-files --stage >treeM.out &&
@@ -381,7 +381,7 @@ test_expect_success \
      mkdir a &&
      : >a/b &&
      git update-index --add --remove a a/b &&
-     treeH=`git write-tree` &&
+     treeH=$(git write-tree) &&
      echo treeH $treeH &&
      git ls-tree $treeH'
 
index a847709a1354a824c90a13d2c9e9ab6d6bc69b6c..fed877b20f428a1987357ad1f66dc678f5c7e2eb 100755 (executable)
@@ -21,7 +21,7 @@ compare_change () {
 }
 
 check_cache_at () {
-       clean_if_empty=`git diff-files -- "$1"`
+       clean_if_empty=$(git diff-files -- "$1")
        case "$clean_if_empty" in
        '')  echo "$1: clean" ;;
        ?*)  echo "$1: dirty" ;;
@@ -41,14 +41,14 @@ test_expect_success \
      echo bozbar >bozbar &&
      echo rezrov >rezrov &&
      git update-index --add nitfol bozbar rezrov &&
-     treeH=`git write-tree` &&
+     treeH=$(git write-tree) &&
      echo treeH $treeH &&
      git ls-tree $treeH &&
 
      echo gnusto >bozbar &&
      git update-index --add frotz bozbar --force-remove rezrov &&
      git ls-files --stage >M.out &&
-     treeM=`git write-tree` &&
+     treeM=$(git write-tree) &&
      echo treeM $treeM &&
      git ls-tree $treeM &&
      sum bozbar frotz nitfol >M.sum &&
@@ -318,7 +318,7 @@ test_expect_success \
     'rm -f .git/index &&
      echo DF >DF &&
      git update-index --add DF &&
-     treeDF=`git write-tree` &&
+     treeDF=$(git write-tree) &&
      echo treeDF $treeDF &&
      git ls-tree $treeDF &&
 
@@ -326,7 +326,7 @@ test_expect_success \
      mkdir DF &&
      echo DF/DF >DF/DF &&
      git update-index --add --remove DF DF/DF &&
-     treeDFDF=`git write-tree` &&
+     treeDFDF=$(git write-tree) &&
      echo treeDFDF $treeDFDF &&
      git ls-tree $treeDFDF &&
      git ls-files --stage >DFDF.out'
index 8c6d67edda1468ba0f1c7afc6d13ea3a7bbe0a90..b6111cd150fdd69973142808cf4a86a4fa6b7e76 100755 (executable)
@@ -11,7 +11,7 @@ test_description='git read-tree --prefix test.
 test_expect_success setup '
        echo hello >one &&
        git update-index --add one &&
-       tree=`git write-tree` &&
+       tree=$(git write-tree) &&
        echo tree is $tree
 '
 
index 3e72aff470f8d9e5e79689de459904d1f3271d0d..c70cf423008cfb6f3f3fd735c1f6ee2d1408de2c 100755 (executable)
@@ -30,7 +30,7 @@ test_expect_success 'two-way not clobbering' '
 
        echo >file2 master creates untracked file2 &&
        echo >subdir/file2 master creates untracked subdir/file2 &&
-       if err=`read_tree_u_must_succeed -m -u master side 2>&1`
+       if err=$(read_tree_u_must_succeed -m -u master side 2>&1)
        then
                echo should have complained
                false
@@ -43,7 +43,7 @@ echo file2 >.gitignore
 
 test_expect_success 'two-way with incorrect --exclude-per-directory (1)' '
 
-       if err=`read_tree_u_must_succeed -m --exclude-per-directory=.gitignore master side 2>&1`
+       if err=$(read_tree_u_must_succeed -m --exclude-per-directory=.gitignore master side 2>&1)
        then
                echo should have complained
                false
@@ -54,7 +54,7 @@ test_expect_success 'two-way with incorrect --exclude-per-directory (1)' '
 
 test_expect_success 'two-way with incorrect --exclude-per-directory (2)' '
 
-       if err=`read_tree_u_must_succeed -m -u --exclude-per-directory=foo --exclude-per-directory=.gitignore master side 2>&1`
+       if err=$(read_tree_u_must_succeed -m -u --exclude-per-directory=foo --exclude-per-directory=.gitignore master side 2>&1)
        then
                echo should have complained
                false
@@ -95,7 +95,7 @@ test_expect_success 'three-way not clobbering a working tree file' '
        git checkout master &&
        echo >file3 file three created in master, untracked &&
        echo >subdir/file3 file three created in master, untracked &&
-       if err=`read_tree_u_must_succeed -m -u branch-point master side 2>&1`
+       if err=$(read_tree_u_must_succeed -m -u branch-point master side 2>&1)
        then
                echo should have complained
                false
index 6902320e819651553beac7d80971b984b9168a8a..62c0d25af4ca1c8ef5d0d63b6e3ea329a6d75205 100755 (executable)
@@ -20,27 +20,27 @@ test_expect_success setup '
 
 test_expect_success 'update-index and ls-files' '
        git update-index --add one &&
-       case "`git ls-files`" in
+       case "$(git ls-files)" in
        one) echo pass one ;;
        *) echo bad one; exit 1 ;;
        esac &&
        (
                cd dir &&
                git update-index --add two &&
-               case "`git ls-files`" in
+               case "$(git ls-files)" in
                two) echo pass two ;;
                *) echo bad two; exit 1 ;;
                esac
        ) &&
-       case "`git ls-files`" in
+       case "$(git ls-files)" in
        dir/two"$LF"one) echo pass both ;;
        *) echo bad; exit 1 ;;
        esac
 '
 
 test_expect_success 'cat-file' '
-       two=`git ls-files -s dir/two` &&
-       two=`expr "$two" : "[0-7]* \\([0-9a-f]*\\)"` &&
+       two=$(git ls-files -s dir/two) &&
+       two=$(expr "$two" : "[0-7]* \\([0-9a-f]*\\)") &&
        echo "$two" &&
        git cat-file -p "$two" >actual &&
        cmp dir/two actual &&
@@ -55,18 +55,18 @@ rm -f actual dir/actual
 test_expect_success 'diff-files' '
        echo a >>one &&
        echo d >>dir/two &&
-       case "`git diff-files --name-only`" in
+       case "$(git diff-files --name-only)" in
        dir/two"$LF"one) echo pass top ;;
        *) echo bad top; exit 1 ;;
        esac &&
        # diff should not omit leading paths
        (
                cd dir &&
-               case "`git diff-files --name-only`" in
+               case "$(git diff-files --name-only)" in
                dir/two"$LF"one) echo pass subdir ;;
                *) echo bad subdir; exit 1 ;;
                esac &&
-               case "`git diff-files --name-only .`" in
+               case "$(git diff-files --name-only .)" in
                dir/two) echo pass subdir limited ;;
                *) echo bad subdir limited; exit 1 ;;
                esac
@@ -74,11 +74,11 @@ test_expect_success 'diff-files' '
 '
 
 test_expect_success 'write-tree' '
-       top=`git write-tree` &&
+       top=$(git write-tree) &&
        echo $top &&
        (
                cd dir &&
-               sub=`git write-tree` &&
+               sub=$(git write-tree) &&
                echo $sub &&
                test "z$top" = "z$sub"
        )
@@ -96,7 +96,7 @@ test_expect_success 'checkout-index' '
 
 test_expect_success 'read-tree' '
        rm -f one dir/two &&
-       tree=`git write-tree` &&
+       tree=$(git write-tree) &&
        read_tree_u_must_succeed --reset -u "$tree" &&
        cmp one original.one &&
        cmp dir/two original.two &&
index fd105280092b7f655f5c48f09b2e8f5e0ee6d351..aea493646e4400e733749768e48f2a3d1a470299 100755 (executable)
@@ -131,7 +131,7 @@ test_expect_success 'git-show a large file' '
 '
 
 test_expect_success 'index-pack' '
-       git clone file://"`pwd`"/.git foo &&
+       git clone file://"$(pwd)"/.git foo &&
        GIT_DIR=non-existent git index-pack --strict --verify foo/.git/objects/pack/*.pack
 '
 
@@ -140,7 +140,7 @@ test_expect_success 'repack' '
 '
 
 test_expect_success 'pack-objects with large loose object' '
-       SHA1=`git hash-object huge` &&
+       SHA1=$(git hash-object huge) &&
        test_create_repo loose &&
        echo $SHA1 | git pack-objects --stdout |
                GIT_ALLOC_LIMIT=0 GIT_DIR=loose/.git git unpack-objects &&
index 58cd5435be59107c3bac323e0d53816ab0f8e4ae..3f80ff0c14c47b87bbbecb74d1951a1abe6bc5ba 100755 (executable)
@@ -1158,4 +1158,14 @@ test_expect_failure 'adding a key into an empty section reuses header' '
        test_cmp expect .git/config
 '
 
+test_expect_success POSIXPERM,PERL 'preserves existing permissions' '
+       chmod 0600 .git/config &&
+       git config imap.pass Hunter2 &&
+       perl -e \
+         "die q(badset) if ((stat(q(.git/config)))[2] & 07777) != 0600" &&
+       git config --rename-section imap pop &&
+       perl -e \
+         "die q(badrename) if ((stat(q(.git/config)))[2] & 07777) != 0600"
+'
+
 test_done
index e130c528fe5a0115c99b1203cfe9dced046cece3..0218e96366ddd8659d5a78b42ffcfd415013114c 100755 (executable)
@@ -235,7 +235,7 @@ test_expect_success \
        'rm -f o e &&
         git rev-parse --verify "master@{2005-05-26 23:33:01}" >o 2>e &&
         test '"$B"' = $(cat o) &&
-        test "warning: Log .git/logs/'"$m has gap after $gd"'." = "$(cat e)"'
+        test "warning: Log for ref '"$m has gap after $gd"'." = "$(cat e)"'
 test_expect_success \
        'Query "master@{2005-05-26 23:38:00}" (middle of history)' \
        'rm -f o e &&
@@ -253,7 +253,7 @@ test_expect_success \
        'rm -f o e &&
         git rev-parse --verify "master@{2005-05-28}" >o 2>e &&
         test '"$D"' = $(cat o) &&
-        test "warning: Log .git/logs/'"$m unexpectedly ended on $ld"'." = "$(cat e)"'
+        test "warning: Log for ref '"$m unexpectedly ended on $ld"'." = "$(cat e)"'
 
 
 rm -f .git/$m .git/logs/$m expect
@@ -350,22 +350,28 @@ test_expect_success 'stdin fails on unknown command' '
        grep "fatal: unknown command: unknown $a" err
 '
 
-test_expect_success 'stdin fails on badly quoted input' '
+test_expect_success 'stdin fails on unbalanced quotes' '
        echo "create $a \"master" >stdin &&
        test_must_fail git update-ref --stdin <stdin 2>err &&
        grep "fatal: badly quoted argument: \\\"master" err
 '
 
-test_expect_success 'stdin fails on arguments not separated by space' '
+test_expect_success 'stdin fails on invalid escape' '
+       echo "create $a \"ma\zter\"" >stdin &&
+       test_must_fail git update-ref --stdin <stdin 2>err &&
+       grep "fatal: badly quoted argument: \\\"ma\\\\zter\\\"" err
+'
+
+test_expect_success 'stdin fails on junk after quoted argument' '
        echo "create \"$a\"master" >stdin &&
        test_must_fail git update-ref --stdin <stdin 2>err &&
-       grep "fatal: expected SP but got: master" err
+       grep "fatal: unexpected character after quoted argument: \\\"$a\\\"master" err
 '
 
 test_expect_success 'stdin fails create with no ref' '
        echo "create " >stdin &&
        test_must_fail git update-ref --stdin <stdin 2>err &&
-       grep "fatal: create line missing <ref>" err
+       grep "fatal: create: missing <ref>" err
 '
 
 test_expect_success 'stdin fails create with bad ref name' '
@@ -377,19 +383,19 @@ test_expect_success 'stdin fails create with bad ref name' '
 test_expect_success 'stdin fails create with no new value' '
        echo "create $a" >stdin &&
        test_must_fail git update-ref --stdin <stdin 2>err &&
-       grep "fatal: create $a missing <newvalue>" err
+       grep "fatal: create $a: missing <newvalue>" err
 '
 
 test_expect_success 'stdin fails create with too many arguments' '
        echo "create $a $m $m" >stdin &&
        test_must_fail git update-ref --stdin <stdin 2>err &&
-       grep "fatal: create $a has extra input:  $m" err
+       grep "fatal: create $a: extra input:  $m" err
 '
 
 test_expect_success 'stdin fails update with no ref' '
        echo "update " >stdin &&
        test_must_fail git update-ref --stdin <stdin 2>err &&
-       grep "fatal: update line missing <ref>" err
+       grep "fatal: update: missing <ref>" err
 '
 
 test_expect_success 'stdin fails update with bad ref name' '
@@ -401,19 +407,19 @@ test_expect_success 'stdin fails update with bad ref name' '
 test_expect_success 'stdin fails update with no new value' '
        echo "update $a" >stdin &&
        test_must_fail git update-ref --stdin <stdin 2>err &&
-       grep "fatal: update $a missing <newvalue>" err
+       grep "fatal: update $a: missing <newvalue>" err
 '
 
 test_expect_success 'stdin fails update with too many arguments' '
        echo "update $a $m $m $m" >stdin &&
        test_must_fail git update-ref --stdin <stdin 2>err &&
-       grep "fatal: update $a has extra input:  $m" err
+       grep "fatal: update $a: extra input:  $m" err
 '
 
 test_expect_success 'stdin fails delete with no ref' '
        echo "delete " >stdin &&
        test_must_fail git update-ref --stdin <stdin 2>err &&
-       grep "fatal: delete line missing <ref>" err
+       grep "fatal: delete: missing <ref>" err
 '
 
 test_expect_success 'stdin fails delete with bad ref name' '
@@ -425,13 +431,13 @@ test_expect_success 'stdin fails delete with bad ref name' '
 test_expect_success 'stdin fails delete with too many arguments' '
        echo "delete $a $m $m" >stdin &&
        test_must_fail git update-ref --stdin <stdin 2>err &&
-       grep "fatal: delete $a has extra input:  $m" err
+       grep "fatal: delete $a: extra input:  $m" err
 '
 
 test_expect_success 'stdin fails verify with too many arguments' '
        echo "verify $a $m $m" >stdin &&
        test_must_fail git update-ref --stdin <stdin 2>err &&
-       grep "fatal: verify $a has extra input:  $m" err
+       grep "fatal: verify $a: extra input:  $m" err
 '
 
 test_expect_success 'stdin fails option with unknown name' '
@@ -458,6 +464,24 @@ test_expect_success 'stdin create ref works' '
        test_cmp expect actual
 '
 
+test_expect_success 'stdin succeeds with quoted argument' '
+       git update-ref -d $a &&
+       echo "create $a \"$m\"" >stdin &&
+       git update-ref --stdin <stdin &&
+       git rev-parse $m >expect &&
+       git rev-parse $a >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'stdin succeeds with escaped character' '
+       git update-ref -d $a &&
+       echo "create $a \"ma\\163ter\"" >stdin &&
+       git update-ref --stdin <stdin &&
+       git rev-parse $m >expect &&
+       git rev-parse $a >actual &&
+       test_cmp expect actual
+'
+
 test_expect_success 'stdin update ref creates with zero old value' '
        echo "update $b $m $Z" >stdin &&
        git update-ref --stdin <stdin &&
@@ -494,21 +518,21 @@ test_expect_success 'stdin update ref fails with wrong old value' '
 test_expect_success 'stdin update ref fails with bad old value' '
        echo "update $c $m does-not-exist" >stdin &&
        test_must_fail git update-ref --stdin <stdin 2>err &&
-       grep "fatal: invalid old value for ref $c: does-not-exist" err &&
+       grep "fatal: update $c: invalid <oldvalue>: does-not-exist" err &&
        test_must_fail git rev-parse --verify -q $c
 '
 
 test_expect_success 'stdin create ref fails with bad new value' '
        echo "create $c does-not-exist" >stdin &&
        test_must_fail git update-ref --stdin <stdin 2>err &&
-       grep "fatal: invalid new value for ref $c: does-not-exist" err &&
+       grep "fatal: create $c: invalid <newvalue>: does-not-exist" err &&
        test_must_fail git rev-parse --verify -q $c
 '
 
 test_expect_success 'stdin create ref fails with zero new value' '
        echo "create $c " >stdin &&
        test_must_fail git update-ref --stdin <stdin 2>err &&
-       grep "fatal: create $c given zero new value" err &&
+       grep "fatal: create $c: zero <newvalue>" err &&
        test_must_fail git rev-parse --verify -q $c
 '
 
@@ -532,7 +556,7 @@ test_expect_success 'stdin delete ref fails with wrong old value' '
 test_expect_success 'stdin delete ref fails with zero old value' '
        echo "delete $a " >stdin &&
        test_must_fail git update-ref --stdin <stdin 2>err &&
-       grep "fatal: delete $a given zero old value" err &&
+       grep "fatal: delete $a: zero <oldvalue>" err &&
        git rev-parse $m >expect &&
        git rev-parse $a >actual &&
        test_cmp expect actual
@@ -673,7 +697,7 @@ test_expect_success 'stdin -z fails on unknown command' '
 test_expect_success 'stdin -z fails create with no ref' '
        printf $F "create " >stdin &&
        test_must_fail git update-ref -z --stdin <stdin 2>err &&
-       grep "fatal: create line missing <ref>" err
+       grep "fatal: create: missing <ref>" err
 '
 
 test_expect_success 'stdin -z fails create with bad ref name' '
@@ -685,7 +709,7 @@ test_expect_success 'stdin -z fails create with bad ref name' '
 test_expect_success 'stdin -z fails create with no new value' '
        printf $F "create $a" >stdin &&
        test_must_fail git update-ref -z --stdin <stdin 2>err &&
-       grep "fatal: create $a missing <newvalue>" err
+       grep "fatal: create $a: unexpected end of input when reading <newvalue>" err
 '
 
 test_expect_success 'stdin -z fails create with too many arguments' '
@@ -697,25 +721,39 @@ test_expect_success 'stdin -z fails create with too many arguments' '
 test_expect_success 'stdin -z fails update with no ref' '
        printf $F "update " >stdin &&
        test_must_fail git update-ref -z --stdin <stdin 2>err &&
-       grep "fatal: update line missing <ref>" err
+       grep "fatal: update: missing <ref>" err
+'
+
+test_expect_success 'stdin -z fails update with too few args' '
+       printf $F "update $a" "$m" >stdin &&
+       test_must_fail git update-ref -z --stdin <stdin 2>err &&
+       grep "fatal: update $a: unexpected end of input when reading <oldvalue>" err
 '
 
 test_expect_success 'stdin -z fails update with bad ref name' '
-       printf $F "update ~a" "$m" >stdin &&
+       printf $F "update ~a" "$m" "" >stdin &&
        test_must_fail git update-ref -z --stdin <stdin 2>err &&
        grep "fatal: invalid ref format: ~a" err
 '
 
+test_expect_success 'stdin -z emits warning with empty new value' '
+       git update-ref $a $m &&
+       printf $F "update $a" "" "" >stdin &&
+       git update-ref -z --stdin <stdin 2>err &&
+       grep "warning: update $a: missing <newvalue>, treating as zero" err &&
+       test_must_fail git rev-parse --verify -q $a
+'
+
 test_expect_success 'stdin -z fails update with no new value' '
        printf $F "update $a" >stdin &&
        test_must_fail git update-ref -z --stdin <stdin 2>err &&
-       grep "fatal: update $a missing <newvalue>" err
+       grep "fatal: update $a: unexpected end of input when reading <newvalue>" err
 '
 
 test_expect_success 'stdin -z fails update with no old value' '
        printf $F "update $a" "$m" >stdin &&
        test_must_fail git update-ref -z --stdin <stdin 2>err &&
-       grep "fatal: update $a missing \\[<oldvalue>\\] NUL" err
+       grep "fatal: update $a: unexpected end of input when reading <oldvalue>" err
 '
 
 test_expect_success 'stdin -z fails update with too many arguments' '
@@ -727,7 +765,7 @@ test_expect_success 'stdin -z fails update with too many arguments' '
 test_expect_success 'stdin -z fails delete with no ref' '
        printf $F "delete " >stdin &&
        test_must_fail git update-ref -z --stdin <stdin 2>err &&
-       grep "fatal: delete line missing <ref>" err
+       grep "fatal: delete: missing <ref>" err
 '
 
 test_expect_success 'stdin -z fails delete with bad ref name' '
@@ -739,7 +777,7 @@ test_expect_success 'stdin -z fails delete with bad ref name' '
 test_expect_success 'stdin -z fails delete with no old value' '
        printf $F "delete $a" >stdin &&
        test_must_fail git update-ref -z --stdin <stdin 2>err &&
-       grep "fatal: delete $a missing \\[<oldvalue>\\] NUL" err
+       grep "fatal: delete $a: unexpected end of input when reading <oldvalue>" err
 '
 
 test_expect_success 'stdin -z fails delete with too many arguments' '
@@ -757,7 +795,7 @@ test_expect_success 'stdin -z fails verify with too many arguments' '
 test_expect_success 'stdin -z fails verify with no old value' '
        printf $F "verify $a" >stdin &&
        test_must_fail git update-ref -z --stdin <stdin 2>err &&
-       grep "fatal: verify $a missing \\[<oldvalue>\\] NUL" err
+       grep "fatal: verify $a: unexpected end of input when reading <oldvalue>" err
 '
 
 test_expect_success 'stdin -z fails option with unknown name' '
@@ -816,7 +854,7 @@ test_expect_success 'stdin -z update ref fails with wrong old value' '
 test_expect_success 'stdin -z update ref fails with bad old value' '
        printf $F "update $c" "$m" "does-not-exist" >stdin &&
        test_must_fail git update-ref -z --stdin <stdin 2>err &&
-       grep "fatal: invalid old value for ref $c: does-not-exist" err &&
+       grep "fatal: update $c: invalid <oldvalue>: does-not-exist" err &&
        test_must_fail git rev-parse --verify -q $c
 '
 
@@ -834,14 +872,14 @@ test_expect_success 'stdin -z create ref fails with bad new value' '
        git update-ref -d "$c" &&
        printf $F "create $c" "does-not-exist" >stdin &&
        test_must_fail git update-ref -z --stdin <stdin 2>err &&
-       grep "fatal: invalid new value for ref $c: does-not-exist" err &&
+       grep "fatal: create $c: invalid <newvalue>: does-not-exist" err &&
        test_must_fail git rev-parse --verify -q $c
 '
 
-test_expect_success 'stdin -z create ref fails with zero new value' '
+test_expect_success 'stdin -z create ref fails with empty new value' '
        printf $F "create $c" "" >stdin &&
        test_must_fail git update-ref -z --stdin <stdin 2>err &&
-       grep "fatal: create $c given zero new value" err &&
+       grep "fatal: create $c: missing <newvalue>" err &&
        test_must_fail git rev-parse --verify -q $c
 '
 
@@ -865,7 +903,7 @@ test_expect_success 'stdin -z delete ref fails with wrong old value' '
 test_expect_success 'stdin -z delete ref fails with zero old value' '
        printf $F "delete $a" "$Z" >stdin &&
        test_must_fail git update-ref -z --stdin <stdin 2>err &&
-       grep "fatal: delete $a given zero old value" err &&
+       grep "fatal: delete $a: zero <oldvalue>" err &&
        git rev-parse $m >expect &&
        git rev-parse $a >actual &&
        test_cmp expect actual
@@ -923,7 +961,7 @@ test_expect_success 'stdin -z update refs works with identity updates' '
 
 test_expect_success 'stdin -z update refs fails with wrong old value' '
        git update-ref $c $m &&
-       printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "" "$Z" >stdin &&
+       printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$m" "$Z" >stdin &&
        test_must_fail git update-ref -z --stdin <stdin 2>err &&
        grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err &&
        git rev-parse $m >expect &&
index 1a5a5f39fd94f9eb98824b3d84983782b9ff71bb..9aeb352b3dba3fd7e46a5a0732425cd2686fc9f3 100755 (executable)
@@ -64,6 +64,7 @@ valid_ref "$(printf 'heads/fu\303\237')"
 invalid_ref 'heads/*foo/bar' --refspec-pattern
 invalid_ref 'heads/foo*/bar' --refspec-pattern
 invalid_ref 'heads/f*o/bar' --refspec-pattern
+invalid_ref 'heads/foo*//bar' --refspec-pattern
 
 ref='foo'
 invalid_ref "$ref"
@@ -128,6 +129,20 @@ valid_ref NOT_MINGW "$ref" '--allow-onelevel --normalize'
 invalid_ref NOT_MINGW "$ref" '--refspec-pattern --normalize'
 valid_ref NOT_MINGW "$ref" '--refspec-pattern --allow-onelevel --normalize'
 
+
+valid_ref 'refs/heads/a-very-long-refname'
+invalid_ref 'refs/heads/.a-very-long-refname'
+invalid_ref 'refs/heads/abcdefgh0123..'
+invalid_ref 'refs/heads/abcdefgh01234..'
+invalid_ref 'refs/heads/abcdefgh012345..'
+invalid_ref 'refs/heads/abcdefgh0123456..'
+invalid_ref 'refs/heads/abcdefgh01234567..'
+valid_ref 'refs/heads/abcdefgh0123.a'
+valid_ref 'refs/heads/abcdefgh01234.a'
+valid_ref 'refs/heads/abcdefgh012345.a'
+valid_ref 'refs/heads/abcdefgh0123456.a'
+valid_ref 'refs/heads/abcdefgh01234567.a'
+
 test_expect_success "check-ref-format --branch @{-1}" '
        T=$(git write-tree) &&
        sha1=$(echo A | git commit-tree $T) &&
index 236b13a3ab27f54808fa88574738747e3c3936b1..8cab06f90a52b82518aca6f7baa0530eb77ab986 100755 (executable)
@@ -245,4 +245,12 @@ test_expect_success 'gc.reflogexpire=false' '
 
 '
 
+test_expect_success 'checkout should not delete log for packed ref' '
+       test $(git reflog master | wc -l) = 4 &&
+       git branch foo &&
+       git pack-refs --all &&
+       git checkout foo &&
+       test $(git reflog master | wc -l) = 4
+'
+
 test_done
diff --git a/t/t1700-split-index.sh b/t/t1700-split-index.sh
new file mode 100755 (executable)
index 0000000..94fb473
--- /dev/null
@@ -0,0 +1,194 @@
+#!/bin/sh
+
+test_description='split index mode tests'
+
+. ./test-lib.sh
+
+# We need total control of index splitting here
+sane_unset GIT_TEST_SPLIT_INDEX
+
+test_expect_success 'enable split index' '
+       git update-index --split-index &&
+       test-dump-split-index .git/index >actual &&
+       cat >expect <<EOF &&
+own 8299b0bcd1ac364e5f1d7768efb62fa2da79a339
+base 39d890139ee5356c7ef572216cebcd27aa41f9df
+replacements:
+deletions:
+EOF
+       test_cmp expect actual
+'
+
+test_expect_success 'add one file' '
+       : >one &&
+       git update-index --add one &&
+       git ls-files --stage >ls-files.actual &&
+       cat >ls-files.expect <<EOF &&
+100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0      one
+EOF
+       test_cmp ls-files.expect ls-files.actual &&
+
+       test-dump-split-index .git/index | sed "/^own/d" >actual &&
+       cat >expect <<EOF &&
+base 39d890139ee5356c7ef572216cebcd27aa41f9df
+100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0      one
+replacements:
+deletions:
+EOF
+       test_cmp expect actual
+'
+
+test_expect_success 'disable split index' '
+       git update-index --no-split-index &&
+       git ls-files --stage >ls-files.actual &&
+       cat >ls-files.expect <<EOF &&
+100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0      one
+EOF
+       test_cmp ls-files.expect ls-files.actual &&
+
+       BASE=`test-dump-split-index .git/index | grep "^own" | sed "s/own/base/"` &&
+       test-dump-split-index .git/index | sed "/^own/d" >actual &&
+       cat >expect <<EOF &&
+not a split index
+EOF
+       test_cmp expect actual
+'
+
+test_expect_success 'enable split index again, "one" now belongs to base index"' '
+       git update-index --split-index &&
+       git ls-files --stage >ls-files.actual &&
+       cat >ls-files.expect <<EOF &&
+100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0      one
+EOF
+       test_cmp ls-files.expect ls-files.actual &&
+
+       test-dump-split-index .git/index | sed "/^own/d" >actual &&
+       cat >expect <<EOF &&
+$BASE
+replacements:
+deletions:
+EOF
+       test_cmp expect actual
+'
+
+test_expect_success 'modify original file, base index untouched' '
+       echo modified >one &&
+       git update-index one &&
+       git ls-files --stage >ls-files.actual &&
+       cat >ls-files.expect <<EOF &&
+100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0      one
+EOF
+       test_cmp ls-files.expect ls-files.actual &&
+
+       test-dump-split-index .git/index | sed "/^own/d" >actual &&
+       q_to_tab >expect <<EOF &&
+$BASE
+100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0Q
+replacements: 0
+deletions:
+EOF
+       test_cmp expect actual
+'
+
+test_expect_success 'add another file, which stays index' '
+       : >two &&
+       git update-index --add two &&
+       git ls-files --stage >ls-files.actual &&
+       cat >ls-files.expect <<EOF &&
+100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0      one
+100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0      two
+EOF
+       test_cmp ls-files.expect ls-files.actual &&
+
+       test-dump-split-index .git/index | sed "/^own/d" >actual &&
+       q_to_tab >expect <<EOF &&
+$BASE
+100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0Q
+100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0      two
+replacements: 0
+deletions:
+EOF
+       test_cmp expect actual
+'
+
+test_expect_success 'remove file not in base index' '
+       git update-index --force-remove two &&
+       git ls-files --stage >ls-files.actual &&
+       cat >ls-files.expect <<EOF &&
+100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0      one
+EOF
+       test_cmp ls-files.expect ls-files.actual &&
+
+       test-dump-split-index .git/index | sed "/^own/d" >actual &&
+       q_to_tab >expect <<EOF &&
+$BASE
+100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0Q
+replacements: 0
+deletions:
+EOF
+       test_cmp expect actual
+'
+
+test_expect_success 'remove file in base index' '
+       git update-index --force-remove one &&
+       git ls-files --stage >ls-files.actual &&
+       cat >ls-files.expect <<EOF &&
+EOF
+       test_cmp ls-files.expect ls-files.actual &&
+
+       test-dump-split-index .git/index | sed "/^own/d" >actual &&
+       cat >expect <<EOF &&
+$BASE
+replacements:
+deletions: 0
+EOF
+       test_cmp expect actual
+'
+
+test_expect_success 'add original file back' '
+       : >one &&
+       git update-index --add one &&
+       git ls-files --stage >ls-files.actual &&
+       cat >ls-files.expect <<EOF &&
+100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0      one
+EOF
+       test_cmp ls-files.expect ls-files.actual &&
+
+       test-dump-split-index .git/index | sed "/^own/d" >actual &&
+       cat >expect <<EOF &&
+$BASE
+100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0      one
+replacements:
+deletions: 0
+EOF
+       test_cmp expect actual
+'
+
+test_expect_success 'add new file' '
+       : >two &&
+       git update-index --add two &&
+       git ls-files --stage >actual &&
+       cat >expect <<EOF &&
+100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0      one
+100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0      two
+EOF
+       test_cmp expect actual
+'
+
+test_expect_success 'unify index, two files remain' '
+       git update-index --no-split-index &&
+       git ls-files --stage >ls-files.actual &&
+       cat >ls-files.expect <<EOF &&
+100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0      one
+100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0      two
+EOF
+       test_cmp ls-files.expect ls-files.actual
+
+       test-dump-split-index .git/index | sed "/^own/d" >actual &&
+       cat >expect <<EOF &&
+not a split index
+EOF
+       test_cmp expect actual
+'
+
+test_done
index 29c1fb10cad93818d467780b799ff874e8fdcab0..cc830da58d920718b7b0a990a359afa9dd783b4c 100755 (executable)
@@ -7,6 +7,8 @@ test_description='skip-worktree bit test'
 
 . ./test-lib.sh
 
+sane_unset GIT_TEST_SPLIT_INDEX
+
 test_set_index_version 3
 
 cat >expect.full <<EOF
index 5fd7bbb65244bdf6470508b6bc79aef58e79e86d..4029c9c8c06d24887e7d9fa7c97c2c8c5826eb42 100755 (executable)
@@ -14,7 +14,11 @@ test_description='merge-recursive options
 . ./test-lib.sh
 
 test_have_prereq SED_STRIPS_CR && SED_OPTIONS=-b
-test_have_prereq GREP_STRIPS_CR && export GREP_OPTIONS=-U
+if test_have_prereq GREP_STRIPS_CR
+then
+       GREP_OPTIONS=-U
+       export GREP_OPTIONS
+fi
 
 test_expect_success 'setup' '
        conflict_hunks () {
index e35d7811acc60415e38e58866b5488938d0372a4..8d44e04354f05856465904700ff0374dae74ba59 100755 (executable)
@@ -7,9 +7,7 @@ test_description='Test commit notes index (expensive!)'
 
 . ./test-lib.sh
 
-test_set_prereq NOT_EXPENSIVE
 test -n "$GIT_NOTES_TIMING_TESTS" && test_set_prereq EXPENSIVE
-test -x /usr/bin/time && test_set_prereq USR_BIN_TIME
 
 create_repo () {
        number_of_commits=$1
@@ -17,43 +15,43 @@ create_repo () {
        test -d .git || {
        git init &&
        (
-               while [ $nr -lt $number_of_commits ]; do
+               while test $nr -lt $number_of_commits
+               do
                        nr=$(($nr+1))
                        mark=$(($nr+$nr))
                        notemark=$(($mark+1))
                        test_tick &&
-                       cat <<INPUT_END &&
-commit refs/heads/master
-mark :$mark
-committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
-data <<COMMIT
-commit #$nr
-COMMIT
-
-M 644 inline file
-data <<EOF
-file in commit #$nr
-EOF
-
-blob
-mark :$notemark
-data <<EOF
-note for commit #$nr
-EOF
-
-INPUT_END
-
-                       echo "N :$notemark :$mark" >> note_commit
+                       cat <<-INPUT_END &&
+                       commit refs/heads/master
+                       mark :$mark
+                       committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+                       data <<COMMIT
+                       commit #$nr
+                       COMMIT
+
+                       M 644 inline file
+                       data <<EOF
+                       file in commit #$nr
+                       EOF
+
+                       blob
+                       mark :$notemark
+                       data <<EOF
+                       note for commit #$nr
+                       EOF
+
+                       INPUT_END
+                       echo "N :$notemark :$mark" >>note_commit
                done &&
                test_tick &&
-               cat <<INPUT_END &&
-commit refs/notes/commits
-committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
-data <<COMMIT
-notes
-COMMIT
+               cat <<-INPUT_END &&
+               commit refs/notes/commits
+               committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+               data <<COMMIT
+               notes
+               COMMIT
 
-INPUT_END
+               INPUT_END
 
                cat note_commit
        ) |
@@ -65,62 +63,74 @@ INPUT_END
 test_notes () {
        count=$1 &&
        git config core.notesRef refs/notes/commits &&
-       git log | grep "^    " > output &&
+       git log | grep "^    " >output &&
        i=$count &&
-       while [ $i -gt 0 ]; do
+       while test $i -gt 0
+       do
                echo "    commit #$i" &&
                echo "    note for commit #$i" &&
-               i=$(($i-1));
-       done > expect &&
+               i=$(($i-1))
+       done >expect &&
        test_cmp expect output
 }
 
-cat > time_notes << \EOF
+write_script time_notes <<\EOF
        mode=$1
        i=1
-       while [ $i -lt $2 ]; do
+       while test $i -lt $2
+       do
                case $1 in
                no-notes)
-                       GIT_NOTES_REF=non-existing; export GIT_NOTES_REF
-               ;;
+                       GIT_NOTES_REF=non-existing
+                       export GIT_NOTES_REF
+                       ;;
                notes)
                        unset GIT_NOTES_REF
-               ;;
+                       ;;
                esac
-               git log >/dev/null
+               git log
                i=$(($i+1))
-       done
+       done >/dev/null
 EOF
 
 time_notes () {
        for mode in no-notes notes
        do
                echo $mode
-               /usr/bin/time "$SHELL_PATH" ../time_notes $mode $1
+               /usr/bin/time ../time_notes $mode $1
        done
 }
 
 do_tests () {
-       pr=$1
-       count=$2
-
-       test_expect_success $pr 'setup / mkdir' '
-               mkdir $count &&
-               cd $count
+       count=$1 pr=${2-}
+
+       test_expect_success $pr "setup $count" '
+               mkdir "$count" &&
+               (
+                       cd "$count" &&
+                       create_repo "$count"
+               )
        '
 
-       test_expect_success $pr "setup $count" "create_repo $count"
-
-       test_expect_success $pr 'notes work' "test_notes $count"
-
-       test_expect_success USR_BIN_TIME,$pr 'notes timing with /usr/bin/time' "time_notes 100"
+       test_expect_success $pr 'notes work' '
+               (
+                       cd "$count" &&
+                       test_notes "$count"
+               )
+       '
 
-       test_expect_success $pr 'teardown / cd ..' 'cd ..'
+       test_expect_success "USR_BIN_TIME${pr:+,$pr}" 'notes timing with /usr/bin/time' '
+               (
+                       cd "$count" &&
+                       time_notes 100
+               )
+       '
 }
 
-do_tests NOT_EXPENSIVE 10
-for count in 100 1000 10000; do
-       do_tests EXPENSIVE $count
+do_tests 10
+for count in 100 1000 10000
+do
+       do_tests "$count" EXPENSIVE
 done
 
 test_done
index be8c1d5ef9fd650c128a9fe7126cbcd8db6c5a95..5a27ec9b5eb7c37145a098d878432948233ba756 100755 (executable)
@@ -33,6 +33,7 @@ test_expect_success setup '
        tr "[a-z]" "[A-Z]" <original >newfile &&
        git add newfile &&
        git commit -a -m"side edits further." &&
+       git branch second-side &&
 
        tr "[a-m]" "[A-M]" <original >newfile &&
        rm -f original &&
@@ -41,6 +42,7 @@ test_expect_success setup '
        git branch test-rebase side &&
        git branch test-rebase-pick side &&
        git branch test-reference-pick side &&
+       git branch test-conflicts side &&
        git checkout -b test-merge side
 '
 
@@ -138,4 +140,17 @@ test_expect_success 'rebase -s funny -Xopt' '
        test -f funny.was.run
 '
 
+test_expect_success 'rebase --skip works with two conflicts in a row' '
+       git checkout second-side  &&
+       tr "[A-Z]" "[a-z]" <newfile >tmp &&
+       mv tmp newfile &&
+       git commit -a -m"edit conflicting with side" &&
+       tr "[d-f]" "[D-F]" <newfile >tmp &&
+       mv tmp newfile &&
+       git commit -a -m"another edit conflicting with side" &&
+       test_must_fail git rebase --merge test-conflicts &&
+       test_must_fail git rebase --skip &&
+       git rebase --skip
+'
+
 test_done
index c0023a5b4ff6ef60f5d77e9e54a64adf387bce6e..8197ed29a9ecedb43679200f1485a7b50984fdff 100755 (executable)
@@ -67,6 +67,14 @@ test_expect_success 'setup' '
 SHELL=
 export SHELL
 
+test_expect_success 'rebase --keep-empty' '
+       git checkout -b emptybranch master &&
+       git commit --allow-empty -m "empty" &&
+       git rebase --keep-empty -i HEAD~2 &&
+       git log --oneline >actual &&
+       test_line_count = 6 actual
+'
+
 test_expect_success 'rebase -i with the exec command' '
        git checkout master &&
        (
index e70ac10a0cdbcd112b7b3c3e74aa89b09d46d1df..9292b499f39925b6832bccd826fb43a8818f155a 100755 (executable)
@@ -4,12 +4,9 @@ test_description='git rebase - test patch id computation'
 
 . ./test-lib.sh
 
-test_set_prereq NOT_EXPENSIVE
 test -n "$GIT_PATCHID_TIMING_TESTS" && test_set_prereq EXPENSIVE
-test -x /usr/bin/time && test_set_prereq USR_BIN_TIME
 
-count()
-{
+count () {
        i=0
        while test $i -lt $1
        do
@@ -18,8 +15,7 @@ count()
        done
 }
 
-scramble()
-{
+scramble () {
        i=0
        while read x
        do
@@ -28,12 +24,11 @@ scramble()
                        echo "$x"
                fi
                i=$((($i+1) % 10))
-       done < "$1" > "$1.new"
+       done <"$1" >"$1.new"
        mv -f "$1.new" "$1"
 }
 
-run()
-{
+run () {
        echo \$ "$@"
        /usr/bin/time "$@" >/dev/null
 }
@@ -43,10 +38,8 @@ test_expect_success 'setup' '
        git tag root
 '
 
-do_tests()
-{
-       pr=$1
-       nlines=$2
+do_tests () {
+       nlines=$1 pr=${2-}
 
        test_expect_success $pr "setup: $nlines lines" "
                rm -f .gitattributes &&
@@ -103,7 +96,7 @@ do_tests()
        "
 }
 
-do_tests NOT_EXPENSIVE 500
-do_tests EXPENSIVE 50000
+do_tests 500
+do_tests 50000 EXPENSIVE
 
 test_done
index 19c99d7ef1bc02e67a7b995206b9f66c04c1b31c..b457333e1865de794e47fa6b601648fd67a02a7c 100755 (executable)
@@ -65,12 +65,15 @@ test_expect_success 'output to keep user entertained during multi-pick' '
        cat <<-\EOF >expected &&
        [master OBJID] second
         Author: A U Thor <author@example.com>
+        Date: Thu Apr 7 15:14:13 2005 -0700
         1 file changed, 1 insertion(+)
        [master OBJID] third
         Author: A U Thor <author@example.com>
+        Date: Thu Apr 7 15:15:13 2005 -0700
         1 file changed, 1 insertion(+)
        [master OBJID] fourth
         Author: A U Thor <author@example.com>
+        Date: Thu Apr 7 15:16:13 2005 -0700
         1 file changed, 1 insertion(+)
        EOF
 
@@ -98,14 +101,17 @@ test_expect_success 'output during multi-pick indicates merge strategy' '
        Trying simple merge.
        [master OBJID] second
         Author: A U Thor <author@example.com>
+        Date: Thu Apr 7 15:14:13 2005 -0700
         1 file changed, 1 insertion(+)
        Trying simple merge.
        [master OBJID] third
         Author: A U Thor <author@example.com>
+        Date: Thu Apr 7 15:15:13 2005 -0700
         1 file changed, 1 insertion(+)
        Trying simple merge.
        [master OBJID] fourth
         Author: A U Thor <author@example.com>
+        Date: Thu Apr 7 15:16:13 2005 -0700
         1 file changed, 1 insertion(+)
        EOF
 
index a5e7e6b2ba3138d06c400e965decf1389da3274a..f372fc8ca8e3b311b03313a46db1aa8f35de2ea9 100755 (executable)
@@ -96,8 +96,8 @@ test_expect_success 'stash pop after save --include-untracked leaves files untra
        git stash pop &&
        git status --porcelain >actual &&
        test_cmp expect actual &&
-       test "1" = "`cat file2`" &&
-       test untracked = "`cat untracked/untracked`"
+       test "1" = "$(cat file2)" &&
+       test untracked = "$(cat untracked/untracked)"
 '
 
 git clean --force --quiet -d
index e4ba6013e41927bc0ec3ff3876648a71a71ce6e1..831935665e012c04bbe4c57feee92c0310df5c04 100755 (executable)
@@ -14,13 +14,13 @@ then
 fi
 
 # create utf-8 variables
-Adiarnfc=`printf '\303\204'`
-Adiarnfd=`printf 'A\314\210'`
+Adiarnfc=$(printf '\303\204')
+Adiarnfd=$(printf 'A\314\210')
 
-Odiarnfc=`printf '\303\226'`
-Odiarnfd=`printf 'O\314\210'`
-AEligatu=`printf '\303\206'`
-Invalidu=`printf '\303\377'`
+Odiarnfc=$(printf '\303\226')
+Odiarnfd=$(printf 'O\314\210')
+AEligatu=$(printf '\303\206')
+Invalidu=$(printf '\303\377')
 
 
 #Create a string with 255 bytes (decomposed)
@@ -35,7 +35,7 @@ Alongc=$Alongc$Alongc$Alongc$Alongc$Alongc           #250 Byte
 Alongc=$Alongc$AEligatu$AEligatu                     #254 Byte
 
 test_expect_success "detect if nfd needed" '
-       precomposeunicode=`git config core.precomposeunicode` &&
+       precomposeunicode=$(git config core.precomposeunicode) &&
        test "$precomposeunicode" = true &&
        git config core.precomposeunicode true
 '
@@ -140,13 +140,23 @@ test_expect_success "Add long precomposed filename" '
        git add * &&
        git commit -m "Long filename"
 '
+
+test_expect_failure 'handle existing decomposed filenames' '
+       echo content >"verbatim.$Adiarnfd" &&
+       git -c core.precomposeunicode=false add "verbatim.$Adiarnfd" &&
+       git commit -m "existing decomposed file" &&
+       >expect &&
+       git ls-files --exclude-standard -o "verbatim*" >untracked &&
+       test_cmp expect untracked
+'
+
 # Test if the global core.precomposeunicode stops autosensing
 # Must be the last test case
 test_expect_success "respect git config --global core.precomposeunicode" '
        git config --global core.precomposeunicode true &&
        rm -rf .git &&
        git init &&
-       precomposeunicode=`git config core.precomposeunicode` &&
+       precomposeunicode=$(git config core.precomposeunicode) &&
        test "$precomposeunicode" = "true"
 '
 
index 05911492ca6df386bfe344ffcfb9562beeaceabf..76f643b2c2a2c7e307135de6942cf46743b6cbef 100755 (executable)
@@ -13,7 +13,7 @@ sed_script='s/\(:100644 100755\) \('"$_x40"'\) \2 /\1 X X /'
 test_expect_success 'setup' '
        echo frotz >rezrov &&
        git update-index --add rezrov &&
-       tree=`git write-tree` &&
+       tree=$(git write-tree) &&
        echo $tree
 '
 
index 2bb973655bf043cc43292764ffd68becda25aa2e..bf078418662c4bab4e512be8fc22a5aa76466119 100755 (executable)
@@ -18,7 +18,7 @@ test_expect_success \
      mkdir path1 &&
      echo rezrov >path1/file1 &&
      git update-index --add file0 path1/file1 &&
-     tree=`git write-tree` &&
+     tree=$(git write-tree) &&
      echo "$tree" &&
      echo nitfol >file0 &&
      echo yomin >path1/file1 &&
@@ -131,7 +131,7 @@ test_expect_success 'diff multiple wildcard pathspecs' '
        mkdir path2 &&
        echo rezrov >path2/file1 &&
        git update-index --add path2/file1 &&
-       tree3=`git write-tree` &&
+       tree3=$(git write-tree) &&
        git diff --name-only $tree $tree3 -- "path2*1" "path1*1" >actual &&
        cat <<-\EOF >expect &&
        path1/file1
index 1215ae544b6915fe2cc6df4d193c8f3a805beba1..643d729157d23ce501258710640e4090c34922fc 100755 (executable)
@@ -67,18 +67,18 @@ test_expect_success C_LOCALE_OUTPUT 'apply detecting corrupt patch correctly' '
        git diff >output &&
        sed -e "s/-CIT/xCIT/" <output >broken &&
        test_must_fail git apply --stat --summary broken 2>detected &&
-       detected=`cat detected` &&
-       detected=`expr "$detected" : "fatal.*at line \\([0-9]*\\)\$"` &&
-       detected=`sed -ne "${detected}p" broken` &&
+       detected=$(cat detected) &&
+       detected=$(expr "$detected" : "fatal.*at line \\([0-9]*\\)\$") &&
+       detected=$(sed -ne "${detected}p" broken) &&
        test "$detected" = xCIT
 '
 
 test_expect_success C_LOCALE_OUTPUT 'apply detecting corrupt patch correctly' '
        git diff --binary | sed -e "s/-CIT/xCIT/" >broken &&
        test_must_fail git apply --stat --summary broken 2>detected &&
-       detected=`cat detected` &&
-       detected=`expr "$detected" : "fatal.*at line \\([0-9]*\\)\$"` &&
-       detected=`sed -ne "${detected}p" broken` &&
+       detected=$(cat detected) &&
+       detected=$(expr "$detected" : "fatal.*at line \\([0-9]*\\)\$") &&
+       detected=$(sed -ne "${detected}p" broken) &&
        test "$detected" = xCIT
 '
 
@@ -88,7 +88,7 @@ test_expect_success 'initial commit' 'git commit -a -m initial'
 test_expect_success 'diff-index with --binary' '
        echo AIT >a && mv b e && echo CIT >c && cat e >d &&
        git update-index --add --remove a b c d e &&
-       tree0=`git write-tree` &&
+       tree0=$(git write-tree) &&
        git diff --cached --binary >current &&
        git apply --stat --summary current
 '
@@ -96,7 +96,7 @@ test_expect_success 'diff-index with --binary' '
 test_expect_success 'apply binary patch' '
        git reset --hard &&
        git apply --binary --index <current &&
-       tree1=`git write-tree` &&
+       tree1=$(git write-tree) &&
        test "$tree1" = "$tree0"
 '
 
index e77c09c37eede2f039610199ba8e3c45e94213d4..805b055c899e7c9f5653eb740572f67417c9dcb6 100755 (executable)
@@ -107,14 +107,14 @@ test_expect_success setup '
 +*++ [initial] Initial
 EOF
 
-V=`git version | sed -e 's/^git version //' -e 's/\./\\./g'`
+V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g')
 while read cmd
 do
        case "$cmd" in
        '' | '#'*) continue ;;
        esac
-       test=`echo "$cmd" | sed -e 's|[/ ][/ ]*|_|g'`
-       pfx=`printf "%04d" $test_count`
+       test=$(echo "$cmd" | sed -e 's|[/ ][/ ]*|_|g')
+       pfx=$(printf "%04d" $test_count)
        expect="$TEST_DIRECTORY/t4013/diff.$test"
        actual="$pfx-diff.$test"
 
index 9c8063314688ec0c03d3fb2099379cbbf4ff2e19..256affce89517a707f9054d2c9643db4f5398832 100755 (executable)
@@ -43,7 +43,7 @@ test_expect_success setup '
 test_expect_success "format-patch --ignore-if-in-upstream" '
 
        git format-patch --stdout master..side >patch0 &&
-       cnt=`grep "^From " patch0 | wc -l` &&
+       cnt=$(grep "^From " patch0 | wc -l) &&
        test $cnt = 3
 
 '
@@ -52,7 +52,7 @@ test_expect_success "format-patch --ignore-if-in-upstream" '
 
        git format-patch --stdout \
                --ignore-if-in-upstream master..side >patch1 &&
-       cnt=`grep "^From " patch1 | wc -l` &&
+       cnt=$(grep "^From " patch1 | wc -l) &&
        test $cnt = 2
 
 '
@@ -69,7 +69,7 @@ test_expect_success "format-patch doesn't consider merge commits" '
        git checkout -b merger master &&
        test_tick &&
        git merge --no-ff slave &&
-       cnt=`git format-patch -3 --stdout | grep "^From " | wc -l` &&
+       cnt=$(git format-patch -3 --stdout | grep "^From " | wc -l) &&
        test $cnt = 3
 '
 
@@ -77,7 +77,7 @@ test_expect_success "format-patch result applies" '
 
        git checkout -b rebuild-0 master &&
        git am -3 patch0 &&
-       cnt=`git rev-list master.. | wc -l` &&
+       cnt=$(git rev-list master.. | wc -l) &&
        test $cnt = 2
 '
 
@@ -85,7 +85,7 @@ test_expect_success "format-patch --ignore-if-in-upstream result applies" '
 
        git checkout -b rebuild-1 master &&
        git am -3 patch1 &&
-       cnt=`git rev-list master.. | wc -l` &&
+       cnt=$(git rev-list master.. | wc -l) &&
        test $cnt = 2
 '
 
@@ -762,6 +762,67 @@ test_expect_success 'format-patch --signature="" suppresses signatures' '
        ! grep "^-- \$" output
 '
 
+test_expect_success 'prepare mail-signature input' '
+       cat >mail-signature <<-\EOF
+
+       Test User <test.email@kernel.org>
+       http://git.kernel.org/cgit/git/git.git
+
+       git.kernel.org/?p=git/git.git;a=summary
+
+       EOF
+'
+
+test_expect_success '--signature-file=file works' '
+       git format-patch --stdout --signature-file=mail-signature -1 >output &&
+       check_patch output &&
+       sed -e "1,/^-- \$/d" <output >actual &&
+       {
+               cat mail-signature && echo
+       } >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success 'format.signaturefile works' '
+       test_config format.signaturefile mail-signature &&
+       git format-patch --stdout -1 >output &&
+       check_patch output &&
+       sed -e "1,/^-- \$/d" <output >actual &&
+       {
+               cat mail-signature && echo
+       } >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success '--no-signature suppresses format.signaturefile ' '
+       test_config format.signaturefile mail-signature &&
+       git format-patch --stdout --no-signature -1 >output &&
+       check_patch output &&
+       ! grep "^-- \$" output
+'
+
+test_expect_success '--signature-file overrides format.signaturefile' '
+       cat >other-mail-signature <<-\EOF
+       Use this other signature instead of mail-signature.
+       EOF
+       test_config format.signaturefile mail-signature &&
+       git format-patch --stdout \
+                       --signature-file=other-mail-signature -1 >output &&
+       check_patch output &&
+       sed -e "1,/^-- \$/d" <output >actual &&
+       {
+               cat other-mail-signature && echo
+       } >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success '--signature overrides format.signaturefile' '
+       test_config format.signaturefile mail-signature &&
+       git format-patch --stdout --signature="my sig" -1 >output &&
+       check_patch output &&
+       grep "my sig" output
+'
+
 test_expect_success TTY 'format-patch --stdout paginates' '
        rm -f pager_used &&
        test_terminal env GIT_PAGER="wc >pager_used" git format-patch --stdout --all &&
index ba43f185494630c50fc2a168df8dcd45c0b2421b..98d9713d8b2454eb1dfc4f137133a7cb0174bd0d 100755 (executable)
@@ -42,7 +42,7 @@ test_expect_success 'attach and signoff do not duplicate mime headers' '
 
        GIT_COMMITTER_NAME="はまの ふにおう" \
        git format-patch -s --stdout -1 --attach >output &&
-       test `grep -ci ^MIME-Version: output` = 1
+       test $(grep -ci ^MIME-Version: output) = 1
 
 '
 
index 1019d7b35fcb350761a44cf4ccd5ae156ce8d577..41913c3aa30de6d55b016fa9331e0877579b2d6b 100755 (executable)
@@ -94,7 +94,7 @@ test_expect_success 'setup for --cc --raw' '
        blob=$(echo file | git hash-object --stdin -w) &&
        base_tree=$(echo "100644 blob $blob     file" | git mktree) &&
        trees= &&
-       for i in `test_seq 1 40`
+       for i in $(test_seq 1 40)
        do
                blob=$(echo file$i | git hash-object --stdin -w) &&
                trees="$trees$(echo "100644 blob $blob  file" | git mktree)$LF"
index 097e63215e1ffc349ae9e3803f953aa70882b6a4..dff36b77ec8856573da26685376d156d49f8e021 100755 (executable)
@@ -5,7 +5,7 @@ test_description='combined diff show only paths that are different to all parent
 . ./test-lib.sh
 
 # verify that diffc.expect matches output of
-# `git diff -c --name-only HEAD HEAD^ HEAD^2`
+# $(git diff -c --name-only HEAD HEAD^ HEAD^2)
 diffc_verify () {
        git diff -c --name-only HEAD HEAD^ HEAD^2 >diffc.actual &&
        test_cmp diffc.expect diffc.actual
index 49e2d6c34983c7e4620739a52ecc03cf158efe3a..fae305979a88614bdf33963936d3fce32df83b8c 100755 (executable)
@@ -52,6 +52,6 @@ EOF
 
 test_expect_success 'apply copy' \
     'git apply --index --stat --summary --apply test-patch &&
-     test "$(cat bar)" = "This is bar" -a "$(cat foo)" = "This is foo"'
+     test "$(cat bar)" = "This is bar" && test "$(cat foo)" = "This is foo"'
 
 test_done
index 1e4d4380bf01c081aeb1df44cef40319063f2faa..ce8567f496438c18501f30632269ecbe7de15fd3 100755 (executable)
@@ -30,10 +30,10 @@ test_expect_success setup '
 
 test_expect_success 'apply in forward' '
 
-       T0=`git rev-parse "second^{tree}"` &&
+       T0=$(git rev-parse "second^{tree}") &&
        git reset --hard initial &&
        git apply --index --binary patch &&
-       T1=`git write-tree` &&
+       T1=$(git write-tree) &&
        test "$T0" = "$T1"
 '
 
@@ -62,22 +62,22 @@ test_expect_success 'setup separate repository lacking postimage' '
 
 test_expect_success 'apply in forward without postimage' '
 
-       T0=`git rev-parse "second^{tree}"` &&
+       T0=$(git rev-parse "second^{tree}") &&
        (
                cd initial &&
                git apply --index --binary ../patch &&
-               T1=`git write-tree` &&
+               T1=$(git write-tree) &&
                test "$T0" = "$T1"
        )
 '
 
 test_expect_success 'apply in reverse without postimage' '
 
-       T0=`git rev-parse "initial^{tree}"` &&
+       T0=$(git rev-parse "initial^{tree}") &&
        (
                cd second &&
                git apply --index --binary --reverse ../patch &&
-               T1=`git write-tree` &&
+               T1=$(git write-tree) &&
                test "$T0" = "$T1"
        )
 '
index 3d0384daa8a7b7369826b05bcb793cb445c3f9ee..c393be691be42a0b0a982c07ffeee489d4075bce 100755 (executable)
@@ -68,7 +68,7 @@ test_expect_success 'apply --whitespace=strip from config' '
        check_result sub/file1
 '
 
-D=`pwd`
+D=$(pwd)
 
 test_expect_success 'apply --whitespace=strip in subdir' '
 
index d2c930de87f721a0e876351e511295ae0b094108..baa9d3c82e8a54dc7501d90bc9da0527f2a72b2e 100755 (executable)
@@ -5,27 +5,44 @@ test_description='git patch-id'
 . ./test-lib.sh
 
 test_expect_success 'setup' '
-       test_commit initial foo a &&
-       test_commit first foo b &&
-       git checkout -b same HEAD^ &&
-       test_commit same-msg foo b &&
-       git checkout -b notsame HEAD^ &&
-       test_commit notsame-msg foo c
+       as="a a a a a a a a" && # eight a
+       test_write_lines $as >foo &&
+       test_write_lines $as >bar &&
+       git add foo bar &&
+       git commit -a -m initial &&
+       test_write_lines $as b >foo &&
+       test_write_lines $as b >bar &&
+       git commit -a -m first &&
+       git checkout -b same master &&
+       git commit --amend -m same-msg &&
+       git checkout -b notsame master &&
+       echo c >foo &&
+       echo c >bar &&
+       git commit --amend -a -m notsame-msg &&
+       test_write_lines bar foo >bar-then-foo &&
+       test_write_lines foo bar >foo-then-bar
 '
 
 test_expect_success 'patch-id output is well-formed' '
-       git log -p -1 | git patch-id > output &&
+       git log -p -1 | git patch-id >output &&
        grep "^[a-f0-9]\{40\} $(git rev-parse HEAD)$" output
 '
 
+#calculate patch id. Make sure output is not empty.
 calc_patch_id () {
-       git patch-id |
-               sed "s# .*##" > patch-id_"$1"
+       name="$1"
+       shift
+       git patch-id "$@" |
+       sed "s/ .*//" >patch-id_"$name" &&
+       test_line_count -gt 0 patch-id_"$name"
+}
+
+get_top_diff () {
+       git log -p -1 "$@" -O bar-then-foo --
 }
 
 get_patch_id () {
-       git log -p -1 "$1" | git patch-id |
-               sed "s# .*##" > patch-id_"$1"
+       get_top_diff "$1" | calc_patch_id "$@"
 }
 
 test_expect_success 'patch-id detects equality' '
@@ -45,8 +62,8 @@ test_expect_success 'patch-id supports git-format-patch output' '
        git checkout same &&
        git format-patch -1 --stdout | calc_patch_id same &&
        test_cmp patch-id_master patch-id_same &&
-       set `git format-patch -1 --stdout | git patch-id` &&
-       test "$2" = `git rev-parse HEAD`
+       set $(git format-patch -1 --stdout | git patch-id) &&
+       test "$2" = $(git rev-parse HEAD)
 '
 
 test_expect_success 'whitespace is irrelevant in footer' '
@@ -56,6 +73,69 @@ test_expect_success 'whitespace is irrelevant in footer' '
        test_cmp patch-id_master patch-id_same
 '
 
+cmp_patch_id () {
+       if
+               test "$1" = "relevant"
+       then
+               ! test_cmp patch-id_"$2" patch-id_"$3"
+       else
+               test_cmp patch-id_"$2" patch-id_"$3"
+       fi
+}
+
+test_patch_id_file_order () {
+       relevant="$1"
+       shift
+       name="order-${1}-$relevant"
+       shift
+       get_top_diff "master" | calc_patch_id "$name" "$@" &&
+       git checkout same &&
+       git format-patch -1 --stdout -O foo-then-bar |
+               calc_patch_id "ordered-$name" "$@" &&
+       cmp_patch_id $relevant "$name" "ordered-$name"
+
+}
+
+# combined test for options: add more tests here to make them
+# run with all options
+test_patch_id () {
+       test_patch_id_file_order "$@"
+}
+
+# small tests with detailed diagnostic for basic options.
+test_expect_success 'file order is irrelevant with --stable' '
+       test_patch_id_file_order irrelevant --stable --stable
+'
+
+test_expect_success 'file order is relevant with --unstable' '
+       test_patch_id_file_order relevant --unstable --unstable
+'
+
+#Now test various option combinations.
+test_expect_success 'default is unstable' '
+       test_patch_id relevant default
+'
+
+test_expect_success 'patchid.stable = true is stable' '
+       test_config patchid.stable true &&
+       test_patch_id irrelevant patchid.stable=true
+'
+
+test_expect_success 'patchid.stable = false is unstable' '
+       test_config patchid.stable false &&
+       test_patch_id relevant patchid.stable=false
+'
+
+test_expect_success '--unstable overrides patchid.stable = true' '
+       test_config patchid.stable true &&
+       test_patch_id relevant patchid.stable=true--unstable --unstable
+'
+
+test_expect_success '--stable overrides patchid.stable = false' '
+       test_config patchid.stable false &&
+       test_patch_id irrelevant patchid.stable=false--stable --stable
+'
+
 test_expect_success 'patch-id supports git-format-patch MIME output' '
        get_patch_id master &&
        git checkout same &&
index 1cf0a4e10301fe1bbfb3acced0c010da7b8df7f8..7b8babd89b22dc94d3a3f839d72cce86c5aaea59 100755 (executable)
@@ -72,7 +72,7 @@ check_tar() {
                        for header in *.paxheader
                        do
                                data=${header%.paxheader}.data &&
-                               if test -h $data -o -e $data
+                               if test -h $data || test -e $data
                                then
                                        path=$(get_pax_header $header path) &&
                                        if test -n "$path"
@@ -119,14 +119,10 @@ test_expect_success \
     'echo ignore me >a/ignored &&
      echo ignored export-ignore >.git/info/attributes'
 
-test_expect_success \
-    'add files to repository' \
-    'find a -type f | xargs git update-index --add &&
-     find a -type l | xargs git update-index --add &&
-     treeid=`git write-tree` &&
-     echo $treeid >treeid &&
-     git update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \
-     git commit-tree $treeid </dev/null)'
+test_expect_success 'add files to repository' '
+       git add a &&
+       GIT_COMMITTER_DATE="2005-05-27 22:00" git commit -m initial
+'
 
 test_expect_success 'setup export-subst' '
        echo "substfile?" export-subst >>.git/info/attributes &&
@@ -164,7 +160,7 @@ check_tar with_olde-prefix olde-
 test_expect_success 'git archive on large files' '
     test_config core.bigfilethreshold 1 &&
     git archive HEAD >b3.tar &&
-    test_cmp b.tar b3.tar
+    test_cmp_bin b.tar b3.tar
 '
 
 test_expect_success \
@@ -173,15 +169,15 @@ test_expect_success \
 
 test_expect_success \
     'git archive vs. the same in a bare repo' \
-    'test_cmp b.tar b3.tar'
+    'test_cmp_bin b.tar b3.tar'
 
 test_expect_success 'git archive with --output' \
     'git archive --output=b4.tar HEAD &&
-    test_cmp b.tar b4.tar'
+    test_cmp_bin b.tar b4.tar'
 
 test_expect_success 'git archive --remote' \
     'git archive --remote=. HEAD >b5.tar &&
-    test_cmp b.tar b5.tar'
+    test_cmp_bin b.tar b5.tar'
 
 test_expect_success \
     'validate file modification time' \
@@ -198,7 +194,7 @@ test_expect_success \
 
 test_expect_success 'git archive with --output, override inferred format' '
        git archive --format=tar --output=d4.zip HEAD &&
-       test_cmp b.tar d4.zip
+       test_cmp_bin b.tar d4.zip
 '
 
 test_expect_success \
@@ -207,7 +203,7 @@ test_expect_success \
 
 test_expect_success 'clients cannot access unreachable commits' '
        test_commit unreachable &&
-       sha1=`git rev-parse HEAD` &&
+       sha1=$(git rev-parse HEAD) &&
        git reset --hard HEAD^ &&
        git archive $sha1 >remote.tar &&
        test_must_fail git archive --remote=. $sha1 >remote.tar
@@ -215,7 +211,7 @@ test_expect_success 'clients cannot access unreachable commits' '
 
 test_expect_success 'upload-archive can allow unreachable commits' '
        test_commit unreachable1 &&
-       sha1=`git rev-parse HEAD` &&
+       sha1=$(git rev-parse HEAD) &&
        git reset --hard HEAD^ &&
        git archive $sha1 >remote.tar &&
        test_config uploadarchive.allowUnreachable true &&
@@ -244,34 +240,34 @@ test_expect_success 'archive --list shows only enabled remote filters' '
 test_expect_success 'invoke tar filter by format' '
        git archive --format=tar.foo HEAD >config.tar.foo &&
        tr ab ba <config.tar.foo >config.tar &&
-       test_cmp b.tar config.tar &&
+       test_cmp_bin b.tar config.tar &&
        git archive --format=bar HEAD >config.bar &&
        tr ab ba <config.bar >config.tar &&
-       test_cmp b.tar config.tar
+       test_cmp_bin b.tar config.tar
 '
 
 test_expect_success 'invoke tar filter by extension' '
        git archive -o config-implicit.tar.foo HEAD &&
-       test_cmp config.tar.foo config-implicit.tar.foo &&
+       test_cmp_bin config.tar.foo config-implicit.tar.foo &&
        git archive -o config-implicit.bar HEAD &&
-       test_cmp config.tar.foo config-implicit.bar
+       test_cmp_bin config.tar.foo config-implicit.bar
 '
 
 test_expect_success 'default output format remains tar' '
        git archive -o config-implicit.baz HEAD &&
-       test_cmp b.tar config-implicit.baz
+       test_cmp_bin b.tar config-implicit.baz
 '
 
 test_expect_success 'extension matching requires dot' '
        git archive -o config-implicittar.foo HEAD &&
-       test_cmp b.tar config-implicittar.foo
+       test_cmp_bin b.tar config-implicittar.foo
 '
 
 test_expect_success 'only enabled filters are available remotely' '
        test_must_fail git archive --remote=. --format=tar.foo HEAD \
                >remote.tar.foo &&
        git archive --remote=. --format=bar >remote.bar HEAD &&
-       test_cmp remote.bar config.bar
+       test_cmp_bin remote.bar config.bar
 '
 
 test_expect_success GZIP 'git archive --format=tgz' '
@@ -280,27 +276,27 @@ test_expect_success GZIP 'git archive --format=tgz' '
 
 test_expect_success GZIP 'git archive --format=tar.gz' '
        git archive --format=tar.gz HEAD >j1.tar.gz &&
-       test_cmp j.tgz j1.tar.gz
+       test_cmp_bin j.tgz j1.tar.gz
 '
 
 test_expect_success GZIP 'infer tgz from .tgz filename' '
        git archive --output=j2.tgz HEAD &&
-       test_cmp j.tgz j2.tgz
+       test_cmp_bin j.tgz j2.tgz
 '
 
 test_expect_success GZIP 'infer tgz from .tar.gz filename' '
        git archive --output=j3.tar.gz HEAD &&
-       test_cmp j.tgz j3.tar.gz
+       test_cmp_bin j.tgz j3.tar.gz
 '
 
 test_expect_success GZIP 'extract tgz file' '
        gzip -d -c <j.tgz >j.tar &&
-       test_cmp b.tar j.tar
+       test_cmp_bin b.tar j.tar
 '
 
 test_expect_success GZIP 'remote tar.gz is allowed by default' '
        git archive --remote=. --format=tar.gz HEAD >remote.tar.gz &&
-       test_cmp j.tgz remote.tar.gz
+       test_cmp_bin j.tgz remote.tar.gz
 '
 
 test_expect_success GZIP 'remote tar.gz can be disabled' '
index 51dedab29b682749990fb29a3f11134a2629f941..b04d955bfa8229a9c864ad53d1f9f1ec06260637 100755 (executable)
@@ -68,7 +68,7 @@ test_expect_missing   worktree2/ignored-by-worktree
 
 test_expect_success 'git archive vs. bare' '
        (cd bare && git archive HEAD) >bare-archive.tar &&
-       test_cmp archive.tar bare-archive.tar
+       test_cmp_bin archive.tar bare-archive.tar
 '
 
 test_expect_success 'git archive with worktree attributes, bare' '
index c72f71eb18ee90b7885ea2af574e1115154a5549..c929db563326614e01962b3e322f087640fa19d9 100755 (executable)
@@ -61,14 +61,10 @@ test_expect_success \
     'echo ignore me >a/ignored &&
      echo ignored export-ignore >.git/info/attributes'
 
-test_expect_success \
-    'add files to repository' \
-    'find a -type f | xargs git update-index --add &&
-     find a -type l | xargs git update-index --add &&
-     treeid=`git write-tree` &&
-     echo $treeid >treeid &&
-     git update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \
-     git commit-tree $treeid </dev/null)'
+test_expect_success 'add files to repository' '
+       git add a &&
+       GIT_COMMITTER_DATE="2005-05-27 22:00" git commit -m initial
+'
 
 test_expect_success 'setup export-subst' '
        echo "substfile?" export-subst >>.git/info/attributes &&
@@ -97,15 +93,15 @@ test_expect_success \
 
 test_expect_success \
     'git archive --format=zip vs. the same in a bare repo' \
-    'test_cmp d.zip d1.zip'
+    'test_cmp_bin d.zip d1.zip'
 
 test_expect_success 'git archive --format=zip with --output' \
     'git archive --format=zip --output=d2.zip HEAD &&
-    test_cmp d.zip d2.zip'
+    test_cmp_bin d.zip d2.zip'
 
 test_expect_success 'git archive with --output, inferring format' '
        git archive --output=d3.zip HEAD &&
-       test_cmp d.zip d3.zip
+       test_cmp_bin d.zip d3.zip
 '
 
 test_expect_success \
index 67f3b54bed3545417d1f6186f6f42452cb55dc87..305bcac6b765111106887d4d24d99657c0554b5b 100755 (executable)
@@ -45,7 +45,7 @@ test_expect_success HEADER_ONLY_TAR_OK 'tar archive of commit with empty tree' '
 test_expect_success 'tar archive of empty tree is empty' '
        git archive --format=tar HEAD: >empty.tar &&
        perl -e "print \"\\0\" x 10240" >10knuls.tar &&
-       test_cmp 10knuls.tar empty.tar
+       test_cmp_bin 10knuls.tar empty.tar
 '
 
 test_expect_success 'tar archive of empty tree with prefix' '
index 93e2c65de65f8dd8544332dd512e6d61dad1746c..82c33b88e710b5fb6163a7bdcd9ecb783633aa83 100755 (executable)
@@ -229,7 +229,7 @@ test_expect_success 'pull request format' '
                cd local &&
                git request-pull initial "$downstream_url" full
        ) >request &&
-       grep ' tags/full$'
+       grep " tags/full\$" request
 '
 
 test_expect_success 'request-pull ignores OPTIONS_KEEPDASHDASH poison' '
index f4f02ba918535d5c40a30585a54469bc12ab96d3..0580258c91a07aabe2773cce04df47d3c183b425 100755 (executable)
@@ -18,7 +18,7 @@ test_expect_success 'setup repo with moderate-sized history' '
        git checkout master &&
        blob=$(echo tagged-blob | git hash-object -w --stdin) &&
        git tag tagged-blob $blob &&
-       git config pack.writebitmaps true &&
+       git config repack.writebitmaps true &&
        git config pack.writebitmaphashcache true
 '
 
index 1753ef2b91e3e5846f12fc16e1209b1895210f3b..fc898c9eac704c934cfbef47fc1463f27dd50c6f 100755 (executable)
@@ -39,7 +39,7 @@ test_expect_success 'post-checkout receives the right arguments with HEAD unchan
        old=$(awk "{print \$1}" clone1/.git/post-checkout.args) &&
        new=$(awk "{print \$2}" clone1/.git/post-checkout.args) &&
        flag=$(awk "{print \$3}" clone1/.git/post-checkout.args) &&
-       test $old = $new -a $flag = 1
+       test $old = $new && test $flag = 1
 '
 
 test_expect_success 'post-checkout runs as expected ' '
@@ -52,7 +52,7 @@ test_expect_success 'post-checkout args are correct with git checkout -b ' '
        old=$(awk "{print \$1}" clone1/.git/post-checkout.args) &&
        new=$(awk "{print \$2}" clone1/.git/post-checkout.args) &&
        flag=$(awk "{print \$3}" clone1/.git/post-checkout.args) &&
-       test $old = $new -a $flag = 1
+       test $old = $new && test $flag = 1
 '
 
 test_expect_success 'post-checkout receives the right args with HEAD changed ' '
@@ -60,7 +60,7 @@ test_expect_success 'post-checkout receives the right args with HEAD changed ' '
        old=$(awk "{print \$1}" clone2/.git/post-checkout.args) &&
        new=$(awk "{print \$2}" clone2/.git/post-checkout.args) &&
        flag=$(awk "{print \$3}" clone2/.git/post-checkout.args) &&
-       test $old != $new -a $flag = 1
+       test $old != $new && test $flag = 1
 '
 
 test_expect_success 'post-checkout receives the right args when not switching branches ' '
@@ -68,7 +68,7 @@ test_expect_success 'post-checkout receives the right args when not switching br
        old=$(awk "{print \$1}" clone2/.git/post-checkout.args) &&
        new=$(awk "{print \$2}" clone2/.git/post-checkout.args) &&
        flag=$(awk "{print \$3}" clone2/.git/post-checkout.args) &&
-       test $old = $new -a $flag = 0
+       test $old = $new && test $flag = 0
 '
 
 if test "$(git config --bool core.filemode)" = true; then
index 29d59ef9fa2bf2bffb0075f07e03103387ab718e..d78f3201f423504bf5d53029492cc1bc056aab06 100755 (executable)
@@ -447,6 +447,43 @@ test_expect_success 'explicit pull should update tracking' '
        )
 '
 
+test_expect_success 'explicit --refmap is allowed only with command-line refspec' '
+       cd "$D" &&
+       (
+               cd three &&
+               test_must_fail git fetch --refmap="*:refs/remotes/none/*"
+       )
+'
+
+test_expect_success 'explicit --refmap option overrides remote.*.fetch' '
+       cd "$D" &&
+       git branch -f side &&
+       (
+               cd three &&
+               git update-ref refs/remotes/origin/master base-origin-master &&
+               o=$(git rev-parse --verify refs/remotes/origin/master) &&
+               git fetch --refmap="refs/heads/*:refs/remotes/other/*" origin master &&
+               n=$(git rev-parse --verify refs/remotes/origin/master) &&
+               test "$o" = "$n" &&
+               test_must_fail git rev-parse --verify refs/remotes/origin/side &&
+               git rev-parse --verify refs/remotes/other/master
+       )
+'
+
+test_expect_success 'explicitly empty --refmap option disables remote.*.fetch' '
+       cd "$D" &&
+       git branch -f side &&
+       (
+               cd three &&
+               git update-ref refs/remotes/origin/master base-origin-master &&
+               o=$(git rev-parse --verify refs/remotes/origin/master) &&
+               git fetch --refmap="" origin master &&
+               n=$(git rev-parse --verify refs/remotes/origin/master) &&
+               test "$o" = "$n" &&
+               test_must_fail git rev-parse --verify refs/remotes/origin/side
+       )
+'
+
 test_expect_success 'configured fetch updates tracking' '
 
        cd "$D" &&
index c28932216b1dd0893bc3c3a0a643963663ff8e1f..de6db86ccff044b5cc97a7b9236760076a8784d8 100755 (executable)
@@ -5,7 +5,6 @@ test_description='refspec parsing'
 . ./test-lib.sh
 
 test_refspec () {
-
        kind=$1 refspec=$2 expect=$3
        git config remote.frotz.url "." &&
        git config --remove-section remote.frotz &&
@@ -84,4 +83,9 @@ test_refspec push 'refs/heads/*/*/for-linus:refs/remotes/mine/*' invalid
 test_refspec fetch 'refs/heads/*/for-linus:refs/remotes/mine/*'
 test_refspec push 'refs/heads/*/for-linus:refs/remotes/mine/*'
 
+good=$(printf '\303\204')
+test_refspec fetch "refs/heads/${good}"
+bad=$(printf '\011tab')
+test_refspec fetch "refs/heads/${bad}"                         invalid
+
 test_done
index 1a3a2b6c1a20558a019143d1abbd2168af0caf53..ac71418a1b26bc17a1252d6831869b96a8d8c176 100755 (executable)
@@ -171,5 +171,30 @@ test_expect_success 'did not use upload-pack service' '
        test_cmp exp act
 '
 
+test_expect_success 'git client shows text/plain errors' '
+       test_must_fail git clone "$HTTPD_URL/error/text" 2>stderr &&
+       grep "this is the error message" stderr
+'
+
+test_expect_success 'git client does not show html errors' '
+       test_must_fail git clone "$HTTPD_URL/error/html" 2>stderr &&
+       ! grep "this is the error message" stderr
+'
+
+test_expect_success 'git client shows text/plain with a charset' '
+       test_must_fail git clone "$HTTPD_URL/error/charset" 2>stderr &&
+       grep "this is the error message" stderr
+'
+
+test_expect_success 'http error messages are reencoded' '
+       test_must_fail git clone "$HTTPD_URL/error/utf16" 2>stderr &&
+       grep "this is the error message" stderr
+'
+
+test_expect_success 'reencoding is robust to whitespace oddities' '
+       test_must_fail git clone "$HTTPD_URL/error/odd-spacing" 2>stderr &&
+       grep "this is the error message" stderr
+'
+
 stop_httpd
 test_done
index e07eaf35f118893da9240f12d115da1affd5eb05..6cbc12d9a7ad059f77967c0bdb702d8a5ec75bb9 100755 (executable)
@@ -213,8 +213,6 @@ test_expect_success 'cookies stored in http.cookiefile when http.savecookies set
        test_cmp expect_cookies.txt cookies_tail.txt
 '
 
-test -n "$GIT_TEST_LONG" && test_set_prereq EXPENSIVE
-
 test_expect_success EXPENSIVE 'create 50,000 tags in the repo' '
        (
        cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
@@ -240,8 +238,7 @@ test_expect_success EXPENSIVE 'create 50,000 tags in the repo' '
 '
 
 test_expect_success EXPENSIVE 'clone the 50,000 tag repo to check OS command line overflow' '
-       git clone $HTTPD_URL/smart/repo.git too-many-refs 2>err &&
-       test_line_count = 0 err &&
+       git clone $HTTPD_URL/smart/repo.git too-many-refs &&
        (
                cd too-many-refs &&
                test $(git for-each-ref refs/tags | wc -l) = 50000
index 5abd11a5638299f2d3fe41d38f9a3d10050a4e4b..aa73eeaef82adff56083fdc2d5d35d599b73edee 100755 (executable)
@@ -5,7 +5,11 @@ test_description='test git-http-backend-noserver'
 
 HTTPD_DOCUMENT_ROOT_PATH="$TRASH_DIRECTORY"
 
-test_have_prereq GREP_STRIPS_CR && export GREP_OPTIONS=-U
+if test_have_prereq GREP_STRIPS_CR
+then
+       GREP_OPTIONS=-U
+       export GREP_OPTIONS
+fi
 
 run_backend() {
        echo "$2" |
index a00a660763451d57b2a9537ec1b99fcfd0c9a831..24194075468819881826c24c08b1aa97bacb9897 100755 (executable)
@@ -87,13 +87,29 @@ test_expect_success 'push new branch by name' '
        compare_refs local HEAD server refs/heads/new-name
 '
 
-test_expect_failure 'push new branch with old:new refspec' '
+test_expect_success 'push new branch with old:new refspec' '
        (cd local &&
         git push origin new-name:new-refspec
        ) &&
        compare_refs local HEAD server refs/heads/new-refspec
 '
 
+test_expect_success 'push new branch with HEAD:new refspec' '
+       (cd local &&
+        git checkout new-name
+        git push origin HEAD:new-refspec-2
+       ) &&
+       compare_refs local HEAD server refs/heads/new-refspec-2
+'
+
+test_expect_success 'push delete branch' '
+       (cd local &&
+        git push origin :new-name
+       ) &&
+       test_must_fail git --git-dir="server/.git" \
+        rev-parse --verify refs/heads/new-name
+'
+
 test_expect_success 'forced push' '
        (cd local &&
        git checkout -b force-test &&
index c277db64f75ac9f9c0cd617262824d76959fbfbd..88ed3191e871cd9a164c3c903f69b07e7d9cf937 100755 (executable)
@@ -468,4 +468,10 @@ test_expect_success 'single-character name is parsed correctly' '
        test_cmp expect actual
 '
 
+test_expect_success 'unused %G placeholders are passed through' '
+       echo "%GX %G" >expect &&
+       git log -1 --format="%GX %G" >actual &&
+       test_cmp expect actual
+'
+
 test_done
index 432f086c063198e82ad8a2f7c8dd175a8685fdf5..3758961765635c4ce504eec1540605f65efd386a 100755 (executable)
@@ -77,12 +77,29 @@ test_expect_success "merge without conflict (--quiet)" \
        "git merge-file --quiet test.txt orig.txt new2.txt"
 
 cp new1.txt test2.txt
-test_expect_success "merge without conflict (missing LF at EOF)" \
-       "git merge-file test2.txt orig.txt new2.txt"
+test_expect_failure "merge without conflict (missing LF at EOF)" \
+       "git merge-file test2.txt orig.txt new4.txt"
 
-test_expect_success "merge result added missing LF" \
+test_expect_failure "merge result added missing LF" \
        "test_cmp test.txt test2.txt"
 
+cp new4.txt test3.txt
+test_expect_success "merge without conflict (missing LF at EOF, away from change in the other file)" \
+       "git merge-file --quiet test3.txt new2.txt new3.txt"
+
+cat > expect.txt << EOF
+DOMINUS regit me,
+et nihil mihi deerit.
+In loco pascuae ibi me collocavit,
+super aquam refectionis educavit me;
+animam meam convertit,
+deduxit me super semitas jusitiae,
+EOF
+printf "propter nomen suum." >> expect.txt
+
+test_expect_success "merge does not add LF away of change" \
+       "test_cmp test3.txt expect.txt"
+
 cp test.txt backup.txt
 test_expect_success "merge with conflicts" \
        "test_must_fail git merge-file test.txt orig.txt new3.txt"
@@ -107,6 +124,55 @@ EOF
 test_expect_success "expected conflict markers" "test_cmp test.txt expect.txt"
 
 cp backup.txt test.txt
+
+cat > expect.txt << EOF
+Dominus regit me, et nihil mihi deerit.
+In loco pascuae ibi me collocavit,
+super aquam refectionis educavit me;
+animam meam convertit,
+deduxit me super semitas jusitiae,
+propter nomen suum.
+Nam et si ambulavero in medio umbrae mortis,
+non timebo mala, quoniam tu mecum es:
+virga tua et baculus tuus ipsa me consolata sunt.
+EOF
+test_expect_success "merge conflicting with --ours" \
+       "git merge-file --ours test.txt orig.txt new3.txt && test_cmp test.txt expect.txt"
+cp backup.txt test.txt
+
+cat > expect.txt << EOF
+DOMINUS regit me,
+et nihil mihi deerit.
+In loco pascuae ibi me collocavit,
+super aquam refectionis educavit me;
+animam meam convertit,
+deduxit me super semitas jusitiae,
+propter nomen suum.
+Nam et si ambulavero in medio umbrae mortis,
+non timebo mala, quoniam tu mecum es:
+virga tua et baculus tuus ipsa me consolata sunt.
+EOF
+test_expect_success "merge conflicting with --theirs" \
+       "git merge-file --theirs test.txt orig.txt new3.txt && test_cmp test.txt expect.txt"
+cp backup.txt test.txt
+
+cat > expect.txt << EOF
+Dominus regit me, et nihil mihi deerit.
+DOMINUS regit me,
+et nihil mihi deerit.
+In loco pascuae ibi me collocavit,
+super aquam refectionis educavit me;
+animam meam convertit,
+deduxit me super semitas jusitiae,
+propter nomen suum.
+Nam et si ambulavero in medio umbrae mortis,
+non timebo mala, quoniam tu mecum es:
+virga tua et baculus tuus ipsa me consolata sunt.
+EOF
+test_expect_success "merge conflicting with --union" \
+       "git merge-file --union test.txt orig.txt new3.txt && test_cmp test.txt expect.txt"
+cp backup.txt test.txt
+
 test_expect_success "merge with conflicts, using -L" \
        "test_must_fail git merge-file -L 1 -L 2 test.txt orig.txt new3.txt"
 
@@ -260,4 +326,23 @@ test_expect_success 'marker size' '
        test_cmp expect actual
 '
 
+printf "line1\nline2\nline3" >nolf-orig.txt
+printf "line1\nline2\nline3x" >nolf-diff1.txt
+printf "line1\nline2\nline3y" >nolf-diff2.txt
+
+test_expect_success 'conflict at EOF without LF resolved by --ours' \
+       'git merge-file -p --ours nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >output.txt &&
+        printf "line1\nline2\nline3x" >expect.txt &&
+        test_cmp expect.txt output.txt'
+
+test_expect_success 'conflict at EOF without LF resolved by --theirs' \
+       'git merge-file -p --theirs nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >output.txt &&
+        printf "line1\nline2\nline3y" >expect.txt &&
+        test_cmp expect.txt output.txt'
+
+test_expect_success 'conflict at EOF without LF resolved by --union' \
+       'git merge-file -p --union nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >output.txt &&
+        printf "line1\nline2\nline3x\nline3y" >expect.txt &&
+        test_cmp expect.txt output.txt'
+
 test_done
index 719a11673bfc93463870d7d601eb3a0634b59b48..68b3cb26d90c5b88d28bbd03e8d50d4527f8a19b 100755 (executable)
@@ -318,6 +318,33 @@ test_expect_success 'test --format long' '
        test_cmp expected actual
 '
 
+test_expect_success 'setup a fake editor' '
+       write_script fakeeditor <<-\EOF
+               sed -e "s/A U Thor/A fake Thor/" "$1" >"$1.new"
+               mv "$1.new" "$1"
+       EOF
+'
+
+test_expect_success '--edit with and without already replaced object' '
+       test_must_fail env GIT_EDITOR=./fakeeditor git replace --edit "$PARA3" &&
+       GIT_EDITOR=./fakeeditor git replace --force --edit "$PARA3" &&
+       git replace -l | grep "$PARA3" &&
+       git cat-file commit "$PARA3" | grep "A fake Thor" &&
+       git replace -d "$PARA3" &&
+       GIT_EDITOR=./fakeeditor git replace --edit "$PARA3" &&
+       git replace -l | grep "$PARA3" &&
+       git cat-file commit "$PARA3" | grep "A fake Thor"
+'
+
+test_expect_success '--edit and change nothing or command failed' '
+       git replace -d "$PARA3" &&
+       test_must_fail env GIT_EDITOR=true git replace --edit "$PARA3" &&
+       test_must_fail env GIT_EDITOR="./fakeeditor;false" git replace --edit "$PARA3" &&
+       GIT_EDITOR=./fakeeditor git replace --edit "$PARA3" &&
+       git replace -l | grep "$PARA3" &&
+       git cat-file commit "$PARA3" | grep "A fake Thor"
+'
+
 test_expect_success 'replace ref cleanup' '
        test -n "$(git replace)" &&
        git replace -d $(git replace) &&
index 9496736a89eb6b0b1ece64052cd2726c516c952b..66643e4bd758aa55f4f58d70675e32f1ad173460 100755 (executable)
@@ -308,6 +308,17 @@ test_expect_success 'Prune empty commits' '
        test_cmp expect actual
 '
 
+test_expect_success 'prune empty collapsed merges' '
+       test_config merge.ff false &&
+       git rev-list HEAD >expect &&
+       test_commit to_remove_2 &&
+       git reset --hard HEAD^ &&
+       test_merge non-ff to_remove_2 &&
+       git filter-branch -f --index-filter "git update-index --remove to_remove_2.t" --prune-empty HEAD &&
+       git rev-list HEAD >actual &&
+       test_cmp expect actual
+'
+
 test_expect_success '--remap-to-ancestor with filename filters' '
        git checkout master &&
        git reset --hard A &&
index 143a8ea60507a35bbdfb310eb74a33cf5b88bf1f..e4ab0f5b64194da05b159782a5e41479bf47de20 100755 (executable)
@@ -1423,4 +1423,30 @@ EOF
        test_cmp expect actual
 '
 
+run_with_limited_stack () {
+       (ulimit -s 64 && "$@")
+}
+
+test_lazy_prereq ULIMIT 'run_with_limited_stack true'
+
+# we require ulimit, this excludes Windows
+test_expect_success ULIMIT '--contains works in a deep repo' '
+       >expect &&
+       i=1 &&
+       while test $i -lt 4000
+       do
+               echo "commit refs/heads/master
+committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200
+data <<EOF
+commit #$i
+EOF"
+               test $i = 1 && echo "from refs/heads/master^0"
+               i=$(($i + 1))
+       done | git fast-import &&
+       git checkout master &&
+       git tag far-far-away HEAD^ &&
+       run_with_limited_stack git tag --contains HEAD >actual &&
+       test_cmp expect actual
+'
+
 test_done
index d58b097ff3b3d0e6e68d15491d38f1f32460f6e7..63e04277f99a08b15e12c3392f9e128147180fad 100755 (executable)
@@ -346,8 +346,21 @@ test_expect_success 'amend commit to fix date' '
 
 '
 
-test_expect_success 'commit complains about bogus date' '
-       test_must_fail git commit --amend --date=10.11.2010
+test_expect_success 'commit mentions forced date in output' '
+       git commit --amend --date=2010-01-02T03:04:05 >output &&
+       grep "Date: *Sat Jan 2 03:04:05 2010" output
+'
+
+test_expect_success 'commit complains about completely bogus dates' '
+       test_must_fail git commit --amend --date=seventeen
+'
+
+test_expect_success 'commit --date allows approxidate' '
+       git commit --amend \
+               --date="midnight the 12th of october, anno domini 1979" &&
+       echo "Fri Oct 12 00:00:00 1979 +0000" >expect &&
+       git log -1 --format=%ad >actual &&
+       test_cmp expect actual
 '
 
 test_expect_success 'sign off (1)' '
index 9a3f3a1b4151ebf16cfd773a0f9efcb1b61d40d7..051489ea334c9693c2d19823ad23947703f66d90 100755 (executable)
@@ -344,6 +344,13 @@ test_expect_success 'message shows author when it is not equal to committer' '
          .git/COMMIT_EDITMSG
 '
 
+test_expect_success 'message shows date when it is explicitly set' '
+       git commit --allow-empty -e -m foo --date="2010-01-02T03:04:05" &&
+       test_i18ngrep \
+         "^# Date: *Sat Jan 2 03:04:05 2010 +0000" \
+         .git/COMMIT_EDITMSG
+'
+
 test_expect_success AUTOIDENT 'message shows committer when it is automatic' '
 
        echo >>negative &&
@@ -563,4 +570,30 @@ test_expect_success 'commit --status with custom comment character' '
        test_i18ngrep "^; Changes to be committed:" .git/COMMIT_EDITMSG
 '
 
+test_expect_success 'switch core.commentchar' '
+       test_commit "#foo" foo &&
+       GIT_EDITOR=.git/FAKE_EDITOR git -c core.commentChar=auto commit --amend &&
+       test_i18ngrep "^; Changes to be committed:" .git/COMMIT_EDITMSG
+'
+
+test_expect_success 'switch core.commentchar but out of options' '
+       cat >text <<\EOF &&
+# 1
+; 2
+@ 3
+! 4
+$ 5
+% 6
+^ 7
+& 8
+| 9
+: 10
+EOF
+       git commit --amend -F text &&
+       (
+               test_set_editor .git/FAKE_EDITOR &&
+               test_must_fail git -c core.commentChar=auto commit --amend
+       )
+'
+
 test_done
index d48006960e8b4e5feb3d8af8d7a505983f8317eb..8ed5788808055889208ac9451054f098538a6878 100755 (executable)
@@ -1350,8 +1350,7 @@ test_expect_success "status (core.commentchar with submodule summary)" '
 
 test_expect_success "status (core.commentchar with two chars with submodule summary)" '
        test_config core.commentchar ";;" &&
-       git -c status.displayCommentPrefix=true status >output &&
-       test_i18ncmp expect output
+       test_must_fail git -c status.displayCommentPrefix=true status
 '
 
 test_expect_success "--ignore-submodules=all suppresses submodule summary" '
index 5ddac1a9f740c03f1d94f75db2c6e54dd3391eda..474dab381aef027207026cb938df7a09cc7a9056 100755 (executable)
@@ -43,44 +43,74 @@ test_expect_success GPG 'create signed commits' '
 
        test_tick && git rebase -f HEAD^^ && git tag sixth-signed HEAD^ &&
        git tag seventh-signed
+
+       echo 8 >file && test_tick && git commit -a -m eighth -SB7227189 &&
+       git tag eighth-signed-alt
 '
 
-test_expect_success GPG 'show signatures' '
+test_expect_success GPG 'verify and show signatures' '
        (
-               for commit in initial second merge fourth-signed fifth-signed sixth-signed master
+               for commit in initial second merge fourth-signed fifth-signed sixth-signed seventh-signed
                do
+                       git verify-commit $commit &&
                        git show --pretty=short --show-signature $commit >actual &&
-                       grep "Good signature from" actual || exit 1
-                       ! grep "BAD signature from" actual || exit 1
-                       echo $commit OK
+                       grep "Good signature from" actual &&
+                       ! grep "BAD signature from" actual &&
+                       echo $commit OK || exit 1
                done
        ) &&
        (
                for commit in merge^2 fourth-unsigned sixth-unsigned seventh-unsigned
                do
+                       test_must_fail git verify-commit $commit &&
                        git show --pretty=short --show-signature $commit >actual &&
-                       grep "Good signature from" actual && exit 1
-                       ! grep "BAD signature from" actual || exit 1
-                       echo $commit OK
+                       ! grep "Good signature from" actual &&
+                       ! grep "BAD signature from" actual &&
+                       echo $commit OK || exit 1
+               done
+       ) &&
+       (
+               for commit in eighth-signed-alt
+               do
+                       git show --pretty=short --show-signature $commit >actual &&
+                       grep "Good signature from" actual &&
+                       ! grep "BAD signature from" actual &&
+                       grep "not certified" actual &&
+                       echo $commit OK || exit 1
                done
        )
 '
 
+test_expect_success GPG 'show signed commit with signature' '
+       git show -s initial >commit &&
+       git show -s --show-signature initial >show &&
+       git verify-commit -v initial >verify.1 2>verify.2 &&
+       git cat-file commit initial >cat &&
+       grep -v "gpg: " show >show.commit &&
+       grep "gpg: " show >show.gpg &&
+       grep -v "^ " cat | grep -v "^gpgsig " >cat.commit &&
+       test_cmp show.commit commit &&
+       test_cmp show.gpg verify.2 &&
+       test_cmp cat.commit verify.1
+'
+
 test_expect_success GPG 'detect fudged signature' '
-       git cat-file commit master >raw &&
+       git cat-file commit seventh-signed >raw &&
 
        sed -e "s/seventh/7th forged/" raw >forged1 &&
        git hash-object -w -t commit forged1 >forged1.commit &&
+       ! git verify-commit $(cat forged1.commit) &&
        git show --pretty=short --show-signature $(cat forged1.commit) >actual1 &&
        grep "BAD signature from" actual1 &&
        ! grep "Good signature from" actual1
 '
 
 test_expect_success GPG 'detect fudged signature with NUL' '
-       git cat-file commit master >raw &&
+       git cat-file commit seventh-signed >raw &&
        cat raw >forged2 &&
        echo Qwik | tr "Q" "\000" >>forged2 &&
        git hash-object -w -t commit forged2 >forged2.commit &&
+       ! git verify-commit $(cat forged2.commit) &&
        git show --pretty=short --show-signature $(cat forged2.commit) >actual2 &&
        grep "BAD signature from" actual2 &&
        ! grep "Good signature from" actual2
@@ -89,9 +119,50 @@ test_expect_success GPG 'detect fudged signature with NUL' '
 test_expect_success GPG 'amending already signed commit' '
        git checkout fourth-signed^0 &&
        git commit --amend -S --no-edit &&
+       git verify-commit HEAD &&
        git show -s --show-signature HEAD >actual &&
        grep "Good signature from" actual &&
        ! grep "BAD signature from" actual
 '
 
+test_expect_success GPG 'show good signature with custom format' '
+       cat >expect <<-\EOF &&
+       G
+       13B6F51ECDDE430D
+       C O Mitter <committer@example.com>
+       EOF
+       git log -1 --format="%G?%n%GK%n%GS" sixth-signed >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success GPG 'show bad signature with custom format' '
+       cat >expect <<-\EOF &&
+       B
+       13B6F51ECDDE430D
+       C O Mitter <committer@example.com>
+       EOF
+       git log -1 --format="%G?%n%GK%n%GS" $(cat forged1.commit) >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success GPG 'show unknown signature with custom format' '
+       cat >expect <<-\EOF &&
+       U
+       61092E85B7227189
+       Eris Discordia <discord@example.net>
+       EOF
+       git log -1 --format="%G?%n%GK%n%GS" eighth-signed-alt >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success GPG 'show lack of signature with custom format' '
+       cat >expect <<-\EOF &&
+       N
+
+
+       EOF
+       git log -1 --format="%G?%n%GK%n%GS" seventh-unsigned >actual &&
+       test_cmp expect actual
+'
+
 test_done
index 284018e3cdb31e7db179a93f7196fda47578c43c..021c5479bdf4665e815590dc05a0831e7d92c53c 100755 (executable)
@@ -21,7 +21,7 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
        objsha1=$(git verify-pack -v pack-$packsha1.idx | head -n 1 |
                sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") &&
        mv pack-* .git/objects/pack/ &&
-       git repack --no-pack-kept-objects -A -d -l &&
+       git repack -A -d -l &&
        git prune-packed &&
        for p in .git/objects/pack/*.idx; do
                idx=$(basename $p)
@@ -35,9 +35,25 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
        test -z "$found_duplicate_object"
 '
 
-test_expect_success 'writing bitmaps can duplicate .keep objects' '
+test_expect_success 'writing bitmaps via command-line can duplicate .keep objects' '
        # build on $objsha1, $packsha1, and .keep state from previous
-       git repack -Adl &&
+       git repack -Adbl &&
+       test_when_finished "found_duplicate_object=" &&
+       for p in .git/objects/pack/*.idx; do
+               idx=$(basename $p)
+               test "pack-$packsha1.idx" = "$idx" && continue
+               if git verify-pack -v $p | egrep "^$objsha1"; then
+                       found_duplicate_object=1
+                       echo "DUPLICATE OBJECT FOUND"
+                       break
+               fi
+       done &&
+       test "$found_duplicate_object" = 1
+'
+
+test_expect_success 'writing bitmaps via config can duplicate .keep objects' '
+       # build on $objsha1, $packsha1, and .keep state from previous
+       git -c repack.writebitmaps=true repack -Adl &&
        test_when_finished "found_duplicate_object=" &&
        for p in .git/objects/pack/*.idx; do
                idx=$(basename $p)
index 5a193c500d282cc2b13e8de6e128229585897a16..dc30a514bf681dde44dea32e671632ef6f0a47a7 100755 (executable)
@@ -58,7 +58,7 @@ test_expect_success PERL 'custom tool commands override built-ins' '
 
 test_expect_success PERL 'difftool ignores bad --tool values' '
        : >expect &&
-       test_expect_code 1 \
+       test_must_fail \
                git difftool --no-prompt --tool=bad-tool branch >actual &&
        test_cmp expect actual
 '
index 63b303924307ad3a1d0658ec3b69a3ebf9e5670e..40615debc42479970c6a38565b71227bcf7f27c8 100755 (executable)
@@ -1096,11 +1096,6 @@ test_expect_success 'grep -E pattern with grep.patternType=fixed' '
        test_cmp expected actual
 '
 
-test_config() {
-       git config "$1" "$2" &&
-       test_when_finished "git config --unset $1"
-}
-
 cat >expected <<EOF
 hello.c<RED>:<RESET>int main(int argc, const char **argv)
 hello.c<RED>-<RESET>{
index 1ecdacb6fd0ceb7e43e6ec3bad018e7b6dc8100b..19a3ced600a20d805d430533b275a8fa4269b835 100755 (executable)
@@ -1334,6 +1334,51 @@ test_expect_success $PREREQ '--force sends cover letter template anyway' '
        test -n "$(ls msgtxt*)"
 '
 
+test_cover_addresses () {
+       header="$1"
+       shift
+       clean_fake_sendmail &&
+       rm -fr outdir &&
+       git format-patch --cover-letter -2 -o outdir &&
+       cover=`echo outdir/0000-*.patch` &&
+       mv $cover cover-to-edit.patch &&
+       perl -pe "s/^From:/$header: extra\@address.com\nFrom:/" cover-to-edit.patch >"$cover" &&
+       git send-email \
+         --force \
+         --from="Example <nobody@example.com>" \
+         --no-to --no-cc \
+         "$@" \
+         --smtp-server="$(pwd)/fake.sendmail" \
+         outdir/0000-*.patch \
+         outdir/0001-*.patch \
+         outdir/0002-*.patch \
+         2>errors >out &&
+       grep "^$header: extra@address.com" msgtxt1 >to1 &&
+       grep "^$header: extra@address.com" msgtxt2 >to2 &&
+       grep "^$header: extra@address.com" msgtxt3 >to3 &&
+       test_line_count = 1 to1 &&
+       test_line_count = 1 to2 &&
+       test_line_count = 1 to3
+}
+
+test_expect_success $PREREQ 'to-cover adds To to all mail' '
+       test_cover_addresses "To" --to-cover
+'
+
+test_expect_success $PREREQ 'cc-cover adds Cc to all mail' '
+       test_cover_addresses "Cc" --cc-cover
+'
+
+test_expect_success $PREREQ 'tocover adds To to all mail' '
+       test_config sendemail.tocover true &&
+       test_cover_addresses "To"
+'
+
+test_expect_success $PREREQ 'cccover adds Cc to all mail' '
+       test_config sendemail.cccover true &&
+       test_cover_addresses "Cc"
+'
+
 test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' '
        clean_fake_sendmail &&
        echo "alias sbd  somebody@example.org" >.mailrc &&
index 83cc5fc9d1a381ecd006fa0a203f22dea0825a82..2937f4c265b26a92f9ce0634c6e7df578c6c781a 100755 (executable)
@@ -7,40 +7,39 @@ test_description='git svn authors prog tests'
 
 . ./lib-git-svn.sh
 
-cat > svn-authors-prog <<'EOF'
-#!/usr/bin/perl
-$_ = shift;
-if (s/-sub$//)  {
-       print "$_ <$_\@sub.example.com>\n";
-}
-else {
-       print "$_ <$_\@example.com>\n";
-}
+write_script svn-authors-prog "$PERL_PATH" <<-\EOF
+       $_ = shift;
+       if (s/-sub$//)  {
+               print "$_ <$_\@sub.example.com>\n";
+       } else {
+               print "$_ <$_\@example.com>\n";
+       }
 EOF
-chmod +x svn-authors-prog
 
-cat > svn-authors <<'EOF'
-ff = FFFFFFF FFFFFFF <fFf@other.example.com>
-EOF
+test_expect_success 'svn-authors setup' '
+       cat >svn-authors <<-\EOF
+       ff = FFFFFFF FFFFFFF <fFf@other.example.com>
+       EOF
+'
 
 test_expect_success 'setup svnrepo' '
        for i in aa bb cc-sub dd-sub ee-foo ff
        do
                svn mkdir -m $i --username $i "$svnrepo"/$i
        done
-       '
+'
 
 test_expect_success 'import authors with prog and file' '
        git svn clone --authors-prog=./svn-authors-prog \
            --authors-file=svn-authors "$svnrepo" x
-       '
+'
 
 test_expect_success 'imported 6 revisions successfully' '
        (
                cd x
                test "`git rev-list refs/remotes/git-svn | wc -l`" -eq 6
        )
-       '
+'
 
 test_expect_success 'authors-prog ran correctly' '
        (
@@ -56,7 +55,7 @@ test_expect_success 'authors-prog ran correctly' '
                git rev-list -1 --pretty=raw refs/remotes/git-svn~5 | \
                  grep "^author aa <aa@example\.com> "
        )
-       '
+'
 
 test_expect_success 'authors-file overrode authors-prog' '
        (
@@ -64,7 +63,7 @@ test_expect_success 'authors-file overrode authors-prog' '
                git rev-list -1 --pretty=raw refs/remotes/git-svn | \
                  grep "^author FFFFFFF FFFFFFF <fFf@other\.example\.com> "
        )
-       '
+'
 
 git --git-dir=x/.git config --unset svn.authorsfile
 git --git-dir=x/.git config --unset svn.authorsprog
index 27263dfb80420a417bb0f33aa8731ef2fb7bc7b6..5fc9ef262ac1297d9442ed08208cb183ecc0e5c1 100755 (executable)
@@ -2999,4 +2999,22 @@ test_expect_success 'T: ls root tree' '
        test_cmp expect actual
 '
 
+test_expect_success 'T: delete branch' '
+       git branch to-delete &&
+       git fast-import <<-EOF &&
+       reset refs/heads/to-delete
+       from 0000000000000000000000000000000000000000
+       EOF
+       test_must_fail git rev-parse --verify refs/heads/to-delete
+'
+
+test_expect_success 'T: empty reset doesnt delete branch' '
+       git branch not-to-delete &&
+       git fast-import <<-EOF &&
+       reset refs/heads/not-to-delete
+       EOF
+       git show-ref &&
+       git rev-parse --verify refs/heads/not-to-delete
+'
+
 test_done
index 2312dec8f096fe7e36feeabd0e1cd85b5e421d4a..66c8b0a371e37f90cff8da0c92f09c8784ec45a2 100755 (executable)
@@ -504,4 +504,22 @@ test_expect_success 'refs are updated even if no commits need to be exported' '
        test_cmp expected actual
 '
 
+test_expect_success 'use refspec' '
+       git fast-export --refspec refs/heads/master:refs/heads/foobar master | \
+               grep "^commit " | sort | uniq > actual &&
+       echo "commit refs/heads/foobar" > expected &&
+       test_cmp expected actual
+'
+
+test_expect_success 'delete refspec' '
+       git branch to-delete &&
+       git fast-export --refspec :refs/heads/to-delete to-delete ^to-delete > actual &&
+       cat > expected <<-EOF &&
+       reset refs/heads/to-delete
+       from 0000000000000000000000000000000000000000
+
+       EOF
+       test_cmp expected actual
+'
+
 test_done
index 4caf36e0066313f5402f61645c4330093ba23fcf..7fab2ed977a529c8754b9e5acd44b7f7c2cfaf2f 100755 (executable)
@@ -403,7 +403,8 @@ test_expect_success 'submit --prepare-p4-only' '
                git commit -m "prep only add" &&
                git p4 submit --prepare-p4-only >out &&
                test_i18ngrep "prepared for submission" out &&
-               test_i18ngrep "must be deleted" out
+               test_i18ngrep "must be deleted" out &&
+               ! test_i18ngrep "everything below this line is just the diff" out
        ) &&
        (
                cd "$cli" &&
index be802e0e16f165f92d3526572a483d1287b19ef9..1fc1f5f2afcf205f10d04cd1deaf5708f727332e 100755 (executable)
@@ -177,7 +177,7 @@ test_expect_success 'detect copies' '
                level=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/C0*//") &&
                test -n "$level" && test "$level" -gt 0 && test "$level" -lt 98 &&
                src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) &&
-               test "$src" = file10 -o "$src" = file11 &&
+               test "$src" = file10 || test "$src" = file11 &&
                git config git-p4.detectCopies $(($level + 2)) &&
                git p4 submit &&
                p4 filelog //depot/file12 &&
@@ -191,7 +191,7 @@ test_expect_success 'detect copies' '
                level=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/C0*//") &&
                test -n "$level" && test "$level" -gt 2 && test "$level" -lt 100 &&
                src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) &&
-               test "$src" = file10 -o "$src" = file11 -o "$src" = file12 &&
+               test "$src" = file10 || test "$src" = file11 || test "$src" = file12 &&
                git config git-p4.detectCopies $(($level - 2)) &&
                git p4 submit &&
                p4 filelog //depot/file13 &&
index 2d4beb5e50c257fed2f4b6475cb5834425b5a64f..1d1c1063a38866f1792f9b451a4942d06c91edb4 100755 (executable)
@@ -550,6 +550,33 @@ test_expect_success 'complete files' '
        test_completion "git add mom" "momified"
 '
 
+test_expect_success "completion uses <cmd> completion for alias: !sh -c 'git <cmd> ...'" '
+       test_config alias.co "!sh -c '"'"'git checkout ...'"'"'" &&
+       test_completion "git co m" <<-\EOF
+       master Z
+       mybranch Z
+       mytag Z
+       EOF
+'
+
+test_expect_success 'completion uses <cmd> completion for alias: !f () { VAR=val git <cmd> ... }' '
+       test_config alias.co "!f () { VAR=val git checkout ... ; } f" &&
+       test_completion "git co m" <<-\EOF
+       master Z
+       mybranch Z
+       mytag Z
+       EOF
+'
+
+test_expect_success 'completion used <cmd> completion for alias: !f() { : git <cmd> ; ... }' '
+       test_config alias.co "!f() { : git checkout ; if ... } f" &&
+       test_completion "git co m" <<-\EOF
+       master Z
+       mybranch Z
+       mytag Z
+       EOF
+'
+
 test_expect_failure 'complete with tilde expansion' '
        git init tmp && cd tmp &&
        test_when_finished "cd .. && rm -rf tmp" &&
index 158e10a67e5878bb9031af2f28439b099b65fd50..0377d3e2960cc282ce1a2c7cb629245728c82092 100644 (file)
@@ -542,7 +542,7 @@ test_must_fail () {
        if test $exit_code = 0; then
                echo >&2 "test_must_fail: command succeeded: $*"
                return 1
-       elif test $exit_code -gt 129 -a $exit_code -le 192; then
+       elif test $exit_code -gt 129 && test $exit_code -le 192; then
                echo >&2 "test_must_fail: died by signal: $*"
                return 1
        elif test $exit_code = 127; then
@@ -569,7 +569,7 @@ test_must_fail () {
 test_might_fail () {
        "$@"
        exit_code=$?
-       if test $exit_code -gt 129 -a $exit_code -le 192; then
+       if test $exit_code -gt 129 && test $exit_code -le 192; then
                echo >&2 "test_might_fail: died by signal: $*"
                return 1
        elif test $exit_code = 127; then
@@ -617,6 +617,12 @@ test_cmp() {
        $GIT_TEST_CMP "$@"
 }
 
+# test_cmp_bin - helper to compare binary files
+
+test_cmp_bin() {
+       cmp "$@"
+}
+
 # Check if the file expected to be empty is indeed empty, and barfs
 # otherwise.
 
@@ -717,6 +723,11 @@ test_ln_s_add () {
        fi
 }
 
+# This function writes out its parameters, one per line
+test_write_lines () {
+       printf "%s\n" "$@"
+}
+
 perl () {
        command "$PERL_PATH" "$@"
 }
index c081668dfe16c85dda29bace564f7c1c3da77cb0..a4795373a6a2e1f247b3cef9880f2a82309b3594 100644 (file)
@@ -91,6 +91,7 @@ unset VISUAL EMAIL LANGUAGE COLUMNS $("$PERL_PATH" -e '
                VALGRIND
                UNZIP
                PERF_
+               CURL_VERBOSE
        ));
        my @vars = grep(/^GIT_/ && !/^GIT_($ok)/o, @env);
        print join("\n", @vars);
@@ -191,6 +192,14 @@ do
                immediate=t; shift ;;
        -l|--l|--lo|--lon|--long|--long-|--long-t|--long-te|--long-tes|--long-test|--long-tests)
                GIT_TEST_LONG=t; export GIT_TEST_LONG; shift ;;
+       -r)
+               shift; test "$#" -ne 0 || {
+                       echo 'error: -r requires an argument' >&2;
+                       exit 1;
+               }
+               run_list=$1; shift ;;
+       --run=*)
+               run_list=$(expr "z$1" : 'z[^=]*=\(.*\)'); shift ;;
        -h|--h|--he|--hel|--help)
                help=t; shift ;;
        -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
@@ -366,6 +375,99 @@ match_pattern_list () {
        return 1
 }
 
+match_test_selector_list () {
+       title="$1"
+       shift
+       arg="$1"
+       shift
+       test -z "$1" && return 0
+
+       # Both commas and whitespace are accepted as separators.
+       OLDIFS=$IFS
+       IFS='   ,'
+       set -- $1
+       IFS=$OLDIFS
+
+       # If the first selector is negative we include by default.
+       include=
+       case "$1" in
+               !*) include=t ;;
+       esac
+
+       for selector
+       do
+               orig_selector=$selector
+
+               positive=t
+               case "$selector" in
+                       !*)
+                               positive=
+                               selector=${selector##?}
+                               ;;
+               esac
+
+               test -z "$selector" && continue
+
+               case "$selector" in
+                       *-*)
+                               if expr "z${selector%%-*}" : "z[0-9]*[^0-9]" >/dev/null
+                               then
+                                       echo "error: $title: invalid non-numeric in range" \
+                                               "start: '$orig_selector'" >&2
+                                       exit 1
+                               fi
+                               if expr "z${selector#*-}" : "z[0-9]*[^0-9]" >/dev/null
+                               then
+                                       echo "error: $title: invalid non-numeric in range" \
+                                               "end: '$orig_selector'" >&2
+                                       exit 1
+                               fi
+                               ;;
+                       *)
+                               if expr "z$selector" : "z[0-9]*[^0-9]" >/dev/null
+                               then
+                                       echo "error: $title: invalid non-numeric in test" \
+                                               "selector: '$orig_selector'" >&2
+                                       exit 1
+                               fi
+               esac
+
+               # Short cut for "obvious" cases
+               test -z "$include" && test -z "$positive" && continue
+               test -n "$include" && test -n "$positive" && continue
+
+               case "$selector" in
+                       -*)
+                               if test $arg -le ${selector#-}
+                               then
+                                       include=$positive
+                               fi
+                               ;;
+                       *-)
+                               if test $arg -ge ${selector%-}
+                               then
+                                       include=$positive
+                               fi
+                               ;;
+                       *-*)
+                               if test ${selector%%-*} -le $arg \
+                                       && test $arg -le ${selector#*-}
+                               then
+                                       include=$positive
+                               fi
+                               ;;
+                       *)
+                               if test $arg -eq $selector
+                               then
+                                       include=$positive
+                               fi
+                               ;;
+               esac
+       done
+
+       test -n "$include"
+}
+
 maybe_teardown_verbose () {
        test -z "$verbose_only" && return
        exec 4>/dev/null 3>/dev/null
@@ -452,25 +554,35 @@ test_finish_ () {
 
 test_skip () {
        to_skip=
+       skipped_reason=
        if match_pattern_list $this_test.$test_count $GIT_SKIP_TESTS
        then
                to_skip=t
+               skipped_reason="GIT_SKIP_TESTS"
        fi
        if test -z "$to_skip" && test -n "$test_prereq" &&
           ! test_have_prereq "$test_prereq"
        then
                to_skip=t
-       fi
-       case "$to_skip" in
-       t)
+
                of_prereq=
                if test "$missing_prereq" != "$test_prereq"
                then
                        of_prereq=" of $test_prereq"
                fi
+               skipped_reason="missing $missing_prereq${of_prereq}"
+       fi
+       if test -z "$to_skip" && test -n "$run_list" &&
+               ! match_test_selector_list '--run' $test_count "$run_list"
+       then
+               to_skip=t
+               skipped_reason="--run"
+       fi
 
+       case "$to_skip" in
+       t)
                say_color skip >&3 "skipping test: $@"
-               say_color skip "ok $test_count # skip $1 (missing $missing_prereq${of_prereq})"
+               say_color skip "ok $test_count # skip $1 ($skipped_reason)"
                : true
                ;;
        *)
@@ -864,6 +976,14 @@ test_lazy_prereq AUTOIDENT '
        git var GIT_AUTHOR_IDENT
 '
 
+test_lazy_prereq EXPENSIVE '
+       test -n "$GIT_TEST_LONG"
+'
+
+test_lazy_prereq USR_BIN_TIME '
+       test -x /usr/bin/time
+'
+
 # When the tests are run as root, permission tests will report that
 # things are writable when they shouldn't be.
 test -w / || test_set_prereq SANITY
index 0a6724fcc45eed89d612b0e641fd3fe6d4231fcb..9d51c92b74b5b9251470ea3b5d168a4cfbfb9939 100644 (file)
        Memcheck:Addr4
        fun:copy_ref
 }
+{
+       ignore-sse-check_refname_format-addr
+       Memcheck:Addr8
+       fun:check_refname_format
+}
+{
+       ignore-sse-check_refname_format-cond
+       Memcheck:Cond
+       fun:check_refname_format
+}
+{
+       ignore-sse-check_refname_format-value
+       Memcheck:Value8
+       fun:check_refname_format
+}
index 47eab9765f5cd172ca630b2a632a92d123354442..330ba4f4dd23e2cf21acbe8a7023eaca4ec09afe 100644 (file)
@@ -56,11 +56,12 @@ static int dump_cache_tree(struct cache_tree *it,
 
 int main(int ac, char **av)
 {
+       struct index_state istate;
        struct cache_tree *another = cache_tree();
        if (read_cache() < 0)
                die("unable to read index file");
-       cache_tree_update(another,
-                         (const struct cache_entry * const *)active_cache,
-                         active_nr, WRITE_TREE_DRY_RUN);
+       istate = the_index;
+       istate.cache_tree = another;
+       cache_tree_update(&istate, WRITE_TREE_DRY_RUN);
        return dump_cache_tree(active_cache_tree, another, "");
 }
diff --git a/test-dump-split-index.c b/test-dump-split-index.c
new file mode 100644 (file)
index 0000000..9cf3112
--- /dev/null
@@ -0,0 +1,34 @@
+#include "cache.h"
+#include "split-index.h"
+#include "ewah/ewok.h"
+
+static void show_bit(size_t pos, void *data)
+{
+       printf(" %d", (int)pos);
+}
+
+int main(int ac, char **av)
+{
+       struct split_index *si;
+       int i;
+
+       do_read_index(&the_index, av[1], 1);
+       printf("own %s\n", sha1_to_hex(the_index.sha1));
+       si = the_index.split_index;
+       if (!si) {
+               printf("not a split index\n");
+               return 0;
+       }
+       printf("base %s\n", sha1_to_hex(si->base_sha1));
+       for (i = 0; i < the_index.cache_nr; i++) {
+               struct cache_entry *ce = the_index.cache[i];
+               printf("%06o %s %d\t%s\n", ce->ce_mode,
+                      sha1_to_hex(ce->sha1), ce_stage(ce), ce->name);
+       }
+       printf("replacements:");
+       ewah_each_bit(si->replace_bitmap, show_bit, NULL);
+       printf("\ndeletions:");
+       ewah_each_bit(si->delete_bitmap, show_bit, NULL);
+       printf("\n");
+       return 0;
+}
index 4728013910cf1a36dac6a594c403c29de60b1fe6..9ebcbca9d25150e9bfca77a73ca45d2a06423f49 100644 (file)
@@ -6,12 +6,11 @@ static struct lock_file index_lock;
 
 int main(int ac, char **av)
 {
-       int fd = hold_locked_index(&index_lock, 1);
+       hold_locked_index(&index_lock, 1);
        if (read_cache() < 0)
                die("unable to read index file");
        active_cache_tree = NULL;
-       if (write_cache(fd, active_cache, active_nr)
-           || commit_lock_file(&index_lock))
+       if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK))
                die("unable to write index file");
        return 0;
 }
index b468e4f88e730f88a1d231a574585ace56e7066a..3d8fe7d801293a338f13dfd01ba352e84c658813 100644 (file)
@@ -101,7 +101,6 @@ static void do_take_over(struct transport *transport)
 static struct child_process *get_helper(struct transport *transport)
 {
        struct helper_data *data = transport->data;
-       struct argv_array argv = ARGV_ARRAY_INIT;
        struct strbuf buf = STRBUF_INIT;
        struct child_process *helper;
        const char **refspecs = NULL;
@@ -123,10 +122,9 @@ static struct child_process *get_helper(struct transport *transport)
        helper->in = -1;
        helper->out = -1;
        helper->err = 0;
-       argv_array_pushf(&argv, "git-remote-%s", data->name);
-       argv_array_push(&argv, transport->remote->name);
-       argv_array_push(&argv, remove_ext_force(transport->url));
-       helper->argv = argv_array_detach(&argv, NULL);
+       argv_array_pushf(&helper->args, "git-remote-%s", data->name);
+       argv_array_push(&helper->args, transport->remote->name);
+       argv_array_push(&helper->args, remove_ext_force(transport->url));
        helper->git_cmd = 0;
        helper->silent_exec_failure = 1;
 
@@ -155,7 +153,7 @@ static struct child_process *get_helper(struct transport *transport)
        write_constant(helper->in, "capabilities\n");
 
        while (1) {
-               const char *capname;
+               const char *capname, *arg;
                int mandatory = 0;
                if (recvline(data, &buf))
                        exit(128);
@@ -185,19 +183,19 @@ static struct child_process *get_helper(struct transport *transport)
                        data->export = 1;
                else if (!strcmp(capname, "check-connectivity"))
                        data->check_connectivity = 1;
-               else if (!data->refspecs && starts_with(capname, "refspec ")) {
+               else if (!data->refspecs && skip_prefix(capname, "refspec ", &arg)) {
                        ALLOC_GROW(refspecs,
                                   refspec_nr + 1,
                                   refspec_alloc);
-                       refspecs[refspec_nr++] = xstrdup(capname + strlen("refspec "));
+                       refspecs[refspec_nr++] = xstrdup(arg);
                } else if (!strcmp(capname, "connect")) {
                        data->connect = 1;
                } else if (!strcmp(capname, "signed-tags")) {
                        data->signed_tags = 1;
-               } else if (starts_with(capname, "export-marks ")) {
-                       data->export_marks = xstrdup(capname + strlen("export-marks "));
-               } else if (starts_with(capname, "import-marks")) {
-                       data->import_marks = xstrdup(capname + strlen("import-marks "));
+               } else if (skip_prefix(capname, "export-marks ", &arg)) {
+                       data->export_marks = xstrdup(arg);
+               } else if (skip_prefix(capname, "import-marks ", &arg)) {
+                       data->import_marks = xstrdup(arg);
                } else if (starts_with(capname, "no-private-update")) {
                        data->no_private_update = 1;
                } else if (mandatory) {
@@ -245,7 +243,6 @@ static int disconnect_helper(struct transport *transport)
                close(data->helper->out);
                fclose(data->out);
                res = finish_command(data->helper);
-               argv_array_free_detached(data->helper->argv);
                free(data->helper);
                data->helper = NULL;
        }
@@ -397,18 +394,16 @@ static int get_importer(struct transport *transport, struct child_process *fasti
 {
        struct child_process *helper = get_helper(transport);
        struct helper_data *data = transport->data;
-       struct argv_array argv = ARGV_ARRAY_INIT;
        int cat_blob_fd, code;
        memset(fastimport, 0, sizeof(*fastimport));
        fastimport->in = helper->out;
-       argv_array_push(&argv, "fast-import");
-       argv_array_push(&argv, debug ? "--stats" : "--quiet");
+       argv_array_push(&fastimport->args, "fast-import");
+       argv_array_push(&fastimport->args, debug ? "--stats" : "--quiet");
 
        if (data->bidi_import) {
                cat_blob_fd = xdup(helper->in);
-               argv_array_pushf(&argv, "--cat-blob-fd=%d", cat_blob_fd);
+               argv_array_pushf(&fastimport->args, "--cat-blob-fd=%d", cat_blob_fd);
        }
-       fastimport->argv = argv.argv;
        fastimport->git_cmd = 1;
 
        code = start_command(fastimport);
@@ -421,30 +416,24 @@ static int get_exporter(struct transport *transport,
 {
        struct helper_data *data = transport->data;
        struct child_process *helper = get_helper(transport);
-       int argc = 0, i;
-       struct strbuf tmp = STRBUF_INIT;
+       int i;
 
        memset(fastexport, 0, sizeof(*fastexport));
 
        /* we need to duplicate helper->in because we want to use it after
         * fastexport is done with it. */
        fastexport->out = dup(helper->in);
-       fastexport->argv = xcalloc(6 + revlist_args->nr, sizeof(*fastexport->argv));
-       fastexport->argv[argc++] = "fast-export";
-       fastexport->argv[argc++] = "--use-done-feature";
-       fastexport->argv[argc++] = data->signed_tags ?
-               "--signed-tags=verbatim" : "--signed-tags=warn-strip";
-       if (data->export_marks) {
-               strbuf_addf(&tmp, "--export-marks=%s.tmp", data->export_marks);
-               fastexport->argv[argc++] = strbuf_detach(&tmp, NULL);
-       }
-       if (data->import_marks) {
-               strbuf_addf(&tmp, "--import-marks=%s", data->import_marks);
-               fastexport->argv[argc++] = strbuf_detach(&tmp, NULL);
-       }
+       argv_array_push(&fastexport->args, "fast-export");
+       argv_array_push(&fastexport->args, "--use-done-feature");
+       argv_array_push(&fastexport->args, data->signed_tags ?
+               "--signed-tags=verbatim" : "--signed-tags=warn-strip");
+       if (data->export_marks)
+               argv_array_pushf(&fastexport->args, "--export-marks=%s.tmp", data->export_marks);
+       if (data->import_marks)
+               argv_array_pushf(&fastexport->args, "--import-marks=%s", data->import_marks);
 
        for (i = 0; i < revlist_args->nr; i++)
-               fastexport->argv[argc++] = revlist_args->items[i].string;
+               argv_array_push(&fastexport->args, revlist_args->items[i].string);
 
        fastexport->git_cmd = 1;
        return start_command(fastexport);
@@ -485,7 +474,6 @@ static int fetch_with_import(struct transport *transport,
 
        if (finish_command(&fastimport))
                die("Error while running fast-import");
-       argv_array_free_detached(fastimport.argv);
 
        /*
         * The fast-import stream of a remote helper that advertises
@@ -862,7 +850,7 @@ static int push_refs_with_export(struct transport *transport,
        struct ref *ref;
        struct child_process *helper, exporter;
        struct helper_data *data = transport->data;
-       struct string_list revlist_args = STRING_LIST_INIT_NODUP;
+       struct string_list revlist_args = STRING_LIST_INIT_DUP;
        struct strbuf buf = STRBUF_INIT;
 
        if (!data->refspecs)
@@ -882,15 +870,10 @@ static int push_refs_with_export(struct transport *transport,
 
        write_constant(helper->in, "export\n");
 
-       strbuf_reset(&buf);
-
        for (ref = remote_refs; ref; ref = ref->next) {
                char *private;
                unsigned char sha1[20];
 
-               if (ref->deletion)
-                       die("remote-helpers do not support ref deletion");
-
                private = apply_refspecs(data->refspecs, data->refspec_nr, ref->name);
                if (private && !get_sha1(private, sha1)) {
                        strbuf_addf(&buf, "^%s", private);
@@ -900,15 +883,34 @@ static int push_refs_with_export(struct transport *transport,
                free(private);
 
                if (ref->peer_ref) {
-                       if (strcmp(ref->peer_ref->name, ref->name))
-                               die("remote-helpers do not support old:new syntax");
-                       string_list_append(&revlist_args, ref->peer_ref->name);
+                       if (strcmp(ref->name, ref->peer_ref->name)) {
+                               if (!ref->deletion) {
+                                       const char *name;
+                                       int flag;
+
+                                       /* Follow symbolic refs (mainly for HEAD). */
+                                       name = resolve_ref_unsafe(ref->peer_ref->name, sha1, 1, &flag);
+                                       if (!name || !(flag & REF_ISSYMREF))
+                                               name = ref->peer_ref->name;
+
+                                       strbuf_addf(&buf, "%s:%s", name, ref->name);
+                               } else
+                                       strbuf_addf(&buf, ":%s", ref->name);
+
+                               string_list_append(&revlist_args, "--refspec");
+                               string_list_append(&revlist_args, buf.buf);
+                               strbuf_release(&buf);
+                       }
+                       if (!ref->deletion)
+                               string_list_append(&revlist_args, ref->peer_ref->name);
                }
        }
 
        if (get_exporter(transport, &exporter, &revlist_args))
                die("Couldn't run fast-export");
 
+       string_list_clear(&revlist_args, 1);
+
        if (finish_command(&exporter))
                die("Error while running fast-export");
        if (push_update_refs_status(data, remote_refs, flags))
@@ -1026,7 +1028,7 @@ static struct ref *get_refs_list(struct transport *transport, int for_push)
 
 int transport_helper_init(struct transport *transport, const char *name)
 {
-       struct helper_data *data = xcalloc(sizeof(*data), 1);
+       struct helper_data *data = xcalloc(1, sizeof(*data));
        data->name = name;
 
        if (getenv("GIT_TRANSPORT_HELPER_DEBUG"))
index 325f03e1eef97df296bb1cc9f7d2d33c218dde26..59c9727d8d63d548001513c1560b5c7a7e065b95 100644 (file)
@@ -192,7 +192,9 @@ static void set_upstreams(struct transport *transport, struct ref *refs,
 
 static const char *rsync_url(const char *url)
 {
-       return !starts_with(url, "rsync://") ? skip_prefix(url, "rsync:") : url;
+       if (!starts_with(url, "rsync://"))
+               skip_prefix(url, "rsync:", &url);
+       return url;
 }
 
 static struct ref *get_refs_via_rsync(struct transport *transport, int for_push)
index 11c3550177dbaab30596be2fc3c1633f2a0485f8..e7b378c8b2c8f145519410bb17811bf60eb29384 100644 (file)
 #include "diffcore.h"
 #include "tree.h"
 
-static void show_entry(struct diff_options *opt, const char *prefix,
-                      struct tree_desc *desc, struct strbuf *base);
+/*
+ * internal mode marker, saying a tree entry != entry of tp[imin]
+ * (see ll_diff_tree_paths for what it means there)
+ *
+ * we will update/use/emit entry for diff only with it unset.
+ */
+#define S_IFXMIN_NEQ   S_DIFFTREE_IFXMIN_NEQ
 
-static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2,
-                             struct strbuf *base, struct diff_options *opt)
-{
-       unsigned mode1, mode2;
-       const char *path1, *path2;
-       const unsigned char *sha1, *sha2;
-       int cmp, pathlen1, pathlen2;
-       int old_baselen = base->len;
 
-       sha1 = tree_entry_extract(t1, &path1, &mode1);
-       sha2 = tree_entry_extract(t2, &path2, &mode2);
+static struct combine_diff_path *ll_diff_tree_paths(
+       struct combine_diff_path *p, const unsigned char *sha1,
+       const unsigned char **parents_sha1, int nparent,
+       struct strbuf *base, struct diff_options *opt);
+static int ll_diff_tree_sha1(const unsigned char *old, const unsigned char *new,
+                            struct strbuf *base, struct diff_options *opt);
+
+/*
+ * Compare two tree entries, taking into account only path/S_ISDIR(mode),
+ * but not their sha1's.
+ *
+ * NOTE files and directories *always* compare differently, even when having
+ *      the same name - thanks to base_name_compare().
+ *
+ * NOTE empty (=invalid) descriptor(s) take part in comparison as +infty,
+ *      so that they sort *after* valid tree entries.
+ *
+ *      Due to this convention, if trees are scanned in sorted order, all
+ *      non-empty descriptors will be processed first.
+ */
+static int tree_entry_pathcmp(struct tree_desc *t1, struct tree_desc *t2)
+{
+       struct name_entry *e1, *e2;
+       int cmp;
 
-       pathlen1 = tree_entry_len(&t1->entry);
-       pathlen2 = tree_entry_len(&t2->entry);
-       cmp = base_name_compare(path1, pathlen1, mode1, path2, pathlen2, mode2);
-       if (cmp < 0) {
-               show_entry(opt, "-", t1, base);
+       /* empty descriptors sort after valid tree entries */
+       if (!t1->size)
+               return t2->size ? 1 : 0;
+       else if (!t2->size)
                return -1;
-       }
-       if (cmp > 0) {
-               show_entry(opt, "+", t2, base);
-               return 1;
-       }
-       if (!DIFF_OPT_TST(opt, FIND_COPIES_HARDER) && !hashcmp(sha1, sha2) && mode1 == mode2)
-               return 0;
 
-       /*
-        * If the filemode has changed to/from a directory from/to a regular
-        * file, we need to consider it a remove and an add.
-        */
-       if (S_ISDIR(mode1) != S_ISDIR(mode2)) {
-               show_entry(opt, "-", t1, base);
-               show_entry(opt, "+", t2, base);
-               return 0;
-       }
+       e1 = &t1->entry;
+       e2 = &t2->entry;
+       cmp = base_name_compare(e1->path, tree_entry_len(e1), e1->mode,
+                               e2->path, tree_entry_len(e2), e2->mode);
+       return cmp;
+}
 
-       strbuf_add(base, path1, pathlen1);
-       if (DIFF_OPT_TST(opt, RECURSIVE) && S_ISDIR(mode1)) {
-               if (DIFF_OPT_TST(opt, TREE_IN_RECURSIVE)) {
-                       opt->change(opt, mode1, mode2,
-                                   sha1, sha2, 1, 1, base->buf, 0, 0);
+
+/*
+ * convert path -> opt->diff_*() callbacks
+ *
+ * emits diff to first parent only, and tells diff tree-walker that we are done
+ * with p and it can be freed.
+ */
+static int emit_diff_first_parent_only(struct diff_options *opt, struct combine_diff_path *p)
+{
+       struct combine_diff_parent *p0 = &p->parent[0];
+       if (p->mode && p0->mode) {
+               opt->change(opt, p0->mode, p->mode, p0->sha1, p->sha1,
+                       1, 1, p->path, 0, 0);
+       }
+       else {
+               const unsigned char *sha1;
+               unsigned int mode;
+               int addremove;
+
+               if (p->mode) {
+                       addremove = '+';
+                       sha1 = p->sha1;
+                       mode = p->mode;
+               } else {
+                       addremove = '-';
+                       sha1 = p0->sha1;
+                       mode = p0->mode;
                }
-               strbuf_addch(base, '/');
-               diff_tree_sha1(sha1, sha2, base->buf, opt);
-       } else {
-               opt->change(opt, mode1, mode2, sha1, sha2, 1, 1, base->buf, 0, 0);
+
+               opt->add_remove(opt, addremove, mode, sha1, 1, p->path, 0);
        }
-       strbuf_setlen(base, old_baselen);
-       return 0;
+
+       return 0;       /* we are done with p */
 }
 
-/* A whole sub-tree went away or appeared */
-static void show_tree(struct diff_options *opt, const char *prefix,
-                     struct tree_desc *desc, struct strbuf *base)
+
+/*
+ * Make a new combine_diff_path from path/mode/sha1
+ * and append it to paths list tail.
+ *
+ * Memory for created elements could be reused:
+ *
+ *     - if last->next == NULL, the memory is allocated;
+ *
+ *     - if last->next != NULL, it is assumed that p=last->next was returned
+ *       earlier by this function, and p->next was *not* modified.
+ *       The memory is then reused from p.
+ *
+ * so for clients,
+ *
+ * - if you do need to keep the element
+ *
+ *     p = path_appendnew(p, ...);
+ *     process(p);
+ *     p->next = NULL;
+ *
+ * - if you don't need to keep the element after processing
+ *
+ *     pprev = p;
+ *     p = path_appendnew(p, ...);
+ *     process(p);
+ *     p = pprev;
+ *     ; don't forget to free tail->next in the end
+ *
+ * p->parent[] remains uninitialized.
+ */
+static struct combine_diff_path *path_appendnew(struct combine_diff_path *last,
+       int nparent, const struct strbuf *base, const char *path, int pathlen,
+       unsigned mode, const unsigned char *sha1)
 {
-       enum interesting match = entry_not_interesting;
-       for (; desc->size; update_tree_entry(desc)) {
-               if (match != all_entries_interesting) {
-                       match = tree_entry_interesting(&desc->entry, base, 0,
-                                                      &opt->pathspec);
-                       if (match == all_entries_not_interesting)
-                               break;
-                       if (match == entry_not_interesting)
-                               continue;
-               }
-               show_entry(opt, prefix, desc, base);
+       struct combine_diff_path *p;
+       int len = base->len + pathlen;
+       int alloclen = combine_diff_path_size(nparent, len);
+
+       /* if last->next is !NULL - it is a pre-allocated memory, we can reuse */
+       p = last->next;
+       if (p && (alloclen > (intptr_t)p->next)) {
+               free(p);
+               p = NULL;
+       }
+
+       if (!p) {
+               p = xmalloc(alloclen);
+
+               /*
+                * until we go to it next round, .next holds how many bytes we
+                * allocated (for faster realloc - we don't need copying old data).
+                */
+               p->next = (struct combine_diff_path *)(intptr_t)alloclen;
        }
+
+       last->next = p;
+
+       p->path = (char *)&(p->parent[nparent]);
+       memcpy(p->path, base->buf, base->len);
+       memcpy(p->path + base->len, path, pathlen);
+       p->path[len] = 0;
+       p->mode = mode;
+       hashcpy(p->sha1, sha1 ? sha1 : null_sha1);
+
+       return p;
 }
 
-/* A file entry went away or appeared */
-static void show_entry(struct diff_options *opt, const char *prefix,
-                      struct tree_desc *desc, struct strbuf *base)
+/*
+ * new path should be added to combine diff
+ *
+ * 3 cases on how/when it should be called and behaves:
+ *
+ *      t, !tp         -> path added, all parents lack it
+ *     !t,  tp         -> path removed from all parents
+ *      t,  tp         -> path modified/added
+ *                        (M for tp[i]=tp[imin], A otherwise)
+ */
+static struct combine_diff_path *emit_path(struct combine_diff_path *p,
+       struct strbuf *base, struct diff_options *opt, int nparent,
+       struct tree_desc *t, struct tree_desc *tp,
+       int imin)
 {
        unsigned mode;
        const char *path;
-       const unsigned char *sha1 = tree_entry_extract(desc, &path, &mode);
-       int pathlen = tree_entry_len(&desc->entry);
+       const unsigned char *sha1;
+       int pathlen;
        int old_baselen = base->len;
+       int i, isdir, recurse = 0, emitthis = 1;
+
+       /* at least something has to be valid */
+       assert(t || tp);
 
-       strbuf_add(base, path, pathlen);
-       if (DIFF_OPT_TST(opt, RECURSIVE) && S_ISDIR(mode)) {
-               enum object_type type;
-               struct tree_desc inner;
-               void *tree;
-               unsigned long size;
+       if (t) {
+               /* path present in resulting tree */
+               sha1 = tree_entry_extract(t, &path, &mode);
+               pathlen = tree_entry_len(&t->entry);
+               isdir = S_ISDIR(mode);
+       } else {
+               /*
+                * a path was removed - take path from imin parent. Also take
+                * mode from that parent, to decide on recursion(1).
+                *
+                * 1) all modes for tp[i]=tp[imin] should be the same wrt
+                *    S_ISDIR, thanks to base_name_compare().
+                */
+               tree_entry_extract(&tp[imin], &path, &mode);
+               pathlen = tree_entry_len(&tp[imin].entry);
 
-               tree = read_sha1_file(sha1, &type, &size);
-               if (!tree || type != OBJ_TREE)
-                       die("corrupt tree sha %s", sha1_to_hex(sha1));
+               isdir = S_ISDIR(mode);
+               sha1 = NULL;
+               mode = 0;
+       }
 
-               if (DIFF_OPT_TST(opt, TREE_IN_RECURSIVE))
-                       opt->add_remove(opt, *prefix, mode, sha1, 1, base->buf, 0);
+       if (DIFF_OPT_TST(opt, RECURSIVE) && isdir) {
+               recurse = 1;
+               emitthis = DIFF_OPT_TST(opt, TREE_IN_RECURSIVE);
+       }
 
-               strbuf_addch(base, '/');
+       if (emitthis) {
+               int keep;
+               struct combine_diff_path *pprev = p;
+               p = path_appendnew(p, nparent, base, path, pathlen, mode, sha1);
 
-               init_tree_desc(&inner, tree, size);
-               show_tree(opt, prefix, &inner, base);
-               free(tree);
-       } else
-               opt->add_remove(opt, prefix[0], mode, sha1, 1, base->buf, 0);
+               for (i = 0; i < nparent; ++i) {
+                       /*
+                        * tp[i] is valid, if present and if tp[i]==tp[imin] -
+                        * otherwise, we should ignore it.
+                        */
+                       int tpi_valid = tp && !(tp[i].entry.mode & S_IFXMIN_NEQ);
+
+                       const unsigned char *sha1_i;
+                       unsigned mode_i;
+
+                       p->parent[i].status =
+                               !t ? DIFF_STATUS_DELETED :
+                                       tpi_valid ?
+                                               DIFF_STATUS_MODIFIED :
+                                               DIFF_STATUS_ADDED;
+
+                       if (tpi_valid) {
+                               sha1_i = tp[i].entry.sha1;
+                               mode_i = tp[i].entry.mode;
+                       }
+                       else {
+                               sha1_i = NULL;
+                               mode_i = 0;
+                       }
+
+                       p->parent[i].mode = mode_i;
+                       hashcpy(p->parent[i].sha1, sha1_i ? sha1_i : null_sha1);
+               }
+
+               keep = 1;
+               if (opt->pathchange)
+                       keep = opt->pathchange(opt, p);
+
+               /*
+                * If a path was filtered or consumed - we don't need to add it
+                * to the list and can reuse its memory, leaving it as
+                * pre-allocated element on the tail.
+                *
+                * On the other hand, if path needs to be kept, we need to
+                * correct its .next to NULL, as it was pre-initialized to how
+                * much memory was allocated.
+                *
+                * see path_appendnew() for details.
+                */
+               if (!keep)
+                       p = pprev;
+               else
+                       p->next = NULL;
+       }
+
+       if (recurse) {
+               const unsigned char **parents_sha1;
+
+               parents_sha1 = xalloca(nparent * sizeof(parents_sha1[0]));
+               for (i = 0; i < nparent; ++i) {
+                       /* same rule as in emitthis */
+                       int tpi_valid = tp && !(tp[i].entry.mode & S_IFXMIN_NEQ);
+
+                       parents_sha1[i] = tpi_valid ? tp[i].entry.sha1
+                                                   : NULL;
+               }
+
+               strbuf_add(base, path, pathlen);
+               strbuf_addch(base, '/');
+               p = ll_diff_tree_paths(p, sha1, parents_sha1, nparent, base, opt);
+               xalloca_free(parents_sha1);
+       }
 
        strbuf_setlen(base, old_baselen);
+       return p;
 }
 
 static void skip_uninteresting(struct tree_desc *t, struct strbuf *base,
-                              struct diff_options *opt,
-                              enum interesting *match)
+                              struct diff_options *opt)
 {
+       enum interesting match;
+
        while (t->size) {
-               *match = tree_entry_interesting(&t->entry, base, 0, &opt->pathspec);
-               if (*match) {
-                       if (*match == all_entries_not_interesting)
+               match = tree_entry_interesting(&t->entry, base, 0, &opt->pathspec);
+               if (match) {
+                       if (match == all_entries_not_interesting)
                                t->size = 0;
                        break;
                }
@@ -128,55 +300,260 @@ static void skip_uninteresting(struct tree_desc *t, struct strbuf *base,
        }
 }
 
-int diff_tree(struct tree_desc *t1, struct tree_desc *t2,
-             const char *base_str, struct diff_options *opt)
+
+/*
+ * generate paths for combined diff D(sha1,parents_sha1[])
+ *
+ * Resulting paths are appended to combine_diff_path linked list, and also, are
+ * emitted on the go via opt->pathchange() callback, so it is possible to
+ * process the result as batch or incrementally.
+ *
+ * The paths are generated scanning new tree and all parents trees
+ * simultaneously, similarly to what diff_tree() was doing for 2 trees.
+ * The theory behind such scan is as follows:
+ *
+ *
+ * D(T,P1...Pn) calculation scheme
+ * -------------------------------
+ *
+ * D(T,P1...Pn) = D(T,P1) ^ ... ^ D(T,Pn)      (regarding resulting paths set)
+ *
+ *     D(T,Pj)         - diff between T..Pj
+ *     D(T,P1...Pn)    - combined diff from T to parents P1,...,Pn
+ *
+ *
+ * We start from all trees, which are sorted, and compare their entries in
+ * lock-step:
+ *
+ *      T     P1       Pn
+ *      -     -        -
+ *     |t|   |p1|     |pn|
+ *     |-|   |--| ... |--|      imin = argmin(p1...pn)
+ *     | |   |  |     |  |
+ *     |-|   |--|     |--|
+ *     |.|   |. |     |. |
+ *      .     .        .
+ *      .     .        .
+ *
+ * at any time there could be 3 cases:
+ *
+ *     1)  t < p[imin];
+ *     2)  t > p[imin];
+ *     3)  t = p[imin].
+ *
+ * Schematic deduction of what every case means, and what to do, follows:
+ *
+ * 1)  t < p[imin]  ->  ∀j t ∉ Pj  ->  "+t" ∈ D(T,Pj)  ->  D += "+t";  t↓
+ *
+ * 2)  t > p[imin]
+ *
+ *     2.1) ∃j: pj > p[imin]  ->  "-p[imin]" ∉ D(T,Pj)  ->  D += ø;  ∀ pi=p[imin]  pi↓
+ *     2.2) ∀i  pi = p[imin]  ->  pi ∉ T  ->  "-pi" ∈ D(T,Pi)  ->  D += "-p[imin]";  ∀i pi↓
+ *
+ * 3)  t = p[imin]
+ *
+ *     3.1) ∃j: pj > p[imin]  ->  "+t" ∈ D(T,Pj)  ->  only pi=p[imin] remains to investigate
+ *     3.2) pi = p[imin]  ->  investigate δ(t,pi)
+ *      |
+ *      |
+ *      v
+ *
+ *     3.1+3.2) looking at δ(t,pi) ∀i: pi=p[imin] - if all != ø  ->
+ *
+ *                       ⎧δ(t,pi)  - if pi=p[imin]
+ *              ->  D += ⎨
+ *                       ⎩"+t"     - if pi>p[imin]
+ *
+ *
+ *     in any case t↓  ∀ pi=p[imin]  pi↓
+ *
+ *
+ * ~~~~~~~~
+ *
+ * NOTE
+ *
+ *     Usual diff D(A,B) is by definition the same as combined diff D(A,[B]),
+ *     so this diff paths generator can, and is used, for plain diffs
+ *     generation too.
+ *
+ *     Please keep attention to the common D(A,[B]) case when working on the
+ *     code, in order not to slow it down.
+ *
+ * NOTE
+ *     nparent must be > 0.
+ */
+
+
+/* ∀ pi=p[imin]  pi↓ */
+static inline void update_tp_entries(struct tree_desc *tp, int nparent)
 {
-       struct strbuf base;
-       int baselen = strlen(base_str);
-       enum interesting t1_match = entry_not_interesting;
-       enum interesting t2_match = entry_not_interesting;
+       int i;
+       for (i = 0; i < nparent; ++i)
+               if (!(tp[i].entry.mode & S_IFXMIN_NEQ))
+                       update_tree_entry(&tp[i]);
+}
+
+static struct combine_diff_path *ll_diff_tree_paths(
+       struct combine_diff_path *p, const unsigned char *sha1,
+       const unsigned char **parents_sha1, int nparent,
+       struct strbuf *base, struct diff_options *opt)
+{
+       struct tree_desc t, *tp;
+       void *ttree, **tptree;
+       int i;
+
+       tp     = xalloca(nparent * sizeof(tp[0]));
+       tptree = xalloca(nparent * sizeof(tptree[0]));
+
+       /*
+        * load parents first, as they are probably already cached.
+        *
+        * ( log_tree_diff() parses commit->parent before calling here via
+        *   diff_tree_sha1(parent, commit) )
+        */
+       for (i = 0; i < nparent; ++i)
+               tptree[i] = fill_tree_descriptor(&tp[i], parents_sha1[i]);
+       ttree = fill_tree_descriptor(&t, sha1);
 
        /* Enable recursion indefinitely */
        opt->pathspec.recursive = DIFF_OPT_TST(opt, RECURSIVE);
 
-       strbuf_init(&base, PATH_MAX);
-       strbuf_add(&base, base_str, baselen);
-
        for (;;) {
+               int imin, cmp;
+
                if (diff_can_quit_early(opt))
                        break;
+
                if (opt->pathspec.nr) {
-                       skip_uninteresting(t1, &base, opt, &t1_match);
-                       skip_uninteresting(t2, &base, opt, &t2_match);
+                       skip_uninteresting(&t, base, opt);
+                       for (i = 0; i < nparent; i++)
+                               skip_uninteresting(&tp[i], base, opt);
                }
-               if (!t1->size) {
-                       if (!t2->size)
+
+               /* comparing is finished when all trees are done */
+               if (!t.size) {
+                       int done = 1;
+                       for (i = 0; i < nparent; ++i)
+                               if (tp[i].size) {
+                                       done = 0;
+                                       break;
+                               }
+                       if (done)
                                break;
-                       show_entry(opt, "+", t2, &base);
-                       update_tree_entry(t2);
-                       continue;
                }
-               if (!t2->size) {
-                       show_entry(opt, "-", t1, &base);
-                       update_tree_entry(t1);
-                       continue;
+
+               /*
+                * lookup imin = argmin(p1...pn),
+                * mark entries whether they =p[imin] along the way
+                */
+               imin = 0;
+               tp[0].entry.mode &= ~S_IFXMIN_NEQ;
+
+               for (i = 1; i < nparent; ++i) {
+                       cmp = tree_entry_pathcmp(&tp[i], &tp[imin]);
+                       if (cmp < 0) {
+                               imin = i;
+                               tp[i].entry.mode &= ~S_IFXMIN_NEQ;
+                       }
+                       else if (cmp == 0) {
+                               tp[i].entry.mode &= ~S_IFXMIN_NEQ;
+                       }
+                       else {
+                               tp[i].entry.mode |= S_IFXMIN_NEQ;
+                       }
+               }
+
+               /* fixup markings for entries before imin */
+               for (i = 0; i < imin; ++i)
+                       tp[i].entry.mode |= S_IFXMIN_NEQ;       /* pi > p[imin] */
+
+
+
+               /* compare t vs p[imin] */
+               cmp = tree_entry_pathcmp(&t, &tp[imin]);
+
+               /* t = p[imin] */
+               if (cmp == 0) {
+                       /* are either pi > p[imin] or diff(t,pi) != ø ? */
+                       if (!DIFF_OPT_TST(opt, FIND_COPIES_HARDER)) {
+                               for (i = 0; i < nparent; ++i) {
+                                       /* p[i] > p[imin] */
+                                       if (tp[i].entry.mode & S_IFXMIN_NEQ)
+                                               continue;
+
+                                       /* diff(t,pi) != ø */
+                                       if (hashcmp(t.entry.sha1, tp[i].entry.sha1) ||
+                                           (t.entry.mode != tp[i].entry.mode))
+                                               continue;
+
+                                       goto skip_emit_t_tp;
+                               }
+                       }
+
+                       /* D += {δ(t,pi) if pi=p[imin];  "+a" if pi > p[imin]} */
+                       p = emit_path(p, base, opt, nparent,
+                                       &t, tp, imin);
+
+               skip_emit_t_tp:
+                       /* t↓,  ∀ pi=p[imin]  pi↓ */
+                       update_tree_entry(&t);
+                       update_tp_entries(tp, nparent);
+               }
+
+               /* t < p[imin] */
+               else if (cmp < 0) {
+                       /* D += "+t" */
+                       p = emit_path(p, base, opt, nparent,
+                                       &t, /*tp=*/NULL, -1);
+
+                       /* t↓ */
+                       update_tree_entry(&t);
                }
-               switch (compare_tree_entry(t1, t2, &base, opt)) {
-               case -1:
-                       update_tree_entry(t1);
-                       continue;
-               case 0:
-                       update_tree_entry(t1);
-                       /* Fallthrough */
-               case 1:
-                       update_tree_entry(t2);
-                       continue;
+
+               /* t > p[imin] */
+               else {
+                       /* ∀i pi=p[imin] -> D += "-p[imin]" */
+                       if (!DIFF_OPT_TST(opt, FIND_COPIES_HARDER)) {
+                               for (i = 0; i < nparent; ++i)
+                                       if (tp[i].entry.mode & S_IFXMIN_NEQ)
+                                               goto skip_emit_tp;
+                       }
+
+                       p = emit_path(p, base, opt, nparent,
+                                       /*t=*/NULL, tp, imin);
+
+               skip_emit_tp:
+                       /* ∀ pi=p[imin]  pi↓ */
+                       update_tp_entries(tp, nparent);
                }
-               die("git diff-tree: internal error");
        }
 
-       strbuf_release(&base);
-       return 0;
+       free(ttree);
+       for (i = nparent-1; i >= 0; i--)
+               free(tptree[i]);
+       xalloca_free(tptree);
+       xalloca_free(tp);
+
+       return p;
+}
+
+struct combine_diff_path *diff_tree_paths(
+       struct combine_diff_path *p, const unsigned char *sha1,
+       const unsigned char **parents_sha1, int nparent,
+       struct strbuf *base, struct diff_options *opt)
+{
+       p = ll_diff_tree_paths(p, sha1, parents_sha1, nparent, base, opt);
+
+       /*
+        * free pre-allocated last element, if any
+        * (see path_appendnew() for details about why)
+        */
+       if (p->next) {
+               free(p->next);
+               p->next = NULL;
+       }
+
+       return p;
 }
 
 /*
@@ -190,7 +567,7 @@ static inline int diff_might_be_rename(void)
                !DIFF_FILE_VALID(diff_queued_diff.queue[0]->one);
 }
 
-static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, const char *base, struct diff_options *opt)
+static void try_to_follow_renames(const unsigned char *old, const unsigned char *new, struct strbuf *base, struct diff_options *opt)
 {
        struct diff_options diff_opts;
        struct diff_queue_struct *q = &diff_queued_diff;
@@ -228,7 +605,7 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co
        diff_opts.break_opt = opt->break_opt;
        diff_opts.rename_score = opt->rename_score;
        diff_setup_done(&diff_opts);
-       diff_tree(t1, t2, base, &diff_opts);
+       ll_diff_tree_sha1(old, new, base, &diff_opts);
        diffcore_std(&diff_opts);
        free_pathspec(&diff_opts.pathspec);
 
@@ -287,25 +664,40 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co
        q->nr = 1;
 }
 
-int diff_tree_sha1(const unsigned char *old, const unsigned char *new, const char *base, struct diff_options *opt)
+static int ll_diff_tree_sha1(const unsigned char *old, const unsigned char *new,
+                            struct strbuf *base, struct diff_options *opt)
 {
-       void *tree1, *tree2;
-       struct tree_desc t1, t2;
-       unsigned long size1, size2;
-       int retval;
+       struct combine_diff_path phead, *p;
+       pathchange_fn_t pathchange_old = opt->pathchange;
 
-       tree1 = fill_tree_descriptor(&t1, old);
-       tree2 = fill_tree_descriptor(&t2, new);
-       size1 = t1.size;
-       size2 = t2.size;
-       retval = diff_tree(&t1, &t2, base, opt);
-       if (!*base && DIFF_OPT_TST(opt, FOLLOW_RENAMES) && diff_might_be_rename()) {
-               init_tree_desc(&t1, tree1, size1);
-               init_tree_desc(&t2, tree2, size2);
-               try_to_follow_renames(&t1, &t2, base, opt);
+       phead.next = NULL;
+       opt->pathchange = emit_diff_first_parent_only;
+       diff_tree_paths(&phead, new, &old, 1, base, opt);
+
+       for (p = phead.next; p;) {
+               struct combine_diff_path *pprev = p;
+               p = p->next;
+               free(pprev);
        }
-       free(tree1);
-       free(tree2);
+
+       opt->pathchange = pathchange_old;
+       return 0;
+}
+
+int diff_tree_sha1(const unsigned char *old, const unsigned char *new, const char *base_str, struct diff_options *opt)
+{
+       struct strbuf base;
+       int retval;
+
+       strbuf_init(&base, PATH_MAX);
+       strbuf_addstr(&base, base_str);
+
+       retval = ll_diff_tree_sha1(old, new, &base, opt);
+       if (!*base_str && DIFF_OPT_TST(opt, FOLLOW_RENAMES) && diff_might_be_rename())
+               try_to_follow_renames(old, new, &base, opt);
+
+       strbuf_release(&base);
+
        return retval;
 }
 
index 4dc86c7fe5f66b858b6bd7834a76b1dbbb63a339..5dd9a718047bc14e9ae840a46d1f71cb435fd6d7 100644 (file)
@@ -144,16 +144,6 @@ struct tree_desc_x {
        struct tree_desc_skip *skip;
 };
 
-static int name_compare(const char *a, int a_len,
-                       const char *b, int b_len)
-{
-       int len = (a_len < b_len) ? a_len : b_len;
-       int cmp = memcmp(a, b, len);
-       if (cmp)
-               return cmp;
-       return (a_len - b_len);
-}
-
 static int check_entry_match(const char *a, int a_len, const char *b, int b_len)
 {
        /*
diff --git a/unicode_width.h b/unicode_width.h
new file mode 100644 (file)
index 0000000..47cdd23
--- /dev/null
@@ -0,0 +1,323 @@
+static const struct interval zero_width[] = {
+{ 0x0300, 0x036F },
+{ 0x0483, 0x0489 },
+{ 0x0591, 0x05BD },
+{ 0x05BF, 0x05BF },
+{ 0x05C1, 0x05C2 },
+{ 0x05C4, 0x05C5 },
+{ 0x05C7, 0x05C7 },
+{ 0x0600, 0x0605 },
+{ 0x0610, 0x061A },
+{ 0x061C, 0x061C },
+{ 0x064B, 0x065F },
+{ 0x0670, 0x0670 },
+{ 0x06D6, 0x06DD },
+{ 0x06DF, 0x06E4 },
+{ 0x06E7, 0x06E8 },
+{ 0x06EA, 0x06ED },
+{ 0x070F, 0x070F },
+{ 0x0711, 0x0711 },
+{ 0x0730, 0x074A },
+{ 0x07A6, 0x07B0 },
+{ 0x07EB, 0x07F3 },
+{ 0x0816, 0x0819 },
+{ 0x081B, 0x0823 },
+{ 0x0825, 0x0827 },
+{ 0x0829, 0x082D },
+{ 0x0859, 0x085B },
+{ 0x08E4, 0x0902 },
+{ 0x093A, 0x093A },
+{ 0x093C, 0x093C },
+{ 0x0941, 0x0948 },
+{ 0x094D, 0x094D },
+{ 0x0951, 0x0957 },
+{ 0x0962, 0x0963 },
+{ 0x0981, 0x0981 },
+{ 0x09BC, 0x09BC },
+{ 0x09C1, 0x09C4 },
+{ 0x09CD, 0x09CD },
+{ 0x09E2, 0x09E3 },
+{ 0x0A01, 0x0A02 },
+{ 0x0A3C, 0x0A3C },
+{ 0x0A41, 0x0A42 },
+{ 0x0A47, 0x0A48 },
+{ 0x0A4B, 0x0A4D },
+{ 0x0A51, 0x0A51 },
+{ 0x0A70, 0x0A71 },
+{ 0x0A75, 0x0A75 },
+{ 0x0A81, 0x0A82 },
+{ 0x0ABC, 0x0ABC },
+{ 0x0AC1, 0x0AC5 },
+{ 0x0AC7, 0x0AC8 },
+{ 0x0ACD, 0x0ACD },
+{ 0x0AE2, 0x0AE3 },
+{ 0x0B01, 0x0B01 },
+{ 0x0B3C, 0x0B3C },
+{ 0x0B3F, 0x0B3F },
+{ 0x0B41, 0x0B44 },
+{ 0x0B4D, 0x0B4D },
+{ 0x0B56, 0x0B56 },
+{ 0x0B62, 0x0B63 },
+{ 0x0B82, 0x0B82 },
+{ 0x0BC0, 0x0BC0 },
+{ 0x0BCD, 0x0BCD },
+{ 0x0C00, 0x0C00 },
+{ 0x0C3E, 0x0C40 },
+{ 0x0C46, 0x0C48 },
+{ 0x0C4A, 0x0C4D },
+{ 0x0C55, 0x0C56 },
+{ 0x0C62, 0x0C63 },
+{ 0x0C81, 0x0C81 },
+{ 0x0CBC, 0x0CBC },
+{ 0x0CBF, 0x0CBF },
+{ 0x0CC6, 0x0CC6 },
+{ 0x0CCC, 0x0CCD },
+{ 0x0CE2, 0x0CE3 },
+{ 0x0D01, 0x0D01 },
+{ 0x0D41, 0x0D44 },
+{ 0x0D4D, 0x0D4D },
+{ 0x0D62, 0x0D63 },
+{ 0x0DCA, 0x0DCA },
+{ 0x0DD2, 0x0DD4 },
+{ 0x0DD6, 0x0DD6 },
+{ 0x0E31, 0x0E31 },
+{ 0x0E34, 0x0E3A },
+{ 0x0E47, 0x0E4E },
+{ 0x0EB1, 0x0EB1 },
+{ 0x0EB4, 0x0EB9 },
+{ 0x0EBB, 0x0EBC },
+{ 0x0EC8, 0x0ECD },
+{ 0x0F18, 0x0F19 },
+{ 0x0F35, 0x0F35 },
+{ 0x0F37, 0x0F37 },
+{ 0x0F39, 0x0F39 },
+{ 0x0F71, 0x0F7E },
+{ 0x0F80, 0x0F84 },
+{ 0x0F86, 0x0F87 },
+{ 0x0F8D, 0x0F97 },
+{ 0x0F99, 0x0FBC },
+{ 0x0FC6, 0x0FC6 },
+{ 0x102D, 0x1030 },
+{ 0x1032, 0x1037 },
+{ 0x1039, 0x103A },
+{ 0x103D, 0x103E },
+{ 0x1058, 0x1059 },
+{ 0x105E, 0x1060 },
+{ 0x1071, 0x1074 },
+{ 0x1082, 0x1082 },
+{ 0x1085, 0x1086 },
+{ 0x108D, 0x108D },
+{ 0x109D, 0x109D },
+{ 0x1160, 0x11FF },
+{ 0x135D, 0x135F },
+{ 0x1712, 0x1714 },
+{ 0x1732, 0x1734 },
+{ 0x1752, 0x1753 },
+{ 0x1772, 0x1773 },
+{ 0x17B4, 0x17B5 },
+{ 0x17B7, 0x17BD },
+{ 0x17C6, 0x17C6 },
+{ 0x17C9, 0x17D3 },
+{ 0x17DD, 0x17DD },
+{ 0x180B, 0x180E },
+{ 0x18A9, 0x18A9 },
+{ 0x1920, 0x1922 },
+{ 0x1927, 0x1928 },
+{ 0x1932, 0x1932 },
+{ 0x1939, 0x193B },
+{ 0x1A17, 0x1A18 },
+{ 0x1A1B, 0x1A1B },
+{ 0x1A56, 0x1A56 },
+{ 0x1A58, 0x1A5E },
+{ 0x1A60, 0x1A60 },
+{ 0x1A62, 0x1A62 },
+{ 0x1A65, 0x1A6C },
+{ 0x1A73, 0x1A7C },
+{ 0x1A7F, 0x1A7F },
+{ 0x1AB0, 0x1ABE },
+{ 0x1B00, 0x1B03 },
+{ 0x1B34, 0x1B34 },
+{ 0x1B36, 0x1B3A },
+{ 0x1B3C, 0x1B3C },
+{ 0x1B42, 0x1B42 },
+{ 0x1B6B, 0x1B73 },
+{ 0x1B80, 0x1B81 },
+{ 0x1BA2, 0x1BA5 },
+{ 0x1BA8, 0x1BA9 },
+{ 0x1BAB, 0x1BAD },
+{ 0x1BE6, 0x1BE6 },
+{ 0x1BE8, 0x1BE9 },
+{ 0x1BED, 0x1BED },
+{ 0x1BEF, 0x1BF1 },
+{ 0x1C2C, 0x1C33 },
+{ 0x1C36, 0x1C37 },
+{ 0x1CD0, 0x1CD2 },
+{ 0x1CD4, 0x1CE0 },
+{ 0x1CE2, 0x1CE8 },
+{ 0x1CED, 0x1CED },
+{ 0x1CF4, 0x1CF4 },
+{ 0x1CF8, 0x1CF9 },
+{ 0x1DC0, 0x1DF5 },
+{ 0x1DFC, 0x1DFF },
+{ 0x200B, 0x200F },
+{ 0x202A, 0x202E },
+{ 0x2060, 0x2064 },
+{ 0x2066, 0x206F },
+{ 0x20D0, 0x20F0 },
+{ 0x2CEF, 0x2CF1 },
+{ 0x2D7F, 0x2D7F },
+{ 0x2DE0, 0x2DFF },
+{ 0x302A, 0x302D },
+{ 0x3099, 0x309A },
+{ 0xA66F, 0xA672 },
+{ 0xA674, 0xA67D },
+{ 0xA69F, 0xA69F },
+{ 0xA6F0, 0xA6F1 },
+{ 0xA802, 0xA802 },
+{ 0xA806, 0xA806 },
+{ 0xA80B, 0xA80B },
+{ 0xA825, 0xA826 },
+{ 0xA8C4, 0xA8C4 },
+{ 0xA8E0, 0xA8F1 },
+{ 0xA926, 0xA92D },
+{ 0xA947, 0xA951 },
+{ 0xA980, 0xA982 },
+{ 0xA9B3, 0xA9B3 },
+{ 0xA9B6, 0xA9B9 },
+{ 0xA9BC, 0xA9BC },
+{ 0xA9E5, 0xA9E5 },
+{ 0xAA29, 0xAA2E },
+{ 0xAA31, 0xAA32 },
+{ 0xAA35, 0xAA36 },
+{ 0xAA43, 0xAA43 },
+{ 0xAA4C, 0xAA4C },
+{ 0xAA7C, 0xAA7C },
+{ 0xAAB0, 0xAAB0 },
+{ 0xAAB2, 0xAAB4 },
+{ 0xAAB7, 0xAAB8 },
+{ 0xAABE, 0xAABF },
+{ 0xAAC1, 0xAAC1 },
+{ 0xAAEC, 0xAAED },
+{ 0xAAF6, 0xAAF6 },
+{ 0xABE5, 0xABE5 },
+{ 0xABE8, 0xABE8 },
+{ 0xABED, 0xABED },
+{ 0xFB1E, 0xFB1E },
+{ 0xFE00, 0xFE0F },
+{ 0xFE20, 0xFE2D },
+{ 0xFEFF, 0xFEFF },
+{ 0xFFF9, 0xFFFB },
+{ 0x101FD, 0x101FD },
+{ 0x102E0, 0x102E0 },
+{ 0x10376, 0x1037A },
+{ 0x10A01, 0x10A03 },
+{ 0x10A05, 0x10A06 },
+{ 0x10A0C, 0x10A0F },
+{ 0x10A38, 0x10A3A },
+{ 0x10A3F, 0x10A3F },
+{ 0x10AE5, 0x10AE6 },
+{ 0x11001, 0x11001 },
+{ 0x11038, 0x11046 },
+{ 0x1107F, 0x11081 },
+{ 0x110B3, 0x110B6 },
+{ 0x110B9, 0x110BA },
+{ 0x110BD, 0x110BD },
+{ 0x11100, 0x11102 },
+{ 0x11127, 0x1112B },
+{ 0x1112D, 0x11134 },
+{ 0x11173, 0x11173 },
+{ 0x11180, 0x11181 },
+{ 0x111B6, 0x111BE },
+{ 0x1122F, 0x11231 },
+{ 0x11234, 0x11234 },
+{ 0x11236, 0x11237 },
+{ 0x112DF, 0x112DF },
+{ 0x112E3, 0x112EA },
+{ 0x11301, 0x11301 },
+{ 0x1133C, 0x1133C },
+{ 0x11340, 0x11340 },
+{ 0x11366, 0x1136C },
+{ 0x11370, 0x11374 },
+{ 0x114B3, 0x114B8 },
+{ 0x114BA, 0x114BA },
+{ 0x114BF, 0x114C0 },
+{ 0x114C2, 0x114C3 },
+{ 0x115B2, 0x115B5 },
+{ 0x115BC, 0x115BD },
+{ 0x115BF, 0x115C0 },
+{ 0x11633, 0x1163A },
+{ 0x1163D, 0x1163D },
+{ 0x1163F, 0x11640 },
+{ 0x116AB, 0x116AB },
+{ 0x116AD, 0x116AD },
+{ 0x116B0, 0x116B5 },
+{ 0x116B7, 0x116B7 },
+{ 0x16AF0, 0x16AF4 },
+{ 0x16B30, 0x16B36 },
+{ 0x16F8F, 0x16F92 },
+{ 0x1BC9D, 0x1BC9E },
+{ 0x1BCA0, 0x1BCA3 },
+{ 0x1D167, 0x1D169 },
+{ 0x1D173, 0x1D182 },
+{ 0x1D185, 0x1D18B },
+{ 0x1D1AA, 0x1D1AD },
+{ 0x1D242, 0x1D244 },
+{ 0x1E8D0, 0x1E8D6 },
+{ 0xE0001, 0xE0001 },
+{ 0xE0020, 0xE007F },
+{ 0xE0100, 0xE01EF }
+};
+static const struct interval double_width[] = {
+{ /* plane */ 0x0, 0x1C },
+{ /* plane */ 0x1C, 0x21 },
+{ /* plane */ 0x21, 0x22 },
+{ /* plane */ 0x22, 0x23 },
+{ /* plane */ 0x0, 0x0 },
+{ /* plane */ 0x0, 0x0 },
+{ /* plane */ 0x0, 0x0 },
+{ /* plane */ 0x0, 0x0 },
+{ /* plane */ 0x0, 0x0 },
+{ /* plane */ 0x0, 0x0 },
+{ /* plane */ 0x0, 0x0 },
+{ /* plane */ 0x0, 0x0 },
+{ /* plane */ 0x0, 0x0 },
+{ /* plane */ 0x0, 0x0 },
+{ /* plane */ 0x0, 0x0 },
+{ /* plane */ 0x0, 0x0 },
+{ /* plane */ 0x0, 0x0 },
+{ 0x1100, 0x115F },
+{ 0x2329, 0x232A },
+{ 0x2E80, 0x2E99 },
+{ 0x2E9B, 0x2EF3 },
+{ 0x2F00, 0x2FD5 },
+{ 0x2FF0, 0x2FFB },
+{ 0x3000, 0x303E },
+{ 0x3041, 0x3096 },
+{ 0x3099, 0x30FF },
+{ 0x3105, 0x312D },
+{ 0x3131, 0x318E },
+{ 0x3190, 0x31BA },
+{ 0x31C0, 0x31E3 },
+{ 0x31F0, 0x321E },
+{ 0x3220, 0x3247 },
+{ 0x3250, 0x32FE },
+{ 0x3300, 0x4DBF },
+{ 0x4E00, 0xA48C },
+{ 0xA490, 0xA4C6 },
+{ 0xA960, 0xA97C },
+{ 0xAC00, 0xD7A3 },
+{ 0xF900, 0xFAFF },
+{ 0xFE10, 0xFE19 },
+{ 0xFE30, 0xFE52 },
+{ 0xFE54, 0xFE66 },
+{ 0xFE68, 0xFE6B },
+{ 0xFF01, 0xFF60 },
+{ 0xFFE0, 0xFFE6 },
+{ 0x1B000, 0x1B001 },
+{ 0x1F200, 0x1F202 },
+{ 0x1F210, 0x1F23A },
+{ 0x1F240, 0x1F248 },
+{ 0x1F250, 0x1F251 },
+{ 0x20000, 0x2FFFD },
+{ 0x30000, 0x3FFFD }
+};
index 97fc9954672f2c374541cad827bb5c459abebcdc..c6aa8fb993aa4bd92e4269d7a85c6b45fe9801e8 100644 (file)
@@ -8,6 +8,7 @@
 #include "progress.h"
 #include "refs.h"
 #include "attr.h"
+#include "split-index.h"
 
 /*
  * Error messages expected by scripts out of plumbing commands such as
@@ -56,17 +57,15 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,
        int i;
        const char **msgs = opts->msgs;
        const char *msg;
-       char *tmp;
        const char *cmd2 = strcmp(cmd, "checkout") ? cmd : "switch branches";
+
        if (advice_commit_before_merge)
                msg = "Your local changes to the following files would be overwritten by %s:\n%%s"
                        "Please, commit your changes or stash them before you can %s.";
        else
                msg = "Your local changes to the following files would be overwritten by %s:\n%%s";
-       tmp = xmalloc(strlen(msg) + strlen(cmd) + strlen(cmd2) - 2);
-       sprintf(tmp, msg, cmd, cmd2);
-       msgs[ERROR_WOULD_OVERWRITE] = tmp;
-       msgs[ERROR_NOT_UPTODATE_FILE] = tmp;
+       msgs[ERROR_WOULD_OVERWRITE] = msgs[ERROR_NOT_UPTODATE_FILE] =
+               xstrfmt(msg, cmd, cmd2);
 
        msgs[ERROR_NOT_UPTODATE_DIR] =
                "Updating the following directories would lose untracked files in it:\n%s";
@@ -76,12 +75,9 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,
                        "Please move or remove them before you can %s.";
        else
                msg = "The following untracked working tree files would be %s by %s:\n%%s";
-       tmp = xmalloc(strlen(msg) + strlen(cmd) + strlen("removed") + strlen(cmd2) - 4);
-       sprintf(tmp, msg, "removed", cmd, cmd2);
-       msgs[ERROR_WOULD_LOSE_UNTRACKED_REMOVED] = tmp;
-       tmp = xmalloc(strlen(msg) + strlen(cmd) + strlen("overwritten") + strlen(cmd2) - 4);
-       sprintf(tmp, msg, "overwritten", cmd, cmd2);
-       msgs[ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN] = tmp;
+
+       msgs[ERROR_WOULD_LOSE_UNTRACKED_REMOVED] = xstrfmt(msg, "removed", cmd, cmd2);
+       msgs[ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN] = xstrfmt(msg, "overwritten", cmd, cmd2);
 
        /*
         * Special case: ERROR_BIND_OVERLAP refers to a pair of paths, we
@@ -246,7 +242,9 @@ static int verify_absent_sparse(const struct cache_entry *ce,
                                enum unpack_trees_error_types,
                                struct unpack_trees_options *o);
 
-static int apply_sparse_checkout(struct cache_entry *ce, struct unpack_trees_options *o)
+static int apply_sparse_checkout(struct index_state *istate,
+                                struct cache_entry *ce,
+                                struct unpack_trees_options *o)
 {
        int was_skip_worktree = ce_skip_worktree(ce);
 
@@ -254,6 +252,10 @@ static int apply_sparse_checkout(struct cache_entry *ce, struct unpack_trees_opt
                ce->ce_flags |= CE_SKIP_WORKTREE;
        else
                ce->ce_flags &= ~CE_SKIP_WORKTREE;
+       if (was_skip_worktree != ce_skip_worktree(ce)) {
+               ce->ce_flags |= CE_UPDATE_IN_BASE;
+               istate->cache_changed |= CE_ENTRY_CHANGED;
+       }
 
        /*
         * if (!was_skip_worktree && !ce_skip_worktree()) {
@@ -622,17 +624,6 @@ static int unpack_failed(struct unpack_trees_options *o, const char *message)
        return -1;
 }
 
-/* NEEDSWORK: give this a better name and share with tree-walk.c */
-static int name_compare(const char *a, int a_len,
-                       const char *b, int b_len)
-{
-       int len = (a_len < b_len) ? a_len : b_len;
-       int cmp = memcmp(a, b, len);
-       if (cmp)
-               return cmp;
-       return (a_len - b_len);
-}
-
 /*
  * The tree traversal is looking at name p.  If we have a matching entry,
  * return it.  If name p is a directory in the index, do not return
@@ -1025,6 +1016,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
        state.force = 1;
        state.quiet = 1;
        state.refresh_cache = 1;
+       state.istate = &o->result;
 
        memset(&el, 0, sizeof(el));
        if (!core_apply_sparse_checkout || !o->update)
@@ -1041,6 +1033,10 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
        o->result.timestamp.sec = o->src_index->timestamp.sec;
        o->result.timestamp.nsec = o->src_index->timestamp.nsec;
        o->result.version = o->src_index->version;
+       o->result.split_index = o->src_index->split_index;
+       if (o->result.split_index)
+               o->result.split_index->refcount++;
+       hashcpy(o->result.sha1, o->src_index->sha1);
        o->merge_size = len;
        mark_all_ce_unused(o->src_index);
 
@@ -1131,7 +1127,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
                                ret = -1;
                        }
 
-                       if (apply_sparse_checkout(ce, o)) {
+                       if (apply_sparse_checkout(&o->result, ce, o)) {
                                if (!o->show_all_errors)
                                        goto return_failed;
                                ret = -1;
@@ -1259,7 +1255,7 @@ static void invalidate_ce_path(const struct cache_entry *ce,
                               struct unpack_trees_options *o)
 {
        if (ce)
-               cache_tree_invalidate_path(o->src_index->cache_tree, ce->name);
+               cache_tree_invalidate_path(o->src_index, ce->name);
 }
 
 /*
diff --git a/update_unicode.sh b/update_unicode.sh
new file mode 100755 (executable)
index 0000000..000b937
--- /dev/null
@@ -0,0 +1,37 @@
+#!/bin/sh
+#See http://www.unicode.org/reports/tr44/
+#
+#Me Enclosing_Mark  an enclosing combining mark
+#Mn Nonspacing_Mark a nonspacing combining mark (zero advance width)
+#Cf Format          a format control character
+#
+UNICODEWIDTH_H=../unicode_width.h
+if ! test -d unicode; then
+       mkdir unicode
+fi &&
+( cd unicode &&
+       if ! test -f UnicodeData.txt; then
+               wget http://www.unicode.org/Public/UCD/latest/ucd/UnicodeData.txt
+       fi &&
+       if ! test -f EastAsianWidth.txt; then
+               wget http://www.unicode.org/Public/UCD/latest/ucd/EastAsianWidth.txt
+       fi &&
+       if ! test -d uniset; then
+               git clone https://github.com/depp/uniset.git
+       fi &&
+       (
+               cd uniset &&
+               if ! test -x uniset; then
+                       autoreconf -i &&
+                       ./configure --enable-warnings=-Werror CFLAGS='-O0 -ggdb'
+               fi &&
+               make
+       ) &&
+       echo "static const struct interval zero_width[] = {" >$UNICODEWIDTH_H &&
+       UNICODE_DIR=. ./uniset/uniset --32 cat:Me,Mn,Cf + U+1160..U+11FF - U+00AD |
+       grep -v plane >>$UNICODEWIDTH_H &&
+       echo "};" >>$UNICODEWIDTH_H &&
+       echo "static const struct interval double_width[] = {" >>$UNICODEWIDTH_H &&
+       UNICODE_DIR=. ./uniset/uniset --32 eaw:F,W >>$UNICODEWIDTH_H &&
+       echo "};" >>$UNICODEWIDTH_H
+)
index ec87cba75099ebe05e936430ca3b688275e01a4a..3d4c54b5cd5d6f6cb4e0ea97550799eb9d46f033 100644 (file)
@@ -483,8 +483,7 @@ int urlmatch_config_entry(const char *var, const char *value, void *cb)
        int user_matched = 0;
        int retval;
 
-       key = skip_prefix(var, collect->section);
-       if (!key || *(key++) != '.') {
+       if (!skip_prefix(var, collect->section, &key) || *(key++) != '.') {
                if (collect->cascade_fn)
                        return collect->cascade_fn(var, value, cb);
                return 0; /* not interested */
diff --git a/utf8.c b/utf8.c
index 77c28d492cccfcbcb8a302d168a81b21d909ef12..b30790d043aa4b01da00686654dfb615a92e75b6 100644 (file)
--- a/utf8.c
+++ b/utf8.c
@@ -80,52 +80,8 @@ static int git_wcwidth(ucs_char_t ch)
 {
        /*
         * Sorted list of non-overlapping intervals of non-spacing characters,
-        * generated by
-        *   "uniset +cat=Me +cat=Mn +cat=Cf -00AD +1160-11FF +200B c".
         */
-       static const struct interval combining[] = {
-               { 0x0300, 0x036F }, { 0x0483, 0x0489 }, { 0x0591, 0x05BD },
-               { 0x05BF, 0x05BF }, { 0x05C1, 0x05C2 }, { 0x05C4, 0x05C5 },
-               { 0x05C7, 0x05C7 }, { 0x0600, 0x0604 }, { 0x0610, 0x061A },
-               { 0x064B, 0x065F }, { 0x0670, 0x0670 }, { 0x06D6, 0x06E4 },
-               { 0x06E7, 0x06E8 }, { 0x06EA, 0x06ED }, { 0x070F, 0x070F },
-               { 0x0711, 0x0711 }, { 0x0730, 0x074A }, { 0x07A6, 0x07B0 },
-               { 0x0901, 0x0902 }, { 0x093C, 0x093C }, { 0x0941, 0x0948 },
-               { 0x094D, 0x094D }, { 0x0951, 0x0954 }, { 0x0962, 0x0963 },
-               { 0x0981, 0x0981 }, { 0x09BC, 0x09BC }, { 0x09C1, 0x09C4 },
-               { 0x09CD, 0x09CD }, { 0x09E2, 0x09E3 }, { 0x0A01, 0x0A02 },
-               { 0x0A3C, 0x0A3C }, { 0x0A41, 0x0A42 }, { 0x0A47, 0x0A48 },
-               { 0x0A4B, 0x0A4D }, { 0x0A70, 0x0A71 }, { 0x0A81, 0x0A82 },
-               { 0x0ABC, 0x0ABC }, { 0x0AC1, 0x0AC5 }, { 0x0AC7, 0x0AC8 },
-               { 0x0ACD, 0x0ACD }, { 0x0AE2, 0x0AE3 }, { 0x0B01, 0x0B01 },
-               { 0x0B3C, 0x0B3C }, { 0x0B3F, 0x0B3F }, { 0x0B41, 0x0B43 },
-               { 0x0B4D, 0x0B4D }, { 0x0B56, 0x0B56 }, { 0x0B82, 0x0B82 },
-               { 0x0BC0, 0x0BC0 }, { 0x0BCD, 0x0BCD }, { 0x0C3E, 0x0C40 },
-               { 0x0C46, 0x0C48 }, { 0x0C4A, 0x0C4D }, { 0x0C55, 0x0C56 },
-               { 0x0CBC, 0x0CBC }, { 0x0CBF, 0x0CBF }, { 0x0CC6, 0x0CC6 },
-               { 0x0CCC, 0x0CCD }, { 0x0D41, 0x0D43 }, { 0x0D4D, 0x0D4D },
-               { 0x0DCA, 0x0DCA }, { 0x0DD2, 0x0DD4 }, { 0x0DD6, 0x0DD6 },
-               { 0x0E31, 0x0E31 }, { 0x0E34, 0x0E3A }, { 0x0E47, 0x0E4E },
-               { 0x0EB1, 0x0EB1 }, { 0x0EB4, 0x0EB9 }, { 0x0EBB, 0x0EBC },
-               { 0x0EC8, 0x0ECD }, { 0x0F18, 0x0F19 }, { 0x0F35, 0x0F35 },
-               { 0x0F37, 0x0F37 }, { 0x0F39, 0x0F39 }, { 0x0F71, 0x0F7E },
-               { 0x0F80, 0x0F84 }, { 0x0F86, 0x0F87 }, { 0x0F90, 0x0F97 },
-               { 0x0F99, 0x0FBC }, { 0x0FC6, 0x0FC6 }, { 0x102D, 0x1030 },
-               { 0x1032, 0x1032 }, { 0x1036, 0x1037 }, { 0x1039, 0x1039 },
-               { 0x1058, 0x1059 }, { 0x1160, 0x11FF }, { 0x1712, 0x1714 },
-               { 0x1732, 0x1734 }, { 0x1752, 0x1753 }, { 0x1772, 0x1773 },
-               { 0x17B4, 0x17B5 }, { 0x17B7, 0x17BD }, { 0x17C6, 0x17C6 },
-               { 0x17C9, 0x17D3 }, { 0x17DD, 0x17DD }, { 0x180B, 0x180D },
-               { 0x18A9, 0x18A9 }, { 0x1920, 0x1922 }, { 0x1927, 0x1928 },
-               { 0x1932, 0x1932 }, { 0x1939, 0x193B }, { 0x200B, 0x200F },
-               { 0x202A, 0x202E }, { 0x2060, 0x2063 }, { 0x206A, 0x206F },
-               { 0x20D0, 0x20EA }, { 0x302A, 0x302F }, { 0x3099, 0x309A },
-               { 0xFB1E, 0xFB1E }, { 0xFE00, 0xFE0F }, { 0xFE20, 0xFE23 },
-               { 0xFEFF, 0xFEFF }, { 0xFFF9, 0xFFFB }, { 0x1D167, 0x1D169 },
-               { 0x1D173, 0x1D182 }, { 0x1D185, 0x1D18B },
-               { 0x1D1AA, 0x1D1AD }, { 0xE0001, 0xE0001 },
-               { 0xE0020, 0xE007F }, { 0xE0100, 0xE01EF }
-       };
+#include "unicode_width.h"
 
        /* test for 8-bit control characters */
        if (ch == 0)
@@ -134,34 +90,16 @@ static int git_wcwidth(ucs_char_t ch)
                return -1;
 
        /* binary search in table of non-spacing characters */
-       if (bisearch(ch, combining, sizeof(combining)
+       if (bisearch(ch, zero_width, sizeof(zero_width)
                                / sizeof(struct interval) - 1))
                return 0;
 
-       /*
-        * If we arrive here, ch is neither a combining nor a C0/C1
-        * control character.
-        */
+       /* binary search in table of double width characters */
+       if (bisearch(ch, double_width, sizeof(double_width)
+                               / sizeof(struct interval) - 1))
+               return 2;
 
-       return 1 +
-               (ch >= 0x1100 &&
-                    /* Hangul Jamo init. consonants */
-                (ch <= 0x115f ||
-                 ch == 0x2329 || ch == 0x232a ||
-                  /* CJK ... Yi */
-                 (ch >= 0x2e80 && ch <= 0xa4cf &&
-                  ch != 0x303f) ||
-                 /* Hangul Syllables */
-                 (ch >= 0xac00 && ch <= 0xd7a3) ||
-                 /* CJK Compatibility Ideographs */
-                 (ch >= 0xf900 && ch <= 0xfaff) ||
-                 /* CJK Compatibility Forms */
-                 (ch >= 0xfe30 && ch <= 0xfe6f) ||
-                 /* Fullwidth Forms */
-                 (ch >= 0xff00 && ch <= 0xff60) ||
-                 (ch >= 0xffe0 && ch <= 0xffe6) ||
-                 (ch >= 0x20000 && ch <= 0x2fffd) ||
-                 (ch >= 0x30000 && ch <= 0x3fffd)));
+       return 1;
 }
 
 /*
index 1dd86b8f33e04cfc6c0616578416acb1160b5718..014826464e07c93374868c61673cfe308961dfb7 100644 (file)
--- a/walker.c
+++ b/walker.c
@@ -253,7 +253,8 @@ int walker_fetch(struct walker *walker, int targets, char **target,
 {
        struct ref_lock **lock = xcalloc(targets, sizeof(struct ref_lock *));
        unsigned char *sha1 = xmalloc(targets * 20);
-       char *msg;
+       const char *msg;
+       char *to_free = NULL;
        int ret;
        int i;
 
@@ -285,21 +286,19 @@ int walker_fetch(struct walker *walker, int targets, char **target,
        if (loop(walker))
                goto unlock_and_fail;
 
-       if (write_ref_log_details) {
-               msg = xmalloc(strlen(write_ref_log_details) + 12);
-               sprintf(msg, "fetch from %s", write_ref_log_details);
-       } else {
-               msg = NULL;
-       }
+       if (write_ref_log_details)
+               msg = to_free = xstrfmt("fetch from %s", write_ref_log_details);
+       else
+               msg = "fetch (unknown)";
        for (i = 0; i < targets; i++) {
                if (!write_ref || !write_ref[i])
                        continue;
-               ret = write_ref_sha1(lock[i], &sha1[20 * i], msg ? msg : "fetch (unknown)");
+               ret = write_ref_sha1(lock[i], &sha1[20 * i], msg);
                lock[i] = NULL;
                if (ret)
                        goto unlock_and_fail;
        }
-       free(msg);
+       free(to_free);
 
        return 0;
 
@@ -307,6 +306,7 @@ unlock_and_fail:
        for (i = 0; i < targets; i++)
                if (lock[i])
                        unlock_ref(lock[i]);
+       free(to_free);
 
        return -1;
 }
index 86fec8986f3c22911a85a042704d4150ccb6a134..882cfe9fb050efe84e2330b9aea76685c6a7f891 100644 (file)
@@ -188,7 +188,7 @@ static void wt_status_print_unmerged_header(struct wt_status *s)
        } else {
                status_printf_ln(s, c, _("  (use \"git add/rm <file>...\" as appropriate to mark resolution)"));
        }
-       status_printf_ln(s, c, "");
+       status_printf_ln(s, c, "%s", "");
 }
 
 static void wt_status_print_cached_header(struct wt_status *s)
@@ -204,7 +204,7 @@ static void wt_status_print_cached_header(struct wt_status *s)
                status_printf_ln(s, c, _("  (use \"git reset %s <file>...\" to unstage)"), s->reference);
        else
                status_printf_ln(s, c, _("  (use \"git rm --cached <file>...\" to unstage)"));
-       status_printf_ln(s, c, "");
+       status_printf_ln(s, c, "%s", "");
 }
 
 static void wt_status_print_dirty_header(struct wt_status *s,
@@ -223,7 +223,7 @@ static void wt_status_print_dirty_header(struct wt_status *s,
        status_printf_ln(s, c, _("  (use \"git checkout -- <file>...\" to discard changes in working directory)"));
        if (has_dirty_submodules)
                status_printf_ln(s, c, _("  (commit or discard the untracked or modified content in submodules)"));
-       status_printf_ln(s, c, "");
+       status_printf_ln(s, c, "%s", "");
 }
 
 static void wt_status_print_other_header(struct wt_status *s,
@@ -235,12 +235,12 @@ static void wt_status_print_other_header(struct wt_status *s,
        if (!s->hints)
                return;
        status_printf_ln(s, c, _("  (use \"git %s <file>...\" to include in what will be committed)"), how);
-       status_printf_ln(s, c, "");
+       status_printf_ln(s, c, "%s", "");
 }
 
 static void wt_status_print_trailer(struct wt_status *s)
 {
-       status_printf_ln(s, color(WT_STATUS_HEADER, s), "");
+       status_printf_ln(s, color(WT_STATUS_HEADER, s), "%s", "");
 }
 
 #define quote_path quote_path_relative
@@ -734,37 +734,34 @@ static void wt_status_print_changed(struct wt_status *s)
 static void wt_status_print_submodule_summary(struct wt_status *s, int uncommitted)
 {
        struct child_process sm_summary;
-       char summary_limit[64];
-       char index[PATH_MAX];
-       const char *env[] = { NULL, NULL };
+       struct argv_array env = ARGV_ARRAY_INIT;
        struct argv_array argv = ARGV_ARRAY_INIT;
        struct strbuf cmd_stdout = STRBUF_INIT;
        struct strbuf summary = STRBUF_INIT;
        char *summary_content;
        size_t len;
 
-       sprintf(summary_limit, "%d", s->submodule_summary);
-       snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", s->index_file);
+       argv_array_pushf(&env, "GIT_INDEX_FILE=%s", s->index_file);
 
-       env[0] = index;
        argv_array_push(&argv, "submodule");
        argv_array_push(&argv, "summary");
        argv_array_push(&argv, uncommitted ? "--files" : "--cached");
        argv_array_push(&argv, "--for-status");
        argv_array_push(&argv, "--summary-limit");
-       argv_array_push(&argv, summary_limit);
+       argv_array_pushf(&argv, "%d", s->submodule_summary);
        if (!uncommitted)
                argv_array_push(&argv, s->amend ? "HEAD^" : "HEAD");
 
        memset(&sm_summary, 0, sizeof(sm_summary));
        sm_summary.argv = argv.argv;
-       sm_summary.env = env;
+       sm_summary.env = env.argv;
        sm_summary.git_cmd = 1;
        sm_summary.no_stdin = 1;
        fflush(s->fp);
        sm_summary.out = -1;
 
        run_command(&sm_summary);
+       argv_array_clear(&env);
        argv_array_clear(&argv);
 
        len = strbuf_read(&cmd_stdout, sm_summary.out, 1024);
@@ -836,7 +833,7 @@ static void wt_status_print_other(struct wt_status *s,
        string_list_clear(&output, 0);
        strbuf_release(&buf);
 conclude:
-       status_printf_ln(s, GIT_COLOR_NORMAL, "");
+       status_printf_ln(s, GIT_COLOR_NORMAL, "%s", "");
 }
 
 void wt_status_truncate_message_at_cut_line(struct strbuf *buf)
@@ -923,7 +920,7 @@ static void wt_status_print_tracking(struct wt_status *s)
                color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "%c",
                                 comment_line_char);
        else
-               fprintf_ln(s->fp, "");
+               fputs("", s->fp);
 }
 
 static int has_unmerged(struct wt_status *s)
@@ -1339,7 +1336,7 @@ void wt_status_print(struct wt_status *s)
                                on_what = _("Not currently on any branch.");
                        }
                }
-               status_printf(s, color(WT_STATUS_HEADER, s), "");
+               status_printf(s, color(WT_STATUS_HEADER, s), "%s", "");
                status_printf_more(s, branch_status_color, "%s", on_what);
                status_printf_more(s, branch_color, "%s\n", branch_name);
                if (!s->is_initial)
@@ -1352,9 +1349,9 @@ void wt_status_print(struct wt_status *s)
        free(state.detached_from);
 
        if (s->is_initial) {
-               status_printf_ln(s, color(WT_STATUS_HEADER, s), "");
+               status_printf_ln(s, color(WT_STATUS_HEADER, s), "%s", "");
                status_printf_ln(s, color(WT_STATUS_HEADER, s), _("Initial commit"));
-               status_printf_ln(s, color(WT_STATUS_HEADER, s), "");
+               status_printf_ln(s, color(WT_STATUS_HEADER, s), "%s", "");
        }
 
        wt_status_print_updated(s);
@@ -1371,7 +1368,7 @@ void wt_status_print(struct wt_status *s)
                if (s->show_ignored_files)
                        wt_status_print_other(s, &s->ignored, _("Ignored files"), "add -f");
                if (advice_status_u_option && 2000 < s->untracked_in_ms) {
-                       status_printf_ln(s, GIT_COLOR_NORMAL, "");
+                       status_printf_ln(s, GIT_COLOR_NORMAL, "%s", "");
                        status_printf_ln(s, GIT_COLOR_NORMAL,
                                         _("It took %.2f seconds to enumerate untracked files. 'status -uno'\n"
                                           "may speed it up, but you have to be careful not to forget to add\n"
index 9e13b25abc90350de4488276074dc282edc216b1..625198e0585c52c20c778790c82126efd1b57009 100644 (file)
@@ -245,11 +245,11 @@ static int xdl_fill_merge_buffer(xdfenv_t *xe1, const char *name1,
                                              dest ? dest + size : NULL);
                        /* Postimage from side #1 */
                        if (m->mode & 1)
-                               size += xdl_recs_copy(xe1, m->i1, m->chg1, 1,
+                               size += xdl_recs_copy(xe1, m->i1, m->chg1, (m->mode & 2),
                                                      dest ? dest + size : NULL);
                        /* Postimage from side #2 */
                        if (m->mode & 2)
-                               size += xdl_recs_copy(xe2, m->i2, m->chg2, 1,
+                               size += xdl_recs_copy(xe2, m->i2, m->chg2, 0,
                                                      dest ? dest + size : NULL);
                } else
                        continue;