Merge branch 'ye/http-extract-charset'
authorJunio C Hamano <gitster@pobox.com>
Wed, 2 Jul 2014 19:53:05 +0000 (12:53 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 2 Jul 2014 19:53:05 +0000 (12:53 -0700)
* ye/http-extract-charset:
http: fix charset detection of extract_content_type()

298 files changed:
.gitignore
Documentation/CodingGuidelines
Documentation/Makefile
Documentation/RelNotes/1.9.4.txt [new file with mode: 0644]
Documentation/RelNotes/2.0.1.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-send-email.txt
Documentation/git-submodule.txt
Documentation/git-svn.txt
Documentation/git-update-ref.txt
Documentation/git-web--browse.txt
Documentation/git.txt
Documentation/gitcli.txt
Documentation/gitk.txt
Documentation/gitmodules.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/user-manual.txt
GIT-VERSION-GEN
Makefile
RelNotes
advice.c
alloc.c
argv-array.c
argv-array.h
builtin/apply.c
builtin/blame.c
builtin/checkout.c
builtin/clean.c
builtin/clone.c
builtin/commit-tree.c
builtin/commit.c
builtin/config.c
builtin/fast-export.c
builtin/fetch.c
builtin/fmt-merge-msg.c
builtin/for-each-ref.c
builtin/fsck.c
builtin/gc.c
builtin/grep.c
builtin/index-pack.c
builtin/log.c
builtin/ls-remote.c
builtin/mailinfo.c
builtin/merge.c
builtin/mv.c
builtin/notes.c
builtin/pack-objects.c
builtin/patch-id.c
builtin/reflog.c
builtin/remote.c
builtin/repack.c
builtin/replace.c
builtin/rerere.c
builtin/reset.c
builtin/rev-list.c
builtin/tag.c
builtin/update-index.c
builtin/update-ref.c
cache.h
check_bindir
column.c
combine-diff.c
commit-slab.h
commit.c
commit.h
compat/bswap.h
compat/mingw.c
compat/mingw.h
compat/mmap.c
compat/poll/poll.c
compat/vcbuild/include/alloca.h [deleted file]
compat/win32/alloca.h [new file with mode: 0644]
config.c
config.mak.uname
configure.ac
connect.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]
daemon.c
diff-lib.c
diff.c
diff.h
dir.c
environment.c
fast-import.c
fetch-pack.c
fsck.c
git-bisect.sh
git-compat-util.h
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]
grep.c
http-push.c
imap-send.c
log-tree.c
merge-recursive.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-objects.c
pack-revindex.c
pager.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.c
revision.c
run-command.c
run-command.h
sequencer.c
sha1_file.c
sha1_name.c
sideband.c
strbuf.c
strbuf.h
string-list.h
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/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/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/t1410-reflog.sh
t/t1507-rev-parse-upstream.sh
t/t2107-update-index-basic.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/t3420-rebase-autostash.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/t4039-diff-assume-unchanged.sh
t/t4041-diff-submodule-option.sh
t/t4057-diff-combined-paths.sh
t/t4102-apply-rename.sh
t/t4107-apply-ignore-whitespace.sh
t/t4116-apply-reverse.sh
t/t4119-apply-config.sh
t/t4201-shortlog.sh
t/t4204-patch-id.sh
t/t4205-log-pretty-formats.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/t5537-fetch-shallow.sh
t/t5538-push-shallow.sh
t/t5542-push-http-shallow.sh [new file with mode: 0755]
t/t5551-http-fetch-smart.sh
t/t5560-http-backend-noserver.sh
t/t5801-remote-helpers.sh
t/t6006-rev-list-format.sh
t/t6039-merge-ignorecase.sh [new file with mode: 0755]
t/t6050-replace.sh
t/t7004-tag.sh
t/t7007-show.sh
t/t7102-reset.sh
t/t7300-clean.sh
t/t7500-commit.sh
t/t7501-commit.sh
t/t7502-commit.sh
t/t7508-status.sh
t/t7600-merge.sh
t/t7700-repack.sh
t/t7800-difftool.sh
t/t7810-grep.sh
t/t8003-blame-corner-cases.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
transport-helper.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]
utf8.c
wrapper.c
wt-status.c
index dc600f9b36d09f0668064e044520c7ce633f09d8..42294e59a1fcf5d744199b6a0feafd4ca6e3eda1 100644 (file)
 /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/1.9.4.txt b/Documentation/RelNotes/1.9.4.txt
new file mode 100644 (file)
index 0000000..e1d1835
--- /dev/null
@@ -0,0 +1,16 @@
+Git v1.9.4 Release Notes
+========================
+
+Fixes since v1.9.3
+------------------
+
+ * Commands that take pathspecs on the command line misbehaved when
+   the pathspec is given as an absolute pathname (which is a
+   practice not particularly encouraged) that points at a symbolic
+   link in the working tree.
+
+ * An earlier fix to the shell prompt script (in contrib/) for using
+   the PROMPT_COMMAND interface did not correctly check if the extra
+   code path needs to trigger, causing the branch name not to appear
+   when 'promptvars' option is disabled in bash or PROMPT_SUBST is
+   unset in zsh.
diff --git a/Documentation/RelNotes/2.0.1.txt b/Documentation/RelNotes/2.0.1.txt
new file mode 100644 (file)
index 0000000..ce5579d
--- /dev/null
@@ -0,0 +1,115 @@
+Git v2.0.1 Release Notes
+========================
+
+ * 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.
+
+ * 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.
+ * 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.
+
+ * "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.
+
+ * 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.
+
+ * The "mailmap.file" configuration option did not support the tilde
+   expansion (i.e. ~user/path and ~/path).
+
+ * 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".
+
+ * "--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.
+
+ * "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.
+
+ * "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.
+
+ * "git commit --allow-empty-message -C $commit" did not work when the
+   commit did not have any log message.
+
+ * "git diff --find-copies-harder" sometimes pretended as if the mode
+   bits have changed for paths that are marked with assume-unchanged
+   bit.
+
+ * "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.
+
+ * "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.
+
+ * "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).
+
+ * 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".
+
+ * The error reporting from "git index-pack" has been improved to
+   distinguish missing objects from type errors.
+
+ * "git mailinfo" used to read beyond the end of header string while
+   parsing an incoming e-mail message to extract the patch.
+
+ * 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.
+
+ * "git pack-objects" unnecessarily copied the previous contents when
+   extending the hashtable, even though it will populate the table
+   from scratch anyway.
+
+ * "git rerere forget" did not work well when merge.conflictstyle
+   was set to a non-default value.
+
+ * "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.
+
+ * "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.
+
+ * 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.
+
+ * "git show -s" (i.e. show log message only) used to incorrectly emit
+   an extra blank line after a merge commit.
+
+ * "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.
+
+ * "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.
+
+ * The mode to run tests with HTTP server tests disabled was broken.
diff --git a/Documentation/RelNotes/2.1.0.txt b/Documentation/RelNotes/2.1.0.txt
new file mode 100644 (file)
index 0000000..828a439
--- /dev/null
@@ -0,0 +1,301 @@
+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.
+
+
+Performance, Internal Implementation, etc.
+
+ * Build procedure for 'subtree' (in contrib/) has been cleaned up.
+
+ * 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).
+
+ * 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).
+
+ * 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 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).
+
+ * "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 1932e9b9a2be5437dd467f91472318a5bf1bb992..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
@@ -2293,9 +2308,11 @@ status.submodulesummary::
        --summary-limit option of linkgit:git-submodule[1]). Please note
        that the summary output command will be suppressed for all
        submodules when `diff.ignoreSubmodules` is set to 'all' or only
-       for those submodules where `submodule.<name>.ignore=all`. To
+       for those submodules where `submodule.<name>.ignore=all`. The only
+       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.
 
@@ -2317,14 +2334,16 @@ 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.
 
 submodule.<name>.ignore::
        Defines under what circumstances "git status" and the diff family show
        a submodule as modified. When set to "all", it will never be considered
-       modified, "dirty" will ignore all changes to the submodules work tree and
+       modified (but it will nonetheless show up in the output of status and
+       commit when it has been staged), "dirty" will ignore all changes
+       to the submodules work tree and
        takes only differences between the HEAD of the submodule and the commit
        recorded in the superproject into account. "untracked" will additionally
        let submodules with modified tracked files in their work tree show up.
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..61461b9f3399bd99547407ae0f3ccb4a38b77582 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,15 @@ 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.
+
 -l <pattern>::
 --list <pattern>::
        List replace refs for objects that match the given pattern (or
@@ -92,7 +102,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 +129,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 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 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
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 a041cd006a5a32937fff7938d6396fc563b145c2..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,13 +39,20 @@ 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:
 
-* link:v1.9.3/git.html[documentation for release 1.9.3]
+* link:v2.0.1/git.html[documentation for release 2.0.1]
 
 * release notes for
+  link:RelNotes/2.0.1.txt[2.0.1],
+  link:RelNotes/2.0.0.txt[2.0.0].
+
+* link:v1.9.4/git.html[documentation for release 1.9.4]
+
+* release notes for
+  link:RelNotes/1.9.4.txt[1.9.4],
   link:RelNotes/1.9.3.txt[1.9.3],
   link:RelNotes/1.9.2.txt[1.9.2],
   link:RelNotes/1.9.1.txt[1.9.1],
@@ -749,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'::
@@ -874,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 347a9f76ee809c3691dc6580b0fba3ebde0b0e3c..f6c0dfd0290a9b2174c645630998d2a62cdb9f5e 100644 (file)
@@ -67,7 +67,9 @@ submodule.<name>.fetchRecurseSubmodules::
 submodule.<name>.ignore::
        Defines under what circumstances "git status" and the diff family show
        a submodule as modified. When set to "all", it will never be considered
-       modified, "dirty" will ignore all changes to the submodules work tree and
+       modified (but will nonetheless show up in the output of status and
+       commit when it has been staged), "dirty" will ignore all changes
+       to the submodules work tree and
        takes only differences between the HEAD of the submodule and the commit
        recorded in the superproject into account. "untracked" will additionally
        let submodules with modified tracked files in their work tree show up.
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 9d28b034ad9a35108f8069557e194992f8e36b0f..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,15 +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
@@ -189,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 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 aa039b4ab24457814d09e30b1d55c981036034ea..40adbf7bf79ad7d7800b71d2ca79418cdbddd3ed 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 
 GVF=GIT-VERSION-FILE
-DEF_VER=v2.0.0-rc4
+DEF_VER=v2.0.0.GIT
 
 LF='
 '
index a53f3a8326c2e62dc79bae7169d64137ac3dab20..07ea1058379ab963648d0df7fd2917e0d2efa8a7 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).
@@ -183,9 +185,6 @@ all::
 # Define NO_STRUCT_ITIMERVAL if you don't have struct itimerval
 # This also implies NO_SETITIMER
 #
-# Define NO_THREAD_SAFE_PREAD if your pread() implementation is not
-# thread-safe. (e.g. compat/pread.c or cygwin)
-#
 # Define NO_FAST_WORKING_DIRECTORY if accessing objects in pack files is
 # generally faster on your platform than accessing the working directory.
 #
@@ -730,6 +729,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
@@ -1111,6 +1111,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 =
@@ -1339,10 +1343,6 @@ endif
 ifdef NO_PREAD
        COMPAT_CFLAGS += -DNO_PREAD
        COMPAT_OBJS += compat/pread.o
-       NO_THREAD_SAFE_PREAD = YesPlease
-endif
-ifdef NO_THREAD_SAFE_PREAD
-       BASIC_CFLAGS += -DNO_THREAD_SAFE_PREAD
 endif
 ifdef NO_FAST_WORKING_DIRECTORY
        BASIC_CFLAGS += -DNO_FAST_WORKING_DIRECTORY
index e50885caa1043665dfe2d995e0a2f7a7a7bb51ca..bf760914010786c830233effc8b96ddacfb114fd 120000 (symlink)
--- a/RelNotes
+++ b/RelNotes
@@ -1 +1 @@
-Documentation/RelNotes/2.0.0.txt
\ No newline at end of file
+Documentation/RelNotes/2.1.0.txt
\ No newline at end of file
index 486f823c78118212080a48e74debd7adae241cda..c50ebdf5fe82d88b901ca26668806c94e03fbb37 100644 (file)
--- a/advice.c
+++ b/advice.c
@@ -76,16 +76,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/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 87439fad118a2671989120dd5993a17b4541e2db..9c5724eaccfaee62ff10eb097adc39ace351cade 100644 (file)
@@ -300,11 +300,13 @@ static int fuzzy_matchlines(const char *s1, size_t n1,
        while ((*last2 == '\r') || (*last2 == '\n'))
                last2--;
 
-       /* skip leading whitespace */
-       while (isspace(*s1) && (s1 <= last1))
-               s1++;
-       while (isspace(*s2) && (s2 <= last2))
-               s2++;
+       /* skip leading whitespaces, if both begin with whitespace */
+       if (s1 <= last1 && s2 <= last2 && isspace(*s1) && isspace(*s2)) {
+               while (isspace(*s1) && (s1 <= last1))
+                       s1++;
+               while (isspace(*s2) && (s2 <= last2))
+                       s2++;
+       }
        /* early return if both lines are empty */
        if ((s1 > last1) && (s2 > last2))
                return 1;
index 88cb7997274de6f9ab6f8a5944748334ce605f60..d3b256e545a76b096682223539c4faec8d770b2f 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 */
@@ -1556,22 +1818,29 @@ static void assign_blame(struct scoreboard *sb, int opt)
 static const char *format_time(unsigned long time, const char *tz_str,
                               int show_raw_time)
 {
-       static char time_buf[128];
+       static struct strbuf time_buf = STRBUF_INIT;
 
+       strbuf_reset(&time_buf);
        if (show_raw_time) {
-               snprintf(time_buf, sizeof(time_buf), "%lu %s", time, tz_str);
+               strbuf_addf(&time_buf, "%lu %s", time, tz_str);
        }
        else {
                const char *time_str;
-               int time_len;
+               size_t time_width;
                int tz;
                tz = atoi(tz_str);
                time_str = show_date(time, tz, blame_date_mode);
-               time_len = strlen(time_str);
-               memcpy(time_buf, time_str, time_len);
-               memset(time_buf + time_len, ' ', blame_date_width - time_len);
+               strbuf_addstr(&time_buf, time_str);
+               /*
+                * Add space paddings to time_buf to display a fixed width
+                * string, and use time_width for display width calibration.
+                */
+               for (time_width = utf8_strwidth(time_str);
+                    time_width < blame_date_width;
+                    time_width++)
+                       strbuf_addch(&time_buf, ' ');
        }
-       return time_buf;
+       return time_buf.buf;
 }
 
 #define OUTPUT_ANNOTATE_COMPAT 001
@@ -1602,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);
@@ -1717,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;
+                               }
                        }
                }
        }
