Sync with 2.4.2
authorJunio C Hamano <gitster@pobox.com>
Tue, 26 May 2015 20:50:39 +0000 (13:50 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 26 May 2015 20:50:51 +0000 (13:50 -0700)
195 files changed:
.gitignore
Documentation/RelNotes/2.5.0.txt [new file with mode: 0644]
Documentation/config.txt
Documentation/diff-generate-patch.txt
Documentation/diff-options.txt
Documentation/git-add.txt
Documentation/git-cat-file.txt
Documentation/git-checkout.txt
Documentation/git-commit.txt
Documentation/git-credential-store.txt
Documentation/git-fast-export.txt
Documentation/git-fast-import.txt
Documentation/git-fetch-pack.txt
Documentation/git-http-backend.txt
Documentation/git-merge.txt
Documentation/git-p4.txt
Documentation/git-pack-objects.txt
Documentation/git-prune.txt
Documentation/git-push.txt
Documentation/git-rebase.txt
Documentation/git-rev-list.txt
Documentation/git-rev-parse.txt
Documentation/git-send-pack.txt
Documentation/git-show.txt
Documentation/git-status.txt
Documentation/git-stripspace.txt
Documentation/git-svn.txt
Documentation/git-tag.txt
Documentation/git-unpack-objects.txt
Documentation/git-update-index.txt
Documentation/git-verify-pack.txt
Documentation/git.txt
Documentation/gitcore-tutorial.txt
Documentation/gitdiffcore.txt
Documentation/gitremote-helpers.txt
Documentation/gitrepository-layout.txt
Documentation/technical/index-format.txt
Documentation/technical/pack-protocol.txt
GIT-VERSION-GEN
Makefile
RelNotes
archive-zip.c
archive.c
attr.c
bisect.c
builtin/add.c
builtin/apply.c
builtin/blame.c
builtin/branch.c
builtin/bundle.c
builtin/cat-file.c
builtin/checkout-index.c
builtin/checkout.c
builtin/clone.c
builtin/commit.c
builtin/config.c
builtin/count-objects.c
builtin/fetch.c
builtin/fmt-merge-msg.c
builtin/fsck.c
builtin/gc.c
builtin/index-pack.c
builtin/init-db.c
builtin/merge.c
builtin/pack-objects.c
builtin/patch-id.c
builtin/prune.c
builtin/receive-pack.c
builtin/remote.c
builtin/repack.c
builtin/rev-parse.c
builtin/show-branch.c
builtin/update-index.c
bulk-checkin.c
cache.h
combine-diff.c
command-list.txt
commit.c
commit.h
compat/mingw.c
compat/mingw.h
config.c
config.mak.uname
connect.c
contrib/completion/git-completion.bash
contrib/subtree/git-subtree.sh
contrib/subtree/git-subtree.txt
convert.c
copy.c
credential-store.c
daemon.c
diff-lib.c
diff.h
dir.c
dir.h
environment.c
ewah/ewah_io.c
ewah/ewok.h
fast-import.c
git-am.sh
git-compat-util.h
git-cvsimport.perl
git-p4.py
git-pull.sh
git-rebase--interactive.sh
git-rebase--merge.sh
git-rebase.sh
git-sh-setup.sh
git-stash.sh
git.c
hex.c
http.c
lockfile.c
lockfile.h
log-tree.c
notes-merge.c
pack-bitmap.c
path.c
progress.c
read-cache.c
refs.c
refs.h
rerere.c
run-command.c
run-command.h
send-pack.c
setup.c
sha1_file.c
shallow.c
split-index.c
strbuf.c
strbuf.h
submodule.c
t/lib-git-p4.sh
t/lib-httpd.sh
t/t0008-ignores.sh
t/t0021-conversion.sh
t/t0027-auto-crlf.sh
t/t0060-path-utils.sh
t/t0302-credential-store.sh
t/t1006-cat-file.sh
t/t1020-subdirectory.sh
t/t1400-update-ref.sh
t/t1404-update-ref-df-conflicts.sh [new file with mode: 0755]
t/t1430-bad-ref-name.sh
t/t1501-worktree.sh
t/t1510-repo-setup.sh
t/t2025-checkout-to.sh [new file with mode: 0755]
t/t2026-prune-linked-checkouts.sh [new file with mode: 0755]
t/t2203-add-intent.sh
t/t3033-merge-toplevel.sh [new file with mode: 0755]
t/t3210-pack-refs.sh
t/t3402-rebase-merge.sh
t/t3404-rebase-interactive.sh
t/t3701-add-interactive.sh
t/t3702-add-edit.sh
t/t3904-stash-patch.sh
t/t4011-diff-symlink.sh
t/t4013/diff.log_--decorate=full_--all
t/t5520-pull.sh
t/t5524-pull-msg.sh
t/t5539-fetch-http-shallow.sh
t/t5541-http-push-smart.sh
t/t5542-push-http-shallow.sh
t/t5550-http-fetch-dumb.sh
t/t5551-http-fetch-smart.sh
t/t5561-http-backend.sh
t/t5601-clone.sh
t/t6020-merge-df.sh
t/t6021-merge-criss-cross.sh
t/t7004-tag.sh
t/t7063-status-untracked-cache.sh [new file with mode: 0755]
t/t7410-submodule-checkout-to.sh [new file with mode: 0755]
t/t7502-commit.sh
t/t7601-merge-pull-config.sh
t/t8003-blame-corner-cases.sh
t/t9402-git-cvsserver-refs.sh
t/t9801-git-p4-branch.sh
t/t9814-git-p4-rename.sh
t/t9816-git-p4-locked.sh
t/t9818-git-p4-block.sh [new file with mode: 0755]
t/t9819-git-p4-case-folding.sh [new file with mode: 0755]
t/t9902-completion.sh
t/test-lib-functions.sh
t/test-lib.sh
templates/hooks--applypatch-msg.sample
templates/hooks--pre-applypatch.sample
test-dump-untracked-cache.c [new file with mode: 0644]
trace.c
transport.c
tree-diff.c
unpack-trees.c
upload-pack.c
wrapper.c
wt-status.c
index a05241916c9c9a3760a6e98670a7f6427d553d77..422c5382c1acfde24223fda6236dd3586456a263 100644 (file)
 /test-delta
 /test-dump-cache-tree
 /test-dump-split-index
+/test-dump-untracked-cache
 /test-scrap-cache-tree
 /test-genrandom
 /test-hashmap
diff --git a/Documentation/RelNotes/2.5.0.txt b/Documentation/RelNotes/2.5.0.txt
new file mode 100644 (file)
index 0000000..3b2f628
--- /dev/null
@@ -0,0 +1,344 @@
+Git 2.5 Release Notes
+=====================
+
+Updates since v2.4
+------------------
+
+Ports
+
+
+UI, Workflows & Features
+
+ * "git p4" now detects the filetype (e.g. binary) correctly even when
+   the files are opened exclusively.
+
+ * git p4 attempts to better handle branches in Perforce.
+
+ * "git p4" learned "--changes-block-size <n>" to read the changes in
+   chunks from Perforce, instead of making one call to "p4 changes"
+   that may trigger "too many rows scanned" error from Perforce.
+
+ * "git show-branch --topics HEAD" (with no other arguments) did not
+   do anything interesting.  Instead, contrast the given revision
+   against all the local branches by default.
+
+ * A replacement for contrib/workdir/git-new-workdir that does not
+   rely on symbolic links and make sharing of objects and refs safer
+   by making the borrowee and borrowers aware of each other.
+
+ * Tweak the sample "store" backend of the credential helper to honor
+   XDG configuration file locations when specified.
+
+ * A heuristic to help the "git <cmd> <revs> <pathspec>" command line
+   convention to catch mistyped paths is to make sure all the non-rev
+   parameters in the later part of the command line are names of the
+   files in the working tree, but that means "git grep $str -- \*.c"
+   must always be disambiguated with "--", because nobody sane will
+   create a file whose name literally is asterisk-dot-see.  Loosen the
+   heuristic to declare that with a wildcard string the user likely
+   meant to give us a pathspec.
+
+ * "git merge FETCH_HEAD" learned that the previous "git fetch" could
+   be to create an Octopus merge, i.e. recording multiple branches
+   that are not marked as "not-for-merge"; this allows us to lose an
+   old style invocation "git merge <msg> HEAD $commits..." in the
+   implementation of "git pull" script; the old style syntax can now
+   be deprecated.
+
+ * Help us to find broken test script that splits the body part of the
+   test by mistaken use of wrong kind of quotes.
+   (merge d93d5d5 jc/test-prereq-validate later to maint).
+
+ * Developer support to automatically detect broken &&-chain in the
+   test scripts is now turned on by default.
+   (merge 92b269f jk/test-chain-lint later to maint).
+
+ * Filter scripts were run with SIGPIPE disabled on the Git side,
+   expecting that they may not read what Git feeds them to filter.
+   We however treated a filter that does not read its input fully
+   before exiting as an error.
+
+   This changes semantics, but arguably in a good way.  If a filter
+   can produce its output without consuming its input using whatever
+   magic, we now let it do so, instead of diagnosing it as a
+   programming error.
+
+ * Instead of dying immediately upon failing to obtain a lock, the
+   locking (of refs etc) retries after a short while with backoff.
+
+ * Introduce http.<url>.SSLCipherList configuration variable to tweak
+   the list of cipher suite to be used with libcURL when talking with
+   https:// sites.
+
+ * "git subtree" script (in contrib/) used "echo -n" to produce
+   progress messages in a non-portable way.
+
+ * "git subtree" script (in contrib/) does not have --squash option
+   when pushing, but the documentation and help text pretended as if
+   it did.
+
+ * The Git subcommand completion (in contrib/) listed credential
+   helpers among candidates, which is not something the end user would
+   invoke interactively.
+
+ * The index file can be taught with "update-index --untracked-cache"
+   to optionally remember already seen untracked files, in order to
+   speed up "git status" in a working tree with tons of cruft.
+
+
+Performance, Internal Implementation, Development Support etc.
+
+ * "unsigned char [20]" used throughout the code to represent object
+   names are being converted into a semi-opaque "struct object_id".
+   This effort is expected to interfere with other topics in flight,
+   but hopefully will give us one extra level of abstraction in the
+   end, when completed.
+
+ * Catch a programmer mistake to feed a pointer not an array to
+   ARRAY_SIZE() macro, by using a couple of GCC extensions.
+   (merge 89c855e ep/do-not-feed-a-pointer-to-array-size later to maint).
+
+ * Some error messages in "git config" were emitted without calling
+   the usual error() facility.
+
+ * When "add--interactive" splits a hunk into two overlapping hunks
+   and then let the user choose only one, it sometimes feeds an
+   incorrect patch text to "git apply".  Add tests to demonstrate
+   this.
+
+   I have a slight suspicion that this may be $gmane/87202 coming back
+   and biting us (I seem to have said "let's run with this and see
+   what happens" back then).
+
+ * More line-ending tests.
+
+ * An earlier rewrite to use strbuf_getwholeline() instead of fgets(3)
+   to read packed-refs file revealed that the former is unacceptably
+   inefficient.
+
+ * The refs API uses ref_lock struct which had its own "int fd", even
+   though the same file descriptor was in the lock struct it contains.
+   Clean-up the code to lose this redundant field.
+
+ * Add the "--allow-unknown-type" option to "cat-file" to allow
+   inspecting loose objects of an experimental or a broken type.
+
+ * Many long-running operations show progress eye-candy, even when
+   they are later backgrounded.  Hide the eye-candy when the process
+   is sent to the background instead.
+   (merge 9a9a41d lm/squelch-bg-progress later to maint).
+
+ * There was a dead code that used to handle "git pull --tags" and
+   show special-cased error message, which was made irrelevant when
+   the semantics of the option changed back in Git 1.9 days.
+   (merge 19d122b pt/pull-tags-error-diag later to maint).
+
+
+Also contains various documentation updates and code clean-ups.
+
+
+Fixes since v2.4
+----------------
+
+Unless otherwise noted, all the fixes since v2.4 in the maintenance
+track are contained in this release (see the maintenance releases'
+notes for details).
+
+ * Git 2.4 broke setting verbosity and progress levels on "git clone"
+   with native transports.
+   (merge 822f0c4 mh/clone-verbosity-fix later to maint).
+
+ * "git add -e" did not allow the user to abort the operation by
+   killing the editor.
+   (merge cb64800 jk/add-e-kill-editor later to maint).
+
+ * Memory usage of "git index-pack" has been trimmed by tens of
+   per-cent.
+   (merge c6458e6 nd/slim-index-pack-memory-usage later to maint).
+
+ * "git rev-list --objects $old --not --all" to see if everything that
+   is reachable from $old is already connected to the existing refs
+   was very inefficient.
+   (merge b6e8a3b jk/still-interesting later to maint).
+
+ * "hash-object --literally" introduced in v2.2 was not prepared to
+   take a really long object type name.
+   (merge 1427a7f jc/hash-object later to maint).
+
+ * "git rebase --quiet" was not quite quiet when there is nothing to
+   do.
+   (merge 22946a9 jk/rebase-quiet-noop later to maint).
+
+ * The completion for "log --decorate=" parameter value was incorrect.
+   (merge af16bda sg/complete-decorate-full-not-long later to maint).
+
+ * "filter-branch" corrupted commit log message that ends with an
+   incomplete line on platforms with some "sed" implementations that
+   munge such a line.  Work it around by avoiding to use "sed".
+   (merge df06201 jk/filter-branch-use-of-sed-on-incomplete-line later to maint).
+
+ * "git daemon" fails to build from the source under NO_IPV6
+   configuration (regression in 2.4).
+   (merge d358f77 jc/daemon-no-ipv6-for-2.4.1 later to maint).
+
+ * Some time ago, "git blame" (incorrectly) lost the convert_to_git()
+   call when synthesizing a fake "tip" commit that represents the
+   state in the working tree, which broke folks who record the history
+   with LF line ending to make their project portable across platforms
+   while terminating lines in their working tree files with CRLF for
+   their platform.
+   (merge 4bf256d tb/blame-resurrect-convert-to-git later to maint).
+
+ * We avoid setting core.worktree when the repository location is the
+   ".git" directory directly at the top level of the working tree, but
+   the code misdetected the case in which the working tree is at the
+   root level of the filesystem (which arguably is a silly thing to
+   do, but still valid).
+   (merge 84ccad8 jk/init-core-worktree-at-root later to maint).
+
+ * "git commit --date=now" or anything that relies on approxidate lost
+   the daylight-saving-time offset.
+   (merge f6e6362 jc/epochtime-wo-tz later to maint).
+
+ * Access to objects in repositories that borrow from another one on a
+   slow NFS server unnecessarily got more expensive due to recent code
+   becoming more cautious in a naive way not to lose objects to pruning.
+   (merge ee1c6c3 jk/prune-mtime later to maint).
+
+ * The codepaths that read .gitignore and .gitattributes files have been
+   taught that these files encoded in UTF-8 may have UTF-8 BOM marker at
+   the beginning; this makes it in line with what we do for configuration
+   files already.
+   (merge 27547e5 cn/bom-in-gitignore later to maint).
+
+ * a few helper scripts in the test suite did not report errors
+   correctly.
+   (merge de248e9 ep/fix-test-lib-functions-report later to maint).
+
+ * The default $HOME/.gitconfig file created upon "git config --global"
+   that edits it had incorrectly spelled user.name and user.email
+   entries in it.
+   (merge 7e11052 oh/fix-config-default-user-name-section later to maint).
+
+ * "git cat-file bl $blob" failed to barf even though there is no
+   object type that is "bl".
+   (merge b7994af jk/type-from-string-gently later to maint).
+
+ * The usual "git diff" when seeing a file turning into a directory
+   showed a patchset to remove the file and create all files in the
+   directory, but "git diff --no-index" simply refused to work.  Also,
+   when asked to compare a file and a directory, imitate POSIX "diff"
+   and compare the file with the file with the same name in the
+   directory, instead of refusing to run.
+   (merge 0615173 jc/diff-no-index-d-f later to maint).
+
+ * "git rebase -i" moved the "current" command from "todo" to "done" a
+   bit too prematurely, losing a step when a "pick" did not even start.
+   (merge 8cbc57c ph/rebase-i-redo later to maint).
+
+ * The connection initiation code for "ssh" transport tried to absorb
+   differences between the stock "ssh" and Putty-supplied "plink" and
+   its derivatives, but the logic to tell that we are using "plink"
+   variants were too loose and falsely triggered when "plink" appeared
+   anywhere in the path (e.g. "/home/me/bin/uplink/ssh").
+   (merge baaf233 bc/connect-plink later to maint).
+
+ * "git stash pop/apply" forgot to make sure that not just the working
+   tree is clean but also the index is clean. The latter is important
+   as a stash application can conflict and the index will be used for
+   conflict resolution.
+   (merge ed178ef jk/stash-require-clean-index later to maint).
+
+ * We have prepended $GIT_EXEC_PATH and the path "git" is installed in
+   (typically "/usr/bin") to $PATH when invoking subprograms and hooks
+   for almost eternity, but the original use case the latter tried to
+   support was semi-bogus (i.e. install git to /opt/foo/git and run it
+   without having /opt/foo on $PATH), and more importantly it has
+   become less and less relevant as Git grew more mainstream (i.e. the
+   users would _want_ to have it on their $PATH).  Stop prepending the
+   path in which "git" is installed to users' $PATH, as that would
+   interfere the command search order people depend on (e.g. they may
+   not like versions of programs that are unrelated to Git in /usr/bin
+   and want to override them by having different ones in /usr/local/bin
+   and have the latter directory earlier in their $PATH).
+   (merge a0b4507 jk/git-no-more-argv0-path-munging later to maint).
+
+ * core.excludesfile (defaulting to $XDG_HOME/git/ignore) is supposed
+   to be overridden by repository-specific .git/info/exclude file, but
+   the order was swapped from the beginning. This belatedly fixes it.
+   (merge 099d2d8 jc/gitignore-precedence later to maint).
+
+ * After "git add -N", the path appeared in output of "git diff HEAD"
+   and "git diff --cached HEAD", leading "git status" to classify it
+   as "Changes to be committed".  Such a path, however, is not yet to
+   be scheduled to be committed.  "git diff" showed the change to the
+   path as modification, not as a "new file", in the header of its
+   output.
+
+   Treat such paths as "yet to be added to the index but Git already
+   know about them"; "git diff HEAD" and "git diff --cached HEAD"
+   should not talk about them, and "git diff" should show them as new
+   files yet to be added to the index.
+   (merge d95d728 nd/diff-i-t-a later to maint).
+
+ * There was a commented-out (instead of being marked to expect
+   failure) test that documented a breakage that was fixed since the
+   test was written; turn it into a proper test.
+   (merge 66d2e04 sb/t1020-cleanup later to maint).
+
+ * The "log --decorate" enhancement in Git 2.4 that shows the commit
+   at the tip of the current branch e.g. "HEAD -> master", did not
+   work with --decorate=full.
+   (merge 429ad20 mg/log-decorate-HEAD later to maint).
+
+ * The ref API did not handle cases where 'refs/heads/xyzzy/frotz' is
+   removed at the same time as 'refs/heads/xyzzy' is added (or vice
+   versa) very well.
+   (merge c628edf mh/ref-directory-file later to maint).
+
+ * Multi-ref transaction support we merged a few releases ago
+   unnecessarily kept many file descriptors open, risking to fail with
+   resource exhaustion.  This is for 2.4.x track.
+   (merge 185ce3a mh/write-refs-sooner-2.4 later to maint).
+
+ * "git bundle verify" did not diagnose extra parameters on the
+   command line.
+   (merge 7886cfa ps/bundle-verify-arg later to maint).
+
+ * Various documentation mark-up fixes to make the output more
+   consistent in general and also make AsciiDoctor (an alternative
+   formatter) happier.
+   (merge d0258b9 jk/asciidoc-markup-fix later to maint).
+   (merge ad3967a jk/stripspace-asciidoctor-fix later to maint).
+   (merge 975e382 ja/tutorial-asciidoctor-fix later to maint).
+
+ * The code to read pack-bitmap wanted to allocate a few hundred
+   pointers to a structure, but by mistake allocated and leaked memory
+   enough to hold that many actual structures.  Correct the allocation
+   size and also have it on stack, as it is small enough.
+   (merge 599dc76 rs/plug-leak-in-pack-bitmaps later to maint).
+
+ * The pull.ff configuration was supposed to override the merge.ff
+   configuration, but it didn't.
+   (merge db9bb28 pt/pull-ff-vs-merge-ff later to maint).
+
+ * "git pull --log" and "git pull --no-log" worked as expected, but
+   "git pull --log=20" did not.
+   (merge 5061a44 pt/pull-log-n later to maint).
+
+ * "git rerere forget" in a repository without rerere enabled gave a
+   cryptic error message; it should be a silent no-op instead.
+   (merge 0544574 jk/rerere-forget-check-enabled later to maint).
+
+ * Code cleanups and documentation updates.
+   (merge 0269f96 mm/usage-log-l-can-take-regex later to maint).
+   (merge 64f2589 nd/t1509-chroot-test later to maint).
+   (merge f86a374 sb/test-bitmap-free-at-end later to maint).
+   (merge 05bfc7d sb/line-log-plug-pairdiff-leak later to maint).
+   (merge 846e5df pt/xdg-config-path later to maint).
+   (merge 1154aa4 jc/plug-fmt-merge-msg-leak later to maint).
+   (merge 319b678 jk/sha1-file-reduce-useless-warnings later to maint).
+   (merge 9a35c14 fg/document-commit-message-stripping later to maint).
+   (merge bbf431c ps/doc-packfile-vs-pack-file later to maint).
+   (merge 309a9e3 jk/skip-http-tests-under-no-curl later to maint).
+   (merge ccd593c dl/branch-error-message later to maint).
index 2e5ceaf71974b1e5404de79103648da1829eaf42..5f76e8cf4e5251d4bd414f9739247c752366070d 100644 (file)
@@ -453,6 +453,8 @@ false), while all other repositories are assumed to be bare (bare
 
 core.worktree::
        Set the path to the root of the working tree.
+       If GIT_COMMON_DIR environment variable is set, core.worktree
+       is ignored and not used for determining the root of working tree.
        This can be overridden by the GIT_WORK_TREE environment
        variable and the '--work-tree' command-line option.
        The value can be an absolute path or relative to the path to
@@ -622,6 +624,12 @@ core.commentChar::
 If set to "auto", `git-commit` would select a character that is not
 the beginning character of any line in existing commit messages.
 
+core.packedRefsTimeout::
+       The length of time, in milliseconds, to retry when trying to
+       lock the `packed-refs` file. Value 0 means not to retry at
+       all; -1 means to try indefinitely. Default is 1000 (i.e.,
+       retry for 1 second).
+
 sequence.editor::
        Text editor used by `git rebase -i` for editing the rebase instruction file.
        The value is meant to be interpreted by the shell when it is used.
@@ -1274,6 +1282,13 @@ gc.pruneExpire::
        "now" may be used to disable this  grace period and always prune
        unreachable objects immediately.
 
+gc.pruneWorktreesExpire::
+       When 'git gc' is run, it will call
+       'prune --worktrees --expire 3.months.ago'.
+       Override the grace period with this config variable. The value
+       "now" may be used to disable the grace period and prune
+       $GIT_DIR/worktrees immediately.
+
 gc.reflogExpire::
 gc.<pattern>.reflogExpire::
        'git reflog expire' removes reflog entries older than
@@ -1560,6 +1575,19 @@ http.saveCookies::
        If set, store cookies received during requests to the file specified by
        http.cookieFile. Has no effect if http.cookieFile is unset.
 
+http.sslCipherList::
+  A list of SSL ciphers to use when negotiating an SSL connection.
+  The available ciphers depend on whether libcurl was built against
+  NSS or OpenSSL and the particular configuration of the crypto
+  library in use.  Internally this sets the 'CURLOPT_SSL_CIPHER_LIST'
+  option; see the libcurl documentation for more details on the format
+  of this list.
++
+Can be overridden by the 'GIT_SSL_CIPHER_LIST' environment variable.
+To force git to use libcurl's default cipher list and ignore any
+explicit http.sslCipherList option, set 'GIT_SSL_CIPHER_LIST' to the
+empty string.
+
 http.sslVerify::
        Whether to verify the SSL certificate when fetching or pushing
        over HTTPS. Can be overridden by the 'GIT_SSL_NO_VERIFY' environment
@@ -2033,7 +2061,7 @@ pull.ff::
        a case (equivalent to giving the `--no-ff` option from the command
        line). When set to `only`, only such fast-forward merges are
        allowed (equivalent to giving the `--ff-only` option from the
-       command line).
+       command line). This setting overrides `merge.ff` when pulling.
 
 pull.rebase::
        When true, rebase branches on top of the fetched branch, instead
@@ -2270,18 +2298,18 @@ remote.<name>.skipFetchAll::
 
 remote.<name>.receivepack::
        The default program to execute on the remote side when pushing.  See
-       option \--receive-pack of linkgit:git-push[1].
+       option --receive-pack of linkgit:git-push[1].
 
 remote.<name>.uploadpack::
        The default program to execute on the remote side when fetching.  See
-       option \--upload-pack of linkgit:git-fetch-pack[1].
+       option --upload-pack of linkgit:git-fetch-pack[1].
 
 remote.<name>.tagOpt::
-       Setting this value to \--no-tags disables automatic tag following when
-       fetching from remote <name>. Setting it to \--tags will fetch every
+       Setting this value to --no-tags disables automatic tag following when
+       fetching from remote <name>. Setting it to --tags will fetch every
        tag from remote <name>, even if they are not reachable from remote
        branch heads. Passing these flags directly to linkgit:git-fetch[1] can
-       override this setting. See options \--tags and \--no-tags of
+       override this setting. See options --tags and --no-tags of
        linkgit:git-fetch[1].
 
 remote.<name>.vcs::
index 843a20bac2bb50916210fa8b055201bfcd1aabd9..bcf54da82a8c11367354a86efd8c802f58a6e502 100644 (file)
@@ -77,7 +77,7 @@ combined diff format
 Any diff-generating command can take the `-c` or `--cc` option to
 produce a 'combined diff' when showing a merge. This is the default
 format when showing merges with linkgit:git-diff[1] or
-linkgit:git-show[1]. Note also that you can give the `-m' option to any
+linkgit:git-show[1]. Note also that you can give the `-m` option to any
 of these commands to force generation of diffs with individual parents
 of a merge.
 
index ccd499867b64d0609df66196f833fff173dd60da..b7c3afeb3a0ce871d426de6912a6a875f37620fa 100644 (file)
@@ -23,7 +23,9 @@ ifndef::git-format-patch[]
 -u::
 --patch::
        Generate patch (see section on generating patches).
-       {git-diff? This is the default.}
+ifdef::git-diff[]
+       This is the default.
+endif::git-diff[]
 endif::git-format-patch[]
 
 -s::
@@ -42,7 +44,9 @@ endif::git-format-patch[]
 ifndef::git-format-patch[]
 --raw::
        Generate the raw format.
-       {git-diff-core? This is the default.}
+ifdef::git-diff-core[]
+       This is the default.
+endif::git-diff-core[]
 endif::git-format-patch[]
 
 ifndef::git-format-patch[]
index f2eb9076d73d830c19dc70bf2175e55a46ae1111..fe5282f1305902545eaff585ced432d296dd64f4 100644 (file)
@@ -93,7 +93,8 @@ This effectively runs `add --interactive`, but bypasses the
 initial command menu and directly jumps to the `patch` subcommand.
 See ``Interactive mode'' for details.
 
--e, \--edit::
+-e::
+--edit::
        Open the diff vs. the index in an editor and let the user
        edit it.  After the editor was closed, adjust the hunk headers
        and apply the patch to the index.
index f6a16f4300b15669a518faa3d8a63d7586233258..499ae7b98a4d9bf48aa2c5a235608dfcffcc1c10 100644 (file)
@@ -9,7 +9,7 @@ git-cat-file - Provide content or type and size information for repository objec
 SYNOPSIS
 --------
 [verse]
-'git cat-file' (-t | -s | -e | -p | <type> | --textconv ) <object>
+'git cat-file' (-t [--allow-unknown-type]| -s [--allow-unknown-type]| -e | -p | <type> | --textconv ) <object>
 'git cat-file' (--batch | --batch-check) < <list-of-objects>
 
 DESCRIPTION
@@ -69,6 +69,9 @@ OPTIONS
        not be combined with any other options or arguments.  See the
        section `BATCH OUTPUT` below for details.
 
+--allow-unknown-type::
+       Allow -s or -t to query broken/corrupt objects of unknown type.
+
 OUTPUT
 ------
 If '-t' is specified, one of the <type>.
index d5041082e88349d7c814ae1c036b15841f47a6d0..d263a5652f06777b987eefae4f14f2003d53448b 100644 (file)
@@ -225,6 +225,19 @@ This means that you can use `git checkout -p` to selectively discard
 edits from your current working tree. See the ``Interactive Mode''
 section of linkgit:git-add[1] to learn how to operate the `--patch` mode.
 
+--to=<path>::
+       Check out a branch in a separate working directory at
+       `<path>`. A new working directory is linked to the current
+       repository, sharing everything except working directory
+       specific files such as HEAD, index... See "MULTIPLE WORKING
+       TREES" section for more information.
+
+--ignore-other-worktrees::
+       `git checkout` refuses when the wanted ref is already checked
+       out by another worktree. This option makes it check the ref
+       out anyway. In other words, the ref can be held by more than one
+       worktree.
+
 <branch>::
        Branch to checkout; if it refers to a branch (i.e., a name that,
        when prepended with "refs/heads/", is a valid ref), then that
@@ -388,6 +401,71 @@ $ git reflog -2 HEAD # or
 $ git log -g -2 HEAD
 ------------
 
+MULTIPLE WORKING TREES
+----------------------
+
+A git repository can support multiple working trees, allowing you to check
+out more than one branch at a time.  With `git checkout --to` a new working
+tree is associated with the repository.  This new working tree is called a
+"linked working tree" as opposed to the "main working tree" prepared by "git
+init" or "git clone".  A repository has one main working tree (if it's not a
+bare repository) and zero or more linked working trees.
+
+Each linked working tree has a private sub-directory in the repository's
+$GIT_DIR/worktrees directory.  The private sub-directory's name is usually
+the base name of the linked working tree's path, possibly appended with a
+number to make it unique.  For example, when `$GIT_DIR=/path/main/.git` the
+command `git checkout --to /path/other/test-next next` creates the linked
+working tree in `/path/other/test-next` and also creates a
+`$GIT_DIR/worktrees/test-next` directory (or `$GIT_DIR/worktrees/test-next1`
+if `test-next` is already taken).
+
+Within a linked working tree, $GIT_DIR is set to point to this private
+directory (e.g. `/path/main/.git/worktrees/test-next` in the example) and
+$GIT_COMMON_DIR is set to point back to the main working tree's $GIT_DIR
+(e.g. `/path/main/.git`). These settings are made in a `.git` file located at
+the top directory of the linked working tree.
+
+Path resolution via `git rev-parse --git-path` uses either
+$GIT_DIR or $GIT_COMMON_DIR depending on the path. For example, in the
+linked working tree `git rev-parse --git-path HEAD` returns
+`/path/main/.git/worktrees/test-next/HEAD` (not
+`/path/other/test-next/.git/HEAD` or `/path/main/.git/HEAD`) while `git
+rev-parse --git-path refs/heads/master` uses
+$GIT_COMMON_DIR and returns `/path/main/.git/refs/heads/master`,
+since refs are shared across all working trees.
+
+See linkgit:gitrepository-layout[5] for more information. The rule of
+thumb is do not make any assumption about whether a path belongs to
+$GIT_DIR or $GIT_COMMON_DIR when you need to directly access something
+inside $GIT_DIR. Use `git rev-parse --git-path` to get the final path.
+
+When you are done with a linked working tree you can simply delete it.
+The working tree's entry in the repository's $GIT_DIR/worktrees
+directory will eventually be removed automatically (see
+`gc.pruneworktreesexpire` in linkgit::git-config[1]), or you can run
+`git prune --worktrees` in the main or any linked working tree to
+clean up any stale entries in $GIT_DIR/worktrees.
+
+If you move a linked working directory to another file system, or
+within a file system that does not support hard links, you need to run
+at least one git command inside the linked working directory
+(e.g. `git status`) in order to update its entry in $GIT_DIR/worktrees
+so that it does not get automatically removed.
+
+To prevent a $GIT_DIR/worktrees entry from from being pruned (which
+can be useful in some situations, such as when the
+entry's working tree is stored on a portable device), add a file named
+'locked' to the entry's directory. The file contains the reason in
+plain text. For example, if a linked working tree's `.git` file points
+to `/path/main/.git/worktrees/test-next` then a file named
+`/path/main/.git/worktrees/test-next/locked` will prevent the
+`test-next` entry from being pruned.  See
+linkgit:gitrepository-layout[5] for details.
+
+Multiple checkout support for submodules is incomplete. It is NOT
+recommended to make multiple checkouts of a superproject.
+
 EXAMPLES
 --------
 
index 617e29b38b337a40d8aede609d9d979c1b3aac02..617dea083e273467f50493dacd3d859ebbe52aff 100644 (file)
@@ -180,8 +180,8 @@ OPTIONS
 +
 --
 strip::
-       Strip leading and trailing empty lines, trailing whitespace, and
-       #commentary and collapse consecutive empty lines.
+       Strip leading and trailing empty lines, trailing whitespace,
+       commentary and collapse consecutive empty lines.
 whitespace::
        Same as `strip` except #commentary is not removed.
 verbatim::
@@ -282,8 +282,11 @@ configuration variable documented in linkgit:git-config[1].
 --verbose::
        Show unified diff between the HEAD commit and what
        would be committed at the bottom of the commit message
-       template.  Note that this diff output doesn't have its
-       lines prefixed with '#'.
+       template to help the user describe the commit by reminding
+       what changes the commit has.
+       Note that this diff output doesn't have its
+       lines prefixed with '#'. This diff will not be a part
+       of the commit message.
 +
 If specified twice, show in addition the unified diff between
 what would be committed and the worktree files, i.e. the unstaged
index bc97071e7668ac48d07065190e88d1ce74822041..e3c8f276b14ed188284536636d259974f46d755e 100644 (file)
@@ -31,10 +31,41 @@ OPTIONS
 
 --file=<path>::
 
-       Use `<path>` to store credentials. The file will have its
+       Use `<path>` to lookup and store credentials. The file will have its
        filesystem permissions set to prevent other users on the system
        from reading it, but will not be encrypted or otherwise
-       protected. Defaults to `~/.git-credentials`.
+       protected. If not specified, credentials will be searched for from
+       `~/.git-credentials` and `$XDG_CONFIG_HOME/git/credentials`, and
+       credentials will be written to `~/.git-credentials` if it exists, or
+       `$XDG_CONFIG_HOME/git/credentials` if it exists and the former does
+       not. See also <<FILES>>.
+
+[[FILES]]
+FILES
+-----
+
+If not set explicitly with '--file', there are two files where
+git-credential-store will search for credentials in order of precedence:
+
+~/.git-credentials::
+       User-specific credentials file.
+
+$XDG_CONFIG_HOME/git/credentials::
+       Second user-specific credentials file. If '$XDG_CONFIG_HOME' is not set
+       or empty, `$HOME/.config/git/credentials` will be used. Any credentials
+       stored in this file will not be used if `~/.git-credentials` has a
+       matching credential as well. It is a good idea not to create this file
+       if you sometimes use older versions of Git that do not support it.
+
+For credential lookups, the files are read in the order given above, with the
+first matching credential found taking precedence over credentials found in
+files further down the list.
+
+Credential storage will by default write to the first existing file in the
+list. If none of these files exist, `~/.git-credentials` will be created and
+written to.
+
+When erasing credentials, matching credentials will be erased from all files.
 
 EXAMPLES
 --------
index 929e496af8d6b93904cb91d2148272516dd92033..ed57c684dbc82c587ca1cf6b66ae46f3760ecfba 100644 (file)
@@ -67,17 +67,17 @@ produced incorrect results if you gave these options.
        have been completed, or to save the marks table across
        incremental runs.  As <file> is only opened and truncated
        at completion, the same path can also be safely given to
-       \--import-marks.
+       --import-marks.
        The file will not be written if no new object has been
        marked/exported.
 
 --import-marks=<file>::
        Before processing any input, load the marks specified in
        <file>.  The input file must exist, must be readable, and
-       must use the same format as produced by \--export-marks.
+       must use the same format as produced by --export-marks.
 +
 Any commits that have already been marked will not be exported again.
-If the backend uses a similar \--import-marks file, this allows for
+If the backend uses a similar --import-marks file, this allows for
 incremental bidirectional exporting of the repository by keeping the
 marks the same across runs.
 
index 690fed3ea40d3de73a2b6f1c194216b72738da8f..fd328952556fc8a28db72e6537595067aadbd946 100644 (file)
@@ -42,13 +42,13 @@ OPTIONS
 --quiet::
        Disable all non-fatal output, making fast-import silent when it
        is successful.  This option disables the output shown by
-       \--stats.
+       --stats.
 
 --stats::
        Display some basic statistics about the objects fast-import has
        created, the packfiles they were stored into, and the
        memory used by fast-import during this run.  Showing this output
-       is currently the default, but can be disabled with \--quiet.
+       is currently the default, but can be disabled with --quiet.
 
 Options for Frontends
 ~~~~~~~~~~~~~~~~~~~~~
@@ -81,12 +81,12 @@ Locations of Marks Files
        have been completed, or to save the marks table across
        incremental runs.  As <file> is only opened and truncated
        at checkpoint (or completion) the same path can also be
-       safely given to \--import-marks.
+       safely given to --import-marks.
 
 --import-marks=<file>::
        Before processing any input, load the marks specified in
        <file>.  The input file must exist, must be readable, and
-       must use the same format as produced by \--export-marks.
+       must use the same format as produced by --export-marks.
        Multiple options may be supplied to import more than one
        set of marks.  If a mark is defined to different values,
        the last file wins.
@@ -179,8 +179,8 @@ fast-forward update, fast-import will skip updating that ref and instead
 prints a warning message.  fast-import will always attempt to update all
 branch refs, and does not stop on the first failure.
 
-Branch updates can be forced with \--force, but it's recommended that
-this only be used on an otherwise quiet repository.  Using \--force
+Branch updates can be forced with --force, but it's recommended that
+this only be used on an otherwise quiet repository.  Using --force
 is not necessary for an initial import into an empty repository.
 
 
@@ -231,11 +231,11 @@ 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>`.
-       It is also fast-import's default format, if \--date-format was
+       It is also fast-import's default format, if --date-format was
        not specified.
 +
 The time of the event is specified by `<time>` as the number of
@@ -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.
 
@@ -600,7 +600,7 @@ be removed from the branch.
 See `filemodify` above for a detailed description of `<path>`.
 
 `filecopy`
-^^^^^^^^^^^^
+^^^^^^^^^^
 Recursively copies an existing file or subdirectory to a different
 location within the branch.  The existing file or directory must
 exist.  If the destination exists it will be completely replaced
@@ -888,7 +888,7 @@ save out all current branch refs, tags and marks.
 ....
 
 Note that fast-import automatically switches packfiles when the current
-packfile reaches \--max-pack-size, or 4 GiB, whichever limit is
+packfile reaches --max-pack-size, or 4 GiB, whichever limit is
 smaller.  During an automatic packfile switch fast-import does not update
 the branch refs, tags or marks.
 
@@ -1226,7 +1226,7 @@ users of fast-import, and are offered here as suggestions.
 Use One Mark Per Commit
 ~~~~~~~~~~~~~~~~~~~~~~~
 When doing a repository conversion, use a unique mark per commit
-(`mark :<n>`) and supply the \--export-marks option on the command
+(`mark :<n>`) and supply the --export-marks option on the command
 line.  fast-import will dump a file which lists every mark and the Git
 object SHA-1 that corresponds to it.  If the frontend can tie
 the marks back to the source repository, it is easy to verify the
@@ -1291,7 +1291,7 @@ even for considerably large projects (100,000+ commits).
 
 However repacking the repository is necessary to improve data
 locality and access performance.  It can also take hours on extremely
-large projects (especially if -f and a large \--window parameter is
+large projects (especially if -f and a large --window parameter is
 used).  Since repacking is safe to run alongside readers and writers,
 run the repack in the background and let it finish when it finishes.
 There is no reason to wait to explore your new Git project!
@@ -1305,7 +1305,7 @@ Repacking Historical Data
 ~~~~~~~~~~~~~~~~~~~~~~~~~
 If you are repacking very old imported data (e.g. older than the
 last year), consider expending some extra CPU time and supplying
-\--window=50 (or higher) when you run 'git repack'.
+--window=50 (or higher) when you run 'git repack'.
 This will take longer, but will also produce a smaller packfile.
 You only need to expend the effort once, and everyone using your
 project will benefit from the smaller repository.
@@ -1407,7 +1407,7 @@ branch, their in-memory storage size can grow to a considerable size
 fast-import automatically moves active branches to inactive status based on
 a simple least-recently-used algorithm.  The LRU chain is updated on
 each `commit` command.  The maximum number of active branches can be
-increased or decreased on the command line with \--active-branches=.
+increased or decreased on the command line with --active-branches=.
 
 per active tree
 ~~~~~~~~~~~~~~~
index 93b50679461a201badf62afe5ed3931bbdfa88e5..8680f45f8d635253576499453588308618afdc5f 100644 (file)
@@ -80,7 +80,7 @@ be in a separate packet, and the list must end with a flush packet.
        the things up in .bash_profile).
 
 --exec=<git-upload-pack>::
-       Same as \--upload-pack=<git-upload-pack>.
+       Same as --upload-pack=<git-upload-pack>.
 
 --depth=<n>::
        Limit fetching to ancestor-chains not longer than n.
index d422ba4b59acf31151f149c8067c18e541e5bdb2..3ca18c4de519ebdf0a2af6509d0d6bed3e6e492c 100644 (file)
@@ -65,8 +65,8 @@ automatically by the web server.
 
 EXAMPLES
 --------
-All of the following examples map 'http://$hostname/git/foo/bar.git'
-to '/var/www/git/foo/bar.git'.
+All of the following examples map `http://$hostname/git/foo/bar.git`
+to `/var/www/git/foo/bar.git`.
 
 Apache 2.x::
        Ensure mod_cgi, mod_alias, and mod_env are enabled, set
index 1f94908e3c0a803c32eb2392ef4dc8158c6e1c53..273a1009be002e64ee83e1835bdd1c3e1e84f526 100644 (file)
@@ -104,6 +104,10 @@ commit or stash your changes before running 'git merge'.
 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.
++
+When `FETCH_HEAD` (and no other commit) is specified, the branches
+recorded in the `.git/FETCH_HEAD` file by the previous invocation
+of `git fetch` for merging are merged to the current branch.
 
 
 PRE-MERGE CHECKS
index a1664b9f684bae0d3e715b36760ce62f4745ed06..82aa5d60736ccc75510c19ddec2da9eb4c5611a8 100644 (file)
@@ -225,9 +225,20 @@ Git repository:
        they can find the p4 branches in refs/heads.
 
 --max-changes <n>::
-       Limit the number of imported changes to 'n'.  Useful to
-       limit the amount of history when using the '@all' p4 revision
-       specifier.
+       Import at most 'n' changes, rather than the entire range of
+       changes included in the given revision specifier. A typical
+       usage would be use '@all' as the revision specifier, but then
+       to use '--max-changes 1000' to import only the last 1000
+       revisions rather than the entire revision history.
+
+--changes-block-size <n>::
+       The internal block size to use when converting a revision
+       specifier such as '@all' into a list of specific change
+       numbers. Instead of using a single call to 'p4 changes' to
+       find the full list of changes for the conversion, there are a
+       sequence of calls to 'p4 changes -m', each of which requests
+       one block of changes of the given size. The default block size
+       is 500, which should usually be suitable.
 
 --keep-path::
        The mapping of file names from the p4 depot path to Git, by
index c2f76fb1ea476aa551963349ee976ad8745f10e2..bbea5294ca9680dd7efee9caeea861711dafc3a5 100644 (file)
@@ -192,7 +192,7 @@ self-contained. Use `git index-pack --fix-thin`
 
 --shallow::
        Optimize a pack that will be provided to a client with a shallow
-       repository.  This option, combined with \--thin, can result in a
+       repository.  This option, combined with --thin, can result in a
        smaller pack at the cost of speed.
 
 --delta-base-offset::
index 7a493c80f776092265abd4fb2575639e683bcf5c..1cf3bed4ab7ab19364c6801fbc73920170dfd1e4 100644 (file)
@@ -48,6 +48,9 @@ OPTIONS
 --expire <time>::
        Only expire loose objects older than <time>.
 
+--worktrees::
+       Prune dead working tree information in $GIT_DIR/worktrees.
+
 <head>...::
        In addition to objects
        reachable from any of our references, keep objects
index 863c30c4c2d0fd78ee81d219ed221cb248ce1994..135d810b7a9b7e36d1cb06ca49c185655a655bee 100644 (file)
@@ -265,8 +265,8 @@ origin +master` to force a push to the `master` branch). See the
 
 --[no-]verify::
        Toggle the pre-push hook (see linkgit:githooks[5]).  The
-       default is \--verify, giving the hook a chance to prevent the
-       push.  With \--no-verify, the hook is bypassed completely.
+       default is --verify, giving the hook a chance to prevent the
+       push.  With --no-verify, the hook is bypassed completely.
 
 
 include::urls-remotes.txt[]
index 47984e84ed2f994ec48c1d659e47c1ecd6a17f23..1d01baa5fcfd03370953e8311b9c7bf3b49e2f4e 100644 (file)
@@ -80,7 +80,7 @@ remain the checked-out branch.
 If the upstream branch already contains a change you have made (e.g.,
 because you mailed a patch which was applied upstream), then that commit
 will be skipped. For example, running `git rebase master` on the
-following history (in which A' and A introduce the same set of changes,
+following history (in which `A'` and `A` introduce the same set of changes,
 but have different committer information):
 
 ------------
index 5b119220bf168153d63bf2051a065e40b68c1ed3..b10ea60833ca67ca1d3c5bd413958980405575d4 100644 (file)
@@ -9,54 +9,54 @@ git-rev-list - Lists commit objects in reverse chronological order
 SYNOPSIS
 --------
 [verse]
-'git rev-list' [ \--max-count=<number> ]
-            [ \--skip=<number> ]
-            [ \--max-age=<timestamp> ]
-            [ \--min-age=<timestamp> ]
-            [ \--sparse ]
-            [ \--merges ]
-            [ \--no-merges ]
-            [ \--min-parents=<number> ]
-            [ \--no-min-parents ]
-            [ \--max-parents=<number> ]
-            [ \--no-max-parents ]
-            [ \--first-parent ]
-            [ \--remove-empty ]
-            [ \--full-history ]
-            [ \--not ]
-            [ \--all ]
-            [ \--branches[=<pattern>] ]
-            [ \--tags[=<pattern>] ]
-            [ \--remotes[=<pattern>] ]
-            [ \--glob=<glob-pattern> ]
-            [ \--ignore-missing ]
-            [ \--stdin ]
-            [ \--quiet ]
-            [ \--topo-order ]
-            [ \--parents ]
-            [ \--timestamp ]
-            [ \--left-right ]
-            [ \--left-only ]
-            [ \--right-only ]
-            [ \--cherry-mark ]
-            [ \--cherry-pick ]
-            [ \--encoding=<encoding> ]
-            [ \--(author|committer|grep)=<pattern> ]
-            [ \--regexp-ignore-case | -i ]
-            [ \--extended-regexp | -E ]
-            [ \--fixed-strings | -F ]
-            [ \--date=(local|relative|default|iso|iso-strict|rfc|short) ]
-            [ [ \--objects | \--objects-edge | \--objects-edge-aggressive ]
-              [ \--unpacked ] ]
-            [ \--pretty | \--header ]
-            [ \--bisect ]
-            [ \--bisect-vars ]
-            [ \--bisect-all ]
-            [ \--merge ]
-            [ \--reverse ]
-            [ \--walk-reflogs ]
-            [ \--no-walk ] [ \--do-walk ]
-            [ \--use-bitmap-index ]
+'git rev-list' [ --max-count=<number> ]
+            [ --skip=<number> ]
+            [ --max-age=<timestamp> ]
+            [ --min-age=<timestamp> ]
+            [ --sparse ]
+            [ --merges ]
+            [ --no-merges ]
+            [ --min-parents=<number> ]
+            [ --no-min-parents ]
+            [ --max-parents=<number> ]
+            [ --no-max-parents ]
+            [ --first-parent ]
+            [ --remove-empty ]
+            [ --full-history ]
+            [ --not ]
+            [ --all ]
+            [ --branches[=<pattern>] ]
+            [ --tags[=<pattern>] ]
+            [ --remotes[=<pattern>] ]
+            [ --glob=<glob-pattern> ]
+            [ --ignore-missing ]
+            [ --stdin ]
+            [ --quiet ]
+            [ --topo-order ]
+            [ --parents ]
+            [ --timestamp ]
+            [ --left-right ]
+            [ --left-only ]
+            [ --right-only ]
+            [ --cherry-mark ]
+            [ --cherry-pick ]
+            [ --encoding=<encoding> ]
+            [ --(author|committer|grep)=<pattern> ]
+            [ --regexp-ignore-case | -i ]
+            [ --extended-regexp | -E ]
+            [ --fixed-strings | -F ]
+            [ --date=(local|relative|default|iso|iso-strict|rfc|short) ]
+            [ [ --objects | --objects-edge | --objects-edge-aggressive ]
+              [ --unpacked ] ]
+            [ --pretty | --header ]
+            [ --bisect ]
+            [ --bisect-vars ]
+            [ --bisect-all ]
+            [ --merge ]
+            [ --reverse ]
+            [ --walk-reflogs ]
+            [ --no-walk ] [ --do-walk ]
+            [ --use-bitmap-index ]
             <commit>... [ \-- <paths>... ]
 
 DESCRIPTION
index d6de42f74efeedda228a97746c123de6e3e1f0ab..c483100e75886e7326cecabcd66f1449e640365a 100644 (file)
@@ -102,7 +102,7 @@ eval "set -- $(git rev-parse --sq --prefix "$prefix" "$@")"
 +
 If you want to make sure that the output actually names an object in
 your object database and/or can be used as a specific type of object
-you require, you can add "\^{type}" peeling operator to the parameter.
+you require, you can add the `^{type}` peeling operator to the parameter.
 For example, `git rev-parse "$VAR^{commit}"` will make sure `$VAR`
 names an existing object that is a commit-ish (i.e. a commit, or an
 annotated tag that points at a commit).  To make sure that `$VAR`
@@ -147,7 +147,7 @@ can be used.
        form as close to the original input as possible.
 
 --symbolic-full-name::
-       This is similar to \--symbolic, but it omits input that
+       This is similar to --symbolic, but it omits input that
        are not refs (i.e. branch or tag names; or more
        explicitly disambiguating "heads/master" form, when you
        want to name the "master" branch when there is an
@@ -216,6 +216,9 @@ If `$GIT_DIR` is not defined and the current directory
 is not detected to lie in a Git repository or work tree
 print a message to stderr and exit with nonzero status.
 
+--git-common-dir::
+       Show `$GIT_COMMON_DIR` if defined, else `$GIT_DIR`.
+
 --is-inside-git-dir::
        When the current working directory is below the repository
        directory print "true", otherwise "false".
@@ -233,6 +236,13 @@ print a message to stderr and exit with nonzero status.
        repository.  If <path> is a gitfile then the resolved path
        to the real repository is printed.
 
+--git-path <path>::
+       Resolve "$GIT_DIR/<path>" and takes other path relocation
+       variables such as $GIT_OBJECT_DIRECTORY,
+       $GIT_INDEX_FILE... into account. For example, if
+       $GIT_OBJECT_DIRECTORY is set to /foo/bar then "git rev-parse
+       --git-path objects/abc" returns /foo/bar/abc.
+
 --show-cdup::
        When the command is invoked from a subdirectory, show the
        path of the top-level directory relative to the current
index 45c7725dc303eed198fc0ed370f603a71d1fa8c1..b5d09f79ee686d20b6e99196202546eac1ce2635 100644 (file)
@@ -29,7 +29,7 @@ OPTIONS
        a directory on the default $PATH.
 
 --exec=<git-receive-pack>::
-       Same as \--receive-pack=<git-receive-pack>.
+       Same as --receive-pack=<git-receive-pack>.
 
 --all::
        Instead of explicitly specifying which refs to update,
index 4e617e6979dda86138e14cb93d84016d304de07a..82a4125a2da805e0b3c21e4e827bf203d5ac4532 100644 (file)
@@ -22,7 +22,7 @@ presents the merge commit in a special format as produced by
 For tags, it shows the tag message and the referenced objects.
 
 For trees, it shows the names (equivalent to 'git ls-tree'
-with \--name-only).
+with --name-only).
 
 For plain blobs, it shows the plain contents.
 
index 5221f950ce06cda1a764424ec217760d044a5ac3..335f3123353482cfd708420dac3b766f181e89ff 100644 (file)
@@ -66,7 +66,10 @@ When `-u` option is not used, untracked files and directories are
 shown (i.e. the same as specifying `normal`), to help you avoid
 forgetting to add newly created files.  Because it takes extra work
 to find untracked files in the filesystem, this mode may take some
-time in a large working tree.  You can use `no` to have `git status`
+time in a large working tree.
+Consider enabling untracked cache and split index if supported (see
+`git update-index --untracked-cache` and `git update-index
+--split-index`), Otherwise you can use `no` to have `git status`
 return more quickly without showing untracked files.
 +
 The default can be changed using the status.showUntrackedFiles
index 6c6e989074c58840ca1c8c4e6f4cad0b8fdb718d..60328d5d08d43d31dd80e14b07fe75257a1f4446 100644 (file)
@@ -49,7 +49,7 @@ EXAMPLES
 
 Given the following noisy input with '$' indicating the end of a line:
 
---------
+---------
 |A brief introduction   $
 |   $
 |$
@@ -65,7 +65,7 @@ Given the following noisy input with '$' indicating the end of a line:
 
 Use 'git stripspace' with no arguments to obtain:
 
---------
+---------
 |A brief introduction$
 |$
 |A new paragraph$
@@ -79,7 +79,7 @@ Use 'git stripspace' with no arguments to obtain:
 
 Use 'git stripspace --strip-comments' to obtain:
 
---------
+---------
 |A brief introduction$
 |$
 |A new paragraph$
index 39e9a181cce8e58c4dfd0e3fb62e15cedecb30b7..11d1e2fc66bb6e92eb0c0f5a85f86fb38eca865a 100644 (file)
@@ -70,8 +70,8 @@ COMMANDS
 --username=<user>;;
        For transports that SVN handles authentication for (http,
        https, and plain svn), specify the username.  For other
-       transports (e.g. svn+ssh://), you must include the username in
-       the URL, e.g. svn+ssh://foo@svn.bar.com/project
+       transports (e.g. `svn+ssh://`), you must include the username in
+       the URL, e.g. `svn+ssh://foo@svn.bar.com/project`
 --prefix=<prefix>;;
        This allows one to specify a prefix which is prepended
        to the names of remotes if trunk/branches/tags are
@@ -279,9 +279,9 @@ first have already been pushed into SVN.
        Ask the user to confirm that a patch set should actually be sent to SVN.
        For each patch, one may answer "yes" (accept this patch), "no" (discard this
        patch), "all" (accept all patches), or "quit".
-       +
-       'git svn dcommit' returns immediately if answer is "no" or "quit", without
-       committing anything to SVN.
++
+'git svn dcommit' returns immediately if answer is "no" or "quit", without
+committing anything to SVN.
 
 'branch'::
        Create a branch in the SVN repository.
index f5b267e1e300c965704ab3918fe16163351fd1cf..034d10d633c343b17a83879b00aae3ba2a98a388 100644 (file)
@@ -158,7 +158,7 @@ This option is only applicable when listing tags without annotation lines.
 CONFIGURATION
 -------------
 By default, 'git tag' in sign-with-default mode (-s) will use your
-committer identity (of the form "Your Name <\your@email.address>") to
+committer identity (of the form `Your Name <your@email.address>`) to
 find a key.  If you want to use a different default key, you can specify
 it in the repository configuration as follows:
 
index 12cb108b8561a6365192a65688d116901468decf..07d432988f249d7439ae56699496da97b7d6f828 100644 (file)
@@ -9,7 +9,7 @@ git-unpack-objects - Unpack objects from a packed archive
 SYNOPSIS
 --------
 [verse]
-'git unpack-objects' [-n] [-q] [-r] [--strict] < <pack-file>
+'git unpack-objects' [-n] [-q] [-r] [--strict] < <packfile>
 
 
 DESCRIPTION
@@ -19,8 +19,8 @@ the objects contained within and writing them into the repository in
 "loose" (one object per file) format.
 
 Objects that already exist in the repository will *not* be unpacked
-from the pack-file.  Therefore, nothing will be unpacked if you use
-this command on a pack-file that exists within the target repository.
+from the packfile.  Therefore, nothing will be unpacked if you use
+this command on a packfile that exists within the target repository.
 
 See linkgit:git-repack[1] for options to generate
 new packs and replace existing ones.
index aff01798cdf6b114009eae8dfc4f2866a8a24d17..1a296bc29a16fcf4ee6b581310033861c1ec82bc 100644 (file)
@@ -170,6 +170,20 @@ may not support it yet.
        the shared index file. This mode is designed for very large
        indexes that take a significant amount of time to read or write.
 
+--untracked-cache::
+--no-untracked-cache::
+       Enable or disable untracked cache extension. This could speed
+       up for commands that involve determining untracked files such
+       as `git status`. The underlying operating system and file
+       system must change `st_mtime` field of a directory if files
+       are added or deleted in that directory.
+
+--force-untracked-cache::
+       For safety, `--untracked-cache` performs tests on the working
+       directory to make sure untracked cache can be used. These
+       tests can take a few seconds. `--force-untracked-cache` can be
+       used to skip the tests.
+
 \--::
        Do not interpret any more arguments as options.
 
index 526ba7be9ca08ff1925a387a4d98a9a3aaf867a8..61ca6d04c206dc5667ffe83b8dd3c9cc4d1ab31c 100644 (file)
@@ -40,7 +40,7 @@ OUTPUT FORMAT
 -------------
 When specifying the -v option the format used is:
 
-       SHA-1 type size size-in-pack-file offset-in-packfile
+       SHA-1 type size size-in-packfile offset-in-packfile
 
 for objects that are not deltified in the pack, and
 
index f582742bc81a761218f30cead342491cf5580a5d..ccc12b280652609bfd5eb089e194a9219b7fc9f2 100644 (file)
@@ -836,6 +836,15 @@ Git so take care if using Cogito etc.
        an explicit repository directory set via 'GIT_DIR' or on the
        command line.
 
+'GIT_COMMON_DIR'::
+       If this variable is set to a path, non-worktree files that are
+       normally in $GIT_DIR will be taken from this path
+       instead. Worktree-specific files such as HEAD or index are
+       taken from $GIT_DIR. See linkgit:gitrepository-layout[5] and
+       the section 'MULTIPLE CHECKOUT MODE' in linkgit:checkout[1]
+       details. This variable has lower precedence than other path
+       variables such as GIT_INDEX_FILE, GIT_OBJECT_DIRECTORY...
+
 Git Commits
 ~~~~~~~~~~~
 'GIT_AUTHOR_NAME'::
index 8475c079325103fe102027fccd5f5f02818667f3..36e9ab3e16860be21e6bcdc6e2f7c6ff44aa4757 100644 (file)
@@ -259,7 +259,7 @@ index 557db03..263414f 100644
 @@ -1 +1,2 @@
  Hello World
 +It's a new day for git
-----
+------------
 
 i.e. the diff of the change we caused by adding another line to `hello`.
 
index c8b3e51c84a58d6f9e4a0ba324f9071cc125881f..c579593e55008b09ca1914270fb8b52a08476f72 100644 (file)
@@ -28,8 +28,8 @@ The 'git diff-{asterisk}' family works by first comparing two sets of
 files:
 
  - 'git diff-index' compares contents of a "tree" object and the
-   working directory (when '\--cached' flag is not used) or a
-   "tree" object and the index file (when '\--cached' flag is
+   working directory (when '--cached' flag is not used) or a
+   "tree" object and the index file (when '--cached' flag is
    used);
 
  - 'git diff-files' compares contents of the index file and the
@@ -142,7 +142,7 @@ merges these filepairs and creates:
 
 When the "-C" option is used, the original contents of modified files,
 and deleted files (and also unmodified files, if the
-"\--find-copies-harder" option is used) are considered as candidates
+"--find-copies-harder" option is used) are considered as candidates
 of the source files in rename/copy operation.  If the input were like
 these filepairs, that talk about a modified file fileY and a newly
 created file file0:
index 8edf72cf5398f3a13002e8e08774f75b4cc7180d..82e2d154359de5dba6694ac7a844b34984e09300 100644 (file)
@@ -408,14 +408,14 @@ set by Git if the remote helper has the 'option' capability.
        of <n> correspond to the number of -v flags passed on the
        command line.
 
-'option progress' \{'true'|'false'\}::
+'option progress' {'true'|'false'}::
        Enables (or disables) progress messages displayed by the
        transport helper during a command.
 
 'option depth' <depth>::
        Deepens the history of a shallow repository.
 
-'option followtags' \{'true'|'false'\}::
+'option followtags' {'true'|'false'}::
        If enabled the helper should automatically fetch annotated
        tag objects if the object the tag points at was transferred
        during the fetch command.  If the tag is not fetched by
@@ -423,7 +423,7 @@ set by Git if the remote helper has the 'option' capability.
        ask for the tag specifically.  Some helpers may be able to
        use this option to avoid a second network connection.
 
-'option dry-run' \{'true'|'false'\}:
+'option dry-run' {'true'|'false'}:
        If true, pretend the operation completed successfully,
        but don't actually change any repository data.  For most
        helpers this only applies to the 'push', if supported.
@@ -434,18 +434,18 @@ set by Git if the remote helper has the 'option' capability.
        must not rely on this option being set before
        connect request occurs.
 
-'option check-connectivity' \{'true'|'false'\}::
+'option check-connectivity' {'true'|'false'}::
        Request the helper to check connectivity of a clone.
 
-'option force' \{'true'|'false'\}::
+'option force' {'true'|'false'}::
        Request the helper to perform a force update.  Defaults to
        'false'.
 
-'option cloning \{'true'|'false'\}::
+'option cloning {'true'|'false'}::
        Notify the helper this is a clone request (i.e. the current
        repository is guaranteed empty).
 
-'option update-shallow \{'true'|'false'\}::
+'option update-shallow {'true'|'false'}::
        Allow to extend .git/shallow if the new refs require it.
 
 SEE ALSO
index 79653f313474fa658f072c97d8744e5afccb77d7..7173b38830015ba1be09772e80cf3973c10bab69 100644 (file)
@@ -46,6 +46,9 @@ of incomplete object store is not suitable to be published for
 use with dumb transports but otherwise is OK as long as
 `objects/info/alternates` points at the object stores it
 borrows from.
++
+This directory is ignored if $GIT_COMMON_DIR is set and
+"$GIT_COMMON_DIR/objects" will be used instead.
 
 objects/[0-9a-f][0-9a-f]::
        A newly created object is stored in its own file.
@@ -92,7 +95,8 @@ refs::
        References are stored in subdirectories of this
        directory.  The 'git prune' command knows to preserve
        objects reachable from refs found in this directory and
-       its subdirectories.
+       its subdirectories. This directory is ignored if $GIT_COMMON_DIR
+       is set and "$GIT_COMMON_DIR/refs" will be used instead.
 
 refs/heads/`name`::
        records tip-of-the-tree commit objects of branch `name`
@@ -114,7 +118,8 @@ refs/replace/`<obj-sha1>`::
 packed-refs::
        records the same information as refs/heads/, refs/tags/,
        and friends record in a more efficient way.  See
-       linkgit:git-pack-refs[1].
+       linkgit:git-pack-refs[1]. This file is ignored if $GIT_COMMON_DIR
+       is set and "$GIT_COMMON_DIR/packed-refs" will be used instead.
 
 HEAD::
        A symref (see glossary) to the `refs/heads/` namespace
@@ -133,6 +138,11 @@ being a symref to point at the current branch.  Such a state
 is often called 'detached HEAD.'  See linkgit:git-checkout[1]
 for details.
 
+config::
+       Repository specific configuration file. This file is ignored
+       if $GIT_COMMON_DIR is set and "$GIT_COMMON_DIR/config" will be
+       used instead.
+
 branches::
        A slightly deprecated way to store shorthands to be used
        to specify a URL to 'git fetch', 'git pull' and 'git push'.
@@ -140,7 +150,10 @@ branches::
        'name' can be given to these commands in place of
        'repository' argument.  See the REMOTES section in
        linkgit:git-fetch[1] for details.  This mechanism is legacy
-       and not likely to be found in modern repositories.
+       and not likely to be found in modern repositories. This
+       directory is ignored if $GIT_COMMON_DIR is set and
+       "$GIT_COMMON_DIR/branches" will be used instead.
+
 
 hooks::
        Hooks are customization scripts used by various Git
@@ -149,7 +162,9 @@ hooks::
        default.  To enable, the `.sample` suffix has to be
        removed from the filename by renaming.
        Read linkgit:githooks[5] for more details about
-       each hook.
+       each hook. This directory is ignored if $GIT_COMMON_DIR is set
+       and "$GIT_COMMON_DIR/hooks" will be used instead.
+
 
 index::
        The current index file for the repository.  It is
@@ -161,7 +176,8 @@ sharedindex.<SHA-1>::
 
 info::
        Additional information about the repository is recorded
-       in this directory.
+       in this directory. This directory is ignored if $GIT_COMMON_DIR
+       is set and "$GIT_COMMON_DIR/index" will be used instead.
 
 info/refs::
        This file helps dumb transports discover what refs are
@@ -201,12 +217,15 @@ remotes::
        when interacting with remote repositories via 'git fetch',
        'git pull' and 'git push' commands.  See the REMOTES section
        in linkgit:git-fetch[1] for details.  This mechanism is legacy
-       and not likely to be found in modern repositories.
+       and not likely to be found in modern repositories. This
+       directory is ignored if $GIT_COMMON_DIR is set and
+       "$GIT_COMMON_DIR/remotes" will be used instead.
 
 logs::
-       Records of changes made to refs are stored in this
-       directory.  See linkgit:git-update-ref[1]
-       for more information.
+       Records of changes made to refs are stored in this directory.
+       See linkgit:git-update-ref[1] for more information. This
+       directory is ignored if $GIT_COMMON_DIR is set and
+       "$GIT_COMMON_DIR/logs" will be used instead.
 
 logs/refs/heads/`name`::
        Records all changes made to the branch tip named `name`.
@@ -217,11 +236,46 @@ logs/refs/tags/`name`::
 shallow::
        This is similar to `info/grafts` but is internally used
        and maintained by shallow clone mechanism.  See `--depth`
-       option to linkgit:git-clone[1] and linkgit:git-fetch[1].
+       option to linkgit:git-clone[1] and linkgit:git-fetch[1]. This
+       file is ignored if $GIT_COMMON_DIR is set and
+       "$GIT_COMMON_DIR/shallow" will be used instead.
+
+commondir::
+       If this file exists, $GIT_COMMON_DIR (see linkgit:git[1]) will
+       be set to the path specified in this file if it is not
+       explicitly set. If the specified path is relative, it is
+       relative to $GIT_DIR. The repository with commondir is
+       incomplete without the repository pointed by "commondir".
 
 modules::
        Contains the git-repositories of the submodules.
 
+worktrees::
+       Contains worktree specific information of linked
+       checkouts. Each subdirectory contains the worktree-related
+       part of a linked checkout. This directory is ignored if
+       $GIT_COMMON_DIR is set and "$GIT_COMMON_DIR/worktrees" will be
+       used instead.
+
+worktrees/<id>/gitdir::
+       A text file containing the absolute path back to the .git file
+       that points to here. This is used to check if the linked
+       repository has been manually removed and there is no need to
+       keep this directory any more. mtime of this file should be
+       updated every time the linked repository is accessed.
+
+worktrees/<id>/locked::
+       If this file exists, the linked repository may be on a
+       portable device and not available. It does not mean that the
+       linked repository is gone and `worktrees/<id>` could be
+       removed. The file's content contains a reason string on why
+       the repository is locked.
+
+worktrees/<id>/link::
+       If this file exists, it is a hard link to the linked .git
+       file. It is used to detect if the linked repository is
+       manually removed.
+
 SEE ALSO
 --------
 linkgit:git-init[1],
index 35112e4966f9b021b0889d734d5cb945b8943003..b7093af8b23e6a83741b81678e7aae0c5ff7c88a 100644 (file)
@@ -233,3 +233,65 @@ Git index format
   The remaining index entries after replaced ones will be added to the
   final index. These added entries are also sorted by entry name then
   stage.
+
+== Untracked cache
+
+  Untracked cache saves the untracked file list and necessary data to
+  verify the cache. The signature for this extension is { 'U', 'N',
+  'T', 'R' }.
+
+  The extension starts with
+
+  - A sequence of NUL-terminated strings, preceded by the size of the
+    sequence in variable width encoding. Each string describes the
+    environment where the cache can be used.
+
+  - Stat data of $GIT_DIR/info/exclude. See "Index entry" section from
+    ctime field until "file size".
+
+  - Stat data of core.excludesfile
+
+  - 32-bit dir_flags (see struct dir_struct)
+
+  - 160-bit SHA-1 of $GIT_DIR/info/exclude. Null SHA-1 means the file
+    does not exist.
+
+  - 160-bit SHA-1 of core.excludesfile. Null SHA-1 means the file does
+    not exist.
+
+  - NUL-terminated string of per-dir exclude file name. This usually
+    is ".gitignore".
+
+  - The number of following directory blocks, variable width
+    encoding. If this number is zero, the extension ends here with a
+    following NUL.
+
+  - A number of directory blocks in depth-first-search order, each
+    consists of
+
+    - The number of untracked entries, variable width encoding.
+
+    - The number of sub-directory blocks, variable width encoding.
+
+    - The directory name terminated by NUL.
+
+    - A number of untrached file/dir names terminated by NUL.
+
+The remaining data of each directory block is grouped by type:
+
+  - An ewah bitmap, the n-th bit marks whether the n-th directory has
+    valid untracked cache entries.
+
+  - An ewah bitmap, the n-th bit records "check-only" bit of
+    read_directory_recursive() for the n-th directory.
+
+  - An ewah bitmap, the n-th bit indicates whether SHA-1 and stat data
+    is valid for the n-th directory and exists in the next data.
+
+  - An array of stat data. The n-th data corresponds with the n-th
+    "one" bit in the previous ewah bitmap.
+
+  - An array of SHA-1. The n-th SHA-1 corresponds with the n-th "one" bit
+    in the previous ewah bitmap.
+
+  - One NUL.
index 462e20645f1ea87dcc04938b8ca504bd0d7d7636..fc09c63b32e1776347f6b6c562739f9245593639 100644 (file)
@@ -465,7 +465,7 @@ contain all the objects that the server will need to complete the new
 references.
 
 ----
-  update-request    =  *shallow ( command-list | push-cert ) [pack-file]
+  update-request    =  *shallow ( command-list | push-cert ) [packfile]
 
   shallow           =  PKT-LINE("shallow" SP obj-id LF)
 
@@ -491,7 +491,7 @@ references.
                      *PKT-LINE(gpg-signature-lines LF)
                      PKT-LINE("push-cert-end" LF)
 
-  pack-file         = "PACK" 28*(OCTET)
+  packfile          = "PACK" 28*(OCTET)
 ----
 
 If the receiving end does not support delete-refs, the sending end MUST
@@ -502,11 +502,11 @@ MUST NOT send a push-cert command.  When a push-cert command is
 sent, command-list MUST NOT be sent; the commands recorded in the
 push certificate is used instead.
 
-The pack-file MUST NOT be sent if the only command used is 'delete'.
+The packfile MUST NOT be sent if the only command used is 'delete'.
 
-A pack-file MUST be sent if either create or update command is used,
+A packfile MUST be sent if either create or update command is used,
 even if the server already has all the necessary objects.  In this
-case the client MUST send an empty pack-file.   The only time this
+case the client MUST send an empty packfile.   The only time this
 is likely to happen is if the client is creating
 a new branch or a tag that points to an existing obj-id.
 
index c4a6631fc0458faaa52ed57dcaef7eea5def20df..bfb715d3c896bea3f6eba7da43fabe4370530efa 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 
 GVF=GIT-VERSION-FILE
-DEF_VER=v2.4.2
+DEF_VER=v2.4.0.GIT
 
 LF='
 '
index 5f3987fe3bd945fb5a84c9f45a8de7da5581f79a..323c401e966eb8a69057e563fc43b4f87e7d897f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -359,6 +359,8 @@ all::
 # compiler is detected to support it.
 #
 # Define HAVE_BSD_SYSCTL if your platform has a BSD-compatible sysctl function.
+#
+# Define HAVE_GETDELIM if your system has the getdelim() function.
 
 GIT-VERSION-FILE: FORCE
        @$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -572,6 +574,7 @@ TEST_PROGRAMS_NEED_X += test-date
 TEST_PROGRAMS_NEED_X += test-delta
 TEST_PROGRAMS_NEED_X += test-dump-cache-tree
 TEST_PROGRAMS_NEED_X += test-dump-split-index
+TEST_PROGRAMS_NEED_X += test-dump-untracked-cache
 TEST_PROGRAMS_NEED_X += test-genrandom
 TEST_PROGRAMS_NEED_X += test-hashmap
 TEST_PROGRAMS_NEED_X += test-index-version
@@ -1437,6 +1440,10 @@ ifdef HAVE_BSD_SYSCTL
        BASIC_CFLAGS += -DHAVE_BSD_SYSCTL
 endif
 
+ifdef HAVE_GETDELIM
+       BASIC_CFLAGS += -DHAVE_GETDELIM
+endif
+
 ifeq ($(TCLTK_PATH),)
 NO_TCLTK = NoThanks
 endif
@@ -2102,6 +2109,7 @@ GIT-BUILD-OPTIONS: FORCE
        @echo PYTHON_PATH=\''$(subst ','\'',$(PYTHON_PATH_SQ))'\' >>$@
        @echo TAR=\''$(subst ','\'',$(subst ','\'',$(TAR)))'\' >>$@
        @echo NO_CURL=\''$(subst ','\'',$(subst ','\'',$(NO_CURL)))'\' >>$@
+       @echo NO_EXPAT=\''$(subst ','\'',$(subst ','\'',$(NO_EXPAT)))'\' >>$@
        @echo USE_LIBPCRE=\''$(subst ','\'',$(subst ','\'',$(USE_LIBPCRE)))'\' >>$@
        @echo NO_PERL=\''$(subst ','\'',$(subst ','\'',$(NO_PERL)))'\' >>$@
        @echo NO_PYTHON=\''$(subst ','\'',$(subst ','\'',$(NO_PYTHON)))'\' >>$@
index f43dfd9767a9ca8117d12bdecdae682d733eebc3..3295d667f396a686891335ceaaf817545a7d9e25 120000 (symlink)
--- a/RelNotes
+++ b/RelNotes
@@ -1 +1 @@
-Documentation/RelNotes/2.4.2.txt
\ No newline at end of file
+Documentation/RelNotes/2.5.0.txt
\ No newline at end of file
index ffb3535e93dca2135724d998657b80c2bc4d6f20..ae3d67f9d310e2e34c6d2c5919eff467b951783f 100644 (file)
@@ -448,12 +448,12 @@ static void write_zip_trailer(const unsigned char *sha1)
        copy_le16(trailer.entries, zip_dir_entries);
        copy_le32(trailer.size, zip_dir_offset);
        copy_le32(trailer.offset, zip_offset);
-       copy_le16(trailer.comment_length, sha1 ? 40 : 0);
+       copy_le16(trailer.comment_length, sha1 ? GIT_SHA1_HEXSZ : 0);
 
        write_or_die(1, zip_dir, zip_dir_offset);
        write_or_die(1, &trailer, ZIP_DIR_TRAILER_SIZE);
        if (sha1)
-               write_or_die(1, sha1_to_hex(sha1), 40);
+               write_or_die(1, sha1_to_hex(sha1), GIT_SHA1_HEXSZ);
 }
 
 static void dos_time(time_t *time, int *dos_date, int *dos_time)
index 96057ed830e521a5f12b0a73b4a04a6b5e581e87..d37c41daf29b1163ac7743e5ce17cdafc9b2e8a3 100644 (file)
--- a/archive.c
+++ b/archive.c
@@ -101,7 +101,7 @@ static void setup_archive_check(struct git_attr_check *check)
 
 struct directory {
        struct directory *up;
-       unsigned char sha1[20];
+       struct object_id oid;
        int baselen, len;
        unsigned mode;
        int stage;
@@ -177,7 +177,7 @@ static void queue_directory(const unsigned char *sha1,
        d->stage   = stage;
        c->bottom  = d;
        d->len = sprintf(d->path, "%.*s%s/", (int)base->len, base->buf, filename);
-       hashcpy(d->sha1, sha1);
+       hashcpy(d->oid.hash, sha1);
 }
 
 static int write_directory(struct archiver_context *c)
@@ -191,7 +191,7 @@ static int write_directory(struct archiver_context *c)
        d->path[d->len - 1] = '\0'; /* no trailing slash */
        ret =
                write_directory(c) ||
-               write_archive_entry(d->sha1, d->path, d->baselen,
+               write_archive_entry(d->oid.hash, d->path, d->baselen,
                                    d->path + d->baselen, d->mode,
                                    d->stage, c) != READ_TREE_RECURSIVE;
        free(d);
@@ -354,7 +354,7 @@ static void parse_treeish_arg(const char **argv,
        time_t archive_time;
        struct tree *tree;
        const struct commit *commit;
-       unsigned char sha1[20];
+       struct object_id oid;
 
        /* Remotes are only allowed to fetch actual refs */
        if (remote && !remote_allow_unreachable) {
@@ -362,15 +362,15 @@ static void parse_treeish_arg(const char **argv,
                const char *colon = strchrnul(name, ':');
                int refnamelen = colon - name;
 
-               if (!dwim_ref(name, refnamelen, sha1, &ref))
+               if (!dwim_ref(name, refnamelen, oid.hash, &ref))
                        die("no such ref: %.*s", refnamelen, name);
                free(ref);
        }
 
-       if (get_sha1(name, sha1))
+       if (get_sha1(name, oid.hash))
                die("Not a valid object name");
 
-       commit = lookup_commit_reference_gently(sha1, 1);
+       commit = lookup_commit_reference_gently(oid.hash, 1);
        if (commit) {
                commit_sha1 = commit->object.sha1;
                archive_time = commit->date;
@@ -379,21 +379,21 @@ static void parse_treeish_arg(const char **argv,
                archive_time = time(NULL);
        }
 
-       tree = parse_tree_indirect(sha1);
+       tree = parse_tree_indirect(oid.hash);
        if (tree == NULL)
                die("not a tree object");
 
        if (prefix) {
-               unsigned char tree_sha1[20];
+               struct object_id tree_oid;
                unsigned int mode;
                int err;
 
                err = get_tree_entry(tree->object.sha1, prefix,
-                                    tree_sha1, &mode);
+                                    tree_oid.hash, &mode);
                if (err || !S_ISDIR(mode))
                        die("current working directory is untracked");
 
-               tree = parse_tree_indirect(tree_sha1);
+               tree = parse_tree_indirect(tree_oid.hash);
        }
        ar_args->tree = tree;
        ar_args->commit_sha1 = commit_sha1;
diff --git a/attr.c b/attr.c
index 7f445965c1886fe8cb53966969b48f4b0bde4826..8f2ac6c88c8c2f7cff514981a7c01c136f734892 100644 (file)
--- a/attr.c
+++ b/attr.c
@@ -493,7 +493,6 @@ static int git_attr_system(void)
 static void bootstrap_attr_stack(void)
 {
        struct attr_stack *elem;
-       char *xdg_attributes_file;
 
        if (attr_stack)
                return;
@@ -512,10 +511,8 @@ static void bootstrap_attr_stack(void)
                }
        }
 
-       if (!git_attributes_file) {
-               home_config_paths(NULL, &xdg_attributes_file, "attributes");
-               git_attributes_file = xdg_attributes_file;
-       }
+       if (!git_attributes_file)
+               git_attributes_file = xdg_config_home("attributes");
        if (git_attributes_file) {
                elem = read_attr_from_file(git_attributes_file, 1);
                if (elem) {
index 8c6d843699ab04bc0fe952268d14965943446a17..10f5e57ef37873682f2b987e67708fea61cd05f8 100644 (file)
--- a/bisect.c
+++ b/bisect.c
@@ -15,7 +15,7 @@
 static struct sha1_array good_revs;
 static struct sha1_array skipped_revs;
 
-static unsigned char *current_bad_sha1;
+static struct object_id *current_bad_oid;
 
 static const char *argv_checkout[] = {"checkout", "-q", NULL, "--", NULL};
 static const char *argv_show_branch[] = {"show-branch", NULL, NULL};
@@ -404,8 +404,8 @@ static int register_ref(const char *refname, const unsigned char *sha1,
                        int flags, void *cb_data)
 {
        if (!strcmp(refname, "bad")) {
-               current_bad_sha1 = xmalloc(20);
-               hashcpy(current_bad_sha1, sha1);
+               current_bad_oid = xmalloc(sizeof(*current_bad_oid));
+               hashcpy(current_bad_oid->hash, sha1);
        } else if (starts_with(refname, "good-")) {
                sha1_array_append(&good_revs, sha1);
        } else if (starts_with(refname, "skip-")) {
@@ -564,7 +564,7 @@ static struct commit_list *skip_away(struct commit_list *list, int count)
 
        for (i = 0; cur; cur = cur->next, i++) {
                if (i == index) {
-                       if (hashcmp(cur->item->object.sha1, current_bad_sha1))
+                       if (hashcmp(cur->item->object.sha1, current_bad_oid->hash))
                                return cur;
                        if (previous)
                                return previous;
@@ -607,7 +607,7 @@ static void bisect_rev_setup(struct rev_info *revs, const char *prefix,
 
        /* rev_argv.argv[0] will be ignored by setup_revisions */
        argv_array_push(&rev_argv, "bisect_rev_setup");
-       argv_array_pushf(&rev_argv, bad_format, sha1_to_hex(current_bad_sha1));
+       argv_array_pushf(&rev_argv, bad_format, oid_to_hex(current_bad_oid));
        for (i = 0; i < good_revs.nr; i++)
                argv_array_pushf(&rev_argv, good_format,
                                 sha1_to_hex(good_revs.sha1[i]));
@@ -628,7 +628,7 @@ static void bisect_common(struct rev_info *revs)
 }
 
 static void exit_if_skipped_commits(struct commit_list *tried,
-                                   const unsigned char *bad)
+                                   const struct object_id *bad)
 {
        if (!tried)
                return;
@@ -637,12 +637,12 @@ static void exit_if_skipped_commits(struct commit_list *tried,
               "The first bad commit could be any of:\n");
        print_commit_list(tried, "%s\n", "%s\n");
        if (bad)
-               printf("%s\n", sha1_to_hex(bad));
+               printf("%s\n", oid_to_hex(bad));
        printf("We cannot bisect more!\n");
        exit(2);
 }
 
-static int is_expected_rev(const unsigned char *sha1)
+static int is_expected_rev(const struct object_id *oid)
 {
        const char *filename = git_path("BISECT_EXPECTED_REV");
        struct stat st;
@@ -658,7 +658,7 @@ static int is_expected_rev(const unsigned char *sha1)
                return 0;
 
        if (strbuf_getline(&str, fp, '\n') != EOF)
-               res = !strcmp(str.buf, sha1_to_hex(sha1));
+               res = !strcmp(str.buf, oid_to_hex(oid));
 
        strbuf_release(&str);
        fclose(fp);
@@ -719,7 +719,7 @@ static struct commit **get_bad_and_good_commits(int *rev_nr)
        struct commit **rev = xmalloc(len * sizeof(*rev));
        int i, n = 0;
 
-       rev[n++] = get_commit_reference(current_bad_sha1);
+       rev[n++] = get_commit_reference(current_bad_oid->hash);
        for (i = 0; i < good_revs.nr; i++)
                rev[n++] = get_commit_reference(good_revs.sha1[i]);
        *rev_nr = n;
@@ -729,8 +729,8 @@ static struct commit **get_bad_and_good_commits(int *rev_nr)
 
 static void handle_bad_merge_base(void)
 {
-       if (is_expected_rev(current_bad_sha1)) {
-               char *bad_hex = sha1_to_hex(current_bad_sha1);
+       if (is_expected_rev(current_bad_oid)) {
+               char *bad_hex = oid_to_hex(current_bad_oid);
                char *good_hex = join_sha1_array_hex(&good_revs, ' ');
 
                fprintf(stderr, "The merge base %s is bad.\n"
@@ -750,7 +750,7 @@ static void handle_bad_merge_base(void)
 static void handle_skipped_merge_base(const unsigned char *mb)
 {
        char *mb_hex = sha1_to_hex(mb);
-       char *bad_hex = sha1_to_hex(current_bad_sha1);
+       char *bad_hex = sha1_to_hex(current_bad_oid->hash);
        char *good_hex = join_sha1_array_hex(&good_revs, ' ');
 
        warning("the merge base between %s and [%s] "
@@ -781,7 +781,7 @@ static void check_merge_bases(int no_checkout)
 
        for (; result; result = result->next) {
                const unsigned char *mb = result->item->object.sha1;
-               if (!hashcmp(mb, current_bad_sha1)) {
+               if (!hashcmp(mb, current_bad_oid->hash)) {
                        handle_bad_merge_base();
                } else if (0 <= sha1_array_lookup(&good_revs, mb)) {
                        continue;
@@ -838,7 +838,7 @@ static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)
        struct stat st;
        int fd;
 
-       if (!current_bad_sha1)
+       if (!current_bad_oid)
                die("a bad revision is needed");
 
        /* Check if file BISECT_ANCESTORS_OK exists. */
@@ -903,7 +903,7 @@ int bisect_next_all(const char *prefix, int no_checkout)
        struct commit_list *tried;
        int reaches = 0, all = 0, nr, steps;
        const unsigned char *bisect_rev;
-       char bisect_rev_hex[41];
+       char bisect_rev_hex[GIT_SHA1_HEXSZ + 1];
 
        if (read_bisect_refs())
                die("reading bisect refs failed");
@@ -927,7 +927,7 @@ int bisect_next_all(const char *prefix, int no_checkout)
                exit_if_skipped_commits(tried, NULL);
 
                printf("%s was both good and bad\n",
-                      sha1_to_hex(current_bad_sha1));
+                      oid_to_hex(current_bad_oid));
                exit(1);
        }
 
@@ -938,10 +938,10 @@ int bisect_next_all(const char *prefix, int no_checkout)
        }
 
        bisect_rev = revs.commits->item->object.sha1;
-       memcpy(bisect_rev_hex, sha1_to_hex(bisect_rev), 41);
+       memcpy(bisect_rev_hex, sha1_to_hex(bisect_rev), GIT_SHA1_HEXSZ + 1);
 
-       if (!hashcmp(bisect_rev, current_bad_sha1)) {
-               exit_if_skipped_commits(tried, current_bad_sha1);
+       if (!hashcmp(bisect_rev, current_bad_oid->hash)) {
+               exit_if_skipped_commits(tried, current_bad_oid);
                printf("%s is the first bad commit\n", bisect_rev_hex);
                show_diff_tree(prefix, revs.commits->item);
                /* This means the bisection process succeeded. */
index 3390933d68b2dd6c7296a7d2103d009fa27f2ca8..df5135bf62acabfa9f68793435c1576ba7c1a36a 100644 (file)
@@ -63,6 +63,7 @@ static void update_callback(struct diff_queue_struct *q,
                switch (fix_unmerged_status(p, data)) {
                default:
                        die(_("unexpected diff status %c"), p->status);
+               case DIFF_STATUS_ADDED:
                case DIFF_STATUS_MODIFIED:
                case DIFF_STATUS_TYPE_CHANGED:
                        if (add_file_to_index(&the_index, path, data->flags)) {
@@ -208,7 +209,8 @@ static int edit_patch(int argc, const char **argv, const char *prefix)
        if (run_diff_files(&rev, 0))
                die(_("Could not write patch"));
 
-       launch_editor(file, NULL, NULL);
+       if (launch_editor(file, NULL, NULL))
+               die(_("editing patch failed"));
 
        if (stat(file, &st))
                die_errno(_("Could not stat '%s'"), file);
index 0769b09287b2bcf6b3f85ff503a396fa245c31a0..146be97a1a879242aa12eb066c5c69cd6af92409 100644 (file)
@@ -208,7 +208,7 @@ struct patch {
        struct patch *next;
 
        /* three-way fallback result */
-       unsigned char threeway_stage[3][20];
+       struct object_id threeway_stage[3];
 };
 
 static void free_fragment_list(struct fragment *list)
@@ -3426,11 +3426,11 @@ static int try_threeway(struct image *image, struct patch *patch,
        if (status) {
                patch->conflicted_threeway = 1;
                if (patch->is_new)
-                       hashclr(patch->threeway_stage[0]);
+                       oidclr(&patch->threeway_stage[0]);
                else
-                       hashcpy(patch->threeway_stage[0], pre_sha1);
-               hashcpy(patch->threeway_stage[1], our_sha1);
-               hashcpy(patch->threeway_stage[2], post_sha1);
+                       hashcpy(patch->threeway_stage[0].hash, pre_sha1);
+               hashcpy(patch->threeway_stage[1].hash, our_sha1);
+               hashcpy(patch->threeway_stage[2].hash, post_sha1);
                fprintf(stderr, "Applied patch to '%s' with conflicts.\n", patch->new_name);
        } else {
                fprintf(stderr, "Applied patch to '%s' cleanly.\n", patch->new_name);
@@ -4186,14 +4186,14 @@ static void add_conflicted_stages_file(struct patch *patch)
 
        remove_file_from_cache(patch->new_name);
        for (stage = 1; stage < 4; stage++) {
-               if (is_null_sha1(patch->threeway_stage[stage - 1]))
+               if (is_null_oid(&patch->threeway_stage[stage - 1]))
                        continue;
                ce = xcalloc(1, ce_size);
                memcpy(ce->name, patch->new_name, namelen);
                ce->ce_mode = create_ce_mode(mode);
                ce->ce_flags = create_ce_flags(stage);
                ce->ce_namelen = namelen;
-               hashcpy(ce->sha1, patch->threeway_stage[stage - 1]);
+               hashcpy(ce->sha1, patch->threeway_stage[stage - 1].hash);
                if (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD) < 0)
                        die(_("unable to add cache entry for %s"), patch->new_name);
        }
index 06484c2e0e23237bff711bbe3cda6e1382004ef3..8d70623cb8714a87650f2425daf4ee7aaf6307a8 100644 (file)
@@ -2348,6 +2348,7 @@ 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);
index 1d150378e91cd47c4cd555bfc858ec0b7ea9d604..9cbab189f5cb1776324a2494d5e35ffacf461b69 100644 (file)
@@ -242,7 +242,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
                                            sha1, &flags);
                if (!target) {
                        error(remote_branch
-                             ? _("remote branch '%s' not found.")
+                             ? _("remote-tracking branch '%s' not found.")
                              : _("branch '%s' not found."), bname.buf);
                        ret = 1;
                        continue;
@@ -257,7 +257,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
 
                if (delete_ref(name, sha1, REF_NODEREF)) {
                        error(remote_branch
-                             ? _("Error deleting remote branch '%s'")
+                             ? _("Error deleting remote-tracking branch '%s'")
                              : _("Error deleting branch '%s'"),
                              bname.buf);
                        ret = 1;
@@ -265,7 +265,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
                }
                if (!quiet) {
                        printf(remote_branch
-                              ? _("Deleted remote branch %s (was %s).\n")
+                              ? _("Deleted remote-tracking branch %s (was %s).\n")
                               : _("Deleted branch %s (was %s).\n"),
                               bname.buf,
                               (flags & REF_ISBROKEN) ? "broken"
@@ -771,7 +771,6 @@ static const char edit_description[] = "BRANCH_DESCRIPTION";
 
 static int edit_branch_description(const char *branch_name)
 {
-       FILE *fp;
        int status;
        struct strbuf buf = STRBUF_INIT;
        struct strbuf name = STRBUF_INIT;
@@ -784,8 +783,7 @@ static int edit_branch_description(const char *branch_name)
                    "  %s\n"
                    "Lines starting with '%c' will be stripped.\n",
                    branch_name, comment_line_char);
-       fp = fopen(git_path(edit_description), "w");
-       if ((fwrite(buf.buf, 1, buf.len, fp) < buf.len) || fclose(fp)) {
+       if (write_file(git_path(edit_description), 0, "%s", buf.buf)) {
                strbuf_release(&buf);
                return error(_("could not write branch description template: %s"),
                             strerror(errno));
index 92a8a6026a9bd6da5394e7b37f07dbe91f73db9c..4883a435a9afc607618d34c9b61b218eeda7de45 100644 (file)
@@ -42,6 +42,10 @@ int cmd_bundle(int argc, const char **argv, const char *prefix)
 
        if (!strcmp(cmd, "verify")) {
                close(bundle_fd);
+               if (argc != 1) {
+                       usage(builtin_bundle_usage);
+                       return 1;
+               }
                if (verify_bundle(&header, 1))
                        return 1;
                fprintf(stderr, _("%s is okay\n"), bundle_file);
@@ -52,6 +56,10 @@ int cmd_bundle(int argc, const char **argv, const char *prefix)
                return !!list_bundle_refs(&header, argc, argv);
        }
        if (!strcmp(cmd, "create")) {
+               if (argc < 2) {
+                       usage(builtin_bundle_usage);
+                       return 1;
+               }
                if (!startup_info->have_repository)
                        die(_("Need a repository to create a bundle."));
                return !!create_bundle(&header, bundle_file, argc, argv);
index df99df4db1ddb058368fe88f07c890d87600e6d9..ecb488822f903c56b5d14bdec3130c71817e1b65 100644 (file)
@@ -9,13 +9,20 @@
 #include "userdiff.h"
 #include "streaming.h"
 
-static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
+static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
+                       int unknown_type)
 {
        unsigned char sha1[20];
        enum object_type type;
        char *buf;
        unsigned long size;
        struct object_context obj_context;
+       struct object_info oi = {NULL};
+       struct strbuf sb = STRBUF_INIT;
+       unsigned flags = LOOKUP_REPLACE_OBJECT;
+
+       if (unknown_type)
+               flags |= LOOKUP_UNKNOWN_OBJECT;
 
        if (get_sha1_with_context(obj_name, 0, sha1, &obj_context))
                die("Not a valid object name %s", obj_name);
@@ -23,20 +30,22 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
        buf = NULL;
        switch (opt) {
        case 't':
-               type = sha1_object_info(sha1, NULL);
-               if (type > 0) {
-                       printf("%s\n", typename(type));
+               oi.typename = &sb;
+               if (sha1_object_info_extended(sha1, &oi, flags) < 0)
+                       die("git cat-file: could not get object info");
+               if (sb.len) {
+                       printf("%s\n", sb.buf);
+                       strbuf_release(&sb);
                        return 0;
                }
                break;
 
        case 's':
-               type = sha1_object_info(sha1, &size);
-               if (type > 0) {
-                       printf("%lu\n", size);
-                       return 0;
-               }
-               break;
+               oi.sizep = &size;
+               if (sha1_object_info_extended(sha1, &oi, flags) < 0)
+                       die("git cat-file: could not get object info");
+               printf("%lu\n", size);
+               return 0;
 
        case 'e':
                return !has_sha1_file(sha1);
@@ -323,7 +332,7 @@ static int batch_objects(struct batch_options *opt)
 }
 
 static const char * const cat_file_usage[] = {
-       N_("git cat-file (-t | -s | -e | -p | <type> | --textconv) <object>"),
+       N_("git cat-file (-t [--allow-unknown-type]|-s [--allow-unknown-type]|-e|-p|<type>|--textconv) <object>"),
        N_("git cat-file (--batch | --batch-check) < <list-of-objects>"),
        NULL
 };
@@ -359,16 +368,19 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
        int opt = 0;
        const char *exp_type = NULL, *obj_name = NULL;
        struct batch_options batch = {0};
+       int unknown_type = 0;
 
        const struct option options[] = {
                OPT_GROUP(N_("<type> can be one of: blob, tree, commit, tag")),
-               OPT_SET_INT('t', NULL, &opt, N_("show object type"), 't'),
-               OPT_SET_INT('s', NULL, &opt, N_("show object size"), 's'),
-               OPT_SET_INT('e', NULL, &opt,
+               OPT_CMDMODE('t', NULL, &opt, N_("show object type"), 't'),
+               OPT_CMDMODE('s', NULL, &opt, N_("show object size"), 's'),
+               OPT_CMDMODE('e', NULL, &opt,
                            N_("exit with zero when there's no error"), 'e'),
-               OPT_SET_INT('p', NULL, &opt, N_("pretty-print object's content"), 'p'),
-               OPT_SET_INT(0, "textconv", &opt,
+               OPT_CMDMODE('p', NULL, &opt, N_("pretty-print object's content"), 'p'),
+               OPT_CMDMODE(0, "textconv", &opt,
                            N_("for blob objects, run textconv on object's content"), 'c'),
+               OPT_BOOL( 0, "allow-unknown-type", &unknown_type,
+                         N_("allow -s and -t to work with broken/corrupt objects")),
                { OPTION_CALLBACK, 0, "batch", &batch, "format",
                        N_("show info and content of objects fed from the standard input"),
                        PARSE_OPT_OPTARG, batch_option_callback },
@@ -380,9 +392,6 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
 
        git_config(git_cat_file_config, NULL);
 
-       if (argc != 3 && argc != 2)
-               usage_with_options(cat_file_usage, options);
-
        argc = parse_options(argc, argv, prefix, options, cat_file_usage, 0);
 
        if (opt) {
@@ -405,5 +414,7 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
        if (batch.enabled)
                return batch_objects(&batch);
 
-       return cat_one_file(opt, exp_type, obj_name);
+       if (unknown_type && opt != 't' && opt != 's')
+               die("git cat-file --allow-unknown-type: use with -s or -t");
+       return cat_one_file(opt, exp_type, obj_name, unknown_type);
 }
index 9ca2da15836d161d5c28b9919eff0edf4347a446..8028c3768f3ef09035ba9092b4e34cdb498405e9 100644 (file)
@@ -241,7 +241,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
        /* Check out named files first */
        for (i = 0; i < argc; i++) {
                const char *arg = argv[i];
-               const char *p;
+               char *p;
 
                if (all)
                        die("git checkout-index: don't mix '--all' and explicit filenames");
@@ -249,8 +249,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
                        die("git checkout-index: don't mix '--stdin' and explicit filenames");
                p = prefix_path(prefix, prefix_length, arg);
                checkout_file(p, prefix);
-               if (p < arg || p > arg + strlen(arg))
-                       free((char *)p);
+               free(p);
        }
 
        if (read_from_stdin) {
@@ -260,7 +259,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
                        die("git checkout-index: don't mix '--all' and '--stdin'");
 
                while (strbuf_getline(&buf, stdin, line_termination) != EOF) {
-                       const char *p;
+                       char *p;
                        if (line_termination && buf.buf[0] == '"') {
                                strbuf_reset(&nbuf);
                                if (unquote_c_style(&nbuf, buf.buf, NULL))
@@ -269,8 +268,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
                        }
                        p = prefix_path(prefix, prefix_length, buf.buf);
                        checkout_file(p, prefix);
-                       if (p < buf.buf || p > buf.buf + buf.len)
-                               free((char *)p);
+                       free(p);
                }
                strbuf_release(&nbuf);
                strbuf_release(&buf);
index 3e141fc1491949a2dbb47c59d7d156ae6fe4eb47..2f92328db46b4ff81e32b32339ad830c4b76688b 100644 (file)
@@ -20,6 +20,7 @@
 #include "resolve-undo.h"
 #include "submodule.h"
 #include "argv-array.h"
+#include "sigchain.h"
 
 static const char * const checkout_usage[] = {
        N_("git checkout [<options>] <branch>"),
@@ -36,6 +37,7 @@ struct checkout_opts {
        int writeout_stage;
        int overwrite_ignore;
        int ignore_skipworktree;
+       int ignore_other_worktrees;
 
        const char *new_branch;
        const char *new_branch_force;
@@ -48,6 +50,10 @@ struct checkout_opts {
        const char *prefix;
        struct pathspec pathspec;
        struct tree *source_tree;
+
+       const char *new_worktree;
+       const char **saved_argv;
+       int new_worktree_mode;
 };
 
 static int post_checkout_hook(struct commit *old, struct commit *new,
@@ -267,6 +273,9 @@ static int checkout_paths(const struct checkout_opts *opts,
                die(_("Cannot update paths and switch to branch '%s' at the same time."),
                    opts->new_branch);
 
+       if (opts->new_worktree)
+               die(_("'%s' cannot be used with updating paths"), "--to");
+
        if (opts->patch_mode)
                return run_add_interactive(revision, "--patch=checkout",
                                           &opts->pathspec);
@@ -441,6 +450,11 @@ struct branch_info {
        const char *name; /* The short name used */
        const char *path; /* The full name of a real branch */
        struct commit *commit; /* The named commit */
+       /*
+        * if not null the branch is detached because it's already
+        * checked out in this checkout
+        */
+       char *checkout;
 };
 
 static void setup_branch_path(struct branch_info *branch)
@@ -502,7 +516,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
                        topts.dir->flags |= DIR_SHOW_IGNORED;
                        setup_standard_excludes(topts.dir);
                }
-               tree = parse_tree_indirect(old->commit ?
+               tree = parse_tree_indirect(old->commit && !opts->new_worktree_mode ?
                                           old->commit->object.sha1 :
                                           EMPTY_TREE_SHA1_BIN);
                init_tree_desc(&trees[0], tree->buffer, tree->size);
@@ -606,18 +620,21 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
                if (opts->new_orphan_branch) {
                        if (opts->new_branch_log && !log_all_ref_updates) {
                                int temp;
-                               char log_file[PATH_MAX];
-                               char *ref_name = mkpath("refs/heads/%s", opts->new_orphan_branch);
+                               struct strbuf log_file = STRBUF_INIT;
+                               int ret;
+                               const char *ref_name;
 
+                               ref_name = mkpath("refs/heads/%s", opts->new_orphan_branch);
                                temp = log_all_ref_updates;
                                log_all_ref_updates = 1;
-                               if (log_ref_setup(ref_name, log_file, sizeof(log_file))) {
+                               ret = log_ref_setup(ref_name, &log_file);
+                               log_all_ref_updates = temp;
+                               strbuf_release(&log_file);
+                               if (ret) {
                                        fprintf(stderr, _("Can not do reflog for '%s'\n"),
                                            opts->new_orphan_branch);
-                                       log_all_ref_updates = temp;
                                        return;
                                }
-                               log_all_ref_updates = temp;
                        }
                }
                else
@@ -743,10 +760,17 @@ static void suggest_reattach(struct commit *commit, struct rev_info *revs)
 
        if (advice_detached_head)
                fprintf(stderr,
-                       _(
+                       Q_(
+                       /* The singular version */
+                       "If you want to keep it by creating a new branch, "
+                       "this may be a good time\nto do so with:\n\n"
+                       " git branch <new-branch-name> %s\n\n",
+                       /* The plural version */
                        "If you want to keep them by creating a new branch, "
                        "this may be a good time\nto do so with:\n\n"
-                       " git branch <new-branch-name> %s\n\n"),
+                       " git branch <new-branch-name> %s\n\n",
+                       /* Give ngettext() the count */
+                       lost),
                        find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV));
 }
 
@@ -815,7 +839,8 @@ static int switch_branches(const struct checkout_opts *opts,
                return ret;
        }
 
-       if (!opts->quiet && !old.path && old.commit && new->commit != old.commit)
+       if (!opts->quiet && !old.path && old.commit &&
+           new->commit != old.commit && !opts->new_worktree_mode)
                orphaned_commit_warning(old.commit, new->commit);
 
        update_refs_for_switch(opts, &old, new);
@@ -825,6 +850,138 @@ static int switch_branches(const struct checkout_opts *opts,
        return ret || writeout_error;
 }
 
+static char *junk_work_tree;
+static char *junk_git_dir;
+static int is_junk;
+static pid_t junk_pid;
+
+static void remove_junk(void)
+{
+       struct strbuf sb = STRBUF_INIT;
+       if (!is_junk || getpid() != junk_pid)
+               return;
+       if (junk_git_dir) {
+               strbuf_addstr(&sb, junk_git_dir);
+               remove_dir_recursively(&sb, 0);
+               strbuf_reset(&sb);
+       }
+       if (junk_work_tree) {
+               strbuf_addstr(&sb, junk_work_tree);
+               remove_dir_recursively(&sb, 0);
+       }
+       strbuf_release(&sb);
+}
+
+static void remove_junk_on_signal(int signo)
+{
+       remove_junk();
+       sigchain_pop(signo);
+       raise(signo);
+}
+
+static int prepare_linked_checkout(const struct checkout_opts *opts,
+                                  struct branch_info *new)
+{
+       struct strbuf sb_git = STRBUF_INIT, sb_repo = STRBUF_INIT;
+       struct strbuf sb = STRBUF_INIT;
+       const char *path = opts->new_worktree, *name;
+       struct stat st;
+       struct child_process cp;
+       int counter = 0, len, ret;
+
+       if (!new->commit)
+               die(_("no branch specified"));
+       if (file_exists(path) && !is_empty_dir(path))
+               die(_("'%s' already exists"), path);
+
+       len = strlen(path);
+       while (len && is_dir_sep(path[len - 1]))
+               len--;
+
+       for (name = path + len - 1; name > path; name--)
+               if (is_dir_sep(*name)) {
+                       name++;
+                       break;
+               }
+       strbuf_addstr(&sb_repo,
+                     git_path("worktrees/%.*s", (int)(path + len - name), name));
+       len = sb_repo.len;
+       if (safe_create_leading_directories_const(sb_repo.buf))
+               die_errno(_("could not create leading directories of '%s'"),
+                         sb_repo.buf);
+       while (!stat(sb_repo.buf, &st)) {
+               counter++;
+               strbuf_setlen(&sb_repo, len);
+               strbuf_addf(&sb_repo, "%d", counter);
+       }
+       name = strrchr(sb_repo.buf, '/') + 1;
+
+       junk_pid = getpid();
+       atexit(remove_junk);
+       sigchain_push_common(remove_junk_on_signal);
+
+       if (mkdir(sb_repo.buf, 0777))
+               die_errno(_("could not create directory of '%s'"), sb_repo.buf);
+       junk_git_dir = xstrdup(sb_repo.buf);
+       is_junk = 1;
+
+       /*
+        * lock the incomplete repo so prune won't delete it, unlock
+        * after the preparation is over.
+        */
+       strbuf_addf(&sb, "%s/locked", sb_repo.buf);
+       write_file(sb.buf, 1, "initializing\n");
+
+       strbuf_addf(&sb_git, "%s/.git", path);
+       if (safe_create_leading_directories_const(sb_git.buf))
+               die_errno(_("could not create leading directories of '%s'"),
+                         sb_git.buf);
+       junk_work_tree = xstrdup(path);
+
+       strbuf_reset(&sb);
+       strbuf_addf(&sb, "%s/gitdir", sb_repo.buf);
+       write_file(sb.buf, 1, "%s\n", real_path(sb_git.buf));
+       write_file(sb_git.buf, 1, "gitdir: %s/worktrees/%s\n",
+                  real_path(get_git_common_dir()), name);
+       /*
+        * This is to keep resolve_ref() happy. We need a valid HEAD
+        * or is_git_directory() will reject the directory. Any valid
+        * value would do because this value will be ignored and
+        * replaced at the next (real) checkout.
+        */
+       strbuf_reset(&sb);
+       strbuf_addf(&sb, "%s/HEAD", sb_repo.buf);
+       write_file(sb.buf, 1, "%s\n", sha1_to_hex(new->commit->object.sha1));
+       strbuf_reset(&sb);
+       strbuf_addf(&sb, "%s/commondir", sb_repo.buf);
+       write_file(sb.buf, 1, "../..\n");
+
+       if (!opts->quiet)
+               fprintf_ln(stderr, _("Enter %s (identifier %s)"), path, name);
+
+       setenv("GIT_CHECKOUT_NEW_WORKTREE", "1", 1);
+       setenv(GIT_DIR_ENVIRONMENT, sb_git.buf, 1);
+       setenv(GIT_WORK_TREE_ENVIRONMENT, path, 1);
+       memset(&cp, 0, sizeof(cp));
+       cp.git_cmd = 1;
+       cp.argv = opts->saved_argv;
+       ret = run_command(&cp);
+       if (!ret) {
+               is_junk = 0;
+               free(junk_work_tree);
+               free(junk_git_dir);
+               junk_work_tree = NULL;
+               junk_git_dir = NULL;
+       }
+       strbuf_reset(&sb);
+       strbuf_addf(&sb, "%s/locked", sb_repo.buf);
+       unlink_or_warn(sb.buf);
+       strbuf_release(&sb);
+       strbuf_release(&sb_repo);
+       strbuf_release(&sb_git);
+       return ret;
+}
+
 static int git_checkout_config(const char *var, const char *value, void *cb)
 {
        if (!strcmp(var, "diff.ignoresubmodules")) {
@@ -880,13 +1037,80 @@ static const char *unique_tracking_name(const char *name, unsigned char *sha1)
        return NULL;
 }
 
+static void check_linked_checkout(struct branch_info *new, const char *id)
+{
+       struct strbuf sb = STRBUF_INIT;
+       struct strbuf path = STRBUF_INIT;
+       struct strbuf gitdir = STRBUF_INIT;
+       const char *start, *end;
+
+       if (id)
+               strbuf_addf(&path, "%s/worktrees/%s/HEAD", get_git_common_dir(), id);
+       else
+               strbuf_addf(&path, "%s/HEAD", get_git_common_dir());
+
+       if (strbuf_read_file(&sb, path.buf, 0) < 0 ||
+           !skip_prefix(sb.buf, "ref:", &start))
+               goto done;
+       while (isspace(*start))
+               start++;
+       end = start;
+       while (*end && !isspace(*end))
+               end++;
+       if (strncmp(start, new->path, end - start) || new->path[end - start] != '\0')
+               goto done;
+       if (id) {
+               strbuf_reset(&path);
+               strbuf_addf(&path, "%s/worktrees/%s/gitdir", get_git_common_dir(), id);
+               if (strbuf_read_file(&gitdir, path.buf, 0) <= 0)
+                       goto done;
+               strbuf_rtrim(&gitdir);
+       } else
+               strbuf_addstr(&gitdir, get_git_common_dir());
+       die(_("'%s' is already checked out at '%s'"), new->name, gitdir.buf);
+done:
+       strbuf_release(&path);
+       strbuf_release(&sb);
+       strbuf_release(&gitdir);
+}
+
+static void check_linked_checkouts(struct branch_info *new)
+{
+       struct strbuf path = STRBUF_INIT;
+       DIR *dir;
+       struct dirent *d;
+
+       strbuf_addf(&path, "%s/worktrees", get_git_common_dir());
+       if ((dir = opendir(path.buf)) == NULL) {
+               strbuf_release(&path);
+               return;
+       }
+
+       /*
+        * $GIT_COMMON_DIR/HEAD is practically outside
+        * $GIT_DIR so resolve_ref_unsafe() won't work (it
+        * uses git_path). Parse the ref ourselves.
+        */
+       check_linked_checkout(new, NULL);
+
+       while ((d = readdir(dir)) != NULL) {
+               if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
+                       continue;
+               check_linked_checkout(new, d->d_name);
+       }
+       strbuf_release(&path);
+       closedir(dir);
+}
+
 static int parse_branchname_arg(int argc, const char **argv,
                                int dwim_new_local_branch_ok,
                                struct branch_info *new,
-                               struct tree **source_tree,
-                               unsigned char rev[20],
-                               const char **new_branch)
+                               struct checkout_opts *opts,
+                               unsigned char rev[20])
 {
+       struct tree **source_tree = &opts->source_tree;
+       const char **new_branch = &opts->new_branch;
+       int force_detach = opts->force_detach;
        int argcount = 0;
        unsigned char branch_rev[20];
        const char *arg;
@@ -1007,6 +1231,17 @@ static int parse_branchname_arg(int argc, const char **argv,
        else
                new->path = NULL; /* not an existing branch */
 
+       if (new->path && !force_detach && !*new_branch) {
+               unsigned char sha1[20];
+               int flag;
+               char *head_ref = resolve_refdup("HEAD", 0, sha1, &flag);
+               if (head_ref &&
+                   (!(flag & REF_ISSYMREF) || strcmp(head_ref, new->path)) &&
+                   !opts->ignore_other_worktrees)
+                       check_linked_checkouts(new);
+               free(head_ref);
+       }
+
        new->commit = lookup_commit_reference_gently(rev, 1);
        if (!new->commit) {
                /* not a commit */
@@ -1086,6 +1321,9 @@ static int checkout_branch(struct checkout_opts *opts,
                die(_("Cannot switch branch to a non-commit '%s'"),
                    new->name);
 
+       if (opts->new_worktree)
+               return prepare_linked_checkout(opts, new);
+
        if (!new->commit && opts->new_branch) {
                unsigned char rev[20];
                int flag;
@@ -1128,6 +1366,10 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
                         N_("do not limit pathspecs to sparse entries only")),
                OPT_HIDDEN_BOOL(0, "guess", &dwim_new_local_branch,
                                N_("second guess 'git checkout <no-such-branch>'")),
+               OPT_FILENAME(0, "to", &opts.new_worktree,
+                          N_("check a branch out in a separate working directory")),
+               OPT_BOOL(0, "ignore-other-worktrees", &opts.ignore_other_worktrees,
+                        N_("do not check if another worktree is holding the given ref")),
                OPT_END(),
        };
 
@@ -1136,6 +1378,9 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
        opts.overwrite_ignore = 1;
        opts.prefix = prefix;
 
+       opts.saved_argv = xmalloc(sizeof(const char *) * (argc + 2));
+       memcpy(opts.saved_argv, argv, sizeof(const char *) * (argc + 1));
+
        gitmodules_config();
        git_config(git_checkout_config, &opts);
 
@@ -1144,6 +1389,14 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
        argc = parse_options(argc, argv, prefix, options, checkout_usage,
                             PARSE_OPT_KEEP_DASHDASH);
 
+       /* recursive execution from checkout_new_worktree() */
+       opts.new_worktree_mode = getenv("GIT_CHECKOUT_NEW_WORKTREE") != NULL;
+       if (opts.new_worktree_mode)
+               opts.new_worktree = NULL;
+
+       if (!opts.new_worktree)
+               setup_work_tree();
+
        if (conflict_style) {
                opts.merge = 1; /* implied */
                git_xmerge_config("merge.conflictstyle", conflict_style, NULL);
@@ -1197,8 +1450,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
                        opts.track == BRANCH_TRACK_UNSPECIFIED &&
                        !opts.new_branch;
                int n = parse_branchname_arg(argc, argv, dwim_ok,
-                                            &new, &opts.source_tree,
-                                            rev, &opts.new_branch);
+                                            &new, &opts, rev);
                argv += n;
                argc -= n;
        }
index 53a2e5af35ebfc37b378442a238f1894e5bec962..b878252bc2e64bbe95adbae5554618f017c9ac85 100644 (file)
@@ -293,16 +293,17 @@ static void copy_alternates(struct strbuf *src, struct strbuf *dst,
        struct strbuf line = STRBUF_INIT;
 
        while (strbuf_getline(&line, in, '\n') != EOF) {
-               char *abs_path, abs_buf[PATH_MAX];
+               char *abs_path;
                if (!line.len || line.buf[0] == '#')
                        continue;
                if (is_absolute_path(line.buf)) {
                        add_to_alternates_file(line.buf);
                        continue;
                }
-               abs_path = mkpath("%s/objects/%s", src_repo, line.buf);
-               normalize_path_copy(abs_buf, abs_path);
-               add_to_alternates_file(abs_buf);
+               abs_path = mkpathdup("%s/objects/%s", src_repo, line.buf);
+               normalize_path_copy(abs_path, abs_path);
+               add_to_alternates_file(abs_path);
+               free(abs_path);
        }
        strbuf_release(&line);
        fclose(in);
@@ -906,6 +907,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 
        remote = remote_get(option_origin);
        transport = transport_get(remote, remote->url[0]);
+       transport_set_verbosity(transport, option_verbosity, option_progress);
+
        path = get_repo_path(remote->url[0], &is_bundle);
        is_local = option_local != 0 && path && !is_bundle;
        if (is_local) {
@@ -932,8 +935,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
        if (option_single_branch)
                transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, "1");
 
-       transport_set_verbosity(transport, option_verbosity, option_progress);
-
        if (option_upload_pack)
                transport_set_option(transport, TRANS_OPT_UPLOADPACK,
                                     option_upload_pack);
index da79ac4bc7a7247017e2f952b35642a1976c8101..254477fd1d4e8b96f50eb42dc11ec1253c7467f8 100644 (file)
@@ -170,7 +170,7 @@ static void determine_whence(struct wt_status *s)
                whence = FROM_MERGE;
        else if (file_exists(git_path("CHERRY_PICK_HEAD"))) {
                whence = FROM_CHERRY_PICK;
-               if (file_exists(git_path("sequencer")))
+               if (file_exists(git_path(SEQ_DIR)))
                        sequencer_in_use = 1;
        }
        else
@@ -1366,13 +1366,14 @@ int cmd_status(int argc, const char **argv, const char *prefix)
        refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &s.pathspec, NULL, NULL);
 
        fd = hold_locked_index(&index_lock, 0);
-       if (0 <= fd)
-               update_index_if_able(&the_index, &index_lock);
 
        s.is_initial = get_sha1(s.reference, sha1) ? 1 : 0;
        s.ignore_submodule_arg = ignore_submodule_arg;
        wt_status_collect(&s);
 
+       if (0 <= fd)
+               update_index_if_able(&the_index, &index_lock);
+
        if (s.relative_paths)
                s.prefix = prefix;
 
@@ -1398,12 +1399,10 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 
 static const char *implicit_ident_advice(void)
 {
-       char *user_config = NULL;
-       char *xdg_config = NULL;
-       int config_exists;
+       char *user_config = expand_user_path("~/.gitconfig");
+       char *xdg_config = xdg_config_home("config");
+       int config_exists = file_exists(user_config) || file_exists(xdg_config);
 
-       home_config_paths(&user_config, &xdg_config, "config");
-       config_exists = file_exists(user_config) || file_exists(xdg_config);
        free(user_config);
        free(xdg_config);
 
index bfd3016e83f3fd4e5f4f2ec8f4d6f4c5a24e711f..7188405f7ef587d7b09b1cf2c6e422c8385ed794 100644 (file)
@@ -193,7 +193,7 @@ static int get_value(const char *key_, const char *regex_)
 
                key_regexp = (regex_t*)xmalloc(sizeof(regex_t));
                if (regcomp(key_regexp, key, REG_EXTENDED)) {
-                       fprintf(stderr, "Invalid key pattern: %s\n", key_);
+                       error("invalid key pattern: %s", key_);
                        free(key_regexp);
                        key_regexp = NULL;
                        ret = CONFIG_INVALID_PATTERN;
@@ -214,7 +214,7 @@ static int get_value(const char *key_, const char *regex_)
 
                regexp = (regex_t*)xmalloc(sizeof(regex_t));
                if (regcomp(regexp, regex_, REG_EXTENDED)) {
-                       fprintf(stderr, "Invalid pattern: %s\n", regex_);
+                       error("invalid pattern: %s", regex_);
                        free(regexp);
                        regexp = NULL;
                        ret = CONFIG_INVALID_PATTERN;
@@ -488,10 +488,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
        }
 
        if (use_global_config) {
-               char *user_config = NULL;
-               char *xdg_config = NULL;
-
-               home_config_paths(&user_config, &xdg_config, "config");
+               char *user_config = expand_user_path("~/.gitconfig");
+               char *xdg_config = xdg_config_home("config");
 
                if (!user_config)
                        /*
index e47ef0b1af06a1abd63f7818c363db6c859a9bf6..ad0c79954aa0dfb8b9918500d08dd841d19d4ab3 100644 (file)
@@ -70,8 +70,10 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
        /* we do not take arguments other than flags for now */
        if (argc)
                usage_with_options(count_objects_usage, opts);
-       if (verbose)
+       if (verbose) {
                report_garbage = real_report_garbage;
+               report_linked_checkout_garbage();
+       }
 
        for_each_loose_file_in_objdir(get_object_directory(),
                                      count_loose, count_cruft, NULL, NULL);
index f9512652cf1389a770bd94fd170d123206e024c5..7910419c93275c58f4881202905ae1f24bfe8c91 100644 (file)
@@ -588,7 +588,8 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
        struct strbuf note = STRBUF_INIT;
        const char *what, *kind;
        struct ref *rm;
-       char *url, *filename = dry_run ? "/dev/null" : git_path("FETCH_HEAD");
+       char *url;
+       const char *filename = dry_run ? "/dev/null" : git_path("FETCH_HEAD");
        int want_status;
 
        fp = fopen(filename, "a");
@@ -822,7 +823,7 @@ static void check_not_current_branch(struct ref *ref_map)
 
 static int truncate_fetch_head(void)
 {
-       char *filename = git_path("FETCH_HEAD");
+       const char *filename = git_path("FETCH_HEAD");
        FILE *fp = fopen(filename, "w");
 
        if (!fp)
index 1d962dc569eaafc8429c4cec815922f382c576b9..05f4c263112ae94978e4961988e9a4805fde2427 100644 (file)
@@ -223,16 +223,14 @@ static void add_branch_desc(struct strbuf *out, const char *name)
 
 #define util_as_integral(elem) ((intptr_t)((elem)->util))
 
-static void record_person(int which, struct string_list *people,
-                         struct commit *commit)
+static void record_person_from_buf(int which, struct string_list *people,
+                                  const char *buffer)
 {
-       const char *buffer;
        char *name_buf, *name, *name_end;
        struct string_list_item *elem;
        const char *field;
 
        field = (which == 'a') ? "\nauthor " : "\ncommitter ";
-       buffer = get_commit_buffer(commit, NULL);
        name = strstr(buffer, field);
        if (!name)
                return;
@@ -245,7 +243,6 @@ 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) {
@@ -256,6 +253,15 @@ static void record_person(int which, struct string_list *people,
        free(name_buf);
 }
 
+
+static void record_person(int which, struct string_list *people,
+                         struct commit *commit)
+{
+       const char *buffer = get_commit_buffer(commit, NULL);
+       record_person_from_buf(which, people, buffer);
+       unuse_commit_buffer(commit, buffer);
+}
+
 static int cmp_string_list_util_as_integral(const void *a_, const void *b_)
 {
        const struct string_list_item *a = a_, *b = b_;
index 0c757862e8cd414c087b27a608281b66c8608a4b..4783896fd65f0206f3382bddc68a0dad8b5dd896 100644 (file)
@@ -225,12 +225,12 @@ static void check_unreachable_object(struct object *obj)
                        printf("dangling %s %s\n", typename(obj->type),
                               sha1_to_hex(obj->sha1));
                if (write_lost_and_found) {
-                       char *filename = git_path("lost-found/%s/%s",
+                       const char *filename = git_path("lost-found/%s/%s",
                                obj->type == OBJ_COMMIT ? "commit" : "other",
                                sha1_to_hex(obj->sha1));
                        FILE *f;
 
-                       if (safe_create_leading_directories(filename)) {
+                       if (safe_create_leading_directories_const(filename)) {
                                error("Could not create lost-found");
                                return;
                        }
index 5c634afc0022c0ea7a8cd8c81727935ad79a6333..36fe33300f644fc9c7e5139b452a9703548ba2a2 100644 (file)
@@ -33,11 +33,13 @@ static int gc_auto_threshold = 6700;
 static int gc_auto_pack_limit = 50;
 static int detach_auto = 1;
 static const char *prune_expire = "2.weeks.ago";
+static const char *prune_worktrees_expire = "3.months.ago";
 
 static struct argv_array pack_refs_cmd = ARGV_ARRAY_INIT;
 static struct argv_array reflog = ARGV_ARRAY_INIT;
 static struct argv_array repack = ARGV_ARRAY_INIT;
 static struct argv_array prune = ARGV_ARRAY_INIT;
+static struct argv_array prune_worktrees = ARGV_ARRAY_INIT;
 static struct argv_array rerere = ARGV_ARRAY_INIT;
 
 static char *pidfile;
@@ -55,6 +57,17 @@ static void remove_pidfile_on_signal(int signo)
        raise(signo);
 }
 
+static void git_config_date_string(const char *key, const char **output)
+{
+       if (git_config_get_string_const(key, output))
+               return;
+       if (strcmp(*output, "now")) {
+               unsigned long now = approxidate("now");
+               if (approxidate(*output) >= now)
+                       git_die_config(key, _("Invalid %s: '%s'"), key, *output);
+       }
+}
+
 static void gc_config(void)
 {
        const char *value;
@@ -71,16 +84,8 @@ static void gc_config(void)
        git_config_get_int("gc.auto", &gc_auto_threshold);
        git_config_get_int("gc.autopacklimit", &gc_auto_pack_limit);
        git_config_get_bool("gc.autodetach", &detach_auto);
-
-       if (!git_config_get_string_const("gc.pruneexpire", &prune_expire)) {
-               if (strcmp(prune_expire, "now")) {
-                       unsigned long now = approxidate("now");
-                       if (approxidate(prune_expire) >= now) {
-                               git_die_config("gc.pruneexpire", _("Invalid gc.pruneexpire: '%s'"),
-                                               prune_expire);
-                       }
-               }
-       }
+       git_config_date_string("gc.pruneexpire", &prune_expire);
+       git_config_date_string("gc.pruneworktreesexpire", &prune_worktrees_expire);
        git_config(git_default_config, NULL);
 }
 
@@ -287,7 +292,8 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
        argv_array_pushl(&pack_refs_cmd, "pack-refs", "--all", "--prune", NULL);
        argv_array_pushl(&reflog, "reflog", "expire", "--all", NULL);
        argv_array_pushl(&repack, "repack", "-d", "-l", NULL);
-       argv_array_pushl(&prune, "prune", "--expire", NULL );
+       argv_array_pushl(&prune, "prune", "--expire", NULL);
+       argv_array_pushl(&prune_worktrees, "prune", "--worktrees", "--expire", NULL);
        argv_array_pushl(&rerere, "rerere", "gc", NULL);
 
        gc_config();
@@ -357,6 +363,12 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
                        return error(FAILED_RUN, prune.argv[0]);
        }
 
+       if (prune_worktrees_expire) {
+               argv_array_push(&prune_worktrees, prune_worktrees_expire);
+               if (run_command_v_opt(prune_worktrees.argv, RUN_GIT_CMD))
+                       return error(FAILED_RUN, prune_worktrees.argv[0]);
+       }
+
        if (run_command_v_opt(rerere.argv, RUN_GIT_CMD))
                return error(FAILED_RUN, rerere.argv[0]);
 
index cf654df09b3734063f415b2b735f3062706f75a0..7ea2020d821004569a6913d9cf550149032a1b96 100644 (file)
@@ -18,16 +18,14 @@ static const char index_pack_usage[] =
 struct object_entry {
        struct pack_idx_entry idx;
        unsigned long size;
-       unsigned int hdr_size;
-       enum object_type type;
-       enum object_type real_type;
-       unsigned delta_depth;
-       int base_object_no;
+       unsigned char hdr_size;
+       signed char type;
+       signed char real_type;
 };
 
-union delta_base {
-       unsigned char sha1[20];
-       off_t offset;
+struct object_stat {
+       unsigned delta_depth;
+       int base_object_no;
 };
 
 struct base_data {
@@ -49,25 +47,28 @@ struct thread_local {
        int pack_fd;
 };
 
-/*
- * Even if sizeof(union delta_base) == 24 on 64-bit archs, we really want
- * to memcmp() only the first 20 bytes.
- */
-#define UNION_BASE_SZ  20
-
 #define FLAG_LINK (1u<<20)
 #define FLAG_CHECKED (1u<<21)
 
-struct delta_entry {
-       union delta_base base;
+struct ofs_delta_entry {
+       off_t offset;
+       int obj_no;
+};
+
+struct ref_delta_entry {
+       unsigned char sha1[20];
        int obj_no;
 };
 
 static struct object_entry *objects;
-static struct delta_entry *deltas;
+static struct object_stat *obj_stat;
+static struct ofs_delta_entry *ofs_deltas;
+static struct ref_delta_entry *ref_deltas;
 static struct thread_local nothread_data;
 static int nr_objects;
-static int nr_deltas;
+static int nr_ofs_deltas;
+static int nr_ref_deltas;
+static int ref_deltas_alloc;
 static int nr_resolved_deltas;
 static int nr_threads;
 
@@ -476,7 +477,8 @@ static void *unpack_entry_data(unsigned long offset, unsigned long size,
 }
 
 static void *unpack_raw_entry(struct object_entry *obj,
-                             union delta_base *delta_base,
+                             off_t *ofs_offset,
+                             unsigned char *ref_sha1,
                              unsigned char *sha1)
 {
        unsigned char *p;
@@ -505,11 +507,10 @@ static void *unpack_raw_entry(struct object_entry *obj,
 
        switch (obj->type) {
        case OBJ_REF_DELTA:
-               hashcpy(delta_base->sha1, fill(20));
+               hashcpy(ref_sha1, fill(20));
                use(20);
                break;
        case OBJ_OFS_DELTA:
-               memset(delta_base, 0, sizeof(*delta_base));
                p = fill(1);
                c = *p;
                use(1);
@@ -523,8 +524,8 @@ static void *unpack_raw_entry(struct object_entry *obj,
                        use(1);
                        base_offset = (base_offset << 7) + (c & 127);
                }
-               delta_base->offset = obj->idx.offset - base_offset;
-               if (delta_base->offset <= 0 || delta_base->offset >= obj->idx.offset)
+               *ofs_offset = obj->idx.offset - base_offset;
+               if (*ofs_offset <= 0 || *ofs_offset >= obj->idx.offset)
                        bad_object(obj->idx.offset, _("delta base offset is out of bound"));
                break;
        case OBJ_COMMIT:
@@ -608,55 +609,108 @@ static void *get_data_from_pack(struct object_entry *obj)
        return unpack_data(obj, NULL, NULL);
 }
 
-static int compare_delta_bases(const union delta_base *base1,
-                              const union delta_base *base2,
-                              enum object_type type1,
-                              enum object_type type2)
+static int compare_ofs_delta_bases(off_t offset1, off_t offset2,
+                                  enum object_type type1,
+                                  enum object_type type2)
 {
        int cmp = type1 - type2;
        if (cmp)
                return cmp;
-       return memcmp(base1, base2, UNION_BASE_SZ);
+       return offset1 - offset2;
 }
 
-static int find_delta(const union delta_base *base, enum object_type type)
+static int find_ofs_delta(const off_t offset, enum object_type type)
 {
-       int first = 0, last = nr_deltas;
-
-        while (first < last) {
-                int next = (first + last) / 2;
-                struct delta_entry *delta = &deltas[next];
-                int cmp;
-
-               cmp = compare_delta_bases(base, &delta->base,
-                                         type, objects[delta->obj_no].type);
-                if (!cmp)
-                        return next;
-                if (cmp < 0) {
-                        last = next;
-                        continue;
-                }
-                first = next+1;
-        }
-        return -first-1;
+       int first = 0, last = nr_ofs_deltas;
+
+       while (first < last) {
+               int next = (first + last) / 2;
+               struct ofs_delta_entry *delta = &ofs_deltas[next];
+               int cmp;
+
+               cmp = compare_ofs_delta_bases(offset, delta->offset,
+                                             type, objects[delta->obj_no].type);
+               if (!cmp)
+                       return next;
+               if (cmp < 0) {
+                       last = next;
+                       continue;
+               }
+               first = next+1;
+       }
+       return -first-1;
 }
 
-static void find_delta_children(const union delta_base *base,
-                               int *first_index, int *last_index,
-                               enum object_type type)
+static void find_ofs_delta_children(off_t offset,
+                                   int *first_index, int *last_index,
+                                   enum object_type type)
 {
-       int first = find_delta(base, type);
+       int first = find_ofs_delta(offset, type);
        int last = first;
-       int end = nr_deltas - 1;
+       int end = nr_ofs_deltas - 1;
 
        if (first < 0) {
                *first_index = 0;
                *last_index = -1;
                return;
        }
-       while (first > 0 && !memcmp(&deltas[first - 1].base, base, UNION_BASE_SZ))
+       while (first > 0 && ofs_deltas[first - 1].offset == offset)
                --first;
-       while (last < end && !memcmp(&deltas[last + 1].base, base, UNION_BASE_SZ))
+       while (last < end && ofs_deltas[last + 1].offset == offset)
+               ++last;
+       *first_index = first;
+       *last_index = last;
+}
+
+static int compare_ref_delta_bases(const unsigned char *sha1,
+                                  const unsigned char *sha2,
+                                  enum object_type type1,
+                                  enum object_type type2)
+{
+       int cmp = type1 - type2;
+       if (cmp)
+               return cmp;
+       return hashcmp(sha1, sha2);
+}
+
+static int find_ref_delta(const unsigned char *sha1, enum object_type type)
+{
+       int first = 0, last = nr_ref_deltas;
+
+       while (first < last) {
+               int next = (first + last) / 2;
+               struct ref_delta_entry *delta = &ref_deltas[next];
+               int cmp;
+
+               cmp = compare_ref_delta_bases(sha1, delta->sha1,
+                                             type, objects[delta->obj_no].type);
+               if (!cmp)
+                       return next;
+               if (cmp < 0) {
+                       last = next;
+                       continue;
+               }
+               first = next+1;
+       }
+       return -first-1;
+}
+
+static void find_ref_delta_children(const unsigned char *sha1,
+                                   int *first_index, int *last_index,
+                                   enum object_type type)
+{
+       int first = find_ref_delta(sha1, type);
+       int last = first;
+       int end = nr_ref_deltas - 1;
+
+       if (first < 0) {
+               *first_index = 0;
+               *last_index = -1;
+               return;
+       }
+       while (first > 0 && !hashcmp(ref_deltas[first - 1].sha1, sha1))
+               --first;
+       while (last < end && !hashcmp(ref_deltas[last + 1].sha1, sha1))
                ++last;
        *first_index = first;
        *last_index = last;
@@ -873,13 +927,15 @@ static void resolve_delta(struct object_entry *delta_obj,
        void *base_data, *delta_data;
 
        if (show_stat) {
-               delta_obj->delta_depth = base->obj->delta_depth + 1;
+               int i = delta_obj - objects;
+               int j = base->obj - objects;
+               obj_stat[i].delta_depth = obj_stat[j].delta_depth + 1;
                deepest_delta_lock();
-               if (deepest_delta < delta_obj->delta_depth)
-                       deepest_delta = delta_obj->delta_depth;
+               if (deepest_delta < obj_stat[i].delta_depth)
+                       deepest_delta = obj_stat[i].delta_depth;
                deepest_delta_unlock();
+               obj_stat[i].base_object_no = j;
        }
-       delta_obj->base_object_no = base->obj - objects;
        delta_data = get_data_from_pack(delta_obj);
        base_data = get_base_data(base);
        result->obj = delta_obj;
@@ -902,7 +958,7 @@ static void resolve_delta(struct object_entry *delta_obj,
  * "want"; if so, swap in "set" and return true. Otherwise, leave it untouched
  * and return false.
  */
-static int compare_and_swap_type(enum object_type *type,
+static int compare_and_swap_type(signed char *type,
                                 enum object_type want,
                                 enum object_type set)
 {
@@ -921,16 +977,13 @@ static struct base_data *find_unresolved_deltas_1(struct base_data *base,
                                                  struct base_data *prev_base)
 {
        if (base->ref_last == -1 && base->ofs_last == -1) {
-               union delta_base base_spec;
+               find_ref_delta_children(base->obj->idx.sha1,
+                                       &base->ref_first, &base->ref_last,
+                                       OBJ_REF_DELTA);
 
-               hashcpy(base_spec.sha1, base->obj->idx.sha1);
-               find_delta_children(&base_spec,
-                                   &base->ref_first, &base->ref_last, OBJ_REF_DELTA);
-
-               memset(&base_spec, 0, sizeof(base_spec));
-               base_spec.offset = base->obj->idx.offset;
-               find_delta_children(&base_spec,
-                                   &base->ofs_first, &base->ofs_last, OBJ_OFS_DELTA);
+               find_ofs_delta_children(base->obj->idx.offset,
+                                       &base->ofs_first, &base->ofs_last,
+                                       OBJ_OFS_DELTA);
 
                if (base->ref_last == -1 && base->ofs_last == -1) {
                        free(base->data);
@@ -941,7 +994,7 @@ static struct base_data *find_unresolved_deltas_1(struct base_data *base,
        }
 
        if (base->ref_first <= base->ref_last) {
-               struct object_entry *child = objects + deltas[base->ref_first].obj_no;
+               struct object_entry *child = objects + ref_deltas[base->ref_first].obj_no;
                struct base_data *result = alloc_base_data();
 
                if (!compare_and_swap_type(&child->real_type, OBJ_REF_DELTA,
@@ -957,7 +1010,7 @@ static struct base_data *find_unresolved_deltas_1(struct base_data *base,
        }
 
        if (base->ofs_first <= base->ofs_last) {
-               struct object_entry *child = objects + deltas[base->ofs_first].obj_no;
+               struct object_entry *child = objects + ofs_deltas[base->ofs_first].obj_no;
                struct base_data *result = alloc_base_data();
 
                assert(child->real_type == OBJ_OFS_DELTA);
@@ -993,15 +1046,20 @@ static void find_unresolved_deltas(struct base_data *base)
        }
 }
 
-static int compare_delta_entry(const void *a, const void *b)
+static int compare_ofs_delta_entry(const void *a, const void *b)
 {
-       const struct delta_entry *delta_a = a;
-       const struct delta_entry *delta_b = b;
+       const struct ofs_delta_entry *delta_a = a;
+       const struct ofs_delta_entry *delta_b = b;
 
-       /* group by type (ref vs ofs) and then by value (sha-1 or offset) */
-       return compare_delta_bases(&delta_a->base, &delta_b->base,
-                                  objects[delta_a->obj_no].type,
-                                  objects[delta_b->obj_no].type);
+       return delta_a->offset - delta_b->offset;
+}
+
+static int compare_ref_delta_entry(const void *a, const void *b)
+{
+       const struct ref_delta_entry *delta_a = a;
+       const struct ref_delta_entry *delta_b = b;
+
+       return hashcmp(delta_a->sha1, delta_b->sha1);
 }
 
 static void resolve_base(struct object_entry *obj)
@@ -1047,7 +1105,8 @@ static void *threaded_second_pass(void *data)
 static void parse_pack_objects(unsigned char *sha1)
 {
        int i, nr_delays = 0;
-       struct delta_entry *delta = deltas;
+       struct ofs_delta_entry *ofs_delta = ofs_deltas;
+       unsigned char ref_delta_sha1[20];
        struct stat st;
 
        if (verbose)
@@ -1056,12 +1115,18 @@ static void parse_pack_objects(unsigned char *sha1)
                                nr_objects);
        for (i = 0; i < nr_objects; i++) {
                struct object_entry *obj = &objects[i];
-               void *data = unpack_raw_entry(obj, &delta->base, obj->idx.sha1);
+               void *data = unpack_raw_entry(obj, &ofs_delta->offset,
+                                             ref_delta_sha1, obj->idx.sha1);
                obj->real_type = obj->type;
-               if (is_delta_type(obj->type)) {
-                       nr_deltas++;
-                       delta->obj_no = i;
-                       delta++;
+               if (obj->type == OBJ_OFS_DELTA) {
+                       nr_ofs_deltas++;
+                       ofs_delta->obj_no = i;
+                       ofs_delta++;
+               } else if (obj->type == OBJ_REF_DELTA) {
+                       ALLOC_GROW(ref_deltas, nr_ref_deltas + 1, ref_deltas_alloc);
+                       hashcpy(ref_deltas[nr_ref_deltas].sha1, ref_delta_sha1);
+                       ref_deltas[nr_ref_deltas].obj_no = i;
+                       nr_ref_deltas++;
                } else if (!data) {
                        /* large blobs, check later */
                        obj->real_type = OBJ_BAD;
@@ -1112,15 +1177,18 @@ static void resolve_deltas(void)
 {
        int i;
 
-       if (!nr_deltas)
+       if (!nr_ofs_deltas && !nr_ref_deltas)
                return;
 
        /* Sort deltas by base SHA1/offset for fast searching */
-       qsort(deltas, nr_deltas, sizeof(struct delta_entry),
-             compare_delta_entry);
+       qsort(ofs_deltas, nr_ofs_deltas, sizeof(struct ofs_delta_entry),
+             compare_ofs_delta_entry);
+       qsort(ref_deltas, nr_ref_deltas, sizeof(struct ref_delta_entry),
+             compare_ref_delta_entry);
 
        if (verbose)
-               progress = start_progress(_("Resolving deltas"), nr_deltas);
+               progress = start_progress(_("Resolving deltas"),
+                                         nr_ref_deltas + nr_ofs_deltas);
 
 #ifndef NO_PTHREADS
        nr_dispatched = 0;
@@ -1158,7 +1226,7 @@ static void resolve_deltas(void)
 static void fix_unresolved_deltas(struct sha1file *f, int nr_unresolved);
 static void conclude_pack(int fix_thin_pack, const char *curr_pack, unsigned char *pack_sha1)
 {
-       if (nr_deltas == nr_resolved_deltas) {
+       if (nr_ref_deltas + nr_ofs_deltas == nr_resolved_deltas) {
                stop_progress(&progress);
                /* Flush remaining pack final 20-byte SHA1. */
                flush();
@@ -1169,7 +1237,7 @@ static void conclude_pack(int fix_thin_pack, const char *curr_pack, unsigned cha
                struct sha1file *f;
                unsigned char read_sha1[20], tail_sha1[20];
                struct strbuf msg = STRBUF_INIT;
-               int nr_unresolved = nr_deltas - nr_resolved_deltas;
+               int nr_unresolved = nr_ofs_deltas + nr_ref_deltas - nr_resolved_deltas;
                int nr_objects_initial = nr_objects;
                if (nr_unresolved <= 0)
                        die(_("confusion beyond insanity"));
@@ -1191,11 +1259,11 @@ static void conclude_pack(int fix_thin_pack, const char *curr_pack, unsigned cha
                        die(_("Unexpected tail checksum for %s "
                              "(disk corruption?)"), curr_pack);
        }
-       if (nr_deltas != nr_resolved_deltas)
+       if (nr_ofs_deltas + nr_ref_deltas != nr_resolved_deltas)
                die(Q_("pack has %d unresolved delta",
                       "pack has %d unresolved deltas",
-                      nr_deltas - nr_resolved_deltas),
-                   nr_deltas - nr_resolved_deltas);
+                      nr_ofs_deltas + nr_ref_deltas - nr_resolved_deltas),
+                   nr_ofs_deltas + nr_ref_deltas - nr_resolved_deltas);
 }
 
 static int write_compressed(struct sha1file *f, void *in, unsigned int size)
@@ -1254,14 +1322,14 @@ static struct object_entry *append_obj_to_pack(struct sha1file *f,
 
 static int delta_pos_compare(const void *_a, const void *_b)
 {
-       struct delta_entry *a = *(struct delta_entry **)_a;
-       struct delta_entry *b = *(struct delta_entry **)_b;
+       struct ref_delta_entry *a = *(struct ref_delta_entry **)_a;
+       struct ref_delta_entry *b = *(struct ref_delta_entry **)_b;
        return a->obj_no - b->obj_no;
 }
 
 static void fix_unresolved_deltas(struct sha1file *f, int nr_unresolved)
 {
-       struct delta_entry **sorted_by_pos;
+       struct ref_delta_entry **sorted_by_pos;
        int i, n = 0;
 
        /*
@@ -1275,28 +1343,25 @@ static void fix_unresolved_deltas(struct sha1file *f, int nr_unresolved)
         * resolving deltas in the same order as their position in the pack.
         */
        sorted_by_pos = xmalloc(nr_unresolved * sizeof(*sorted_by_pos));
-       for (i = 0; i < nr_deltas; i++) {
-               if (objects[deltas[i].obj_no].real_type != OBJ_REF_DELTA)
-                       continue;
-               sorted_by_pos[n++] = &deltas[i];
-       }
+       for (i = 0; i < nr_ref_deltas; i++)
+               sorted_by_pos[n++] = &ref_deltas[i];
        qsort(sorted_by_pos, n, sizeof(*sorted_by_pos), delta_pos_compare);
 
        for (i = 0; i < n; i++) {
-               struct delta_entry *d = sorted_by_pos[i];
+               struct ref_delta_entry *d = sorted_by_pos[i];
                enum object_type type;
                struct base_data *base_obj = alloc_base_data();
 
                if (objects[d->obj_no].real_type != OBJ_REF_DELTA)
                        continue;
-               base_obj->data = read_sha1_file(d->base.sha1, &type, &base_obj->size);
+               base_obj->data = read_sha1_file(d->sha1, &type, &base_obj->size);
                if (!base_obj->data)
                        continue;
 
-               if (check_sha1_signature(d->base.sha1, base_obj->data,
+               if (check_sha1_signature(d->sha1, base_obj->data,
                                base_obj->size, typename(type)))
-                       die(_("local object %s is corrupt"), sha1_to_hex(d->base.sha1));
-               base_obj->obj = append_obj_to_pack(f, d->base.sha1,
+                       die(_("local object %s is corrupt"), sha1_to_hex(d->sha1));
+               base_obj->obj = append_obj_to_pack(f, d->sha1,
                                        base_obj->data, base_obj->size, type);
                find_unresolved_deltas(base_obj);
                display_progress(progress, nr_resolved_deltas);
@@ -1488,7 +1553,7 @@ static void read_idx_option(struct pack_idx_option *opts, const char *pack_name)
 
 static void show_pack_info(int stat_only)
 {
-       int i, baseobjects = nr_objects - nr_deltas;
+       int i, baseobjects = nr_objects - nr_ref_deltas - nr_ofs_deltas;
        unsigned long *chain_histogram = NULL;
 
        if (deepest_delta)
@@ -1498,7 +1563,7 @@ static void show_pack_info(int stat_only)
                struct object_entry *obj = &objects[i];
 
                if (is_delta_type(obj->type))
-                       chain_histogram[obj->delta_depth - 1]++;
+                       chain_histogram[obj_stat[i].delta_depth - 1]++;
                if (stat_only)
                        continue;
                printf("%s %-6s %lu %lu %"PRIuMAX,
@@ -1507,8 +1572,8 @@ static void show_pack_info(int stat_only)
                       (unsigned long)(obj[1].idx.offset - obj->idx.offset),
                       (uintmax_t)obj->idx.offset);
                if (is_delta_type(obj->type)) {
-                       struct object_entry *bobj = &objects[obj->base_object_no];
-                       printf(" %u %s", obj->delta_depth, sha1_to_hex(bobj->idx.sha1));
+                       struct object_entry *bobj = &objects[obj_stat[i].base_object_no];
+                       printf(" %u %s", obj_stat[i].delta_depth, sha1_to_hex(bobj->idx.sha1));
                }
                putchar('\n');
        }
@@ -1671,11 +1736,14 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
        curr_pack = open_pack_file(pack_name);
        parse_pack_header();
        objects = xcalloc(nr_objects + 1, sizeof(struct object_entry));
-       deltas = xcalloc(nr_objects, sizeof(struct delta_entry));
+       if (show_stat)
+               obj_stat = xcalloc(nr_objects + 1, sizeof(struct object_stat));
+       ofs_deltas = xcalloc(nr_objects, sizeof(struct ofs_delta_entry));
        parse_pack_objects(pack_sha1);
        resolve_deltas();
        conclude_pack(fix_thin_pack, curr_pack, pack_sha1);
-       free(deltas);
+       free(ofs_deltas);
+       free(ref_deltas);
        if (strict)
                foreign_nr = check_objects();
 
index ab9f86b8890ed99547144096ff56c3cbef780505..4335738135df32aeea3712cbdae88bd862015969 100644 (file)
@@ -362,7 +362,6 @@ int set_git_dir_init(const char *git_dir, const char *real_git_dir,
 static void separate_git_dir(const char *git_dir)
 {
        struct stat st;
-       FILE *fp;
 
        if (!stat(git_link, &st)) {
                const char *src;
@@ -378,11 +377,7 @@ static void separate_git_dir(const char *git_dir)
                        die_errno(_("unable to move %s to %s"), src, git_dir);
        }
 
-       fp = fopen(git_link, "w");
-       if (!fp)
-               die(_("Could not create git link %s"), git_link);
-       fprintf(fp, "gitdir: %s\n", git_dir);
-       fclose(fp);
+       write_file(git_link, 1, "gitdir: %s\n", git_dir);
 }
 
 int init_db(const char *template_dir, unsigned int flags)
index 3b0f8f96d4168463139d15f1cde655facc73426c..f89f60e11a523d45a81c3bd3a92fa9b4c5021673 100644 (file)
@@ -492,8 +492,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
        }
        if (len) {
                struct strbuf truname = STRBUF_INIT;
-               strbuf_addstr(&truname, "refs/heads/");
-               strbuf_addstr(&truname, remote);
+               strbuf_addf(&truname, "refs/heads/%s", remote);
                strbuf_setlen(&truname, truname.len - len);
                if (ref_exists(truname.buf)) {
                        strbuf_addf(msg,
@@ -504,28 +503,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
                        strbuf_release(&truname);
                        goto cleanup;
                }
-       }
-
-       if (!strcmp(remote, "FETCH_HEAD") &&
-                       !access(git_path("FETCH_HEAD"), R_OK)) {
-               const char *filename;
-               FILE *fp;
-               struct strbuf line = STRBUF_INIT;
-               char *ptr;
-
-               filename = git_path("FETCH_HEAD");
-               fp = fopen(filename, "r");
-               if (!fp)
-                       die_errno(_("could not open '%s' for reading"),
-                                 filename);
-               strbuf_getline(&line, fp, '\n');
-               fclose(fp);
-               ptr = strstr(line.buf, "\tnot-for-merge\t");
-               if (ptr)
-                       strbuf_remove(&line, ptr-line.buf+1, 13);
-               strbuf_addbuf(msg, &line);
-               strbuf_release(&line);
-               goto cleanup;
+               strbuf_release(&truname);
        }
 
        if (remote_head->util) {
@@ -1037,28 +1015,24 @@ static int default_edit_option(void)
                st_stdin.st_mode == st_stdout.st_mode);
 }
 
-static struct commit_list *collect_parents(struct commit *head_commit,
-                                          int *head_subsumed,
-                                          int argc, const char **argv)
+static struct commit_list *reduce_parents(struct commit *head_commit,
+                                         int *head_subsumed,
+                                         struct commit_list *remoteheads)
 {
-       int i;
-       struct commit_list *remoteheads = NULL, *parents, *next;
-       struct commit_list **remotes = &remoteheads;
+       struct commit_list *parents, *next, **remotes = &remoteheads;
 
-       if (head_commit)
-               remotes = &commit_list_insert(head_commit, remotes)->next;
-       for (i = 0; i < argc; i++) {
-               struct commit *commit = get_merge_parent(argv[i]);
-               if (!commit)
-                       help_unknown_ref(argv[i], "merge",
-                                        "not something we can merge");
-               remotes = &commit_list_insert(commit, remotes)->next;
-       }
-       *remotes = NULL;
+       /*
+        * Is the current HEAD reachable from another commit being
+        * merged?  If so we do not want to record it as a parent of
+        * the resulting merge, unless --no-ff is given.  We will flip
+        * this variable to 0 when we find HEAD among the independent
+        * tips being merged.
+        */
+       *head_subsumed = 1;
 
+       /* Find what parents to record by checking independent ones. */
        parents = reduce_heads(remoteheads);
 
-       *head_subsumed = 1; /* we will flip this to 0 when we find it */
        for (remoteheads = NULL, remotes = &remoteheads;
             parents;
             parents = next) {
@@ -1068,7 +1042,119 @@ static struct commit_list *collect_parents(struct commit *head_commit,
                        *head_subsumed = 0;
                else
                        remotes = &commit_list_insert(commit, remotes)->next;
+               free(parents);
+       }
+       return remoteheads;
+}
+
+static void prepare_merge_message(struct strbuf *merge_names, struct strbuf *merge_msg)
+{
+       struct fmt_merge_msg_opts opts;
+
+       memset(&opts, 0, sizeof(opts));
+       opts.add_title = !have_message;
+       opts.shortlog_len = shortlog_len;
+       opts.credit_people = (0 < option_edit);
+
+       fmt_merge_msg(merge_names, merge_msg, &opts);
+       if (merge_msg->len)
+               strbuf_setlen(merge_msg, merge_msg->len - 1);
+}
+
+static void handle_fetch_head(struct commit_list **remotes, struct strbuf *merge_names)
+{
+       const char *filename;
+       int fd, pos, npos;
+       struct strbuf fetch_head_file = STRBUF_INIT;
+
+       if (!merge_names)
+               merge_names = &fetch_head_file;
+
+       filename = git_path("FETCH_HEAD");
+       fd = open(filename, O_RDONLY);
+       if (fd < 0)
+               die_errno(_("could not open '%s' for reading"), filename);
+
+       if (strbuf_read(merge_names, fd, 0) < 0)
+               die_errno(_("could not read '%s'"), filename);
+       if (close(fd) < 0)
+               die_errno(_("could not close '%s'"), filename);
+
+       for (pos = 0; pos < merge_names->len; pos = npos) {
+               unsigned char sha1[20];
+               char *ptr;
+               struct commit *commit;
+
+               ptr = strchr(merge_names->buf + pos, '\n');
+               if (ptr)
+                       npos = ptr - merge_names->buf + 1;
+               else
+                       npos = merge_names->len;
+
+               if (npos - pos < 40 + 2 ||
+                   get_sha1_hex(merge_names->buf + pos, sha1))
+                       commit = NULL; /* bad */
+               else if (memcmp(merge_names->buf + pos + 40, "\t\t", 2))
+                       continue; /* not-for-merge */
+               else {
+                       char saved = merge_names->buf[pos + 40];
+                       merge_names->buf[pos + 40] = '\0';
+                       commit = get_merge_parent(merge_names->buf + pos);
+                       merge_names->buf[pos + 40] = saved;
+               }
+               if (!commit) {
+                       if (ptr)
+                               *ptr = '\0';
+                       die("not something we can merge in %s: %s",
+                           filename, merge_names->buf + pos);
+               }
+               remotes = &commit_list_insert(commit, remotes)->next;
+       }
+
+       if (merge_names == &fetch_head_file)
+               strbuf_release(&fetch_head_file);
+}
+
+static struct commit_list *collect_parents(struct commit *head_commit,
+                                          int *head_subsumed,
+                                          int argc, const char **argv,
+                                          struct strbuf *merge_msg)
+{
+       int i;
+       struct commit_list *remoteheads = NULL;
+       struct commit_list **remotes = &remoteheads;
+       struct strbuf merge_names = STRBUF_INIT, *autogen = NULL;
+
+       if (merge_msg && (!have_message || shortlog_len))
+               autogen = &merge_names;
+
+       if (head_commit)
+               remotes = &commit_list_insert(head_commit, remotes)->next;
+
+       if (argc == 1 && !strcmp(argv[0], "FETCH_HEAD")) {
+               handle_fetch_head(remotes, autogen);
+               remoteheads = reduce_parents(head_commit, head_subsumed, remoteheads);
+       } else {
+               for (i = 0; i < argc; i++) {
+                       struct commit *commit = get_merge_parent(argv[i]);
+                       if (!commit)
+                               help_unknown_ref(argv[i], "merge",
+                                                "not something we can merge");
+                       remotes = &commit_list_insert(commit, remotes)->next;
+               }
+               remoteheads = reduce_parents(head_commit, head_subsumed, remoteheads);
+               if (autogen) {
+                       struct commit_list *p;
+                       for (p = remoteheads; p; p = p->next)
+                               merge_name(merge_remote_util(p->item)->name, autogen);
+               }
        }
+
+       if (autogen) {
+               prepare_merge_message(autogen, merge_msg);
+               strbuf_release(autogen);
+       }
+
        return remoteheads;
 }
 
@@ -1158,61 +1244,62 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
                option_commit = 0;
        }
 
-       if (!abort_current_merge) {
-               if (!argc) {
-                       if (default_to_upstream)
-                               argc = setup_with_upstream(&argv);
-                       else
-                               die(_("No commit specified and merge.defaultToUpstream not set."));
-               } else if (argc == 1 && !strcmp(argv[0], "-"))
-                       argv[0] = "@{-1}";
+       if (!argc) {
+               if (default_to_upstream)
+                       argc = setup_with_upstream(&argv);
+               else
+                       die(_("No commit specified and merge.defaultToUpstream not set."));
+       } else if (argc == 1 && !strcmp(argv[0], "-")) {
+               argv[0] = "@{-1}";
        }
+
        if (!argc)
                usage_with_options(builtin_merge_usage,
                        builtin_merge_options);
 
-       /*
-        * This could be traditional "merge <msg> HEAD <commit>..."  and
-        * the way we can tell it is to see if the second token is HEAD,
-        * but some people might have misused the interface and used a
-        * commit-ish that is the same as HEAD there instead.
-        * Traditional format never would have "-m" so it is an
-        * additional safety measure to check for it.
-        */
-
-       if (!have_message && head_commit &&
-           is_old_style_invocation(argc, argv, head_commit->object.sha1)) {
-               strbuf_addstr(&merge_msg, argv[0]);
-               head_arg = argv[1];
-               argv += 2;
-               argc -= 2;
-               remoteheads = collect_parents(head_commit, &head_subsumed, argc, argv);
-       } else if (!head_commit) {
+       if (!head_commit) {
                struct commit *remote_head;
                /*
                 * If the merged head is a valid one there is no reason
                 * to forbid "git merge" into a branch yet to be born.
                 * We do the same for "git pull".
                 */
-               if (argc != 1)
-                       die(_("Can merge only exactly one commit into "
-                               "empty head"));
                if (squash)
                        die(_("Squash commit into empty head not supported yet"));
                if (fast_forward == FF_NO)
                        die(_("Non-fast-forward commit does not make sense into "
                            "an empty head"));
-               remoteheads = collect_parents(head_commit, &head_subsumed, argc, argv);
+               remoteheads = collect_parents(head_commit, &head_subsumed,
+                                             argc, argv, NULL);
                remote_head = remoteheads->item;
                if (!remote_head)
                        die(_("%s - not something we can merge"), argv[0]);
+               if (remoteheads->next)
+                       die(_("Can merge only exactly one commit into empty head"));
                read_empty(remote_head->object.sha1, 0);
                update_ref("initial pull", "HEAD", remote_head->object.sha1,
                           NULL, 0, UPDATE_REFS_DIE_ON_ERR);
                goto done;
-       } else {
-               struct strbuf merge_names = STRBUF_INIT;
+       }
 
+       /*
+        * This could be traditional "merge <msg> HEAD <commit>..."  and
+        * the way we can tell it is to see if the second token is HEAD,
+        * but some people might have misused the interface and used a
+        * commit-ish that is the same as HEAD there instead.
+        * Traditional format never would have "-m" so it is an
+        * additional safety measure to check for it.
+        */
+       if (!have_message &&
+           is_old_style_invocation(argc, argv, head_commit->object.sha1)) {
+               warning("old-style 'git merge <msg> HEAD <commit>' is deprecated.");
+               strbuf_addstr(&merge_msg, argv[0]);
+               head_arg = argv[1];
+               argv += 2;
+               argc -= 2;
+               remoteheads = collect_parents(head_commit, &head_subsumed,
+                                             argc, argv, NULL);
+       } else {
                /* We are invoked directly as the first-class UI. */
                head_arg = "HEAD";
 
@@ -1221,21 +1308,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
                 * the standard merge summary message to be appended
                 * to the given message.
                 */
-               remoteheads = collect_parents(head_commit, &head_subsumed, argc, argv);
-               for (p = remoteheads; p; p = p->next)
-                       merge_name(merge_remote_util(p->item)->name, &merge_names);
-
-               if (!have_message || shortlog_len) {
-                       struct fmt_merge_msg_opts opts;
-                       memset(&opts, 0, sizeof(opts));
-                       opts.add_title = !have_message;
-                       opts.shortlog_len = shortlog_len;
-                       opts.credit_people = (0 < option_edit);
-
-                       fmt_merge_msg(&merge_names, &merge_msg, &opts);
-                       if (merge_msg.len)
-                               strbuf_setlen(&merge_msg, merge_msg.len - 1);
-               }
+               remoteheads = collect_parents(head_commit, &head_subsumed,
+                                             argc, argv, &merge_msg);
        }
 
        if (!head_commit || !argc)
index c3a75166bd10918d21d3df19832880c4373dc8d7..c067107a6a6b8d6f797854d1e3a7cc9ce5da0cdc 100644 (file)
@@ -961,10 +961,8 @@ static int want_object_in_pack(const unsigned char *sha1,
                off_t offset = find_pack_entry_one(sha1, p);
                if (offset) {
                        if (!*found_pack) {
-                               if (!is_pack_valid(p)) {
-                                       warning("packfile %s cannot be accessed", p->pack_name);
+                               if (!is_pack_valid(p))
                                        continue;
-                               }
                                *found_offset = offset;
                                *found_pack = p;
                        }
index 77db8739b5165f15a437651b0803711f6e019839..ba34dac4d2fae9bce24932c92fcee2a4bfc0f102 100644 (file)
@@ -1,14 +1,14 @@
 #include "builtin.h"
 
-static void flush_current_id(int patchlen, unsigned char *id, unsigned char *result)
+static void flush_current_id(int patchlen, struct object_id *id, struct object_id *result)
 {
        char name[50];
 
        if (!patchlen)
                return;
 
-       memcpy(name, sha1_to_hex(id), 41);
-       printf("%s %s\n", sha1_to_hex(result), name);
+       memcpy(name, oid_to_hex(id), GIT_SHA1_HEXSZ + 1);
+       printf("%s %s\n", oid_to_hex(result), name);
 }
 
 static int remove_space(char *line)
@@ -53,23 +53,23 @@ static int scan_hunk_header(const char *p, int *p_before, int *p_after)
        return 1;
 }
 
-static void flush_one_hunk(unsigned char *result, git_SHA_CTX *ctx)
+static void flush_one_hunk(struct object_id *result, git_SHA_CTX *ctx)
 {
-       unsigned char hash[20];
+       unsigned char hash[GIT_SHA1_RAWSZ];
        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;
+       for (i = 0; i < GIT_SHA1_RAWSZ; ++i) {
+               carry += result->hash[i] + hash[i];
+               result->hash[i] = carry;
                carry >>= 8;
        }
 }
 
-static int get_one_patchid(unsigned char *next_sha1, unsigned char *result,
+static int get_one_patchid(struct object_id *next_oid, struct object_id *result,
                           struct strbuf *line_buf, int stable)
 {
        int patchlen = 0, found_next = 0;
@@ -77,7 +77,7 @@ static int get_one_patchid(unsigned char *next_sha1, unsigned char *result,
        git_SHA_CTX ctx;
 
        git_SHA1_Init(&ctx);
-       hashclr(result);
+       oidclr(result);
 
        while (strbuf_getwholeline(line_buf, stdin, '\n') != EOF) {
                char *line = line_buf->buf;
@@ -93,7 +93,7 @@ static int get_one_patchid(unsigned char *next_sha1, unsigned char *result,
                else if (!memcmp(line, "\\ ", 2) && 12 < strlen(line))
                        continue;
 
-               if (!get_sha1_hex(p, next_sha1)) {
+               if (!get_oid_hex(p, next_oid)) {
                        found_next = 1;
                        break;
                }
@@ -143,7 +143,7 @@ static int get_one_patchid(unsigned char *next_sha1, unsigned char *result,
        }
 
        if (!found_next)
-               hashclr(next_sha1);
+               oidclr(next_oid);
 
        flush_one_hunk(result, &ctx);
 
@@ -152,15 +152,15 @@ static int get_one_patchid(unsigned char *next_sha1, unsigned char *result,
 
 static void generate_id_list(int stable)
 {
-       unsigned char sha1[20], n[20], result[20];
+       struct object_id oid, n, result;
        int patchlen;
        struct strbuf line_buf = STRBUF_INIT;
 
-       hashclr(sha1);
+       oidclr(&oid);
        while (!feof(stdin)) {
-               patchlen = get_one_patchid(n, result, &line_buf, stable);
-               flush_current_id(patchlen, sha1, result);
-               hashcpy(sha1, n);
+               patchlen = get_one_patchid(&n, &result, &line_buf, stable);
+               flush_current_id(patchlen, &oid, &result);
+               oidcpy(&oid, &n);
        }
        strbuf_release(&line_buf);
 }
index 17094ad954c9da68bc5e251dce1a87ec67c00146..0c73246c721b3307f0d68b4e58f7c684aebce2e9 100644 (file)
@@ -76,6 +76,95 @@ static int prune_subdir(int nr, const char *path, void *data)
        return 0;
 }
 
+static int prune_worktree(const char *id, struct strbuf *reason)
+{
+       struct stat st;
+       char *path;
+       int fd, len;
+
+       if (!is_directory(git_path("worktrees/%s", id))) {
+               strbuf_addf(reason, _("Removing worktrees/%s: not a valid directory"), id);
+               return 1;
+       }
+       if (file_exists(git_path("worktrees/%s/locked", id)))
+               return 0;
+       if (stat(git_path("worktrees/%s/gitdir", id), &st)) {
+               strbuf_addf(reason, _("Removing worktrees/%s: gitdir file does not exist"), id);
+               return 1;
+       }
+       fd = open(git_path("worktrees/%s/gitdir", id), O_RDONLY);
+       if (fd < 0) {
+               strbuf_addf(reason, _("Removing worktrees/%s: unable to read gitdir file (%s)"),
+                           id, strerror(errno));
+               return 1;
+       }
+       len = st.st_size;
+       path = xmalloc(len + 1);
+       read_in_full(fd, path, len);
+       close(fd);
+       while (len && (path[len - 1] == '\n' || path[len - 1] == '\r'))
+               len--;
+       if (!len) {
+               strbuf_addf(reason, _("Removing worktrees/%s: invalid gitdir file"), id);
+               free(path);
+               return 1;
+       }
+       path[len] = '\0';
+       if (!file_exists(path)) {
+               struct stat st_link;
+               free(path);
+               /*
+                * the repo is moved manually and has not been
+                * accessed since?
+                */
+               if (!stat(git_path("worktrees/%s/link", id), &st_link) &&
+                   st_link.st_nlink > 1)
+                       return 0;
+               if (st.st_mtime <= expire) {
+                       strbuf_addf(reason, _("Removing worktrees/%s: gitdir file points to non-existent location"), id);
+                       return 1;
+               } else {
+                       return 0;
+               }
+       }
+       free(path);
+       return 0;
+}
+
+static void prune_worktrees(void)
+{
+       struct strbuf reason = STRBUF_INIT;
+       struct strbuf path = STRBUF_INIT;
+       DIR *dir = opendir(git_path("worktrees"));
+       struct dirent *d;
+       int ret;
+       if (!dir)
+               return;
+       while ((d = readdir(dir)) != NULL) {
+               if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
+                       continue;
+               strbuf_reset(&reason);
+               if (!prune_worktree(d->d_name, &reason))
+                       continue;
+               if (show_only || verbose)
+                       printf("%s\n", reason.buf);
+               if (show_only)
+                       continue;
+               strbuf_reset(&path);
+               strbuf_addstr(&path, git_path("worktrees/%s", d->d_name));
+               ret = remove_dir_recursively(&path, 0);
+               if (ret < 0 && errno == ENOTDIR)
+                       ret = unlink(path.buf);
+               if (ret)
+                       error(_("failed to remove: %s"), strerror(errno));
+       }
+       closedir(dir);
+       if (!show_only)
+               rmdir(git_path("worktrees"));
+       strbuf_release(&reason);
+       strbuf_release(&path);
+}
+
 /*
  * Write errors (particularly out of space) can result in
  * failed temporary packs (and more rarely indexes and other
@@ -102,10 +191,12 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
 {
        struct rev_info revs;
        struct progress *progress = NULL;
+       int do_prune_worktrees = 0;
        const struct option options[] = {
                OPT__DRY_RUN(&show_only, N_("do not remove, show only")),
                OPT__VERBOSE(&verbose, N_("report pruned objects")),
                OPT_BOOL(0, "progress", &show_progress, N_("show progress")),
+               OPT_BOOL(0, "worktrees", &do_prune_worktrees, N_("prune .git/worktrees")),
                OPT_EXPIRY_DATE(0, "expire", &expire,
                                N_("expire objects older than <time>")),
                OPT_END()
@@ -119,6 +210,14 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
        init_revisions(&revs, prefix);
 
        argc = parse_options(argc, argv, prefix, options, prune_usage, 0);
+
+       if (do_prune_worktrees) {
+               if (argc)
+                       die(_("--worktrees does not take extra arguments"));
+               prune_worktrees();
+               return 0;
+       }
+
        while (argc--) {
                unsigned char sha1[20];
                const char *name = *argv++;
index 5292bb5a506805778c6b9c164523c80a44da3edd..d2ec52bca983d9dfe1094cffe6049c902049e4d6 100644 (file)
@@ -1008,7 +1008,7 @@ static void run_update_post_hook(struct command *commands)
        int argc;
        const char **argv;
        struct child_process proc = CHILD_PROCESS_INIT;
-       char *hook;
+       const char *hook;
 
        hook = find_hook("post-update");
        for (argc = 0, cmd = commands; cmd; cmd = cmd->next) {
index 5d3ab906bc7ef6cc8cc9c65a3b86cf4c1ff443fb..ad57fc984edc8a7ea7f3784e14068e247a5d27ad 100644 (file)
@@ -584,7 +584,7 @@ static int migrate_file(struct remote *remote)
 {
        struct strbuf buf = STRBUF_INIT;
        int i;
-       char *path = NULL;
+       const char *path = NULL;
 
        strbuf_addf(&buf, "remote.%s.url", remote->name);
        for (i = 0; i < remote->url_nr; i++)
index f2edeb0f4ca2b81246ee37d7ca5f53f58161ad6f..af7340c7bafbfbbf991f782139775e18b6ac570a 100644 (file)
@@ -285,7 +285,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
        failed = 0;
        for_each_string_list_item(item, &names) {
                for (ext = 0; ext < ARRAY_SIZE(exts); ext++) {
-                       char *fname, *fname_old;
+                       const char *fname_old;
+                       char *fname;
                        fname = mkpathdup("%s/pack-%s%s", packdir,
                                                item->string, exts[ext].name);
                        if (!file_exists(fname)) {
@@ -313,7 +314,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
        if (failed) {
                struct string_list rollback_failure = STRING_LIST_INIT_DUP;
                for_each_string_list_item(item, &rollback) {
-                       char *fname, *fname_old;
+                       const char *fname_old;
+                       char *fname;
                        fname = mkpathdup("%s/%s", packdir, item->string);
                        fname_old = mkpath("%s/old-%s", packdir, item->string);
                        if (rename(fname_old, fname))
@@ -366,7 +368,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
        /* Remove the "old-" files */
        for_each_string_list_item(item, &names) {
                for (ext = 0; ext < ARRAY_SIZE(exts); ext++) {
-                       char *fname;
+                       const char *fname;
                        fname = mkpath("%s/old-%s%s",
                                        packdir,
                                        item->string,
index 3626c61da67abbe418e492c7828f6e153f6055d8..4d10dd9545af70c32f9e19533b2cfc9b00b7f00a 100644 (file)
@@ -533,6 +533,13 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
        for (i = 1; i < argc; i++) {
                const char *arg = argv[i];
 
+               if (!strcmp(arg, "--git-path")) {
+                       if (!argv[i + 1])
+                               die("--git-path requires an argument");
+                       puts(git_path("%s", argv[i + 1]));
+                       i++;
+                       continue;
+               }
                if (as_is) {
                        if (show_file(arg, output_prefix) && as_is < 2)
                                verify_filename(prefix, arg, 0);
@@ -755,6 +762,10 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
                                free(cwd);
                                continue;
                        }
+                       if (!strcmp(arg, "--git-common-dir")) {
+                               puts(get_git_common_dir());
+                               continue;
+                       }
                        if (!strcmp(arg, "--resolve-git-dir")) {
                                const char *gitdir = argv[++i];
                                if (!gitdir)
index f3fb5fb2bf28019dafcbd2bfbd6b1a024aa6da2f..e69fb7c489885ad2466397a8a25c34d87eff9ce9 100644 (file)
@@ -718,7 +718,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
        }
 
        /* If nothing is specified, show all branches by default */
-       if (ac + all_heads + all_remotes == 0)
+       if (ac <= topics && all_heads + all_remotes == 0)
                all_heads = 1;
 
        if (reflog) {
@@ -785,13 +785,13 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
                }
                free(ref);
        }
-       else if (all_heads + all_remotes)
-               snarf_refs(all_heads, all_remotes);
        else {
                while (0 < ac) {
                        append_one_rev(*av);
                        ac--; av++;
                }
+               if (all_heads + all_remotes)
+                       snarf_refs(all_heads, all_remotes);
        }
 
        head_p = resolve_ref_unsafe("HEAD", RESOLVE_REF_READING,
index 6271b54adc24c8765ca0b179faf53f6af86dc630..7431938fa654ba9af524a7018ab2c7be8242caaa 100644 (file)
@@ -33,6 +33,7 @@ static int mark_valid_only;
 static int mark_skip_worktree_only;
 #define MARK_FLAG 1
 #define UNMARK_FLAG 2
+static struct strbuf mtime_dir = STRBUF_INIT;
 
 __attribute__((format (printf, 1, 2)))
 static void report(const char *fmt, ...)
@@ -48,6 +49,166 @@ static void report(const char *fmt, ...)
        va_end(vp);
 }
 
+static void remove_test_directory(void)
+{
+       if (mtime_dir.len)
+               remove_dir_recursively(&mtime_dir, 0);
+}
+
+static const char *get_mtime_path(const char *path)
+{
+       static struct strbuf sb = STRBUF_INIT;
+       strbuf_reset(&sb);
+       strbuf_addf(&sb, "%s/%s", mtime_dir.buf, path);
+       return sb.buf;
+}
+
+static void xmkdir(const char *path)
+{
+       path = get_mtime_path(path);
+       if (mkdir(path, 0700))
+               die_errno(_("failed to create directory %s"), path);
+}
+
+static int xstat_mtime_dir(struct stat *st)
+{
+       if (stat(mtime_dir.buf, st))
+               die_errno(_("failed to stat %s"), mtime_dir.buf);
+       return 0;
+}
+
+static int create_file(const char *path)
+{
+       int fd;
+       path = get_mtime_path(path);
+       fd = open(path, O_CREAT | O_RDWR, 0644);
+       if (fd < 0)
+               die_errno(_("failed to create file %s"), path);
+       return fd;
+}
+
+static void xunlink(const char *path)
+{
+       path = get_mtime_path(path);
+       if (unlink(path))
+               die_errno(_("failed to delete file %s"), path);
+}
+
+static void xrmdir(const char *path)
+{
+       path = get_mtime_path(path);
+       if (rmdir(path))
+               die_errno(_("failed to delete directory %s"), path);
+}
+
+static void avoid_racy(void)
+{
+       /*
+        * not use if we could usleep(10) if USE_NSEC is defined. The
+        * field nsec could be there, but the OS could choose to
+        * ignore it?
+        */
+       sleep(1);
+}
+
+static int test_if_untracked_cache_is_supported(void)
+{
+       struct stat st;
+       struct stat_data base;
+       int fd, ret = 0;
+
+       strbuf_addstr(&mtime_dir, "mtime-test-XXXXXX");
+       if (!mkdtemp(mtime_dir.buf))
+               die_errno("Could not make temporary directory");
+
+       fprintf(stderr, _("Testing "));
+       atexit(remove_test_directory);
+       xstat_mtime_dir(&st);
+       fill_stat_data(&base, &st);
+       fputc('.', stderr);
+
+       avoid_racy();
+       fd = create_file("newfile");
+       xstat_mtime_dir(&st);
+       if (!match_stat_data(&base, &st)) {
+               close(fd);
+               fputc('\n', stderr);
+               fprintf_ln(stderr,_("directory stat info does not "
+                                   "change after adding a new file"));
+               goto done;
+       }
+       fill_stat_data(&base, &st);
+       fputc('.', stderr);
+
+       avoid_racy();
+       xmkdir("new-dir");
+       xstat_mtime_dir(&st);
+       if (!match_stat_data(&base, &st)) {
+               close(fd);
+               fputc('\n', stderr);
+               fprintf_ln(stderr, _("directory stat info does not change "
+                                    "after adding a new directory"));
+               goto done;
+       }
+       fill_stat_data(&base, &st);
+       fputc('.', stderr);
+
+       avoid_racy();
+       write_or_die(fd, "data", 4);
+       close(fd);
+       xstat_mtime_dir(&st);
+       if (match_stat_data(&base, &st)) {
+               fputc('\n', stderr);
+               fprintf_ln(stderr, _("directory stat info changes "
+                                    "after updating a file"));
+               goto done;
+       }
+       fputc('.', stderr);
+
+       avoid_racy();
+       close(create_file("new-dir/new"));
+       xstat_mtime_dir(&st);
+       if (match_stat_data(&base, &st)) {
+               fputc('\n', stderr);
+               fprintf_ln(stderr, _("directory stat info changes after "
+                                    "adding a file inside subdirectory"));
+               goto done;
+       }
+       fputc('.', stderr);
+
+       avoid_racy();
+       xunlink("newfile");
+       xstat_mtime_dir(&st);
+       if (!match_stat_data(&base, &st)) {
+               fputc('\n', stderr);
+               fprintf_ln(stderr, _("directory stat info does not "
+                                    "change after deleting a file"));
+               goto done;
+       }
+       fill_stat_data(&base, &st);
+       fputc('.', stderr);
+
+       avoid_racy();
+       xunlink("new-dir/new");
+       xrmdir("new-dir");
+       xstat_mtime_dir(&st);
+       if (!match_stat_data(&base, &st)) {
+               fputc('\n', stderr);
+               fprintf_ln(stderr, _("directory stat info does not "
+                                    "change after deleting a directory"));
+               goto done;
+       }
+
+       if (rmdir(mtime_dir.buf))
+               die_errno(_("failed to delete directory %s"), mtime_dir.buf);
+       fprintf_ln(stderr, _(" OK"));
+       ret = 1;
+
+done:
+       strbuf_release(&mtime_dir);
+       return ret;
+}
+
 static int mark_ce_flags(const char *path, int flag, int mark)
 {
        int namelen = strlen(path);
@@ -532,10 +693,9 @@ static int do_unresolve(int ac, const char **av,
 
        for (i = 1; i < ac; i++) {
                const char *arg = av[i];
-               const char *p = prefix_path(prefix, prefix_length, arg);
+               char *p = prefix_path(prefix, prefix_length, arg);
                err |= unresolve_one(p);
-               if (p < arg || p > arg + strlen(arg))
-                       free((char *)p);
+               free(p);
        }
        return err;
 }
@@ -742,6 +902,7 @@ static int reupdate_callback(struct parse_opt_ctx_t *ctx,
 int cmd_update_index(int argc, const char **argv, const char *prefix)
 {
        int newfd, entries, has_errors = 0, line_termination = '\n';
+       int untracked_cache = -1;
        int read_from_stdin = 0;
        int prefix_length = prefix ? strlen(prefix) : 0;
        int preferred_index_format = 0;
@@ -833,6 +994,10 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
                        N_("write index in this format")),
                OPT_BOOL(0, "split-index", &split_index,
                        N_("enable or disable split index")),
+               OPT_BOOL(0, "untracked-cache", &untracked_cache,
+                       N_("enable/disable untracked cache")),
+               OPT_SET_INT(0, "force-untracked-cache", &untracked_cache,
+                           N_("enable untracked cache without testing the filesystem"), 2),
                OPT_END()
        };
 
@@ -871,14 +1036,14 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
                case PARSE_OPT_DONE:
                {
                        const char *path = ctx.argv[0];
-                       const char *p;
+                       char *p;
 
                        setup_work_tree();
                        p = prefix_path(prefix, prefix_length, path);
                        update_one(p);
                        if (set_executable_bit)
                                chmod_path(set_executable_bit, p);
-                       free((char *)p);
+                       free(p);
                        ctx.argc--;
                        ctx.argv++;
                        break;
@@ -909,7 +1074,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
 
                setup_work_tree();
                while (strbuf_getline(&buf, stdin, line_termination) != EOF) {
-                       const char *p;
+                       char *p;
                        if (line_termination && buf.buf[0] == '"') {
                                strbuf_reset(&nbuf);
                                if (unquote_c_style(&nbuf, buf.buf, NULL))
@@ -920,7 +1085,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
                        update_one(p);
                        if (set_executable_bit)
                                chmod_path(set_executable_bit, p);
-                       free((char *)p);
+                       free(p);
                }
                strbuf_release(&nbuf);
                strbuf_release(&buf);
@@ -939,6 +1104,28 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
                the_index.split_index = NULL;
                the_index.cache_changed |= SOMETHING_CHANGED;
        }
+       if (untracked_cache > 0) {
+               struct untracked_cache *uc;
+
+               if (untracked_cache < 2) {
+                       setup_work_tree();
+                       if (!test_if_untracked_cache_is_supported())
+                               return 1;
+               }
+               if (!the_index.untracked) {
+                       uc = xcalloc(1, sizeof(*uc));
+                       strbuf_init(&uc->ident, 100);
+                       uc->exclude_per_dir = ".gitignore";
+                       /* should be the same flags used by git-status */
+                       uc->dir_flags = DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES;
+                       the_index.untracked = uc;
+               }
+               add_untracked_ident(the_index.untracked);
+               the_index.cache_changed |= UNTRACKED_CHANGED;
+       } else if (!untracked_cache && the_index.untracked) {
+               the_index.untracked = NULL;
+               the_index.cache_changed |= UNTRACKED_CHANGED;
+       }
 
        if (active_cache_changed) {
                if (newfd < 0) {
index 8d157eba455f15a00cc7bf9b970f1862167ee1bb..7cffc3a579e4a02c1422284092cef18cd4b7d059 100644 (file)
@@ -24,7 +24,7 @@ static struct bulk_checkin_state {
 
 static void finish_bulk_checkin(struct bulk_checkin_state *state)
 {
-       unsigned char sha1[20];
+       struct object_id oid;
        struct strbuf packname = STRBUF_INIT;
        int i;
 
@@ -36,11 +36,11 @@ static void finish_bulk_checkin(struct bulk_checkin_state *state)
                unlink(state->pack_tmp_name);
                goto clear_exit;
        } else if (state->nr_written == 1) {
-               sha1close(state->f, sha1, CSUM_FSYNC);
+               sha1close(state->f, oid.hash, CSUM_FSYNC);
        } else {
-               int fd = sha1close(state->f, sha1, 0);
-               fixup_pack_header_footer(fd, sha1, state->pack_tmp_name,
-                                        state->nr_written, sha1,
+               int fd = sha1close(state->f, oid.hash, 0);
+               fixup_pack_header_footer(fd, oid.hash, state->pack_tmp_name,
+                                        state->nr_written, oid.hash,
                                         state->offset);
                close(fd);
        }
@@ -48,7 +48,7 @@ static void finish_bulk_checkin(struct bulk_checkin_state *state)
        strbuf_addf(&packname, "%s/pack/pack-", get_object_directory());
        finish_tmp_packfile(&packname, state->pack_tmp_name,
                            state->written, state->nr_written,
-                           &state->pack_idx_opts, sha1);
+                           &state->pack_idx_opts, oid.hash);
        for (i = 0; i < state->nr_written; i++)
                free(state->written[i]);
 
diff --git a/cache.h b/cache.h
index e42be4b11ba114a1ae01b9c5f6825d23bbf61eba..9da9784824dc3a93db2c753613bb56866a356070 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -43,6 +43,14 @@ int git_deflate_end_gently(git_zstream *);
 int git_deflate(git_zstream *, int flush);
 unsigned long git_deflate_bound(git_zstream *, unsigned long);
 
+/* The length in bytes and in hex digits of an object name (SHA-1 value). */
+#define GIT_SHA1_RAWSZ 20
+#define GIT_SHA1_HEXSZ (2 * GIT_SHA1_RAWSZ)
+
+struct object_id {
+       unsigned char hash[GIT_SHA1_RAWSZ];
+};
+
 #if defined(DT_UNKNOWN) && !defined(NO_D_TYPE_IN_DIRENT)
 #define DTYPE(de)      ((de)->d_type)
 #else
@@ -289,8 +297,11 @@ static inline unsigned int canon_mode(unsigned int mode)
 #define RESOLVE_UNDO_CHANGED   (1 << 4)
 #define CACHE_TREE_CHANGED     (1 << 5)
 #define SPLIT_INDEX_ORDERED    (1 << 6)
+#define UNTRACKED_CHANGED      (1 << 7)
 
 struct split_index;
+struct untracked_cache;
+
 struct index_state {
        struct cache_entry **cache;
        unsigned int version;
@@ -304,6 +315,7 @@ struct index_state {
        struct hashmap name_hash;
        struct hashmap dir_hash;
        unsigned char sha1[20];
+       struct untracked_cache *untracked;
 };
 
 extern struct index_state the_index;
@@ -370,6 +382,7 @@ static inline enum object_type object_type(unsigned int mode)
 
 /* Double-check local_repo_env below if you add to this list. */
 #define GIT_DIR_ENVIRONMENT "GIT_DIR"
+#define GIT_COMMON_DIR_ENVIRONMENT "GIT_COMMON_DIR"
 #define GIT_NAMESPACE_ENVIRONMENT "GIT_NAMESPACE"
 #define GIT_WORK_TREE_ENVIRONMENT "GIT_WORK_TREE"
 #define GIT_PREFIX_ENVIRONMENT "GIT_PREFIX"
@@ -423,11 +436,13 @@ extern int is_inside_git_dir(void);
 extern char *git_work_tree_cfg;
 extern int is_inside_work_tree(void);
 extern const char *get_git_dir(void);
+extern const char *get_git_common_dir(void);
 extern int is_git_directory(const char *path);
 extern char *get_object_directory(void);
 extern char *get_index_file(void);
 extern char *get_graft_file(void);
 extern int set_git_dir(const char *path);
+extern int get_common_dir(struct strbuf *sb, const char *gitdir);
 extern const char *get_git_namespace(void);
 extern const char *strip_namespace(const char *namespaced_ref);
 extern const char *get_git_work_tree(void);
@@ -552,6 +567,8 @@ extern void fill_stat_data(struct stat_data *sd, struct stat *st);
  * INODE_CHANGED, and DATA_CHANGED.
  */
 extern int match_stat_data(const struct stat_data *sd, struct stat *st);
+extern int match_stat_data_racy(const struct index_state *istate,
+                               const struct stat_data *sd, struct stat *st);
 
 extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);
 
@@ -612,6 +629,7 @@ extern int core_apply_sparse_checkout;
 extern int precomposed_unicode;
 extern int protect_hfs;
 extern int protect_ntfs;
+extern int git_db_env, git_index_env, git_graft_env, git_common_dir_env;
 
 /*
  * Include broken refs in all ref iterations, which will
@@ -682,18 +700,19 @@ extern int check_repository_format(void);
 
 extern char *mksnpath(char *buf, size_t n, const char *fmt, ...)
        __attribute__((format (printf, 3, 4)));
-extern char *git_snpath(char *buf, size_t n, const char *fmt, ...)
-       __attribute__((format (printf, 3, 4)));
+extern void strbuf_git_path(struct strbuf *sb, const char *fmt, ...)
+       __attribute__((format (printf, 2, 3)));
 extern char *git_pathdup(const char *fmt, ...)
        __attribute__((format (printf, 1, 2)));
 extern char *mkpathdup(const char *fmt, ...)
        __attribute__((format (printf, 1, 2)));
 
 /* Return a statically allocated filename matching the sha1 signature */
-extern char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
-extern char *git_path(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
-extern char *git_path_submodule(const char *path, const char *fmt, ...)
+extern const char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
+extern const char *git_path(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
+extern const char *git_path_submodule(const char *path, const char *fmt, ...)
        __attribute__((format (printf, 2, 3)));
+extern void report_linked_checkout_garbage(void);
 
 /*
  * Return the name of the file in the local object database that would
@@ -718,13 +737,13 @@ extern char *sha1_pack_name(const unsigned char *sha1);
 extern char *sha1_pack_index_name(const unsigned char *sha1);
 
 extern const char *find_unique_abbrev(const unsigned char *sha1, int);
-extern const unsigned char null_sha1[20];
+extern const unsigned char null_sha1[GIT_SHA1_RAWSZ];
 
 static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
 {
        int i;
 
-       for (i = 0; i < 20; i++, sha1++, sha2++) {
+       for (i = 0; i < GIT_SHA1_RAWSZ; i++, sha1++, sha2++) {
                if (*sha1 != *sha2)
                        return *sha1 - *sha2;
        }
@@ -732,20 +751,42 @@ static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
        return 0;
 }
 
+static inline int oidcmp(const struct object_id *oid1, const struct object_id *oid2)
+{
+       return hashcmp(oid1->hash, oid2->hash);
+}
+
 static inline int is_null_sha1(const unsigned char *sha1)
 {
        return !hashcmp(sha1, null_sha1);
 }
 
+static inline int is_null_oid(const struct object_id *oid)
+{
+       return !hashcmp(oid->hash, null_sha1);
+}
+
 static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src)
 {
-       memcpy(sha_dst, sha_src, 20);
+       memcpy(sha_dst, sha_src, GIT_SHA1_RAWSZ);
 }
+
+static inline void oidcpy(struct object_id *dst, const struct object_id *src)
+{
+       hashcpy(dst->hash, src->hash);
+}
+
 static inline void hashclr(unsigned char *hash)
 {
-       memset(hash, 0, 20);
+       memset(hash, 0, GIT_SHA1_RAWSZ);
+}
+
+static inline void oidclr(struct object_id *oid)
+{
+       hashclr(oid->hash);
 }
 
+
 #define EMPTY_TREE_SHA1_HEX \
        "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
 #define EMPTY_TREE_SHA1_BIN_LITERAL \
@@ -816,7 +857,6 @@ enum scld_error safe_create_leading_directories(char *path);
 enum scld_error safe_create_leading_directories_const(const char *path);
 
 int mkdir_in_gitdir(const char *path);
-extern void home_config_paths(char **global, char **xdg, char *file);
 extern char *expand_user_path(const char *path);
 const char *enter_repo(const char *path, int strict);
 static inline int is_absolute_path(const char *path)
@@ -836,8 +876,16 @@ char *strip_path_suffix(const char *path, const char *suffix);
 int daemon_avoid_alias(const char *path);
 extern int is_ntfs_dotgit(const char *name);
 
+/**
+ * Return a newly allocated string with the evaluation of
+ * "$XDG_CONFIG_HOME/git/$filename" if $XDG_CONFIG_HOME is non-empty, otherwise
+ * "$HOME/.config/git/$filename". Return NULL upon error.
+ */
+extern char *xdg_config_home(const char *filename);
+
 /* object replacement */
 #define LOOKUP_REPLACE_OBJECT 1
+#define LOOKUP_UNKNOWN_OBJECT 2
 extern void *read_sha1_file_extended(const unsigned char *sha1, enum object_type *type, unsigned long *size, unsigned flag);
 static inline void *read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size)
 {
@@ -953,8 +1001,10 @@ extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *);
  * null-terminated string.
  */
 extern int get_sha1_hex(const char *hex, unsigned char *sha1);
+extern int get_oid_hex(const char *hex, struct object_id *sha1);
 
 extern char *sha1_to_hex(const unsigned char *sha1);   /* static buffer result! */
+extern char *oid_to_hex(const struct object_id *oid);  /* same static buffer as sha1_to_hex */
 extern int read_ref_full(const char *refname, int resolve_flags,
                         unsigned char *sha1, int *flags);
 extern int read_ref(const char *refname, unsigned char *sha1);
@@ -1308,6 +1358,7 @@ struct object_info {
        unsigned long *sizep;
        unsigned long *disk_sizep;
        unsigned char *delta_base_sha1;
+       struct strbuf *typename;
 
        /* Response */
        enum {
@@ -1496,9 +1547,13 @@ extern const char *git_mailmap_blob;
 extern void maybe_flush_or_die(FILE *, const char *);
 __attribute__((format (printf, 2, 3)))
 extern void fprintf_or_die(FILE *, const char *fmt, ...);
+
+#define COPY_READ_ERROR (-2)
+#define COPY_WRITE_ERROR (-3)
 extern int copy_fd(int ifd, int ofd);
 extern int copy_file(const char *dst, const char *src, int mode);
 extern int copy_file_with_time(const char *dst, const char *src, int mode);
+
 extern void write_or_die(int fd, const void *buf, size_t count);
 extern int write_or_whine(int fd, const void *buf, size_t count, const char *msg);
 extern int write_or_whine_pipe(int fd, const void *buf, size_t count, const char *msg);
@@ -1512,6 +1567,8 @@ static inline ssize_t write_str_in_full(int fd, const char *str)
 {
        return write_in_full(fd, str, strlen(str));
 }
+__attribute__((format (printf, 3, 4)))
+extern int write_file(const char *path, int fatal, const char *fmt, ...);
 
 /* pager.c */
 extern void setup_pager(void);
index 91edce58e15b82428fcc5f3b006e23bf5380d38c..8eb7278978ddaadc605787eb4139d688a01fb052 100644 (file)
@@ -44,9 +44,9 @@ static struct combine_diff_path *intersect_paths(struct combine_diff_path *curr,
                        memset(p->parent, 0,
                               sizeof(p->parent[0]) * num_parent);
 
-                       hashcpy(p->sha1, q->queue[i]->two->sha1);
+                       hashcpy(p->oid.hash, q->queue[i]->two->sha1);
                        p->mode = q->queue[i]->two->mode;
-                       hashcpy(p->parent[n].sha1, q->queue[i]->one->sha1);
+                       hashcpy(p->parent[n].oid.hash, q->queue[i]->one->sha1);
                        p->parent[n].mode = q->queue[i]->one->mode;
                        p->parent[n].status = q->queue[i]->status;
                        *tail = p;
@@ -77,7 +77,7 @@ static struct combine_diff_path *intersect_paths(struct combine_diff_path *curr,
                        continue;
                }
 
-               hashcpy(p->parent[n].sha1, q->queue[i]->one->sha1);
+               hashcpy(p->parent[n].oid.hash, q->queue[i]->one->sha1);
                p->parent[n].mode = q->queue[i]->one->mode;
                p->parent[n].status = q->queue[i]->status;
 
@@ -284,7 +284,7 @@ static struct lline *coalesce_lines(struct lline *base, int *lenbase,
        return base;
 }
 
-static char *grab_blob(const unsigned char *sha1, unsigned int mode,
+static char *grab_blob(const struct object_id *oid, unsigned int mode,
                       unsigned long *size, struct userdiff_driver *textconv,
                       const char *path)
 {
@@ -294,20 +294,20 @@ static char *grab_blob(const unsigned char *sha1, unsigned int mode,
        if (S_ISGITLINK(mode)) {
                blob = xmalloc(100);
                *size = snprintf(blob, 100,
-                                "Subproject commit %s\n", sha1_to_hex(sha1));
-       } else if (is_null_sha1(sha1)) {
+                                "Subproject commit %s\n", oid_to_hex(oid));
+       } else if (is_null_oid(oid)) {
                /* deleted blob */
                *size = 0;
                return xcalloc(1, 1);
        } else if (textconv) {
                struct diff_filespec *df = alloc_filespec(path);
-               fill_filespec(df, sha1, 1, mode);
+               fill_filespec(df, oid->hash, 1, mode);
                *size = fill_textconv(textconv, df, &blob);
                free_filespec(df);
        } else {
-               blob = read_sha1_file(sha1, &type, size);
+               blob = read_sha1_file(oid->hash, &type, size);
                if (type != OBJ_BLOB)
-                       die("object '%s' is not a blob!", sha1_to_hex(sha1));
+                       die("object '%s' is not a blob!", oid_to_hex(oid));
        }
        return blob;
 }
@@ -389,7 +389,7 @@ static void consume_line(void *state_, char *line, unsigned long len)
        }
 }
 
-static void combine_diff(const unsigned char *parent, unsigned int mode,
+static void combine_diff(const struct object_id *parent, unsigned int mode,
                         mmfile_t *result_file,
                         struct sline *sline, unsigned int cnt, int n,
                         int num_parent, int result_deleted,
@@ -897,7 +897,7 @@ static void show_combined_header(struct combine_diff_path *elem,
                                 int show_file_header)
 {
        struct diff_options *opt = &rev->diffopt;
-       int abbrev = DIFF_OPT_TST(opt, FULL_INDEX) ? 40 : DEFAULT_ABBREV;
+       int abbrev = DIFF_OPT_TST(opt, FULL_INDEX) ? GIT_SHA1_HEXSZ : DEFAULT_ABBREV;
        const char *a_prefix = opt->a_prefix ? opt->a_prefix : "a/";
        const char *b_prefix = opt->b_prefix ? opt->b_prefix : "b/";
        const char *c_meta = diff_get_color_opt(opt, DIFF_METAINFO);
@@ -914,11 +914,11 @@ static void show_combined_header(struct combine_diff_path *elem,
                         "", elem->path, line_prefix, c_meta, c_reset);
        printf("%s%sindex ", line_prefix, c_meta);
        for (i = 0; i < num_parent; i++) {
-               abb = find_unique_abbrev(elem->parent[i].sha1,
+               abb = find_unique_abbrev(elem->parent[i].oid.hash,
                                         abbrev);
                printf("%s%s", i ? "," : "", abb);
        }
-       abb = find_unique_abbrev(elem->sha1, abbrev);
+       abb = find_unique_abbrev(elem->oid.hash, abbrev);
        printf("..%s%s\n", abb, c_reset);
 
        if (mode_differs) {
@@ -991,7 +991,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
 
        /* Read the result of merge first */
        if (!working_tree_file)
-               result = grab_blob(elem->sha1, elem->mode, &result_size,
+               result = grab_blob(&elem->oid, elem->mode, &result_size,
                                   textconv, elem->path);
        else {
                /* Used by diff-tree to read from the working tree */
@@ -1013,12 +1013,12 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
                        result = strbuf_detach(&buf, NULL);
                        elem->mode = canon_mode(st.st_mode);
                } else if (S_ISDIR(st.st_mode)) {
-                       unsigned char sha1[20];
-                       if (resolve_gitlink_ref(elem->path, "HEAD", sha1) < 0)
-                               result = grab_blob(elem->sha1, elem->mode,
+                       struct object_id oid;
+                       if (resolve_gitlink_ref(elem->path, "HEAD", oid.hash) < 0)
+                               result = grab_blob(&elem->oid, elem->mode,
                                                   &result_size, NULL, NULL);
                        else
-                               result = grab_blob(sha1, elem->mode,
+                               result = grab_blob(&oid, elem->mode,
                                                   &result_size, NULL, NULL);
                } else if (textconv) {
                        struct diff_filespec *df = alloc_filespec(elem->path);
@@ -1090,7 +1090,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
                for (i = 0; !is_binary && i < num_parent; i++) {
                        char *buf;
                        unsigned long size;
-                       buf = grab_blob(elem->parent[i].sha1,
+                       buf = grab_blob(&elem->parent[i].oid,
                                        elem->parent[i].mode,
                                        &size, NULL, NULL);
                        if (buffer_is_binary(buf, size))
@@ -1139,14 +1139,14 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
        for (i = 0; i < num_parent; i++) {
                int j;
                for (j = 0; j < i; j++) {
-                       if (!hashcmp(elem->parent[i].sha1,
-                                    elem->parent[j].sha1)) {
+                       if (!oidcmp(&elem->parent[i].oid,
+                                    &elem->parent[j].oid)) {
                                reuse_combine_diff(sline, cnt, i, j);
                                break;
                        }
                }
                if (i <= j)
-                       combine_diff(elem->parent[i].sha1,
+                       combine_diff(&elem->parent[i].oid,
                                     elem->parent[i].mode,
                                     &result_file, sline,
                                     cnt, i, num_parent, result_deleted,
@@ -1206,9 +1206,9 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, struct re
 
                /* Show sha1's */
                for (i = 0; i < num_parent; i++)
-                       printf(" %s", diff_unique_abbrev(p->parent[i].sha1,
+                       printf(" %s", diff_unique_abbrev(p->parent[i].oid.hash,
                                                         opt->abbrev));
-               printf(" %s ", diff_unique_abbrev(p->sha1, opt->abbrev));
+               printf(" %s ", diff_unique_abbrev(p->oid.hash, opt->abbrev));
        }
 
        if (opt->output_format & (DIFF_FORMAT_RAW | DIFF_FORMAT_NAME_STATUS)) {
@@ -1271,16 +1271,16 @@ static struct diff_filepair *combined_pair(struct combine_diff_path *p,
        for (i = 0; i < num_parent; i++) {
                pair->one[i].path = p->path;
                pair->one[i].mode = p->parent[i].mode;
-               hashcpy(pair->one[i].sha1, p->parent[i].sha1);
-               pair->one[i].sha1_valid = !is_null_sha1(p->parent[i].sha1);
+               hashcpy(pair->one[i].sha1, p->parent[i].oid.hash);
+               pair->one[i].sha1_valid = !is_null_oid(&p->parent[i].oid);
                pair->one[i].has_more_entries = 1;
        }
        pair->one[num_parent - 1].has_more_entries = 0;
 
        pair->two->path = p->path;
        pair->two->mode = p->mode;
-       hashcpy(pair->two->sha1, p->sha1);
-       pair->two->sha1_valid = !is_null_sha1(p->sha1);
+       hashcpy(pair->two->sha1, p->oid.hash);
+       pair->two->sha1_valid = !is_null_oid(&p->oid);
        return pair;
 }
 
index f1eae0810de9d7e405759190221742534c293745..54d8d21ad2b0dc43659e0dd7ee64c4cd3a3f8ed9 100644 (file)
@@ -1,5 +1,5 @@
 # List of known git commands.
-# command name                         category [deprecated] [common]
+# command name                          category [deprecated] [common]
 git-add                                 mainporcelain common
 git-am                                  mainporcelain
 git-annotate                            ancillaryinterrogators
@@ -40,21 +40,21 @@ git-diff-files                          plumbinginterrogators
 git-diff-index                          plumbinginterrogators
 git-diff-tree                           plumbinginterrogators
 git-difftool                            ancillaryinterrogators
-git-fast-export                                ancillarymanipulators
-git-fast-import                                ancillarymanipulators
+git-fast-export                         ancillarymanipulators
+git-fast-import                         ancillarymanipulators
 git-fetch                               mainporcelain common
 git-fetch-pack                          synchingrepositories
 git-filter-branch                       ancillarymanipulators
 git-fmt-merge-msg                       purehelpers
 git-for-each-ref                        plumbinginterrogators
 git-format-patch                        mainporcelain
-git-fsck                               ancillaryinterrogators
+git-fsck                                ancillaryinterrogators
 git-gc                                  mainporcelain
 git-get-tar-commit-id                   ancillaryinterrogators
 git-grep                                mainporcelain common
 git-gui                                 mainporcelain
 git-hash-object                         plumbingmanipulators
-git-help                               ancillaryinterrogators
+git-help                                ancillaryinterrogators
 git-http-backend                        synchingrepositories
 git-http-fetch                          synchelpers
 git-http-push                           synchelpers
index a8c7577d28a4b2a0b5fc13420f8a141871626087..2d9de807aeb230c97e74928c1b446544186bc4e1 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -55,12 +55,12 @@ struct commit *lookup_commit(const unsigned char *sha1)
 
 struct commit *lookup_commit_reference_by_name(const char *name)
 {
-       unsigned char sha1[20];
+       struct object_id oid;
        struct commit *commit;
 
-       if (get_sha1_committish(name, sha1))
+       if (get_sha1_committish(name, oid.hash))
                return NULL;
-       commit = lookup_commit_reference(sha1);
+       commit = lookup_commit_reference(oid.hash);
        if (parse_commit(commit))
                return NULL;
        return commit;
@@ -99,7 +99,7 @@ static int commit_graft_alloc, commit_graft_nr;
 static const unsigned char *commit_graft_sha1_access(size_t index, void *table)
 {
        struct commit_graft **commit_graft_table = table;
-       return commit_graft_table[index]->sha1;
+       return commit_graft_table[index]->oid.hash;
 }
 
 static int commit_graft_pos(const unsigned char *sha1)
@@ -110,7 +110,7 @@ static int commit_graft_pos(const unsigned char *sha1)
 
 int register_commit_graft(struct commit_graft *graft, int ignore_dups)
 {
-       int pos = commit_graft_pos(graft->sha1);
+       int pos = commit_graft_pos(graft->oid.hash);
 
        if (0 <= pos) {
                if (ignore_dups)
@@ -138,22 +138,23 @@ struct commit_graft *read_graft_line(char *buf, int len)
        /* The format is just "Commit Parent1 Parent2 ...\n" */
        int i;
        struct commit_graft *graft = NULL;
+       const int entry_size = GIT_SHA1_HEXSZ + 1;
 
        while (len && isspace(buf[len-1]))
                buf[--len] = '\0';
        if (buf[0] == '#' || buf[0] == '\0')
                return NULL;
-       if ((len + 1) % 41)
+       if ((len + 1) % entry_size)
                goto bad_graft_data;
-       i = (len + 1) / 41 - 1;
-       graft = xmalloc(sizeof(*graft) + 20 * i);
+       i = (len + 1) / entry_size - 1;
+       graft = xmalloc(sizeof(*graft) + GIT_SHA1_RAWSZ * i);
        graft->nr_parent = i;
-       if (get_sha1_hex(buf, graft->sha1))
+       if (get_oid_hex(buf, &graft->oid))
                goto bad_graft_data;
-       for (i = 40; i < len; i += 41) {
+       for (i = GIT_SHA1_HEXSZ; i < len; i += entry_size) {
                if (buf[i] != ' ')
                        goto bad_graft_data;
-               if (get_sha1_hex(buf + i + 1, graft->parent[i/41]))
+               if (get_sha1_hex(buf + i + 1, graft->parent[i/entry_size].hash))
                        goto bad_graft_data;
        }
        return graft;
@@ -302,39 +303,42 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
 {
        const char *tail = buffer;
        const char *bufptr = buffer;
-       unsigned char parent[20];
+       struct object_id parent;
        struct commit_list **pptr;
        struct commit_graft *graft;
+       const int tree_entry_len = GIT_SHA1_HEXSZ + 5;
+       const int parent_entry_len = GIT_SHA1_HEXSZ + 7;
 
        if (item->object.parsed)
                return 0;
        item->object.parsed = 1;
        tail += size;
-       if (tail <= bufptr + 46 || memcmp(bufptr, "tree ", 5) || bufptr[45] != '\n')
+       if (tail <= bufptr + tree_entry_len + 1 || memcmp(bufptr, "tree ", 5) ||
+                       bufptr[tree_entry_len] != '\n')
                return error("bogus commit object %s", sha1_to_hex(item->object.sha1));
-       if (get_sha1_hex(bufptr + 5, parent) < 0)
+       if (get_sha1_hex(bufptr + 5, parent.hash) < 0)
                return error("bad tree pointer in commit %s",
                             sha1_to_hex(item->object.sha1));
-       item->tree = lookup_tree(parent);
-       bufptr += 46; /* "tree " + "hex sha1" + "\n" */
+       item->tree = lookup_tree(parent.hash);
+       bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */
        pptr = &item->parents;
 
        graft = lookup_commit_graft(item->object.sha1);
-       while (bufptr + 48 < tail && !memcmp(bufptr, "parent ", 7)) {
+       while (bufptr + parent_entry_len < tail && !memcmp(bufptr, "parent ", 7)) {
                struct commit *new_parent;
 
-               if (tail <= bufptr + 48 ||
-                   get_sha1_hex(bufptr + 7, parent) ||
-                   bufptr[47] != '\n')
+               if (tail <= bufptr + parent_entry_len + 1 ||
+                   get_sha1_hex(bufptr + 7, parent.hash) ||
+                   bufptr[parent_entry_len] != '\n')
                        return error("bad parents in commit %s", sha1_to_hex(item->object.sha1));
-               bufptr += 48;
+               bufptr += parent_entry_len + 1;
                /*
                 * The clone is shallow if nr_parent < 0, and we must
                 * not traverse its real parents even when we unhide them.
                 */
                if (graft && (graft->nr_parent < 0 || grafts_replace_parents))
                        continue;
-               new_parent = lookup_commit(parent);
+               new_parent = lookup_commit(parent.hash);
                if (new_parent)
                        pptr = &commit_list_insert(new_parent, pptr)->next;
        }
@@ -342,7 +346,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
                int i;
                struct commit *new_parent;
                for (i = 0; i < graft->nr_parent; i++) {
-                       new_parent = lookup_commit(graft->parent[i]);
+                       new_parent = lookup_commit(graft->parent[i].hash);
                        if (!new_parent)
                                continue;
                        pptr = &commit_list_insert(new_parent, pptr)->next;
@@ -1580,10 +1584,10 @@ struct commit *get_merge_parent(const char *name)
 {
        struct object *obj;
        struct commit *commit;
-       unsigned char sha1[20];
-       if (get_sha1(name, sha1))
+       struct object_id oid;
+       if (get_sha1(name, oid.hash))
                return NULL;
-       obj = parse_object(sha1);
+       obj = parse_object(oid.hash);
        commit = (struct commit *)peel_to_type(name, 0, obj, OBJ_COMMIT);
        if (commit && !commit->util) {
                struct merge_remote_desc *desc;
index 9f189cb054266cd8f8c084853afbb678ca56c9e9..ed3a1d59a553b498b20d28f4999effde78e51c3c 100644 (file)
--- a/commit.h
+++ b/commit.h
@@ -226,9 +226,9 @@ enum rev_sort_order {
 void sort_in_topological_order(struct commit_list **, enum rev_sort_order);
 
 struct commit_graft {
-       unsigned char sha1[20];
+       struct object_id oid;
        int nr_parent; /* < 0 if shallow commit */
-       unsigned char parent[FLEX_ARRAY][20]; /* more */
+       struct object_id parent[FLEX_ARRAY]; /* more */
 };
 typedef int (*each_commit_graft_fn)(const struct commit_graft *, void *);
 
index 70f3191a4f19f10a156d1f2c054943d5147ab049..496e6f8bb0217c40450c61e88fbf1e08fdb3f704 100644 (file)
@@ -2128,3 +2128,14 @@ void mingw_startup()
        /* initialize Unicode console */
        winansi_init();
 }
+
+int uname(struct utsname *buf)
+{
+       DWORD v = GetVersion();
+       memset(buf, 0, sizeof(*buf));
+       strcpy(buf->sysname, "Windows");
+       sprintf(buf->release, "%u.%u", v & 0xff, (v >> 8) & 0xff);
+       /* assuming NT variants only.. */
+       sprintf(buf->version, "%u", (v >> 16) & 0x7fff);
+       return 0;
+}
index 5e499cfb71a00ea81013c1ed21e9a5e9dc9e2544..738865c6c068ed7d8849aff5a9b533dfb1ef8bab 100644 (file)
@@ -76,6 +76,14 @@ struct itimerval {
 };
 #define ITIMER_REAL 0
 
+struct utsname {
+       char sysname[16];
+       char nodename[1];
+       char release[16];
+       char version[16];
+       char machine[1];
+};
+
 /*
  * sanitize preprocessor namespace polluted by Windows headers defining
  * macros which collide with git local versions
@@ -98,8 +106,6 @@ static inline unsigned int alarm(unsigned int seconds)
 { return 0; }
 static inline int fsync(int fd)
 { return _commit(fd); }
-static inline pid_t getppid(void)
-{ return 1; }
 static inline void sync(void)
 {}
 static inline uid_t getuid(void)
@@ -121,6 +127,12 @@ static inline int sigaddset(sigset_t *set, int signum)
 #define SIG_UNBLOCK 0
 static inline int sigprocmask(int how, const sigset_t *set, sigset_t *oldset)
 { return 0; }
+static inline pid_t getppid(void)
+{ return 1; }
+static inline pid_t getpgid(pid_t pid)
+{ return pid == 0 ? getpid() : pid; }
+static inline pid_t tcgetpgrp(int fd)
+{ return getpid(); }
 
 /*
  * simple adaptors
@@ -171,6 +183,7 @@ struct passwd *getpwuid(uid_t uid);
 int setitimer(int type, struct itimerval *in, struct itimerval *out);
 int sigaction(int sig, struct sigaction *in, struct sigaction *out);
 int link(const char *oldpath, const char *newpath);
+int uname(struct utsname *buf);
 
 /*
  * replacements of existing functions
index c4424c01388496b5995e19f9601f0c87b9fdd3c0..ab46462e151dd5cd9d1e5a1fecd23fe5c6607c5d 100644 (file)
--- a/config.c
+++ b/config.c
@@ -50,7 +50,7 @@ static struct config_set the_config_set;
 
 static int config_file_fgetc(struct config_source *conf)
 {
-       return fgetc(conf->u.file);
+       return getc_unlocked(conf->u.file);
 }
 
 static int config_file_ungetc(int c, struct config_source *conf)
@@ -1088,7 +1088,9 @@ int git_config_from_file(config_fn_t fn, const char *filename, void *data)
 
        f = fopen(filename, "r");
        if (f) {
+               flockfile(f);
                ret = do_config_from_file(fn, filename, filename, f, data);
+               funlockfile(f);
                fclose(f);
        }
        return ret;
@@ -1185,10 +1187,8 @@ int git_config_system(void)
 int git_config_early(config_fn_t fn, void *data, const char *repo_config)
 {
        int ret = 0, found = 0;
-       char *xdg_config = NULL;
-       char *user_config = NULL;
-
-       home_config_paths(&user_config, &xdg_config, "config");
+       char *xdg_config = xdg_config_home("config");
+       char *user_config = expand_user_path("~/.gitconfig");
 
        if (git_config_system() && !access_or_die(git_etc_gitconfig(), R_OK, 0)) {
                ret += git_config_from_file(fn, git_etc_gitconfig(),
index f4e77cb9e5099cd3de723ad98894c92d516f176e..d26665fa54c90a45724c0eb6bdbcbb81c94574a1 100644 (file)
@@ -36,6 +36,7 @@ ifeq ($(uname_S),Linux)
        HAVE_DEV_TTY = YesPlease
        HAVE_CLOCK_GETTIME = YesPlease
        HAVE_CLOCK_MONOTONIC = YesPlease
+       HAVE_GETDELIM = YesPlease
 endif
 ifeq ($(uname_S),GNU/kFreeBSD)
        HAVE_ALLOCA_H = YesPlease
index 391d21192f8d9593ce9b194488019eae3ec7d8d3..c0144d859ae4275860df464f73a688c649d092fe 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -724,7 +724,7 @@ struct child_process *git_connect(int fd[2], const char *url,
                conn->in = conn->out = -1;
                if (protocol == PROTO_SSH) {
                        const char *ssh;
-                       int putty;
+                       int putty, tortoiseplink = 0;
                        char *ssh_host = hostandport;
                        const char *port = NULL;
                        get_host_and_port(&ssh_host, &port);
@@ -743,28 +743,40 @@ struct child_process *git_connect(int fd[2], const char *url,
                                free(path);
                                free(conn);
                                return NULL;
+                       }
+
+                       ssh = getenv("GIT_SSH_COMMAND");
+                       if (ssh) {
+                               conn->use_shell = 1;
+                               putty = 0;
                        } else {
-                               ssh = getenv("GIT_SSH_COMMAND");
-                               if (ssh) {
-                                       conn->use_shell = 1;
-                                       putty = 0;
-                               } else {
-                                       ssh = getenv("GIT_SSH");
-                                       if (!ssh)
-                                               ssh = "ssh";
-                                       putty = !!strcasestr(ssh, "plink");
-                               }
-
-                               argv_array_push(&conn->args, ssh);
-                               if (putty && !strcasestr(ssh, "tortoiseplink"))
-                                       argv_array_push(&conn->args, "-batch");
-                               if (port) {
-                                       /* P is for PuTTY, p is for OpenSSH */
-                                       argv_array_push(&conn->args, putty ? "-P" : "-p");
-                                       argv_array_push(&conn->args, port);
-                               }
-                               argv_array_push(&conn->args, ssh_host);
+                               const char *base;
+                               char *ssh_dup;
+
+                               ssh = getenv("GIT_SSH");
+                               if (!ssh)
+                                       ssh = "ssh";
+
+                               ssh_dup = xstrdup(ssh);
+                               base = basename(ssh_dup);
+
+                               tortoiseplink = !strcasecmp(base, "tortoiseplink") ||
+                                       !strcasecmp(base, "tortoiseplink.exe");
+                               putty = !strcasecmp(base, "plink") ||
+                                       !strcasecmp(base, "plink.exe") || tortoiseplink;
+
+                               free(ssh_dup);
+                       }
+
+                       argv_array_push(&conn->args, ssh);
+                       if (tortoiseplink)
+                               argv_array_push(&conn->args, "-batch");
+                       if (port) {
+                               /* P is for PuTTY, p is for OpenSSH */
+                               argv_array_push(&conn->args, putty ? "-P" : "-p");
+                               argv_array_push(&conn->args, port);
                        }
+                       argv_array_push(&conn->args, ssh_host);
                } else {
                        /* remove repo-local variables from the environment */
                        conn->env = local_repo_env;
index eae9dce590e0000eb93e441106ef6538c07e86cc..bfc74e9d57a5293fce39362c68e7490888ec08e6 100644 (file)
@@ -665,8 +665,8 @@ __git_list_porcelain_commands ()
                checkout-index)   : plumbing;;
                commit-tree)      : plumbing;;
                count-objects)    : infrequent;;
-               credential-cache) : credentials helper;;
-               credential-store) : credentials helper;;
+               credential)       : credentials;;
+               credential-*)     : credentials helper;;
                cvsexportcommit)  : export;;
                cvsimport)        : import;;
                cvsserver)        : daemon;;
@@ -735,35 +735,29 @@ __git_list_porcelain_commands ()
 __git_porcelain_commands=
 __git_compute_porcelain_commands ()
 {
-       __git_compute_all_commands
        test -n "$__git_porcelain_commands" ||
        __git_porcelain_commands=$(__git_list_porcelain_commands)
 }
 
-__git_pretty_aliases ()
+# Lists all set config variables starting with the given section prefix,
+# with the prefix removed.
+__git_get_config_variables ()
 {
-       local i IFS=$'\n'
-       for i in $(git --git-dir="$(__gitdir)" config --get-regexp "pretty\..*" 2>/dev/null); do
-               case "$i" in
-               pretty.*)
-                       i="${i#pretty.}"
-                       echo "${i/ */}"
-                       ;;
-               esac
+       local section="$1" i IFS=$'\n'
+       for i in $(git --git-dir="$(__gitdir)" config --get-regexp "^$section\..*" 2>/dev/null); do
+               i="${i#$section.}"
+               echo "${i/ */}"
        done
 }
 
+__git_pretty_aliases ()
+{
+       __git_get_config_variables "pretty"
+}
+
 __git_aliases ()
 {
-       local i IFS=$'\n'
-       for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
-               case "$i" in
-               alias.*)
-                       i="${i#alias.}"
-                       echo "${i/ */}"
-                       ;;
-               esac
-       done
+       __git_get_config_variables "alias"
 }
 
 # __git_aliased_command requires 1 argument
@@ -2123,6 +2117,7 @@ _git_config ()
                http.noEPSV
                http.postBuffer
                http.proxy
+               http.sslCipherList
                http.sslCAInfo
                http.sslCAPath
                http.sslCert
@@ -2260,12 +2255,7 @@ _git_remote ()
                __git_complete_remote_or_refspec
                ;;
        update)
-               local i c='' IFS=$'\n'
-               for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
-                       i="${i#remotes.}"
-                       c="$c ${i/ */}"
-               done
-               __gitcomp "$c"
+               __gitcomp "$(__git_get_config_variables "remotes")"
                ;;
        *)
                ;;
index fa1a5839af2d0c423adb51238fb330f555dc4dff..07bd77c4c8c63cff3ecac05f9ce922fda5fddf67 100755 (executable)
@@ -26,7 +26,7 @@ b,branch=     create a new branch from the split subtree
 ignore-joins  ignore prior --rejoin commits
 onto=         try connecting new tree to an existing one
 rejoin        merge the new branch back into HEAD
- options for 'add', 'merge', 'pull' and 'push'
+ options for 'add', 'merge', and 'pull'
 squash        merge subtree changes as a single commit
 "
 eval "$(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)"
@@ -51,14 +51,21 @@ prefix=
 debug()
 {
        if [ -n "$debug" ]; then
-               echo "$@" >&2
+               printf "%s\n" "$*" >&2
        fi
 }
 
 say()
 {
        if [ -z "$quiet" ]; then
-               echo "$@" >&2
+               printf "%s\n" "$*" >&2
+       fi
+}
+
+progress()
+{
+       if [ -z "$quiet" ]; then
+               printf "%s\r" "$*" >&2
        fi
 }
 
@@ -599,7 +606,7 @@ cmd_split()
        eval "$grl" |
        while read rev parents; do
                revcount=$(($revcount + 1))
-               say -n "$revcount/$revmax ($createcount)\r"
+               progress "$revcount/$revmax ($createcount)"
                debug "Processing commit: $rev"
                exists=$(cache_get $rev)
                if [ -n "$exists" ]; then
index 54e4b4a24331045d97d92355b681b675048a5df7..60d76cdddfc75f0c77d5798ac0b1adc6b0e93899 100644 (file)
@@ -146,7 +146,7 @@ OPTIONS
 OPTIONS FOR add, merge, push, pull
 ----------------------------------
 --squash::
-       This option is only valid for add, merge, push and pull
+       This option is only valid for add, merge, and pull
        commands.
 +
 Instead of merging the entire history from the subtree project, produce
index 9a5612e93da2058f64bcec20cfd474a8b6b2d223..f3bd3e93fb2ecf95413db3c53d7e686cd03d1e69 100644 (file)
--- a/convert.c
+++ b/convert.c
@@ -356,9 +356,14 @@ static int filter_buffer_or_fd(int in, int out, void *data)
        sigchain_push(SIGPIPE, SIG_IGN);
 
        if (params->src) {
-               write_err = (write_in_full(child_process.in, params->src, params->size) < 0);
+               write_err = (write_in_full(child_process.in,
+                                          params->src, params->size) < 0);
+               if (errno == EPIPE)
+                       write_err = 0;
        } else {
                write_err = copy_fd(params->fd, child_process.in);
+               if (write_err == COPY_WRITE_ERROR && errno == EPIPE)
+                       write_err = 0;
        }
 
        if (close(child_process.in))
diff --git a/copy.c b/copy.c
index f2970ec46282a07593366c598f688e5d70c05c83..574fa1f09dadc2e9cc9a39702bafb352f71a56c4 100644 (file)
--- a/copy.c
+++ b/copy.c
@@ -7,13 +7,10 @@ int copy_fd(int ifd, int ofd)
                ssize_t len = xread(ifd, buffer, sizeof(buffer));
                if (!len)
                        break;
-               if (len < 0) {
-                       return error("copy-fd: read returned %s",
-                                    strerror(errno));
-               }
+               if (len < 0)
+                       return COPY_READ_ERROR;
                if (write_in_full(ofd, buffer, len) < 0)
-                       return error("copy-fd: write returned %s",
-                                    strerror(errno));
+                       return COPY_WRITE_ERROR;
        }
        return 0;
 }
@@ -43,6 +40,14 @@ int copy_file(const char *dst, const char *src, int mode)
                return fdo;
        }
        status = copy_fd(fdi, fdo);
+       switch (status) {
+       case COPY_READ_ERROR:
+               error("copy-fd: read returned %s", strerror(errno));
+               break;
+       case COPY_WRITE_ERROR:
+               error("copy-fd: write returned %s", strerror(errno));
+               break;
+       }
        close(fdi);
        if (close(fdo) != 0)
                return error("%s: close error: %s", dst, strerror(errno));
index 925d3f40247d7f41d709b4e6b3eaabaf646572b6..f6925096ffa7e036b4e63f65ce372c596c9e1b70 100644 (file)
@@ -6,7 +6,7 @@
 
 static struct lock_file credential_lock;
 
-static void parse_credential_file(const char *fn,
+static int parse_credential_file(const char *fn,
                                  struct credential *c,
                                  void (*match_cb)(struct credential *),
                                  void (*other_cb)(struct strbuf *))
@@ -14,18 +14,20 @@ static void parse_credential_file(const char *fn,
        FILE *fh;
        struct strbuf line = STRBUF_INIT;
        struct credential entry = CREDENTIAL_INIT;
+       int found_credential = 0;
 
        fh = fopen(fn, "r");
        if (!fh) {
-               if (errno != ENOENT)
+               if (errno != ENOENT && errno != EACCES)
                        die_errno("unable to open %s", fn);
-               return;
+               return found_credential;
        }
 
        while (strbuf_getline(&line, fh, '\n') != EOF) {
                credential_from_url(&entry, line.buf);
                if (entry.username && entry.password &&
                    credential_match(c, &entry)) {
+                       found_credential = 1;
                        if (match_cb) {
                                match_cb(&entry);
                                break;
@@ -38,6 +40,7 @@ static void parse_credential_file(const char *fn,
        credential_clear(&entry);
        strbuf_release(&line);
        fclose(fh);
+       return found_credential;
 }
 
 static void print_entry(struct credential *c)
@@ -64,21 +67,10 @@ static void rewrite_credential_file(const char *fn, struct credential *c,
                die_errno("unable to commit credential store");
 }
 
-static void store_credential(const char *fn, struct credential *c)
+static void store_credential_file(const char *fn, struct credential *c)
 {
        struct strbuf buf = STRBUF_INIT;
 
-       /*
-        * Sanity check that what we are storing is actually sensible.
-        * In particular, we can't make a URL without a protocol field.
-        * Without either a host or pathname (depending on the scheme),
-        * we have no primary key. And without a username and password,
-        * we are not actually storing a credential.
-        */
-       if (!c->protocol || !(c->host || c->path) ||
-           !c->username || !c->password)
-               return;
-
        strbuf_addf(&buf, "%s://", c->protocol);
        strbuf_addstr_urlencode(&buf, c->username, 1);
        strbuf_addch(&buf, ':');
@@ -95,8 +87,37 @@ static void store_credential(const char *fn, struct credential *c)
        strbuf_release(&buf);
 }
 
-static void remove_credential(const char *fn, struct credential *c)
+static void store_credential(const struct string_list *fns, struct credential *c)
+{
+       struct string_list_item *fn;
+
+       /*
+        * Sanity check that what we are storing is actually sensible.
+        * In particular, we can't make a URL without a protocol field.
+        * Without either a host or pathname (depending on the scheme),
+        * we have no primary key. And without a username and password,
+        * we are not actually storing a credential.
+        */
+       if (!c->protocol || !(c->host || c->path) || !c->username || !c->password)
+               return;
+
+       for_each_string_list_item(fn, fns)
+               if (!access(fn->string, F_OK)) {
+                       store_credential_file(fn->string, c);
+                       return;
+               }
+       /*
+        * Write credential to the filename specified by fns->items[0], thus
+        * creating it
+        */
+       if (fns->nr)
+               store_credential_file(fns->items[0].string, c);
+}
+
+static void remove_credential(const struct string_list *fns, struct credential *c)
 {
+       struct string_list_item *fn;
+
        /*
         * Sanity check that we actually have something to match
         * against. The input we get is a restrictive pattern,
@@ -105,14 +126,20 @@ static void remove_credential(const char *fn, struct credential *c)
         * to empty input. So explicitly disallow it, and require that the
         * pattern have some actual content to match.
         */
-       if (c->protocol || c->host || c->path || c->username)
-               rewrite_credential_file(fn, c, NULL);
+       if (!c->protocol && !c->host && !c->path && !c->username)
+               return;
+       for_each_string_list_item(fn, fns)
+               if (!access(fn->string, F_OK))
+                       rewrite_credential_file(fn->string, c, NULL);
 }
 
-static int lookup_credential(const char *fn, struct credential *c)
+static void lookup_credential(const struct string_list *fns, struct credential *c)
 {
-       parse_credential_file(fn, c, print_entry, NULL);
-       return c->username && c->password;
+       struct string_list_item *fn;
+
+       for_each_string_list_item(fn, fns)
+               if (parse_credential_file(fn->string, c, print_entry, NULL))
+                       return; /* Found credential */
 }
 
 int main(int argc, char **argv)
@@ -123,6 +150,7 @@ int main(int argc, char **argv)
        };
        const char *op;
        struct credential c = CREDENTIAL_INIT;
+       struct string_list fns = STRING_LIST_INIT_DUP;
        char *file = NULL;
        struct option options[] = {
                OPT_STRING(0, "file", &file, "path",
@@ -137,22 +165,30 @@ int main(int argc, char **argv)
                usage_with_options(usage, options);
        op = argv[0];
 
-       if (!file)
-               file = expand_user_path("~/.git-credentials");
-       if (!file)
+       if (file) {
+               string_list_append(&fns, file);
+       } else {
+               if ((file = expand_user_path("~/.git-credentials")))
+                       string_list_append_nodup(&fns, file);
+               file = xdg_config_home("credentials");
+               if (file)
+                       string_list_append_nodup(&fns, file);
+       }
+       if (!fns.nr)
                die("unable to set up default path; use --file");
 
        if (credential_read(&c, stdin) < 0)
                die("unable to read credential");
 
        if (!strcmp(op, "get"))
-               lookup_credential(file, &c);
+               lookup_credential(&fns, &c);
        else if (!strcmp(op, "erase"))
-               remove_credential(file, &c);
+               remove_credential(&fns, &c);
        else if (!strcmp(op, "store"))
-               store_credential(file, &c);
+               store_credential(&fns, &c);
        else
                ; /* Ignore unknown operation. */
 
+       string_list_clear(&fns, 0);
        return 0;
 }
index 4be10914e63bda68272c25e52cb199346cf9ec3c..d3d3e433e370e7a21dad829b5861172e92a6d72f 100644 (file)
--- a/daemon.c
+++ b/daemon.c
@@ -1166,15 +1166,6 @@ static struct credentials *prepare_credentials(const char *user_name,
 }
 #endif
 
-static void store_pid(const char *path)
-{
-       FILE *f = fopen(path, "w");
-       if (!f)
-               die_errno("cannot open pid file '%s'", path);
-       if (fprintf(f, "%"PRIuMAX"\n", (uintmax_t) getpid()) < 0 || fclose(f) != 0)
-               die_errno("failed to write pid file '%s'", path);
-}
-
 static int serve(struct string_list *listen_addr, int listen_port,
     struct credentials *cred)
 {
@@ -1385,7 +1376,7 @@ int main(int argc, char **argv)
                sanitize_stdfds();
 
        if (pid_file)
-               store_pid(pid_file);
+               write_file(pid_file, 1, "%"PRIuMAX"\n", (uintmax_t) getpid());
 
        /* prepare argv for serving-processes */
        cld_argv = xmalloc(sizeof (char *) * (argc + 2));
index a85c4971ac8ece6397c05d0674bbac8c75cf219f..0d8c5358e4236bf1d0c2ceb214d6a4fa09b2d2de 100644 (file)
@@ -125,7 +125,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
                        dpath->next = NULL;
                        memcpy(dpath->path, ce->name, path_len);
                        dpath->path[path_len] = '\0';
-                       hashclr(dpath->sha1);
+                       oidclr(&dpath->oid);
                        memset(&(dpath->parent[0]), 0,
                               sizeof(struct combine_diff_parent)*5);
 
@@ -155,7 +155,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
                                if (2 <= stage) {
                                        int mode = nce->ce_mode;
                                        num_compare_stages++;
-                                       hashcpy(dpath->parent[stage-2].sha1, nce->sha1);
+                                       hashcpy(dpath->parent[stage-2].oid.hash, nce->sha1);
                                        dpath->parent[stage-2].mode = ce_mode_from_stat(nce, mode);
                                        dpath->parent[stage-2].status =
                                                DIFF_STATUS_MODIFIED;
@@ -212,6 +212,11 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
                                               ce->sha1, !is_null_sha1(ce->sha1),
                                               ce->name, 0);
                                continue;
+                       } else if (ce->ce_flags & CE_INTENT_TO_ADD) {
+                               diff_addremove(&revs->diffopt, '+', ce->ce_mode,
+                                              EMPTY_BLOB_SHA1_BIN, 0,
+                                              ce->name, 0);
+                               continue;
                        }
 
                        changed = match_stat_with_submodule(&revs->diffopt, ce, &st,
@@ -339,14 +344,14 @@ static int show_modified(struct rev_info *revs,
                memcpy(p->path, new->name, pathlen);
                p->path[pathlen] = 0;
                p->mode = mode;
-               hashclr(p->sha1);
+               oidclr(&p->oid);
                memset(p->parent, 0, 2 * sizeof(struct combine_diff_parent));
                p->parent[0].status = DIFF_STATUS_MODIFIED;
                p->parent[0].mode = new->ce_mode;
-               hashcpy(p->parent[0].sha1, new->sha1);
+               hashcpy(p->parent[0].oid.hash, new->sha1);
                p->parent[1].status = DIFF_STATUS_MODIFIED;
                p->parent[1].mode = old->ce_mode;
-               hashcpy(p->parent[1].sha1, old->sha1);
+               hashcpy(p->parent[1].oid.hash, old->sha1);
                show_combined_diff(p, 2, revs->dense_combined_merges, revs);
                free(p);
                return 0;
@@ -376,6 +381,13 @@ static void do_oneway_diff(struct unpack_trees_options *o,
        struct rev_info *revs = o->unpack_data;
        int match_missing, cached;
 
+       /* i-t-a entries do not actually exist in the index */
+       if (idx && (idx->ce_flags & CE_INTENT_TO_ADD)) {
+               idx = NULL;
+               if (!tree)
+                       return; /* nothing to diff.. */
+       }
+
        /* if the entry is not checked out, don't examine work tree */
        cached = o->index_only ||
                (idx && ((idx->ce_flags & CE_VALID) || ce_skip_worktree(idx)));
diff --git a/diff.h b/diff.h
index b4a624d235748bf13be44e7479f086880dcf574f..f6fdf49e14b7c0e2997e7516275013555555e908 100644 (file)
--- a/diff.h
+++ b/diff.h
@@ -6,6 +6,7 @@
 
 #include "tree-walk.h"
 #include "pathspec.h"
+#include "object.h"
 
 struct rev_info;
 struct diff_options;
@@ -207,11 +208,11 @@ struct combine_diff_path {
        struct combine_diff_path *next;
        char *path;
        unsigned int mode;
-       unsigned char sha1[20];
+       struct object_id oid;
        struct combine_diff_parent {
                char status;
                unsigned int mode;
-               unsigned char sha1[20];
+               struct object_id oid;
        } parent[FLEX_ARRAY];
 };
 #define combine_diff_path_size(n, l) \
diff --git a/dir.c b/dir.c
index a3e70734004e5da22dce9ba4062c0d6684061855..d318ffcb2a6a51feca5aee993049fd0fa64acc8f 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -13,6 +13,8 @@
 #include "wildmatch.h"
 #include "pathspec.h"
 #include "utf8.h"
+#include "varint.h"
+#include "ewah/ewok.h"
 
 struct path_simplify {
        int len;
@@ -32,8 +34,22 @@ enum path_treatment {
        path_untracked
 };
 
+/*
+ * Support data structure for our opendir/readdir/closedir wrappers
+ */
+struct cached_dir {
+       DIR *fdir;
+       struct untracked_cache_dir *untracked;
+       int nr_files;
+       int nr_dirs;
+
+       struct dirent *de;
+       const char *file;
+       struct untracked_cache_dir *ucd;
+};
+
 static enum path_treatment read_directory_recursive(struct dir_struct *dir,
-       const char *path, int len,
+       const char *path, int len, struct untracked_cache_dir *untracked,
        int check_only, const struct path_simplify *simplify);
 static int get_dtype(struct dirent *de, const char *path, int len);
 
@@ -510,7 +526,8 @@ void add_exclude(const char *string, const char *base,
        x->el = el;
 }
 
-static void *read_skip_worktree_file_from_index(const char *path, size_t *size)
+static void *read_skip_worktree_file_from_index(const char *path, size_t *size,
+                                               struct sha1_stat *sha1_stat)
 {
        int pos, len;
        unsigned long sz;
@@ -529,6 +546,10 @@ static void *read_skip_worktree_file_from_index(const char *path, size_t *size)
                return NULL;
        }
        *size = xsize_t(sz);
+       if (sha1_stat) {
+               memset(&sha1_stat->stat, 0, sizeof(sha1_stat->stat));
+               hashcpy(sha1_stat->sha1, active_cache[pos]->sha1);
+       }
        return data;
 }
 
@@ -573,11 +594,93 @@ static void trim_trailing_spaces(char *buf)
                *last_space = '\0';
 }
 
-int add_excludes_from_file_to_list(const char *fname,
-                                  const char *base,
-                                  int baselen,
-                                  struct exclude_list *el,
-                                  int check_index)
+/*
+ * Given a subdirectory name and "dir" of the current directory,
+ * search the subdir in "dir" and return it, or create a new one if it
+ * does not exist in "dir".
+ *
+ * If "name" has the trailing slash, it'll be excluded in the search.
+ */
+static struct untracked_cache_dir *lookup_untracked(struct untracked_cache *uc,
+                                                   struct untracked_cache_dir *dir,
+                                                   const char *name, int len)
+{
+       int first, last;
+       struct untracked_cache_dir *d;
+       if (!dir)
+               return NULL;
+       if (len && name[len - 1] == '/')
+               len--;
+       first = 0;
+       last = dir->dirs_nr;
+       while (last > first) {
+               int cmp, next = (last + first) >> 1;
+               d = dir->dirs[next];
+               cmp = strncmp(name, d->name, len);
+               if (!cmp && strlen(d->name) > len)
+                       cmp = -1;
+               if (!cmp)
+                       return d;
+               if (cmp < 0) {
+                       last = next;
+                       continue;
+               }
+               first = next+1;
+       }
+
+       uc->dir_created++;
+       d = xmalloc(sizeof(*d) + len + 1);
+       memset(d, 0, sizeof(*d));
+       memcpy(d->name, name, len);
+       d->name[len] = '\0';
+
+       ALLOC_GROW(dir->dirs, dir->dirs_nr + 1, dir->dirs_alloc);
+       memmove(dir->dirs + first + 1, dir->dirs + first,
+               (dir->dirs_nr - first) * sizeof(*dir->dirs));
+       dir->dirs_nr++;
+       dir->dirs[first] = d;
+       return d;
+}
+
+static void do_invalidate_gitignore(struct untracked_cache_dir *dir)
+{
+       int i;
+       dir->valid = 0;
+       dir->untracked_nr = 0;
+       for (i = 0; i < dir->dirs_nr; i++)
+               do_invalidate_gitignore(dir->dirs[i]);
+}
+
+static void invalidate_gitignore(struct untracked_cache *uc,
+                                struct untracked_cache_dir *dir)
+{
+       uc->gitignore_invalidated++;
+       do_invalidate_gitignore(dir);
+}
+
+static void invalidate_directory(struct untracked_cache *uc,
+                                struct untracked_cache_dir *dir)
+{
+       int i;
+       uc->dir_invalidated++;
+       dir->valid = 0;
+       dir->untracked_nr = 0;
+       for (i = 0; i < dir->dirs_nr; i++)
+               dir->dirs[i]->recurse = 0;
+}
+
+/*
+ * Given a file with name "fname", read it (either from disk, or from
+ * the index if "check_index" is non-zero), parse it and store the
+ * exclude rules in "el".
+ *
+ * If "ss" is not NULL, compute SHA-1 of the exclude file and fill
+ * stat data from disk (only valid if add_excludes returns zero). If
+ * ss_valid is non-zero, "ss" must contain good value as input.
+ */
+static int add_excludes(const char *fname, const char *base, int baselen,
+                       struct exclude_list *el, int check_index,
+                       struct sha1_stat *sha1_stat)
 {
        struct stat st;
        int fd, i, lineno = 1;
@@ -591,7 +694,7 @@ int add_excludes_from_file_to_list(const char *fname,
                if (0 <= fd)
                        close(fd);
                if (!check_index ||
-                   (buf = read_skip_worktree_file_from_index(fname, &size)) == NULL)
+                   (buf = read_skip_worktree_file_from_index(fname, &size, sha1_stat)) == NULL)
                        return -1;
                if (size == 0) {
                        free(buf);
@@ -604,6 +707,11 @@ int add_excludes_from_file_to_list(const char *fname,
        } else {
                size = xsize_t(st.st_size);
                if (size == 0) {
+                       if (sha1_stat) {
+                               fill_stat_data(&sha1_stat->stat, &st);
+                               hashcpy(sha1_stat->sha1, EMPTY_BLOB_SHA1_BIN);
+                               sha1_stat->valid = 1;
+                       }
                        close(fd);
                        return 0;
                }
@@ -615,6 +723,22 @@ int add_excludes_from_file_to_list(const char *fname,
                }
                buf[size++] = '\n';
                close(fd);
+               if (sha1_stat) {
+                       int pos;
+                       if (sha1_stat->valid &&
+                           !match_stat_data_racy(&the_index, &sha1_stat->stat, &st))
+                               ; /* no content change, ss->sha1 still good */
+                       else if (check_index &&
+                                (pos = cache_name_pos(fname, strlen(fname))) >= 0 &&
+                                !ce_stage(active_cache[pos]) &&
+                                ce_uptodate(active_cache[pos]) &&
+                                !would_convert_to_git(fname))
+                               hashcpy(sha1_stat->sha1, active_cache[pos]->sha1);
+                       else
+                               hash_sha1_file(buf, size, "blob", sha1_stat->sha1);
+                       fill_stat_data(&sha1_stat->stat, &st);
+                       sha1_stat->valid = 1;
+               }
        }
 
        el->filebuf = buf;
@@ -638,6 +762,13 @@ int add_excludes_from_file_to_list(const char *fname,
        return 0;
 }
 
+int add_excludes_from_file_to_list(const char *fname, const char *base,
+                                  int baselen, struct exclude_list *el,
+                                  int check_index)
+{
+       return add_excludes(fname, base, baselen, el, check_index, NULL);
+}
+
 struct exclude_list *add_exclude_list(struct dir_struct *dir,
                                      int group_type, const char *src)
 {
@@ -655,14 +786,28 @@ struct exclude_list *add_exclude_list(struct dir_struct *dir,
 /*
  * Used to set up core.excludesfile and .git/info/exclude lists.
  */
-void add_excludes_from_file(struct dir_struct *dir, const char *fname)
+static void add_excludes_from_file_1(struct dir_struct *dir, const char *fname,
+                                    struct sha1_stat *sha1_stat)
 {
        struct exclude_list *el;
+       /*
+        * catch setup_standard_excludes() that's called before
+        * dir->untracked is assigned. That function behaves
+        * differently when dir->untracked is non-NULL.
+        */
+       if (!dir->untracked)
+               dir->unmanaged_exclude_files++;
        el = add_exclude_list(dir, EXC_FILE, fname);
-       if (add_excludes_from_file_to_list(fname, "", 0, el, 0) < 0)
+       if (add_excludes(fname, "", 0, el, 0, sha1_stat) < 0)
                die("cannot use %s as an exclude file", fname);
 }
 
+void add_excludes_from_file(struct dir_struct *dir, const char *fname)
+{
+       dir->unmanaged_exclude_files++; /* see validate_untracked_cache() */
+       add_excludes_from_file_1(dir, fname, NULL);
+}
+
 int match_basename(const char *basename, int basenamelen,
                   const char *pattern, int prefix, int patternlen,
                   int flags)
@@ -837,6 +982,7 @@ static void prep_exclude(struct dir_struct *dir, const char *base, int baselen)
        struct exclude_list_group *group;
        struct exclude_list *el;
        struct exclude_stack *stk = NULL;
+       struct untracked_cache_dir *untracked;
        int current;
 
        group = &dir->exclude_list_group[EXC_DIRS];
@@ -874,8 +1020,14 @@ static void prep_exclude(struct dir_struct *dir, const char *base, int baselen)
        /* Read from the parent directories and push them down. */
        current = stk ? stk->baselen : -1;
        strbuf_setlen(&dir->basebuf, current < 0 ? 0 : current);
+       if (dir->untracked)
+               untracked = stk ? stk->ucd : dir->untracked->root;
+       else
+               untracked = NULL;
+
        while (current < baselen) {
                const char *cp;
+               struct sha1_stat sha1_stat;
 
                stk = xcalloc(1, sizeof(*stk));
                if (current < 0) {
@@ -886,10 +1038,15 @@ static void prep_exclude(struct dir_struct *dir, const char *base, int baselen)
                        if (!cp)
                                die("oops in prep_exclude");
                        cp++;
+                       untracked =
+                               lookup_untracked(dir->untracked, untracked,
+                                                base + current,
+                                                cp - base - current);
                }
                stk->prev = dir->exclude_stack;
                stk->baselen = cp - base;
                stk->exclude_ix = group->nr;
+               stk->ucd = untracked;
                el = add_exclude_list(dir, EXC_DIRS, NULL);
                strbuf_add(&dir->basebuf, base + current, stk->baselen - current);
                assert(stk->baselen == dir->basebuf.len);
@@ -912,7 +1069,23 @@ static void prep_exclude(struct dir_struct *dir, const char *base, int baselen)
                }
 
                /* Try to read per-directory file */
-               if (dir->exclude_per_dir) {
+               hashclr(sha1_stat.sha1);
+               sha1_stat.valid = 0;
+               if (dir->exclude_per_dir &&
+                   /*
+                    * If we know that no files have been added in
+                    * this directory (i.e. valid_cached_dir() has
+                    * been executed and set untracked->valid) ..
+                    */
+                   (!untracked || !untracked->valid ||
+                    /*
+                     * .. and .gitignore does not exist before
+                     * (i.e. null exclude_sha1 and skip_worktree is
+                     * not set). Then we can skip loading .gitignore,
+                     * which would result in ENOENT anyway.
+                     * skip_worktree is taken care in read_directory()
+                     */
+                    !is_null_sha1(untracked->exclude_sha1))) {
                        /*
                         * dir->basebuf gets reused by the traversal, but we
                         * need fname to remain unchanged to ensure the src
@@ -925,8 +1098,27 @@ static void prep_exclude(struct dir_struct *dir, const char *base, int baselen)
                        strbuf_addbuf(&sb, &dir->basebuf);
                        strbuf_addstr(&sb, dir->exclude_per_dir);
                        el->src = strbuf_detach(&sb, NULL);
-                       add_excludes_from_file_to_list(el->src, el->src,
-                                                      stk->baselen, el, 1);
+                       add_excludes(el->src, el->src, stk->baselen, el, 1,
+                                    untracked ? &sha1_stat : NULL);
+               }
+               /*
+                * NEEDSWORK: when untracked cache is enabled, prep_exclude()
+                * will first be called in valid_cached_dir() then maybe many
+                * times more in last_exclude_matching(). When the cache is
+                * used, last_exclude_matching() will not be called and
+                * reading .gitignore content will be a waste.
+                *
+                * So when it's called by valid_cached_dir() and we can get
+                * .gitignore SHA-1 from the index (i.e. .gitignore is not
+                * modified on work tree), we could delay reading the
+                * .gitignore content until we absolutely need it in
+                * last_exclude_matching(). Be careful about ignore rule
+                * order, though, if you do that.
+                */
+               if (untracked &&
+                   hashcmp(sha1_stat.sha1, untracked->exclude_sha1)) {
+                       invalidate_gitignore(dir->untracked, untracked);
+                       hashcpy(untracked->exclude_sha1, sha1_stat.sha1);
                }
                dir->exclude_stack = stk;
                current = stk->baselen;
@@ -1107,6 +1299,7 @@ static enum exist_status directory_exists_in_index(const char *dirname, int len)
  *  (c) otherwise, we recurse into it.
  */
 static enum path_treatment treat_directory(struct dir_struct *dir,
+       struct untracked_cache_dir *untracked,
        const char *dirname, int len, int exclude,
        const struct path_simplify *simplify)
 {
@@ -1134,7 +1327,9 @@ static enum path_treatment treat_directory(struct dir_struct *dir,
        if (!(dir->flags & DIR_HIDE_EMPTY_DIRECTORIES))
                return exclude ? path_excluded : path_untracked;
 
-       return read_directory_recursive(dir, dirname, len, 1, simplify);
+       untracked = lookup_untracked(dir->untracked, untracked, dirname, len);
+       return read_directory_recursive(dir, dirname, len,
+                                       untracked, 1, simplify);
 }
 
 /*
@@ -1250,6 +1445,7 @@ static int get_dtype(struct dirent *de, const char *path, int len)
 }
 
 static enum path_treatment treat_one_path(struct dir_struct *dir,
+                                         struct untracked_cache_dir *untracked,
                                          struct strbuf *path,
                                          const struct path_simplify *simplify,
                                          int dtype, struct dirent *de)
@@ -1302,7 +1498,7 @@ static enum path_treatment treat_one_path(struct dir_struct *dir,
                return path_none;
        case DT_DIR:
                strbuf_addch(path, '/');
-               return treat_directory(dir, path->buf, path->len, exclude,
+               return treat_directory(dir, untracked, path->buf, path->len, exclude,
                        simplify);
        case DT_REG:
        case DT_LNK:
@@ -1310,14 +1506,52 @@ static enum path_treatment treat_one_path(struct dir_struct *dir,
        }
 }
 
+static enum path_treatment treat_path_fast(struct dir_struct *dir,
+                                          struct untracked_cache_dir *untracked,
+                                          struct cached_dir *cdir,
+                                          struct strbuf *path,
+                                          int baselen,
+                                          const struct path_simplify *simplify)
+{
+       strbuf_setlen(path, baselen);
+       if (!cdir->ucd) {
+               strbuf_addstr(path, cdir->file);
+               return path_untracked;
+       }
+       strbuf_addstr(path, cdir->ucd->name);
+       /* treat_one_path() does this before it calls treat_directory() */
+       if (path->buf[path->len - 1] != '/')
+               strbuf_addch(path, '/');
+       if (cdir->ucd->check_only)
+               /*
+                * check_only is set as a result of treat_directory() getting
+                * to its bottom. Verify again the same set of directories
+                * with check_only set.
+                */
+               return read_directory_recursive(dir, path->buf, path->len,
+                                               cdir->ucd, 1, simplify);
+       /*
+        * We get path_recurse in the first run when
+        * directory_exists_in_index() returns index_nonexistent. We
+        * are sure that new changes in the index does not impact the
+        * outcome. Return now.
+        */
+       return path_recurse;
+}
+
 static enum path_treatment treat_path(struct dir_struct *dir,
-                                     struct dirent *de,
+                                     struct untracked_cache_dir *untracked,
+                                     struct cached_dir *cdir,
                                      struct strbuf *path,
                                      int baselen,
                                      const struct path_simplify *simplify)
 {
        int dtype;
+       struct dirent *de = cdir->de;
 
+       if (!de)
+               return treat_path_fast(dir, untracked, cdir, path,
+                                      baselen, simplify);
        if (is_dot_or_dotdot(de->d_name) || !strcmp(de->d_name, ".git"))
                return path_none;
        strbuf_setlen(path, baselen);
@@ -1326,7 +1560,121 @@ static enum path_treatment treat_path(struct dir_struct *dir,
                return path_none;
 
        dtype = DTYPE(de);
-       return treat_one_path(dir, path, simplify, dtype, de);
+       return treat_one_path(dir, untracked, path, simplify, dtype, de);
+}
+
+static void add_untracked(struct untracked_cache_dir *dir, const char *name)
+{
+       if (!dir)
+               return;
+       ALLOC_GROW(dir->untracked, dir->untracked_nr + 1,
+                  dir->untracked_alloc);
+       dir->untracked[dir->untracked_nr++] = xstrdup(name);
+}
+
+static int valid_cached_dir(struct dir_struct *dir,
+                           struct untracked_cache_dir *untracked,
+                           struct strbuf *path,
+                           int check_only)
+{
+       struct stat st;
+
+       if (!untracked)
+               return 0;
+
+       if (stat(path->len ? path->buf : ".", &st)) {
+               invalidate_directory(dir->untracked, untracked);
+               memset(&untracked->stat_data, 0, sizeof(untracked->stat_data));
+               return 0;
+       }
+       if (!untracked->valid ||
+           match_stat_data_racy(&the_index, &untracked->stat_data, &st)) {
+               if (untracked->valid)
+                       invalidate_directory(dir->untracked, untracked);
+               fill_stat_data(&untracked->stat_data, &st);
+               return 0;
+       }
+
+       if (untracked->check_only != !!check_only) {
+               invalidate_directory(dir->untracked, untracked);
+               return 0;
+       }
+
+       /*
+        * prep_exclude will be called eventually on this directory,
+        * but it's called much later in last_exclude_matching(). We
+        * need it now to determine the validity of the cache for this
+        * path. The next calls will be nearly no-op, the way
+        * prep_exclude() is designed.
+        */
+       if (path->len && path->buf[path->len - 1] != '/') {
+               strbuf_addch(path, '/');
+               prep_exclude(dir, path->buf, path->len);
+               strbuf_setlen(path, path->len - 1);
+       } else
+               prep_exclude(dir, path->buf, path->len);
+
+       /* hopefully prep_exclude() haven't invalidated this entry... */
+       return untracked->valid;
+}
+
+static int open_cached_dir(struct cached_dir *cdir,
+                          struct dir_struct *dir,
+                          struct untracked_cache_dir *untracked,
+                          struct strbuf *path,
+                          int check_only)
+{
+       memset(cdir, 0, sizeof(*cdir));
+       cdir->untracked = untracked;
+       if (valid_cached_dir(dir, untracked, path, check_only))
+               return 0;
+       cdir->fdir = opendir(path->len ? path->buf : ".");
+       if (dir->untracked)
+               dir->untracked->dir_opened++;
+       if (!cdir->fdir)
+               return -1;
+       return 0;
+}
+
+static int read_cached_dir(struct cached_dir *cdir)
+{
+       if (cdir->fdir) {
+               cdir->de = readdir(cdir->fdir);
+               if (!cdir->de)
+                       return -1;
+               return 0;
+       }
+       while (cdir->nr_dirs < cdir->untracked->dirs_nr) {
+               struct untracked_cache_dir *d = cdir->untracked->dirs[cdir->nr_dirs];
+               if (!d->recurse) {
+                       cdir->nr_dirs++;
+                       continue;
+               }
+               cdir->ucd = d;
+               cdir->nr_dirs++;
+               return 0;
+       }
+       cdir->ucd = NULL;
+       if (cdir->nr_files < cdir->untracked->untracked_nr) {
+               struct untracked_cache_dir *d = cdir->untracked;
+               cdir->file = d->untracked[cdir->nr_files++];
+               return 0;
+       }
+       return -1;
+}
+
+static void close_cached_dir(struct cached_dir *cdir)
+{
+       if (cdir->fdir)
+               closedir(cdir->fdir);
+       /*
+        * We have gone through this directory and found no untracked
+        * entries. Mark it valid.
+        */
+       if (cdir->untracked) {
+               cdir->untracked->valid = 1;
+               cdir->untracked->recurse = 1;
+       }
 }
 
 /*
@@ -1342,38 +1690,48 @@ static enum path_treatment treat_path(struct dir_struct *dir,
  */
 static enum path_treatment read_directory_recursive(struct dir_struct *dir,
                                    const char *base, int baselen,
-                                   int check_only,
+                                   struct untracked_cache_dir *untracked, int check_only,
                                    const struct path_simplify *simplify)
 {
-       DIR *fdir;
+       struct cached_dir cdir;
        enum path_treatment state, subdir_state, dir_state = path_none;
-       struct dirent *de;
        struct strbuf path = STRBUF_INIT;
 
        strbuf_add(&path, base, baselen);
 
-       fdir = opendir(path.len ? path.buf : ".");
-       if (!fdir)
+       if (open_cached_dir(&cdir, dir, untracked, &path, check_only))
                goto out;
 
-       while ((de = readdir(fdir)) != NULL) {
+       if (untracked)
+               untracked->check_only = !!check_only;
+
+       while (!read_cached_dir(&cdir)) {
                /* check how the file or directory should be treated */
-               state = treat_path(dir, de, &path, baselen, simplify);
+               state = treat_path(dir, untracked, &cdir, &path, baselen, simplify);
+
                if (state > dir_state)
                        dir_state = state;
 
                /* recurse into subdir if instructed by treat_path */
                if (state == path_recurse) {
-                       subdir_state = read_directory_recursive(dir, path.buf,
-                               path.len, check_only, simplify);
+                       struct untracked_cache_dir *ud;
+                       ud = lookup_untracked(dir->untracked, untracked,
+                                             path.buf + baselen,
+                                             path.len - baselen);
+                       subdir_state =
+                               read_directory_recursive(dir, path.buf, path.len,
+                                                        ud, check_only, simplify);
                        if (subdir_state > dir_state)
                                dir_state = subdir_state;
                }
 
                if (check_only) {
                        /* abort early if maximum state has been reached */
-                       if (dir_state == path_untracked)
+                       if (dir_state == path_untracked) {
+                               if (cdir.fdir)
+                                       add_untracked(untracked, path.buf + baselen);
                                break;
+                       }
                        /* skip the dir_add_* part */
                        continue;
                }
@@ -1391,15 +1749,18 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir,
                        break;
 
                case path_untracked:
-                       if (!(dir->flags & DIR_SHOW_IGNORED))
-                               dir_add_name(dir, path.buf, path.len);
+                       if (dir->flags & DIR_SHOW_IGNORED)
+                               break;
+                       dir_add_name(dir, path.buf, path.len);
+                       if (cdir.fdir)
+                               add_untracked(untracked, path.buf + baselen);
                        break;
 
                default:
                        break;
                }
        }
-       closedir(fdir);
+       close_cached_dir(&cdir);
  out:
        strbuf_release(&path);
 
@@ -1469,7 +1830,7 @@ static int treat_leading_path(struct dir_struct *dir,
                        break;
                if (simplify_away(sb.buf, sb.len, simplify))
                        break;
-               if (treat_one_path(dir, &sb, simplify,
+               if (treat_one_path(dir, NULL, &sb, simplify,
                                   DT_DIR, NULL) == path_none)
                        break; /* do not recurse into it */
                if (len <= baselen) {
@@ -1482,9 +1843,139 @@ static int treat_leading_path(struct dir_struct *dir,
        return rc;
 }
 
+static const char *get_ident_string(void)
+{
+       static struct strbuf sb = STRBUF_INIT;
+       struct utsname uts;
+
+       if (sb.len)
+               return sb.buf;
+       if (uname(&uts))
+               die_errno(_("failed to get kernel name and information"));
+       strbuf_addf(&sb, "Location %s, system %s %s %s", get_git_work_tree(),
+                   uts.sysname, uts.release, uts.version);
+       return sb.buf;
+}
+
+static int ident_in_untracked(const struct untracked_cache *uc)
+{
+       const char *end = uc->ident.buf + uc->ident.len;
+       const char *p   = uc->ident.buf;
+
+       for (p = uc->ident.buf; p < end; p += strlen(p) + 1)
+               if (!strcmp(p, get_ident_string()))
+                       return 1;
+       return 0;
+}
+
+void add_untracked_ident(struct untracked_cache *uc)
+{
+       if (ident_in_untracked(uc))
+               return;
+       strbuf_addstr(&uc->ident, get_ident_string());
+       /* this strbuf contains a list of strings, save NUL too */
+       strbuf_addch(&uc->ident, 0);
+}
+
+static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *dir,
+                                                     int base_len,
+                                                     const struct pathspec *pathspec)
+{
+       struct untracked_cache_dir *root;
+       int i;
+
+       if (!dir->untracked || getenv("GIT_DISABLE_UNTRACKED_CACHE"))
+               return NULL;
+
+       /*
+        * We only support $GIT_DIR/info/exclude and core.excludesfile
+        * as the global ignore rule files. Any other additions
+        * (e.g. from command line) invalidate the cache. This
+        * condition also catches running setup_standard_excludes()
+        * before setting dir->untracked!
+        */
+       if (dir->unmanaged_exclude_files)
+               return NULL;
+
+       /*
+        * Optimize for the main use case only: whole-tree git
+        * status. More work involved in treat_leading_path() if we
+        * use cache on just a subset of the worktree. pathspec
+        * support could make the matter even worse.
+        */
+       if (base_len || (pathspec && pathspec->nr))
+               return NULL;
+
+       /* Different set of flags may produce different results */
+       if (dir->flags != dir->untracked->dir_flags ||
+           /*
+            * See treat_directory(), case index_nonexistent. Without
+            * this flag, we may need to also cache .git file content
+            * for the resolve_gitlink_ref() call, which we don't.
+            */
+           !(dir->flags & DIR_SHOW_OTHER_DIRECTORIES) ||
+           /* We don't support collecting ignore files */
+           (dir->flags & (DIR_SHOW_IGNORED | DIR_SHOW_IGNORED_TOO |
+                          DIR_COLLECT_IGNORED)))
+               return NULL;
+
+       /*
+        * If we use .gitignore in the cache and now you change it to
+        * .gitexclude, everything will go wrong.
+        */
+       if (dir->exclude_per_dir != dir->untracked->exclude_per_dir &&
+           strcmp(dir->exclude_per_dir, dir->untracked->exclude_per_dir))
+               return NULL;
+
+       /*
+        * EXC_CMDL is not considered in the cache. If people set it,
+        * skip the cache.
+        */
+       if (dir->exclude_list_group[EXC_CMDL].nr)
+               return NULL;
+
+       /*
+        * An optimization in prep_exclude() does not play well with
+        * CE_SKIP_WORKTREE. It's a rare case anyway, if a single
+        * entry has that bit set, disable the whole untracked cache.
+        */
+       for (i = 0; i < active_nr; i++)
+               if (ce_skip_worktree(active_cache[i]))
+                       return NULL;
+
+       if (!ident_in_untracked(dir->untracked)) {
+               warning(_("Untracked cache is disabled on this system."));
+               return NULL;
+       }
+
+       if (!dir->untracked->root) {
+               const int len = sizeof(*dir->untracked->root);
+               dir->untracked->root = xmalloc(len);
+               memset(dir->untracked->root, 0, len);
+       }
+
+       /* Validate $GIT_DIR/info/exclude and core.excludesfile */
+       root = dir->untracked->root;
+       if (hashcmp(dir->ss_info_exclude.sha1,
+                   dir->untracked->ss_info_exclude.sha1)) {
+               invalidate_gitignore(dir->untracked, root);
+               dir->untracked->ss_info_exclude = dir->ss_info_exclude;
+       }
+       if (hashcmp(dir->ss_excludes_file.sha1,
+                   dir->untracked->ss_excludes_file.sha1)) {
+               invalidate_gitignore(dir->untracked, root);
+               dir->untracked->ss_excludes_file = dir->ss_excludes_file;
+       }
+
+       /* Make sure this directory is not dropped out at saving phase */
+       root->recurse = 1;
+       return root;
+}
+
 int read_directory(struct dir_struct *dir, const char *path, int len, const struct pathspec *pathspec)
 {
        struct path_simplify *simplify;
+       struct untracked_cache_dir *untracked;
 
        /*
         * Check out create_simplify()
@@ -1508,11 +1999,39 @@ int read_directory(struct dir_struct *dir, const char *path, int len, const stru
         * create_simplify().
         */
        simplify = create_simplify(pathspec ? pathspec->_raw : NULL);
+       untracked = validate_untracked_cache(dir, len, pathspec);
+       if (!untracked)
+               /*
+                * make sure untracked cache code path is disabled,
+                * e.g. prep_exclude()
+                */
+               dir->untracked = NULL;
        if (!len || treat_leading_path(dir, path, len, simplify))
-               read_directory_recursive(dir, path, len, 0, simplify);
+               read_directory_recursive(dir, path, len, untracked, 0, simplify);
        free_simplify(simplify);
        qsort(dir->entries, dir->nr, sizeof(struct dir_entry *), cmp_name);
        qsort(dir->ignored, dir->ignored_nr, sizeof(struct dir_entry *), cmp_name);
+       if (dir->untracked) {
+               static struct trace_key trace_untracked_stats = TRACE_KEY_INIT(UNTRACKED_STATS);
+               trace_printf_key(&trace_untracked_stats,
+                                "node creation: %u\n"
+                                "gitignore invalidation: %u\n"
+                                "directory invalidation: %u\n"
+                                "opendir: %u\n",
+                                dir->untracked->dir_created,
+                                dir->untracked->gitignore_invalidated,
+                                dir->untracked->dir_invalidated,
+                                dir->untracked->dir_opened);
+               if (dir->untracked == the_index.untracked &&
+                   (dir->untracked->dir_opened ||
+                    dir->untracked->gitignore_invalidated ||
+                    dir->untracked->dir_invalidated))
+                       the_index.cache_changed |= UNTRACKED_CHANGED;
+               if (dir->untracked != the_index.untracked) {
+                       free(dir->untracked);
+                       dir->untracked = NULL;
+               }
+       }
        return dir->nr;
 }
 
@@ -1671,18 +2190,21 @@ int remove_dir_recursively(struct strbuf *path, int flag)
 void setup_standard_excludes(struct dir_struct *dir)
 {
        const char *path;
-       char *xdg_path;
 
        dir->exclude_per_dir = ".gitignore";
+
+       /* core.excludefile defaulting to $XDG_HOME/git/ignore */
+       if (!excludes_file)
+               excludes_file = xdg_config_home("ignore");
+       if (excludes_file && !access_or_warn(excludes_file, R_OK, 0))
+               add_excludes_from_file_1(dir, excludes_file,
+                                        dir->untracked ? &dir->ss_excludes_file : NULL);
+
+       /* per repository user preference */
        path = git_path("info/exclude");
-       if (!excludes_file) {
-               home_config_paths(NULL, &xdg_path, "ignore");
-               excludes_file = xdg_path;
-       }
        if (!access_or_warn(path, R_OK, 0))
-               add_excludes_from_file(dir, path);
-       if (excludes_file && !access_or_warn(excludes_file, R_OK, 0))
-               add_excludes_from_file(dir, excludes_file);
+               add_excludes_from_file_1(dir, path,
+                                        dir->untracked ? &dir->ss_info_exclude : NULL);
 }
 
 int remove_path(const char *name)
@@ -1734,3 +2256,404 @@ void clear_directory(struct dir_struct *dir)
        }
        strbuf_release(&dir->basebuf);
 }
+
+struct ondisk_untracked_cache {
+       struct stat_data info_exclude_stat;
+       struct stat_data excludes_file_stat;
+       uint32_t dir_flags;
+       unsigned char info_exclude_sha1[20];
+       unsigned char excludes_file_sha1[20];
+       char exclude_per_dir[FLEX_ARRAY];
+};
+
+#define ouc_size(len) (offsetof(struct ondisk_untracked_cache, exclude_per_dir) + len + 1)
+
+struct write_data {
+       int index;         /* number of written untracked_cache_dir */
+       struct ewah_bitmap *check_only; /* from untracked_cache_dir */
+       struct ewah_bitmap *valid;      /* from untracked_cache_dir */
+       struct ewah_bitmap *sha1_valid; /* set if exclude_sha1 is not null */
+       struct strbuf out;
+       struct strbuf sb_stat;
+       struct strbuf sb_sha1;
+};
+
+static void stat_data_to_disk(struct stat_data *to, const struct stat_data *from)
+{
+       to->sd_ctime.sec  = htonl(from->sd_ctime.sec);
+       to->sd_ctime.nsec = htonl(from->sd_ctime.nsec);
+       to->sd_mtime.sec  = htonl(from->sd_mtime.sec);
+       to->sd_mtime.nsec = htonl(from->sd_mtime.nsec);
+       to->sd_dev        = htonl(from->sd_dev);
+       to->sd_ino        = htonl(from->sd_ino);
+       to->sd_uid        = htonl(from->sd_uid);
+       to->sd_gid        = htonl(from->sd_gid);
+       to->sd_size       = htonl(from->sd_size);
+}
+
+static void write_one_dir(struct untracked_cache_dir *untracked,
+                         struct write_data *wd)
+{
+       struct stat_data stat_data;
+       struct strbuf *out = &wd->out;
+       unsigned char intbuf[16];
+       unsigned int intlen, value;
+       int i = wd->index++;
+
+       /*
+        * untracked_nr should be reset whenever valid is clear, but
+        * for safety..
+        */
+       if (!untracked->valid) {
+               untracked->untracked_nr = 0;
+               untracked->check_only = 0;
+       }
+
+       if (untracked->check_only)
+               ewah_set(wd->check_only, i);
+       if (untracked->valid) {
+               ewah_set(wd->valid, i);
+               stat_data_to_disk(&stat_data, &untracked->stat_data);
+               strbuf_add(&wd->sb_stat, &stat_data, sizeof(stat_data));
+       }
+       if (!is_null_sha1(untracked->exclude_sha1)) {
+               ewah_set(wd->sha1_valid, i);
+               strbuf_add(&wd->sb_sha1, untracked->exclude_sha1, 20);
+       }
+
+       intlen = encode_varint(untracked->untracked_nr, intbuf);
+       strbuf_add(out, intbuf, intlen);
+
+       /* skip non-recurse directories */
+       for (i = 0, value = 0; i < untracked->dirs_nr; i++)
+               if (untracked->dirs[i]->recurse)
+                       value++;
+       intlen = encode_varint(value, intbuf);
+       strbuf_add(out, intbuf, intlen);
+
+       strbuf_add(out, untracked->name, strlen(untracked->name) + 1);
+
+       for (i = 0; i < untracked->untracked_nr; i++)
+               strbuf_add(out, untracked->untracked[i],
+                          strlen(untracked->untracked[i]) + 1);
+
+       for (i = 0; i < untracked->dirs_nr; i++)
+               if (untracked->dirs[i]->recurse)
+                       write_one_dir(untracked->dirs[i], wd);
+}
+
+void write_untracked_extension(struct strbuf *out, struct untracked_cache *untracked)
+{
+       struct ondisk_untracked_cache *ouc;
+       struct write_data wd;
+       unsigned char varbuf[16];
+       int len = 0, varint_len;
+       if (untracked->exclude_per_dir)
+               len = strlen(untracked->exclude_per_dir);
+       ouc = xmalloc(sizeof(*ouc) + len + 1);
+       stat_data_to_disk(&ouc->info_exclude_stat, &untracked->ss_info_exclude.stat);
+       stat_data_to_disk(&ouc->excludes_file_stat, &untracked->ss_excludes_file.stat);
+       hashcpy(ouc->info_exclude_sha1, untracked->ss_info_exclude.sha1);
+       hashcpy(ouc->excludes_file_sha1, untracked->ss_excludes_file.sha1);
+       ouc->dir_flags = htonl(untracked->dir_flags);
+       memcpy(ouc->exclude_per_dir, untracked->exclude_per_dir, len + 1);
+
+       varint_len = encode_varint(untracked->ident.len, varbuf);
+       strbuf_add(out, varbuf, varint_len);
+       strbuf_add(out, untracked->ident.buf, untracked->ident.len);
+
+       strbuf_add(out, ouc, ouc_size(len));
+       free(ouc);
+       ouc = NULL;
+
+       if (!untracked->root) {
+               varint_len = encode_varint(0, varbuf);
+               strbuf_add(out, varbuf, varint_len);
+               return;
+       }
+
+       wd.index      = 0;
+       wd.check_only = ewah_new();
+       wd.valid      = ewah_new();
+       wd.sha1_valid = ewah_new();
+       strbuf_init(&wd.out, 1024);
+       strbuf_init(&wd.sb_stat, 1024);
+       strbuf_init(&wd.sb_sha1, 1024);
+       write_one_dir(untracked->root, &wd);
+
+       varint_len = encode_varint(wd.index, varbuf);
+       strbuf_add(out, varbuf, varint_len);
+       strbuf_addbuf(out, &wd.out);
+       ewah_serialize_strbuf(wd.valid, out);
+       ewah_serialize_strbuf(wd.check_only, out);
+       ewah_serialize_strbuf(wd.sha1_valid, out);
+       strbuf_addbuf(out, &wd.sb_stat);
+       strbuf_addbuf(out, &wd.sb_sha1);
+       strbuf_addch(out, '\0'); /* safe guard for string lists */
+
+       ewah_free(wd.valid);
+       ewah_free(wd.check_only);
+       ewah_free(wd.sha1_valid);
+       strbuf_release(&wd.out);
+       strbuf_release(&wd.sb_stat);
+       strbuf_release(&wd.sb_sha1);
+}
+
+static void free_untracked(struct untracked_cache_dir *ucd)
+{
+       int i;
+       if (!ucd)
+               return;
+       for (i = 0; i < ucd->dirs_nr; i++)
+               free_untracked(ucd->dirs[i]);
+       for (i = 0; i < ucd->untracked_nr; i++)
+               free(ucd->untracked[i]);
+       free(ucd->untracked);
+       free(ucd->dirs);
+       free(ucd);
+}
+
+void free_untracked_cache(struct untracked_cache *uc)
+{
+       if (uc)
+               free_untracked(uc->root);
+       free(uc);
+}
+
+struct read_data {
+       int index;
+       struct untracked_cache_dir **ucd;
+       struct ewah_bitmap *check_only;
+       struct ewah_bitmap *valid;
+       struct ewah_bitmap *sha1_valid;
+       const unsigned char *data;
+       const unsigned char *end;
+};
+
+static void stat_data_from_disk(struct stat_data *to, const struct stat_data *from)
+{
+       to->sd_ctime.sec  = get_be32(&from->sd_ctime.sec);
+       to->sd_ctime.nsec = get_be32(&from->sd_ctime.nsec);
+       to->sd_mtime.sec  = get_be32(&from->sd_mtime.sec);
+       to->sd_mtime.nsec = get_be32(&from->sd_mtime.nsec);
+       to->sd_dev        = get_be32(&from->sd_dev);
+       to->sd_ino        = get_be32(&from->sd_ino);
+       to->sd_uid        = get_be32(&from->sd_uid);
+       to->sd_gid        = get_be32(&from->sd_gid);
+       to->sd_size       = get_be32(&from->sd_size);
+}
+
+static int read_one_dir(struct untracked_cache_dir **untracked_,
+                       struct read_data *rd)
+{
+       struct untracked_cache_dir ud, *untracked;
+       const unsigned char *next, *data = rd->data, *end = rd->end;
+       unsigned int value;
+       int i, len;
+
+       memset(&ud, 0, sizeof(ud));
+
+       next = data;
+       value = decode_varint(&next);
+       if (next > end)
+               return -1;
+       ud.recurse         = 1;
+       ud.untracked_alloc = value;
+       ud.untracked_nr    = value;
+       if (ud.untracked_nr)
+               ud.untracked = xmalloc(sizeof(*ud.untracked) * ud.untracked_nr);
+       data = next;
+
+       next = data;
+       ud.dirs_alloc = ud.dirs_nr = decode_varint(&next);
+       if (next > end)
+               return -1;
+       ud.dirs = xmalloc(sizeof(*ud.dirs) * ud.dirs_nr);
+       data = next;
+
+       len = strlen((const char *)data);
+       next = data + len + 1;
+       if (next > rd->end)
+               return -1;
+       *untracked_ = untracked = xmalloc(sizeof(*untracked) + len);
+       memcpy(untracked, &ud, sizeof(ud));
+       memcpy(untracked->name, data, len + 1);
+       data = next;
+
+       for (i = 0; i < untracked->untracked_nr; i++) {
+               len = strlen((const char *)data);
+               next = data + len + 1;
+               if (next > rd->end)
+                       return -1;
+               untracked->untracked[i] = xstrdup((const char*)data);
+               data = next;
+       }
+
+       rd->ucd[rd->index++] = untracked;
+       rd->data = data;
+
+       for (i = 0; i < untracked->dirs_nr; i++) {
+               len = read_one_dir(untracked->dirs + i, rd);
+               if (len < 0)
+                       return -1;
+       }
+       return 0;
+}
+
+static void set_check_only(size_t pos, void *cb)
+{
+       struct read_data *rd = cb;
+       struct untracked_cache_dir *ud = rd->ucd[pos];
+       ud->check_only = 1;
+}
+
+static void read_stat(size_t pos, void *cb)
+{
+       struct read_data *rd = cb;
+       struct untracked_cache_dir *ud = rd->ucd[pos];
+       if (rd->data + sizeof(struct stat_data) > rd->end) {
+               rd->data = rd->end + 1;
+               return;
+       }
+       stat_data_from_disk(&ud->stat_data, (struct stat_data *)rd->data);
+       rd->data += sizeof(struct stat_data);
+       ud->valid = 1;
+}
+
+static void read_sha1(size_t pos, void *cb)
+{
+       struct read_data *rd = cb;
+       struct untracked_cache_dir *ud = rd->ucd[pos];
+       if (rd->data + 20 > rd->end) {
+               rd->data = rd->end + 1;
+               return;
+       }
+       hashcpy(ud->exclude_sha1, rd->data);
+       rd->data += 20;
+}
+
+static void load_sha1_stat(struct sha1_stat *sha1_stat,
+                          const struct stat_data *stat,
+                          const unsigned char *sha1)
+{
+       stat_data_from_disk(&sha1_stat->stat, stat);
+       hashcpy(sha1_stat->sha1, sha1);
+       sha1_stat->valid = 1;
+}
+
+struct untracked_cache *read_untracked_extension(const void *data, unsigned long sz)
+{
+       const struct ondisk_untracked_cache *ouc;
+       struct untracked_cache *uc;
+       struct read_data rd;
+       const unsigned char *next = data, *end = (const unsigned char *)data + sz;
+       const char *ident;
+       int ident_len, len;
+
+       if (sz <= 1 || end[-1] != '\0')
+               return NULL;
+       end--;
+
+       ident_len = decode_varint(&next);
+       if (next + ident_len > end)
+               return NULL;
+       ident = (const char *)next;
+       next += ident_len;
+
+       ouc = (const struct ondisk_untracked_cache *)next;
+       if (next + ouc_size(0) > end)
+               return NULL;
+
+       uc = xcalloc(1, sizeof(*uc));
+       strbuf_init(&uc->ident, ident_len);
+       strbuf_add(&uc->ident, ident, ident_len);
+       load_sha1_stat(&uc->ss_info_exclude, &ouc->info_exclude_stat,
+                      ouc->info_exclude_sha1);
+       load_sha1_stat(&uc->ss_excludes_file, &ouc->excludes_file_stat,
+                      ouc->excludes_file_sha1);
+       uc->dir_flags = get_be32(&ouc->dir_flags);
+       uc->exclude_per_dir = xstrdup(ouc->exclude_per_dir);
+       /* NUL after exclude_per_dir is covered by sizeof(*ouc) */
+       next += ouc_size(strlen(ouc->exclude_per_dir));
+       if (next >= end)
+               goto done2;
+
+       len = decode_varint(&next);
+       if (next > end || len == 0)
+               goto done2;
+
+       rd.valid      = ewah_new();
+       rd.check_only = ewah_new();
+       rd.sha1_valid = ewah_new();
+       rd.data       = next;
+       rd.end        = end;
+       rd.index      = 0;
+       rd.ucd        = xmalloc(sizeof(*rd.ucd) * len);
+
+       if (read_one_dir(&uc->root, &rd) || rd.index != len)
+               goto done;
+
+       next = rd.data;
+       len = ewah_read_mmap(rd.valid, next, end - next);
+       if (len < 0)
+               goto done;
+
+       next += len;
+       len = ewah_read_mmap(rd.check_only, next, end - next);
+       if (len < 0)
+               goto done;
+
+       next += len;
+       len = ewah_read_mmap(rd.sha1_valid, next, end - next);
+       if (len < 0)
+               goto done;
+
+       ewah_each_bit(rd.check_only, set_check_only, &rd);
+       rd.data = next + len;
+       ewah_each_bit(rd.valid, read_stat, &rd);
+       ewah_each_bit(rd.sha1_valid, read_sha1, &rd);
+       next = rd.data;
+
+done:
+       free(rd.ucd);
+       ewah_free(rd.valid);
+       ewah_free(rd.check_only);
+       ewah_free(rd.sha1_valid);
+done2:
+       if (next != end) {
+               free_untracked_cache(uc);
+               uc = NULL;
+       }
+       return uc;
+}
+
+void untracked_cache_invalidate_path(struct index_state *istate,
+                                    const char *path)
+{
+       const char *sep;
+       struct untracked_cache_dir *d;
+       if (!istate->untracked || !istate->untracked->root)
+               return;
+       sep = strrchr(path, '/');
+       if (sep)
+               d = lookup_untracked(istate->untracked,
+                                    istate->untracked->root,
+                                    path, sep - path);
+       else
+               d = istate->untracked->root;
+       istate->untracked->dir_invalidated++;
+       d->valid = 0;
+       d->untracked_nr = 0;
+}
+
+void untracked_cache_remove_from_index(struct index_state *istate,
+                                      const char *path)
+{
+       untracked_cache_invalidate_path(istate, path);
+}
+
+void untracked_cache_add_to_index(struct index_state *istate,
+                                 const char *path)
+{
+       untracked_cache_invalidate_path(istate, path);
+}
diff --git a/dir.h b/dir.h
index 72b73c65dcfc6f31004a032d0706626424ac2241..7b5855dd80eda02973a55c827d79826a25937880 100644 (file)
--- a/dir.h
+++ b/dir.h
@@ -66,6 +66,7 @@ struct exclude_stack {
        struct exclude_stack *prev; /* the struct exclude_stack for the parent directory */
        int baselen;
        int exclude_ix; /* index of exclude_list within EXC_DIRS exclude_list_group */
+       struct untracked_cache_dir *ucd;
 };
 
 struct exclude_list_group {
@@ -73,6 +74,73 @@ struct exclude_list_group {
        struct exclude_list *el;
 };
 
+struct sha1_stat {
+       struct stat_data stat;
+       unsigned char sha1[20];
+       int valid;
+};
+
+/*
+ *  Untracked cache
+ *
+ *  The following inputs are sufficient to determine what files in a
+ *  directory are excluded:
+ *
+ *   - The list of files and directories of the directory in question
+ *   - The $GIT_DIR/index
+ *   - dir_struct flags
+ *   - The content of $GIT_DIR/info/exclude
+ *   - The content of core.excludesfile
+ *   - The content (or the lack) of .gitignore of all parent directories
+ *     from $GIT_WORK_TREE
+ *   - The check_only flag in read_directory_recursive (for
+ *     DIR_HIDE_EMPTY_DIRECTORIES)
+ *
+ *  The first input can be checked using directory mtime. In many
+ *  filesystems, directory mtime (stat_data field) is updated when its
+ *  files or direct subdirs are added or removed.
+ *
+ *  The second one can be hooked from cache_tree_invalidate_path().
+ *  Whenever a file (or a submodule) is added or removed from a
+ *  directory, we invalidate that directory.
+ *
+ *  The remaining inputs are easy, their SHA-1 could be used to verify
+ *  their contents (exclude_sha1[], info_exclude_sha1[] and
+ *  excludes_file_sha1[])
+ */
+struct untracked_cache_dir {
+       struct untracked_cache_dir **dirs;
+       char **untracked;
+       struct stat_data stat_data;
+       unsigned int untracked_alloc, dirs_nr, dirs_alloc;
+       unsigned int untracked_nr;
+       unsigned int check_only : 1;
+       /* all data except 'dirs' in this struct are good */
+       unsigned int valid : 1;
+       unsigned int recurse : 1;
+       /* null SHA-1 means this directory does not have .gitignore */
+       unsigned char exclude_sha1[20];
+       char name[FLEX_ARRAY];
+};
+
+struct untracked_cache {
+       struct sha1_stat ss_info_exclude;
+       struct sha1_stat ss_excludes_file;
+       const char *exclude_per_dir;
+       struct strbuf ident;
+       /*
+        * dir_struct#flags must match dir_flags or the untracked
+        * cache is ignored.
+        */
+       unsigned dir_flags;
+       struct untracked_cache_dir *root;
+       /* Statistics */
+       int dir_created;
+       int gitignore_invalidated;
+       int dir_invalidated;
+       int dir_opened;
+};
+
 struct dir_struct {
        int nr, alloc;
        int ignored_nr, ignored_alloc;
@@ -120,6 +188,12 @@ struct dir_struct {
        struct exclude_stack *exclude_stack;
        struct exclude *exclude;
        struct strbuf basebuf;
+
+       /* Enable untracked file cache if set */
+       struct untracked_cache *untracked;
+       struct sha1_stat ss_info_exclude;
+       struct sha1_stat ss_excludes_file;
+       unsigned unmanaged_exclude_files;
 };
 
 /*
@@ -226,4 +300,12 @@ static inline int dir_path_match(const struct dir_entry *ent,
                              has_trailing_dir);
 }
 
+void untracked_cache_invalidate_path(struct index_state *, const char *);
+void untracked_cache_remove_from_index(struct index_state *, const char *);
+void untracked_cache_add_to_index(struct index_state *, const char *);
+
+void free_untracked_cache(struct untracked_cache *);
+struct untracked_cache *read_untracked_extension(const void *data, unsigned long sz);
+void write_untracked_extension(struct strbuf *out, struct untracked_cache *untracked);
+void add_untracked_ident(struct untracked_cache *);
 #endif
index a40044c3bf8040a36ddfb5c260b389ec63683abd..61c685b8d93091666891f0091d5005fe62543fc2 100644 (file)
@@ -92,8 +92,9 @@ static char *work_tree;
 static const char *namespace;
 static size_t namespace_len;
 
-static const char *git_dir;
+static const char *git_dir, *git_common_dir;
 static char *git_object_dir, *git_index_file, *git_graft_file;
+int git_db_env, git_index_env, git_graft_env, git_common_dir_env;
 
 /*
  * Repository-local GIT_* environment variables; see cache.h for details.
@@ -111,6 +112,7 @@ const char * const local_repo_env[] = {
        NO_REPLACE_OBJECTS_ENVIRONMENT,
        GIT_PREFIX_ENVIRONMENT,
        GIT_SHALLOW_FILE_ENVIRONMENT,
+       GIT_COMMON_DIR_ENVIRONMENT,
        NULL
 };
 
@@ -135,14 +137,23 @@ static char *expand_namespace(const char *raw_namespace)
        return strbuf_detach(&buf, NULL);
 }
 
-static char *git_path_from_env(const char *envvar, const char *path)
+static char *git_path_from_env(const char *envvar, const char *git_dir,
+                              const char *path, int *fromenv)
 {
        const char *value = getenv(envvar);
-       return value ? xstrdup(value) : git_pathdup("%s", path);
+       if (!value) {
+               char *buf = xmalloc(strlen(git_dir) + strlen(path) + 2);
+               sprintf(buf, "%s/%s", git_dir, path);
+               return buf;
+       }
+       if (fromenv)
+               *fromenv = 1;
+       return xstrdup(value);
 }
 
 static void setup_git_env(void)
 {
+       struct strbuf sb = STRBUF_INIT;
        const char *gitfile;
        const char *shallow_file;
 
@@ -151,9 +162,15 @@ static void setup_git_env(void)
                git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
        gitfile = read_gitfile(git_dir);
        git_dir = xstrdup(gitfile ? gitfile : git_dir);
-       git_object_dir = git_path_from_env(DB_ENVIRONMENT, "objects");
-       git_index_file = git_path_from_env(INDEX_ENVIRONMENT, "index");
-       git_graft_file = git_path_from_env(GRAFT_ENVIRONMENT, "info/grafts");
+       if (get_common_dir(&sb, git_dir))
+               git_common_dir_env = 1;
+       git_common_dir = strbuf_detach(&sb, NULL);
+       git_object_dir = git_path_from_env(DB_ENVIRONMENT, git_common_dir,
+                                          "objects", &git_db_env);
+       git_index_file = git_path_from_env(INDEX_ENVIRONMENT, git_dir,
+                                          "index", &git_index_env);
+       git_graft_file = git_path_from_env(GRAFT_ENVIRONMENT, git_common_dir,
+                                          "info/grafts", &git_graft_env);
        if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT))
                check_replace_refs = 0;
        namespace = expand_namespace(getenv(GIT_NAMESPACE_ENVIRONMENT));
@@ -176,6 +193,11 @@ const char *get_git_dir(void)
        return git_dir;
 }
 
+const char *get_git_common_dir(void)
+{
+       return git_common_dir;
+}
+
 const char *get_git_namespace(void)
 {
        if (!namespace)
index 1c2d7afd4cb9b70a324d355c3d69b732b181012b..43481b9c60c8afe30d6916650dd0e765065715c9 100644 (file)
@@ -19,6 +19,7 @@
  */
 #include "git-compat-util.h"
 #include "ewok.h"
+#include "strbuf.h"
 
 int ewah_serialize_native(struct ewah_bitmap *self, int fd)
 {
@@ -110,6 +111,18 @@ int ewah_serialize(struct ewah_bitmap *self, int fd)
        return ewah_serialize_to(self, write_helper, (void *)(intptr_t)fd);
 }
 
+static int write_strbuf(void *user_data, const void *data, size_t len)
+{
+       struct strbuf *sb = user_data;
+       strbuf_add(sb, data, len);
+       return len;
+}
+
+int ewah_serialize_strbuf(struct ewah_bitmap *self, struct strbuf *sb)
+{
+       return ewah_serialize_to(self, write_strbuf, sb);
+}
+
 int ewah_read_mmap(struct ewah_bitmap *self, const void *map, size_t len)
 {
        const uint8_t *ptr = map;
index 13c6e20412591ed3bc56b38b17419a540264f6c5..e73252536702aaf9fed17757937fbaf4b4593f91 100644 (file)
@@ -30,6 +30,7 @@
 #      define ewah_calloc xcalloc
 #endif
 
+struct strbuf;
 typedef uint64_t eword_t;
 #define BITS_IN_WORD (sizeof(eword_t) * 8)
 
@@ -98,6 +99,7 @@ int ewah_serialize_to(struct ewah_bitmap *self,
                      void *out);
 int ewah_serialize(struct ewah_bitmap *self, int fd);
 int ewah_serialize_native(struct ewah_bitmap *self, int fd);
+int ewah_serialize_strbuf(struct ewah_bitmap *self, struct strbuf *);
 
 int ewah_deserialize(struct ewah_bitmap *self, int fd);
 int ewah_read_mmap(struct ewah_bitmap *self, const void *map, size_t len);
index e78ca107b3d66d7e537c86eb10dc7503be8681b9..6378726993445694581ac36d6351f817fe488c72 100644 (file)
@@ -405,7 +405,7 @@ static void dump_marks_helper(FILE *, uintmax_t, struct mark_set *);
 
 static void write_crash_report(const char *err)
 {
-       char *loc = git_path("fast_import_crash_%"PRIuMAX, (uintmax_t) getpid());
+       const char *loc = git_path("fast_import_crash_%"PRIuMAX, (uintmax_t) getpid());
        FILE *rpt = fopen(loc, "w");
        struct branch *b;
        unsigned long lu;
@@ -3113,12 +3113,9 @@ static void parse_progress(void)
 
 static char* make_fast_import_path(const char *path)
 {
-       struct strbuf abs_path = STRBUF_INIT;
-
        if (!relative_marks_paths || is_absolute_path(path))
                return xstrdup(path);
-       strbuf_addf(&abs_path, "%s/info/fast-import/%s", get_git_dir(), path);
-       return strbuf_detach(&abs_path, NULL);
+       return xstrdup(git_path("info/fast-import/%s", path));
 }
 
 static void option_import_marks(const char *marks,
index a67d0f98989706fa69df4cf7d6242ad9531eb337..761befbd37088c176a65e4d3a12e8a8281e47553 100755 (executable)
--- a/git-am.sh
+++ b/git-am.sh
@@ -827,10 +827,10 @@ To restore the original branch and stop patching run \"\$cmdline --abort\"."
                continue
        fi
 
-       if test -x "$GIT_DIR"/hooks/applypatch-msg
+       hook="$(git rev-parse --git-path hooks/applypatch-msg)"
+       if test -x "$hook"
        then
-               "$GIT_DIR"/hooks/applypatch-msg "$dotest/final-commit" ||
-               stop_here $this
+               "$hook" "$dotest/final-commit" || stop_here $this
        fi
 
        if test -f "$dotest/final-commit"
@@ -904,9 +904,10 @@ did you forget to use 'git add'?"
                stop_here_user_resolve $this
        fi
 
-       if test -x "$GIT_DIR"/hooks/pre-applypatch
+       hook="$(git rev-parse --git-path hooks/pre-applypatch)"
+       if test -x "$hook"
        then
-               "$GIT_DIR"/hooks/pre-applypatch || stop_here $this
+               "$hook" || stop_here $this
        fi
 
        tree=$(git write-tree) &&
@@ -933,18 +934,17 @@ did you forget to use 'git add'?"
                echo "$(cat "$dotest/original-commit") $commit" >> "$dotest/rewritten"
        fi
 
-       if test -x "$GIT_DIR"/hooks/post-applypatch
-       then
-               "$GIT_DIR"/hooks/post-applypatch
-       fi
+       hook="$(git rev-parse --git-path hooks/post-applypatch)"
+       test -x "$hook" && "$hook"
 
        go_next
 done
 
 if test -s "$dotest"/rewritten; then
     git notes copy --for-rewrite=rebase < "$dotest"/rewritten
-    if test -x "$GIT_DIR"/hooks/post-rewrite; then
-       "$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten
+    hook="$(git rev-parse --git-path hooks/post-rewrite)"
+    if test -x "$hook"; then
+       "$hook" rebase < "$dotest"/rewritten
     fi
 fi
 
index bc8fc8cf854e96badfdf4d96673d33b799207ff3..17584adbd093a0848debcc23b2a73dcf520a8fb4 100644 (file)
@@ -3,6 +3,23 @@
 
 #define _FILE_OFFSET_BITS 64
 
+
+/* Derived from Linux "Features Test Macro" header
+ * Convenience macros to test the versions of gcc (or
+ * a compatible compiler).
+ * Use them like this:
+ *  #if GIT_GNUC_PREREQ (2,8)
+ *   ... code requiring gcc 2.8 or later ...
+ *  #endif
+*/
+#if defined(__GNUC__) && defined(__GNUC_MINOR__)
+# define GIT_GNUC_PREREQ(maj, min) \
+       ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
+#else
+ #define GIT_GNUC_PREREQ(maj, min) 0
+#endif
+
+
 #ifndef FLEX_ARRAY
 /*
  * See if our compiler is known to support flexible array members.
 #endif
 #endif
 
-#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
+
+/*
+ * BUILD_ASSERT_OR_ZERO - assert a build-time dependency, as an expression.
+ * @cond: the compile-time condition which must be true.
+ *
+ * Your compile will fail if the condition isn't true, or can't be evaluated
+ * by the compiler.  This can be used in an expression: its value is "0".
+ *
+ * Example:
+ *     #define foo_to_char(foo)                                        \
+ *              ((char *)(foo)                                         \
+ *               + BUILD_ASSERT_OR_ZERO(offsetof(struct foo, string) == 0))
+ */
+#define BUILD_ASSERT_OR_ZERO(cond) \
+       (sizeof(char [1 - 2*!(cond)]) - 1)
+
+#if defined(__GNUC__) && (__GNUC__ >= 3)
+# if GIT_GNUC_PREREQ(3, 1)
+ /* &arr[0] degrades to a pointer: a different type from an array */
+# define BARF_UNLESS_AN_ARRAY(arr)                                             \
+       BUILD_ASSERT_OR_ZERO(!__builtin_types_compatible_p(__typeof__(arr), \
+                                                          __typeof__(&(arr)[0])))
+# else
+#  define BARF_UNLESS_AN_ARRAY(arr) 0
+# endif
+#endif
+/*
+ * ARRAY_SIZE - get the number of elements in a visible array
+ *  <at> x: the array whose size you want.
+ *
+ * This does not work on pointers, or arrays declared as [], or
+ * function parameters.  With correct compiler support, such usage
+ * will cause a build error (see the build_assert_or_zero macro).
+ */
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]) + BARF_UNLESS_AN_ARRAY(x))
+
 #define bitsizeof(x)  (CHAR_BIT * sizeof(x))
 
 #define maximum_signed_value_of_type(a) \
 #elif defined(_MSC_VER)
 #include "compat/msvc.h"
 #else
+#include <sys/utsname.h>
 #include <sys/wait.h>
 #include <sys/resource.h>
 #include <sys/socket.h>
@@ -883,4 +936,10 @@ struct tm *git_gmtime_r(const time_t *, struct tm *);
 # define SHELL_PATH "/bin/sh"
 #endif
 
+#ifndef _POSIX_THREAD_SAFE_FUNCTIONS
+#define flockfile(fh)
+#define funlockfile(fh)
+#define getc_unlocked(fh) getc(fh)
+#endif
+
 #endif
index 73d367cea8f130bc7721803e397df710e7cfff58..82ecb0343a3864d1db0b066749d2087c11f689e7 100755 (executable)
@@ -1162,7 +1162,7 @@ sub commit {
                die "Fast-forward update failed: $?\n" if $?;
        }
        else {
-               system(qw(git merge cvsimport HEAD), "$remote/$opt_o");
+               system(qw(git merge -m cvsimport), "$remote/$opt_o");
                die "Could not merge $opt_o into the current branch.\n" if $?;
        }
 } else {
index 549022e97c83e4a2f1898dc005331e5bca3f0ded..41a77e6648ddad9a7599452bf361fd13ff4dcf88 100755 (executable)
--- a/git-p4.py
+++ b/git-p4.py
@@ -368,7 +368,7 @@ def getP4OpenedType(file):
     # Returns the perforce file type for the given file.
 
     result = p4_read_pipe(["opened", wildcard_encode(file)])
-    match = re.match(".*\((.+)\)\r?$", result)
+    match = re.match(".*\((.+)\)( \*exclusive\*)?\r?$", result)
     if match:
         return match.group(1)
     else:
@@ -502,12 +502,14 @@ def p4Cmd(cmd):
 def p4Where(depotPath):
     if not depotPath.endswith("/"):
         depotPath += "/"
-    depotPath = depotPath + "..."
-    outputList = p4CmdList(["where", depotPath])
+    depotPathLong = depotPath + "..."
+    outputList = p4CmdList(["where", depotPathLong])
     output = None
     for entry in outputList:
         if "depotFile" in entry:
-            if entry["depotFile"] == depotPath:
+            # Search for the base client side depot path, as long as it starts with the branch's P4 path.
+            # The base path always ends with "/...".
+            if entry["depotFile"].find(depotPath) == 0 and entry["depotFile"][-4:] == "/...":
                 output = entry
                 break
         elif "data" in entry:
@@ -740,17 +742,43 @@ def createOrUpdateBranchesFromOrigin(localRefPrefix = "refs/remotes/p4/", silent
 def originP4BranchesExist():
         return gitBranchExists("origin") or gitBranchExists("origin/p4") or gitBranchExists("origin/p4/master")
 
-def p4ChangesForPaths(depotPaths, changeRange):
+def p4ChangesForPaths(depotPaths, changeRange, block_size):
     assert depotPaths
-    cmd = ['changes']
-    for p in depotPaths:
-        cmd += ["%s...%s" % (p, changeRange)]
-    output = p4_read_pipe_lines(cmd)
+    assert block_size
+
+    # Parse the change range into start and end
+    if changeRange is None or changeRange == '':
+        changeStart = '@1'
+        changeEnd = '#head'
+    else:
+        parts = changeRange.split(',')
+        assert len(parts) == 2
+        changeStart = parts[0]
+        changeEnd = parts[1]
 
+    # Accumulate change numbers in a dictionary to avoid duplicates
     changes = {}
-    for line in output:
-        changeNum = int(line.split(" ")[1])
-        changes[changeNum] = True
+
+    for p in depotPaths:
+        # Retrieve changes a block at a time, to prevent running
+        # into a MaxScanRows error from the server.
+        start = changeStart
+        end = changeEnd
+        get_another_block = True
+        while get_another_block:
+            new_changes = []
+            cmd = ['changes']
+            cmd += ['-m', str(block_size)]
+            cmd += ["%s...%s,%s" % (p, start, end)]
+            for line in p4_read_pipe_lines(cmd):
+                changeNum = int(line.split(" ")[1])
+                new_changes.append(changeNum)
+                changes[changeNum] = True
+            if len(new_changes) == block_size:
+                get_another_block = True
+                end = '@' + str(min(new_changes))
+            else:
+                get_another_block = False
 
     changelist = changes.keys()
     changelist.sort()
@@ -1627,7 +1655,10 @@ def run(self, args):
         if self.useClientSpec:
             self.clientSpecDirs = getClientSpec()
 
-        if self.useClientSpec:
+        # Check for the existance of P4 branches
+        branchesDetected = (len(p4BranchesInGit().keys()) > 1)
+
+        if self.useClientSpec and not branchesDetected:
             # all files are relative to the client spec
             self.clientPath = getClientRoot()
         else:
@@ -1911,7 +1942,10 @@ def __init__(self):
                 optparse.make_option("--import-labels", dest="importLabels", action="store_true"),
                 optparse.make_option("--import-local", dest="importIntoRemotes", action="store_false",
                                      help="Import into refs/heads/ , not refs/remotes"),
-                optparse.make_option("--max-changes", dest="maxChanges"),
+                optparse.make_option("--max-changes", dest="maxChanges",
+                                     help="Maximum number of changes to import"),
+                optparse.make_option("--changes-block-size", dest="changes_block_size", type="int",
+                                     help="Internal block size to use when iteratively calling p4 changes"),
                 optparse.make_option("--keep-path", dest="keepRepoPath", action='store_true',
                                      help="Keep entire BRANCH/DIR/SUBDIR prefix during import"),
                 optparse.make_option("--use-client-spec", dest="useClientSpec", action='store_true',
@@ -1940,6 +1974,7 @@ def __init__(self):
         self.syncWithOrigin = True
         self.importIntoRemotes = True
         self.maxChanges = ""
+        self.changes_block_size = 500
         self.keepRepoPath = False
         self.depotPaths = None
         self.p4BranchesInGit = []
@@ -2586,7 +2621,7 @@ def importNewBranch(self, branch, maxChange):
         branchPrefix = self.depotPaths[0] + branch + "/"
         range = "@1,%s" % maxChange
         #print "prefix" + branchPrefix
-        changes = p4ChangesForPaths([branchPrefix], range)
+        changes = p4ChangesForPaths([branchPrefix], range, self.changes_block_size)
         if len(changes) <= 0:
             return False
         firstChange = changes[0]
@@ -3002,7 +3037,7 @@ def run(self, args):
                 if self.verbose:
                     print "Getting p4 changes for %s...%s" % (', '.join(self.depotPaths),
                                                               self.changeRange)
-                changes = p4ChangesForPaths(self.depotPaths, self.changeRange)
+                changes = p4ChangesForPaths(self.depotPaths, self.changeRange, self.changes_block_size)
 
                 if len(self.maxChanges) > 0:
                     changes = changes[:min(int(self.maxChanges), len(changes))]
index 4d4fc77b05648c7d2d76ae932b7d68cdf411d364..0917d0d056573912df60afd7b556efe04eeebae8 100755 (executable)
@@ -54,8 +54,11 @@ then
 fi
 
 # Setup default fast-forward options via `pull.ff`
-pull_ff=$(git config pull.ff)
+pull_ff=$(bool_or_string_config pull.ff)
 case "$pull_ff" in
+true)
+       no_ff=--ff
+       ;;
 false)
        no_ff=--no-ff
        ;;
@@ -81,8 +84,8 @@ do
                diffstat=--no-stat ;;
        --stat|--summary)
                diffstat=--stat ;;
-       --log|--no-log)
-               log_arg=$1 ;;
+       --log|--log=*|--no-log)
+               log_arg="$1" ;;
        --no-c|--no-co|--no-com|--no-comm|--no-commi|--no-commit)
                no_commit=--no-commit ;;
        --c|--co|--com|--comm|--commi|--commit)
@@ -190,15 +193,6 @@ esac
 
 error_on_no_merge_candidates () {
        exec >&2
-       for opt
-       do
-               case "$opt" in
-               -t|--t|--ta|--tag|--tags)
-                       echo "It doesn't make sense to pull all tags; you probably meant:"
-                       echo "  git fetch --tags"
-                       exit 1
-               esac
-       done
 
        if test true = "$rebase"
        then
@@ -240,7 +234,7 @@ test true = "$rebase" && {
        if ! git rev-parse -q --verify HEAD >/dev/null
        then
                # On an unborn branch
-               if test -f "$GIT_DIR/index"
+               if test -f "$(git rev-parse --git-path index)"
                then
                        die "$(gettext "updating an unborn branch with changes added to the index")"
                fi
@@ -323,7 +317,6 @@ then
        fi
 fi
 
-merge_name=$(git fmt-merge-msg $log_arg <"$GIT_DIR/FETCH_HEAD") || exit
 case "$rebase" in
 true)
        eval="git-rebase $diffstat $strategy_args $merge_args $rebase_args $verbosity"
@@ -334,7 +327,7 @@ true)
        eval="git-merge $diffstat $no_commit $verify_signatures $edit $squash $no_ff $ff_only"
        eval="$eval $log_arg $strategy_args $merge_args $verbosity $progress"
        eval="$eval $gpg_sign_args"
-       eval="$eval \"\$merge_name\" HEAD $merge_head"
+       eval="$eval FETCH_HEAD"
        ;;
 esac
 eval "exec $eval"
index f7deeb096e24f4de69bdfe08f0aa35ebf170577a..bab0dccc04d85215223c30597659f23cf8edff32 100644 (file)
@@ -132,6 +132,16 @@ mark_action_done () {
        fi
 }
 
+# Put the last action marked done at the beginning of the todo list
+# again. If there has not been an action marked done yet, leave the list of
+# items on the todo list unchanged.
+reschedule_last_action () {
+       tail -n 1 "$done" | cat - "$todo" >"$todo".new
+       sed -e \$d <"$done" >"$done".new
+       mv -f "$todo".new "$todo"
+       mv -f "$done".new "$done"
+}
+
 append_todo_help () {
        git stripspace --comment-lines >>"$todo" <<\EOF
 
@@ -252,6 +262,12 @@ pick_one () {
        output eval git cherry-pick \
                        ${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")} \
                        "$strategy_args" $empty_args $ff "$@"
+
+       # If cherry-pick dies it leaves the to-be-picked commit unrecorded. Reschedule
+       # previous task so this commit is not lost.
+       ret=$?
+       case "$ret" in [01]) ;; *) reschedule_last_action ;; esac
+       return $ret
 }
 
 pick_one_preserving_merges () {
@@ -642,9 +658,9 @@ do_next () {
                git notes copy --for-rewrite=rebase < "$rewritten_list" ||
                true # we don't care if this copying failed
        } &&
-       if test -x "$GIT_DIR"/hooks/post-rewrite &&
-               test -s "$rewritten_list"; then
-               "$GIT_DIR"/hooks/post-rewrite rebase < "$rewritten_list"
+       hook="$(git rev-parse --git-path hooks/post-rewrite)"
+       if test -x "$hook" && test -s "$rewritten_list"; then
+               "$hook" rebase < "$rewritten_list"
                true # we don't care if this hook failed
        fi &&
        warn "Successfully rebased and updated $head_name."
index d3fb67d75bd3cdfebd048594cdb67eb179b1c435..2cc2a6d2734c0ef12222004f22d717f4f724d82f 100644 (file)
@@ -94,10 +94,8 @@ finish_rb_merge () {
        if test -s "$state_dir"/rewritten
        then
                git notes copy --for-rewrite=rebase <"$state_dir"/rewritten
-               if test -x "$GIT_DIR"/hooks/post-rewrite
-               then
-                       "$GIT_DIR"/hooks/post-rewrite rebase <"$state_dir"/rewritten
-               fi
+               hook="$(git rev-parse --git-path hooks/post-rewrite)"
+               test -x "$hook" && "$hook" rebase <"$state_dir"/rewritten
        fi
        say All done.
 }
index 90854e38cb9ceb6985a5d7bd9faae722ed92361f..1757404bc271ba4e1a08eb30fe27542c35e3008e 100755 (executable)
@@ -202,9 +202,9 @@ run_specific_rebase () {
 
 run_pre_rebase_hook () {
        if test -z "$ok_to_skip_pre_rebase" &&
-          test -x "$GIT_DIR/hooks/pre-rebase"
+          test -x "$(git rev-parse --git-path hooks/pre-rebase)"
        then
-               "$GIT_DIR/hooks/pre-rebase" ${1+"$@"} ||
+               "$(git rev-parse --git-path hooks/pre-rebase)" ${1+"$@"} ||
                die "$(gettext "The pre-rebase hook refused to rebase.")"
        fi
 }
index c42c6e6365090e22ec7892baa51b919f2898e956..4691fbcb64fe7ecbc58930bb96d4e6b28e2b87a7 100644 (file)
@@ -344,7 +344,7 @@ git_dir_init () {
                echo >&2 "Unable to determine absolute path of git directory"
                exit 1
        }
-       : ${GIT_OBJECT_DIRECTORY="$GIT_DIR/objects"}
+       : ${GIT_OBJECT_DIRECTORY="$(git rev-parse --git-path objects)"}
 }
 
 if test -z "$NONGIT_OK"
index cc28368b01fc218f32ae98c21cce4d7f84c68eb0..7911f30c631fe58d6e5655f5213cae4e72ef99e1 100755 (executable)
@@ -20,7 +20,7 @@ require_work_tree
 cd_to_toplevel
 
 TMP="$GIT_DIR/.git-stash.$$"
-TMPindex=${GIT_INDEX_FILE-"$GIT_DIR/index"}.stash.$$
+TMPindex=${GIT_INDEX_FILE-"$(git rev-parse --git-path index)"}.stash.$$
 trap 'rm -f "$TMP-"* "$TMPindex"' 0
 
 ref_stash=refs/stash
@@ -184,7 +184,7 @@ store_stash () {
        fi
 
        # Make sure the reflog for stash is kept.
-       : >>"$GIT_DIR/logs/$ref_stash"
+       : >>"$(git rev-parse --git-path logs/$ref_stash)"
        git update-ref -m "$stash_msg" $ref_stash $w_commit
        ret=$?
        test $ret != 0 && test -z $quiet &&
@@ -259,7 +259,7 @@ save_stash () {
                say "$(gettext "No local changes to save")"
                exit 0
        fi
-       test -f "$GIT_DIR/logs/$ref_stash" ||
+       test -f "$(git rev-parse --git-path logs/$ref_stash)" ||
                clear_stash || die "$(gettext "Cannot initialize stash")"
 
        create_stash "$stash_msg" $untracked
diff --git a/git.c b/git.c
index 42a4ee57843f569fb754121f01bb8c46feee2fd3..44374b1d9b6b73b3669f0f851bee058f45ee4f32 100644 (file)
--- a/git.c
+++ b/git.c
@@ -382,7 +382,7 @@ static struct cmd_struct commands[] = {
        { "check-ignore", cmd_check_ignore, RUN_SETUP | NEED_WORK_TREE },
        { "check-mailmap", cmd_check_mailmap, RUN_SETUP },
        { "check-ref-format", cmd_check_ref_format },
-       { "checkout", cmd_checkout, RUN_SETUP | NEED_WORK_TREE },
+       { "checkout", cmd_checkout, RUN_SETUP },
        { "checkout-index", cmd_checkout_index,
                RUN_SETUP | NEED_WORK_TREE},
        { "cherry", cmd_cherry, RUN_SETUP },
diff --git a/hex.c b/hex.c
index cfd9d722fd92f137a79ee2bf6be44b4b393c6da6..899b74a08cb5298d2b0dd3205a98f5912a700e66 100644 (file)
--- a/hex.c
+++ b/hex.c
@@ -38,7 +38,7 @@ const signed char hexval_table[256] = {
 int get_sha1_hex(const char *hex, unsigned char *sha1)
 {
        int i;
-       for (i = 0; i < 20; i++) {
+       for (i = 0; i < GIT_SHA1_RAWSZ; i++) {
                unsigned int val;
                /*
                 * hex[1]=='\0' is caught when val is checked below,
@@ -56,15 +56,20 @@ int get_sha1_hex(const char *hex, unsigned char *sha1)
        return 0;
 }
 
+int get_oid_hex(const char *hex, struct object_id *oid)
+{
+       return get_sha1_hex(hex, oid->hash);
+}
+
 char *sha1_to_hex(const unsigned char *sha1)
 {
        static int bufno;
-       static char hexbuffer[4][41];
+       static char hexbuffer[4][GIT_SHA1_HEXSZ + 1];
        static const char hex[] = "0123456789abcdef";
        char *buffer = hexbuffer[3 & ++bufno], *buf = buffer;
        int i;
 
-       for (i = 0; i < 20; i++) {
+       for (i = 0; i < GIT_SHA1_RAWSZ; i++) {
                unsigned int val = *sha1++;
                *buf++ = hex[val >> 4];
                *buf++ = hex[val & 0xf];
@@ -73,3 +78,8 @@ char *sha1_to_hex(const unsigned char *sha1)
 
        return buffer;
 }
+
+char *oid_to_hex(const struct object_id *oid)
+{
+       return sha1_to_hex(oid->hash);
+}
diff --git a/http.c b/http.c
index 4b179f6fc8f29c1683b187393203d20f95d29157..f0c5bbc8b59768bb7b177494861d5f548b25fbb1 100644 (file)
--- a/http.c
+++ b/http.c
@@ -36,6 +36,7 @@ char curl_errorstr[CURL_ERROR_SIZE];
 static int curl_ssl_verify = -1;
 static int curl_ssl_try;
 static const char *ssl_cert;
+static const char *ssl_cipherlist;
 #if LIBCURL_VERSION_NUM >= 0x070903
 static const char *ssl_key;
 #endif
@@ -187,6 +188,8 @@ static int http_options(const char *var, const char *value, void *cb)
                curl_ssl_verify = git_config_bool(var, value);
                return 0;
        }
+       if (!strcmp("http.sslcipherlist", var))
+               return git_config_string(&ssl_cipherlist, var, value);
        if (!strcmp("http.sslcert", var))
                return git_config_string(&ssl_cert, var, value);
 #if LIBCURL_VERSION_NUM >= 0x070903
@@ -361,6 +364,13 @@ static CURL *get_curl_handle(void)
        if (http_proactive_auth)
                init_curl_http_auth(result);
 
+       if (getenv("GIT_SSL_CIPHER_LIST"))
+               ssl_cipherlist = getenv("GIT_SSL_CIPHER_LIST");
+
+       if (ssl_cipherlist != NULL && *ssl_cipherlist)
+               curl_easy_setopt(result, CURLOPT_SSL_CIPHER_LIST,
+                               ssl_cipherlist);
+
        if (ssl_cert != NULL)
                curl_easy_setopt(result, CURLOPT_SSLCERT, ssl_cert);
        if (has_cert_password())
index 988927775169487df7677a17465b512a567488dd..5a93bc7bc2425bf01e88f55024854225d6a78aca 100644 (file)
@@ -157,6 +157,80 @@ static int lock_file(struct lock_file *lk, const char *path, int flags)
        return lk->fd;
 }
 
+static int sleep_microseconds(long us)
+{
+       struct timeval tv;
+       tv.tv_sec = 0;
+       tv.tv_usec = us;
+       return select(0, NULL, NULL, NULL, &tv);
+}
+
+/*
+ * Constants defining the gaps between attempts to lock a file. The
+ * first backoff period is approximately INITIAL_BACKOFF_MS
+ * milliseconds. The longest backoff period is approximately
+ * (BACKOFF_MAX_MULTIPLIER * INITIAL_BACKOFF_MS) milliseconds.
+ */
+#define INITIAL_BACKOFF_MS 1L
+#define BACKOFF_MAX_MULTIPLIER 1000
+
+/*
+ * Try locking path, retrying with quadratic backoff for at least
+ * timeout_ms milliseconds. If timeout_ms is 0, try locking the file
+ * exactly once. If timeout_ms is -1, try indefinitely.
+ */
+static int lock_file_timeout(struct lock_file *lk, const char *path,
+                            int flags, long timeout_ms)
+{
+       int n = 1;
+       int multiplier = 1;
+       long remaining_us = 0;
+       static int random_initialized = 0;
+
+       if (timeout_ms == 0)
+               return lock_file(lk, path, flags);
+
+       if (!random_initialized) {
+               srandom((unsigned int)getpid());
+               random_initialized = 1;
+       }
+
+       if (timeout_ms > 0) {
+               /* avoid overflow */
+               if (timeout_ms <= LONG_MAX / 1000)
+                       remaining_us = timeout_ms * 1000;
+               else
+                       remaining_us = LONG_MAX;
+       }
+
+       while (1) {
+               long backoff_ms, wait_us;
+               int fd;
+
+               fd = lock_file(lk, path, flags);
+
+               if (fd >= 0)
+                       return fd; /* success */
+               else if (errno != EEXIST)
+                       return -1; /* failure other than lock held */
+               else if (timeout_ms > 0 && remaining_us <= 0)
+                       return -1; /* failure due to timeout */
+
+               backoff_ms = multiplier * INITIAL_BACKOFF_MS;
+               /* back off for between 0.75*backoff_ms and 1.25*backoff_ms */
+               wait_us = (750 + random() % 500) * backoff_ms;
+               sleep_microseconds(wait_us);
+               remaining_us -= wait_us;
+
+               /* Recursion: (n+1)^2 = n^2 + 2n + 1 */
+               multiplier += 2*n + 1;
+               if (multiplier > BACKOFF_MAX_MULTIPLIER)
+                       multiplier = BACKOFF_MAX_MULTIPLIER;
+               else
+                       n++;
+       }
+}
+
 void unable_to_lock_message(const char *path, int err, struct strbuf *buf)
 {
        if (err == EEXIST) {
@@ -179,9 +253,10 @@ NORETURN void unable_to_lock_die(const char *path, int err)
 }
 
 /* This should return a meaningful errno on failure */
-int hold_lock_file_for_update(struct lock_file *lk, const char *path, int flags)
+int hold_lock_file_for_update_timeout(struct lock_file *lk, const char *path,
+                                     int flags, long timeout_ms)
 {
-       int fd = lock_file(lk, path, flags);
+       int fd = lock_file_timeout(lk, path, flags, timeout_ms);
        if (fd < 0 && (flags & LOCK_DIE_ON_ERROR))
                unable_to_lock_die(path, errno);
        return fd;
@@ -214,7 +289,7 @@ int hold_lock_file_for_append(struct lock_file *lk, const char *path, int flags)
                int save_errno = errno;
 
                if (flags & LOCK_DIE_ON_ERROR)
-                       exit(128);
+                       die("failed to prepare '%s' for appending", path);
                close(orig_fd);
                rollback_lock_file(lk);
                errno = save_errno;
index cd2ec95d3003be5ff28f84e9e5b33cc85d9990c3..b4abc61c008b5199342c9e5eb12886039d2c0cc4 100644 (file)
@@ -74,8 +74,20 @@ struct lock_file {
 extern void unable_to_lock_message(const char *path, int err,
                                   struct strbuf *buf);
 extern NORETURN void unable_to_lock_die(const char *path, int err);
-extern int hold_lock_file_for_update(struct lock_file *, const char *path, int);
-extern int hold_lock_file_for_append(struct lock_file *, const char *path, int);
+extern int hold_lock_file_for_update_timeout(
+               struct lock_file *lk, const char *path,
+               int flags, long timeout_ms);
+
+static inline int hold_lock_file_for_update(
+               struct lock_file *lk, const char *path,
+               int flags)
+{
+       return hold_lock_file_for_update_timeout(lk, path, flags, 0);
+}
+
+extern int hold_lock_file_for_append(struct lock_file *lk, const char *path,
+                                    int flags);
+
 extern FILE *fdopen_lock_file(struct lock_file *, const char *mode);
 extern char *get_locked_file_path(struct lock_file *);
 extern int commit_lock_file_to(struct lock_file *, const char *path);
index 2c1ed0fa90170438e00a2eadbf74e15d89531613..8dba7be92e34e511b1d464983bb6d13861f1555e 100644 (file)
@@ -13,6 +13,8 @@
 #include "line-log.h"
 
 static struct decoration name_decoration = { "object names" };
+static int decoration_loaded;
+static int decoration_flags;
 
 static char decoration_colors[][COLOR_MAXLEN] = {
        GIT_COLOR_RESET,
@@ -92,6 +94,8 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in
        struct object *obj;
        enum decoration_type type = DECORATION_NONE;
 
+       assert(cb_data == NULL);
+
        if (starts_with(refname, "refs/replace/")) {
                unsigned char original_sha1[20];
                if (!check_replace_refs)
@@ -121,8 +125,6 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in
        else if (!strcmp(refname, "HEAD"))
                type = DECORATION_REF_HEAD;
 
-       if (!cb_data || *(int *)cb_data == DECORATE_SHORT_REFS)
-               refname = prettify_refname(refname);
        add_name_decoration(type, refname, obj);
        while (obj->type == OBJ_TAG) {
                obj = ((struct tag *)obj)->tagged;
@@ -137,7 +139,7 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in
 
 static int add_graft_decoration(const struct commit_graft *graft, void *cb_data)
 {
-       struct commit *commit = lookup_commit(graft->sha1);
+       struct commit *commit = lookup_commit(graft->oid.hash);
        if (!commit)
                return 0;
        add_name_decoration(DECORATION_GRAFTED, "grafted", &commit->object);
@@ -146,11 +148,11 @@ static int add_graft_decoration(const struct commit_graft *graft, void *cb_data)
 
 void load_ref_decorations(int flags)
 {
-       static int loaded;
-       if (!loaded) {
-               loaded = 1;
-               for_each_ref(add_ref_decoration, &flags);
-               head_ref(add_ref_decoration, &flags);
+       if (!decoration_loaded) {
+               decoration_loaded = 1;
+               decoration_flags = flags;
+               for_each_ref(add_ref_decoration, NULL);
+               head_ref(add_ref_decoration, NULL);
                for_each_commit_graft(add_graft_decoration, NULL);
        }
 }
@@ -196,7 +198,8 @@ static const struct name_decoration *current_pointed_by_HEAD(const struct name_d
        branch_name = resolve_ref_unsafe("HEAD", 0, unused, &rru_flags);
        if (!(rru_flags & REF_ISSYMREF))
                return NULL;
-       if (!skip_prefix(branch_name, "refs/heads/", &branch_name))
+
+       if (!starts_with(branch_name, "refs/"))
                return NULL;
 
        /* OK, do we have that ref in the list? */
@@ -209,6 +212,14 @@ static const struct name_decoration *current_pointed_by_HEAD(const struct name_d
        return NULL;
 }
 
+static void show_name(struct strbuf *sb, const struct name_decoration *decoration)
+{
+       if (decoration_flags == DECORATE_SHORT_REFS)
+               strbuf_addstr(sb, prettify_refname(decoration->name));
+       else
+               strbuf_addstr(sb, decoration->name);
+}
+
 /*
  * The caller makes sure there is no funny color before calling.
  * format_decorations_extended makes sure the same after return.
@@ -246,7 +257,7 @@ void format_decorations_extended(struct strbuf *sb,
                        if (decoration->type == DECORATION_REF_TAG)
                                strbuf_addstr(sb, "tag: ");
 
-                       strbuf_addstr(sb, decoration->name);
+                       show_name(sb, decoration);
 
                        if (current_and_HEAD &&
                            decoration->type == DECORATION_REF_HEAD) {
@@ -255,7 +266,7 @@ void format_decorations_extended(struct strbuf *sb,
                                strbuf_addstr(sb, " -> ");
                                strbuf_addstr(sb, color_reset);
                                strbuf_addstr(sb, decorate_get_color(use_color, current_and_HEAD->type));
-                               strbuf_addstr(sb, current_and_HEAD->name);
+                               show_name(sb, current_and_HEAD);
                        }
                        strbuf_addstr(sb, color_reset);
 
index 109ff4ef410b77a814cca282f728f1b88948e4ec..0b2b82c41fc043a48e9bf458c4f75f992ead7175 100644 (file)
@@ -280,7 +280,7 @@ static void check_notes_merge_worktree(struct notes_merge_options *o)
                                    "(%s exists).", git_path("NOTES_MERGE_*"));
                }
 
-               if (safe_create_leading_directories(git_path(
+               if (safe_create_leading_directories_const(git_path(
                                NOTES_MERGE_WORKTREE "/.test")))
                        die_errno("unable to create directory %s",
                                  git_path(NOTES_MERGE_WORKTREE));
@@ -295,8 +295,8 @@ static void write_buf_to_worktree(const unsigned char *obj,
                                  const char *buf, unsigned long size)
 {
        int fd;
-       char *path = git_path(NOTES_MERGE_WORKTREE "/%s", sha1_to_hex(obj));
-       if (safe_create_leading_directories(path))
+       const char *path = git_path(NOTES_MERGE_WORKTREE "/%s", sha1_to_hex(obj));
+       if (safe_create_leading_directories_const(path))
                die_errno("unable to create directory for '%s'", path);
        if (file_exists(path))
                die("found existing file at '%s'", path);
index 62a98cc119e3bf5a7b71e6b47143e06653ee9d6e..e5abb8a0460d49b603e29d1afe02db89fede8d24 100644 (file)
@@ -209,14 +209,12 @@ static inline uint8_t read_u8(const unsigned char *buffer, size_t *pos)
        return buffer[(*pos)++];
 }
 
+#define MAX_XOR_OFFSET 160
+
 static int load_bitmap_entries_v1(struct bitmap_index *index)
 {
-       static const size_t MAX_XOR_OFFSET = 160;
-
        uint32_t i;
-       struct stored_bitmap **recent_bitmaps;
-
-       recent_bitmaps = xcalloc(MAX_XOR_OFFSET, sizeof(struct stored_bitmap));
+       struct stored_bitmap *recent_bitmaps[MAX_XOR_OFFSET] = { NULL };
 
        for (i = 0; i < index->entry_count; ++i) {
                int xor_offset, flags;
diff --git a/path.c b/path.c
index 595da81ca67096bae9592d9455bdade442b92628..10f4cbf6b78607870461f21dd1cd0f7a2776bc49 100644 (file)
--- a/path.c
+++ b/path.c
@@ -4,6 +4,7 @@
 #include "cache.h"
 #include "strbuf.h"
 #include "string-list.h"
+#include "dir.h"
 
 static int get_st_mode_bits(const char *path, int *mode)
 {
@@ -16,11 +17,15 @@ static int get_st_mode_bits(const char *path, int *mode)
 
 static char bad_path[] = "/bad-path/";
 
-static char *get_pathname(void)
+static struct strbuf *get_pathname(void)
 {
-       static char pathname_array[4][PATH_MAX];
+       static struct strbuf pathname_array[4] = {
+               STRBUF_INIT, STRBUF_INIT, STRBUF_INIT, STRBUF_INIT
+       };
        static int index;
-       return pathname_array[3 & ++index];
+       struct strbuf *sb = &pathname_array[3 & ++index];
+       strbuf_reset(sb);
+       return sb;
 }
 
 static char *cleanup_path(char *path)
@@ -34,6 +39,13 @@ static char *cleanup_path(char *path)
        return path;
 }
 
+static void strbuf_cleanup_path(struct strbuf *sb)
+{
+       char *path = cleanup_path(sb->buf);
+       if (path > sb->buf)
+               strbuf_remove(sb, 0, path - sb->buf);
+}
+
 char *mksnpath(char *buf, size_t n, const char *fmt, ...)
 {
        va_list args;
@@ -49,152 +61,192 @@ char *mksnpath(char *buf, size_t n, const char *fmt, ...)
        return cleanup_path(buf);
 }
 
-static char *vsnpath(char *buf, size_t n, const char *fmt, va_list args)
+static int dir_prefix(const char *buf, const char *dir)
 {
-       const char *git_dir = get_git_dir();
-       size_t len;
+       int len = strlen(dir);
+       return !strncmp(buf, dir, len) &&
+               (is_dir_sep(buf[len]) || buf[len] == '\0');
+}
 
-       len = strlen(git_dir);
-       if (n < len + 1)
-               goto bad;
-       memcpy(buf, git_dir, len);
-       if (len && !is_dir_sep(git_dir[len-1]))
-               buf[len++] = '/';
-       len += vsnprintf(buf + len, n - len, fmt, args);
-       if (len >= n)
-               goto bad;
-       return cleanup_path(buf);
-bad:
-       strlcpy(buf, bad_path, n);
-       return buf;
+/* $buf =~ m|$dir/+$file| but without regex */
+static int is_dir_file(const char *buf, const char *dir, const char *file)
+{
+       int len = strlen(dir);
+       if (strncmp(buf, dir, len) || !is_dir_sep(buf[len]))
+               return 0;
+       while (is_dir_sep(buf[len]))
+               len++;
+       return !strcmp(buf + len, file);
 }
 
-char *git_snpath(char *buf, size_t n, const char *fmt, ...)
+static void replace_dir(struct strbuf *buf, int len, const char *newdir)
 {
-       char *ret;
-       va_list args;
-       va_start(args, fmt);
-       ret = vsnpath(buf, n, fmt, args);
-       va_end(args);
-       return ret;
+       int newlen = strlen(newdir);
+       int need_sep = (buf->buf[len] && !is_dir_sep(buf->buf[len])) &&
+               !is_dir_sep(newdir[newlen - 1]);
+       if (need_sep)
+               len--;   /* keep one char, to be replaced with '/'  */
+       strbuf_splice(buf, 0, len, newdir, newlen);
+       if (need_sep)
+               buf->buf[newlen] = '/';
 }
 
-char *git_pathdup(const char *fmt, ...)
+static const char *common_list[] = {
+       "/branches", "/hooks", "/info", "!/logs", "/lost-found",
+       "/objects", "/refs", "/remotes", "/worktrees", "/rr-cache", "/svn",
+       "config", "!gc.pid", "packed-refs", "shallow",
+       NULL
+};
+
+static void update_common_dir(struct strbuf *buf, int git_dir_len)
+{
+       char *base = buf->buf + git_dir_len;
+       const char **p;
+
+       if (is_dir_file(base, "logs", "HEAD") ||
+           is_dir_file(base, "info", "sparse-checkout"))
+               return; /* keep this in $GIT_DIR */
+       for (p = common_list; *p; p++) {
+               const char *path = *p;
+               int is_dir = 0;
+               if (*path == '!')
+                       path++;
+               if (*path == '/') {
+                       path++;
+                       is_dir = 1;
+               }
+               if (is_dir && dir_prefix(base, path)) {
+                       replace_dir(buf, git_dir_len, get_git_common_dir());
+                       return;
+               }
+               if (!is_dir && !strcmp(base, path)) {
+                       replace_dir(buf, git_dir_len, get_git_common_dir());
+                       return;
+               }
+       }
+}
+
+void report_linked_checkout_garbage(void)
+{
+       struct strbuf sb = STRBUF_INIT;
+       const char **p;
+       int len;
+
+       if (!git_common_dir_env)
+               return;
+       strbuf_addf(&sb, "%s/", get_git_dir());
+       len = sb.len;
+       for (p = common_list; *p; p++) {
+               const char *path = *p;
+               if (*path == '!')
+                       continue;
+               strbuf_setlen(&sb, len);
+               strbuf_addstr(&sb, path);
+               if (file_exists(sb.buf))
+                       report_garbage("unused in linked checkout", sb.buf);
+       }
+       strbuf_release(&sb);
+}
+
+static void adjust_git_path(struct strbuf *buf, int git_dir_len)
+{
+       const char *base = buf->buf + git_dir_len;
+       if (git_graft_env && is_dir_file(base, "info", "grafts"))
+               strbuf_splice(buf, 0, buf->len,
+                             get_graft_file(), strlen(get_graft_file()));
+       else if (git_index_env && !strcmp(base, "index"))
+               strbuf_splice(buf, 0, buf->len,
+                             get_index_file(), strlen(get_index_file()));
+       else if (git_db_env && dir_prefix(base, "objects"))
+               replace_dir(buf, git_dir_len + 7, get_object_directory());
+       else if (git_common_dir_env)
+               update_common_dir(buf, git_dir_len);
+}
+
+static void do_git_path(struct strbuf *buf, const char *fmt, va_list args)
+{
+       int gitdir_len;
+       strbuf_addstr(buf, get_git_dir());
+       if (buf->len && !is_dir_sep(buf->buf[buf->len - 1]))
+               strbuf_addch(buf, '/');
+       gitdir_len = buf->len;
+       strbuf_vaddf(buf, fmt, args);
+       adjust_git_path(buf, gitdir_len);
+       strbuf_cleanup_path(buf);
+}
+
+void strbuf_git_path(struct strbuf *sb, const char *fmt, ...)
 {
-       char path[PATH_MAX], *ret;
        va_list args;
        va_start(args, fmt);
-       ret = vsnpath(path, sizeof(path), fmt, args);
+       do_git_path(sb, fmt, args);
        va_end(args);
-       return xstrdup(ret);
 }
 
-char *mkpathdup(const char *fmt, ...)
+const char *git_path(const char *fmt, ...)
 {
-       char *path;
-       struct strbuf sb = STRBUF_INIT;
+       struct strbuf *pathname = get_pathname();
        va_list args;
-
        va_start(args, fmt);
-       strbuf_vaddf(&sb, fmt, args);
+       do_git_path(pathname, fmt, args);
        va_end(args);
-       path = xstrdup(cleanup_path(sb.buf));
-
-       strbuf_release(&sb);
-       return path;
+       return pathname->buf;
 }
 
-char *mkpath(const char *fmt, ...)
+char *git_pathdup(const char *fmt, ...)
 {
+       struct strbuf path = STRBUF_INIT;
        va_list args;
-       unsigned len;
-       char *pathname = get_pathname();
-
        va_start(args, fmt);
-       len = vsnprintf(pathname, PATH_MAX, fmt, args);
+       do_git_path(&path, fmt, args);
        va_end(args);
-       if (len >= PATH_MAX)
-               return bad_path;
-       return cleanup_path(pathname);
+       return strbuf_detach(&path, NULL);
 }
 
-char *git_path(const char *fmt, ...)
+char *mkpathdup(const char *fmt, ...)
 {
-       char *pathname = get_pathname();
+       struct strbuf sb = STRBUF_INIT;
        va_list args;
-       char *ret;
-
        va_start(args, fmt);
-       ret = vsnpath(pathname, PATH_MAX, fmt, args);
+       strbuf_vaddf(&sb, fmt, args);
        va_end(args);
-       return ret;
+       strbuf_cleanup_path(&sb);
+       return strbuf_detach(&sb, NULL);
 }
 
-void home_config_paths(char **global, char **xdg, char *file)
+const char *mkpath(const char *fmt, ...)
 {
-       char *xdg_home = getenv("XDG_CONFIG_HOME");
-       char *home = getenv("HOME");
-       char *to_free = NULL;
-
-       if (!home) {
-               if (global)
-                       *global = NULL;
-       } else {
-               if (!xdg_home) {
-                       to_free = mkpathdup("%s/.config", home);
-                       xdg_home = to_free;
-               }
-               if (global)
-                       *global = mkpathdup("%s/.gitconfig", home);
-       }
-
-       if (xdg) {
-               if (!xdg_home)
-                       *xdg = NULL;
-               else
-                       *xdg = mkpathdup("%s/git/%s", xdg_home, file);
-       }
-
-       free(to_free);
+       va_list args;
+       struct strbuf *pathname = get_pathname();
+       va_start(args, fmt);
+       strbuf_vaddf(pathname, fmt, args);
+       va_end(args);
+       return cleanup_path(pathname->buf);
 }
 
-char *git_path_submodule(const char *path, const char *fmt, ...)
+const char *git_path_submodule(const char *path, const char *fmt, ...)
 {
-       char *pathname = get_pathname();
-       struct strbuf buf = STRBUF_INIT;
+       struct strbuf *buf = get_pathname();
        const char *git_dir;
        va_list args;
-       unsigned len;
 
-       len = strlen(path);
-       if (len > PATH_MAX-100)
-               return bad_path;
+       strbuf_addstr(buf, path);
+       if (buf->len && buf->buf[buf->len - 1] != '/')
+               strbuf_addch(buf, '/');
+       strbuf_addstr(buf, ".git");
 
-       strbuf_addstr(&buf, path);
-       if (len && path[len-1] != '/')
-               strbuf_addch(&buf, '/');
-       strbuf_addstr(&buf, ".git");
-
-       git_dir = read_gitfile(buf.buf);
+       git_dir = read_gitfile(buf->buf);
        if (git_dir) {
-               strbuf_reset(&buf);
-               strbuf_addstr(&buf, git_dir);
+               strbuf_reset(buf);
+               strbuf_addstr(buf, git_dir);
        }
-       strbuf_addch(&buf, '/');
-
-       if (buf.len >= PATH_MAX)
-               return bad_path;
-       memcpy(pathname, buf.buf, buf.len + 1);
-
-       strbuf_release(&buf);
-       len = strlen(pathname);
+       strbuf_addch(buf, '/');
 
        va_start(args, fmt);
-       len += vsnprintf(pathname + len, PATH_MAX - len, fmt, args);
+       strbuf_vaddf(buf, fmt, args);
        va_end(args);
-       if (len >= PATH_MAX)
-               return bad_path;
-       return cleanup_path(pathname);
+       strbuf_cleanup_path(buf);
+       return buf->buf;
 }
 
 int validate_headref(const char *path)
@@ -851,3 +903,18 @@ int is_ntfs_dotgit(const char *name)
                        len = -1;
                }
 }
+
+char *xdg_config_home(const char *filename)
+{
+       const char *home, *config_home;
+
+       assert(filename);
+       config_home = getenv("XDG_CONFIG_HOME");
+       if (config_home && *config_home)
+               return mkpathdup("%s/git/%s", config_home, filename);
+
+       home = getenv("HOME");
+       if (home)
+               return mkpathdup("%s/.config/git/%s", home, filename);
+       return NULL;
+}
index 412e6b1ecc36e8bd8b7f090b7da3dcf0c7e4e5bd..2e31bec60f5c98dc7dac69227759cbf2ba5f9974 100644 (file)
@@ -72,6 +72,12 @@ static void clear_progress_signal(void)
        progress_update = 0;
 }
 
+static int is_foreground_fd(int fd)
+{
+       int tpgrp = tcgetpgrp(fd);
+       return tpgrp < 0 || tpgrp == getpgid(0);
+}
+
 static int display(struct progress *progress, unsigned n, const char *done)
 {
        const char *eol, *tp;
@@ -98,16 +104,21 @@ static int display(struct progress *progress, unsigned n, const char *done)
                unsigned percent = n * 100 / progress->total;
                if (percent != progress->last_percent || progress_update) {
                        progress->last_percent = percent;
-                       fprintf(stderr, "%s: %3u%% (%u/%u)%s%s",
-                               progress->title, percent, n,
-                               progress->total, tp, eol);
-                       fflush(stderr);
+                       if (is_foreground_fd(fileno(stderr)) || done) {
+                               fprintf(stderr, "%s: %3u%% (%u/%u)%s%s",
+                                       progress->title, percent, n,
+                                       progress->total, tp, eol);
+                               fflush(stderr);
+                       }
                        progress_update = 0;
                        return 1;
                }
        } else if (progress_update) {
-               fprintf(stderr, "%s: %u%s%s", progress->title, n, tp, eol);
-               fflush(stderr);
+               if (is_foreground_fd(fileno(stderr)) || done) {
+                       fprintf(stderr, "%s: %u%s%s",
+                               progress->title, n, tp, eol);
+                       fflush(stderr);
+               }
                progress_update = 0;
                return 1;
        }
index 36ff89f29e5f56a5b3dcfd803f12cd139295b8b8..723d48dddfe58f50b30105689dfeb9bcb388c8f2 100644 (file)
@@ -39,11 +39,12 @@ static struct cache_entry *refresh_cache_entry(struct cache_entry *ce,
 #define CACHE_EXT_TREE 0x54524545      /* "TREE" */
 #define CACHE_EXT_RESOLVE_UNDO 0x52455543 /* "REUC" */
 #define CACHE_EXT_LINK 0x6c696e6b        /* "link" */
+#define CACHE_EXT_UNTRACKED 0x554E5452   /* "UNTR" */
 
 /* changes that can be kept in $GIT_DIR/index (basically all extensions) */
 #define EXTMASK (RESOLVE_UNDO_CHANGED | CACHE_TREE_CHANGED | \
                 CE_ENTRY_ADDED | CE_ENTRY_REMOVED | CE_ENTRY_CHANGED | \
-                SPLIT_INDEX_ORDERED)
+                SPLIT_INDEX_ORDERED | UNTRACKED_CHANGED)
 
 struct index_state the_index;
 static const char *alternate_index_output;
@@ -79,6 +80,7 @@ void rename_index_entry_at(struct index_state *istate, int nr, const char *new_n
        memcpy(new->name, new_name, namelen + 1);
 
        cache_tree_invalidate_path(istate, old->name);
+       untracked_cache_remove_from_index(istate, old->name);
        remove_index_entry_at(istate, nr);
        add_index_entry(istate, new, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE);
 }
@@ -270,20 +272,34 @@ static int ce_match_stat_basic(const struct cache_entry *ce, struct stat *st)
        return changed;
 }
 
-static int is_racy_timestamp(const struct index_state *istate,
-                            const struct cache_entry *ce)
+static int is_racy_stat(const struct index_state *istate,
+                       const struct stat_data *sd)
 {
-       return (!S_ISGITLINK(ce->ce_mode) &&
-               istate->timestamp.sec &&
+       return (istate->timestamp.sec &&
 #ifdef USE_NSEC
                 /* nanosecond timestamped files can also be racy! */
-               (istate->timestamp.sec < ce->ce_stat_data.sd_mtime.sec ||
-                (istate->timestamp.sec == ce->ce_stat_data.sd_mtime.sec &&
-                 istate->timestamp.nsec <= ce->ce_stat_data.sd_mtime.nsec))
+               (istate->timestamp.sec < sd->sd_mtime.sec ||
+                (istate->timestamp.sec == sd->sd_mtime.sec &&
+                 istate->timestamp.nsec <= sd->sd_mtime.nsec))
 #else
-               istate->timestamp.sec <= ce->ce_stat_data.sd_mtime.sec
+               istate->timestamp.sec <= sd->sd_mtime.sec
 #endif
-                );
+               );
+}
+
+static int is_racy_timestamp(const struct index_state *istate,
+                            const struct cache_entry *ce)
+{
+       return (!S_ISGITLINK(ce->ce_mode) &&
+               is_racy_stat(istate, &ce->ce_stat_data));
+}
+
+int match_stat_data_racy(const struct index_state *istate,
+                        const struct stat_data *sd, struct stat *st)
+{
+       if (is_racy_stat(istate, sd))
+               return MTIME_CHANGED;
+       return match_stat_data(sd, st);
 }
 
 int ie_match_stat(const struct index_state *istate,
@@ -538,6 +554,7 @@ int remove_file_from_index(struct index_state *istate, const char *path)
        if (pos < 0)
                pos = -pos-1;
        cache_tree_invalidate_path(istate, path);
+       untracked_cache_remove_from_index(istate, path);
        while (pos < istate->cache_nr && !strcmp(istate->cache[pos]->name, path))
                remove_index_entry_at(istate, pos);
        return 0;
@@ -982,6 +999,8 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_e
        }
        pos = -pos-1;
 
+       untracked_cache_add_to_index(istate, ce->name);
+
        /*
         * Inserting a merged entry ("stage 0") into the index
         * will always replace all non-merged entries..
@@ -1372,6 +1391,9 @@ static int read_index_extension(struct index_state *istate,
                if (read_link_extension(istate, data, sz))
                        return -1;
                break;
+       case CACHE_EXT_UNTRACKED:
+               istate->untracked = read_untracked_extension(data, sz);
+               break;
        default:
                if (*ext < 'A' || 'Z' < *ext)
                        return error("index uses %.4s extension, which we do not understand",
@@ -1667,6 +1689,8 @@ int discard_index(struct index_state *istate)
        istate->cache = NULL;
        istate->cache_alloc = 0;
        discard_split_index(istate);
+       free_untracked_cache(istate->untracked);
+       istate->untracked = NULL;
        return 0;
 }
 
@@ -2053,6 +2077,17 @@ static int do_write_index(struct index_state *istate, int newfd,
                if (err)
                        return -1;
        }
+       if (!strip_extensions && istate->untracked) {
+               struct strbuf sb = STRBUF_INIT;
+
+               write_untracked_extension(&sb, istate->untracked);
+               err = write_index_ext_header(&c, newfd, CACHE_EXT_UNTRACKED,
+                                            sb.len) < 0 ||
+                       ce_write(&c, newfd, sb.buf, sb.len) < 0;
+               strbuf_release(&sb);
+               if (err)
+                       return -1;
+       }
 
        if (ce_flush(&c, newfd, istate->sha1) || fstat(newfd, &st))
                return -1;
diff --git a/refs.c b/refs.c
index 47e4e5380a1e0fc04f8b81837c51c023f35871cf..8480d8dbf5c78c28d895c9c1a2ac7aa5305f4e5e 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -11,7 +11,6 @@ struct ref_lock {
        char *orig_ref_name;
        struct lock_file *lk;
        unsigned char old_sha1[20];
-       int lock_fd;
 };
 
 /*
@@ -57,6 +56,12 @@ static unsigned char refname_disposition[256] = {
  */
 #define REF_HAVE_OLD   0x10
 
+/*
+ * Used as a flag in ref_update::flags when the lockfile needs to be
+ * committed.
+ */
+#define REF_NEEDS_COMMIT 0x20
+
 /*
  * Try to read one refname component from the front of refname.
  * Return the length of the component found, or -1 if the component is
@@ -263,7 +268,7 @@ struct ref_dir {
  * presence of an empty subdirectory does not block the creation of a
  * similarly-named reference.  (The fact that reference names with the
  * same leading components can conflict *with each other* is a
- * separate issue that is regulated by is_refname_available().)
+ * separate issue that is regulated by verify_refname_available().)
  *
  * Please note that the name field contains the fully-qualified
  * reference (or subdirectory) name.  Space could be saved by only
@@ -344,8 +349,6 @@ static struct ref_entry *create_ref_entry(const char *refname,
        if (check_name &&
            check_refname_format(refname, REFNAME_ALLOW_ONELEVEL))
                die("Reference has invalid format: '%s'", refname);
-       if (!check_name && !refname_is_safe(refname))
-               die("Reference has invalid name: '%s'", refname);
        len = strlen(refname) + 1;
        ref = xmalloc(sizeof(struct ref_entry) + len);
        hashcpy(ref->u.value.sha1, sha1);
@@ -841,121 +844,181 @@ static void prime_ref_dir(struct ref_dir *dir)
        }
 }
 
-static int entry_matches(struct ref_entry *entry, const struct string_list *list)
-{
-       return list && string_list_has_string(list, entry->name);
-}
-
 struct nonmatching_ref_data {
        const struct string_list *skip;
-       struct ref_entry *found;
+       const char *conflicting_refname;
 };
 
 static int nonmatching_ref_fn(struct ref_entry *entry, void *vdata)
 {
        struct nonmatching_ref_data *data = vdata;
 
-       if (entry_matches(entry, data->skip))
+       if (data->skip && string_list_has_string(data->skip, entry->name))
                return 0;
 
-       data->found = entry;
+       data->conflicting_refname = entry->name;
        return 1;
 }
 
-static void report_refname_conflict(struct ref_entry *entry,
-                                   const char *refname)
-{
-       error("'%s' exists; cannot create '%s'", entry->name, refname);
-}
-
 /*
- * Return true iff a reference named refname could be created without
- * conflicting with the name of an existing reference in dir.  If
- * skip is non-NULL, ignore potential conflicts with refs in skip
- * (e.g., because they are scheduled for deletion in the same
- * operation).
+ * Return 0 if a reference named refname could be created without
+ * conflicting with the name of an existing reference in dir.
+ * Otherwise, return a negative value and write an explanation to err.
+ * If extras is non-NULL, it is a list of additional refnames with
+ * which refname is not allowed to conflict. If skip is non-NULL,
+ * ignore potential conflicts with refs in skip (e.g., because they
+ * are scheduled for deletion in the same operation). Behavior is
+ * undefined if the same name is listed in both extras and skip.
  *
  * Two reference names conflict if one of them exactly matches the
- * leading components of the other; e.g., "foo/bar" conflicts with
- * both "foo" and with "foo/bar/baz" but not with "foo/bar" or
- * "foo/barbados".
+ * leading components of the other; e.g., "refs/foo/bar" conflicts
+ * with both "refs/foo" and with "refs/foo/bar/baz" but not with
+ * "refs/foo/bar" or "refs/foo/barbados".
  *
- * skip must be sorted.
+ * extras and skip must be sorted.
  */
-static int is_refname_available(const char *refname,
-                               const struct string_list *skip,
-                               struct ref_dir *dir)
+static int verify_refname_available(const char *refname,
+                                   const struct string_list *extras,
+                                   const struct string_list *skip,
+                                   struct ref_dir *dir,
+                                   struct strbuf *err)
 {
        const char *slash;
-       size_t len;
        int pos;
-       char *dirname;
+       struct strbuf dirname = STRBUF_INIT;
+       int ret = -1;
+
+       /*
+        * For the sake of comments in this function, suppose that
+        * refname is "refs/foo/bar".
+        */
 
+       assert(err);
+
+       strbuf_grow(&dirname, strlen(refname) + 1);
        for (slash = strchr(refname, '/'); slash; slash = strchr(slash + 1, '/')) {
+               /* Expand dirname to the new prefix, not including the trailing slash: */
+               strbuf_add(&dirname, refname + dirname.len, slash - refname - dirname.len);
+
                /*
-                * We are still at a leading dir of the refname; we are
-                * looking for a conflict with a leaf entry.
-                *
-                * If we find one, we still must make sure it is
-                * not in "skip".
+                * We are still at a leading dir of the refname (e.g.,
+                * "refs/foo"; if there is a reference with that name,
+                * it is a conflict, *unless* it is in skip.
                 */
-               pos = search_ref_dir(dir, refname, slash - refname);
-               if (pos >= 0) {
-                       struct ref_entry *entry = dir->entries[pos];
-                       if (entry_matches(entry, skip))
-                               return 1;
-                       report_refname_conflict(entry, refname);
-                       return 0;
+               if (dir) {
+                       pos = search_ref_dir(dir, dirname.buf, dirname.len);
+                       if (pos >= 0 &&
+                           (!skip || !string_list_has_string(skip, dirname.buf))) {
+                               /*
+                                * We found a reference whose name is
+                                * a proper prefix of refname; e.g.,
+                                * "refs/foo", and is not in skip.
+                                */
+                               strbuf_addf(err, "'%s' exists; cannot create '%s'",
+                                           dirname.buf, refname);
+                               goto cleanup;
+                       }
                }
 
+               if (extras && string_list_has_string(extras, dirname.buf) &&
+                   (!skip || !string_list_has_string(skip, dirname.buf))) {
+                       strbuf_addf(err, "cannot process '%s' and '%s' at the same time",
+                                   refname, dirname.buf);
+                       goto cleanup;
+               }
 
                /*
                 * Otherwise, we can try to continue our search with
-                * the next component; if we come up empty, we know
-                * there is nothing under this whole prefix.
+                * the next component. So try to look up the
+                * directory, e.g., "refs/foo/". If we come up empty,
+                * we know there is nothing under this whole prefix,
+                * but even in that case we still have to continue the
+                * search for conflicts with extras.
                 */
-               pos = search_ref_dir(dir, refname, slash + 1 - refname);
-               if (pos < 0)
-                       return 1;
-
-               dir = get_ref_dir(dir->entries[pos]);
+               strbuf_addch(&dirname, '/');
+               if (dir) {
+                       pos = search_ref_dir(dir, dirname.buf, dirname.len);
+                       if (pos < 0) {
+                               /*
+                                * There was no directory "refs/foo/",
+                                * so there is nothing under this
+                                * whole prefix. So there is no need
+                                * to continue looking for conflicting
+                                * references. But we need to continue
+                                * looking for conflicting extras.
+                                */
+                               dir = NULL;
+                       } else {
+                               dir = get_ref_dir(dir->entries[pos]);
+                       }
+               }
        }
 
        /*
-        * We are at the leaf of our refname; we want to
-        * make sure there are no directories which match it.
+        * We are at the leaf of our refname (e.g., "refs/foo/bar").
+        * There is no point in searching for a reference with that
+        * name, because a refname isn't considered to conflict with
+        * itself. But we still need to check for references whose
+        * names are in the "refs/foo/bar/" namespace, because they
+        * *do* conflict.
         */
-       len = strlen(refname);
-       dirname = xmallocz(len + 1);
-       sprintf(dirname, "%s/", refname);
-       pos = search_ref_dir(dir, dirname, len + 1);
-       free(dirname);
+       strbuf_addstr(&dirname, refname + dirname.len);
+       strbuf_addch(&dirname, '/');
+
+       if (dir) {
+               pos = search_ref_dir(dir, dirname.buf, dirname.len);
+
+               if (pos >= 0) {
+                       /*
+                        * We found a directory named "$refname/"
+                        * (e.g., "refs/foo/bar/"). It is a problem
+                        * iff it contains any ref that is not in
+                        * "skip".
+                        */
+                       struct nonmatching_ref_data data;
+
+                       data.skip = skip;
+                       data.conflicting_refname = NULL;
+                       dir = get_ref_dir(dir->entries[pos]);
+                       sort_ref_dir(dir);
+                       if (do_for_each_entry_in_dir(dir, 0, nonmatching_ref_fn, &data)) {
+                               strbuf_addf(err, "'%s' exists; cannot create '%s'",
+                                           data.conflicting_refname, refname);
+                               goto cleanup;
+                       }
+               }
+       }
 
-       if (pos >= 0) {
+       if (extras) {
                /*
-                * We found a directory named "refname". It is a
-                * problem iff it contains any ref that is not
-                * in "skip".
+                * Check for entries in extras that start with
+                * "$refname/". We do that by looking for the place
+                * where "$refname/" would be inserted in extras. If
+                * there is an entry at that position that starts with
+                * "$refname/" and is not in skip, then we have a
+                * conflict.
                 */
-               struct ref_entry *entry = dir->entries[pos];
-               struct ref_dir *dir = get_ref_dir(entry);
-               struct nonmatching_ref_data data;
+               for (pos = string_list_find_insert_index(extras, dirname.buf, 0);
+                    pos < extras->nr; pos++) {
+                       const char *extra_refname = extras->items[pos].string;
 
-               data.skip = skip;
-               sort_ref_dir(dir);
-               if (!do_for_each_entry_in_dir(dir, 0, nonmatching_ref_fn, &data))
-                       return 1;
+                       if (!starts_with(extra_refname, dirname.buf))
+                               break;
 
-               report_refname_conflict(data.found, refname);
-               return 0;
+                       if (!skip || !string_list_has_string(skip, extra_refname)) {
+                               strbuf_addf(err, "cannot process '%s' and '%s' at the same time",
+                                           refname, extra_refname);
+                               goto cleanup;
+                       }
+               }
        }
 
-       /*
-        * There is no point in searching for another leaf
-        * node which matches it; such an entry would be the
-        * ref we are looking for, not a conflict.
-        */
-       return 1;
+       /* No conflicts were found */
+       ret = 0;
+
+cleanup:
+       strbuf_release(&dirname);
+       return ret;
 }
 
 struct packed_ref_cache {
@@ -1178,6 +1241,8 @@ static void read_packed_refs(FILE *f, struct ref_dir *dir)
                        int flag = REF_ISPACKED;
 
                        if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
+                               if (!refname_is_safe(refname))
+                                       die("packed refname is dangerous: %s", refname);
                                hashclr(sha1);
                                flag |= REF_BAD_NAME | REF_ISBROKEN;
                        }
@@ -1323,6 +1388,8 @@ static void read_loose_refs(const char *dirname, struct ref_dir *dir)
                        }
                        if (check_refname_format(refname.buf,
                                                 REFNAME_ALLOW_ONELEVEL)) {
+                               if (!refname_is_safe(refname.buf))
+                                       die("loose refname is dangerous: %s", refname.buf);
                                hashclr(sha1);
                                flag |= REF_BAD_NAME | REF_ISBROKEN;
                        }
@@ -1382,7 +1449,7 @@ static int resolve_gitlink_ref_recursive(struct ref_cache *refs,
 {
        int fd, len;
        char buffer[128], *p;
-       char *path;
+       const char *path;
 
        if (recursion > MAXDEPTH || strlen(refname) > MAXREFLEN)
                return -1;
@@ -1475,7 +1542,11 @@ static int resolve_missing_loose_ref(const char *refname,
 }
 
 /* This function needs to return a meaningful errno on failure */
-const char *resolve_ref_unsafe(const char *refname, int resolve_flags, unsigned char *sha1, int *flags)
+static const char *resolve_ref_unsafe_1(const char *refname,
+                                       int resolve_flags,
+                                       unsigned char *sha1,
+                                       int *flags,
+                                       struct strbuf *sb_path)
 {
        int depth = MAXDEPTH;
        ssize_t len;
@@ -1506,7 +1577,7 @@ const char *resolve_ref_unsafe(const char *refname, int resolve_flags, unsigned
                bad_name = 1;
        }
        for (;;) {
-               char path[PATH_MAX];
+               const char *path;
                struct stat st;
                char *buf;
                int fd;
@@ -1516,7 +1587,9 @@ const char *resolve_ref_unsafe(const char *refname, int resolve_flags, unsigned
                        return NULL;
                }
 
-               git_snpath(path, sizeof(path), "%s", refname);
+               strbuf_reset(sb_path);
+               strbuf_git_path(sb_path, "%s", refname);
+               path = sb_path->buf;
 
                /*
                 * We might have to loop back here to avoid a race
@@ -1643,6 +1716,16 @@ const char *resolve_ref_unsafe(const char *refname, int resolve_flags, unsigned
        }
 }
 
+const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
+                              unsigned char *sha1, int *flags)
+{
+       struct strbuf sb_path = STRBUF_INIT;
+       const char *ret = resolve_ref_unsafe_1(refname, resolve_flags,
+                                              sha1, flags, &sb_path);
+       strbuf_release(&sb_path);
+       return ret;
+}
+
 char *resolve_refdup(const char *ref, int resolve_flags, unsigned char *sha1, int *flags)
 {
        return xstrdup_or_null(resolve_ref_unsafe(ref, resolve_flags, sha1, flags));
@@ -2271,10 +2354,12 @@ int dwim_log(const char *str, int len, unsigned char *sha1, char **log)
  */
 static struct ref_lock *lock_ref_sha1_basic(const char *refname,
                                            const unsigned char *old_sha1,
+                                           const struct string_list *extras,
                                            const struct string_list *skip,
-                                           unsigned int flags, int *type_p)
+                                           unsigned int flags, int *type_p,
+                                           struct strbuf *err)
 {
-       char *ref_file;
+       const char *ref_file;
        const char *orig_refname = refname;
        struct ref_lock *lock;
        int last_errno = 0;
@@ -2283,8 +2368,9 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
        int resolve_flags = 0;
        int attempts_remaining = 3;
 
+       assert(err);
+
        lock = xcalloc(1, sizeof(struct ref_lock));
-       lock->lock_fd = -1;
 
        if (mustexist)
                resolve_flags |= RESOLVE_REF_READING;
@@ -2305,7 +2391,12 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
                ref_file = git_path("%s", orig_refname);
                if (remove_empty_directories(ref_file)) {
                        last_errno = errno;
-                       error("there are still refs under '%s'", orig_refname);
+
+                       if (!verify_refname_available(orig_refname, extras, skip,
+                                                     get_loose_refs(&ref_cache), err))
+                               strbuf_addf(err, "there are still refs under '%s'",
+                                           orig_refname);
+
                        goto error_return;
                }
                refname = resolve_ref_unsafe(orig_refname, resolve_flags,
@@ -2315,8 +2406,12 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
            *type_p = type;
        if (!refname) {
                last_errno = errno;
-               error("unable to resolve reference %s: %s",
-                       orig_refname, strerror(errno));
+               if (last_errno != ENOTDIR ||
+                   !verify_refname_available(orig_refname, extras, skip,
+                                             get_loose_refs(&ref_cache), err))
+                       strbuf_addf(err, "unable to resolve reference %s: %s",
+                                   orig_refname, strerror(last_errno));
+
                goto error_return;
        }
        /*
@@ -2326,7 +2421,8 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
         * our refname.
         */
        if (is_null_sha1(lock->old_sha1) &&
-            !is_refname_available(refname, skip, get_packed_refs(&ref_cache))) {
+           verify_refname_available(refname, extras, skip,
+                                    get_packed_refs(&ref_cache), err)) {
                last_errno = ENOTDIR;
                goto error_return;
        }
@@ -2343,7 +2439,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
        ref_file = git_path("%s", refname);
 
  retry:
-       switch (safe_create_leading_directories(ref_file)) {
+       switch (safe_create_leading_directories_const(ref_file)) {
        case SCLD_OK:
                break; /* success */
        case SCLD_VANISHED:
@@ -2352,12 +2448,11 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
                /* fall through */
        default:
                last_errno = errno;
-               error("unable to create directory for %s", ref_file);
+               strbuf_addf(err, "unable to create directory for %s", ref_file);
                goto error_return;
        }
 
-       lock->lock_fd = hold_lock_file_for_update(lock->lk, ref_file, lflags);
-       if (lock->lock_fd < 0) {
+       if (hold_lock_file_for_update(lock->lk, ref_file, lflags) < 0) {
                last_errno = errno;
                if (errno == ENOENT && --attempts_remaining > 0)
                        /*
@@ -2367,10 +2462,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
                         */
                        goto retry;
                else {
-                       struct strbuf err = STRBUF_INIT;
-                       unable_to_lock_message(ref_file, errno, &err);
-                       error("%s", err.buf);
-                       strbuf_release(&err);
+                       unable_to_lock_message(ref_file, errno, err);
                        goto error_return;
                }
        }
@@ -2413,9 +2505,19 @@ static int write_packed_entry_fn(struct ref_entry *entry, void *cb_data)
 /* This should return a meaningful errno on failure */
 int lock_packed_refs(int flags)
 {
+       static int timeout_configured = 0;
+       static int timeout_value = 1000;
+
        struct packed_ref_cache *packed_ref_cache;
 
-       if (hold_lock_file_for_update(&packlock, git_path("packed-refs"), flags) < 0)
+       if (!timeout_configured) {
+               git_config_get_int("core.packedrefstimeout", &timeout_value);
+               timeout_configured = 1;
+       }
+
+       if (hold_lock_file_for_update_timeout(
+                           &packlock, git_path("packed-refs"),
+                           flags, timeout_value) < 0)
                return -1;
        /*
         * Get the current packed-refs while holding the lock.  If the
@@ -2721,7 +2823,7 @@ static int rename_tmp_log(const char *newrefname)
        int attempts_remaining = 4;
 
  retry:
-       switch (safe_create_leading_directories(git_path("logs/%s", newrefname))) {
+       switch (safe_create_leading_directories_const(git_path("logs/%s", newrefname))) {
        case SCLD_OK:
                break; /* success */
        case SCLD_VANISHED:
@@ -2764,17 +2866,25 @@ static int rename_tmp_log(const char *newrefname)
 static int rename_ref_available(const char *oldname, const char *newname)
 {
        struct string_list skip = STRING_LIST_INIT_NODUP;
+       struct strbuf err = STRBUF_INIT;
        int ret;
 
        string_list_insert(&skip, oldname);
-       ret = is_refname_available(newname, &skip, get_packed_refs(&ref_cache))
-           && is_refname_available(newname, &skip, get_loose_refs(&ref_cache));
+       ret = !verify_refname_available(newname, NULL, &skip,
+                                       get_packed_refs(&ref_cache), &err)
+               && !verify_refname_available(newname, NULL, &skip,
+                                            get_loose_refs(&ref_cache), &err);
+       if (!ret)
+               error("%s", err.buf);
+
        string_list_clear(&skip, 0);
+       strbuf_release(&err);
        return ret;
 }
 
-static int write_ref_sha1(struct ref_lock *lock, const unsigned char *sha1,
-                         const char *logmsg);
+static int write_ref_to_lockfile(struct ref_lock *lock, const unsigned char *sha1);
+static int commit_ref_update(struct ref_lock *lock,
+                            const unsigned char *sha1, const char *logmsg);
 
 int rename_ref(const char *oldrefname, const char *newrefname, const char *logmsg)
 {
@@ -2784,6 +2894,7 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms
        struct stat loginfo;
        int log = !lstat(git_path("logs/%s", oldrefname), &loginfo);
        const char *symref = NULL;
+       struct strbuf err = STRBUF_INIT;
 
        if (log && S_ISLNK(loginfo.st_mode))
                return error("reflog for %s is a symlink", oldrefname);
@@ -2826,13 +2937,16 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms
 
        logmoved = log;
 
-       lock = lock_ref_sha1_basic(newrefname, NULL, NULL, 0, NULL);
+       lock = lock_ref_sha1_basic(newrefname, NULL, NULL, NULL, 0, NULL, &err);
        if (!lock) {
-               error("unable to lock %s for update", newrefname);
+               error("unable to rename '%s' to '%s': %s", oldrefname, newrefname, err.buf);
+               strbuf_release(&err);
                goto rollback;
        }
        hashcpy(lock->old_sha1, orig_sha1);
-       if (write_ref_sha1(lock, orig_sha1, logmsg)) {
+
+       if (write_ref_to_lockfile(lock, orig_sha1) ||
+           commit_ref_update(lock, orig_sha1, logmsg)) {
                error("unable to write current sha1 into %s", newrefname);
                goto rollback;
        }
@@ -2840,15 +2954,17 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms
        return 0;
 
  rollback:
-       lock = lock_ref_sha1_basic(oldrefname, NULL, NULL, 0, NULL);
+       lock = lock_ref_sha1_basic(oldrefname, NULL, NULL, NULL, 0, NULL, &err);
        if (!lock) {
-               error("unable to lock %s for rollback", oldrefname);
+               error("unable to lock %s for rollback: %s", oldrefname, err.buf);
+               strbuf_release(&err);
                goto rollbacklog;
        }
 
        flag = log_all_ref_updates;
        log_all_ref_updates = 0;
-       if (write_ref_sha1(lock, orig_sha1, NULL))
+       if (write_ref_to_lockfile(lock, orig_sha1) ||
+           commit_ref_update(lock, orig_sha1, NULL))
                error("unable to write current sha1 into %s", oldrefname);
        log_all_ref_updates = flag;
 
@@ -2868,7 +2984,6 @@ static int close_ref(struct ref_lock *lock)
 {
        if (close_lock_file(lock->lk))
                return -1;
-       lock->lock_fd = -1;
        return 0;
 }
 
@@ -2876,7 +2991,6 @@ static int commit_ref(struct ref_lock *lock)
 {
        if (commit_lock_file(lock->lk))
                return -1;
-       lock->lock_fd = -1;
        return 0;
 }
 
@@ -2907,11 +3021,15 @@ static int copy_msg(char *buf, const char *msg)
 }
 
 /* This function must set a meaningful errno on failure */
-int log_ref_setup(const char *refname, char *logfile, int bufsize)
+int log_ref_setup(const char *refname, struct strbuf *sb_logfile)
 {
        int logfd, oflags = O_APPEND | O_WRONLY;
+       char *logfile;
 
-       git_snpath(logfile, bufsize, "logs/%s", refname);
+       strbuf_git_path(sb_logfile, "logs/%s", refname);
+       logfile = sb_logfile->buf;
+       /* make sure the rest of the function can't change "logfile" */
+       sb_logfile = NULL;
        if (log_all_ref_updates &&
            (starts_with(refname, "refs/heads/") ||
             starts_with(refname, "refs/remotes/") ||
@@ -2982,18 +3100,22 @@ static int log_ref_write_fd(int fd, const unsigned char *old_sha1,
        return 0;
 }
 
-static int log_ref_write(const char *refname, const unsigned char *old_sha1,
-                        const unsigned char *new_sha1, const char *msg)
+static int log_ref_write_1(const char *refname, const unsigned char *old_sha1,
+                          const unsigned char *new_sha1, const char *msg,
+                          struct strbuf *sb_log_file)
 {
        int logfd, result, oflags = O_APPEND | O_WRONLY;
-       char log_file[PATH_MAX];
+       char *log_file;
 
        if (log_all_ref_updates < 0)
                log_all_ref_updates = !is_bare_repository();
 
-       result = log_ref_setup(refname, log_file, sizeof(log_file));
+       result = log_ref_setup(refname, sb_log_file);
        if (result)
                return result;
+       log_file = sb_log_file->buf;
+       /* make sure the rest of the function can't change "log_file" */
+       sb_log_file = NULL;
 
        logfd = open(log_file, oflags);
        if (logfd < 0)
@@ -3016,17 +3138,26 @@ static int log_ref_write(const char *refname, const unsigned char *old_sha1,
        return 0;
 }
 
+static int log_ref_write(const char *refname, const unsigned char *old_sha1,
+                        const unsigned char *new_sha1, const char *msg)
+{
+       struct strbuf sb = STRBUF_INIT;
+       int ret = log_ref_write_1(refname, old_sha1, new_sha1, msg, &sb);
+       strbuf_release(&sb);
+       return ret;
+}
+
 int is_branch(const char *refname)
 {
        return !strcmp(refname, "HEAD") || starts_with(refname, "refs/heads/");
 }
 
 /*
- * Write sha1 into the ref specified by the lock. Make sure that errno
- * is sane on error.
+ * Write sha1 into the open lockfile, then close the lockfile. On
+ * errors, rollback the lockfile and set errno to reflect the problem.
  */
-static int write_ref_sha1(struct ref_lock *lock,
-       const unsigned char *sha1, const char *logmsg)
+static int write_ref_to_lockfile(struct ref_lock *lock,
+                                const unsigned char *sha1)
 {
        static char term = '\n';
        struct object *o;
@@ -3046,8 +3177,8 @@ static int write_ref_sha1(struct ref_lock *lock,
                errno = EINVAL;
                return -1;
        }
-       if (write_in_full(lock->lock_fd, sha1_to_hex(sha1), 40) != 40 ||
-           write_in_full(lock->lock_fd, &term, 1) != 1 ||
+       if (write_in_full(lock->lk->fd, sha1_to_hex(sha1), 40) != 40 ||
+           write_in_full(lock->lk->fd, &term, 1) != 1 ||
            close_ref(lock) < 0) {
                int save_errno = errno;
                error("Couldn't write %s", lock->lk->filename.buf);
@@ -3055,6 +3186,17 @@ static int write_ref_sha1(struct ref_lock *lock,
                errno = save_errno;
                return -1;
        }
+       return 0;
+}
+
+/*
+ * Commit a change to a loose reference that has already been written
+ * to the loose reference lockfile. Also update the reflogs if
+ * necessary, using the specified lockmsg (which can be NULL).
+ */
+static int commit_ref_update(struct ref_lock *lock,
+                            const unsigned char *sha1, const char *logmsg)
+{
        clear_loose_ref_cache(&ref_cache);
        if (log_ref_write(lock->ref_name, lock->old_sha1, sha1, logmsg) < 0 ||
            (strcmp(lock->ref_name, lock->orig_ref_name) &&
@@ -3695,25 +3837,18 @@ int update_ref(const char *msg, const char *refname,
        return 0;
 }
 
-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)->refname, (*u2)->refname);
-}
-
-static int ref_update_reject_duplicates(struct ref_update **updates, int n,
+static int ref_update_reject_duplicates(struct string_list *refnames,
                                        struct strbuf *err)
 {
-       int i;
+       int i, n = refnames->nr;
 
        assert(err);
 
        for (i = 1; i < n; i++)
-               if (!strcmp(updates[i - 1]->refname, updates[i]->refname)) {
+               if (!strcmp(refnames->items[i - 1].string, refnames->items[i].string)) {
                        strbuf_addf(err,
                                    "Multiple updates for ref '%s' not allowed.",
-                                   updates[i]->refname);
+                                   refnames->items[i].string);
                        return 1;
                }
        return 0;
@@ -3727,6 +3862,7 @@ int ref_transaction_commit(struct ref_transaction *transaction,
        struct ref_update **updates = transaction->updates;
        struct string_list refs_to_delete = STRING_LIST_INIT_NODUP;
        struct string_list_item *ref_to_delete;
+       struct string_list affected_refnames = STRING_LIST_INIT_NODUP;
 
        assert(err);
 
@@ -3738,63 +3874,101 @@ int ref_transaction_commit(struct ref_transaction *transaction,
                return 0;
        }
 
-       /* Copy, sort, and reject duplicate refs */
-       qsort(updates, n, sizeof(*updates), ref_update_compare);
-       if (ref_update_reject_duplicates(updates, n, err)) {
+       /* Fail if a refname appears more than once in the transaction: */
+       for (i = 0; i < n; i++)
+               string_list_append(&affected_refnames, updates[i]->refname);
+       string_list_sort(&affected_refnames);
+       if (ref_update_reject_duplicates(&affected_refnames, err)) {
                ret = TRANSACTION_GENERIC_ERROR;
                goto cleanup;
        }
 
-       /* Acquire all locks while verifying old values */
+       /*
+        * Acquire all locks, verify old values if provided, check
+        * that new values are valid, and write new values to the
+        * lockfiles, ready to be activated. Only keep one lockfile
+        * open at a time to avoid running out of file descriptors.
+        */
        for (i = 0; i < n; i++) {
                struct ref_update *update = updates[i];
-               unsigned int flags = update->flags;
 
-               if ((flags & REF_HAVE_NEW) && is_null_sha1(update->new_sha1))
-                       flags |= REF_DELETING;
+               if ((update->flags & REF_HAVE_NEW) &&
+                   is_null_sha1(update->new_sha1))
+                       update->flags |= REF_DELETING;
                update->lock = lock_ref_sha1_basic(
                                update->refname,
                                ((update->flags & REF_HAVE_OLD) ?
                                 update->old_sha1 : NULL),
-                               NULL,
-                               flags,
-                               &update->type);
+                               &affected_refnames, NULL,
+                               update->flags,
+                               &update->type,
+                               err);
                if (!update->lock) {
+                       char *reason;
+
                        ret = (errno == ENOTDIR)
                                ? TRANSACTION_NAME_CONFLICT
                                : TRANSACTION_GENERIC_ERROR;
-                       strbuf_addf(err, "Cannot lock the ref '%s'.",
-                                   update->refname);
+                       reason = strbuf_detach(err, NULL);
+                       strbuf_addf(err, "Cannot lock ref '%s': %s",
+                                   update->refname, reason);
+                       free(reason);
                        goto cleanup;
                }
-       }
-
-       /* Perform updates first so live commits remain referenced */
-       for (i = 0; i < n; i++) {
-               struct ref_update *update = updates[i];
-               int flags = update->flags;
-
-               if ((flags & REF_HAVE_NEW) && !is_null_sha1(update->new_sha1)) {
+               if ((update->flags & REF_HAVE_NEW) &&
+                   !(update->flags & REF_DELETING)) {
                        int overwriting_symref = ((update->type & REF_ISSYMREF) &&
                                                  (update->flags & REF_NODEREF));
 
-                       if (!overwriting_symref
-                           && !hashcmp(update->lock->old_sha1, update->new_sha1)) {
+                       if (!overwriting_symref &&
+                           !hashcmp(update->lock->old_sha1, update->new_sha1)) {
                                /*
                                 * The reference already has the desired
                                 * value, so we don't need to write it.
                                 */
-                               unlock_ref(update->lock);
+                       } else if (write_ref_to_lockfile(update->lock,
+                                                        update->new_sha1)) {
+                               /*
+                                * The lock was freed upon failure of
+                                * write_ref_to_lockfile():
+                                */
+                               update->lock = NULL;
+                               strbuf_addf(err, "Cannot update the ref '%s'.",
+                                           update->refname);
+                               ret = TRANSACTION_GENERIC_ERROR;
+                               goto cleanup;
+                       } else {
+                               update->flags |= REF_NEEDS_COMMIT;
+                       }
+               }
+               if (!(update->flags & REF_NEEDS_COMMIT)) {
+                       /*
+                        * We didn't have to write anything to the lockfile.
+                        * Close it to free up the file descriptor:
+                        */
+                       if (close_ref(update->lock)) {
+                               strbuf_addf(err, "Couldn't close %s.lock",
+                                           update->refname);
+                               goto cleanup;
+                       }
+               }
+       }
+
+       /* Perform updates first so live commits remain referenced */
+       for (i = 0; i < n; i++) {
+               struct ref_update *update = updates[i];
+
+               if (update->flags & REF_NEEDS_COMMIT) {
+                       if (commit_ref_update(update->lock,
+                                             update->new_sha1, update->msg)) {
+                               /* freed by commit_ref_update(): */
                                update->lock = NULL;
-                       } else if (write_ref_sha1(update->lock, update->new_sha1,
-                                                 update->msg)) {
-                               update->lock = NULL; /* freed by write_ref_sha1 */
                                strbuf_addf(err, "Cannot update the ref '%s'.",
                                            update->refname);
                                ret = TRANSACTION_GENERIC_ERROR;
                                goto cleanup;
                        } else {
-                               /* freed by write_ref_sha1(): */
+                               /* freed by commit_ref_update(): */
                                update->lock = NULL;
                        }
                }
@@ -3803,15 +3977,14 @@ int ref_transaction_commit(struct ref_transaction *transaction,
        /* Perform deletes now that updates are safely completed */
        for (i = 0; i < n; i++) {
                struct ref_update *update = updates[i];
-               int flags = update->flags;
 
-               if ((flags & REF_HAVE_NEW) && is_null_sha1(update->new_sha1)) {
+               if (update->flags & REF_DELETING) {
                        if (delete_ref_loose(update->lock, update->type, err)) {
                                ret = TRANSACTION_GENERIC_ERROR;
                                goto cleanup;
                        }
 
-                       if (!(flags & REF_ISPRUNING))
+                       if (!(update->flags & REF_ISPRUNING))
                                string_list_append(&refs_to_delete,
                                                   update->lock->ref_name);
                }
@@ -3832,6 +4005,7 @@ int ref_transaction_commit(struct ref_transaction *transaction,
                if (updates[i]->lock)
                        unlock_ref(updates[i]->lock);
        string_list_clear(&refs_to_delete, 0);
+       string_list_clear(&affected_refnames, 0);
        return ret;
 }
 
@@ -4021,6 +4195,7 @@ int reflog_expire(const char *refname, const unsigned char *sha1,
        char *log_file;
        int status = 0;
        int type;
+       struct strbuf err = STRBUF_INIT;
 
        memset(&cb, 0, sizeof(cb));
        cb.flags = flags;
@@ -4032,9 +4207,12 @@ int reflog_expire(const char *refname, const unsigned char *sha1,
         * reference itself, plus we might need to update the
         * reference if --updateref was specified:
         */
-       lock = lock_ref_sha1_basic(refname, sha1, NULL, 0, &type);
-       if (!lock)
-               return error("cannot lock ref '%s'", refname);
+       lock = lock_ref_sha1_basic(refname, sha1, NULL, NULL, 0, &type, &err);
+       if (!lock) {
+               error("cannot lock ref '%s': %s", refname, err.buf);
+               strbuf_release(&err);
+               return -1;
+       }
        if (!reflog_exists(refname)) {
                unlock_ref(lock);
                return 0;
@@ -4084,9 +4262,9 @@ int reflog_expire(const char *refname, const unsigned char *sha1,
                        status |= error("couldn't write %s: %s", log_file,
                                        strerror(errno));
                } else if (update &&
-                       (write_in_full(lock->lock_fd,
+                          (write_in_full(lock->lk->fd,
                                sha1_to_hex(cb.last_kept_sha1), 40) != 40 ||
-                        write_str_in_full(lock->lock_fd, "\n") != 1 ||
+                        write_str_in_full(lock->lk->fd, "\n") != 1 ||
                         close_ref(lock) < 0)) {
                        status |= error("couldn't write %s",
                                        lock->lk->filename.buf);
diff --git a/refs.h b/refs.h
index cf642e6ddc438be77d64797a4dbcf790262a9fed..6d7d9b40f318119eea1e3240cca3a96d2c64e2a6 100644 (file)
--- a/refs.h
+++ b/refs.h
@@ -191,7 +191,7 @@ extern int peel_ref(const char *refname, unsigned char *sha1);
 /*
  * Setup reflog before using. Set errno to something meaningful on failure.
  */
-int log_ref_setup(const char *refname, char *logfile, int bufsize);
+int log_ref_setup(const char *refname, struct strbuf *logfile);
 
 /** Reads log for the value of ref during at_time. **/
 extern int read_ref_at(const char *refname, unsigned int flags,
index 31644dec04fe4a77d43624720ff516de2d746dbc..94aea9a36f16d9d72c1769aa9e258c5370c7dc84 100644 (file)
--- a/rerere.c
+++ b/rerere.c
@@ -659,6 +659,8 @@ int rerere_forget(struct pathspec *pathspec)
                return error("Could not read index");
 
        fd = setup_rerere(&merge_rr, RERERE_NOAUTOUPDATE);
+       if (fd < 0)
+               return 0;
 
        unmerge_cache(pathspec);
        find_conflict(&conflict);
index aad03ab705f301268980079282fcf370b9275c5a..4d73e90fad159184bfdd204b82dd8637ad28a955 100644 (file)
@@ -795,9 +795,9 @@ int finish_async(struct async *async)
 #endif
 }
 
-char *find_hook(const char *name)
+const char *find_hook(const char *name)
 {
-       char *path = git_path("hooks/%s", name);
+       const char *path = git_path("hooks/%s", name);
        if (access(path, X_OK) < 0)
                path = NULL;
 
index 263b9662adeba011adcd018f77b7ccbbcd53e94a..1103805af1b01e8396de15f48fbd06f75313fb0d 100644 (file)
@@ -52,7 +52,7 @@ int start_command(struct child_process *);
 int finish_command(struct child_process *);
 int run_command(struct child_process *);
 
-extern char *find_hook(const char *name);
+extern const char *find_hook(const char *name);
 LAST_ARG_MUST_BE_NULL
 extern int run_hook_le(const char *const *env, const char *name, ...);
 extern int run_hook_ve(const char *const *env, const char *name, va_list args);
index 2e07ac3339bce870b12e0023dc985929a277ebef..2a64fec949ea9495b5b9512399cec7979319de1c 100644 (file)
@@ -182,7 +182,7 @@ static int advertise_shallow_grafts_cb(const struct commit_graft *graft, void *c
 {
        struct strbuf *sb = cb;
        if (graft->nr_parent == -1)
-               packet_buf_write(sb, "shallow %s\n", sha1_to_hex(graft->sha1));
+               packet_buf_write(sb, "shallow %s\n", oid_to_hex(&graft->oid));
        return 0;
 }
 
diff --git a/setup.c b/setup.c
index 979b13f0c6cd6bc3c265187e8ea79628bfe99f87..863ddfd938d29e58341bd2be5dd3b7ecd4db7df2 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -140,7 +140,9 @@ int check_filename(const char *prefix, const char *arg)
                if (arg[2] == '\0') /* ":/" is root dir, always exists */
                        return 1;
                name = arg + 2;
-       } else if (prefix)
+       } else if (!no_wildcard(arg))
+               return 1;
+       else if (prefix)
                name = prefix_filename(prefix, strlen(prefix), arg);
        else
                name = arg;
@@ -224,6 +226,36 @@ void verify_non_filename(const char *prefix, const char *arg)
            "'git <command> [<revision>...] -- [<file>...]'", arg);
 }
 
+int get_common_dir(struct strbuf *sb, const char *gitdir)
+{
+       struct strbuf data = STRBUF_INIT;
+       struct strbuf path = STRBUF_INIT;
+       const char *git_common_dir = getenv(GIT_COMMON_DIR_ENVIRONMENT);
+       int ret = 0;
+       if (git_common_dir) {
+               strbuf_addstr(sb, git_common_dir);
+               return 1;
+       }
+       strbuf_addf(&path, "%s/commondir", gitdir);
+       if (file_exists(path.buf)) {
+               if (strbuf_read_file(&data, path.buf, 0) <= 0)
+                       die_errno(_("failed to read %s"), path.buf);
+               while (data.len && (data.buf[data.len - 1] == '\n' ||
+                                   data.buf[data.len - 1] == '\r'))
+                       data.len--;
+               data.buf[data.len] = '\0';
+               strbuf_reset(&path);
+               if (!is_absolute_path(data.buf))
+                       strbuf_addf(&path, "%s/", gitdir);
+               strbuf_addbuf(&path, &data);
+               strbuf_addstr(sb, real_path(path.buf));
+               ret = 1;
+       } else
+               strbuf_addstr(sb, gitdir);
+       strbuf_release(&data);
+       strbuf_release(&path);
+       return ret;
+}
 
 /*
  * Test if it looks like we're at a git directory.
@@ -238,31 +270,40 @@ void verify_non_filename(const char *prefix, const char *arg)
  */
 int is_git_directory(const char *suspect)
 {
-       char path[PATH_MAX];
-       size_t len = strlen(suspect);
+       struct strbuf path = STRBUF_INIT;
+       int ret = 0;
+       size_t len;
+
+       /* Check worktree-related signatures */
+       strbuf_addf(&path, "%s/HEAD", suspect);
+       if (validate_headref(path.buf))
+               goto done;
 
-       if (PATH_MAX <= len + strlen("/objects"))
-               die("Too long path: %.*s", 60, suspect);
-       strcpy(path, suspect);
+       strbuf_reset(&path);
+       get_common_dir(&path, suspect);
+       len = path.len;
+
+       /* Check non-worktree-related signatures */
        if (getenv(DB_ENVIRONMENT)) {
                if (access(getenv(DB_ENVIRONMENT), X_OK))
-                       return 0;
+                       goto done;
        }
        else {
-               strcpy(path + len, "/objects");
-               if (access(path, X_OK))
-                       return 0;
+               strbuf_setlen(&path, len);
+               strbuf_addstr(&path, "/objects");
+               if (access(path.buf, X_OK))
+                       goto done;
        }
 
-       strcpy(path + len, "/refs");
-       if (access(path, X_OK))
-               return 0;
+       strbuf_setlen(&path, len);
+       strbuf_addstr(&path, "/refs");
+       if (access(path.buf, X_OK))
+               goto done;
 
-       strcpy(path + len, "/HEAD");
-       if (validate_headref(path))
-               return 0;
-
-       return 1;
+       ret = 1;
+done:
+       strbuf_release(&path);
+       return ret;
 }
 
 int is_inside_git_dir(void)
@@ -304,9 +345,28 @@ void setup_work_tree(void)
        initialized = 1;
 }
 
+static int check_repo_format(const char *var, const char *value, void *cb)
+{
+       if (strcmp(var, "core.repositoryformatversion") == 0)
+               repository_format_version = git_config_int(var, value);
+       else if (strcmp(var, "core.sharedrepository") == 0)
+               shared_repository = git_config_perm(var, value);
+       return 0;
+}
+
 static int check_repository_format_gently(const char *gitdir, int *nongit_ok)
 {
-       char repo_config[PATH_MAX+1];
+       struct strbuf sb = STRBUF_INIT;
+       const char *repo_config;
+       config_fn_t fn;
+       int ret = 0;
+
+       if (get_common_dir(&sb, gitdir))
+               fn = check_repo_format;
+       else
+               fn = check_repository_format_version;
+       strbuf_addstr(&sb, "/config");
+       repo_config = sb.buf;
 
        /*
         * git_config() can't be used here because it calls git_pathdup()
@@ -317,8 +377,7 @@ static int check_repository_format_gently(const char *gitdir, int *nongit_ok)
         * Use a gentler version of git_config() to check if this repo
         * is a good one.
         */
-       snprintf(repo_config, PATH_MAX, "%s/config", gitdir);
-       git_config_early(check_repository_format_version, NULL, repo_config);
+       git_config_early(fn, NULL, repo_config);
        if (GIT_REPO_VERSION < repository_format_version) {
                if (!nongit_ok)
                        die ("Expected git repo version <= %d, found %d",
@@ -327,9 +386,21 @@ static int check_repository_format_gently(const char *gitdir, int *nongit_ok)
                        GIT_REPO_VERSION, repository_format_version);
                warning("Please upgrade Git");
                *nongit_ok = -1;
-               return -1;
+               ret = -1;
        }
-       return 0;
+       strbuf_release(&sb);
+       return ret;
+}
+
+static void update_linked_gitdir(const char *gitfile, const char *gitdir)
+{
+       struct strbuf path = STRBUF_INIT;
+       struct stat st;
+
+       strbuf_addf(&path, "%s/gitfile", gitdir);
+       if (stat(path.buf, &st) || st.st_mtime + 24 * 3600 < time(NULL))
+               write_file(path.buf, 0, "%s\n", gitfile);
+       strbuf_release(&path);
 }
 
 /*
@@ -380,6 +451,8 @@ const char *read_gitfile(const char *path)
 
        if (!is_git_directory(dir))
                die("Not a git repository: %s", dir);
+
+       update_linked_gitdir(path, dir);
        path = real_path(dir);
 
        free(buf);
@@ -799,11 +872,10 @@ int git_config_perm(const char *var, const char *value)
 
 int check_repository_format_version(const char *var, const char *value, void *cb)
 {
-       if (strcmp(var, "core.repositoryformatversion") == 0)
-               repository_format_version = git_config_int(var, value);
-       else if (strcmp(var, "core.sharedrepository") == 0)
-               shared_repository = git_config_perm(var, value);
-       else if (strcmp(var, "core.bare") == 0) {
+       int ret = check_repo_format(var, value, cb);
+       if (ret)
+               return ret;
+       if (strcmp(var, "core.bare") == 0) {
                is_bare_repository_cfg = git_config_bool(var, value);
                if (is_bare_repository_cfg == 1)
                        inside_work_tree = -1;
index 47f56f2e89d99b58a6d43bb44828c442577424cf..ccc6dac54b570d7174175242ba2d535d4006ab1c 100644 (file)
@@ -405,7 +405,7 @@ void add_to_alternates_file(const char *reference)
 {
        struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
        int fd = hold_lock_file_for_append(lock, git_path("objects/info/alternates"), LOCK_DIE_ON_ERROR);
-       char *alt = mkpath("%s\n", reference);
+       const char *alt = mkpath("%s\n", reference);
        write_or_die(fd, alt, strlen(alt));
        if (commit_lock_file(lock))
                die("could not close alternates file");
@@ -1564,6 +1564,40 @@ int unpack_sha1_header(git_zstream *stream, unsigned char *map, unsigned long ma
        return git_inflate(stream, 0);
 }
 
+static int unpack_sha1_header_to_strbuf(git_zstream *stream, unsigned char *map,
+                                       unsigned long mapsize, void *buffer,
+                                       unsigned long bufsiz, struct strbuf *header)
+{
+       int status;
+
+       status = unpack_sha1_header(stream, map, mapsize, buffer, bufsiz);
+
+       /*
+        * Check if entire header is unpacked in the first iteration.
+        */
+       if (memchr(buffer, '\0', stream->next_out - (unsigned char *)buffer))
+               return 0;
+
+       /*
+        * buffer[0..bufsiz] was not large enough.  Copy the partial
+        * result out to header, and then append the result of further
+        * reading the stream.
+        */
+       strbuf_add(header, buffer, stream->next_out - (unsigned char *)buffer);
+       stream->next_out = buffer;
+       stream->avail_out = bufsiz;
+
+       do {
+               status = git_inflate(stream, 0);
+               strbuf_add(header, buffer, stream->next_out - (unsigned char *)buffer);
+               if (memchr(buffer, '\0', stream->next_out - (unsigned char *)buffer))
+                       return 0;
+               stream->next_out = buffer;
+               stream->avail_out = bufsiz;
+       } while (status != Z_STREAM_END);
+       return -1;
+}
+
 static void *unpack_sha1_rest(git_zstream *stream, void *buffer, unsigned long size, const unsigned char *sha1)
 {
        int bytes = strlen(buffer) + 1;
@@ -1614,27 +1648,38 @@ static void *unpack_sha1_rest(git_zstream *stream, void *buffer, unsigned long s
  * too permissive for what we want to check. So do an anal
  * object header parse by hand.
  */
-int parse_sha1_header(const char *hdr, unsigned long *sizep)
+static int parse_sha1_header_extended(const char *hdr, struct object_info *oi,
+                              unsigned int flags)
 {
-       char type[10];
-       int i;
+       const char *type_buf = hdr;
        unsigned long size;
+       int type, type_len = 0;
 
        /*
-        * The type can be at most ten bytes (including the
-        * terminating '\0' that we add), and is followed by
+        * The type can be of any size but is followed by
         * a space.
         */
-       i = 0;
        for (;;) {
                char c = *hdr++;
                if (c == ' ')
                        break;
-               type[i++] = c;
-               if (i >= sizeof(type))
-                       return -1;
+               type_len++;
        }
-       type[i] = 0;
+
+       type = type_from_string_gently(type_buf, type_len, 1);
+       if (oi->typename)
+               strbuf_add(oi->typename, type_buf, type_len);
+       /*
+        * Set type to 0 if its an unknown object and
+        * we're obtaining the type using '--allow-unkown-type'
+        * option.
+        */
+       if ((flags & LOOKUP_UNKNOWN_OBJECT) && (type < 0))
+               type = 0;
+       else if (type < 0)
+               die("invalid object type");
+       if (oi->typep)
+               *oi->typep = type;
 
        /*
         * The length must follow immediately, and be in canonical
@@ -1652,12 +1697,24 @@ int parse_sha1_header(const char *hdr, unsigned long *sizep)
                        size = size * 10 + c;
                }
        }
-       *sizep = size;
+
+       if (oi->sizep)
+               *oi->sizep = size;
 
        /*
         * The length must be followed by a zero byte
         */
-       return *hdr ? -1 : type_from_string(type);
+       return *hdr ? -1 : type;
+}
+
+int parse_sha1_header(const char *hdr, unsigned long *sizep)
+{
+       struct object_info oi;
+
+       oi.sizep = sizep;
+       oi.typename = NULL;
+       oi.typep = NULL;
+       return parse_sha1_header_extended(hdr, &oi, LOOKUP_REPLACE_OBJECT);
 }
 
 static void *unpack_sha1_file(void *map, unsigned long mapsize, enum object_type *type, unsigned long *size, const unsigned char *sha1)
@@ -2473,10 +2530,8 @@ static int fill_pack_entry(const unsigned char *sha1,
         * answer, as it may have been deleted since the index was
         * loaded!
         */
-       if (!is_pack_valid(p)) {
-               warning("packfile %s cannot be accessed", p->pack_name);
+       if (!is_pack_valid(p))
                return 0;
-       }
        e->offset = offset;
        e->p = p;
        hashcpy(e->sha1, sha1);
@@ -2524,13 +2579,15 @@ struct packed_git *find_sha1_pack(const unsigned char *sha1,
 }
 
 static int sha1_loose_object_info(const unsigned char *sha1,
-                                 struct object_info *oi)
+                                 struct object_info *oi,
+                                 int flags)
 {
-       int status;
-       unsigned long mapsize, size;
+       int status = 0;
+       unsigned long mapsize;
        void *map;
        git_zstream stream;
        char hdr[32];
+       struct strbuf hdrbuf = STRBUF_INIT;
 
        if (oi->delta_base_sha1)
                hashclr(oi->delta_base_sha1);
@@ -2543,7 +2600,7 @@ static int sha1_loose_object_info(const unsigned char *sha1,
         * return value implicitly indicates whether the
         * object even exists.
         */
-       if (!oi->typep && !oi->sizep) {
+       if (!oi->typep && !oi->typename && !oi->sizep) {
                struct stat st;
                if (stat_sha1_file(sha1, &st) < 0)
                        return -1;
@@ -2557,17 +2614,26 @@ static int sha1_loose_object_info(const unsigned char *sha1,
                return -1;
        if (oi->disk_sizep)
                *oi->disk_sizep = mapsize;
-       if (unpack_sha1_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0)
+       if ((flags & LOOKUP_UNKNOWN_OBJECT)) {
+               if (unpack_sha1_header_to_strbuf(&stream, map, mapsize, hdr, sizeof(hdr), &hdrbuf) < 0)
+                       status = error("unable to unpack %s header with --allow-unknown-type",
+                                      sha1_to_hex(sha1));
+       } else if (unpack_sha1_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0)
                status = error("unable to unpack %s header",
                               sha1_to_hex(sha1));
-       else if ((status = parse_sha1_header(hdr, &size)) < 0)
+       if (status < 0)
+               ; /* Do nothing */
+       else if (hdrbuf.len) {
+               if ((status = parse_sha1_header_extended(hdrbuf.buf, oi, flags)) < 0)
+                       status = error("unable to parse %s header with --allow-unknown-type",
+                                      sha1_to_hex(sha1));
+       } else if ((status = parse_sha1_header_extended(hdr, oi, flags)) < 0)
                status = error("unable to parse %s header", sha1_to_hex(sha1));
-       else if (oi->sizep)
-               *oi->sizep = size;
        git_inflate_end(&stream);
        munmap(map, mapsize);
-       if (oi->typep)
+       if (status && oi->typep)
                *oi->typep = status;
+       strbuf_release(&hdrbuf);
        return 0;
 }
 
@@ -2576,6 +2642,7 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,
        struct cached_object *co;
        struct pack_entry e;
        int rtype;
+       enum object_type real_type;
        const unsigned char *real = lookup_replace_object_extended(sha1, flags);
 
        co = find_cached_object(real);
@@ -2588,13 +2655,15 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,
                        *(oi->disk_sizep) = 0;
                if (oi->delta_base_sha1)
                        hashclr(oi->delta_base_sha1);
+               if (oi->typename)
+                       strbuf_addstr(oi->typename, typename(co->type));
                oi->whence = OI_CACHED;
                return 0;
        }
 
        if (!find_pack_entry(real, &e)) {
                /* Most likely it's a loose object. */
-               if (!sha1_loose_object_info(real, oi)) {
+               if (!sha1_loose_object_info(real, oi, flags)) {
                        oi->whence = OI_LOOSE;
                        return 0;
                }
@@ -2605,9 +2674,18 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,
                        return -1;
        }
 
+       /*
+        * packed_object_info() does not follow the delta chain to
+        * find out the real type, unless it is given oi->typep.
+        */
+       if (oi->typename && !oi->typep)
+               oi->typep = &real_type;
+
        rtype = packed_object_info(e.p, e.offset, oi);
        if (rtype < 0) {
                mark_bad_packed_object(e.p, real);
+               if (oi->typep == &real_type)
+                       oi->typep = NULL;
                return sha1_object_info_extended(real, oi, 0);
        } else if (in_delta_base_cache(e.p, e.offset)) {
                oi->whence = OI_DBCACHED;
@@ -2618,6 +2696,10 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,
                oi->u.packed.is_delta = (rtype == OBJ_REF_DELTA ||
                                         rtype == OBJ_OFS_DELTA);
        }
+       if (oi->typename)
+               strbuf_addstr(oi->typename, typename(*oi->typep));
+       if (oi->typep == &real_type)
+               oi->typep = NULL;
 
        return 0;
 }
index d8bf40ad4bed3bc846bb71945f1c2bfce76a202d..d08d264dd2e567e1e467c48d03e579fb21677a29 100644 (file)
--- a/shallow.c
+++ b/shallow.c
@@ -31,7 +31,7 @@ int register_shallow(const unsigned char *sha1)
                xmalloc(sizeof(struct commit_graft));
        struct commit *commit = lookup_commit(sha1);
 
-       hashcpy(graft->sha1, sha1);
+       hashcpy(graft->oid.hash, sha1);
        graft->nr_parent = -1;
        if (commit && commit->object.parsed)
                commit->parents = NULL;
@@ -159,11 +159,11 @@ struct write_shallow_data {
 static int write_one_shallow(const struct commit_graft *graft, void *cb_data)
 {
        struct write_shallow_data *data = cb_data;
-       const char *hex = sha1_to_hex(graft->sha1);
+       const char *hex = oid_to_hex(&graft->oid);
        if (graft->nr_parent != -1)
                return 0;
        if (data->flags & SEEN_ONLY) {
-               struct commit *c = lookup_commit(graft->sha1);
+               struct commit *c = lookup_commit(graft->oid.hash);
                if (!c || !(c->object.flags & SEEN)) {
                        if (data->flags & VERBOSE)
                                printf("Removing %s from .git/shallow\n",
@@ -282,7 +282,7 @@ static int advertise_shallow_grafts_cb(const struct commit_graft *graft, void *c
 {
        int fd = *(int *)cb;
        if (graft->nr_parent == -1)
-               packet_write(fd, "shallow %s\n", sha1_to_hex(graft->sha1));
+               packet_write(fd, "shallow %s\n", oid_to_hex(&graft->oid));
        return 0;
 }
 
index 21485e20665979458fb794ee4c3cc77c27032fa8..968b780a06d1f17b190395f06f78fc3124fcf445 100644 (file)
@@ -41,13 +41,6 @@ int read_link_extension(struct index_state *istate,
        return 0;
 }
 
-static int write_strbuf(void *user_data, const void *data, size_t len)
-{
-       struct strbuf *sb = user_data;
-       strbuf_add(sb, data, len);
-       return len;
-}
-
 int write_link_extension(struct strbuf *sb,
                         struct index_state *istate)
 {
@@ -55,8 +48,8 @@ int write_link_extension(struct strbuf *sb,
        strbuf_add(sb, si->base_sha1, 20);
        if (!si->delete_bitmap && !si->replace_bitmap)
                return 0;
-       ewah_serialize_to(si->delete_bitmap, write_strbuf, sb);
-       ewah_serialize_to(si->replace_bitmap, write_strbuf, sb);
+       ewah_serialize_strbuf(si->delete_bitmap, sb);
+       ewah_serialize_strbuf(si->replace_bitmap, sb);
        return 0;
 }
 
index 88cafd4a70b8179a4e911c18704fb4ab0f2a21f5..0d4f4e54ec1ff1f0d37155e8049476d802a7c7e5 100644 (file)
--- a/strbuf.c
+++ b/strbuf.c
@@ -435,6 +435,47 @@ int strbuf_getcwd(struct strbuf *sb)
        return -1;
 }
 
+#ifdef HAVE_GETDELIM
+int strbuf_getwholeline(struct strbuf *sb, FILE *fp, int term)
+{
+       ssize_t r;
+
+       if (feof(fp))
+               return EOF;
+
+       strbuf_reset(sb);
+
+       /* Translate slopbuf to NULL, as we cannot call realloc on it */
+       if (!sb->alloc)
+               sb->buf = NULL;
+       r = getdelim(&sb->buf, &sb->alloc, term, fp);
+
+       if (r > 0) {
+               sb->len = r;
+               return 0;
+       }
+       assert(r == -1);
+
+       /*
+        * Normally we would have called xrealloc, which will try to free
+        * memory and recover. But we have no way to tell getdelim() to do so.
+        * Worse, we cannot try to recover ENOMEM ourselves, because we have
+        * no idea how many bytes were read by getdelim.
+        *
+        * Dying here is reasonable. It mirrors what xrealloc would do on
+        * catastrophic memory failure. We skip the opportunity to free pack
+        * memory and retry, but that's unlikely to help for a malloc small
+        * enough to hold a single line of input, anyway.
+        */
+       if (errno == ENOMEM)
+               die("Out of memory, getdelim failed");
+
+       /* Restore slopbuf that we moved out of the way before */
+       if (!sb->buf)
+               strbuf_init(sb, 0);
+       return EOF;
+}
+#else
 int strbuf_getwholeline(struct strbuf *sb, FILE *fp, int term)
 {
        int ch;
@@ -443,18 +484,22 @@ int strbuf_getwholeline(struct strbuf *sb, FILE *fp, int term)
                return EOF;
 
        strbuf_reset(sb);
-       while ((ch = fgetc(fp)) != EOF) {
-               strbuf_grow(sb, 1);
+       flockfile(fp);
+       while ((ch = getc_unlocked(fp)) != EOF) {
+               if (!strbuf_avail(sb))
+                       strbuf_grow(sb, 1);
                sb->buf[sb->len++] = ch;
                if (ch == term)
                        break;
        }
+       funlockfile(fp);
        if (ch == EOF && sb->len == 0)
                return EOF;
 
        sb->buf[sb->len] = '\0';
        return 0;
 }
+#endif
 
 int strbuf_getline(struct strbuf *sb, FILE *fp, int term)
 {
index 1883494ca3ad4931640c2a295c94800e287c1664..01c5c6371b8e43686f335704a67a59a1d82dbe3b 100644 (file)
--- a/strbuf.h
+++ b/strbuf.h
@@ -205,7 +205,8 @@ extern int strbuf_cmp(const struct strbuf *, const struct strbuf *);
  */
 static inline void strbuf_addch(struct strbuf *sb, int c)
 {
-       strbuf_grow(sb, 1);
+       if (!strbuf_avail(sb))
+               strbuf_grow(sb, 1);
        sb->buf[sb->len++] = c;
        sb->buf[sb->len] = '\0';
 }
index c0e6c81fc4656342fedeb4b5b68d9b938cb44b84..d491e6a7717ef0e1b9f7efd91becb024b98e0161 100644 (file)
@@ -1100,16 +1100,11 @@ void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir)
        struct strbuf file_name = STRBUF_INIT;
        struct strbuf rel_path = STRBUF_INIT;
        const char *real_work_tree = xstrdup(real_path(work_tree));
-       FILE *fp;
 
        /* Update gitfile */
        strbuf_addf(&file_name, "%s/.git", work_tree);
-       fp = fopen(file_name.buf, "w");
-       if (!fp)
-               die(_("Could not create git link %s"), file_name.buf);
-       fprintf(fp, "gitdir: %s\n", relative_path(git_dir, real_work_tree,
-                                                 &rel_path));
-       fclose(fp);
+       write_file(file_name.buf, 1, "gitdir: %s\n",
+                  relative_path(git_dir, real_work_tree, &rel_path));
 
        /* Update core.worktree setting */
        strbuf_reset(&file_name);
index 5aa8adcf9c8a53b8a643a37b9474886448f6a45b..75482254a3e72a65640c6805abd028e2b7bd0e2f 100644 (file)
@@ -69,7 +69,7 @@ start_p4d() {
        (
                cd "$db" &&
                {
-                       p4d -q -p $P4DPORT &
+                       p4d -q -p $P4DPORT "$@" &
                        echo $! >"$pidfile"
                }
        ) &&
index e6adf2f82d59027279e06e0d273e719226d82184..e9714467d05e57eded6f37c3d5f07b91f63cc9fc 100644 (file)
 # Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at>
 #
 
+if test -n "$NO_CURL"
+then
+       skip_all='skipping test, git built without http support'
+       test_done
+fi
+
+if test -n "$NO_EXPAT" && test -n "$LIB_HTTPD_DAV"
+then
+       skip_all='skipping test, git built without expat support'
+       test_done
+fi
+
 test_tristate GIT_TEST_HTTPD
 if test "$GIT_TEST_HTTPD" = false
 then
index 8dc6939b9049baa32aca1200e36378e6e2296e9d..4ef5ed484c12a4509b9bc66f2cc41118f7254431 100755 (executable)
@@ -831,4 +831,14 @@ test_expect_success !MINGW,!CYGWIN 'correct handling of backslashes' '
        test_cmp err.expect err
 '
 
+test_expect_success 'info/exclude trumps core.excludesfile' '
+       echo >>global-excludes usually-ignored &&
+       echo >>.git/info/exclude "!usually-ignored" &&
+       >usually-ignored &&
+       echo "?? usually-ignored" >expect &&
+
+       git status --porcelain usually-ignored >actual &&
+       test_cmp expect actual
+'
+
 test_done
index ca7d2a630a8442d8812b444708d6f28f2e45fb32..e0200b9f338f0478fd55029eab9c32c6b7956476 100755 (executable)
@@ -204,6 +204,16 @@ test_expect_success 'filtering large input to small output should use little mem
        GIT_MMAP_LIMIT=1m GIT_ALLOC_LIMIT=1m git add 30MB
 '
 
+test_expect_success 'filter that does not read is fine' '
+       test-genrandom foo $((128 * 1024 + 1)) >big &&
+       echo "big filter=epipe" >.gitattributes &&
+       git config filter.epipe.clean "echo xyzzy" &&
+       git add big &&
+       git cat-file blob :big >actual &&
+       echo xyzzy >expect &&
+       test_cmp expect actual
+'
+
 test_expect_success EXPENSIVE 'filter large file' '
        git config filter.largefile.smudge cat &&
        git config filter.largefile.clean cat &&
index 452320df8391580fbc1d7112c45e1758691a0c16..1a56e5e82ee807895da0d597ab75c10cb0299082 100755 (executable)
@@ -57,28 +57,35 @@ create_gitattributes () {
 
 check_warning () {
        case "$1" in
-       LF_CRLF) grep "LF will be replaced by CRLF" $2;;
-       CRLF_LF) grep "CRLF will be replaced by LF" $2;;
-       '')
-               >expect
-               grep "will be replaced by" $2 >actual
-               test_cmp expect actual
-               ;;
-       *) false ;;
+       LF_CRLF) echo "warning: LF will be replaced by CRLF" >"$2".expect ;;
+       CRLF_LF) echo "warning: CRLF will be replaced by LF" >"$2".expect ;;
+       '')                                                      >"$2".expect ;;
+       *) echo >&2 "Illegal 1": "$1" ; return false ;;
        esac
+       grep "will be replaced by" "$2" | sed -e "s/\(.*\) in [^ ]*$/\1/" >"$2".actual
+       test_cmp "$2".expect "$2".actual
 }
 
-create_file_in_repo () {
+commit_check_warn () {
        crlf=$1
        attr=$2
        lfname=$3
        crlfname=$4
-       lfmixcrlf=$5
-       lfmixcr=$6
-       crlfnul=$7
-       create_gitattributes "$attr" &&
+       repoMIX=$5
+       lfmixcrlf=$6
+       lfmixcr=$7
+       crlfnul=$8
        pfx=crlf_${crlf}_attr_${attr}
-       for f in LF CRLF LF_mix_CR CRLF_mix_LF CRLF_nul
+       # Special handling for repoMIX: It should already be in the repo
+       # with CRLF
+       f=repoMIX
+       fname=${pfx}_$f.txt
+       echo >.gitattributes &&
+       cp $f $fname &&
+       git -c core.autocrlf=false add $fname 2>"${pfx}_$f.err" &&
+       git commit -m "repoMIX" &&
+       create_gitattributes "$attr" &&
+       for f in LF CRLF repoMIX LF_mix_CR CRLF_mix_LF LF_nul CRLF_nul
        do
                fname=${pfx}_$f.txt &&
                cp $f $fname &&
@@ -109,7 +116,7 @@ check_files_in_repo () {
 }
 
 
-check_files_in_ws () {
+checkout_files () {
        eol=$1
        crlf=$2
        attr=$3
@@ -122,7 +129,7 @@ check_files_in_ws () {
        git config core.autocrlf $crlf &&
        pfx=eol_${eol}_crlf_${crlf}_attr_${attr}_ &&
        src=crlf_false_attr__ &&
-       for f in LF CRLF LF_mix_CR CRLF_mix_LF CRLF_nul
+       for f in LF CRLF LF_mix_CR CRLF_mix_LF LF_nul
        do
                rm $src$f.txt &&
                if test -z "$eol"; then
@@ -144,8 +151,8 @@ check_files_in_ws () {
        test_expect_success "checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$attr file=LF_mix_CR" "
                compare_ws_file $pfx $lfmixcr   ${src}LF_mix_CR.txt
        "
-       test_expect_success "checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$attr file=CRLF_nul" "
-               compare_ws_file $pfx $crlfnul   ${src}CRLF_nul.txt
+       test_expect_success "checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$attr file=LF_nul" "
+               compare_ws_file $pfx $crlfnul   ${src}LF_nul.txt
        "
 }
 
@@ -157,6 +164,7 @@ test_expect_success 'setup master' '
        git commit -m "add .gitattributes" "" &&
        printf "line1\nline2\nline3"     >LF &&
        printf "line1\r\nline2\r\nline3" >CRLF &&
+       printf "line1\r\nline2\nline3"   >repoMIX &&
        printf "line1\r\nline2\nline3"   >CRLF_mix_LF &&
        printf "line1\nline2\rline3"     >LF_mix_CR &&
        printf "line1\r\nline2\rline3"   >CRLF_mix_CR &&
@@ -169,40 +177,55 @@ test_expect_success 'setup master' '
 warn_LF_CRLF="LF will be replaced by CRLF"
 warn_CRLF_LF="CRLF will be replaced by LF"
 
-test_expect_success 'add files empty attr' '
-       create_file_in_repo false ""     ""        ""        ""        ""        "" &&
-       create_file_in_repo true  ""     "LF_CRLF" ""        "LF_CRLF" ""        "" &&
-       create_file_in_repo input ""     ""        "CRLF_LF" "CRLF_LF" ""        ""
+# WILC stands for "Warn if (this OS) converts LF into CRLF".
+# WICL: Warn if CRLF becomes LF
+# WAMIX: Mixed line endings: either CRLF->LF or LF->CRLF
+if test_have_prereq NATIVE_CRLF
+then
+       WILC=LF_CRLF
+       WICL=
+       WAMIX=LF_CRLF
+else
+       WILC=
+       WICL=CRLF_LF
+       WAMIX=CRLF_LF
+fi
+
+#                         attr   LF        CRLF      repoMIX   CRLFmixLF LFmixCR   CRLFNUL
+test_expect_success 'commit files empty attr' '
+       commit_check_warn false ""     ""        ""        ""        ""        ""        "" &&
+       commit_check_warn true  ""     "LF_CRLF" ""        "LF_CRLF" "LF_CRLF" ""        "" &&
+       commit_check_warn input ""     ""        "CRLF_LF" "CRLF_LF" "CRLF_LF" ""        ""
 '
 
-test_expect_success 'add files attr=auto' '
-       create_file_in_repo false "auto" ""        "CRLF_LF" "CRLF_LF" ""        "" &&
-       create_file_in_repo true  "auto" "LF_CRLF" ""        "LF_CRLF" ""        "" &&
-       create_file_in_repo input "auto" ""        "CRLF_LF" "CRLF_LF" ""        ""
+test_expect_success 'commit files attr=auto' '
+       commit_check_warn false "auto" "$WILC"   "$WICL"   "$WAMIX"  "$WAMIX"  ""        "" &&
+       commit_check_warn true  "auto" "LF_CRLF" ""        "LF_CRLF" "LF_CRLF" ""        "" &&
+       commit_check_warn input "auto" ""        "CRLF_LF" "CRLF_LF" "CRLF_LF" ""        ""
 '
 
-test_expect_success 'add files attr=text' '
-       create_file_in_repo false "text" ""        "CRLF_LF" "CRLF_LF" ""        "CRLF_LF" &&
-       create_file_in_repo true  "text" "LF_CRLF" ""        "LF_CRLF" "LF_CRLF" ""        &&
-       create_file_in_repo input "text" ""        "CRLF_LF" "CRLF_LF" ""        "CRLF_LF"
+test_expect_success 'commit files attr=text' '
+       commit_check_warn false "text" "$WILC"   "$WICL"   "$WAMIX"  "$WAMIX"  "$WILC"   "$WICL"   &&
+       commit_check_warn true  "text" "LF_CRLF" ""        "LF_CRLF" "LF_CRLF" "LF_CRLF" ""        &&
+       commit_check_warn input "text" ""        "CRLF_LF" "CRLF_LF" "CRLF_LF" ""        "CRLF_LF"
 '
 
-test_expect_success 'add files attr=-text' '
-       create_file_in_repo false "-text" ""       ""        ""        ""        "" &&
-       create_file_in_repo true  "-text" ""       ""        ""        ""        "" &&
-       create_file_in_repo input "-text" ""       ""        ""        ""        ""
+test_expect_success 'commit files attr=-text' '
+       commit_check_warn false "-text" ""       ""        ""        ""        ""        "" &&
+       commit_check_warn true  "-text" ""       ""        ""        ""        ""        "" &&
+       commit_check_warn input "-text" ""       ""        ""        ""        ""        ""
 '
 
-test_expect_success 'add files attr=lf' '
-       create_file_in_repo false "lf"    ""       "CRLF_LF" "CRLF_LF"  ""       "CRLF_LF" &&
-       create_file_in_repo true  "lf"    ""       "CRLF_LF" "CRLF_LF"  ""       "CRLF_LF" &&
-       create_file_in_repo input "lf"    ""       "CRLF_LF" "CRLF_LF"  ""       "CRLF_LF"
+test_expect_success 'commit files attr=lf' '
+       commit_check_warn false "lf"    ""       "CRLF_LF" "CRLF_LF" "CRLF_LF"  ""       "CRLF_LF" &&
+       commit_check_warn true  "lf"    ""       "CRLF_LF" "CRLF_LF" "CRLF_LF"  ""       "CRLF_LF" &&
+       commit_check_warn input "lf"    ""       "CRLF_LF" "CRLF_LF" "CRLF_LF"  ""       "CRLF_LF"
 '
 
-test_expect_success 'add files attr=crlf' '
-       create_file_in_repo false "crlf" "LF_CRLF" ""        "LF_CRLF" "LF_CRLF" "" &&
-       create_file_in_repo true  "crlf" "LF_CRLF" ""        "LF_CRLF" "LF_CRLF" "" &&
-       create_file_in_repo input "crlf" "LF_CRLF" ""        "LF_CRLF" "LF_CRLF" ""
+test_expect_success 'commit files attr=crlf' '
+       commit_check_warn false "crlf" "LF_CRLF" ""        "LF_CRLF" "LF_CRLF" "LF_CRLF" "" &&
+       commit_check_warn true  "crlf" "LF_CRLF" ""        "LF_CRLF" "LF_CRLF" "LF_CRLF" "" &&
+       commit_check_warn input "crlf" "LF_CRLF" ""        "LF_CRLF" "LF_CRLF" "LF_CRLF" ""
 '
 
 test_expect_success 'create files cleanup' '
@@ -237,7 +260,7 @@ test_expect_success 'commit -text' '
 ################################################################################
 # Check how files in the repo are changed when they are checked out
 # How to read the table below:
-# - check_files_in_ws will check multiple files with a combination of settings
+# - checkout_files will check multiple files with a combination of settings
 #   and attributes (core.autocrlf=input is forbidden with core.eol=crlf)
 # - parameter $1 : core.eol               lf | crlf
 # - parameter $2 : core.autocrlf          false | true | input
@@ -249,87 +272,89 @@ test_expect_success 'commit -text' '
 # - parameter $8 : reference for a file with CRLF and a NUL (should be handled as binary when auto)
 
 #                                            What we have in the repo:
-#                                                                                                                               ----------------- EOL in repo ----------------
-#                                                                                                                               LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
+#                                            ----------------- EOL in repo ----------------
+#                                            LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
 #                   settings with checkout:
 #                   core.   core.   .gitattr
 #                    eol     acrlf
 #                                            ----------------------------------------------
 #                                            What we want to have in the working tree:
-if test_have_prereq MINGW
+if test_have_prereq NATIVE_CRLF
 then
 MIX_CRLF_LF=CRLF
 MIX_LF_CR=CRLF_mix_CR
 NL=CRLF
+LFNUL=CRLF_nul
 else
 MIX_CRLF_LF=CRLF_mix_LF
 MIX_LF_CR=LF_mix_CR
 NL=LF
+LFNUL=LF_nul
 fi
 export CRLF_MIX_LF_CR MIX NL
 
-check_files_in_ws    lf      false  ""       LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
-check_files_in_ws    lf      true   ""       CRLF  CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
-check_files_in_ws    lf      input  ""       LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
-check_files_in_ws    lf      false "auto"    LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
-check_files_in_ws    lf      true  "auto"    CRLF  CRLF  CRLF         LF_mix_CR    CRLF_nul
-check_files_in_ws    lf      input "auto"    LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
-check_files_in_ws    lf      false "text"    LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
-check_files_in_ws    lf      true  "text"    CRLF  CRLF  CRLF         CRLF_mix_CR  CRLF_nul
-check_files_in_ws    lf      input "text"    LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
-check_files_in_ws    lf      false "-text"   LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
-check_files_in_ws    lf      true  "-text"   LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
-check_files_in_ws    lf      input "-text"   LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
-check_files_in_ws    lf      false "lf"      LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
-check_files_in_ws    lf      true  "lf"      LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
-check_files_in_ws    lf      input "lf"      LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
-check_files_in_ws    lf      false "crlf"    CRLF  CRLF  CRLF         CRLF_mix_CR  CRLF_nul
-check_files_in_ws    lf      true  "crlf"    CRLF  CRLF  CRLF         CRLF_mix_CR  CRLF_nul
-check_files_in_ws    lf      input "crlf"    CRLF  CRLF  CRLF         CRLF_mix_CR  CRLF_nul
-
-check_files_in_ws    crlf    false  ""       LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
-check_files_in_ws    crlf    true   ""       CRLF  CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
-check_files_in_ws    crlf    false "auto"    CRLF  CRLF  CRLF         LF_mix_CR    CRLF_nul
-check_files_in_ws    crlf    true  "auto"    CRLF  CRLF  CRLF         LF_mix_CR    CRLF_nul
-check_files_in_ws    crlf    false "text"    CRLF  CRLF  CRLF         CRLF_mix_CR  CRLF_nul
-check_files_in_ws    crlf    true  "text"    CRLF  CRLF  CRLF         CRLF_mix_CR  CRLF_nul
-check_files_in_ws    crlf    false "-text"   LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
-check_files_in_ws    crlf    true  "-text"   LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
-check_files_in_ws    crlf    false "lf"      LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
-check_files_in_ws    crlf    true  "lf"      LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
-check_files_in_ws    crlf    false "crlf"    CRLF  CRLF  CRLF         CRLF_mix_CR  CRLF_nul
-check_files_in_ws    crlf    true  "crlf"    CRLF  CRLF  CRLF         CRLF_mix_CR  CRLF_nul
-
-check_files_in_ws    ""      false  ""       LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
-check_files_in_ws    ""      true   ""       CRLF  CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
-check_files_in_ws    ""      input  ""       LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
-check_files_in_ws    ""      false "auto"    $NL   CRLF  $MIX_CRLF_LF LF_mix_CR    CRLF_nul
-check_files_in_ws    ""      true  "auto"    CRLF  CRLF  CRLF         LF_mix_CR    CRLF_nul
-check_files_in_ws    ""      input "auto"    LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
-check_files_in_ws    ""      false "text"    $NL   CRLF  $MIX_CRLF_LF $MIX_LF_CR   CRLF_nul
-check_files_in_ws    ""      true  "text"    CRLF  CRLF  CRLF         CRLF_mix_CR  CRLF_nul
-check_files_in_ws    ""      input "text"    LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
-check_files_in_ws    ""      false "-text"   LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
-check_files_in_ws    ""      true  "-text"   LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
-check_files_in_ws    ""      input "-text"   LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
-check_files_in_ws    ""      false "lf"      LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
-check_files_in_ws    ""      true  "lf"      LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
-check_files_in_ws    ""      input "lf"      LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
-check_files_in_ws    ""      false "crlf"    CRLF  CRLF  CRLF         CRLF_mix_CR  CRLF_nul
-check_files_in_ws    ""      true  "crlf"    CRLF  CRLF  CRLF         CRLF_mix_CR  CRLF_nul
-check_files_in_ws    ""      input "crlf"    CRLF  CRLF  CRLF         CRLF_mix_CR  CRLF_nul
-
-check_files_in_ws    native  false  ""       LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
-check_files_in_ws    native  true   ""       CRLF  CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
-check_files_in_ws    native  false "auto"    $NL   CRLF  $MIX_CRLF_LF LF_mix_CR    CRLF_nul
-check_files_in_ws    native  true  "auto"    CRLF  CRLF  CRLF         LF_mix_CR    CRLF_nul
-check_files_in_ws    native  false "text"    $NL   CRLF  $MIX_CRLF_LF $MIX_LF_CR   CRLF_nul
-check_files_in_ws    native  true  "text"    CRLF  CRLF  CRLF         CRLF_mix_CR  CRLF_nul
-check_files_in_ws    native  false "-text"   LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
-check_files_in_ws    native  true  "-text"   LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
-check_files_in_ws    native  false "lf"      LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
-check_files_in_ws    native  true  "lf"      LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
-check_files_in_ws    native  false "crlf"    CRLF  CRLF  CRLF         CRLF_mix_CR  CRLF_nul
-check_files_in_ws    native  true  "crlf"    CRLF  CRLF  CRLF         CRLF_mix_CR  CRLF_nul
+checkout_files    lf      false  ""       LF    CRLF  CRLF_mix_LF  LF_mix_CR    LF_nul
+checkout_files    lf      true   ""       CRLF  CRLF  CRLF_mix_LF  LF_mix_CR    LF_nul
+checkout_files    lf      input  ""       LF    CRLF  CRLF_mix_LF  LF_mix_CR    LF_nul
+checkout_files    lf      false "auto"    LF    CRLF  CRLF_mix_LF  LF_mix_CR    LF_nul
+checkout_files    lf      true  "auto"    CRLF  CRLF  CRLF         LF_mix_CR    LF_nul
+checkout_files    lf      input "auto"    LF    CRLF  CRLF_mix_LF  LF_mix_CR    LF_nul
+checkout_files    lf      false "text"    LF    CRLF  CRLF_mix_LF  LF_mix_CR    LF_nul
+checkout_files    lf      true  "text"    CRLF  CRLF  CRLF         CRLF_mix_CR  CRLF_nul
+checkout_files    lf      input "text"    LF    CRLF  CRLF_mix_LF  LF_mix_CR    LF_nul
+checkout_files    lf      false "-text"   LF    CRLF  CRLF_mix_LF  LF_mix_CR    LF_nul
+checkout_files    lf      true  "-text"   LF    CRLF  CRLF_mix_LF  LF_mix_CR    LF_nul
+checkout_files    lf      input "-text"   LF    CRLF  CRLF_mix_LF  LF_mix_CR    LF_nul
+checkout_files    lf      false "lf"      LF    CRLF  CRLF_mix_LF  LF_mix_CR    LF_nul
+checkout_files    lf      true  "lf"      LF    CRLF  CRLF_mix_LF  LF_mix_CR    LF_nul
+checkout_files    lf      input "lf"      LF    CRLF  CRLF_mix_LF  LF_mix_CR    LF_nul
+checkout_files    lf      false "crlf"    CRLF  CRLF  CRLF         CRLF_mix_CR  CRLF_nul
+checkout_files    lf      true  "crlf"    CRLF  CRLF  CRLF         CRLF_mix_CR  CRLF_nul
+checkout_files    lf      input "crlf"    CRLF  CRLF  CRLF         CRLF_mix_CR  CRLF_nul
+
+checkout_files    crlf    false  ""       LF    CRLF  CRLF_mix_LF  LF_mix_CR    LF_nul
+checkout_files    crlf    true   ""       CRLF  CRLF  CRLF_mix_LF  LF_mix_CR    LF_nul
+checkout_files    crlf    false "auto"    CRLF  CRLF  CRLF         LF_mix_CR    LF_nul
+checkout_files    crlf    true  "auto"    CRLF  CRLF  CRLF         LF_mix_CR    LF_nul
+checkout_files    crlf    false "text"    CRLF  CRLF  CRLF         CRLF_mix_CR  CRLF_nul
+checkout_files    crlf    true  "text"    CRLF  CRLF  CRLF         CRLF_mix_CR  CRLF_nul
+checkout_files    crlf    false "-text"   LF    CRLF  CRLF_mix_LF  LF_mix_CR    LF_nul
+checkout_files    crlf    true  "-text"   LF    CRLF  CRLF_mix_LF  LF_mix_CR    LF_nul
+checkout_files    crlf    false "lf"      LF    CRLF  CRLF_mix_LF  LF_mix_CR    LF_nul
+checkout_files    crlf    true  "lf"      LF    CRLF  CRLF_mix_LF  LF_mix_CR    LF_nul
+checkout_files    crlf    false "crlf"    CRLF  CRLF  CRLF         CRLF_mix_CR  CRLF_nul
+checkout_files    crlf    true  "crlf"    CRLF  CRLF  CRLF         CRLF_mix_CR  CRLF_nul
+
+checkout_files    ""      false  ""       LF    CRLF  CRLF_mix_LF  LF_mix_CR    LF_nul
+checkout_files    ""      true   ""       CRLF  CRLF  CRLF_mix_LF  LF_mix_CR    LF_nul
+checkout_files    ""      input  ""       LF    CRLF  CRLF_mix_LF  LF_mix_CR    LF_nul
+checkout_files    ""      false "auto"    $NL   CRLF  $MIX_CRLF_LF LF_mix_CR    LF_nul
+checkout_files    ""      true  "auto"    CRLF  CRLF  CRLF         LF_mix_CR    LF_nul
+checkout_files    ""      input "auto"    LF    CRLF  CRLF_mix_LF  LF_mix_CR    LF_nul
+checkout_files    ""      false "text"    $NL   CRLF  $MIX_CRLF_LF $MIX_LF_CR   $LFNUL
+checkout_files    ""      true  "text"    CRLF  CRLF  CRLF         CRLF_mix_CR  CRLF_nul
+checkout_files    ""      input "text"    LF    CRLF  CRLF_mix_LF  LF_mix_CR    LF_nul
+checkout_files    ""      false "-text"   LF    CRLF  CRLF_mix_LF  LF_mix_CR    LF_nul
+checkout_files    ""      true  "-text"   LF    CRLF  CRLF_mix_LF  LF_mix_CR    LF_nul
+checkout_files    ""      input "-text"   LF    CRLF  CRLF_mix_LF  LF_mix_CR    LF_nul
+checkout_files    ""      false "lf"      LF    CRLF  CRLF_mix_LF  LF_mix_CR    LF_nul
+checkout_files    ""      true  "lf"      LF    CRLF  CRLF_mix_LF  LF_mix_CR    LF_nul
+checkout_files    ""      input "lf"      LF    CRLF  CRLF_mix_LF  LF_mix_CR    LF_nul
+checkout_files    ""      false "crlf"    CRLF  CRLF  CRLF         CRLF_mix_CR  CRLF_nul
+checkout_files    ""      true  "crlf"    CRLF  CRLF  CRLF         CRLF_mix_CR  CRLF_nul
+checkout_files    ""      input "crlf"    CRLF  CRLF  CRLF         CRLF_mix_CR  CRLF_nul
+
+checkout_files    native  false  ""       LF    CRLF  CRLF_mix_LF  LF_mix_CR    LF_nul
+checkout_files    native  true   ""       CRLF  CRLF  CRLF_mix_LF  LF_mix_CR    LF_nul
+checkout_files    native  false "auto"    $NL   CRLF  $MIX_CRLF_LF LF_mix_CR    LF_nul
+checkout_files    native  true  "auto"    CRLF  CRLF  CRLF         LF_mix_CR    LF_nul
+checkout_files    native  false "text"    $NL   CRLF  $MIX_CRLF_LF $MIX_LF_CR   $LFNUL
+checkout_files    native  true  "text"    CRLF  CRLF  CRLF         CRLF_mix_CR  CRLF_nul
+checkout_files    native  false "-text"   LF    CRLF  CRLF_mix_LF  LF_mix_CR    LF_nul
+checkout_files    native  true  "-text"   LF    CRLF  CRLF_mix_LF  LF_mix_CR    LF_nul
+checkout_files    native  false "lf"      LF    CRLF  CRLF_mix_LF  LF_mix_CR    LF_nul
+checkout_files    native  true  "lf"      LF    CRLF  CRLF_mix_LF  LF_mix_CR    LF_nul
+checkout_files    native  false "crlf"    CRLF  CRLF  CRLF         CRLF_mix_CR  CRLF_nul
+checkout_files    native  true  "crlf"    CRLF  CRLF  CRLF         CRLF_mix_CR  CRLF_nul
 
 test_done
index c0143a0a70b7d3dc213b691aecea6b3fffbc5844..93605f42f27cef9ef3ffe381c84aea9f6f4be426 100755 (executable)
@@ -19,6 +19,14 @@ relative_path() {
        "test \"\$(test-path-utils relative_path '$1' '$2')\" = '$expected'"
 }
 
+test_git_path() {
+       test_expect_success "git-path $1 $2 => $3" "
+               $1 git rev-parse --git-path $2 >actual &&
+               echo $3 >expect &&
+               test_cmp expect actual
+       "
+}
+
 # On Windows, we are using MSYS's bash, which mangles the paths.
 # Absolute paths are anchored at the MSYS installation directory,
 # which means that the path / accounts for this many characters:
@@ -244,4 +252,32 @@ relative_path "<null>"             "<empty>"       ./
 relative_path "<null>"         "<null>"        ./
 relative_path "<null>"         /foo/a/b        ./
 
+test_git_path A=B                info/grafts .git/info/grafts
+test_git_path GIT_GRAFT_FILE=foo info/grafts foo
+test_git_path GIT_GRAFT_FILE=foo info/////grafts foo
+test_git_path GIT_INDEX_FILE=foo index foo
+test_git_path GIT_INDEX_FILE=foo index/foo .git/index/foo
+test_git_path GIT_INDEX_FILE=foo index2 .git/index2
+test_expect_success 'setup fake objects directory foo' 'mkdir foo'
+test_git_path GIT_OBJECT_DIRECTORY=foo objects foo
+test_git_path GIT_OBJECT_DIRECTORY=foo objects/foo foo/foo
+test_git_path GIT_OBJECT_DIRECTORY=foo objects2 .git/objects2
+test_expect_success 'setup common repository' 'git --git-dir=bar init'
+test_git_path GIT_COMMON_DIR=bar index                    .git/index
+test_git_path GIT_COMMON_DIR=bar HEAD                     .git/HEAD
+test_git_path GIT_COMMON_DIR=bar logs/HEAD                .git/logs/HEAD
+test_git_path GIT_COMMON_DIR=bar objects                  bar/objects
+test_git_path GIT_COMMON_DIR=bar objects/bar              bar/objects/bar
+test_git_path GIT_COMMON_DIR=bar info/exclude             bar/info/exclude
+test_git_path GIT_COMMON_DIR=bar info/grafts              bar/info/grafts
+test_git_path GIT_COMMON_DIR=bar info/sparse-checkout     .git/info/sparse-checkout
+test_git_path GIT_COMMON_DIR=bar remotes/bar              bar/remotes/bar
+test_git_path GIT_COMMON_DIR=bar branches/bar             bar/branches/bar
+test_git_path GIT_COMMON_DIR=bar logs/refs/heads/master   bar/logs/refs/heads/master
+test_git_path GIT_COMMON_DIR=bar refs/heads/master        bar/refs/heads/master
+test_git_path GIT_COMMON_DIR=bar hooks/me                 bar/hooks/me
+test_git_path GIT_COMMON_DIR=bar config                   bar/config
+test_git_path GIT_COMMON_DIR=bar packed-refs              bar/packed-refs
+test_git_path GIT_COMMON_DIR=bar shallow                  bar/shallow
+
 test_done
index f61b40c69ba04f6ee364356751c6f21a59552aff..0979df93a1062020e92fa55a780678e20db4f9db 100755 (executable)
@@ -6,4 +6,118 @@ test_description='credential-store tests'
 
 helper_test store
 
+test_expect_success 'when xdg file does not exist, xdg file not created' '
+       test_path_is_missing "$HOME/.config/git/credentials" &&
+       test -s "$HOME/.git-credentials"
+'
+
+test_expect_success 'setup xdg file' '
+       rm -f "$HOME/.git-credentials" &&
+       mkdir -p "$HOME/.config/git" &&
+       >"$HOME/.config/git/credentials"
+'
+
+helper_test store
+
+test_expect_success 'when xdg file exists, home file not created' '
+       test -s "$HOME/.config/git/credentials" &&
+       test_path_is_missing "$HOME/.git-credentials"
+'
+
+test_expect_success 'setup custom xdg file' '
+       rm -f "$HOME/.git-credentials" &&
+       rm -f "$HOME/.config/git/credentials" &&
+       mkdir -p "$HOME/xdg/git" &&
+       >"$HOME/xdg/git/credentials"
+'
+
+XDG_CONFIG_HOME="$HOME/xdg"
+export XDG_CONFIG_HOME
+helper_test store
+unset XDG_CONFIG_HOME
+
+test_expect_success 'if custom xdg file exists, home and xdg files not created' '
+       test_when_finished "rm -f $HOME/xdg/git/credentials" &&
+       test -s "$HOME/xdg/git/credentials" &&
+       test_path_is_missing "$HOME/.git-credentials" &&
+       test_path_is_missing "$HOME/.config/git/credentials"
+'
+
+test_expect_success 'get: use home file if both home and xdg files have matches' '
+       echo "https://home-user:home-pass@example.com" >"$HOME/.git-credentials" &&
+       mkdir -p "$HOME/.config/git" &&
+       echo "https://xdg-user:xdg-pass@example.com" >"$HOME/.config/git/credentials" &&
+       check fill store <<-\EOF
+       protocol=https
+       host=example.com
+       --
+       protocol=https
+       host=example.com
+       username=home-user
+       password=home-pass
+       --
+       EOF
+'
+
+test_expect_success 'get: use xdg file if home file has no matches' '
+       >"$HOME/.git-credentials" &&
+       mkdir -p "$HOME/.config/git" &&
+       echo "https://xdg-user:xdg-pass@example.com" >"$HOME/.config/git/credentials" &&
+       check fill store <<-\EOF
+       protocol=https
+       host=example.com
+       --
+       protocol=https
+       host=example.com
+       username=xdg-user
+       password=xdg-pass
+       --
+       EOF
+'
+
+test_expect_success POSIXPERM 'get: use xdg file if home file is unreadable' '
+       echo "https://home-user:home-pass@example.com" >"$HOME/.git-credentials" &&
+       chmod -r "$HOME/.git-credentials" &&
+       mkdir -p "$HOME/.config/git" &&
+       echo "https://xdg-user:xdg-pass@example.com" >"$HOME/.config/git/credentials" &&
+       check fill store <<-\EOF
+       protocol=https
+       host=example.com
+       --
+       protocol=https
+       host=example.com
+       username=xdg-user
+       password=xdg-pass
+       --
+       EOF
+'
+
+test_expect_success 'store: if both xdg and home files exist, only store in home file' '
+       >"$HOME/.git-credentials" &&
+       mkdir -p "$HOME/.config/git" &&
+       >"$HOME/.config/git/credentials" &&
+       check approve store <<-\EOF &&
+       protocol=https
+       host=example.com
+       username=store-user
+       password=store-pass
+       EOF
+       echo "https://store-user:store-pass@example.com" >expected &&
+       test_cmp expected "$HOME/.git-credentials" &&
+       test_must_be_empty "$HOME/.config/git/credentials"
+'
+
+
+test_expect_success 'erase: erase matching credentials from both xdg and home files' '
+       echo "https://home-user:home-pass@example.com" >"$HOME/.git-credentials" &&
+       mkdir -p "$HOME/.config/git" &&
+       echo "https://xdg-user:xdg-pass@example.com" >"$HOME/.config/git/credentials" &&
+       check reject store <<-\EOF &&
+       protocol=https
+       host=example.com
+       EOF
+       test_must_be_empty "$HOME/.git-credentials" &&
+       test_must_be_empty "$HOME/.config/git/credentials"
+'
+
 test_done
index ab36b1eb72ffc4a54240b37e908cc994756f2f26..4f225db9a72729e99f5eaab0b81ec579691b34c7 100755 (executable)
@@ -47,6 +47,18 @@ $content"
        test_cmp expect actual
     '
 
+    test_expect_success "Type of $type is correct using --allow-unknown-type" '
+       echo $type >expect &&
+       git cat-file -t --allow-unknown-type $sha1 >actual &&
+       test_cmp expect actual
+    '
+
+    test_expect_success "Size of $type is correct using --allow-unknown-type" '
+       echo $size >expect &&
+       git cat-file -s --allow-unknown-type $sha1 >actual &&
+       test_cmp expect actual
+    '
+
     test -z "$content" ||
     test_expect_success "Content of $type is correct" '
        maybe_remove_timestamp "$content" $no_ts >expect &&
@@ -296,4 +308,37 @@ test_expect_success '%(deltabase) reports packed delta bases' '
        }
 '
 
+bogus_type="bogus"
+bogus_content="bogus"
+bogus_size=$(strlen "$bogus_content")
+bogus_sha1=$(echo_without_newline "$bogus_content" | git hash-object -t $bogus_type --literally -w --stdin)
+
+test_expect_success "Type of broken object is correct" '
+       echo $bogus_type >expect &&
+       git cat-file -t --allow-unknown-type $bogus_sha1 >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success "Size of broken object is correct" '
+       echo $bogus_size >expect &&
+       git cat-file -s --allow-unknown-type $bogus_sha1 >actual &&
+       test_cmp expect actual
+'
+bogus_type="abcdefghijklmnopqrstuvwxyz1234679"
+bogus_content="bogus"
+bogus_size=$(strlen "$bogus_content")
+bogus_sha1=$(echo_without_newline "$bogus_content" | git hash-object -t $bogus_type --literally -w --stdin)
+
+test_expect_success "Type of broken object is correct when type is large" '
+       echo $bogus_type >expect &&
+       git cat-file -t --allow-unknown-type $bogus_sha1 >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success "Size of large broken object is correct when type is large" '
+       echo $bogus_size >expect &&
+       git cat-file -s --allow-unknown-type $bogus_sha1 >actual &&
+       test_cmp expect actual
+'
+
 test_done
index 2edb4f2de5cc32d0f8847790d06a8de0c98d99c3..8e22b03cdd132bd54f9db44d362c15d129415651 100755 (executable)
@@ -162,16 +162,20 @@ test_expect_success 'no file/rev ambiguity check inside .git' '
        )
 '
 
-test_expect_success 'no file/rev ambiguity check inside a bare repo' '
+test_expect_success 'no file/rev ambiguity check inside a bare repo (explicit GIT_DIR)' '
+       test_when_finished "rm -fr foo.git" &&
        git clone -s --bare .git foo.git &&
        (
                cd foo.git &&
+               # older Git needed help by exporting GIT_DIR=.
+               # to realize that it is inside a bare repository.
+               # We keep this test around for regression testing.
                GIT_DIR=. git show -s HEAD
        )
 '
 
-# This still does not work as it should...
-: test_expect_success 'no file/rev ambiguity check inside a bare repo' '
+test_expect_success 'no file/rev ambiguity check inside a bare repo' '
+       test_when_finished "rm -fr foo.git" &&
        git clone -s --bare .git foo.git &&
        (
                cd foo.git &&
@@ -180,7 +184,6 @@ test_expect_success 'no file/rev ambiguity check inside a bare repo' '
 '
 
 test_expect_success SYMLINKS 'detection should not be fooled by a symlink' '
-       rm -fr foo.git &&
        git clone -s .git another &&
        ln -s another yetanother &&
        (
index 6805b9e6bb5b7e6a6b6b9546e96023ebeb557bd0..ba89f4c00959112b2cfc0efaff94f3447df32357 100755 (executable)
@@ -519,7 +519,7 @@ test_expect_success 'stdin create ref works with path with space to blob' '
 test_expect_success 'stdin update ref fails with wrong old value' '
        echo "update $c $m $m~1" >stdin &&
        test_must_fail git update-ref --stdin <stdin 2>err &&
-       grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err &&
+       grep "fatal: Cannot lock ref '"'"'$c'"'"'" err &&
        test_must_fail git rev-parse --verify -q $c
 '
 
@@ -555,7 +555,7 @@ test_expect_success 'stdin update ref works with right old value' '
 test_expect_success 'stdin delete ref fails with wrong old value' '
        echo "delete $a $m~1" >stdin &&
        test_must_fail git update-ref --stdin <stdin 2>err &&
-       grep "fatal: Cannot lock the ref '"'"'$a'"'"'" err &&
+       grep "fatal: Cannot lock ref '"'"'$a'"'"'" err &&
        git rev-parse $m >expect &&
        git rev-parse $a >actual &&
        test_cmp expect actual
@@ -688,7 +688,7 @@ test_expect_success 'stdin update refs fails with wrong old value' '
        update $c  ''
        EOF
        test_must_fail git update-ref --stdin <stdin 2>err &&
-       grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err &&
+       grep "fatal: Cannot lock ref '"'"'$c'"'"'" err &&
        git rev-parse $m >expect &&
        git rev-parse $a >actual &&
        test_cmp expect actual &&
@@ -883,7 +883,7 @@ test_expect_success 'stdin -z create ref works with path with space to blob' '
 test_expect_success 'stdin -z update ref fails with wrong old value' '
        printf $F "update $c" "$m" "$m~1" >stdin &&
        test_must_fail git update-ref -z --stdin <stdin 2>err &&
-       grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err &&
+       grep "fatal: Cannot lock ref '"'"'$c'"'"'" err &&
        test_must_fail git rev-parse --verify -q $c
 '
 
@@ -899,7 +899,7 @@ test_expect_success 'stdin -z create ref fails when ref exists' '
        git rev-parse "$c" >expect &&
        printf $F "create $c" "$m~1" >stdin &&
        test_must_fail git update-ref -z --stdin <stdin 2>err &&
-       grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err &&
+       grep "fatal: Cannot lock ref '"'"'$c'"'"'" err &&
        git rev-parse "$c" >actual &&
        test_cmp expect actual
 '
@@ -930,7 +930,7 @@ test_expect_success 'stdin -z update ref works with right old value' '
 test_expect_success 'stdin -z delete ref fails with wrong old value' '
        printf $F "delete $a" "$m~1" >stdin &&
        test_must_fail git update-ref -z --stdin <stdin 2>err &&
-       grep "fatal: Cannot lock the ref '"'"'$a'"'"'" err &&
+       grep "fatal: Cannot lock ref '"'"'$a'"'"'" err &&
        git rev-parse $m >expect &&
        git rev-parse $a >actual &&
        test_cmp expect actual
@@ -1045,7 +1045,7 @@ 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" "$m" "$Z" >stdin &&
        test_must_fail git update-ref -z --stdin <stdin 2>err &&
-       grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err &&
+       grep "fatal: Cannot lock ref '"'"'$c'"'"'" err &&
        git rev-parse $m >expect &&
        git rev-parse $a >actual &&
        test_cmp expect actual &&
@@ -1065,4 +1065,32 @@ test_expect_success 'stdin -z delete refs works with packed and loose refs' '
        test_must_fail git rev-parse --verify -q $c
 '
 
+run_with_limited_open_files () {
+       (ulimit -n 32 && "$@")
+}
+
+test_lazy_prereq ULIMIT_FILE_DESCRIPTORS 'run_with_limited_open_files true'
+
+test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction creating branches does not burst open file limit' '
+(
+       for i in $(test_seq 33)
+       do
+               echo "create refs/heads/$i HEAD"
+       done >large_input &&
+       run_with_limited_open_files git update-ref --stdin <large_input &&
+       git rev-parse --verify -q refs/heads/33
+)
+'
+
+test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction deleting branches does not burst open file limit' '
+(
+       for i in $(test_seq 33)
+       do
+               echo "delete refs/heads/$i HEAD"
+       done >large_input &&
+       run_with_limited_open_files git update-ref --stdin <large_input &&
+       test_must_fail git rev-parse --verify -q refs/heads/33
+)
+'
+
 test_done
diff --git a/t/t1404-update-ref-df-conflicts.sh b/t/t1404-update-ref-df-conflicts.sh
new file mode 100755 (executable)
index 0000000..66bafb5
--- /dev/null
@@ -0,0 +1,107 @@
+#!/bin/sh
+
+test_description='Test git update-ref with D/F conflicts'
+. ./test-lib.sh
+
+test_update_rejected () {
+       prefix="$1" &&
+       before="$2" &&
+       pack="$3" &&
+       create="$4" &&
+       error="$5" &&
+       printf "create $prefix/%s $C\n" $before |
+       git update-ref --stdin &&
+       git for-each-ref $prefix >unchanged &&
+       if $pack
+       then
+               git pack-refs --all
+       fi &&
+       printf "create $prefix/%s $C\n" $create >input &&
+       test_must_fail git update-ref --stdin <input 2>output.err &&
+       grep -F "$error" output.err &&
+       git for-each-ref $prefix >actual &&
+       test_cmp unchanged actual
+}
+
+Q="'"
+
+test_expect_success 'setup' '
+
+       git commit --allow-empty -m Initial &&
+       C=$(git rev-parse HEAD)
+
+'
+
+test_expect_success 'existing loose ref is a simple prefix of new' '
+
+       prefix=refs/1l &&
+       test_update_rejected $prefix "a c e" false "b c/x d" \
+               "$Q$prefix/c$Q exists; cannot create $Q$prefix/c/x$Q"
+
+'
+
+test_expect_success 'existing packed ref is a simple prefix of new' '
+
+       prefix=refs/1p &&
+       test_update_rejected $prefix "a c e" true "b c/x d" \
+               "$Q$prefix/c$Q exists; cannot create $Q$prefix/c/x$Q"
+
+'
+
+test_expect_success 'existing loose ref is a deeper prefix of new' '
+
+       prefix=refs/2l &&
+       test_update_rejected $prefix "a c e" false "b c/x/y d" \
+               "$Q$prefix/c$Q exists; cannot create $Q$prefix/c/x/y$Q"
+
+'
+
+test_expect_success 'existing packed ref is a deeper prefix of new' '
+
+       prefix=refs/2p &&
+       test_update_rejected $prefix "a c e" true "b c/x/y d" \
+               "$Q$prefix/c$Q exists; cannot create $Q$prefix/c/x/y$Q"
+
+'
+
+test_expect_success 'new ref is a simple prefix of existing loose' '
+
+       prefix=refs/3l &&
+       test_update_rejected $prefix "a c/x e" false "b c d" \
+               "$Q$prefix/c/x$Q exists; cannot create $Q$prefix/c$Q"
+
+'
+
+test_expect_success 'new ref is a simple prefix of existing packed' '
+
+       prefix=refs/3p &&
+       test_update_rejected $prefix "a c/x e" true "b c d" \
+               "$Q$prefix/c/x$Q exists; cannot create $Q$prefix/c$Q"
+
+'
+
+test_expect_success 'new ref is a deeper prefix of existing loose' '
+
+       prefix=refs/4l &&
+       test_update_rejected $prefix "a c/x/y e" false "b c d" \
+               "$Q$prefix/c/x/y$Q exists; cannot create $Q$prefix/c$Q"
+
+'
+
+test_expect_success 'new ref is a deeper prefix of existing packed' '
+
+       prefix=refs/4p &&
+       test_update_rejected $prefix "a c/x/y e" true "b c d" \
+               "$Q$prefix/c/x/y$Q exists; cannot create $Q$prefix/c$Q"
+
+'
+
+test_expect_success 'one new ref is a simple prefix of another' '
+
+       prefix=refs/5 &&
+       test_update_rejected $prefix "a e" false "b c c/x d" \
+               "cannot process $Q$prefix/c$Q and $Q$prefix/c/x$Q at the same time"
+
+'
+
+test_done
index 468e85621aadaa4a14678ea4a9bf2b673e4ad810..16d0b8bd1a5b6b6a2701fea1c4f35858cec9528b 100755 (executable)
@@ -68,6 +68,14 @@ test_expect_success 'branch -D cannot delete non-ref in .git dir' '
        test_cmp expect .git/my-private-file
 '
 
+test_expect_success 'branch -D cannot delete ref in .git dir' '
+       git rev-parse HEAD >.git/my-private-file &&
+       git rev-parse HEAD >expect &&
+       git branch foo/legit &&
+       test_must_fail git branch -D foo////./././../../../my-private-file &&
+       test_cmp expect .git/my-private-file
+'
+
 test_expect_success 'branch -D cannot delete absolute path' '
        git branch -f extra &&
        test_must_fail git branch -D "$(pwd)/.git/refs/heads/extra" &&
index 8f36aa9fc4d2bdd8b590e3241eccf88609db4ee2..cc5b870e5875bab8326393aea3a8d9f944210de6 100755 (executable)
@@ -346,4 +346,81 @@ test_expect_success 'relative $GIT_WORK_TREE and git subprocesses' '
        test_cmp expected actual
 '
 
+test_expect_success 'Multi-worktree setup' '
+       mkdir work &&
+       mkdir -p repo.git/repos/foo &&
+       cp repo.git/HEAD repo.git/index repo.git/repos/foo &&
+       test_might_fail cp repo.git/sharedindex.* repo.git/repos/foo &&
+       sane_unset GIT_DIR GIT_CONFIG GIT_WORK_TREE
+'
+
+test_expect_success 'GIT_DIR set (1)' '
+       echo "gitdir: repo.git/repos/foo" >gitfile &&
+       echo ../.. >repo.git/repos/foo/commondir &&
+       (
+               cd work &&
+               GIT_DIR=../gitfile git rev-parse --git-common-dir >actual &&
+               test-path-utils real_path "$TRASH_DIRECTORY/repo.git" >expect &&
+               test_cmp expect actual
+       )
+'
+
+test_expect_success 'GIT_DIR set (2)' '
+       echo "gitdir: repo.git/repos/foo" >gitfile &&
+       echo "$(pwd)/repo.git" >repo.git/repos/foo/commondir &&
+       (
+               cd work &&
+               GIT_DIR=../gitfile git rev-parse --git-common-dir >actual &&
+               test-path-utils real_path "$TRASH_DIRECTORY/repo.git" >expect &&
+               test_cmp expect actual
+       )
+'
+
+test_expect_success 'Auto discovery' '
+       echo "gitdir: repo.git/repos/foo" >.git &&
+       echo ../.. >repo.git/repos/foo/commondir &&
+       (
+               cd work &&
+               git rev-parse --git-common-dir >actual &&
+               test-path-utils real_path "$TRASH_DIRECTORY/repo.git" >expect &&
+               test_cmp expect actual &&
+               echo haha >data1 &&
+               git add data1 &&
+               git ls-files --full-name :/ | grep data1 >actual &&
+               echo work/data1 >expect &&
+               test_cmp expect actual
+       )
+'
+
+test_expect_success '$GIT_DIR/common overrides core.worktree' '
+       mkdir elsewhere &&
+       git --git-dir=repo.git config core.worktree "$TRASH_DIRECTORY/elsewhere" &&
+       echo "gitdir: repo.git/repos/foo" >.git &&
+       echo ../.. >repo.git/repos/foo/commondir &&
+       (
+               cd work &&
+               git rev-parse --git-common-dir >actual &&
+               test-path-utils real_path "$TRASH_DIRECTORY/repo.git" >expect &&
+               test_cmp expect actual &&
+               echo haha >data2 &&
+               git add data2 &&
+               git ls-files --full-name :/ | grep data2 >actual &&
+               echo work/data2 >expect &&
+               test_cmp expect actual
+       )
+'
+
+test_expect_success '$GIT_WORK_TREE overrides $GIT_DIR/common' '
+       echo "gitdir: repo.git/repos/foo" >.git &&
+       echo ../.. >repo.git/repos/foo/commondir &&
+       (
+               cd work &&
+               echo haha >data3 &&
+               git --git-dir=../.git --work-tree=. add data3 &&
+               git ls-files --full-name -- :/ | grep data3 >actual &&
+               echo data3 >expect &&
+               test_cmp expect actual
+       )
+'
+
 test_done
index e1b2a99f105f8700e72974428c126ea049247194..33c1a587b3b9f28ecc824a17650467bdc6011bc6 100755 (executable)
@@ -106,6 +106,7 @@ setup_env () {
 expect () {
        cat >"$1/expected" <<-EOF
        setup: git_dir: $2
+       setup: git_common_dir: $2
        setup: worktree: $3
        setup: cwd: $4
        setup: prefix: $5
diff --git a/t/t2025-checkout-to.sh b/t/t2025-checkout-to.sh
new file mode 100755 (executable)
index 0000000..f8e4df4
--- /dev/null
@@ -0,0 +1,129 @@
+#!/bin/sh
+
+test_description='test git checkout --to'
+
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+       test_commit init
+'
+
+test_expect_success 'checkout --to not updating paths' '
+       test_must_fail git checkout --to -- init.t
+'
+
+test_expect_success 'checkout --to an existing worktree' '
+       mkdir -p existing/subtree &&
+       test_must_fail git checkout --detach --to existing master
+'
+
+test_expect_success 'checkout --to an existing empty worktree' '
+       mkdir existing_empty &&
+       git checkout --detach --to existing_empty master
+'
+
+test_expect_success 'checkout --to refuses to checkout locked branch' '
+       test_must_fail git checkout --to zere master &&
+       ! test -d zere &&
+       ! test -d .git/worktrees/zere
+'
+
+test_expect_success 'checkout --to a new worktree' '
+       git rev-parse HEAD >expect &&
+       git checkout --detach --to here master &&
+       (
+               cd here &&
+               test_cmp ../init.t init.t &&
+               test_must_fail git symbolic-ref HEAD &&
+               git rev-parse HEAD >actual &&
+               test_cmp ../expect actual &&
+               git fsck
+       )
+'
+
+test_expect_success 'checkout --to a new worktree from a subdir' '
+       (
+               mkdir sub &&
+               cd sub &&
+               git checkout --detach --to here master &&
+               cd here &&
+               test_cmp ../../init.t init.t
+       )
+'
+
+test_expect_success 'checkout --to from a linked checkout' '
+       (
+               cd here &&
+               git checkout --detach --to nested-here master &&
+               cd nested-here &&
+               git fsck
+       )
+'
+
+test_expect_success 'checkout --to a new worktree creating new branch' '
+       git checkout --to there -b newmaster master &&
+       (
+               cd there &&
+               test_cmp ../init.t init.t &&
+               git symbolic-ref HEAD >actual &&
+               echo refs/heads/newmaster >expect &&
+               test_cmp expect actual &&
+               git fsck
+       )
+'
+
+test_expect_success 'die the same branch is already checked out' '
+       (
+               cd here &&
+               test_must_fail git checkout newmaster
+       )
+'
+
+test_expect_success 'not die the same branch is already checked out' '
+       (
+               cd here &&
+               git checkout --ignore-other-worktrees --to anothernewmaster newmaster
+       )
+'
+
+test_expect_success 'not die on re-checking out current branch' '
+       (
+               cd there &&
+               git checkout newmaster
+       )
+'
+
+test_expect_success 'checkout --to from a bare repo' '
+       (
+               git clone --bare . bare &&
+               cd bare &&
+               git checkout --to ../there2 -b bare-master master
+       )
+'
+
+test_expect_success 'checkout from a bare repo without --to' '
+       (
+               cd bare &&
+               test_must_fail git checkout master
+       )
+'
+
+test_expect_success 'checkout with grafts' '
+       test_when_finished rm .git/info/grafts &&
+       test_commit abc &&
+       SHA1=`git rev-parse HEAD` &&
+       test_commit def &&
+       test_commit xyz &&
+       echo "`git rev-parse HEAD` $SHA1" >.git/info/grafts &&
+       cat >expected <<-\EOF &&
+       xyz
+       abc
+       EOF
+       git log --format=%s -2 >actual &&
+       test_cmp expected actual &&
+       git checkout --detach --to grafted master &&
+       git --git-dir=grafted/.git log --format=%s -2 >actual &&
+       test_cmp expected actual
+'
+
+test_done
diff --git a/t/t2026-prune-linked-checkouts.sh b/t/t2026-prune-linked-checkouts.sh
new file mode 100755 (executable)
index 0000000..1821a48
--- /dev/null
@@ -0,0 +1,96 @@
+#!/bin/sh
+
+test_description='prune $GIT_DIR/worktrees'
+
+. ./test-lib.sh
+
+test_expect_success initialize '
+       git commit --allow-empty -m init
+'
+
+test_expect_success 'prune --worktrees on normal repo' '
+       git prune --worktrees &&
+       test_must_fail git prune --worktrees abc
+'
+
+test_expect_success 'prune files inside $GIT_DIR/worktrees' '
+       mkdir .git/worktrees &&
+       : >.git/worktrees/abc &&
+       git prune --worktrees --verbose >actual &&
+       cat >expect <<EOF &&
+Removing worktrees/abc: not a valid directory
+EOF
+       test_i18ncmp expect actual &&
+       ! test -f .git/worktrees/abc &&
+       ! test -d .git/worktrees
+'
+
+test_expect_success 'prune directories without gitdir' '
+       mkdir -p .git/worktrees/def/abc &&
+       : >.git/worktrees/def/def &&
+       cat >expect <<EOF &&
+Removing worktrees/def: gitdir file does not exist
+EOF
+       git prune --worktrees --verbose >actual &&
+       test_i18ncmp expect actual &&
+       ! test -d .git/worktrees/def &&
+       ! test -d .git/worktrees
+'
+
+test_expect_success SANITY 'prune directories with unreadable gitdir' '
+       mkdir -p .git/worktrees/def/abc &&
+       : >.git/worktrees/def/def &&
+       : >.git/worktrees/def/gitdir &&
+       chmod u-r .git/worktrees/def/gitdir &&
+       git prune --worktrees --verbose >actual &&
+       test_i18ngrep "Removing worktrees/def: unable to read gitdir file" actual &&
+       ! test -d .git/worktrees/def &&
+       ! test -d .git/worktrees
+'
+
+test_expect_success 'prune directories with invalid gitdir' '
+       mkdir -p .git/worktrees/def/abc &&
+       : >.git/worktrees/def/def &&
+       : >.git/worktrees/def/gitdir &&
+       git prune --worktrees --verbose >actual &&
+       test_i18ngrep "Removing worktrees/def: invalid gitdir file" actual &&
+       ! test -d .git/worktrees/def &&
+       ! test -d .git/worktrees
+'
+
+test_expect_success 'prune directories with gitdir pointing to nowhere' '
+       mkdir -p .git/worktrees/def/abc &&
+       : >.git/worktrees/def/def &&
+       echo "$(pwd)"/nowhere >.git/worktrees/def/gitdir &&
+       git prune --worktrees --verbose >actual &&
+       test_i18ngrep "Removing worktrees/def: gitdir file points to non-existent location" actual &&
+       ! test -d .git/worktrees/def &&
+       ! test -d .git/worktrees
+'
+
+test_expect_success 'not prune locked checkout' '
+       test_when_finished rm -r .git/worktrees &&
+       mkdir -p .git/worktrees/ghi &&
+       : >.git/worktrees/ghi/locked &&
+       git prune --worktrees &&
+       test -d .git/worktrees/ghi
+'
+
+test_expect_success 'not prune recent checkouts' '
+       test_when_finished rm -r .git/worktrees &&
+       mkdir zz &&
+       mkdir -p .git/worktrees/jlm &&
+       echo "$(pwd)"/zz >.git/worktrees/jlm/gitdir &&
+       rmdir zz &&
+       git prune --worktrees --verbose --expire=2.days.ago &&
+       test -d .git/worktrees/jlm
+'
+
+test_expect_success 'not prune proper checkouts' '
+       test_when_finished rm -r .git/worktrees &&
+       git checkout "--to=$PWD/nop" --detach master &&
+       git prune --worktrees &&
+       test -d .git/worktrees/nop
+'
+
+test_done
index 2a4a749b4fa3b07963a18b645d29ef774c01bbd1..7c641bfaf4565a97942a91793370da0ca6285fc3 100755 (executable)
@@ -5,10 +5,24 @@ test_description='Intent to add'
 . ./test-lib.sh
 
 test_expect_success 'intent to add' '
+       test_commit 1 &&
+       git rm 1.t &&
+       echo hello >1.t &&
        echo hello >file &&
        echo hello >elif &&
        git add -N file &&
-       git add elif
+       git add elif &&
+       git add -N 1.t
+'
+
+test_expect_success 'git status' '
+       git status --porcelain | grep -v actual >actual &&
+       cat >expect <<-\EOF &&
+       DA 1.t
+       A  elif
+        A file
+       EOF
+       test_cmp expect actual
 '
 
 test_expect_success 'check result of "add -N"' '
@@ -43,7 +57,8 @@ test_expect_success 'i-t-a entry is simply ignored' '
        git add -N nitfol &&
        git commit -m second &&
        test $(git ls-tree HEAD -- nitfol | wc -l) = 0 &&
-       test $(git diff --name-only HEAD -- nitfol | wc -l) = 1
+       test $(git diff --name-only HEAD -- nitfol | wc -l) = 0 &&
+       test $(git diff --name-only -- nitfol | wc -l) = 1
 '
 
 test_expect_success 'can commit with an unrelated i-t-a entry in index' '
@@ -72,13 +87,13 @@ test_expect_success 'cache-tree invalidates i-t-a paths' '
        : >dir/bar &&
        git add -N dir/bar &&
        git diff --cached --name-only >actual &&
-       echo dir/bar >expect &&
+       >expect &&
        test_cmp expect actual &&
 
        git write-tree >/dev/null &&
 
        git diff --cached --name-only >actual &&
-       echo dir/bar >expect &&
+       >expect &&
        test_cmp expect actual
 '
 
diff --git a/t/t3033-merge-toplevel.sh b/t/t3033-merge-toplevel.sh
new file mode 100755 (executable)
index 0000000..46aadc4
--- /dev/null
@@ -0,0 +1,136 @@
+#!/bin/sh
+
+test_description='"git merge" top-level frontend'
+
+. ./test-lib.sh
+
+t3033_reset () {
+       git checkout -B master two &&
+       git branch -f left three &&
+       git branch -f right four
+}
+
+test_expect_success setup '
+       test_commit one &&
+       git branch left &&
+       git branch right &&
+       test_commit two &&
+       git checkout left &&
+       test_commit three &&
+       git checkout right &&
+       test_commit four &&
+       git checkout master
+'
+
+# Local branches
+
+test_expect_success 'merge an octopus into void' '
+       t3033_reset &&
+       git checkout --orphan test &&
+       git rm -fr . &&
+       test_must_fail git merge left right &&
+       test_must_fail git rev-parse --verify HEAD &&
+       git diff --quiet &&
+       test_must_fail git rev-parse HEAD
+'
+
+test_expect_success 'merge an octopus, fast-forward (ff)' '
+       t3033_reset &&
+       git reset --hard one &&
+       git merge left right &&
+       # one is ancestor of three (left) and four (right)
+       test_must_fail git rev-parse --verify HEAD^3 &&
+       git rev-parse HEAD^1 HEAD^2 | sort >actual &&
+       git rev-parse three four | sort >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success 'merge octopus, non-fast-forward (ff)' '
+       t3033_reset &&
+       git reset --hard one &&
+       git merge --no-ff left right &&
+       # one is ancestor of three (left) and four (right)
+       test_must_fail git rev-parse --verify HEAD^4 &&
+       git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual &&
+       git rev-parse one three four | sort >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success 'merge octopus, fast-forward (does not ff)' '
+       t3033_reset &&
+       git merge left right &&
+       # two (master) is not an ancestor of three (left) and four (right)
+       test_must_fail git rev-parse --verify HEAD^4 &&
+       git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual &&
+       git rev-parse two three four | sort >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success 'merge octopus, non-fast-forward' '
+       t3033_reset &&
+       git merge --no-ff left right &&
+       test_must_fail git rev-parse --verify HEAD^4 &&
+       git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual &&
+       git rev-parse two three four | sort >expect &&
+       test_cmp expect actual
+'
+
+# The same set with FETCH_HEAD
+
+test_expect_success 'merge FETCH_HEAD octopus into void' '
+       t3033_reset &&
+       git checkout --orphan test &&
+       git rm -fr . &&
+       git fetch . left right &&
+       test_must_fail git merge FETCH_HEAD &&
+       test_must_fail git rev-parse --verify HEAD &&
+       git diff --quiet &&
+       test_must_fail git rev-parse HEAD
+'
+
+test_expect_success 'merge FETCH_HEAD octopus fast-forward (ff)' '
+       t3033_reset &&
+       git reset --hard one &&
+       git fetch . left right &&
+       git merge FETCH_HEAD &&
+       # one is ancestor of three (left) and four (right)
+       test_must_fail git rev-parse --verify HEAD^3 &&
+       git rev-parse HEAD^1 HEAD^2 | sort >actual &&
+       git rev-parse three four | sort >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success 'merge FETCH_HEAD octopus non-fast-forward (ff)' '
+       t3033_reset &&
+       git reset --hard one &&
+       git fetch . left right &&
+       git merge --no-ff FETCH_HEAD &&
+       # one is ancestor of three (left) and four (right)
+       test_must_fail git rev-parse --verify HEAD^4 &&
+       git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual &&
+       git rev-parse one three four | sort >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success 'merge FETCH_HEAD octopus fast-forward (does not ff)' '
+       t3033_reset &&
+       git fetch . left right &&
+       git merge FETCH_HEAD &&
+       # two (master) is not an ancestor of three (left) and four (right)
+       test_must_fail git rev-parse --verify HEAD^4 &&
+       git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual &&
+       git rev-parse two three four | sort >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success 'merge FETCH_HEAD octopus non-fast-forward' '
+       t3033_reset &&
+       git fetch . left right &&
+       git merge --no-ff FETCH_HEAD &&
+       test_must_fail git rev-parse --verify HEAD^4 &&
+       git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual &&
+       git rev-parse two three four | sort >expect &&
+       test_cmp expect actual
+'
+
+test_done
index aa9eb3a3e5ef0637615c6d958a29dbd9bbbf0895..8aae98d482aa572b3a9a55f9b38280ad716c7baf 100755 (executable)
@@ -187,4 +187,21 @@ test_expect_success 'notice d/f conflict with existing ref' '
        test_must_fail git branch foo/bar/baz/lots/of/extra/components
 '
 
+test_expect_success 'timeout if packed-refs.lock exists' '
+       LOCK=.git/packed-refs.lock &&
+       >"$LOCK" &&
+       test_when_finished "rm -f $LOCK" &&
+       test_must_fail git pack-refs --all --prune
+'
+
+test_expect_success 'retry acquiring packed-refs.lock' '
+       LOCK=.git/packed-refs.lock &&
+       >"$LOCK" &&
+       test_when_finished "wait; rm -f $LOCK" &&
+       {
+               ( sleep 1 ; rm -f $LOCK ) &
+       } &&
+       git -c core.packedrefstimeout=3000 pack-refs --all --prune
+'
+
 test_done
index 5a27ec9b5eb7c37145a098d878432948233ba756..8f64505e4f94432de6cc287f4ab2f3129703536a 100755 (executable)
@@ -47,7 +47,7 @@ test_expect_success setup '
 '
 
 test_expect_success 'reference merge' '
-       git merge -s recursive "reference merge" HEAD master
+       git merge -s recursive -m "reference merge" master
 '
 
 PRE_REBASE=$(git rev-parse test-rebase)
index eed76cca55ce655cb51c793f21cd5ebbd363ba85..ac429a0bbbbeb95f96336aa203a5d9726ed6eb1d 100755 (executable)
@@ -1055,4 +1055,51 @@ test_expect_success 'todo count' '
        grep "^# Rebase ..* onto ..* ([0-9]" actual
 '
 
+test_expect_success 'rebase -i commits that overwrite untracked files (pick)' '
+       git checkout --force branch2 &&
+       git clean -f &&
+       set_fake_editor &&
+       FAKE_LINES="edit 1 2" git rebase -i A &&
+       test_cmp_rev HEAD F &&
+       test_path_is_missing file6 &&
+       >file6 &&
+       test_must_fail git rebase --continue &&
+       test_cmp_rev HEAD F &&
+       rm file6 &&
+       git rebase --continue &&
+       test_cmp_rev HEAD I
+'
+
+test_expect_success 'rebase -i commits that overwrite untracked files (squash)' '
+       git checkout --force branch2 &&
+       git clean -f &&
+       git tag original-branch2 &&
+       set_fake_editor &&
+       FAKE_LINES="edit 1 squash 2" git rebase -i A &&
+       test_cmp_rev HEAD F &&
+       test_path_is_missing file6 &&
+       >file6 &&
+       test_must_fail git rebase --continue &&
+       test_cmp_rev HEAD F &&
+       rm file6 &&
+       git rebase --continue &&
+       test $(git cat-file commit HEAD | sed -ne \$p) = I &&
+       git reset --hard original-branch2
+'
+
+test_expect_success 'rebase -i commits that overwrite untracked files (no ff)' '
+       git checkout --force branch2 &&
+       git clean -f &&
+       set_fake_editor &&
+       FAKE_LINES="edit 1 2" git rebase -i --no-ff A &&
+       test $(git cat-file commit HEAD | sed -ne \$p) = F &&
+       test_path_is_missing file6 &&
+       >file6 &&
+       test_must_fail git rebase --continue &&
+       test $(git cat-file commit HEAD | sed -ne \$p) = F &&
+       rm file6 &&
+       git rebase --continue &&
+       test $(git cat-file commit HEAD | sed -ne \$p) = I
+'
+
 test_done
index 24ddd8a704b22e32322b8ef52bbd0d2e6195e5e1..deae948c76bd12f9b3ef6b54568717b21d641d8a 100755 (executable)
@@ -326,15 +326,34 @@ test_expect_success 'split hunk "add -p (edit)"' '
        # 2. Correct version applies the (not)edited version, and asks
        #    about the next hunk, against which we say q and program
        #    exits.
-       for a in s e     q n q q
-       do
-               echo $a
-       done |
+       printf "%s\n" s e     q n q q |
        EDITOR=: git add -p &&
        git diff >actual &&
        ! grep "^+15" actual
 '
 
+test_expect_failure 'split hunk "add -p (no, yes, edit)"' '
+       cat >test <<-\EOF &&
+       5
+       10
+       20
+       21
+       30
+       31
+       40
+       50
+       60
+       EOF
+       git reset &&
+       # test sequence is s(plit), n(o), y(es), e(dit)
+       # q n q q is there to make sure we exit at the end.
+       printf "%s\n" s n y e   q n q q |
+       EDITOR=: git add -p 2>error &&
+       test_must_be_empty error &&
+       git diff >actual &&
+       ! grep "^+31" actual
+'
+
 test_expect_success 'patch mode ignores unmerged entries' '
        git reset --hard &&
        test_commit conflict &&
index 4ee47cc9a862cdbe8c63bc9d4ebbe46ff3c344bc..3cb74ca296d141a6bd248e527680f5f217608ca7 100755 (executable)
@@ -118,4 +118,11 @@ test_expect_success 'add -e' '
 
 '
 
+test_expect_success 'add -e notices editor failure' '
+       git reset --hard &&
+       echo change >>file &&
+       test_must_fail env GIT_EDITOR=false git add -e &&
+       test_expect_code 1 git diff --exit-code
+'
+
 test_done
index 70655c184886e35046f05e09ee093df48b59daa6..38e730090fe311ea82c737646aedba214d1143bb 100755 (executable)
@@ -1,9 +1,15 @@
 #!/bin/sh
 
-test_description='git checkout --patch'
+test_description='stash -p'
 . ./lib-patch-mode.sh
 
-test_expect_success PERL 'setup' '
+if ! test_have_prereq PERL
+then
+       skip_all='skipping stash -p tests, perl not available'
+       test_done
+fi
+
+test_expect_success 'setup' '
        mkdir dir &&
        echo parent > dir/foo &&
        echo dummy > bar &&
@@ -20,7 +26,7 @@ test_expect_success PERL 'setup' '
 
 # note: order of files with unstaged changes: HEAD bar dir/foo
 
-test_expect_success PERL 'saying "n" does nothing' '
+test_expect_success 'saying "n" does nothing' '
        set_state HEAD HEADfile_work HEADfile_index &&
        set_state dir/foo work index &&
        (echo n; echo n; echo n) | test_must_fail git stash save -p &&
@@ -29,7 +35,7 @@ test_expect_success PERL 'saying "n" does nothing' '
        verify_state dir/foo work index
 '
 
-test_expect_success PERL 'git stash -p' '
+test_expect_success 'git stash -p' '
        (echo y; echo n; echo y) | git stash save -p &&
        verify_state HEAD committed HEADfile_index &&
        verify_saved_state bar &&
@@ -41,7 +47,7 @@ test_expect_success PERL 'git stash -p' '
        verify_state dir/foo work head
 '
 
-test_expect_success PERL 'git stash -p --no-keep-index' '
+test_expect_success 'git stash -p --no-keep-index' '
        set_state HEAD HEADfile_work HEADfile_index &&
        set_state bar bar_work bar_index &&
        set_state dir/foo work index &&
@@ -56,7 +62,7 @@ test_expect_success PERL 'git stash -p --no-keep-index' '
        verify_state dir/foo work index
 '
 
-test_expect_success PERL 'git stash --no-keep-index -p' '
+test_expect_success 'git stash --no-keep-index -p' '
        set_state HEAD HEADfile_work HEADfile_index &&
        set_state bar bar_work bar_index &&
        set_state dir/foo work index &&
@@ -71,8 +77,31 @@ test_expect_success PERL 'git stash --no-keep-index -p' '
        verify_state dir/foo work index
 '
 
-test_expect_success PERL 'none of this moved HEAD' '
+test_expect_success 'none of this moved HEAD' '
        verify_saved_head
 '
 
+test_expect_failure 'stash -p with split hunk' '
+       git reset --hard &&
+       cat >test <<-\EOF &&
+       aaa
+       bbb
+       ccc
+       EOF
+       git add test &&
+       git commit -m "initial" &&
+       cat >test <<-\EOF &&
+       aaa
+       added line 1
+       bbb
+       added line 2
+       ccc
+       EOF
+       printf "%s\n" s n y q |
+       test_might_fail git stash -p 2>error &&
+       ! test_must_be_empty error &&
+       grep "added line 1" test &&
+       ! grep "added line 2" test
+'
+
 test_done
index 13e7f621ab79f95cc7c3057d9de5710813049102..7452fce0da94a257f289a9fad1e9d24dd1509195 100755 (executable)
@@ -139,11 +139,13 @@ test_expect_success SYMLINKS 'setup symlinks with attributes' '
 test_expect_success SYMLINKS 'symlinks do not respect userdiff config by path' '
        cat >expect <<-\EOF &&
        diff --git a/file.bin b/file.bin
-       index e69de29..d95f3ad 100644
-       Binary files a/file.bin and b/file.bin differ
+       new file mode 100644
+       index 0000000..d95f3ad
+       Binary files /dev/null and b/file.bin differ
        diff --git a/link.bin b/link.bin
-       index e69de29..dce41ec 120000
-       --- a/link.bin
+       new file mode 120000
+       index 0000000..dce41ec
+       --- /dev/null
        +++ b/link.bin
        @@ -0,0 +1 @@
        +file.bin
index 44d45257da708f25bd0eb2c631bd7e68a38a7354..b345b2ebfa53e51cb0ab32635a9123abdf55f2b1 100644 (file)
@@ -5,7 +5,7 @@ Date:   Mon Jun 26 00:06:00 2006 +0000
 
     Rearranged lines in dir/sub
 
-commit 59d314ad6f356dd08601a4cd5e530381da3e3c64 (HEAD, refs/heads/master)
+commit 59d314ad6f356dd08601a4cd5e530381da3e3c64 (HEAD -> refs/heads/master)
 Merge: 9a6d494 c7a2ab9
 Author: A U Thor <author@example.com>
 Date:   Mon Jun 26 00:04:00 2006 +0000
index 227d29335020f3e52a40b03b2f933f4d63942b91..7efd45bc27687a619d149bb581cb6cb2582241e9 100755 (executable)
@@ -9,36 +9,27 @@ modify () {
        mv "$2.x" "$2"
 }
 
-D=`pwd`
-
 test_expect_success setup '
-
        echo file >file &&
        git add file &&
        git commit -a -m original
-
 '
 
 test_expect_success 'pulling into void' '
-       mkdir cloned &&
-       cd cloned &&
-       git init &&
-       git pull ..
-'
-
-cd "$D"
-
-test_expect_success 'checking the results' '
+       git init cloned &&
+       (
+               cd cloned &&
+               git pull ..
+       ) &&
        test -f file &&
        test -f cloned/file &&
        test_cmp file cloned/file
 '
 
 test_expect_success 'pulling into void using master:master' '
-       mkdir cloned-uho &&
+       git init cloned-uho &&
        (
                cd cloned-uho &&
-               git init &&
                git pull .. master:master
        ) &&
        test -f file &&
@@ -71,7 +62,6 @@ test_expect_success 'pulling into void does not overwrite staged files' '
        )
 '
 
-
 test_expect_success 'pulling into void does not remove new staged files' '
        git init cloned-staged-new &&
        (
@@ -86,6 +76,15 @@ test_expect_success 'pulling into void does not remove new staged files' '
        )
 '
 
+test_expect_success 'pulling into void must not create an octopus' '
+       git init cloned-octopus &&
+       (
+               cd cloned-octopus &&
+               test_must_fail git pull .. master master &&
+               ! test -f file
+       )
+'
+
 test_expect_success 'test . as a remote' '
 
        git branch copy master &&
index 8cccecc2fcce0c1a9b1f90a30608ab9e9b662eae..c278adaa5a2556327a820cdeb98943b58d1e429f 100755 (executable)
@@ -17,6 +17,9 @@ test_expect_success setup '
                git commit -m "add bfile"
        ) &&
        test_tick && test_tick &&
+       echo "second" >afile &&
+       git add afile &&
+       git commit -m "second commit" &&
        echo "original $dollar" >afile &&
        git add afile &&
        git commit -m "do not clobber $dollar signs"
@@ -32,4 +35,18 @@ test_expect_success pull '
 )
 '
 
+test_expect_success '--log=1 limits shortlog length' '
+(
+       cd cloned &&
+       git reset --hard HEAD^ &&
+       test "$(cat afile)" = original &&
+       test "$(cat bfile)" = added &&
+       git pull --log=1 &&
+       git log -3 &&
+       git cat-file commit HEAD >result &&
+       grep Dollar result &&
+       ! grep "second commit" result
+)
+'
+
 test_done
index b46118846ca9950684ff3880179ca467253a7970..37a433504e27f8dffc9bbbb9e94d550de20ff035 100755 (executable)
@@ -3,12 +3,6 @@
 test_description='fetch/clone from a shallow clone over http'
 
 . ./test-lib.sh
-
-if test -n "$NO_CURL"; then
-       skip_all='skipping test, git built without http support'
-       test_done
-fi
-
 . "$TEST_DIRECTORY"/lib-httpd.sh
 start_httpd
 
index 9cf27e8c9924770b619b8e21fb22b5225e5f085f..fd7d06b9a23664d0e20cc32a03955ff8816cac7f 100755 (executable)
@@ -6,11 +6,6 @@
 test_description='test smart pushing over http via http-backend'
 . ./test-lib.sh
 
-if test -n "$NO_CURL"; then
-       skip_all='skipping test, git built without http support'
-       test_done
-fi
-
 ROOT_PATH="$PWD"
 . "$TEST_DIRECTORY"/lib-gpg.sh
 . "$TEST_DIRECTORY"/lib-httpd.sh
index 2a691e09ebe5f35e5a1aff6c710e6b4dc525f0d6..51658331571611c568def54be28072f426c48e66 100755 (executable)
@@ -3,12 +3,6 @@
 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
 
index 3d11b7a6bb660f3758bdf12dff06e31be04de9eb..87a7aa04aeb452c162dc5585efd0ec13195ea80a 100755 (executable)
@@ -2,12 +2,6 @@
 
 test_description='test dumb fetching over http via static file'
 . ./test-lib.sh
-
-if test -n "$NO_CURL"; then
-       skip_all='skipping test, git built without http support'
-       test_done
-fi
-
 . "$TEST_DIRECTORY"/lib-httpd.sh
 start_httpd
 
index 66439e58fcf4b08a43ef417b054ae476ffbe3aea..2b293119015af7bfb8f151d2a3ec8c51c4c0b209 100755 (executable)
@@ -2,12 +2,6 @@
 
 test_description='test smart fetching over http via http-backend'
 . ./test-lib.sh
-
-if test -n "$NO_CURL"; then
-       skip_all='skipping test, git built without http support'
-       test_done
-fi
-
 . "$TEST_DIRECTORY"/lib-httpd.sh
 start_httpd
 
index d23fb0238483520e77004a208f15db808941b4af..19afe966986cdc72cf8fc23f113bd77a8128f382 100755 (executable)
@@ -2,12 +2,6 @@
 
 test_description='test git-http-backend'
 . ./test-lib.sh
-
-if test -n "$NO_CURL"; then
-       skip_all='skipping test, git built without http support'
-       test_done
-fi
-
 . "$TEST_DIRECTORY"/lib-httpd.sh
 start_httpd
 
index 1befc453a31e6ad67c3805eb94bfe00f6b7a5469..bfdaf75966f7b8bb057e4db0b8791306f6e6a44f 100755 (executable)
@@ -296,6 +296,12 @@ setup_ssh_wrapper () {
        '
 }
 
+copy_ssh_wrapper_as () {
+       cp "$TRASH_DIRECTORY/ssh-wrapper" "$1" &&
+       GIT_SSH="$1" &&
+       export GIT_SSH
+}
+
 expect_ssh () {
        test_when_finished '
                (cd "$TRASH_DIRECTORY" && rm -f ssh-expect && >ssh-output)
@@ -332,9 +338,36 @@ test_expect_success !MINGW,!CYGWIN 'clone local path foo:bar' '
 
 test_expect_success 'bracketed hostnames are still ssh' '
        git clone "[myhost:123]:src" ssh-bracket-clone &&
-       expect_ssh myhost '-p 123' src
+       expect_ssh "-p 123" myhost src
+'
+
+test_expect_success 'uplink is not treated as putty' '
+       copy_ssh_wrapper_as "$TRASH_DIRECTORY/uplink" &&
+       git clone "[myhost:123]:src" ssh-bracket-clone-uplink &&
+       expect_ssh "-p 123" myhost src
+'
+
+test_expect_success 'plink is treated specially (as putty)' '
+       copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
+       git clone "[myhost:123]:src" ssh-bracket-clone-plink-0 &&
+       expect_ssh "-P 123" myhost src
 '
 
+test_expect_success 'plink.exe is treated specially (as putty)' '
+       copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink.exe" &&
+       git clone "[myhost:123]:src" ssh-bracket-clone-plink-1 &&
+       expect_ssh "-P 123" myhost src
+'
+
+test_expect_success 'tortoiseplink is like putty, with extra arguments' '
+       copy_ssh_wrapper_as "$TRASH_DIRECTORY/tortoiseplink" &&
+       git clone "[myhost:123]:src" ssh-bracket-clone-plink-2 &&
+       expect_ssh "-batch -P 123" myhost src
+'
+
+# Reset the GIT_SSH environment variable for clone tests.
+setup_ssh_wrapper
+
 counter=0
 # $1 url
 # $2 none|host
index 27c3d73961dfc9b50c3eafc7360662076cb31260..2af1beec5f6f330072b3739e3c8b855f988173a9 100755 (executable)
@@ -24,7 +24,7 @@ test_expect_success 'prepare repository' '
 '
 
 test_expect_success 'Merge with d/f conflicts' '
-       test_expect_code 1 git merge "merge msg" B master
+       test_expect_code 1 git merge -m "merge msg" master
 '
 
 test_expect_success 'F/D conflict' '
index d15b313d4b5e65bc583b7c1f0e4efbb5ac56cb00..213deecab1e81685589f9041216b7044243acff3 100755 (executable)
@@ -48,7 +48,7 @@ echo "1
 " > file &&
 git commit -m "C3" file &&
 git branch C3 &&
-git merge "pre E3 merge" B A &&
+git merge -m "pre E3 merge" A &&
 echo "1
 2
 3 changed in E3, branch B. New file size
@@ -61,7 +61,7 @@ echo "1
 " > file &&
 git commit -m "E3" file &&
 git checkout A &&
-git merge "pre D8 merge" A C3 &&
+git merge -m "pre D8 merge" C3 &&
 echo "1
 2
 3 changed in C3, branch B
@@ -73,7 +73,7 @@ echo "1
 9" > file &&
 git commit -m D8 file'
 
-test_expect_success 'Criss-cross merge' 'git merge "final merge" A B'
+test_expect_success 'Criss-cross merge' 'git merge -m "final merge" B'
 
 cat > file-expect <<EOF
 1
index fa207f3b8cae5397904f5fb8da2b20b67d297415..d1ff5c94f2f3241b3b1ed436d0011280986abab7 100755 (executable)
@@ -1491,10 +1491,10 @@ run_with_limited_stack () {
        (ulimit -s 128 && "$@")
 }
 
-test_lazy_prereq ULIMIT 'run_with_limited_stack true'
+test_lazy_prereq ULIMIT_STACK_SIZE 'run_with_limited_stack true'
 
 # we require ulimit, this excludes Windows
-test_expect_success ULIMIT '--contains works in a deep repo' '
+test_expect_success ULIMIT_STACK_SIZE '--contains works in a deep repo' '
        >expect &&
        i=1 &&
        while test $i -lt 8000
diff --git a/t/t7063-status-untracked-cache.sh b/t/t7063-status-untracked-cache.sh
new file mode 100755 (executable)
index 0000000..2b2ffd7
--- /dev/null
@@ -0,0 +1,353 @@
+#!/bin/sh
+
+test_description='test untracked cache'
+
+. ./test-lib.sh
+
+avoid_racy() {
+       sleep 1
+}
+
+git update-index --untracked-cache
+# It's fine if git update-index returns an error code other than one,
+# it'll be caught in the first test.
+if test $? -eq 1; then
+       skip_all='This system does not support untracked cache'
+       test_done
+fi
+
+test_expect_success 'setup' '
+       git init worktree &&
+       cd worktree &&
+       mkdir done dtwo dthree &&
+       touch one two three done/one dtwo/two dthree/three &&
+       git add one two done/one &&
+       : >.git/info/exclude &&
+       git update-index --untracked-cache
+'
+
+test_expect_success 'untracked cache is empty' '
+       test-dump-untracked-cache >../actual &&
+       cat >../expect <<EOF &&
+info/exclude 0000000000000000000000000000000000000000
+core.excludesfile 0000000000000000000000000000000000000000
+exclude_per_dir .gitignore
+flags 00000006
+EOF
+       test_cmp ../expect ../actual
+'
+
+cat >../status.expect <<EOF &&
+A  done/one
+A  one
+A  two
+?? dthree/
+?? dtwo/
+?? three
+EOF
+
+cat >../dump.expect <<EOF &&
+info/exclude e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
+core.excludesfile 0000000000000000000000000000000000000000
+exclude_per_dir .gitignore
+flags 00000006
+/ 0000000000000000000000000000000000000000 recurse valid
+dthree/
+dtwo/
+three
+/done/ 0000000000000000000000000000000000000000 recurse valid
+/dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
+three
+/dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
+two
+EOF
+
+test_expect_success 'status first time (empty cache)' '
+       avoid_racy &&
+       : >../trace &&
+       GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
+       git status --porcelain >../actual &&
+       test_cmp ../status.expect ../actual &&
+       cat >../trace.expect <<EOF &&
+node creation: 3
+gitignore invalidation: 1
+directory invalidation: 0
+opendir: 4
+EOF
+       test_cmp ../trace.expect ../trace
+'
+
+test_expect_success 'untracked cache after first status' '
+       test-dump-untracked-cache >../actual &&
+       test_cmp ../dump.expect ../actual
+'
+
+test_expect_success 'status second time (fully populated cache)' '
+       avoid_racy &&
+       : >../trace &&
+       GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
+       git status --porcelain >../actual &&
+       test_cmp ../status.expect ../actual &&
+       cat >../trace.expect <<EOF &&
+node creation: 0
+gitignore invalidation: 0
+directory invalidation: 0
+opendir: 0
+EOF
+       test_cmp ../trace.expect ../trace
+'
+
+test_expect_success 'untracked cache after second status' '
+       test-dump-untracked-cache >../actual &&
+       test_cmp ../dump.expect ../actual
+'
+
+test_expect_success 'modify in root directory, one dir invalidation' '
+       avoid_racy &&
+       : >four &&
+       : >../trace &&
+       GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
+       git status --porcelain >../actual &&
+       cat >../status.expect <<EOF &&
+A  done/one
+A  one
+A  two
+?? dthree/
+?? dtwo/
+?? four
+?? three
+EOF
+       test_cmp ../status.expect ../actual &&
+       cat >../trace.expect <<EOF &&
+node creation: 0
+gitignore invalidation: 0
+directory invalidation: 1
+opendir: 1
+EOF
+       test_cmp ../trace.expect ../trace
+
+'
+
+test_expect_success 'verify untracked cache dump' '
+       test-dump-untracked-cache >../actual &&
+       cat >../expect <<EOF &&
+info/exclude e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
+core.excludesfile 0000000000000000000000000000000000000000
+exclude_per_dir .gitignore
+flags 00000006
+/ 0000000000000000000000000000000000000000 recurse valid
+dthree/
+dtwo/
+four
+three
+/done/ 0000000000000000000000000000000000000000 recurse valid
+/dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
+three
+/dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
+two
+EOF
+       test_cmp ../expect ../actual
+'
+
+test_expect_success 'new .gitignore invalidates recursively' '
+       avoid_racy &&
+       echo four >.gitignore &&
+       : >../trace &&
+       GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
+       git status --porcelain >../actual &&
+       cat >../status.expect <<EOF &&
+A  done/one
+A  one
+A  two
+?? .gitignore
+?? dthree/
+?? dtwo/
+?? three
+EOF
+       test_cmp ../status.expect ../actual &&
+       cat >../trace.expect <<EOF &&
+node creation: 0
+gitignore invalidation: 1
+directory invalidation: 1
+opendir: 4
+EOF
+       test_cmp ../trace.expect ../trace
+
+'
+
+test_expect_success 'verify untracked cache dump' '
+       test-dump-untracked-cache >../actual &&
+       cat >../expect <<EOF &&
+info/exclude e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
+core.excludesfile 0000000000000000000000000000000000000000
+exclude_per_dir .gitignore
+flags 00000006
+/ e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid
+.gitignore
+dthree/
+dtwo/
+three
+/done/ 0000000000000000000000000000000000000000 recurse valid
+/dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
+three
+/dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
+two
+EOF
+       test_cmp ../expect ../actual
+'
+
+test_expect_success 'new info/exclude invalidates everything' '
+       avoid_racy &&
+       echo three >>.git/info/exclude &&
+       : >../trace &&
+       GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
+       git status --porcelain >../actual &&
+       cat >../status.expect <<EOF &&
+A  done/one
+A  one
+A  two
+?? .gitignore
+?? dtwo/
+EOF
+       test_cmp ../status.expect ../actual &&
+       cat >../trace.expect <<EOF &&
+node creation: 0
+gitignore invalidation: 1
+directory invalidation: 0
+opendir: 4
+EOF
+       test_cmp ../trace.expect ../trace
+'
+
+test_expect_success 'verify untracked cache dump' '
+       test-dump-untracked-cache >../actual &&
+       cat >../expect <<EOF &&
+info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0
+core.excludesfile 0000000000000000000000000000000000000000
+exclude_per_dir .gitignore
+flags 00000006
+/ e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid
+.gitignore
+dtwo/
+/done/ 0000000000000000000000000000000000000000 recurse valid
+/dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
+/dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
+two
+EOF
+       test_cmp ../expect ../actual
+'
+
+test_expect_success 'move two from tracked to untracked' '
+       git rm --cached two &&
+       test-dump-untracked-cache >../actual &&
+       cat >../expect <<EOF &&
+info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0
+core.excludesfile 0000000000000000000000000000000000000000
+exclude_per_dir .gitignore
+flags 00000006
+/ e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse
+/done/ 0000000000000000000000000000000000000000 recurse valid
+/dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
+/dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
+two
+EOF
+       test_cmp ../expect ../actual
+'
+
+test_expect_success 'status after the move' '
+       : >../trace &&
+       GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
+       git status --porcelain >../actual &&
+       cat >../status.expect <<EOF &&
+A  done/one
+A  one
+?? .gitignore
+?? dtwo/
+?? two
+EOF
+       test_cmp ../status.expect ../actual &&
+       cat >../trace.expect <<EOF &&
+node creation: 0
+gitignore invalidation: 0
+directory invalidation: 0
+opendir: 1
+EOF
+       test_cmp ../trace.expect ../trace
+'
+
+test_expect_success 'verify untracked cache dump' '
+       test-dump-untracked-cache >../actual &&
+       cat >../expect <<EOF &&
+info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0
+core.excludesfile 0000000000000000000000000000000000000000
+exclude_per_dir .gitignore
+flags 00000006
+/ e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid
+.gitignore
+dtwo/
+two
+/done/ 0000000000000000000000000000000000000000 recurse valid
+/dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
+/dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
+two
+EOF
+       test_cmp ../expect ../actual
+'
+
+test_expect_success 'move two from untracked to tracked' '
+       git add two &&
+       test-dump-untracked-cache >../actual &&
+       cat >../expect <<EOF &&
+info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0
+core.excludesfile 0000000000000000000000000000000000000000
+exclude_per_dir .gitignore
+flags 00000006
+/ e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse
+/done/ 0000000000000000000000000000000000000000 recurse valid
+/dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
+/dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
+two
+EOF
+       test_cmp ../expect ../actual
+'
+
+test_expect_success 'status after the move' '
+       : >../trace &&
+       GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
+       git status --porcelain >../actual &&
+       cat >../status.expect <<EOF &&
+A  done/one
+A  one
+A  two
+?? .gitignore
+?? dtwo/
+EOF
+       test_cmp ../status.expect ../actual &&
+       cat >../trace.expect <<EOF &&
+node creation: 0
+gitignore invalidation: 0
+directory invalidation: 0
+opendir: 1
+EOF
+       test_cmp ../trace.expect ../trace
+'
+
+test_expect_success 'verify untracked cache dump' '
+       test-dump-untracked-cache >../actual &&
+       cat >../expect <<EOF &&
+info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0
+core.excludesfile 0000000000000000000000000000000000000000
+exclude_per_dir .gitignore
+flags 00000006
+/ e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid
+.gitignore
+dtwo/
+/done/ 0000000000000000000000000000000000000000 recurse valid
+/dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
+/dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
+two
+EOF
+       test_cmp ../expect ../actual
+'
+
+test_done
diff --git a/t/t7410-submodule-checkout-to.sh b/t/t7410-submodule-checkout-to.sh
new file mode 100755 (executable)
index 0000000..8f30aed
--- /dev/null
@@ -0,0 +1,50 @@
+#!/bin/sh
+
+test_description='Combination of submodules and multiple workdirs'
+
+. ./test-lib.sh
+
+base_path=$(pwd -P)
+
+test_expect_success 'setup: make origin' \
+    'mkdir -p origin/sub && ( cd origin/sub && git init &&
+       echo file1 >file1 &&
+       git add file1 &&
+       git commit -m file1 ) &&
+    mkdir -p origin/main && ( cd origin/main && git init &&
+       git submodule add ../sub &&
+       git commit -m "add sub" ) &&
+    ( cd origin/sub &&
+       echo file1updated >file1 &&
+       git add file1 &&
+       git commit -m "file1 updated" ) &&
+    ( cd origin/main/sub && git pull ) &&
+    ( cd origin/main &&
+       git add sub &&
+       git commit -m "sub updated" )'
+
+test_expect_success 'setup: clone' \
+    'mkdir clone && ( cd clone &&
+       git clone --recursive "$base_path/origin/main")'
+
+rev1_hash_main=$(git --git-dir=origin/main/.git show --pretty=format:%h -q "HEAD~1")
+rev1_hash_sub=$(git --git-dir=origin/sub/.git show --pretty=format:%h -q "HEAD~1")
+
+test_expect_success 'checkout main' \
+    'mkdir default_checkout &&
+    (cd clone/main &&
+       git checkout --to "$base_path/default_checkout/main" "$rev1_hash_main")'
+
+test_expect_failure 'can see submodule diffs just after checkout' \
+    '(cd default_checkout/main && git diff --submodule master"^!" | grep "file1 updated")'
+
+test_expect_success 'checkout main and initialize independed clones' \
+    'mkdir fully_cloned_submodule &&
+    (cd clone/main &&
+       git checkout --to "$base_path/fully_cloned_submodule/main" "$rev1_hash_main") &&
+    (cd fully_cloned_submodule/main && git submodule update)'
+
+test_expect_success 'can see submodule diffs after independed cloning' \
+    '(cd fully_cloned_submodule/main && git diff --submodule master"^!" | grep "file1 updated")'
+
+test_done
index 051489ea334c9693c2d19823ad23947703f66d90..2e0d557243d6dadc856e5ebe7446aacd905047f1 100755 (executable)
@@ -370,7 +370,7 @@ exit 0
 EOF
 
 test_expect_success !AUTOIDENT 'do not fire editor when committer is bogus' '
-       >.git/result
+       >.git/result &&
        >expect &&
 
        echo >>negative &&
index f768c900abd1cddc6d69a1bdeae897374e7d0dad..c6c44ec570dac66ca9a800ac687280cd3597e886 100755 (executable)
@@ -45,6 +45,14 @@ test_expect_success 'fast-forward pull succeeds with "true" in pull.ff' '
        test "$(git rev-parse HEAD)" = "$(git rev-parse c1)"
 '
 
+test_expect_success 'pull.ff=true overrides merge.ff=false' '
+       git reset --hard c0 &&
+       test_config merge.ff false &&
+       test_config pull.ff true &&
+       git pull . c1 &&
+       test "$(git rev-parse HEAD)" = "$(git rev-parse c1)"
+'
+
 test_expect_success 'fast-forward pull creates merge with "false" in pull.ff' '
        git reset --hard c0 &&
        test_config pull.ff false &&
index 32895e5acba8d246539d3bd97fe7305827f18aa7..16f1442c1e6e4780dc10474a3fbf516841468c9f 100755 (executable)
@@ -191,12 +191,24 @@ test_expect_success 'indent of line numbers, ten lines' '
        test $(grep -c "  " actual) = 9
 '
 
-test_expect_success 'blaming files with CRLF newlines' '
+test_expect_success 'setup file with CRLF newlines' '
        git config core.autocrlf false &&
-       printf "testcase\r\n" >crlffile &&
+       printf "testcase\n" >crlffile &&
        git add crlffile &&
        git commit -m testcase &&
-       git -c core.autocrlf=input blame crlffile >actual &&
+       printf "testcase\r\n" >crlffile
+'
+
+test_expect_success 'blame file with CRLF core.autocrlf true' '
+       git config core.autocrlf true &&
+       git blame crlffile >actual &&
+       grep "A U Thor" actual
+'
+
+test_expect_success 'blame file with CRLF attributes text' '
+       git config core.autocrlf false &&
+       echo "crlffile text" >.gitattributes &&
+       git blame crlffile >actual &&
        grep "A U Thor" actual
 '
 
index 1e266efffff6880929fdf2a35209511c5cefcba2..d00df0873135a8efcf0edb92cd397b92ab7d06f0 100755 (executable)
@@ -496,7 +496,7 @@ test_expect_success 'check [cvswork3] diff' '
 '
 
 test_expect_success 'merge early [cvswork3] b3 with b1' '
-       ( cd gitwork3 && git merge "message" HEAD b1 ) &&
+       ( cd gitwork3 && git merge -m "message" b1 ) &&
        git fetch gitwork3 b3:b3 &&
        git tag v3merged b3 &&
        git push --tags gitcvs.git b3:b3
index 2bf142d09c784a0c2aac8d814674684a20a7c93b..0aafd03334125d1af23acdff3f396b1bdabaf6c1 100755 (executable)
@@ -504,6 +504,112 @@ test_expect_success 'use-client-spec detect-branches skips files in branches' '
        )
 '
 
+test_expect_success 'restart p4d' '
+       kill_p4d &&
+       start_p4d
+'
+
+#
+# 1: //depot/branch1/base/file1
+#    //depot/branch1/base/file2
+#    //depot/branch1/base/dir/sub_file1
+# 2: integrate //depot/branch1/base/... -> //depot/branch2/base/...
+# 3: //depot/branch1/base/file3
+# 4: //depot/branch1/base/file2 (edit)
+# 5: integrate //depot/branch1/base/... -> //depot/branch3/base/...
+#
+# Note: the client view removes the "base" folder from the workspace
+#       and moves sub_file1 one level up.
+test_expect_success 'add simple p4 branches with common base folder on each branch' '
+       (
+               cd "$cli" &&
+               client_view "//depot/branch1/base/... //client/branch1/..." \
+                           "//depot/branch1/base/dir/sub_file1 //client/branch1/sub_file1" \
+                           "//depot/branch2/base/... //client/branch2/..." \
+                           "//depot/branch3/base/... //client/branch3/..." &&
+               mkdir -p branch1 &&
+               cd branch1 &&
+               echo file1 >file1 &&
+               echo file2 >file2 &&
+               mkdir dir &&
+               echo sub_file1 >sub_file1 &&
+               p4 add file1 file2 sub_file1 &&
+               p4 submit -d "Create branch1" &&
+               p4 integrate //depot/branch1/base/... //depot/branch2/base/... &&
+               p4 submit -d "Integrate branch2 from branch1" &&
+               echo file3 >file3 &&
+               p4 add file3 &&
+               p4 submit -d "add file3 in branch1" &&
+               p4 open file2 &&
+               echo update >>file2 &&
+               p4 submit -d "update file2 in branch1" &&
+               p4 integrate //depot/branch1/base/... //depot/branch3/base/... &&
+               p4 submit -d "Integrate branch3 from branch1"
+       )
+'
+
+# Configure branches through git-config and clone them.
+# All files are tested to make sure branches were cloned correctly.
+# Finally, make an update to branch1 on P4 side to check if it is imported
+# correctly by git p4.
+# git p4 is expected to use the client view to also not include the common
+# "base" folder in the imported directory structure.
+test_expect_success 'git p4 clone simple branches with base folder on server side' '
+       test_create_repo "$git" &&
+       (
+               cd "$git" &&
+               git config git-p4.branchList branch1:branch2 &&
+               git config --add git-p4.branchList branch1:branch3 &&
+               git p4 clone --dest=. --use-client-spec  --detect-branches //depot@all &&
+               git log --all --graph --decorate --stat &&
+               git reset --hard p4/depot/branch1 &&
+               test -f file1 &&
+               test -f file2 &&
+               test -f file3 &&
+               test -f sub_file1 &&
+               grep update file2 &&
+               git reset --hard p4/depot/branch2 &&
+               test -f file1 &&
+               test -f file2 &&
+               test ! -f file3 &&
+               test -f sub_file1 &&
+               ! grep update file2 &&
+               git reset --hard p4/depot/branch3 &&
+               test -f file1 &&
+               test -f file2 &&
+               test -f file3 &&
+               test -f sub_file1 &&
+               grep update file2 &&
+               cd "$cli" &&
+               cd branch1 &&
+               p4 edit file2 &&
+               echo file2_ >>file2 &&
+               p4 submit -d "update file2 in branch1" &&
+               cd "$git" &&
+               git reset --hard p4/depot/branch1 &&
+               git p4 rebase &&
+               grep file2_ file2
+       )
+'
+
+# Now update a file in one of the branches in git and submit to P4
+test_expect_success 'Update a file in git side and submit to P4 using client view' '
+       test_when_finished cleanup_git &&
+       (
+               cd "$git" &&
+               git reset --hard p4/depot/branch1 &&
+               echo "client spec" >> file1 &&
+               git add -u . &&
+               git commit -m "update file1 in branch1" &&
+               git config git-p4.skipSubmitEdit true &&
+               git p4 submit --verbose &&
+               cd "$cli" &&
+               p4 sync ... &&
+               cd branch1 &&
+               grep "client spec" file1
+       )
+'
+
 test_expect_success 'kill p4d' '
        kill_p4d
 '
index 99bb71b89c3c99fff5785e79973b68a826925b22..c89992cf95c7fab5b876f98bb5518bfe39344f4a 100755 (executable)
@@ -226,14 +226,9 @@ test_expect_success 'detect copies' '
 
 # See if configurables can be set, and in particular if the run.move.allow
 # variable exists, which allows admins to disable the "p4 move" command.
-test_expect_success 'p4 configure command and run.move.allow are available' '
-       p4 configure show run.move.allow >out ; retval=$? &&
-       test $retval = 0 &&
-       {
-               egrep ^run.move.allow: out &&
-               test_set_prereq P4D_HAVE_CONFIGURABLE_RUN_MOVE_ALLOW ||
-               true
-       } || true
+test_lazy_prereq P4D_HAVE_CONFIGURABLE_RUN_MOVE_ALLOW '
+       p4 configure show run.move.allow >out &&
+       egrep ^run.move.allow: out
 '
 
 # If move can be disabled, turn it off and test p4 move handling
index e71e54334314ba46fbb75a46f57a6b49216382ad..d048bd33fa3c94402eb750b65553f72b955aa25f 100755 (executable)
@@ -35,13 +35,13 @@ test_expect_success 'edit with lock not taken' '
        )
 '
 
-test_expect_failure 'add with lock not taken' '
+test_expect_success 'add with lock not taken' '
        test_when_finished cleanup_git &&
        git p4 clone --dest="$git" //depot &&
        (
                cd "$git" &&
                echo line1 >>add-lock-not-taken &&
-               git add file2 &&
+               git add add-lock-not-taken &&
                git commit -m "add add-lock-not-taken" &&
                git config git-p4.skipSubmitEdit true &&
                git p4 submit --verbose
@@ -107,7 +107,7 @@ test_expect_failure 'chmod with lock taken' '
        )
 '
 
-test_expect_failure 'copy with lock taken' '
+test_expect_success 'copy with lock taken' '
        lock_in_another_client &&
        test_when_finished cleanup_git &&
        test_when_finished "cd \"$cli\" && p4 revert file2 && rm -f file2" &&
@@ -130,8 +130,8 @@ test_expect_failure 'move with lock taken' '
        git p4 clone --dest="$git" //depot &&
        (
                cd "$git" &&
-               git mv file1 file2 &&
-               git commit -m "mv file1 to file2" &&
+               git mv file1 file3 &&
+               git commit -m "mv file1 to file3" &&
                git config git-p4.skipSubmitEdit true &&
                git config git-p4.detectRenames true &&
                git p4 submit --verbose
diff --git a/t/t9818-git-p4-block.sh b/t/t9818-git-p4-block.sh
new file mode 100755 (executable)
index 0000000..153b20a
--- /dev/null
@@ -0,0 +1,64 @@
+#!/bin/sh
+
+test_description='git p4 fetching changes in multiple blocks'
+
+. ./lib-git-p4.sh
+
+test_expect_success 'start p4d' '
+       start_p4d
+'
+
+test_expect_success 'Create a repo with ~100 changes' '
+       (
+               cd "$cli" &&
+               >file.txt &&
+               p4 add file.txt &&
+               p4 submit -d "Add file.txt" &&
+               for i in $(test_seq 0 9)
+               do
+                       >outer$i.txt &&
+                       p4 add outer$i.txt &&
+                       p4 submit -d "Adding outer$i.txt" &&
+                       for j in $(test_seq 0 9)
+                       do
+                               p4 edit file.txt &&
+                               echo $i$j >file.txt &&
+                               p4 submit -d "Commit $i$j" || exit
+                       done || exit
+               done
+       )
+'
+
+test_expect_success 'Clone the repo' '
+       git p4 clone --dest="$git" --changes-block-size=10 --verbose //depot@all
+'
+
+test_expect_success 'All files are present' '
+       echo file.txt >expected &&
+       test_write_lines outer0.txt outer1.txt outer2.txt outer3.txt outer4.txt >>expected &&
+       test_write_lines outer5.txt outer6.txt outer7.txt outer8.txt outer9.txt >>expected &&
+       ls "$git" >current &&
+       test_cmp expected current
+'
+
+test_expect_success 'file.txt is correct' '
+       echo 99 >expected &&
+       test_cmp expected "$git/file.txt"
+'
+
+test_expect_success 'Correct number of commits' '
+       (cd "$git" && git log --oneline) >log &&
+       test_line_count = 111 log
+'
+
+test_expect_success 'Previous version of file.txt is correct' '
+       (cd "$git" && git checkout HEAD^^) &&
+       echo 97 >expected &&
+       test_cmp expected "$git/file.txt"
+'
+
+test_expect_success 'kill p4d' '
+       kill_p4d
+'
+
+test_done
diff --git a/t/t9819-git-p4-case-folding.sh b/t/t9819-git-p4-case-folding.sh
new file mode 100755 (executable)
index 0000000..78f1d0f
--- /dev/null
@@ -0,0 +1,54 @@
+#!/bin/sh
+
+test_description='interaction with P4 case-folding'
+
+. ./lib-git-p4.sh
+
+test_expect_success 'start p4d with case folding enabled' '
+       start_p4d -C1
+'
+
+test_expect_success 'Create a repo, name is lowercase' '
+       (
+               client_view "//depot/... //client/..." &&
+               cd "$cli" &&
+               mkdir -p lc UC &&
+               >lc/file.txt && >UC/file.txt &&
+               p4 add lc/file.txt UC/file.txt &&
+               p4 submit -d "Add initial lc and UC repos"
+       )
+'
+
+test_expect_success 'Check p4 is in case-folding mode' '
+       (
+               cd "$cli" &&
+               >lc/FILE.TXT &&
+               p4 add lc/FILE.TXT &&
+               test_must_fail p4 submit -d "Cannot add file differing only in case" lc/FILE.TXT
+       )
+'
+
+# Check we created the repo properly
+test_expect_success 'Clone lc repo using lc name' '
+       git p4 clone //depot/lc/... &&
+       test_path_is_file lc/file.txt &&
+       git p4 clone //depot/UC/... &&
+       test_path_is_file UC/file.txt
+'
+
+# The clone should fail, since there is no repo called LC, but because
+# we have case-insensitive p4d enabled, it appears to go ahead and work,
+# but leaves an empty git repo in place.
+test_expect_failure 'Clone lc repo using uc name' '
+       test_must_fail git p4 clone //depot/LC/...
+'
+
+test_expect_failure 'Clone UC repo with lc name' '
+       test_must_fail git p4 clone //depot/uc/...
+'
+
+test_expect_success 'kill p4d' '
+       kill_p4d
+'
+
+test_done
index 4a14a5892e9ac06c967e17a4db68e57b06313c18..2ba62fbc178e1c92dff493beebdc9683b36efd2a 100755 (executable)
@@ -370,6 +370,40 @@ test_expect_success '__git_remotes - list remotes from $GIT_DIR/remotes and from
        test_cmp expect actual
 '
 
+test_expect_success '__git_get_config_variables' '
+       cat >expect <<-EOF &&
+       name-1
+       name-2
+       EOF
+       test_config interesting.name-1 good &&
+       test_config interesting.name-2 good &&
+       test_config subsection.interesting.name-3 bad &&
+       __git_get_config_variables interesting >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success '__git_pretty_aliases' '
+       cat >expect <<-EOF &&
+       author
+       hash
+       EOF
+       test_config pretty.author "%an %ae" &&
+       test_config pretty.hash %H &&
+       __git_pretty_aliases >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success '__git_aliases' '
+       cat >expect <<-EOF &&
+       ci
+       co
+       EOF
+       test_config alias.ci commit &&
+       test_config alias.co checkout &&
+       __git_aliases >actual &&
+       test_cmp expect actual
+'
+
 test_expect_success 'basic' '
        run_completion "git " &&
        # built-in
index 8f8858a5f0a4f7a705960cef5b5558064a86ea28..e8d3c0fdbc76d93ea18f6da1c869fc963e7ca81d 100644 (file)
@@ -348,11 +348,18 @@ test_declared_prereq () {
        return 1
 }
 
+test_verify_prereq () {
+       test -z "$test_prereq" ||
+       expr >/dev/null "$test_prereq" : '[A-Z0-9_,!]*$' ||
+       error "bug in the test script: '$test_prereq' does not look like a prereq"
+}
+
 test_expect_failure () {
        test_start_
        test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
        test "$#" = 2 ||
        error "bug in the test script: not 2 or 3 parameters to test-expect-failure"
+       test_verify_prereq
        export test_prereq
        if ! test_skip "$@"
        then
@@ -372,6 +379,7 @@ test_expect_success () {
        test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
        test "$#" = 2 ||
        error "bug in the test script: not 2 or 3 parameters to test-expect-success"
+       test_verify_prereq
        export test_prereq
        if ! test_skip "$@"
        then
@@ -400,6 +408,7 @@ test_external () {
        error >&5 "bug in the test script: not 3 or 4 parameters to test_external"
        descr="$1"
        shift
+       test_verify_prereq
        export test_prereq
        if ! test_skip "$descr" "$@"
        then
index 4ea99a209d74d7d052a880a2a69d99a65a9dd0a6..39da9c2d9950848cf97686656d80f0f7ad5e3548 100644 (file)
@@ -529,7 +529,7 @@ test_run_ () {
        test_cleanup=:
        expecting_failure=$2
 
-       if test "${GIT_TEST_CHAIN_LINT:-0}" != 0; then
+       if test "${GIT_TEST_CHAIN_LINT:-1}" != 0; then
                # 117 is magic because it is unlikely to match the exit
                # code of other programs
                test_eval_ "(exit 117) && $1"
index 8b2a2fe84feaeaba56953d6d4d0d649b3cf755eb..a5d7b84a673458d14d9aab082183a1968c2c7492 100755 (executable)
@@ -10,6 +10,6 @@
 # To enable this hook, rename this file to "applypatch-msg".
 
 . git-sh-setup
-test -x "$GIT_DIR/hooks/commit-msg" &&
-       exec "$GIT_DIR/hooks/commit-msg" ${1+"$@"}
+commitmsg="$(git rev-parse --git-path hooks/commit-msg)"
+test -x "$commitmsg" && exec "$commitmsg" ${1+"$@"}
 :
index b1f187c2e9acaba942639bca90a63c5b4f058967..4142082bcb939bbc17985a69ba748491ac6b62a5 100755 (executable)
@@ -9,6 +9,6 @@
 # To enable this hook, rename this file to "pre-applypatch".
 
 . git-sh-setup
-test -x "$GIT_DIR/hooks/pre-commit" &&
-       exec "$GIT_DIR/hooks/pre-commit" ${1+"$@"}
+precommit="$(git rev-parse --git-path hooks/pre-commit)"
+test -x "$precommit" && exec "$precommit" ${1+"$@"}
 :
diff --git a/test-dump-untracked-cache.c b/test-dump-untracked-cache.c
new file mode 100644 (file)
index 0000000..25d855d
--- /dev/null
@@ -0,0 +1,62 @@
+#include "cache.h"
+#include "dir.h"
+
+static int compare_untracked(const void *a_, const void *b_)
+{
+       const char *const *a = a_;
+       const char *const *b = b_;
+       return strcmp(*a, *b);
+}
+
+static int compare_dir(const void *a_, const void *b_)
+{
+       const struct untracked_cache_dir *const *a = a_;
+       const struct untracked_cache_dir *const *b = b_;
+       return strcmp((*a)->name, (*b)->name);
+}
+
+static void dump(struct untracked_cache_dir *ucd, struct strbuf *base)
+{
+       int i, len;
+       qsort(ucd->untracked, ucd->untracked_nr, sizeof(*ucd->untracked),
+             compare_untracked);
+       qsort(ucd->dirs, ucd->dirs_nr, sizeof(*ucd->dirs),
+             compare_dir);
+       len = base->len;
+       strbuf_addf(base, "%s/", ucd->name);
+       printf("%s %s", base->buf,
+              sha1_to_hex(ucd->exclude_sha1));
+       if (ucd->recurse)
+               fputs(" recurse", stdout);
+       if (ucd->check_only)
+               fputs(" check_only", stdout);
+       if (ucd->valid)
+               fputs(" valid", stdout);
+       printf("\n");
+       for (i = 0; i < ucd->untracked_nr; i++)
+               printf("%s\n", ucd->untracked[i]);
+       for (i = 0; i < ucd->dirs_nr; i++)
+               dump(ucd->dirs[i], base);
+       strbuf_setlen(base, len);
+}
+
+int main(int ac, char **av)
+{
+       struct untracked_cache *uc;
+       struct strbuf base = STRBUF_INIT;
+       setup_git_directory();
+       if (read_cache() < 0)
+               die("unable to read index file");
+       uc = the_index.untracked;
+       if (!uc) {
+               printf("no untracked cache\n");
+               return 0;
+       }
+       printf("info/exclude %s\n", sha1_to_hex(uc->ss_info_exclude.sha1));
+       printf("core.excludesfile %s\n", sha1_to_hex(uc->ss_excludes_file.sha1));
+       printf("exclude_per_dir %s\n", uc->exclude_per_dir);
+       printf("flags %08x\n", uc->dir_flags);
+       if (uc->root)
+               dump(uc->root, &base);
+       return 0;
+}
diff --git a/trace.c b/trace.c
index 1dc5c7c912d000699b753b1aab5c09a114e26557..3c3bd8fc98742075d6adc673ed2abc4f7e715b62 100644 (file)
--- a/trace.c
+++ b/trace.c
@@ -310,6 +310,7 @@ void trace_repo_setup(const char *prefix)
                prefix = "(null)";
 
        trace_printf_key(&key, "setup: git_dir: %s\n", quote_crnl(get_git_dir()));
+       trace_printf_key(&key, "setup: git_common_dir: %s\n", quote_crnl(get_git_common_dir()));
        trace_printf_key(&key, "setup: worktree: %s\n", quote_crnl(git_work_tree));
        trace_printf_key(&key, "setup: cwd: %s\n", quote_crnl(cwd));
        trace_printf_key(&key, "setup: prefix: %s\n", quote_crnl(prefix));
index eca9b8c817bd723532d7f92da8cfa9f8ee82bb43..f080e93dcd50e5f2329b180bae93c59a461810f8 100644 (file)
@@ -283,7 +283,6 @@ static int write_one_ref(const char *name, const unsigned char *sha1,
 {
        struct strbuf *buf = data;
        int len = buf->len;
-       FILE *f;
 
        /* when called via for_each_ref(), flags is non-zero */
        if (flags && !starts_with(name, "refs/heads/") &&
@@ -292,10 +291,9 @@ static int write_one_ref(const char *name, const unsigned char *sha1,
 
        strbuf_addstr(buf, name);
        if (safe_create_leading_directories(buf->buf) ||
-                       !(f = fopen(buf->buf, "w")) ||
-                       fprintf(f, "%s\n", sha1_to_hex(sha1)) < 0 ||
-                       fclose(f))
-               return error("problems writing temporary file %s", buf->buf);
+           write_file(buf->buf, 0, "%s\n", sha1_to_hex(sha1)))
+               return error("problems writing temporary file %s: %s",
+                            buf->buf, strerror(errno));
        strbuf_setlen(buf, len);
        return 0;
 }
index e7b378c8b2c8f145519410bb17811bf60eb29384..290a1da4ce5c3504dd75e584030a4a00fbdbe9a2 100644 (file)
@@ -64,7 +64,7 @@ static int emit_diff_first_parent_only(struct diff_options *opt, struct combine_
 {
        struct combine_diff_parent *p0 = &p->parent[0];
        if (p->mode && p0->mode) {
-               opt->change(opt, p0->mode, p->mode, p0->sha1, p->sha1,
+               opt->change(opt, p0->mode, p->mode, p0->oid.hash, p->oid.hash,
                        1, 1, p->path, 0, 0);
        }
        else {
@@ -74,11 +74,11 @@ static int emit_diff_first_parent_only(struct diff_options *opt, struct combine_
 
                if (p->mode) {
                        addremove = '+';
-                       sha1 = p->sha1;
+                       sha1 = p->oid.hash;
                        mode = p->mode;
                } else {
                        addremove = '-';
-                       sha1 = p0->sha1;
+                       sha1 = p0->oid.hash;
                        mode = p0->mode;
                }
 
@@ -151,7 +151,7 @@ static struct combine_diff_path *path_appendnew(struct combine_diff_path *last,
        memcpy(p->path + base->len, path, pathlen);
        p->path[len] = 0;
        p->mode = mode;
-       hashcpy(p->sha1, sha1 ? sha1 : null_sha1);
+       hashcpy(p->oid.hash, sha1 ? sha1 : null_sha1);
 
        return p;
 }
@@ -238,7 +238,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,
                        }
 
                        p->parent[i].mode = mode_i;
-                       hashcpy(p->parent[i].sha1, sha1_i ? sha1_i : null_sha1);
+                       hashcpy(p->parent[i].oid.hash, sha1_i ? sha1_i : null_sha1);
                }
 
                keep = 1;
index be84ba2607ad2dbdb17397869c459418abad78e4..2927660d929eee776d43a87851a928df12b17716 100644 (file)
@@ -9,6 +9,7 @@
 #include "refs.h"
 #include "attr.h"
 #include "split-index.h"
+#include "dir.h"
 
 /*
  * Error messages expected by scripts out of plumbing commands such as
@@ -1259,8 +1260,10 @@ static int verify_uptodate_sparse(const struct cache_entry *ce,
 static void invalidate_ce_path(const struct cache_entry *ce,
                               struct unpack_trees_options *o)
 {
-       if (ce)
-               cache_tree_invalidate_path(o->src_index, ce->name);
+       if (!ce)
+               return;
+       cache_tree_invalidate_path(o->src_index, ce->name);
+       untracked_cache_invalidate_path(o->src_index, ce->name);
 }
 
 /*
index aa845765009ac7fb9105851306c3288b3f602369..745fda8515313fa0629489f36aee0ba49fb7d822 100644 (file)
@@ -74,7 +74,7 @@ static int write_one_shallow(const struct commit_graft *graft, void *cb_data)
 {
        FILE *fp = cb_data;
        if (graft->nr_parent == -1)
-               fprintf(fp, "--shallow %s\n", sha1_to_hex(graft->sha1));
+               fprintf(fp, "--shallow %s\n", oid_to_hex(&graft->oid));
        return 0;
 }
 
index d5a6cef2be0fb13b262bed2e0b58bd58fbb5454d..c1a663fd592133b3e26314f3d598a8bca8bcceb1 100644 (file)
--- a/wrapper.c
+++ b/wrapper.c
@@ -564,3 +564,34 @@ char *xgetcwd(void)
                die_errno(_("unable to get current working directory"));
        return strbuf_detach(&sb, NULL);
 }
+
+int write_file(const char *path, int fatal, const char *fmt, ...)
+{
+       struct strbuf sb = STRBUF_INIT;
+       va_list params;
+       int fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0666);
+       if (fd < 0) {
+               if (fatal)
+                       die_errno(_("could not open %s for writing"), path);
+               return -1;
+       }
+       va_start(params, fmt);
+       strbuf_vaddf(&sb, fmt, params);
+       va_end(params);
+       if (write_in_full(fd, sb.buf, sb.len) != sb.len) {
+               int err = errno;
+               close(fd);
+               strbuf_release(&sb);
+               errno = err;
+               if (fatal)
+                       die_errno(_("could not write to %s"), path);
+               return -1;
+       }
+       strbuf_release(&sb);
+       if (close(fd)) {
+               if (fatal)
+                       die_errno(_("could not close %s"), path);
+               return -1;
+       }
+       return 0;
+}
index 38cb165f124d610c789a8d82de42281c795111f7..33452f169dfca7a3cd4f15b1c3cdc91a3cf40735 100644 (file)
@@ -585,6 +585,8 @@ static void wt_status_collect_untracked(struct wt_status *s)
                        DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES;
        if (s->show_ignored_files)
                dir.flags |= DIR_SHOW_IGNORED_TOO;
+       else
+               dir.untracked = the_index.untracked;
        setup_standard_excludes(&dir);
 
        fill_directory(&dir, &s->pathspec);