@@ -1741,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.
@@ -1752,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;
-
-       *lineno++ = 0;
-       for (p = buf;;) {
-               p = memchr(p, '\n', end - p);
-               if (p) {
-                       p++;
-                       *lineno++ = p - buf;
-                       continue;
-               }
-               break;
-       }
+       for (p = buf; p < end; p = get_next_line(p, end))
+               *lineno++ = p - buf;
 
-       if (incomplete)
-               *lineno++ = len;
+       *lineno = len;
 
-       sb->num_lines = num + incomplete;
+       sb->num_lines = num;
        return sb->num_lines;
 }
 
@@ -1998,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.
@@ -2019,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;
@@ -2046,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;
@@ -2088,11 +2353,9 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
                if (strbuf_read(&buf, 0, 0) < 0)
                        die_errno("failed to read from stdin");
        }
-       convert_to_git(path, buf.buf, buf.len, &buf, 0);
        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
@@ -2331,7 +2594,14 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
                blame_date_width = sizeof("2006-10-19");
                break;
        case DATE_RELATIVE:
-               /* "normal" is used as the fallback for "relative" */
+               /* TRANSLATORS: This string is used to tell us the maximum
+                  display width for a relative timestamp in "git blame"
+                  output.  For C locale, "4 years, 11 months ago", which
+                  takes 22 places, is the longest among various forms of
+                  relative timestamps, but your language may need more or
+                  fewer display columns. */
+               blame_date_width = utf8_strwidth(_("4 years, 11 months ago")) + 1; /* add the null */
+               break;
        case DATE_LOCAL:
        case DATE_NORMAL:
                blame_date_width = sizeof("Thu Oct 19 16:00:04 2006 -0700");
@@ -2403,12 +2673,16 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
        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) {
                /*
@@ -2497,12 +2771,16 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
                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);
@@ -2515,6 +2793,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
        if (incremental)
                return 0;
 
+       sb.ent = blame_sort(sb.ent, compare_blame_final);
+
        coalesce(&sb);
 
        if (!(output_option & OUTPUT_PORCELAIN))
index 07cf55530918e8de6ae45e1c9b7e16707c32f844..f1dc56e55f7b2200412142b10517458ccfda2952 100644 (file)
@@ -624,7 +624,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 +651,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();
index 9a9151575d3a8d4eb16d73e432835d3cda4374b8..27701d222c78ed84691b65334a7909f90c589464 100644 (file)
@@ -48,7 +48,7 @@ enum color_clean {
        CLEAN_COLOR_PROMPT = 2,
        CLEAN_COLOR_HEADER = 3,
        CLEAN_COLOR_HELP = 4,
-       CLEAN_COLOR_ERROR = 5,
+       CLEAN_COLOR_ERROR = 5
 };
 
 #define MENU_OPTS_SINGLETON            01
index 9b3c04d914b3d318f723c2d3ded403fca9503c07..b12989d1caecb48128e8a468014f07b237b1a4cc 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);
        }
 }
 
@@ -589,14 +589,15 @@ static void update_head(const struct ref *our, const struct ref *remote,
                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);
        }
 }
 
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 9cfef6c6cca61973a4982763e4b834bf1b45cb75..84cec9a715341fedeabfaedfd82bbb64a4c3c255 100644 (file)
@@ -526,10 +526,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 +593,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 +608,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)
+{
+       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)
 {
-       char *ket = strrchr(string, '>');
-       if (!ket || ket[1] != ' ')
-               die(_("Malformed ident string: '%s'"), string);
-       *++ket = '\0';
-       return ket;
+       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,
@@ -650,9 +706,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
        } else if (use_message) {
                char *buffer;
                buffer = strstr(use_message_buffer, "\n\n");
-               if (!use_editor && (!buffer || buffer[2] == '\0'))
-                       die(_("commit has empty message"));
-               strbuf_add(&sb, buffer + 2, strlen(buffer + 2));
+               if (buffer)
+                       strbuf_add(&sb, buffer + 2, strlen(buffer + 2));
                hook_arg1 = "commit";
                hook_arg2 = use_message;
        } else if (fixup_message) {
@@ -748,6 +803,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 */
@@ -755,7 +812,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);
@@ -795,32 +853,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 <%.*s>"),
+                               ident_shown++ ? "" : "\n",
+                               (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"
-                               "Author:    %s"),
+                               "Date:      %s"),
                                ident_shown++ ? "" : "\n",
-                               author_ident->buf);
+                               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";
@@ -833,8 +898,22 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 
                if (get_sha1(parent, sha1))
                        commitable = !!active_nr;
-               else
-                       commitable = index_differs_from(parent, 0);
+               else {
+                       /*
+                        * Unless the user did explicitly request a submodule
+                        * ignore mode by passing a command line option we do
+                        * not ignore any changed submodule SHA-1s when
+                        * comparing index and parent, no matter what is
+                        * configured. Otherwise we won't commit any
+                        * submodules which were manually staged, which would
+                        * be really confusing.
+                        */
+                       int diff_flags = DIFF_OPT_OVERRIDE_SUBMODULE_CONFIG;
+                       if (ignore_submodule_arg &&
+                           !strcmp(ignore_submodule_arg, "all"))
+                               diff_flags |= DIFF_OPT_IGNORE_SUBMODULES;
+                       commitable = index_differs_from(parent, diff_flags);
+               }
        }
        strbuf_release(&committer_ident);
 
@@ -1356,6 +1435,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);
@@ -1659,8 +1745,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"));
        }
@@ -1672,6 +1758,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)
@@ -1681,10 +1771,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 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..dd46b61d9a31475e3d5289e41e6d7f57a0264b6f 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;
index 3906eda87712ea099e0e5876fff1fe28fc5716be..ef8b254ef218249f7f1b0f28db7ea21110851917 100644 (file)
@@ -230,12 +230,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 +249,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) {
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 85f5c2bc62ec1ead593f5aa2e3d7077e65f2f061..8d219d8c42cb4dfb64468f9b4d82648bff646685 100644 (file)
@@ -26,6 +26,7 @@ static const char * const builtin_gc_usage[] = {
 };
 
 static int pack_refs = 1;
+static int prune_reflogs = 1;
 static int aggressive_depth = 250;
 static int aggressive_window = 250;
 static int gc_auto_threshold = 6700;
@@ -258,6 +259,19 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
        return NULL;
 }
 
+static int gc_before_repack(void)
+{
+       if (pack_refs && run_command_v_opt(pack_refs_cmd.argv, RUN_GIT_CMD))
+               return error(FAILED_RUN, pack_refs_cmd.argv[0]);
+
+       if (prune_reflogs && run_command_v_opt(reflog.argv, RUN_GIT_CMD))
+               return error(FAILED_RUN, reflog.argv[0]);
+
+       pack_refs = 0;
+       prune_reflogs = 0;
+       return 0;
+}
+
 int cmd_gc(int argc, const char **argv, const char *prefix)
 {
        int aggressive = 0;
@@ -320,12 +334,15 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
                                fprintf(stderr, _("Auto packing the repository for optimum performance.\n"));
                        fprintf(stderr, _("See \"git help gc\" for manual housekeeping.\n"));
                }
-               if (detach_auto)
+               if (detach_auto) {
+                       if (gc_before_repack())
+                               return -1;
                        /*
                         * failure to daemonize is ok, we'll continue
                         * in foreground
                         */
                        daemonize();
+               }
        } else
                add_repack_all_option();
 
@@ -337,11 +354,8 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
                    name, (uintmax_t)pid);
        }
 
-       if (pack_refs && run_command_v_opt(pack_refs_cmd.argv, RUN_GIT_CMD))
-               return error(FAILED_RUN, pack_refs_cmd.argv[0]);
-
-       if (run_command_v_opt(reflog.argv, RUN_GIT_CMD))
-               return error(FAILED_RUN, reflog.argv[0]);
+       if (gc_before_repack())
+               return -1;
 
        if (run_command_v_opt(repack.argv, RUN_GIT_CMD))
                return error(FAILED_RUN, repack.argv[0]);
index 69ac2d8797ec32dc206425db0a2f3d7356810cfe..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);
@@ -874,6 +872,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
                if (len > 4 && is_dir_sep(pager[len - 5]))
                        pager += len - 4;
 
+               if (opt.ignore_case && !strcmp("less", pager))
+                       string_list_append(&path_list, "-I");
+
                if (!strcmp("less", pager) || !strcmp("vi", pager)) {
                        struct strbuf buf = STRBUF_INIT;
                        strbuf_addf(&buf, "+/%s%s",
index b9f6e12c0e91635eafd8510dc7cf20d6c3e58433..8b3bd29dbcf22668040c53fffb6e2414ca090f5d 100644 (file)
@@ -40,17 +40,13 @@ struct base_data {
        int ofs_first, ofs_last;
 };
 
-#if !defined(NO_PTHREADS) && defined(NO_THREAD_SAFE_PREAD)
-/* pread() emulation is not thread-safe. Disable threading. */
-#define NO_PTHREADS
-#endif
-
 struct thread_local {
 #ifndef NO_PTHREADS
        pthread_t thread;
 #endif
        struct base_data *base_cache;
        size_t base_cache_used;
+       int pack_fd;
 };
 
 /*
@@ -91,7 +87,8 @@ static off_t consumed_bytes;
 static unsigned deepest_delta;
 static git_SHA_CTX input_ctx;
 static uint32_t input_crc32;
-static int input_fd, output_fd, pack_fd;
+static int input_fd, output_fd;
+static const char *curr_pack;
 
 #ifndef NO_PTHREADS
 
@@ -134,6 +131,7 @@ static inline void unlock_mutex(pthread_mutex_t *mutex)
  */
 static void init_thread(void)
 {
+       int i;
        init_recursive_mutex(&read_mutex);
        pthread_mutex_init(&counter_mutex, NULL);
        pthread_mutex_init(&work_mutex, NULL);
@@ -141,11 +139,18 @@ static void init_thread(void)
                pthread_mutex_init(&deepest_delta_mutex, NULL);
        pthread_key_create(&key, NULL);
        thread_data = xcalloc(nr_threads, sizeof(*thread_data));
+       for (i = 0; i < nr_threads; i++) {
+               thread_data[i].pack_fd = open(curr_pack, O_RDONLY);
+               if (thread_data[i].pack_fd == -1)
+                       die_errno(_("unable to open %s"), curr_pack);
+       }
+
        threads_active = 1;
 }
 
 static void cleanup_thread(void)
 {
+       int i;
        if (!threads_active)
                return;
        threads_active = 0;
@@ -154,6 +159,8 @@ static void cleanup_thread(void)
        pthread_mutex_destroy(&work_mutex);
        if (show_stat)
                pthread_mutex_destroy(&deepest_delta_mutex);
+       for (i = 0; i < nr_threads; i++)
+               close(thread_data[i].pack_fd);
        pthread_key_delete(key);
        free(thread_data);
 }
@@ -200,8 +207,13 @@ static unsigned check_object(struct object *obj)
        if (!(obj->flags & FLAG_CHECKED)) {
                unsigned long size;
                int type = sha1_object_info(obj->sha1, &size);
-               if (type != obj->type || type <= 0)
-                       die(_("object of unexpected type"));
+               if (type <= 0)
+                       die(_("did not receive expected object %s"),
+                             sha1_to_hex(obj->sha1));
+               if (type != obj->type)
+                       die(_("object %s: expected type %s, found %s"),
+                           sha1_to_hex(obj->sha1),
+                           typename(obj->type), typename(type));
                obj->flags |= FLAG_CHECKED;
                return 1;
        }
@@ -288,13 +300,13 @@ static const char *open_pack_file(const char *pack_name)
                        output_fd = open(pack_name, O_CREAT|O_EXCL|O_RDWR, 0600);
                if (output_fd < 0)
                        die_errno(_("unable to create '%s'"), pack_name);
-               pack_fd = output_fd;
+               nothread_data.pack_fd = output_fd;
        } else {
                input_fd = open(pack_name, O_RDONLY);
                if (input_fd < 0)
                        die_errno(_("cannot open packfile '%s'"), pack_name);
                output_fd = -1;
-               pack_fd = input_fd;
+               nothread_data.pack_fd = input_fd;
        }
        git_SHA1_Init(&input_ctx);
        return pack_name;
@@ -542,7 +554,7 @@ static void *unpack_data(struct object_entry *obj,
 
        do {
                ssize_t n = (len < 64*1024) ? len : 64*1024;
-               n = pread(pack_fd, inbuf, n, from);
+               n = xpread(get_thread_data()->pack_fd, inbuf, n, from);
                if (n < 0)
                        die_errno(_("cannot pread pack file"));
                if (!n)
@@ -774,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;
                }
@@ -1490,7 +1503,7 @@ static void show_pack_info(int stat_only)
 int cmd_index_pack(int argc, const char **argv, const char *prefix)
 {
        int i, fix_thin_pack = 0, verify = 0, stat_only = 0;
-       const char *curr_pack, *curr_index;
+       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;
index 39e883635279ad21f3ddd7b224f484b9b04700b0..92063dfc48a73c9b5fa4f9694dd4ac78d5575be3 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;
 }
 
@@ -158,13 +160,9 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
        if (rev->show_notes)
                init_display_notes(&rev->notes_opt);
 
-       if (rev->diffopt.pickaxe || rev->diffopt.filter)
+       if (rev->diffopt.pickaxe || rev->diffopt.filter ||
+           DIFF_OPT_TST(&rev->diffopt, FOLLOW_RENAMES))
                rev->always_show_header = 0;
-       if (DIFF_OPT_TST(&rev->diffopt, FOLLOW_RENAMES)) {
-               rev->always_show_header = 0;
-               if (rev->diffopt.pathspec.nr != 1)
-                       usage("git logs can only follow renames on one pathname at a time");
-       }
 
        if (source)
                rev->show_source = 1;
@@ -349,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;
@@ -673,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 {
@@ -742,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;
@@ -844,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)
@@ -919,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);
@@ -1230,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()
        };
@@ -1447,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) {
@@ -1508,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 2c3cd8eab7073669001ad605020577279ba7a07d..cf11c8d6071dd791508d3bd5f46d30550765a90f 100644 (file)
@@ -334,7 +334,7 @@ static int check_header(const struct strbuf *line,
        }
        if (starts_with(line->buf, "[PATCH]") && isspace(line->buf[7])) {
                for (i = 0; header[i]; i++) {
-                       if (!memcmp("Subject", header[i], 7)) {
+                       if (!strcmp("Subject", header[i])) {
                                handle_header(&hdr_data[i], line);
                                ret = 1;
                                goto check_header_out;
@@ -929,13 +929,13 @@ static void handle_info(void)
                else
                        continue;
 
-               if (!memcmp(header[i], "Subject", 7)) {
+               if (!strcmp(header[i], "Subject")) {
                        if (!keep_subject) {
                                cleanup_subject(hdr);
                                cleanup_space(hdr);
                        }
                        output_header_lines(fout, "Subject", hdr);
-               } else if (!memcmp(header[i], "From", 4)) {
+               } else if (!strcmp(header[i], "From")) {
                        cleanup_space(hdr);
                        handle_from(hdr);
                        fprintf(fout, "Author: %s\n", name.buf);
index 66d8843301b22a6a89d9d765e9d3020942e6f672..b49c310866f76434c3838484c0bf997a1230c7ed 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.
@@ -852,8 +852,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 +877,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 +1222,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;
@@ -1339,7 +1339,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 2a7243f52e413c821f9f75969edcc0a9822c8e21..180ef99127d47d0e8fe9f12a590fd9ba9e524f08 100644 (file)
@@ -203,7 +203,8 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
                        }
                } else if (cache_name_pos(src, length) < 0)
                        bad = _("not under version control");
-               else if (lstat(dst, &st) == 0) {
+               else if (lstat(dst, &st) == 0 &&
+                        (!ignore_case || strcasecmp(src, dst))) {
                        bad = _("destination exists");
                        if (force) {
                                /*
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 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 b3ab4cf8f6517c715845db7e17c67cad5f50d730..c9102e8fe94b41af5136a9cc23db939effae147a 100644 (file)
@@ -282,7 +282,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 +398,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 +433,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 +446,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);
@@ -749,15 +749,23 @@ static int mv(int argc, const char **argv)
 
 static int remove_branches(struct string_list *branches)
 {
+       const char **branch_names;
        int i, result = 0;
+
+       branch_names = xmalloc(branches->nr * sizeof(*branch_names));
+       for (i = 0; i < branches->nr; i++)
+               branch_names[i] = branches->items[i].string;
+       result |= repack_without_refs(branch_names, branches->nr);
+       free(branch_names);
+
        for (i = 0; i < branches->nr; i++) {
                struct string_list_item *item = branches->items + i;
                const char *refname = item->string;
-               unsigned char *sha1 = item->util;
 
-               if (delete_ref(refname, sha1, 0))
+               if (delete_ref(refname, NULL, 0))
                        result |= error(_("Could not remove branch %s"), refname);
        }
+
        return result;
 }
 
@@ -789,10 +797,6 @@ static int rm(int argc, const char **argv)
        known_remotes.to_delete = remote;
        for_each_remote(add_known_remote, &known_remotes);
 
-       strbuf_addf(&buf, "remote.%s", remote->name);
-       if (git_config_rename_section(buf.buf, NULL) < 1)
-               return error(_("Could not remove config section '%s'"), buf.buf);
-
        read_branches();
        for (i = 0; i < branch_list.nr; i++) {
                struct string_list_item *item = branch_list.items + i;
@@ -837,6 +841,12 @@ static int rm(int argc, const char **argv)
        }
        string_list_clear(&skipped, 0);
 
+       if (!result) {
+               strbuf_addf(&buf, "remote.%s", remote->name);
+               if (git_config_rename_section(buf.buf, NULL) < 1)
+                       return error(_("Could not remove config section '%s'"), buf.buf);
+       }
+
        return result;
 }
 
@@ -1303,6 +1313,8 @@ static int prune_remote(const char *remote, int dry_run)
 {
        int result = 0, i;
        struct ref_states states;
+       struct string_list delete_refs_list = STRING_LIST_INIT_NODUP;
+       const char **delete_refs;
        const char *dangling_msg = dry_run
                ? _(" %s will become dangling!")
                : _(" %s has become dangling!");
@@ -1316,11 +1328,20 @@ static int prune_remote(const char *remote, int dry_run)
                       states.remote->url_nr
                       ? states.remote->url[0]
                       : _("(no URL)"));
+
+               delete_refs = xmalloc(states.stale.nr * sizeof(*delete_refs));
+               for (i = 0; i < states.stale.nr; i++)
+                       delete_refs[i] = states.stale.items[i].util;
+               if (!dry_run)
+                       result |= repack_without_refs(delete_refs, states.stale.nr);
+               free(delete_refs);
        }
 
        for (i = 0; i < states.stale.nr; i++) {
                const char *refname = states.stale.items[i].util;
 
+               string_list_insert(&delete_refs_list, refname);
+
                if (!dry_run)
                        result |= delete_ref(refname, NULL, 0);
 
@@ -1330,9 +1351,11 @@ static int prune_remote(const char *remote, int dry_run)
                else
                        printf_ln(_(" * [pruned] %s"),
                               abbrev_ref(refname, "refs/remotes/"));
-               warn_dangling_symref(stdout, dangling_msg, refname);
        }
 
+       warn_dangling_symrefs(stdout, dangling_msg, &delete_refs_list);
+       string_list_clear(&delete_refs_list, 0);
+
        free_remote_ref_states(&states);
        return result;
 }
index 6b0b62dcb2687e78ec433e7de1103f0c0f74a1fc..ff2216a7aaefa3b38385301e4e0d8bb8b94e4ea0 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);
 }
 
@@ -149,7 +155,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 +173,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 +196,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 +222,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..1bb491d3c4f282e7f68d25cae0e00f419df1dd93 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
@@ -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,13 +175,140 @@ 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",
+ * pretty-printed for human editing based on its type.
+ */
+static void export_object(const unsigned char *sha1, const char *filename)
+{
+       const char *argv[] = { "--no-replace-objects", "cat-file", "-p", NULL, NULL };
+       struct child_process cmd = { argv };
+       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[3] = sha1_to_hex(sha1);
+       cmd.git_cmd = 1;
+       cmd.out = fd;
+
+       if (run_command(&cmd))
+               die("cat-file reported failure");
+
+       close(fd);
+}
+
+/*
+ * 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,
+                         const char *filename)
+{
+       int fd;
+
+       fd = open(filename, O_RDONLY);
+       if (fd < 0)
+               die_errno("unable to open %s for reading", filename);
+
+       if (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)
+{
+       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, tmpfile);
+       if (launch_editor(tmpfile, NULL, NULL) < 0)
+               die("editing object file failed");
+       import_object(new, type, 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;
        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_STRING(0, "format", &format, N_("format"), N_("use this format")),
                OPT_END()
@@ -182,44 +318,43 @@ 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",
-                             git_replace_usage, options);
+       if (!cmdmode)
+               cmdmode = argc ? MODE_REPLACE : MODE_LIST;
 
-       if (format && delete)
-               usage_msg_opt("--format and -d cannot be used together",
+       if (format && cmdmode != MODE_LIST)
+               usage_msg_opt("--format cannot be used when not listing",
                              git_replace_usage, options);
 
-       if (force && (list || delete))
-               usage_msg_opt("-f cannot be used with -d or -l",
+       if (force && cmdmode != MODE_REPLACE && cmdmode != MODE_EDIT)
+               usage_msg_opt("-f only makes sense when writing a replacement",
                              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);
+
+       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 4e51addb3e135465bdb728bb00c5dc3dd53b7c51..98eb8c5404914e4046fdb886866b611351deeacf 100644 (file)
@@ -60,6 +60,8 @@ int cmd_rerere(int argc, const char **argv, const char *prefix)
 
        argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
 
+       git_config(git_xmerge_config, NULL);
+
        if (autoupdate == 1)
                flags = RERERE_AUTOUPDATE;
        if (autoupdate == 0)
index f4e087596b6337d2306af4cf45119752b4a049ea..850d53229a1ac757d294ffca6261c9a28af014df 100644 (file)
@@ -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;
 }
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 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 ba54e19cd559018fcca52b5251bffa78165e16a3..ebea285e1b6863bdb8e4b2a30d1487d18ecc5084 100644 (file)
@@ -637,6 +637,9 @@ static int parse_new_style_cacheinfo(const char *arg,
        unsigned long ul;
        char *endp;
 
+       if (!arg)
+               return -1;
+
        errno = 0;
        ul = strtoul(arg, &endp, 8);
        if (errno || endp == arg || *endp != ',' || (unsigned int) ul != ul)
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/cache.h b/cache.h
index 107ac61b68f15b1e15532c09fda9e9799f830e44..df65231ac3db7ae08b5d9cfd37c505c4573c1675 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
@@ -279,6 +294,7 @@ struct index_state {
                 initialized : 1;
        struct hashmap name_hash;
        struct hashmap dir_hash;
+       unsigned char sha1[20];
 };
 
 extern struct index_state the_index;
@@ -602,6 +618,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,
@@ -809,7 +826,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
@@ -983,7 +999,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,
@@ -1045,6 +1061,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.
@@ -1271,8 +1294,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);
@@ -1322,6 +1345,8 @@ extern void fsync_or_die(int fd, const char *);
 
 extern ssize_t read_in_full(int fd, void *buf, size_t count);
 extern ssize_t write_in_full(int fd, const void *buf, size_t count);
+extern ssize_t pread_in_full(int fd, void *buf, size_t count, off_t offset);
+
 static inline ssize_t write_str_in_full(int fd, const char *str)
 {
        return write_in_full(fd, str, strlen(str));
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..1a468debb4abdda3cbb90fcc4972b3d40da6f2ed 100644 (file)
--- a/column.c
+++ b/column.c
@@ -370,46 +370,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 24ca7e2334b68e06afd24051ad1aafcc129bcba4..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,49 +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)
-                               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 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..4ff8077dbfbc6cdd6c14728a3d33a78d075c236f 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,22 +607,12 @@ 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) {
@@ -575,7 +633,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 +1089,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 +1138,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 +1153,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 +1174,7 @@ int parse_signed_commit(const unsigned char *sha1,
                }
                line = next;
        }
- cleanup:
-       free(buffer);
+       unuse_commit_buffer(commit, buffer);
        return saw_signature;
 }
 
@@ -1211,8 +1265,7 @@ 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,
@@ -1257,11 +1310,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 +1395,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 +1404,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 +1525,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 +1537,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 +1576,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..a0e13bc862c052d8c18a6cba1c47a5a15fd12f7b 100644 (file)
@@ -1823,3 +1823,27 @@ 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]);
+}
index e033e720c900c430a0a74b0223522c396cb66629..3eaf822e28e23e6e46e82a9bb7c9db1ed42d252c 100644 (file)
@@ -339,6 +339,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"
index c9d46d174259f42a3e2a2eb073475aba517044be..7f662fef7bcb408045eb1536afed058a607ae97b 100644 (file)
@@ -14,7 +14,7 @@ void *git_mmap(void *start, size_t length, int prot, int flags, int fd, off_t of
        }
 
        while (n < length) {
-               ssize_t count = pread(fd, (char *)start + n, length - n, offset + n);
+               ssize_t count = xpread(fd, (char *)start + n, length - n, offset + n);
 
                if (count == 0) {
                        memset((char *)start+n, 0, length-n);
@@ -22,8 +22,6 @@ void *git_mmap(void *start, size_t length, int prot, int flags, int fd, off_t of
                }
 
                if (count < 0) {
-                       if (errno == EAGAIN || errno == EINTR)
-                               continue;
                        free(start);
                        errno = EACCES;
                        return MAP_FAILED;
index 31163f2ae7b71857889f561dea0b3ffecff61989..a9b41d89f465208b6f0e417672077403bf30898f 100644 (file)
@@ -605,7 +605,7 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout)
 
   if (!rc && timeout == INFTIM)
     {
-      SwitchToThread();
+      SleepEx (1, TRUE);
       goto restart;
     }
 
diff --git a/compat/vcbuild/include/alloca.h b/compat/vcbuild/include/alloca.h
deleted file mode 100644 (file)
index c0d7985..0000000
+++ /dev/null
@@ -1 +0,0 @@
-#include <malloc.h>
diff --git a/compat/win32/alloca.h b/compat/win32/alloca.h
new file mode 100644 (file)
index 0000000..c0d7985
--- /dev/null
@@ -0,0 +1 @@
+#include <malloc.h>
index a30cb5c07db18a5ac16c1c98b6600c9fe6dc1b73..a1aef1cf3eca01e328b3e319636269236ea91ae0 100644 (file)
--- a/config.c
+++ b/config.c
@@ -147,12 +147,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 +174,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 +820,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"))
@@ -952,7 +953,7 @@ static int git_default_push_config(const char *var, const char *value)
 static int git_default_mailmap_config(const char *var, const char *value)
 {
        if (!strcmp(var, "mailmap.file"))
-               return git_config_string(&git_mailmap_file, var, value);
+               return git_config_pathname(&git_mailmap_file, var, value);
        if (!strcmp(var, "mailmap.blob"))
                return git_config_string(&git_mailmap_blob, var, value);
 
@@ -1538,7 +1539,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 +1637,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 +1792,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 +1802,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 +1814,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 23a880365616c34ea84d8a3194b98163864a2cd1..1ae675b05344912d8798b9856b60b03c282cf908 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)
@@ -157,7 +160,6 @@ ifeq ($(uname_O),Cygwin)
                NO_SYMLINK_HEAD = YesPlease
                NO_IPV6 = YesPlease
                OLD_ICONV = UnfortunatelyYes
-               NO_THREAD_SAFE_PREAD = YesPlease
                # There are conflicting reports about this.
                # On some boxes NO_MMAP is needed, and not so elsewhere.
                # Try commenting this out if you suspect MMAP is more efficient
@@ -165,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
@@ -239,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
@@ -313,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
@@ -357,17 +362,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
@@ -465,6 +470,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
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..94a66502464400d5dfc47a4151cc2fd01780a0a4 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -534,22 +534,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 +659,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 +702,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 +712,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 +752,6 @@ int finish_connect(struct child_process *conn)
                return 0;
 
        code = finish_command(conn);
-       free(conn->argv);
        free(conn);
        return code;
 }
index 2c59a76bc2cf2d0fefb633efe805b6c7c15ad7ec..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
@@ -1472,9 +1482,12 @@ _git_log ()
        __git_complete_revlist
 }
 
+# Common merge options shared by git-merge(1) and git-pull(1).
 __git_merge_options="
        --no-commit --no-stat --log --no-log --squash --strategy
        --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
+       --verify-signatures --no-verify-signatures --gpg-sign
+       --quiet --verbose --progress --no-progress
 "
 
 _git_merge ()
@@ -1483,7 +1496,8 @@ _git_merge ()
 
        case "$cur" in
        --*)
-               __gitcomp "$__git_merge_options"
+               __gitcomp "$__git_merge_options
+                       --rerere-autoupdate --no-rerere-autoupdate --abort"
                return
        esac
        __gitcomp_nl "$(__git_refs)"
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 @@
 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 eba12556848e975cd6f1a55ae25760823e90cdc8..f9c63e96137aff6b5ae2376af3fca789ff03e975 100644 (file)
--- a/daemon.c
+++ b/daemon.c
@@ -475,14 +475,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)
 {
index 044872935c30d84affb1955a7ae03c0986c90bda..875aff864391ed037627462ac39c314f248b5ae6 100644 (file)
@@ -97,7 +97,6 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
                diff_unmerged_stage = 2;
        entries = active_nr;
        for (i = 0; i < entries; i++) {
-               struct stat st;
                unsigned int oldmode, newmode;
                struct cache_entry *ce = active_cache[i];
                int changed;
@@ -115,6 +114,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
                        unsigned int wt_mode = 0;
                        int num_compare_stages = 0;
                        size_t path_len;
+                       struct stat st;
 
                        path_len = ce_namelen(ce);
 
@@ -195,26 +195,35 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
                        continue;
 
                /* If CE_VALID is set, don't look at workdir for file removal */
-               changed = (ce->ce_flags & CE_VALID) ? 0 : check_removed(ce, &st);
-               if (changed) {
-                       if (changed < 0) {
-                               perror(ce->name);
+               if (ce->ce_flags & CE_VALID) {
+                       changed = 0;
+                       newmode = ce->ce_mode;
+               } else {
+                       struct stat st;
+
+                       changed = check_removed(ce, &st);
+                       if (changed) {
+                               if (changed < 0) {
+                                       perror(ce->name);
+                                       continue;
+                               }
+                               diff_addremove(&revs->diffopt, '-', ce->ce_mode,
+                                              ce->sha1, !is_null_sha1(ce->sha1),
+                                              ce->name, 0);
                                continue;
                        }
-                       diff_addremove(&revs->diffopt, '-', ce->ce_mode,
-                                      ce->sha1, !is_null_sha1(ce->sha1),
-                                      ce->name, 0);
-                       continue;
+
+                       changed = match_stat_with_submodule(&revs->diffopt, ce, &st,
+                                                           ce_option, &dirty_submodule);
+                       newmode = ce_mode_from_stat(ce, st.st_mode);
                }
-               changed = match_stat_with_submodule(&revs->diffopt, ce, &st,
-                                                   ce_option, &dirty_submodule);
+
                if (!changed && !dirty_submodule) {
                        ce_mark_uptodate(ce);
                        if (!DIFF_OPT_TST(&revs->diffopt, FIND_COPIES_HARDER))
                                continue;
                }
                oldmode = ce->ce_mode;
-               newmode = ce_mode_from_stat(ce, st.st_mode);
                diff_change(&revs->diffopt, oldmode, newmode,
                            ce->sha1, (changed ? null_sha1 : ce->sha1),
                            !is_null_sha1(ce->sha1), (changed ? 0 : !is_null_sha1(ce->sha1)),
diff --git a/diff.c b/diff.c
index f72769a1c492dfcac501032c54c3fb2ac0a4343e..bba9a558a60a490b7edd6dec370181a0941bf985 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -1361,7 +1361,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) {
@@ -2880,6 +2880,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 +2906,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 +3199,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;
@@ -3325,6 +3320,9 @@ void diff_setup_done(struct diff_options *options)
        }
 
        options->diff_path_counter = 0;
+
+       if (DIFF_OPT_TST(options, FOLLOW_RENAMES) && options->pathspec.nr != 1)
+               die(_("--follow requires exactly one pathspec"));
 }
 
 static int opt_arg(const char *arg, int arg_short, const char *arg_long, int *val)
@@ -4749,6 +4747,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)
index 5c4815dbe132fc358aa55eeb20d86d867c97c37f..4dac5e9edd75499ccf52debc847807d2fc180730 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;
index fb4738d373a5a1048c2ff388a729e6088515ca9b..6707a66471f2038a0c826c840a201a7362de95ed 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];
 };
@@ -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);
@@ -2611,8 +2615,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);
 
index eeee2bb7e08a21dfe091a30c8378da6d488228f5..b12bd4c59a1105f4d3a82bbbd5208e3f7ebae0bb 100644 (file)
@@ -507,7 +507,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..a7233c8d0b20c06f0aebffbec9c11dacb22b6769 100644 (file)
--- a/fsck.c
+++ b/fsck.c
@@ -276,9 +276,10 @@ 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;
+       const char *tmp;
        unsigned char tree_sha1[20], sha1[20];
        struct commit_graft *graft;
        int parents = 0;
@@ -336,6 +337,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 f6d3a46622d1de2497b56274a255d7bca46117dd..b6f03b36dc762b891e77a5ca44e7ca5f270c5af9 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));
@@ -521,6 +529,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);
@@ -531,6 +547,7 @@ extern void *xcalloc(size_t nmemb, size_t size);
 extern void *xmmap(void *start, size_t length, int prot, int flags, int fd, off_t offset);
 extern ssize_t xread(int fd, void *buf, size_t len);
 extern ssize_t xwrite(int fd, const void *buf, size_t len);
+extern ssize_t xpread(int fd, void *buf, size_t len, off_t offset);
 extern int xdup(int fd);
 extern FILE *xfdopen(int fd, const char *mode);
 extern int xmkstemp(char *template);
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 @@ def edit_template(self, template_file):
             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 @@ def applyCommit(self, id):
             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 @@ def applyCommit(self, id):
             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 6cd8ebc534c174dfe613f62047424dc7491d75fa..18a394fcc4e704621c8b5e8bc92b7cbee2fd21fe 100755 (executable)
@@ -58,11 +58,9 @@ pull_ff=$(git config pull.ff)
 case "$pull_ff" in
 false)
        no_ff=--no-ff
-       break
        ;;
 only)
        ff_only=--ff-only
-       break
        ;;
 esac
 
@@ -108,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 6ec9d3cb40b1e96f75132a11eb625fd42e64885d..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,
@@ -1049,14 +1049,14 @@ fi
 
 
 has_action "$todo" ||
-       die_abort "Nothing to do"
+       return 2
 
 cp "$todo" "$todo".backup
 git_sequence_editor "$todo" ||
        die_abort "Could not execute editor"
 
 has_action "$todo" ||
-       die_abort "Nothing to do"
+       return 2
 
 expand_todo_ids
 
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 4543815ffd6b0d49466edc3059f6d085b79ebf8a..06c810b64fe04d3675820e38d7eeabe7589dab56 100755 (executable)
@@ -155,7 +155,7 @@ move_to_original_branch () {
        esac
 }
 
-finish_rebase () {
+apply_autostash () {
        if test -f "$state_dir/autostash"
        then
                stash_sha1=$(cat "$state_dir/autostash")
@@ -171,6 +171,10 @@ You can run "git stash pop" or "git stash drop" at any time.
 '
                fi
        fi
+}
+
+finish_rebase () {
+       apply_autostash &&
        git gc --auto &&
        rm -rf "$state_dir"
 }
@@ -186,6 +190,11 @@ run_specific_rebase () {
        if test $ret -eq 0
        then
                finish_rebase
+       elif test $ret -eq 2 # special exit status for rebase -i
+       then
+               apply_autostash &&
+               rm -rf "$state_dir" &&
+               die "Nothing to do"
        fi
        exit $ret
 }
@@ -457,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
@@ -516,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 @@ sub usage {
     --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 @@ sub do_edit {
     "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 @@ sub signal_handler {
                    "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 @@ sub send_message {
 
        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 @@ sub send_message {
                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 @@ sub send_message {
        @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..d6b4a5543f77071aff977f6d58e3ab6c5495f19d 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) {
@@ -272,6 +309,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 +328,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 +390,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 +416,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 },
@@ -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;
        }
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"
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"))
index f2c56c84544be36414686ed2e27c8b08e8946e53..de00d1693af902713ab5562e9d87fe621b02f955 100644 (file)
@@ -1732,7 +1732,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 0bc6f7fae151ea364e9d141b30b8e68d544a4448..83a6ed2ac338d7fc82f3bed6fcb93ffe8dae5739 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;
 }
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 41770929420da4cba934b0b86b9cd2f55f9cab31..d38a3b2eb5bf4b0940a2aa4d5c32f02b9f35cc15 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);
                }
        }
 }
@@ -589,6 +591,12 @@ static int remove_file(struct merge_options *o, int clean,
                        return -1;
        }
        if (update_working_directory) {
+               if (ignore_case) {
+                       struct cache_entry *ce;
+                       ce = cache_file_exists(path, strlen(path), ignore_case);
+                       if (ce && ce_stage(ce) == 0)
+                               return 0;
+               }
                if (remove_path(path))
                        return -1;
        }
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 d01d851ce957c779ff98d243fea4476fa7a1008c..4f36c3204544c40ada8e6ce584deb6063b055518 100644 (file)
@@ -47,8 +47,8 @@ static void rehash_objects(struct packing_data *pdata)
        if (pdata->index_size < 1024)
                pdata->index_size = 1024;
 
-       pdata->index = xrealloc(pdata->index, sizeof(uint32_t) * pdata->index_size);
-       memset(pdata->index, 0, sizeof(int) * pdata->index_size);
+       free(pdata->index);
+       pdata->index = xcalloc(pdata->index_size, sizeof(*pdata->index));
 
        entry = pdata->objects;
 
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 0cc75a8eee32a0195a74c6819a04745f341e45e3..8b5cbc56e4fd57a1b9d2cad3e668df4c508a7b17 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -64,7 +64,7 @@ void setup_pager(void)
 {
        const char *pager = git_pager(isatty(1));
 
-       if (!pager || pager_in_use())
+       if (!pager)
                return;
 
        /*
@@ -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 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 3c43db558aee43b0ea69c23c6611dcc9fae0661f..c93c14b080b8f23fc30fa58b85c9d70f063c7225 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -274,7 +274,7 @@ static void add_rfc822_quoted(struct strbuf *out, const char *s, int len)
 
 enum rfc2047_type {
        RFC2047_SUBJECT,
-       RFC2047_ADDRESS,
+       RFC2047_ADDRESS
 };
 
 static int is_rfc2047_special(char ch, enum rfc2047_type type)
@@ -393,8 +393,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 +606,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 +639,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 +655,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 +675,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 +778,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;
@@ -1506,13 +1488,18 @@ void format_commit_message(const struct commit *commit,
        context.commit = commit;
        context.pretty_ctx = pretty_ctx;
        context.wrap_start = sb->len;
+       /*
+        * convert a commit message to UTF-8 first
+        * as far as 'format_commit_item' assumes it in UTF-8
+        */
        context.message = logmsg_reencode(commit,
                                          &context.commit_encoding,
-                                         output_enc);
+                                         utf8);
 
        strbuf_expand(sb, format, format_commit_item, &context);
        rewrap_message_tail(sb, &context, 0, 0, 0);
 
+       /* then convert a commit message to an actual output encoding */
        if (output_enc) {
                if (same_encoding(utf8, output_enc))
                        output_enc = NULL;
@@ -1531,7 +1518,7 @@ void format_commit_message(const struct commit *commit,
        }
 
        free(context.commit_encoding);
-       logmsg_free(context.message, commit);
+       unuse_commit_buffer(commit, context.message);
        free(context.signature_check.gpg_output);
        free(context.signature_check.signer);
 }
@@ -1700,7 +1687,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;
 
@@ -1767,7 +1754,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 ba13353b377d4f27b9ff6cf1b85811fcca61e224..6a45966ec499b47efbc76719046b53633e8839a1 100644 (file)
@@ -422,18 +422,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 +450,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;
@@ -1477,6 +1480,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);
        istate->version = ntohl(hdr->hdr_version);
        istate->cache_nr = ntohl(hdr->hdr_entries);
        istate->cache_alloc = alloc_nr(istate->cache_nr);
@@ -1760,6 +1764,50 @@ static int ce_write_entry(git_SHA_CTX *c, int fd, struct cache_entry *ce,
        return result;
 }
 
+/*
+ * This function verifies if index_state has the correct sha1 of the
+ * index file.  Don't die if we have any other failure, just return 0.
+ */
+static int verify_index_from(const struct index_state *istate, const char *path)
+{
+       int fd;
+       ssize_t n;
+       struct stat st;
+       unsigned char sha1[20];
+
+       if (!istate->initialized)
+               return 0;
+
+       fd = open(path, O_RDONLY);
+       if (fd < 0)
+               return 0;
+
+       if (fstat(fd, &st))
+               goto out;
+
+       if (st.st_size < sizeof(struct cache_header) + 20)
+               goto out;
+
+       n = pread_in_full(fd, sha1, 20, st.st_size - 20);
+       if (n != 20)
+               goto out;
+
+       if (hashcmp(istate->sha1, sha1))
+               goto out;
+
+       close(fd);
+       return 1;
+
+out:
+       close(fd);
+       return 0;
+}
+
+static int verify_index(const struct index_state *istate)
+{
+       return verify_index_from(istate, get_index_file());
+}
+
 static int has_racy_timestamp(struct index_state *istate)
 {
        int entries = istate->cache_nr;
@@ -1779,7 +1827,7 @@ 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)) &&
-           !write_index(istate, lockfile->fd))
+           verify_index(istate) && !write_index(istate, lockfile->fd))
                commit_locked_index(lockfile);
        else
                rollback_lock_file(lockfile);
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 28d5eca8eaff7be48a4b89e6217886b8c96eb3b2..dc457742eade241ec6b0001580d1ce1a880fee31 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -6,8 +6,29 @@
 #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:
+ * 0: An acceptable character for refs
+ * 1: End-of-component
+ * 2: ., look for a preceding . to reject .. in refs
+ * 3: {, look for a preceding @ to reject @{ in refs
+ * 4: A bad character: ASCII control characters, "~", "^", ":" or SP
+ */
+static unsigned char refname_disposition[256] = {
+       1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+       4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+       4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 2, 1,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 4,
+       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, 4, 4, 0, 4, 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, 3, 0, 0, 4, 4
+};
+
+/*
+ * 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 ends with ".lock"
  * - 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 1:
+                       goto out;
+               case 2:
+                       if (last == '.')
+                               return -1; /* Refname contains "..". */
+                       break;
+               case 3:
+                       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 4:
+                       return -1;
+               }
                last = ch;
        }
+out:
        if (cp == refname)
                return 0; /* Component has zero length. */
        if (refname[0] == '.') {
@@ -1611,6 +1622,7 @@ int peel_ref(const char *refname, unsigned char *sha1)
 struct warn_if_dangling_data {
        FILE *fp;
        const char *refname;
+       const struct string_list *refnames;
        const char *msg_fmt;
 };
 
@@ -1625,8 +1637,12 @@ static int warn_if_dangling_symref(const char *refname, const unsigned char *sha
                return 0;
 
        resolves_to = resolve_ref_unsafe(refname, junk, 0, NULL);
-       if (!resolves_to || strcmp(resolves_to, d->refname))
+       if (!resolves_to
+           || (d->refname
+               ? strcmp(resolves_to, d->refname)
+               : !string_list_has_string(d->refnames, resolves_to))) {
                return 0;
+       }
 
        fprintf(d->fp, d->msg_fmt, refname);
        fputc('\n', d->fp);
@@ -1639,6 +1655,18 @@ void warn_dangling_symref(FILE *fp, const char *msg_fmt, const char *refname)
 
        data.fp = fp;
        data.refname = refname;
+       data.refnames = NULL;
+       data.msg_fmt = msg_fmt;
+       for_each_rawref(warn_if_dangling_symref, &data);
+}
+
+void warn_dangling_symrefs(FILE *fp, const char *msg_fmt, const struct string_list *refnames)
+{
+       struct warn_if_dangling_data data;
+
+       data.fp = fp;
+       data.refname = NULL;
+       data.refnames = refnames;
        data.msg_fmt = msg_fmt;
        for_each_rawref(warn_if_dangling_symref, &data);
 }
@@ -1999,7 +2027,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;
@@ -2008,12 +2035,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;
@@ -2431,7 +2455,7 @@ static int curate_packed_ref_fn(struct ref_entry *entry, void *cb_data)
        return 0;
 }
 
-static int repack_without_refs(const char **refnames, int n)
+int repack_without_refs(const char **refnames, int n)
 {
        struct ref_dir *packed;
        struct string_list refs_to_delete = STRING_LIST_INIT_DUP;
@@ -2930,122 +2954,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];
@@ -3243,9 +3278,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;
@@ -3258,15 +3293,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)
@@ -3282,7 +3420,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,
@@ -3290,15 +3428,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;
@@ -3306,26 +3444,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)
@@ -3333,35 +3466,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]));
@@ -3369,12 +3511,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 87a1a79ad659f3520a22ae14bac1d5082cf2c27b..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():
@@ -89,6 +77,7 @@ static inline const char *has_glob_specials(const char *pattern)
 extern int for_each_rawref(each_ref_fn, void *);
 
 extern void warn_dangling_symref(FILE *fp, const char *msg_fmt, const char *refname);
+extern void warn_dangling_symrefs(FILE *fp, const char *msg_fmt, const struct string_list* refnames);
 
 /*
  * Lock the packed-refs file for writing.  Flags is passed to
@@ -132,6 +121,8 @@ extern void rollback_packed_refs(void);
  */
 int pack_refs(unsigned int flags);
 
+extern int repack_without_refs(const char **refnames, int n);
+
 extern int ref_exists(const char *);
 
 /*
@@ -166,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);
@@ -214,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 eea2c8de45052e3e3a59fb150eef3f54c6086800..ae040432037f7463233c5add8257b17ace365b23 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -523,7 +523,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 +1194,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 71e233742331a435edeadacc7c6a52226bb18b7a..2571ada6bf66ce6e945c539be4b0123e5b9648a9 100644 (file)
@@ -1633,6 +1633,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
            !strcmp(arg, "--reflog") || !strcmp(arg, "--not") ||
            !strcmp(arg, "--no-walk") || !strcmp(arg, "--do-walk") ||
            !strcmp(arg, "--bisect") || starts_with(arg, "--glob=") ||
+           starts_with(arg, "--exclude=") ||
            starts_with(arg, "--branches=") || starts_with(arg, "--tags=") ||
            starts_with(arg, "--remotes=") || starts_with(arg, "--no-walk="))
        {
@@ -1648,8 +1649,10 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
                revs->skip_count = atoi(optarg);
                return argcount;
        } else if ((*arg == '-') && isdigit(arg[1])) {
-       /* accept -<digit>, like traditional "head" */
-               revs->max_count = atoi(arg + 1);
+               /* accept -<digit>, like traditional "head" */
+               if (strtol_i(arg + 1, 10, &revs->max_count) < 0 ||
+                   revs->max_count < 0)
+                       die("'%s': not a non-negative integer", arg + 1);
                revs->no_walk = 0;
        } else if (!strcmp(arg, "-n")) {
                if (argc <= 1)
@@ -2788,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)
@@ -2830,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 @@ int start_command(struct child_process *cmd)
                        close_pair(fderr);
                else if (cmd->err)
                        close(cmd->err);
+               argv_array_clear(&cmd->args);
                errno = failed_errno;
                return -1;
        }
@@ -543,7 +548,9 @@ int start_command(struct child_process *cmd)
 
 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..c513d7eeb4d747cbc41950e3ff197aca8d81d6d4 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;
 }
@@ -485,7 +454,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 +619,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;
@@ -697,10 +666,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 3e9f55f1bb19a33908be174b2fa463f8142d4cae..34d527f6708fe242f75b7fa0fa98e36a5c96a3be 100644 (file)
@@ -1437,19 +1437,23 @@ static int open_sha1_file(const unsigned char *sha1)
 {
        int fd;
        struct alternate_object_database *alt;
+       int most_interesting_errno;
 
        fd = git_open_noatime(sha1_file_name(sha1));
        if (fd >= 0)
                return fd;
+       most_interesting_errno = errno;
 
        prepare_alt_odb();
-       errno = ENOENT;
        for (alt = alt_odb_list; alt; alt = alt->next) {
                fill_sha1_path(alt->name, sha1);
                fd = git_open_noatime(alt->base);
                if (fd >= 0)
                        return fd;
+               if (most_interesting_errno == ENOENT)
+                       most_interesting_errno = errno;
        }
+       errno = most_interesting_errno;
        return -1;
 }
 
index 2b6322fad064845f4c782286fe9764f6b958f30d..c2c938c4e161fc6849a87a7a19336712f36f74ff 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);
index d1125f5c528b680f915bb2fbf54231cc8c3b2ec0..7f9dc229fbc82d005b5c2b417c2af2fc9f6b497a 100644 (file)
@@ -30,7 +30,7 @@ int recv_sideband(const char *me, int in_stream, int out)
 
        memcpy(buf, PREFIX, pf);
        term = getenv("TERM");
-       if (term && strcmp(term, "dumb"))
+       if (isatty(2) && term && strcmp(term, "dumb"))
                suffix = ANSI_SUFFIX;
        else
                suffix = DUMB_SUFFIX;
index fc7290f57a07353ab7bbf86b7c743ec913ee396c..ac62982e672c22457468f601b35716dc9a52a81c 100644 (file)
--- a/strbuf.c
+++ b/strbuf.c
@@ -79,15 +79,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)
 {
@@ -123,6 +116,13 @@ int strbuf_reencode(struct strbuf *sb, const char *from, const char *to)
        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)
 {
@@ -587,3 +587,16 @@ 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;
+}
index 4e9a2f88686e211b8610d72e18c02251c2dc8a92..e9ad03eabe72dc2ee6e7e0086baca71d343264ce 100644 (file)
--- a/strbuf.h
+++ b/strbuf.h
@@ -46,6 +46,7 @@ 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 *);
 
 /*
@@ -184,4 +185,6 @@ 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 *);
+
 #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 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 f7640bee9a4564f3099b0751811e7cd6a41ecc09..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'
@@ -137,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 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..28102de1a0f987b351a423516d394180175a1f13 100755 (executable)
@@ -19,9 +19,9 @@ test_expect_success setup '
 
        git commit -m initial &&
 
-       one=`git rev-parse HEAD:one` &&
-       two=`git rev-parse HEAD:two` &&
-       three=`git rev-parse HEAD:three` &&
+       one=$(git rev-parse HEAD:one) &&
+       two=$(git rev-parse HEAD:two) &&
+       three=$(git rev-parse HEAD:three) &&
 
        echo happy.
 '
@@ -33,10 +33,10 @@ test_expect_success 'default settings cause no changes' '
 
        ! 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"
+       onediff=$(git diff one) &&
+       twodiff=$(git diff two) &&
+       threediff=$(git diff three) &&
+       test -z "$onediff" && test -z "$twodiff" && test -z "$threediff"
 '
 
 test_expect_success 'crlf=true causes a CRLF file to be normalized' '
@@ -48,7 +48,7 @@ test_expect_success 'crlf=true causes a CRLF file to be normalized' '
 
        # Note, "normalized" means that git will normalize it if added
        has_cr two &&
-       twodiff=`git diff two` &&
+       twodiff=$(git diff two) &&
        test -n "$twodiff"
 '
 
@@ -60,7 +60,7 @@ test_expect_success 'text=true causes a CRLF file to be normalized' '
 
        # Note, "normalized" means that git will normalize it if added
        has_cr two &&
-       twodiff=`git diff two` &&
+       twodiff=$(git diff two) &&
        test -n "$twodiff"
 '
 
@@ -72,7 +72,7 @@ test_expect_success 'eol=crlf gives a normalized file CRLFs with autocrlf=false'
        git read-tree --reset -u HEAD &&
 
        has_cr one &&
-       onediff=`git diff one` &&
+       onediff=$(git diff one) &&
        test -z "$onediff"
 '
 
@@ -84,7 +84,7 @@ test_expect_success 'eol=crlf gives a normalized file CRLFs with autocrlf=input'
        git read-tree --reset -u HEAD &&
 
        has_cr one &&
-       onediff=`git diff one` &&
+       onediff=$(git diff one) &&
        test -z "$onediff"
 '
 
@@ -96,7 +96,7 @@ test_expect_success 'eol=lf gives a normalized file LFs with autocrlf=true' '
        git read-tree --reset -u HEAD &&
 
        ! has_cr one &&
-       onediff=`git diff one` &&
+       onediff=$(git diff one) &&
        test -z "$onediff"
 '
 
@@ -108,10 +108,10 @@ test_expect_success 'autocrlf=true does not normalize CRLF files' '
 
        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"
+       onediff=$(git diff one) &&
+       twodiff=$(git diff two) &&
+       threediff=$(git diff three) &&
+       test -z "$onediff" && test -z "$twodiff" && test -z "$threediff"
 '
 
 test_expect_success 'text=auto, autocrlf=true _does_ normalize CRLF files' '
@@ -123,10 +123,10 @@ test_expect_success 'text=auto, autocrlf=true _does_ normalize CRLF files' '
 
        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"
+       onediff=$(git diff one) &&
+       twodiff=$(git diff two) &&
+       threediff=$(git diff three) &&
+       test -z "$onediff" && test -n "$twodiff" && test -z "$threediff"
 '
 
 test_expect_success 'text=auto, autocrlf=true does not normalize binary files' '
@@ -137,7 +137,7 @@ test_expect_success 'text=auto, autocrlf=true does not normalize binary files' '
        git read-tree --reset -u HEAD &&
 
        ! has_cr three &&
-       threediff=`git diff three` &&
+       threediff=$(git diff three) &&
        test -z "$threediff"
 '
 
@@ -148,7 +148,7 @@ test_expect_success 'eol=crlf _does_ normalize binary files' '
        git read-tree --reset -u HEAD &&
 
        has_cr three &&
-       threediff=`git diff three` &&
+       threediff=$(git diff three) &&
        test -z "$threediff"
 '
 
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
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 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
index 178694ee63937a9ec1f8d182d54441c2d20bd4a3..1978947c4196fb666d55395bedc53ae149b6d13d 100755 (executable)
@@ -121,7 +121,7 @@ test_expect_success 'merge my-side@{u} records the correct name' '
        git branch -D new ;# can fail but is ok
        git branch -t new my-side@{u} &&
        git merge -s ours new@{u} &&
-       git show -s --pretty=format:%s >actual &&
+       git show -s --pretty=tformat:%s >actual &&
        echo "Merge remote-tracking branch ${sq}origin/side${sq}" >expect &&
        test_cmp expect actual
 )
index fe2fb17102cdc17168ae2d683d7d51a0b3e3f3bc..1bafb9098c7fae33969e9231fbdee1c0370830a1 100755 (executable)
@@ -29,6 +29,10 @@ test_expect_success 'update-index -h with corrupt index' '
        test_i18ngrep "[Uu]sage: git update-index" broken/usage
 '
 
+test_expect_success '--cacheinfo complains of missing arguments' '
+       test_must_fail git update-index --cacheinfo
+'
+
 test_expect_success '--cacheinfo does not accept blob null sha1' '
        echo content >file &&
        git add file &&
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 90eb26493cd309da34687dffc939166069cd88c6..d783f03d3fc581eed08d8d2593e20ced3cbae200 100755 (executable)
@@ -167,4 +167,19 @@ testrebase "" .git/rebase-apply
 testrebase " --merge" .git/rebase-merge
 testrebase " --interactive" .git/rebase-merge
 
+test_expect_success 'abort rebase -i with --autostash' '
+       test_when_finished "git reset --hard" &&
+       echo uncommited-content >file0 &&
+       (
+               write_script abort-editor.sh <<-\EOF &&
+                       echo >"$1"
+               EOF
+               test_set_editor "$(pwd)/abort-editor.sh" &&
+               test_must_fail git rebase -i --autostash HEAD^ &&
+               rm -f abort-editor.sh
+       ) &&
+       echo uncommited-content >expected &&
+       test_cmp expected file0
+'
+
 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 9d9498bd95c525b008bd3719c2debf87c66ebef2..23c0e357a765f00d807938fccf81a250c371ec4f 100755 (executable)
@@ -28,4 +28,15 @@ test_expect_success 'diff-files does not examine assume-unchanged entries' '
        test -z "$(git diff-files -- one)"
 '
 
+test_expect_success POSIXPERM 'find-copies-harder is not confused by mode bits' '
+       echo content >exec &&
+       chmod +x exec &&
+       git add exec &&
+       git commit -m exec &&
+       git update-index --assume-unchanged exec &&
+       >expect &&
+       git diff-files --find-copies-harder -- exec >actual &&
+       test_cmp expect actual
+'
+
 test_done
index 1751c8330709c56a4b7019513e30434741847b95..463d63bde0f72bb5add9edff762e38f0b5b85ae5 100755 (executable)
@@ -11,6 +11,9 @@ This test tries to verify the sanity of the --submodule option of git diff.
 
 . ./test-lib.sh
 
+# Tested non-UTF-8 encoding
+test_encoding="ISO8859-1"
+
 # String "added" in German (translated with Google Translate), encoded in UTF-8,
 # used in sample commit log messages in add_file() function below.
 added=$(printf "hinzugef\303\274gt")
@@ -23,8 +26,8 @@ add_file () {
                        echo "$name" >"$name" &&
                        git add "$name" &&
                        test_tick &&
-                       msg_added_iso88591=$(echo "Add $name ($added $name)" | iconv -f utf-8 -t iso8859-1) &&
-                       git -c 'i18n.commitEncoding=iso8859-1' commit -m "$msg_added_iso88591"
+                       msg_added_iso88591=$(echo "Add $name ($added $name)" | iconv -f utf-8 -t $test_encoding) &&
+                       git -c "i18n.commitEncoding=$test_encoding" commit -m "$msg_added_iso88591"
                done >/dev/null &&
                git rev-parse --short --verify HEAD
        )
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 b04fc8fc12238c3326306ed0e055b7d67bf950b4..9e29b5262d3f2e8514d5742951e28a3a339218dc 100755 (executable)
@@ -111,7 +111,6 @@ sed -e 's/T/        /g' > main.c.final <<\EOF
 #include <stdio.h>
 
 void print_int(int num);
-T/* a comment */
 int func(int num);
 
 int main() {
@@ -154,7 +153,8 @@ test_expect_success 'patch2 reverse applies with --ignore-space-change' '
 git config apply.ignorewhitespace change
 
 test_expect_success 'patch2 applies (apply.ignorewhitespace = change)' '
-       git apply patch2.patch
+       git apply patch2.patch &&
+       test_cmp main.c.final main.c
 '
 
 test_expect_success 'patch3 fails (missing string at EOL)' '
@@ -165,12 +165,8 @@ test_expect_success 'patch4 fails (missing EOL at EOF)' '
        test_must_fail git apply patch4.patch
 '
 
-test_expect_success 'patch5 applies (leading whitespace)' '
-       git apply patch5.patch
-'
-
-test_expect_success 'patches do not mangle whitespace' '
-       test_cmp main.c main.c.final
+test_expect_success 'patch5 fails (leading whitespace differences matter)' '
+       test_must_fail git apply patch5.patch
 '
 
 test_expect_success 're-create file (with --ignore-whitespace)' '
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 42866992cfe65657019dced508d3490b3851a6c7..97fcb31d6eb516b195e9e26a8716dbf484fcc616 100755 (executable)
@@ -188,4 +188,10 @@ test_expect_success 'shortlog ignores commits with missing authors' '
        test_cmp expect actual
 '
 
+test_expect_success 'shortlog with revision pseudo options' '
+       git shortlog --all &&
+       git shortlog --branches &&
+       git shortlog --exclude=refs/heads/m* --all
+'
+
 test_done
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 2a6278bb333d2843ee617ff69227feae115aefea..c84ec9ae6139be752831365244f5580e46138884 100755 (executable)
@@ -7,6 +7,9 @@
 test_description='Test pretty formats'
 . ./test-lib.sh
 
+# Tested non-UTF-8 encoding
+test_encoding="ISO8859-1"
+
 sample_utf8_part=$(printf "f\303\244ng")
 
 commit_msg () {
@@ -27,8 +30,8 @@ test_expect_success 'set up basic repos' '
        >bar &&
        git add foo &&
        test_tick &&
-       git config i18n.commitEncoding iso8859-1 &&
-       git commit -m "$(commit_msg iso8859-1)" &&
+       git config i18n.commitEncoding $test_encoding &&
+       git commit -m "$(commit_msg $test_encoding)" &&
        git add bar &&
        test_tick &&
        git commit -m "add bar" &&
@@ -56,8 +59,8 @@ test_expect_success 'alias user-defined format' '
        test_cmp expected actual
 '
 
-test_expect_success 'alias user-defined tformat with %s (iso8859-1 encoding)' '
-       git config i18n.logOutputEncoding iso8859-1 &&
+test_expect_success 'alias user-defined tformat with %s (ISO8859-1 encoding)' '
+       git config i18n.logOutputEncoding $test_encoding &&
        git log --oneline >expected-s &&
        git log --pretty="tformat:%h %s" >actual-s &&
        git config --unset i18n.logOutputEncoding &&
@@ -141,9 +144,7 @@ test_expect_success 'setup more commits' '
 '
 
 test_expect_success 'left alignment formatting' '
-       git log --pretty="format:%<(40)%s" >actual &&
-       # complete the incomplete line at the end
-       echo >>actual &&
+       git log --pretty="tformat:%<(40)%s" >actual &&
        qz_to_tab_space <<EOF >expected &&
 message two                            Z
 message one                            Z
@@ -153,10 +154,19 @@ EOF
        test_cmp expected actual
 '
 
+test_expect_success 'left alignment formatting. i18n.logOutputEncoding' '
+       git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(40)%s" >actual &&
+       qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+message two                            Z
+message one                            Z
+add bar                                Z
+$(commit_msg)                    Z
+EOF
+       test_cmp expected actual
+'
+
 test_expect_success 'left alignment formatting at the nth column' '
-       git log --pretty="format:%h %<|(40)%s" >actual &&
-       # complete the incomplete line at the end
-       echo >>actual &&
+       git log --pretty="tformat:%h %<|(40)%s" >actual &&
        qz_to_tab_space <<EOF >expected &&
 $head1 message two                    Z
 $head2 message one                    Z
@@ -166,10 +176,19 @@ EOF
        test_cmp expected actual
 '
 
+test_expect_success 'left alignment formatting at the nth column. i18n.logOutputEncoding' '
+       git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %<|(40)%s" >actual &&
+       qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+$head1 message two                    Z
+$head2 message one                    Z
+$head3 add bar                        Z
+$head4 $(commit_msg)            Z
+EOF
+       test_cmp expected actual
+'
+
 test_expect_success 'left alignment formatting with no padding' '
-       git log --pretty="format:%<(1)%s" >actual &&
-       # complete the incomplete line at the end
-       echo >>actual &&
+       git log --pretty="tformat:%<(1)%s" >actual &&
        cat <<EOF >expected &&
 message two
 message one
@@ -179,10 +198,19 @@ EOF
        test_cmp expected actual
 '
 
+test_expect_success 'left alignment formatting with no padding. i18n.logOutputEncoding' '
+       git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(1)%s" >actual &&
+       cat <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+message two
+message one
+add bar
+$(commit_msg)
+EOF
+       test_cmp expected actual
+'
+
 test_expect_success 'left alignment formatting with trunc' '
-       git log --pretty="format:%<(10,trunc)%s" >actual &&
-       # complete the incomplete line at the end
-       echo >>actual &&
+       git log --pretty="tformat:%<(10,trunc)%s" >actual &&
        qz_to_tab_space <<EOF >expected &&
 message ..
 message ..
@@ -192,10 +220,19 @@ EOF
        test_cmp expected actual
 '
 
+test_expect_success 'left alignment formatting with trunc. i18n.logOutputEncoding' '
+       git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s" >actual &&
+       qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+message ..
+message ..
+add bar  Z
+initial...
+EOF
+       test_cmp expected actual
+'
+
 test_expect_success 'left alignment formatting with ltrunc' '
-       git log --pretty="format:%<(10,ltrunc)%s" >actual &&
-       # complete the incomplete line at the end
-       echo >>actual &&
+       git log --pretty="tformat:%<(10,ltrunc)%s" >actual &&
        qz_to_tab_space <<EOF >expected &&
 ..sage two
 ..sage one
@@ -205,10 +242,19 @@ EOF
        test_cmp expected actual
 '
 
+test_expect_success 'left alignment formatting with ltrunc. i18n.logOutputEncoding' '
+       git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,ltrunc)%s" >actual &&
+       qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+..sage two
+..sage one
+add bar  Z
+..${sample_utf8_part}lich
+EOF
+       test_cmp expected actual
+'
+
 test_expect_success 'left alignment formatting with mtrunc' '
-       git log --pretty="format:%<(10,mtrunc)%s" >actual &&
-       # complete the incomplete line at the end
-       echo >>actual &&
+       git log --pretty="tformat:%<(10,mtrunc)%s" >actual &&
        qz_to_tab_space <<EOF >expected &&
 mess.. two
 mess.. one
@@ -218,10 +264,19 @@ EOF
        test_cmp expected actual
 '
 
+test_expect_success 'left alignment formatting with mtrunc. i18n.logOutputEncoding' '
+       git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,mtrunc)%s" >actual &&
+       qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+mess.. two
+mess.. one
+add bar  Z
+init..lich
+EOF
+       test_cmp expected actual
+'
+
 test_expect_success 'right alignment formatting' '
-       git log --pretty="format:%>(40)%s" >actual &&
-       # complete the incomplete line at the end
-       echo >>actual &&
+       git log --pretty="tformat:%>(40)%s" >actual &&
        qz_to_tab_space <<EOF >expected &&
 Z                            message two
 Z                            message one
@@ -231,10 +286,19 @@ EOF
        test_cmp expected actual
 '
 
+test_expect_success 'right alignment formatting. i18n.logOutputEncoding' '
+       git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%>(40)%s" >actual &&
+       qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+Z                            message two
+Z                            message one
+Z                                add bar
+Z                    $(commit_msg)
+EOF
+       test_cmp expected actual
+'
+
 test_expect_success 'right alignment formatting at the nth column' '
-       git log --pretty="format:%h %>|(40)%s" >actual &&
-       # complete the incomplete line at the end
-       echo >>actual &&
+       git log --pretty="tformat:%h %>|(40)%s" >actual &&
        qz_to_tab_space <<EOF >expected &&
 $head1                      message two
 $head2                      message one
@@ -244,10 +308,19 @@ EOF
        test_cmp expected actual
 '
 
+test_expect_success 'right alignment formatting at the nth column. i18n.logOutputEncoding' '
+       git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %>|(40)%s" >actual &&
+       qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+$head1                      message two
+$head2                      message one
+$head3                          add bar
+$head4              $(commit_msg)
+EOF
+       test_cmp expected actual
+'
+
 test_expect_success 'right alignment formatting with no padding' '
-       git log --pretty="format:%>(1)%s" >actual &&
-       # complete the incomplete line at the end
-       echo >>actual &&
+       git log --pretty="tformat:%>(1)%s" >actual &&
        cat <<EOF >expected &&
 message two
 message one
@@ -257,10 +330,19 @@ EOF
        test_cmp expected actual
 '
 
+test_expect_success 'right alignment formatting with no padding. i18n.logOutputEncoding' '
+       git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%>(1)%s" >actual &&
+       cat <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+message two
+message one
+add bar
+$(commit_msg)
+EOF
+       test_cmp expected actual
+'
+
 test_expect_success 'center alignment formatting' '
-       git log --pretty="format:%><(40)%s" >actual &&
-       # complete the incomplete line at the end
-       echo >>actual &&
+       git log --pretty="tformat:%><(40)%s" >actual &&
        qz_to_tab_space <<EOF >expected &&
 Z             message two              Z
 Z             message one              Z
@@ -270,10 +352,18 @@ EOF
        test_cmp expected actual
 '
 
+test_expect_success 'center alignment formatting. i18n.logOutputEncoding' '
+       git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%><(40)%s" >actual &&
+       qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+Z             message two              Z
+Z             message one              Z
+Z               add bar                Z
+Z         $(commit_msg)          Z
+EOF
+       test_cmp expected actual
+'
 test_expect_success 'center alignment formatting at the nth column' '
-       git log --pretty="format:%h %><|(40)%s" >actual &&
-       # complete the incomplete line at the end
-       echo >>actual &&
+       git log --pretty="tformat:%h %><|(40)%s" >actual &&
        qz_to_tab_space <<EOF >expected &&
 $head1           message two          Z
 $head2           message one          Z
@@ -283,10 +373,19 @@ EOF
        test_cmp expected actual
 '
 
+test_expect_success 'center alignment formatting at the nth column. i18n.logOutputEncoding' '
+       git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %><|(40)%s" >actual &&
+       qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+$head1           message two          Z
+$head2           message one          Z
+$head3             add bar            Z
+$head4       $(commit_msg)      Z
+EOF
+       test_cmp expected actual
+'
+
 test_expect_success 'center alignment formatting with no padding' '
-       git log --pretty="format:%><(1)%s" >actual &&
-       # complete the incomplete line at the end
-       echo >>actual &&
+       git log --pretty="tformat:%><(1)%s" >actual &&
        cat <<EOF >expected &&
 message two
 message one
@@ -296,11 +395,23 @@ EOF
        test_cmp expected actual
 '
 
+# save HEAD's SHA-1 digest (with no abbreviations) to use it below
+# as far as the next test amends HEAD
+old_head1=$(git rev-parse --verify HEAD~0)
+test_expect_success 'center alignment formatting with no padding. i18n.logOutputEncoding' '
+       git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%><(1)%s" >actual &&
+       cat <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+message two
+message one
+add bar
+$(commit_msg)
+EOF
+       test_cmp expected actual
+'
+
 test_expect_success 'left/right alignment formatting with stealing' '
        git commit --amend -m short --author "long long long <long@me.com>" &&
-       git log --pretty="format:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
-       # complete the incomplete line at the end
-       echo >>actual &&
+       git log --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
        cat <<EOF >expected &&
 short long  long long
 message ..   A U Thor
@@ -309,6 +420,20 @@ initial...   A U Thor
 EOF
        test_cmp expected actual
 '
+test_expect_success 'left/right alignment formatting with stealing. i18n.logOutputEncoding' '
+       git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
+       cat <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+short long  long long
+message ..   A U Thor
+add bar      A U Thor
+initial...   A U Thor
+EOF
+       test_cmp expected actual
+'
+
+# get new digests (with no abbreviations)
+head1=$(git rev-parse --verify HEAD~0) &&
+head2=$(git rev-parse --verify HEAD~1) &&
 
 test_expect_success 'log decoration properly follows tag chain' '
        git tag -a tag1 -m tag1 &&
@@ -317,9 +442,9 @@ test_expect_success 'log decoration properly follows tag chain' '
        git commit --amend -m shorter &&
        git log --no-walk --tags --pretty="%H %d" --decorate=full >actual &&
        cat <<EOF >expected &&
-6a908c10688b2503073c39c9ba26322c73902bb5  (tag: refs/tags/tag2)
-9f716384d92283fb915a4eee5073f030638e05f9  (tag: refs/tags/message-one)
-b87e4cccdb77336ea79d89224737be7ea8e95367  (tag: refs/tags/message-two)
+$head1  (tag: refs/tags/tag2)
+$head2  (tag: refs/tags/message-one)
+$old_head1  (tag: refs/tags/message-two)
 EOF
        sort actual >actual1 &&
        test_cmp expected actual1
index 1cf0a4e10301fe1bbfb3acced0c010da7b8df7f8..899c1c5bbcb2e994a1462eb8048344b68d23767d 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"
@@ -123,7 +123,7 @@ 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` &&
+     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)'
@@ -164,7 +164,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 +173,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 +198,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 +207,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 +215,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 +244,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 +280,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..21a5c93f41e28845a540637eb11bd6eec830a063 100755 (executable)
@@ -97,15 +97,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 be951a46797c6b88d2a8d420cf160ea4f3ad71b0..a980574682012fbb3f5f7c28a011df980f45c3de 100755 (executable)
@@ -173,33 +173,6 @@ EOF
        )
 '
 
-if test -n "$NO_CURL" -o -z "$GIT_TEST_HTTPD"; then
-       say 'skipping remaining tests, git built without http support'
-       test_done
-fi
-
-LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5537'}
-. "$TEST_DIRECTORY"/lib-httpd.sh
-start_httpd
-
-test_expect_success 'clone http repository' '
-       git clone --bare --no-local shallow "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
-       git clone $HTTPD_URL/smart/repo.git clone &&
-       (
-       cd clone &&
-       git fsck &&
-       git log --format=%s origin/master >actual &&
-       cat <<EOF >expect &&
-7
-6
-5
-4
-3
-EOF
-       test_cmp expect actual
-       )
-'
-
 test_expect_success POSIXPERM,SANITY 'shallow fetch from a read-only repo' '
        cp -R .git read-only.git &&
        find read-only.git -print | xargs chmod -w &&
@@ -213,5 +186,4 @@ EOF
        test_cmp expect actual
 '
 
-stop_httpd
 test_done
index 8e54ac57462987567b11623d502ffc68fca3d9a0..ceee95b8a48455e15769168fe67af17deec7e179 100755 (executable)
@@ -120,63 +120,4 @@ EOF
        git cat-file blob `echo 1|git hash-object --stdin` >/dev/null
        )
 '
-
-if test -n "$NO_CURL" -o -z "$GIT_TEST_HTTPD"; then
-       say 'skipping remaining tests, git built without http support'
-       test_done
-fi
-
-. "$TEST_DIRECTORY"/lib-httpd.sh
-start_httpd
-
-test_expect_success 'push to shallow repo via http' '
-       git clone --bare --no-local shallow "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
-       (
-       cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
-       git config http.receivepack true
-       ) &&
-       (
-       cd full &&
-       commit 9 &&
-       git push $HTTPD_URL/smart/repo.git +master:refs/remotes/top/master
-       ) &&
-       (
-       cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
-       git fsck &&
-       git log --format=%s top/master >actual &&
-       cat <<EOF >expect &&
-9
-4
-3
-EOF
-       test_cmp expect actual
-       )
-'
-
-test_expect_success 'push from shallow repo via http' '
-       mv "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" shallow-upstream.git &&
-       git clone --bare --no-local full "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
-       (
-       cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
-       git config http.receivepack true
-       ) &&
-       commit 10 &&
-       git push $HTTPD_URL/smart/repo.git +master:refs/remotes/top/master &&
-       (
-       cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
-       git fsck &&
-       git log --format=%s top/master >actual &&
-       cat <<EOF >expect &&
-10
-1
-4
-3
-2
-1
-EOF
-       test_cmp expect actual
-       )
-'
-
-stop_httpd
 test_done
diff --git a/t/t5542-push-http-shallow.sh b/t/t5542-push-http-shallow.sh
new file mode 100755 (executable)
index 0000000..2a691e0
--- /dev/null
@@ -0,0 +1,100 @@
+#!/bin/sh
+
+test_description='push from/to a shallow clone over http'
+
+. ./test-lib.sh
+
+if test -n "$NO_CURL"; then
+       say 'skipping test, git built without http support'
+       test_done
+fi
+
+. "$TEST_DIRECTORY"/lib-httpd.sh
+start_httpd
+
+commit() {
+       echo "$1" >tracked &&
+       git add tracked &&
+       git commit -m "$1"
+}
+
+test_expect_success 'setup' '
+       git config --global transfer.fsckObjects true &&
+       commit 1 &&
+       commit 2 &&
+       commit 3 &&
+       commit 4 &&
+       git clone . full &&
+       (
+       git init full-abc &&
+       cd full-abc &&
+       commit a &&
+       commit b &&
+       commit c
+       ) &&
+       git clone --no-local --depth=2 .git shallow &&
+       git --git-dir=shallow/.git log --format=%s >actual &&
+       cat <<EOF >expect &&
+4
+3
+EOF
+       test_cmp expect actual &&
+       git clone --no-local --depth=2 full-abc/.git shallow2 &&
+       git --git-dir=shallow2/.git log --format=%s >actual &&
+       cat <<EOF >expect &&
+c
+b
+EOF
+       test_cmp expect actual
+'
+
+test_expect_success 'push to shallow repo via http' '
+       git clone --bare --no-local shallow "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
+       (
+       cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
+       git config http.receivepack true
+       ) &&
+       (
+       cd full &&
+       commit 9 &&
+       git push $HTTPD_URL/smart/repo.git +master:refs/remotes/top/master
+       ) &&
+       (
+       cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
+       git fsck &&
+       git log --format=%s top/master >actual &&
+       cat <<EOF >expect &&
+9
+4
+3
+EOF
+       test_cmp expect actual
+       )
+'
+
+test_expect_success 'push from shallow repo via http' '
+       mv "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" shallow-upstream.git &&
+       git clone --bare --no-local full "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
+       (
+       cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
+       git config http.receivepack true
+       ) &&
+       commit 10 &&
+       git push $HTTPD_URL/smart/repo.git +master:refs/remotes/top/master &&
+       (
+       cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
+       git fsck &&
+       git log --format=%s top/master >actual &&
+       cat <<EOF >expect &&
+10
+4
+3
+2
+1
+EOF
+       test_cmp expect actual
+       )
+'
+
+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 9d9d9de08e1926525c24fc01c1217a96964fa1ee..c277db64f75ac9f9c0cd617262824d76959fbfbd 100755 (executable)
@@ -9,19 +9,32 @@ test_description='git rev-list --pretty=format test'
 . "$TEST_DIRECTORY"/lib-terminal.sh
 
 test_tick
+# Tested non-UTF-8 encoding
+test_encoding="ISO8859-1"
+
 # String "added" in German
 # (translated with Google Translate),
 # encoded in UTF-8, used as a commit log message below.
-added=$(printf "added (hinzugef\303\274gt) foo")
-added_iso88591=$(echo "$added" | iconv -f utf-8 -t iso8859-1)
+added_utf8_part=$(printf "\303\274")
+added_utf8_part_iso88591=$(echo "$added_utf8_part" | iconv -f utf-8 -t $test_encoding)
+added=$(printf "added (hinzugef${added_utf8_part}gt) foo")
+added_iso88591=$(echo "$added" | iconv -f utf-8 -t $test_encoding)
 # same but "changed"
-changed=$(printf "changed (ge\303\244ndert) foo")
-changed_iso88591=$(echo "$changed" | iconv -f utf-8 -t iso8859-1)
+changed_utf8_part=$(printf "\303\244")
+changed_utf8_part_iso88591=$(echo "$changed_utf8_part" | iconv -f utf-8 -t $test_encoding)
+changed=$(printf "changed (ge${changed_utf8_part}ndert) foo")
+changed_iso88591=$(echo "$changed" | iconv -f utf-8 -t $test_encoding)
+
+# Count of char to truncate
+# Number is chosen so, that non-ACSII characters
+# (see $added_utf8_part and $changed_utf8_part)
+# fall into truncated parts of appropriate words both from left and right
+truncate_count=20
 
 test_expect_success 'setup' '
        : >foo &&
        git add foo &&
-       git config i18n.commitEncoding iso8859-1 &&
+       git config i18n.commitEncoding $test_encoding &&
        git commit -m "$added_iso88591" &&
        head1=$(git rev-parse --verify HEAD) &&
        head1_short=$(git rev-parse --verify --short $head1) &&
@@ -124,9 +137,9 @@ EOF
 
 test_format encoding %e <<EOF
 commit $head2
-iso8859-1
+$test_encoding
 commit $head1
-iso8859-1
+$test_encoding
 EOF
 
 test_format subject %s <<EOF
@@ -136,6 +149,13 @@ commit $head1
 $added
 EOF
 
+test_format subject-truncated "%<($truncate_count,trunc)%s" <<EOF
+commit $head2
+changed (ge${changed_utf8_part}ndert)..
+commit $head1
+added (hinzugef${added_utf8_part}gt..
+EOF
+
 test_format body %b <<EOF
 commit $head2
 commit $head1
@@ -203,16 +223,16 @@ test_expect_success '%C(auto) respects --color=auto (stdout not tty)' '
        )
 '
 
-iconv -f utf-8 -t iso8859-1 > commit-msg <<EOF
+iconv -f utf-8 -t $test_encoding > commit-msg <<EOF
 Test printing of complex bodies
 
 This commit message is much longer than the others,
-and it will be encoded in iso8859-1. We should therefore
-include an iso8859 character: ¡bueno!
+and it will be encoded in $test_encoding. We should therefore
+include an ISO8859 character: ¡bueno!
 EOF
 
 test_expect_success 'setup complex body' '
-       git config i18n.commitencoding iso8859-1 &&
+       git config i18n.commitencoding $test_encoding &&
        echo change2 >foo && git commit -a -F commit-msg &&
        head3=$(git rev-parse --verify HEAD) &&
        head3_short=$(git rev-parse --short $head3)
@@ -220,11 +240,11 @@ test_expect_success 'setup complex body' '
 
 test_format complex-encoding %e <<EOF
 commit $head3
-iso8859-1
+$test_encoding
 commit $head2
-iso8859-1
+$test_encoding
 commit $head1
-iso8859-1
+$test_encoding
 EOF
 
 test_format complex-subject %s <<EOF
@@ -236,20 +256,47 @@ commit $head1
 $added_iso88591
 EOF
 
+test_format complex-subject-trunc "%<($truncate_count,trunc)%s" <<EOF
+commit $head3
+Test printing of c..
+commit $head2
+changed (ge${changed_utf8_part_iso88591}ndert)..
+commit $head1
+added (hinzugef${added_utf8_part_iso88591}gt..
+EOF
+
+test_format complex-subject-mtrunc "%<($truncate_count,mtrunc)%s" <<EOF
+commit $head3
+Test prin..ex bodies
+commit $head2
+changed (..dert) foo
+commit $head1
+added (hi..f${added_utf8_part_iso88591}gt) foo
+EOF
+
+test_format complex-subject-ltrunc "%<($truncate_count,ltrunc)%s" <<EOF
+commit $head3
+.. of complex bodies
+commit $head2
+..ged (ge${changed_utf8_part_iso88591}ndert) foo
+commit $head1
+.. (hinzugef${added_utf8_part_iso88591}gt) foo
+EOF
+
 test_expect_success 'prepare expected messages (for test %b)' '
        cat <<-EOF >expected.utf-8 &&
        commit $head3
        This commit message is much longer than the others,
-       and it will be encoded in iso8859-1. We should therefore
-       include an iso8859 character: ¡bueno!
+       and it will be encoded in $test_encoding. We should therefore
+       include an ISO8859 character: ¡bueno!
 
        commit $head2
        commit $head1
        EOF
-       iconv -f utf-8 -t iso8859-1 expected.utf-8 >expected.iso8859-1
+       iconv -f utf-8 -t $test_encoding expected.utf-8 >expected.ISO8859-1
 '
 
-test_format complex-body %b <expected.iso8859-1
+test_format complex-body %b <expected.ISO8859-1
 
 # Git uses i18n.commitEncoding if no i18n.logOutputEncoding set
 # so unset i18n.commitEncoding to test encoding conversion
@@ -264,6 +311,33 @@ commit $head1
 $added
 EOF
 
+test_format complex-subject-commitencoding-unset-trunc "%<($truncate_count,trunc)%s" <<EOF
+commit $head3
+Test printing of c..
+commit $head2
+changed (ge${changed_utf8_part}ndert)..
+commit $head1
+added (hinzugef${added_utf8_part}gt..
+EOF
+
+test_format complex-subject-commitencoding-unset-mtrunc "%<($truncate_count,mtrunc)%s" <<EOF
+commit $head3
+Test prin..ex bodies
+commit $head2
+changed (..dert) foo
+commit $head1
+added (hi..f${added_utf8_part}gt) foo
+EOF
+
+test_format complex-subject-commitencoding-unset-ltrunc "%<($truncate_count,ltrunc)%s" <<EOF
+commit $head3
+.. of complex bodies
+commit $head2
+..ged (ge${changed_utf8_part}ndert) foo
+commit $head1
+.. (hinzugef${added_utf8_part}gt) foo
+EOF
+
 test_format complex-body-commitencoding-unset %b <expected.utf-8
 
 test_expect_success '%x00 shows NUL' '
diff --git a/t/t6039-merge-ignorecase.sh b/t/t6039-merge-ignorecase.sh
new file mode 100755 (executable)
index 0000000..a977653
--- /dev/null
@@ -0,0 +1,53 @@
+#!/bin/sh
+
+test_description='git-merge with case-changing rename on case-insensitive file system'
+
+. ./test-lib.sh
+
+if ! test_have_prereq CASE_INSENSITIVE_FS
+then
+       skip_all='skipping case insensitive tests - case sensitive file system'
+       test_done
+fi
+
+test_expect_success 'merge with case-changing rename' '
+       test $(git config core.ignorecase) = true &&
+       >TestCase &&
+       git add TestCase &&
+       git commit -m "add TestCase" &&
+       git tag baseline
+       git checkout -b with-camel &&
+       >foo &&
+       git add foo &&
+       git commit -m "intervening commit" &&
+       git checkout master &&
+       git rm TestCase &&
+       >testcase &&
+       git add testcase &&
+       git commit -m "rename to testcase" &&
+       git checkout with-camel &&
+       git merge master -m "merge" &&
+       test_path_is_file testcase
+'
+
+test_expect_success 'merge with case-changing rename on both sides' '
+       git checkout master &&
+       git reset --hard baseline &&
+       git branch -D with-camel &&
+       git checkout -b with-camel &&
+       git mv TestCase testcase &&
+       git commit -m "recase on branch" &&
+       >foo &&
+       git add foo &&
+       git commit -m "intervening commit" &&
+       git checkout master &&
+       git rm TestCase &&
+       >testcase &&
+       git add testcase &&
+       git commit -m "rename to testcase" &&
+       git checkout with-camel &&
+       git merge master -m "merge" &&
+       test_path_is_file testcase
+'
+
+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 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 e41fa00b80e9b3eb47e45be848397ccda0f47c53..1b824fe5ede3b933350696b78b6f53c1c69d0fff 100755 (executable)
@@ -24,7 +24,8 @@ test_expect_success 'set up a bit of history' '
        git tag -m "annotated tag" annotated &&
        git checkout -b side HEAD^^ &&
        test_commit side2 &&
-       test_commit side3
+       test_commit side3 &&
+       test_merge merge main3
 '
 
 test_expect_success 'showing two commits' '
@@ -109,8 +110,11 @@ test_expect_success 'showing range' '
 '
 
 test_expect_success '-s suppresses diff' '
-       echo main3 >expect &&
-       git show -s --format=%s main3 >actual &&
+       cat >expect <<-\EOF &&
+       merge
+       main3
+       EOF
+       git show -s --format=%s merge main3 >actual &&
        test_cmp expect actual
 '
 
index 450529404c686469ed5ba5ad465cf8b3ef651ef9..ee703bed64cc7572cb9a86fce2b0157026475709 100755 (executable)
@@ -22,6 +22,9 @@ commit_msg () {
        fi
 }
 
+# Tested non-UTF-8 encoding
+test_encoding="ISO8859-1"
+
 test_expect_success 'creating initial files and commits' '
        test_tick &&
        echo "1st file" >first &&
@@ -41,7 +44,7 @@ test_expect_success 'creating initial files and commits' '
 
        echo "1st line 2nd file" >secondfile &&
        echo "2nd line 2nd file" >>secondfile &&
-       git -c "i18n.commitEncoding=iso8859-1" commit -a -m "$(commit_msg iso8859-1)" &&
+       git -c "i18n.commitEncoding=$test_encoding" commit -a -m "$(commit_msg $test_encoding)" &&
        head5=$(git rev-parse --verify HEAD)
 '
 # git log --pretty=oneline # to see those SHA1 involved
@@ -64,10 +67,10 @@ test_expect_success 'reset --hard message' '
        test_cmp .expected .actual
 '
 
-test_expect_success 'reset --hard message (iso8859-1 logoutputencoding)' '
+test_expect_success 'reset --hard message (ISO8859-1 logoutputencoding)' '
        hex=$(git log -1 --format="%h") &&
-       git -c "i18n.logOutputEncoding=iso8859-1" reset --hard > .actual &&
-       echo HEAD is now at $hex $(commit_msg iso8859-1) > .expected &&
+       git -c "i18n.logOutputEncoding=$test_encoding" reset --hard > .actual &&
+       echo HEAD is now at $hex $(commit_msg $test_encoding) > .expected &&
        test_cmp .expected .actual
 '
 
@@ -331,7 +334,7 @@ test_expect_success 'redoing the last two commits should succeed' '
 
        echo "1st line 2nd file" >secondfile &&
        echo "2nd line 2nd file" >>secondfile &&
-       git -c "i18n.commitEncoding=iso8859-1" commit -a -m "$(commit_msg iso8859-1)" &&
+       git -c "i18n.commitEncoding=$test_encoding" commit -a -m "$(commit_msg $test_encoding)" &&
        check_changes $head5
 '
 
index 74de814aec1465848ba316e867106a18635139f6..04118ad75be8462fa2ee1e5e870feb0a44ac0482 100755 (executable)
@@ -426,10 +426,10 @@ test_expect_success SANITY 'removal failure' '
 
        mkdir foo &&
        touch foo/bar &&
+       test_when_finished "chmod 755 foo" &&
        (exec <foo/bar &&
         chmod 0 foo &&
-        test_must_fail git clean -f -d &&
-        chmod 755 foo)
+        test_must_fail git clean -f -d)
 '
 
 test_expect_success 'nested git work tree' '
index bdc1f295030b61fd6d4fc0ef672dffa99c027d8b..116885a260a56f94550ace2b541498a5e6f8e877 100755 (executable)
@@ -223,7 +223,8 @@ test_expect_success 'Commit without message is allowed with --allow-empty-messag
        git add foo &&
        >empty &&
        git commit --allow-empty-message <empty &&
-       commit_msg_is ""
+       commit_msg_is "" &&
+       git tag empty-message-commit
 '
 
 test_expect_success 'Commit without message is no-no without --allow-empty-message' '
@@ -240,6 +241,14 @@ test_expect_success 'Commit a message with --allow-empty-message' '
        commit_msg_is "hello there"
 '
 
+test_expect_success 'commit -C empty respects --allow-empty-message' '
+       echo more >>foo &&
+       git add foo &&
+       test_must_fail git commit -C empty-message-commit &&
+       git commit -C empty-message-commit --allow-empty-message &&
+       commit_msg_is ""
+'
+
 commit_for_rebase_autosquash_setup () {
        echo "first content line" >>foo &&
        git add foo &&
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 c987b5ed652b977cc2169bdd4c64f42eccdf63db..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" '
@@ -1380,7 +1379,32 @@ EOF
        test_i18ncmp expect output
 '
 
-test_expect_success '.gitmodules ignore=all suppresses submodule summary' '
+test_expect_success '.gitmodules ignore=all suppresses unstaged submodule summary' '
+       cat > expect << EOF &&
+On branch master
+Changes to be committed:
+  (use "git reset HEAD <file>..." to unstage)
+
+       modified:   sm
+
+Changes not staged for commit:
+  (use "git add <file>..." to update what will be committed)
+  (use "git checkout -- <file>..." to discard changes in working directory)
+
+       modified:   dir1/modified
+
+Untracked files:
+  (use "git add <file>..." to include in what will be committed)
+
+       .gitmodules
+       dir1/untracked
+       dir2/modified
+       dir2/untracked
+       expect
+       output
+       untracked
+
+EOF
        git config --add -f .gitmodules submodule.subname.ignore all &&
        git config --add -f .gitmodules submodule.subname.path sm &&
        git status > output &&
@@ -1388,7 +1412,7 @@ test_expect_success '.gitmodules ignore=all suppresses submodule summary' '
        git config -f .gitmodules  --remove-section submodule.subname
 '
 
-test_expect_success '.git/config ignore=all suppresses submodule summary' '
+test_expect_success '.git/config ignore=all suppresses unstaged submodule summary' '
        git config --add -f .gitmodules submodule.subname.ignore none &&
        git config --add -f .gitmodules submodule.subname.path sm &&
        git config --add submodule.subname.ignore all &&
@@ -1461,4 +1485,49 @@ test_expect_success 'Restore default test environment' '
        git config --unset status.showUntrackedFiles
 '
 
+test_expect_success 'git commit will commit a staged but ignored submodule' '
+       git config --add -f .gitmodules submodule.subname.ignore all &&
+       git config --add -f .gitmodules submodule.subname.path sm &&
+       git config --add submodule.subname.ignore all &&
+       git status -s --ignore-submodules=dirty >output &&
+       test_i18ngrep "^M. sm" output &&
+       GIT_EDITOR="echo hello >>\"\$1\"" &&
+       export GIT_EDITOR &&
+       git commit -uno &&
+       git status -s --ignore-submodules=dirty >output &&
+       test_i18ngrep ! "^M. sm" output
+'
+
+test_expect_success 'git commit --dry-run will show a staged but ignored submodule' '
+       git reset HEAD^ &&
+       git add sm &&
+       cat >expect << EOF &&
+On branch master
+Changes to be committed:
+  (use "git reset HEAD <file>..." to unstage)
+
+       modified:   sm
+
+Changes not staged for commit:
+  (use "git add <file>..." to update what will be committed)
+  (use "git checkout -- <file>..." to discard changes in working directory)
+
+       modified:   dir1/modified
+
+Untracked files not listed (use -u option to show untracked files)
+EOF
+       git commit -uno --dry-run >output &&
+       test_i18ncmp expect output &&
+       git status -s --ignore-submodules=dirty >output &&
+       test_i18ngrep "^M. sm" output
+'
+
+test_expect_success 'git commit -m will commit a staged but ignored submodule' '
+       git commit -uno -m message &&
+       git status -s --ignore-submodules=dirty >output &&
+        test_i18ngrep ! "^M. sm" output &&
+       git config --remove-section submodule.subname &&
+       git config -f .gitmodules  --remove-section submodule.subname
+'
+
 test_done
index 10aa028017833479c43bbb551741dfd36d9741aa..b16462132fd01f21cfd2af40a3c769803b0b7c50 100755 (executable)
@@ -57,11 +57,10 @@ create_merge_msgs () {
                git log --no-merges ^HEAD c2 c3
        } >squash.1-5-9 &&
        : >msg.nologff &&
-       echo >msg.nolognoff &&
+       : >msg.nolognoff &&
        {
                echo "* tag 'c3':" &&
-               echo "  commit 3" &&
-               echo
+               echo "  commit 3"
        } >msg.log
 }
 
@@ -71,7 +70,7 @@ verify_merge () {
        git diff --exit-code &&
        if test -n "$3"
        then
-               git show -s --pretty=format:%s HEAD >msg.act &&
+               git show -s --pretty=tformat:%s HEAD >msg.act &&
                test_cmp "$3" msg.act
        fi
 }
@@ -620,10 +619,10 @@ test_expect_success 'merge early part of c2' '
        git tag c6 &&
        git branch -f c5-branch c5 &&
        git merge c5-branch~1 &&
-       git show -s --pretty=format:%s HEAD >actual.branch &&
+       git show -s --pretty=tformat:%s HEAD >actual.branch &&
        git reset --keep HEAD^ &&
        git merge c5~1 &&
-       git show -s --pretty=format:%s HEAD >actual.tag &&
+       git show -s --pretty=tformat:%s HEAD >actual.tag &&
        test_cmp expected.branch actual.branch &&
        test_cmp expected.tag actual.tag
 '
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 e7cac1db55113188c7149686399292bded9c07dd..2a3469bcbea39e832ab44280bb1223fc4ee20b61 100755 (executable)
@@ -191,4 +191,13 @@ test_expect_success 'indent of line numbers, ten lines' '
        test $(grep -c "  " actual) = 9
 '
 
+test_expect_success 'blaming files with CRLF newlines' '
+       git config core.autocrlf false &&
+       printf "testcase\r\n" >crlffile &&
+       git add crlffile &&
+       git commit -m testcase &&
+       git -c core.autocrlf=input blame crlffile >actual &&
+       grep "A U Thor" actual
+'
+
 test_done
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 f7e55b1001f21774b9bab0107b68b59e45a9d79e..a4795373a6a2e1f247b3cef9880f2a82309b3594 100644 (file)
@@ -192,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)
@@ -367,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
@@ -453,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
                ;;
        *)
@@ -865,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 b468e4f88e730f88a1d231a574585ace56e7066a..84c616f180bebc730d05f306906558dd0abad2a4 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;
 
@@ -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 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..e9a05b908589a0fa8c446b1896821b77aa24596c 100644 (file)
@@ -622,17 +622,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
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
+)
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 0cc56368bd8ccef90ff643ce091cae25007eeee7..bc1bfb86003cb4133cc4ce3ce6423ce780ed7c84 100644 (file)
--- a/wrapper.c
+++ b/wrapper.c
@@ -174,6 +174,24 @@ ssize_t xwrite(int fd, const void *buf, size_t len)
        }
 }
 
+/*
+ * xpread() is the same as pread(), but it automatically restarts pread()
+ * operations with a recoverable error (EAGAIN and EINTR). xpread() DOES
+ * NOT GUARANTEE that "len" bytes is read even if the data is available.
+ */
+ssize_t xpread(int fd, void *buf, size_t len, off_t offset)
+{
+       ssize_t nr;
+       if (len > MAX_IO_SIZE)
+               len = MAX_IO_SIZE;
+       while (1) {
+               nr = pread(fd, buf, len, offset);
+               if ((nr < 0) && (errno == EAGAIN || errno == EINTR))
+                       continue;
+               return nr;
+       }
+}
+
 ssize_t read_in_full(int fd, void *buf, size_t count)
 {
        char *p = buf;
@@ -214,6 +232,26 @@ ssize_t write_in_full(int fd, const void *buf, size_t count)
        return total;
 }
 
+ssize_t pread_in_full(int fd, void *buf, size_t count, off_t offset)
+{
+       char *p = buf;
+       ssize_t total = 0;
+
+       while (count > 0) {
+               ssize_t loaded = xpread(fd, p, count, offset);
+               if (loaded < 0)
+                       return -1;
+               if (loaded == 0)
+                       return total;
+               count -= loaded;
+               p += loaded;
+               total += loaded;
+               offset += loaded;
+       }
+
+       return total;
+}
+
 int xdup(int fd)
 {
        int ret = dup(fd);
index ec7344e50834f18821692d7e38f634778d632080..318a191238fb831da8b72f04886b311f1c2c2567 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
@@ -519,9 +519,19 @@ static void wt_status_collect_changes_index(struct wt_status *s)
        opt.def = s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference;
        setup_revisions(0, NULL, &rev, &opt);
 
+       DIFF_OPT_SET(&rev.diffopt, OVERRIDE_SUBMODULE_CONFIG);
        if (s->ignore_submodule_arg) {
-               DIFF_OPT_SET(&rev.diffopt, OVERRIDE_SUBMODULE_CONFIG);
                handle_ignore_submodules_arg(&rev.diffopt, s->ignore_submodule_arg);
+       } else {
+               /*
+                * Unless the user did explicitly request a submodule ignore
+                * mode by passing a command line option we do not ignore any
+                * changed submodule SHA-1s when comparing index and HEAD, no
+                * matter what is configured. Otherwise the user won't be
+                * shown any submodules she manually added (and which are
+                * staged to be committed), which would be really confusing.
+                */
+               handle_ignore_submodules_arg(&rev.diffopt, "dirty");
        }
 
        rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK;
@@ -826,7 +836,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)
@@ -913,7 +923,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)
@@ -1329,7 +1339,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)
@@ -1342,9 +1352,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);
@@ -1361,7 +1371,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"