Merge branch 'jk/test-shell-trace'
authorJunio C Hamano <gitster@pobox.com>
Mon, 20 Oct 2014 19:23:40 +0000 (12:23 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 20 Oct 2014 19:23:40 +0000 (12:23 -0700)
Test scripts were taught to notice "-x" option to show shell trace,
as if the tests were run under "sh -x".

* jk/test-shell-trace:
test-lib.sh: support -x option for shell-tracing
t5304: use helper to report failure of "test foo = bar"
t5304: use test_path_is_* instead of "test -f"

84 files changed:
.gitignore
Documentation/Makefile
Documentation/RelNotes/2.2.0.txt
Documentation/everyday.txt [deleted file]
Documentation/everyday.txto [new file with mode: 0644]
Documentation/git-imap-send.txt
Documentation/git-prune-packed.txt
Documentation/git-push.txt
Documentation/git-quiltimport.txt
Documentation/git-rebase.txt
Documentation/git-stage.txt
Documentation/git.txt
Documentation/gitcore-tutorial.txt
Documentation/gitcvs-migration.txt
Documentation/giteveryday.txt [new file with mode: 0644]
Documentation/gitglossary.txt
Documentation/gittutorial-2.txt
Documentation/gittutorial.txt
Documentation/pretty-formats.txt
Documentation/technical/api-lockfile.txt
Makefile
README
archive-tar.c
builtin/add.c
builtin/apply.c
builtin/branch.c
builtin/cat-file.c
builtin/checkout-index.c
builtin/checkout.c
builtin/clean.c
builtin/clone.c
builtin/commit.c
builtin/describe.c
builtin/diff.c
builtin/gc.c
builtin/get-tar-commit-id.c
builtin/help.c
builtin/log.c
builtin/mailsplit.c
builtin/merge.c
builtin/mv.c
builtin/read-tree.c
builtin/receive-pack.c
builtin/reflog.c
builtin/remote-ext.c
builtin/reset.c
builtin/rm.c
builtin/update-index.c
bulk-checkin.c
bulk-checkin.h
bundle.c
cache-tree.c
cache.h
config.c
contrib/completion/git-completion.bash
credential-store.c
daemon.c
fast-import.c
fetch-pack.c
http.c
lockfile.c
lockfile.h [new file with mode: 0644]
merge-recursive.c
merge.c
pretty.c
read-cache.c
refs.c
rerere.c
sequencer.c
sha1-lookup.c
sha1_file.c
shallow.c
sigchain.c
t/t0064-sha1-array.sh [new file with mode: 0755]
t/t0090-cache-tree.sh
t/t5004-archive-corner-cases.sh
t/t7004-tag.sh
test-regex.c
test-scrap-cache-tree.c
test-sha1-array.c [new file with mode: 0644]
test-sigchain.c
trace.c
varint.c
varint.h
index 5bfb234591a63446d9fccf7665e442f02d1c76b5..9ec40fa9fbc645532c9bc36b65521e6771d14324 100644 (file)
 /test-revision-walking
 /test-run-command
 /test-sha1
+/test-sha1-array
 /test-sigchain
 /test-string-list
 /test-subprocess
index cea0e7ae3db37dcd366e094abdd2a2f32514a247..8d0f70938e6d6f04c9edfb9a3ec8ef45d38502c5 100644 (file)
@@ -5,6 +5,7 @@ MAN7_TXT =
 TECH_DOCS =
 ARTICLES =
 SP_ARTICLES =
+OBSOLETE_HTML =
 
 MAN1_TXT += $(filter-out \
                $(addsuffix .txt, $(ARTICLES) $(SP_ARTICLES)), \
@@ -26,6 +27,7 @@ MAN7_TXT += gitcore-tutorial.txt
 MAN7_TXT += gitcredentials.txt
 MAN7_TXT += gitcvs-migration.txt
 MAN7_TXT += gitdiffcore.txt
+MAN7_TXT += giteveryday.txt
 MAN7_TXT += gitglossary.txt
 MAN7_TXT += gitnamespaces.txt
 MAN7_TXT += gitrevisions.txt
@@ -37,11 +39,11 @@ MAN_TXT = $(MAN1_TXT) $(MAN5_TXT) $(MAN7_TXT)
 MAN_XML = $(patsubst %.txt,%.xml,$(MAN_TXT))
 MAN_HTML = $(patsubst %.txt,%.html,$(MAN_TXT))
 
-OBSOLETE_HTML = git-remote-helpers.html
+OBSOLETE_HTML += everyday.html
+OBSOLETE_HTML += git-remote-helpers.html
 DOC_HTML = $(MAN_HTML) $(OBSOLETE_HTML)
 
 ARTICLES += howto-index
-ARTICLES += everyday
 ARTICLES += git-tools
 ARTICLES += git-bisect-lk2009
 # with their own formatting rules.
index 5f0c421365d52134030d14580258059b27a536b9..95891765a139ffe6e2bd8fa524c61f2018dcb432 100644 (file)
@@ -65,6 +65,8 @@ Performance, Internal Implementation, etc.
    all-or-none atomic updates and migrating the storage to something
    other than the traditional filesystem based one (e.g. databases).
 
+ * The lockfile API and its users have been cleaned up.
+
  * We no longer attempt to keep track of individual dependencies to
    the header files in the build procedure, relying on automated
    dependency generation support from modern compilers.
@@ -164,6 +166,11 @@ notes for details).
  * "git checkout -m" did not switch to another branch while carrying
    the local changes forward when a path was deleted from the index.
 
+ * "git daemon" (with NO_IPV6 build configuration) used to incorrectly
+   use the hostname even when gethostbyname() reported that the given
+   hostname is not found.
+   (merge 107efbe rs/daemon-fixes later to maint).
+
  * With sufficiently long refnames, "git fast-import" could have
    overflown an on-stack buffer.
 
@@ -215,3 +222,17 @@ notes for details).
  * "rev-parse --verify --quiet $name" is meant to quietly exit with a
    non-zero status when $name is not a valid object name, but still
    gave error messages in some cases.
+
+ * A handful of C source files have been updated to include
+   "git-compat-util.h" as the first thing, to conform better to our
+   coding guidelines.
+   (merge 1c4b660 da/include-compat-util-first-in-c later to maint).
+
+ * t7004 test, which tried to run Git with small stack space, has been
+   updated to give a bit larger stack to avoid false breakage on some
+   platforms.
+   (merge b9a1907 sk/tag-contains-wo-recursion later to maint).
+
+ * A few documentation pages had example sections marked up not quite
+   correctly, which passed AsciiDoc but failed with AsciiDoctor.
+   (merge c30c43c bc/asciidoc-pretty-formats-fix later to maint).
diff --git a/Documentation/everyday.txt b/Documentation/everyday.txt
deleted file mode 100644 (file)
index b2548ef..0000000
+++ /dev/null
@@ -1,413 +0,0 @@
-Everyday Git With 20 Commands Or So
-===================================
-
-<<Individual Developer (Standalone)>> commands are essential for
-anybody who makes a commit, even for somebody who works alone.
-
-If you work with other people, you will need commands listed in
-the <<Individual Developer (Participant)>> section as well.
-
-People who play the <<Integrator>> role need to learn some more
-commands in addition to the above.
-
-<<Repository Administration>> commands are for system
-administrators who are responsible for the care and feeding
-of Git repositories.
-
-
-Individual Developer (Standalone)[[Individual Developer (Standalone)]]
-----------------------------------------------------------------------
-
-A standalone individual developer does not exchange patches with
-other people, and works alone in a single repository, using the
-following commands.
-
-  * linkgit:git-init[1] to create a new repository.
-
-  * linkgit:git-show-branch[1] to see where you are.
-
-  * linkgit:git-log[1] to see what happened.
-
-  * linkgit:git-checkout[1] and linkgit:git-branch[1] to switch
-    branches.
-
-  * linkgit:git-add[1] to manage the index file.
-
-  * linkgit:git-diff[1] and linkgit:git-status[1] to see what
-    you are in the middle of doing.
-
-  * linkgit:git-commit[1] to advance the current branch.
-
-  * linkgit:git-reset[1] and linkgit:git-checkout[1] (with
-    pathname parameters) to undo changes.
-
-  * linkgit:git-merge[1] to merge between local branches.
-
-  * linkgit:git-rebase[1] to maintain topic branches.
-
-  * linkgit:git-tag[1] to mark known point.
-
-Examples
-~~~~~~~~
-
-Use a tarball as a starting point for a new repository.::
-+
-------------
-$ tar zxf frotz.tar.gz
-$ cd frotz
-$ git init
-$ git add . <1>
-$ git commit -m "import of frotz source tree."
-$ git tag v2.43 <2>
-------------
-+
-<1> add everything under the current directory.
-<2> make a lightweight, unannotated tag.
-
-Create a topic branch and develop.::
-+
-------------
-$ git checkout -b alsa-audio <1>
-$ edit/compile/test
-$ git checkout -- curses/ux_audio_oss.c <2>
-$ git add curses/ux_audio_alsa.c <3>
-$ edit/compile/test
-$ git diff HEAD <4>
-$ git commit -a -s <5>
-$ edit/compile/test
-$ git reset --soft HEAD^ <6>
-$ edit/compile/test
-$ git diff ORIG_HEAD <7>
-$ git commit -a -c ORIG_HEAD <8>
-$ git checkout master <9>
-$ git merge alsa-audio <10>
-$ git log --since='3 days ago' <11>
-$ git log v2.43.. curses/ <12>
-------------
-+
-<1> create a new topic branch.
-<2> revert your botched changes in `curses/ux_audio_oss.c`.
-<3> you need to tell Git if you added a new file; removal and
-modification will be caught if you do `git commit -a` later.
-<4> to see what changes you are committing.
-<5> commit everything as you have tested, with your sign-off.
-<6> take the last commit back, keeping what is in the working tree.
-<7> look at the changes since the premature commit we took back.
-<8> redo the commit undone in the previous step, using the message
-you originally wrote.
-<9> switch to the master branch.
-<10> merge a topic branch into your master branch.
-<11> review commit logs; other forms to limit output can be
-combined and include `--max-count=10` (show 10 commits),
-`--until=2005-12-10`, etc.
-<12> view only the changes that touch what's in `curses/`
-directory, since `v2.43` tag.
-
-
-Individual Developer (Participant)[[Individual Developer (Participant)]]
-------------------------------------------------------------------------
-
-A developer working as a participant in a group project needs to
-learn how to communicate with others, and uses these commands in
-addition to the ones needed by a standalone developer.
-
-  * linkgit:git-clone[1] from the upstream to prime your local
-    repository.
-
-  * linkgit:git-pull[1] and linkgit:git-fetch[1] from "origin"
-    to keep up-to-date with the upstream.
-
-  * linkgit:git-push[1] to shared repository, if you adopt CVS
-    style shared repository workflow.
-
-  * linkgit:git-format-patch[1] to prepare e-mail submission, if
-    you adopt Linux kernel-style public forum workflow.
-
-Examples
-~~~~~~~~
-
-Clone the upstream and work on it.  Feed changes to upstream.::
-+
-------------
-$ git clone git://git.kernel.org/pub/scm/.../torvalds/linux-2.6 my2.6
-$ cd my2.6
-$ edit/compile/test; git commit -a -s <1>
-$ git format-patch origin <2>
-$ git pull <3>
-$ git log -p ORIG_HEAD.. arch/i386 include/asm-i386 <4>
-$ git pull git://git.kernel.org/pub/.../jgarzik/libata-dev.git ALL <5>
-$ git reset --hard ORIG_HEAD <6>
-$ git gc <7>
-$ git fetch --tags <8>
-------------
-+
-<1> repeat as needed.
-<2> extract patches from your branch for e-mail submission.
-<3> `git pull` fetches from `origin` by default and merges into the
-current branch.
-<4> immediately after pulling, look at the changes done upstream
-since last time we checked, only in the
-area we are interested in.
-<5> fetch from a specific branch from a specific repository and merge.
-<6> revert the pull.
-<7> garbage collect leftover objects from reverted pull.
-<8> from time to time, obtain official tags from the `origin`
-and store them under `.git/refs/tags/`.
-
-
-Push into another repository.::
-+
-------------
-satellite$ git clone mothership:frotz frotz <1>
-satellite$ cd frotz
-satellite$ git config --get-regexp '^(remote|branch)\.' <2>
-remote.origin.url mothership:frotz
-remote.origin.fetch refs/heads/*:refs/remotes/origin/*
-branch.master.remote origin
-branch.master.merge refs/heads/master
-satellite$ git config remote.origin.push \
-           master:refs/remotes/satellite/master <3>
-satellite$ edit/compile/test/commit
-satellite$ git push origin <4>
-
-mothership$ cd frotz
-mothership$ git checkout master
-mothership$ git merge satellite/master <5>
-------------
-+
-<1> mothership machine has a frotz repository under your home
-directory; clone from it to start a repository on the satellite
-machine.
-<2> clone sets these configuration variables by default.
-It arranges `git pull` to fetch and store the branches of mothership
-machine to local `remotes/origin/*` remote-tracking branches.
-<3> arrange `git push` to push local `master` branch to
-`remotes/satellite/master` branch of the mothership machine.
-<4> push will stash our work away on `remotes/satellite/master`
-remote-tracking branch on the mothership machine.  You could use this
-as a back-up method.
-<5> on mothership machine, merge the work done on the satellite
-machine into the master branch.
-
-Branch off of a specific tag.::
-+
-------------
-$ git checkout -b private2.6.14 v2.6.14 <1>
-$ edit/compile/test; git commit -a
-$ git checkout master
-$ git format-patch -k -m --stdout v2.6.14..private2.6.14 |
-  git am -3 -k <2>
-------------
-+
-<1> create a private branch based on a well known (but somewhat behind)
-tag.
-<2> forward port all changes in `private2.6.14` branch to `master` branch
-without a formal "merging".
-
-
-Integrator[[Integrator]]
-------------------------
-
-A fairly central person acting as the integrator in a group
-project receives changes made by others, reviews and integrates
-them and publishes the result for others to use, using these
-commands in addition to the ones needed by participants.
-
-  * linkgit:git-am[1] to apply patches e-mailed in from your
-    contributors.
-
-  * linkgit:git-pull[1] to merge from your trusted lieutenants.
-
-  * linkgit:git-format-patch[1] to prepare and send suggested
-    alternative to contributors.
-
-  * linkgit:git-revert[1] to undo botched commits.
-
-  * linkgit:git-push[1] to publish the bleeding edge.
-
-
-Examples
-~~~~~~~~
-
-My typical Git day.::
-+
-------------
-$ git status <1>
-$ git show-branch <2>
-$ mailx <3>
-& s 2 3 4 5 ./+to-apply
-& s 7 8 ./+hold-linus
-& q
-$ git checkout -b topic/one master
-$ git am -3 -i -s -u ./+to-apply <4>
-$ compile/test
-$ git checkout -b hold/linus && git am -3 -i -s -u ./+hold-linus <5>
-$ git checkout topic/one && git rebase master <6>
-$ git checkout pu && git reset --hard next <7>
-$ git merge topic/one topic/two && git merge hold/linus <8>
-$ git checkout maint
-$ git cherry-pick master~4 <9>
-$ compile/test
-$ git tag -s -m "GIT 0.99.9x" v0.99.9x <10>
-$ git fetch ko && git show-branch master maint 'tags/ko-*' <11>
-$ git push ko <12>
-$ git push ko v0.99.9x <13>
-------------
-+
-<1> see what I was in the middle of doing, if any.
-<2> see what topic branches I have and think about how ready
-they are.
-<3> read mails, save ones that are applicable, and save others
-that are not quite ready.
-<4> apply them, interactively, with my sign-offs.
-<5> create topic branch as needed and apply, again with my
-sign-offs.
-<6> rebase internal topic branch that has not been merged to the
-master or exposed as a part of a stable branch.
-<7> restart `pu` every time from the next.
-<8> and bundle topic branches still cooking.
-<9> backport a critical fix.
-<10> create a signed tag.
-<11> make sure I did not accidentally rewind master beyond what I
-already pushed out.  `ko` shorthand points at the repository I have
-at kernel.org, and looks like this:
-+
-------------
-$ cat .git/remotes/ko
-URL: kernel.org:/pub/scm/git/git.git
-Pull: master:refs/tags/ko-master
-Pull: next:refs/tags/ko-next
-Pull: maint:refs/tags/ko-maint
-Push: master
-Push: next
-Push: +pu
-Push: maint
-------------
-+
-In the output from `git show-branch`, `master` should have
-everything `ko-master` has, and `next` should have
-everything `ko-next` has.
-
-<12> push out the bleeding edge.
-<13> push the tag out, too.
-
-
-Repository Administration[[Repository Administration]]
-------------------------------------------------------
-
-A repository administrator uses the following tools to set up
-and maintain access to the repository by developers.
-
-  * linkgit:git-daemon[1] to allow anonymous download from
-    repository.
-
-  * linkgit:git-shell[1] can be used as a 'restricted login shell'
-    for shared central repository users.
-
-link:howto/update-hook-example.html[update hook howto] has a good
-example of managing a shared central repository.
-
-
-Examples
-~~~~~~~~
-We assume the following in /etc/services::
-+
-------------
-$ grep 9418 /etc/services
-git            9418/tcp                # Git Version Control System
-------------
-
-Run git-daemon to serve /pub/scm from inetd.::
-+
-------------
-$ grep git /etc/inetd.conf
-git    stream  tcp     nowait  nobody \
-  /usr/bin/git-daemon git-daemon --inetd --export-all /pub/scm
-------------
-+
-The actual configuration line should be on one line.
-
-Run git-daemon to serve /pub/scm from xinetd.::
-+
-------------
-$ cat /etc/xinetd.d/git-daemon
-# default: off
-# description: The Git server offers access to Git repositories
-service git
-{
-        disable = no
-        type            = UNLISTED
-        port            = 9418
-        socket_type     = stream
-        wait            = no
-        user            = nobody
-        server          = /usr/bin/git-daemon
-        server_args     = --inetd --export-all --base-path=/pub/scm
-        log_on_failure  += USERID
-}
-------------
-+
-Check your xinetd(8) documentation and setup, this is from a Fedora system.
-Others might be different.
-
-Give push/pull only access to developers.::
-+
-------------
-$ grep git /etc/passwd <1>
-alice:x:1000:1000::/home/alice:/usr/bin/git-shell
-bob:x:1001:1001::/home/bob:/usr/bin/git-shell
-cindy:x:1002:1002::/home/cindy:/usr/bin/git-shell
-david:x:1003:1003::/home/david:/usr/bin/git-shell
-$ grep git /etc/shells <2>
-/usr/bin/git-shell
-------------
-+
-<1> log-in shell is set to /usr/bin/git-shell, which does not
-allow anything but `git push` and `git pull`.  The users should
-get an ssh access to the machine.
-<2> in many distributions /etc/shells needs to list what is used
-as the login shell.
-
-CVS-style shared repository.::
-+
-------------
-$ grep git /etc/group <1>
-git:x:9418:alice,bob,cindy,david
-$ cd /home/devo.git
-$ ls -l <2>
-  lrwxrwxrwx   1 david git    17 Dec  4 22:40 HEAD -> refs/heads/master
-  drwxrwsr-x   2 david git  4096 Dec  4 22:40 branches
-  -rw-rw-r--   1 david git    84 Dec  4 22:40 config
-  -rw-rw-r--   1 david git    58 Dec  4 22:40 description
-  drwxrwsr-x   2 david git  4096 Dec  4 22:40 hooks
-  -rw-rw-r--   1 david git 37504 Dec  4 22:40 index
-  drwxrwsr-x   2 david git  4096 Dec  4 22:40 info
-  drwxrwsr-x   4 david git  4096 Dec  4 22:40 objects
-  drwxrwsr-x   4 david git  4096 Nov  7 14:58 refs
-  drwxrwsr-x   2 david git  4096 Dec  4 22:40 remotes
-$ ls -l hooks/update <3>
-  -r-xr-xr-x   1 david git  3536 Dec  4 22:40 update
-$ cat info/allowed-users <4>
-refs/heads/master      alice\|cindy
-refs/heads/doc-update  bob
-refs/tags/v[0-9]*      david
-------------
-+
-<1> place the developers into the same git group.
-<2> and make the shared repository writable by the group.
-<3> use update-hook example by Carl from Documentation/howto/
-for branch policy control.
-<4> alice and cindy can push into master, only bob can push into doc-update.
-david is the release manager and is the only person who can
-create and push version tags.
-
-HTTP server to support dumb protocol transfer.::
-+
-------------
-dev$ git update-server-info <1>
-dev$ ftp user@isp.example.com <2>
-ftp> cp -r .git /home/user/myproject.git
-------------
-+
-<1> make sure your info/refs and objects/info/packs are up-to-date
-<2> upload to public HTTP server hosted by your ISP.
diff --git a/Documentation/everyday.txto b/Documentation/everyday.txto
new file mode 100644 (file)
index 0000000..c5047d8
--- /dev/null
@@ -0,0 +1,9 @@
+Everyday Git With 20 Commands Or So
+===================================
+
+This document has been moved to linkgit:giteveryday[1].
+
+Please let the owners of the referring site know so that they can update the
+link you clicked to get here.
+
+Thanks.
index 7d991d919ccf3378fdc924418aede45f8cb38632..c7c0d21429bb745d1abcfc775308e8ccac8f499a 100644 (file)
@@ -97,7 +97,7 @@ Using direct mode:
     host = imap://imap.example.com
     user = bob
     pass = p4ssw0rd
-..........................
+.........................
 
 Using direct mode with SSL:
 
@@ -109,7 +109,7 @@ Using direct mode with SSL:
     pass = p4ssw0rd
     port = 123
     sslverify = false
-..........................
+.........................
 
 
 EXAMPLE
index 6738055bd3083825c06c82d1b7678ef453854253..9fed59a31724c4dccd7364c03c32c72d9c8d4664 100644 (file)
@@ -1,5 +1,5 @@
 git-prune-packed(1)
-=====================
+===================
 
 NAME
 ----
index b17283ab7a1cc73c5ec741e0da1128bea2a57a65..21b3f29c3bc603df74e07226d27ad63faa6fae24 100644 (file)
@@ -34,7 +34,7 @@ When the command line does not specify what to push with `<refspec>...`
 arguments or `--all`, `--mirror`, `--tags` options, the command finds
 the default `<refspec>` by consulting `remote.*.push` configuration,
 and if it is not found, honors `push.default` configuration to decide
-what to push (See linkgit:git-config[1] for the meaning of `push.default`).
+what to push (See gitlink:git-config[1] for the meaning of `push.default`).
 
 
 OPTIONS[[OPTIONS]]
index a356196586e2cfd472e1e087fb12e981b3a1480f..d64388cb8e454be17e4c20caf95897a71619c11f 100644 (file)
@@ -1,5 +1,5 @@
 git-quiltimport(1)
-================
+==================
 
 NAME
 ----
index 4138554912165478d182d5720d4d7b4c4ab78c05..924827dc2ec79fc4df83a572dcef89425b844f81 100644 (file)
@@ -21,15 +21,17 @@ If <branch> is specified, 'git rebase' will perform an automatic
 it remains on the current branch.
 
 If <upstream> is not specified, the upstream configured in
-branch.<name>.remote and branch.<name>.merge options will be usedsee
-linkgit:git-config[1] for details.  If you are currently not on any
-branch or if the current branch does not have a configured upstream,
-the rebase will abort.
+branch.<name>.remote and branch.<name>.merge options will be used (see
+linkgit:git-config[1] for details) and the `--fork-point` option is
+assumed.  If you are currently not on any branch or if the current
+branch does not have a configured upstream, the rebase will abort.
 
 All changes made by commits in the current branch but that are not
 in <upstream> are saved to a temporary area.  This is the same set
-of commits that would be shown by `git log <upstream>..HEAD` (or
-`git log HEAD`, if --root is specified).
+of commits that would be shown by `git log <upstream>..HEAD`; or by
+`git log 'fork_point'..HEAD`, if `--fork-point` is active (see the
+description on `--fork-point` below); or by `git log HEAD`, if the
+`--root` option is specified.
 
 The current branch is reset to <upstream>, or <newbase> if the
 --onto option was supplied.  This has the exact same effect as
@@ -327,13 +329,18 @@ link:howto/revert-a-faulty-merge.html[revert-a-faulty-merge How-To] for details)
 
 --fork-point::
 --no-fork-point::
-       Use 'git merge-base --fork-point' to find a better common ancestor
-       between `upstream` and `branch` when calculating which commits have
-       have been introduced by `branch` (see linkgit:git-merge-base[1]).
+       Use reflog to find a better common ancestor between <upstream>
+       and <branch> when calculating which commits have been
+       introduced by <branch>.
 +
-If no non-option arguments are given on the command line, then the default is
-`--fork-point @{u}` otherwise the `upstream` argument is interpreted literally
-unless the `--fork-point` option is specified.
+When --fork-point is active, 'fork_point' will be used instead of
+<upstream> to calculate the set of commits to rebase, where
+'fork_point' is the result of `git merge-base --fork-point <upstream>
+<branch>` command (see linkgit:git-merge-base[1]).  If 'fork_point'
+ends up being empty, the <upstream> will be used as a fallback.
++
+If either <upstream> or --root is given on the command line, then the
+default is `--no-fork-point`, otherwise the default is `--fork-point`.
 
 --ignore-whitespace::
 --whitespace=<option>::
index ba3fe0d7f59b1ae4c9ae9e3d32675d2e281ccf13..25bcda936dbe8b171e0195a569d58ba8ce42e714 100644 (file)
@@ -1,5 +1,5 @@
 git-stage(1)
-==============
+============
 
 NAME
 ----
index c6175d45e4257efa96995853f00e42baf4b221f9..9e0a42ce5673c1fc11c311c63b5452181110fd8f 100644 (file)
@@ -22,7 +22,7 @@ unusually rich command set that provides both high-level operations
 and full access to internals.
 
 See linkgit:gittutorial[7] to get started, then see
-link:everyday.html[Everyday Git] for a useful minimum set of
+linkgit:giteveryday[7] for a useful minimum set of
 commands.  The link:user-manual.html[Git User's Manual] has a more
 in-depth introduction.
 
@@ -1098,7 +1098,7 @@ subscribed to the list to send a message there.
 SEE ALSO
 --------
 linkgit:gittutorial[7], linkgit:gittutorial-2[7],
-link:everyday.html[Everyday Git], linkgit:gitcvs-migration[7],
+linkgit:giteveryday[7], linkgit:gitcvs-migration[7],
 linkgit:gitglossary[7], linkgit:gitcore-tutorial[7],
 linkgit:gitcli[7], link:user-manual.html[The Git User's Manual],
 linkgit:gitworkflows[7]
index d2d7c213dd56f3886b7ab7e3651e1e80eec3b2ef..8475c079325103fe102027fccd5f5f02818667f3 100644 (file)
@@ -1667,7 +1667,7 @@ linkgit:gittutorial[7],
 linkgit:gittutorial-2[7],
 linkgit:gitcvs-migration[7],
 linkgit:git-help[1],
-link:everyday.html[Everyday git],
+linkgit:giteveryday[7],
 link:user-manual.html[The Git User's Manual]
 
 GIT
index 5f4e89005c5e554353920fe858bc74399e438a14..b06e852a85587ffd46820c9dfb832784cbf1dfd9 100644 (file)
@@ -194,7 +194,7 @@ linkgit:gittutorial[7],
 linkgit:gittutorial-2[7],
 linkgit:gitcore-tutorial[7],
 linkgit:gitglossary[7],
-link:everyday.html[Everyday Git],
+linkgit:giteveryday[7],
 link:user-manual.html[The Git User's Manual]
 
 GIT
diff --git a/Documentation/giteveryday.txt b/Documentation/giteveryday.txt
new file mode 100644 (file)
index 0000000..7be6e64
--- /dev/null
@@ -0,0 +1,455 @@
+giteveryday(7)
+===============
+
+NAME
+----
+giteveryday - A useful minimum set of commands for Everyday Git
+
+SYNOPSIS
+--------
+
+Everyday Git With 20 Commands Or So
+
+DESCRIPTION
+-----------
+
+Git users can broadly be grouped into four categories for the purposes of
+describing here a small set of useful command for everyday Git.
+
+*      <<STANDALONE,Individual Developer (Standalone)>> commands are essential
+       for anybody who makes a commit, even for somebody who works alone.
+
+*      If you work with other people, you will need commands listed in
+       the <<PARTICIPANT,Individual Developer (Participant)>> section as well.
+
+*      People who play the <<INTEGRATOR,Integrator>> role need to learn some
+       more commands in addition to the above.
+
+*      <<ADMINISTRATION,Repository Administration>> commands are for system
+       administrators who are responsible for the care and feeding
+       of Git repositories.
+
+
+Individual Developer (Standalone)[[STANDALONE]]
+-----------------------------------------------
+
+A standalone individual developer does not exchange patches with
+other people, and works alone in a single repository, using the
+following commands.
+
+  * linkgit:git-init[1] to create a new repository.
+
+  * linkgit:git-log[1] to see what happened.
+
+  * linkgit:git-checkout[1] and linkgit:git-branch[1] to switch
+    branches.
+
+  * linkgit:git-add[1] to manage the index file.
+
+  * linkgit:git-diff[1] and linkgit:git-status[1] to see what
+    you are in the middle of doing.
+
+  * linkgit:git-commit[1] to advance the current branch.
+
+  * linkgit:git-reset[1] and linkgit:git-checkout[1] (with
+    pathname parameters) to undo changes.
+
+  * linkgit:git-merge[1] to merge between local branches.
+
+  * linkgit:git-rebase[1] to maintain topic branches.
+
+  * linkgit:git-tag[1] to mark a known point.
+
+Examples
+~~~~~~~~
+
+Use a tarball as a starting point for a new repository.::
++
+------------
+$ tar zxf frotz.tar.gz
+$ cd frotz
+$ git init
+$ git add . <1>
+$ git commit -m "import of frotz source tree."
+$ git tag v2.43 <2>
+------------
++
+<1> add everything under the current directory.
+<2> make a lightweight, unannotated tag.
+
+Create a topic branch and develop.::
++
+------------
+$ git checkout -b alsa-audio <1>
+$ edit/compile/test
+$ git checkout -- curses/ux_audio_oss.c <2>
+$ git add curses/ux_audio_alsa.c <3>
+$ edit/compile/test
+$ git diff HEAD <4>
+$ git commit -a -s <5>
+$ edit/compile/test
+$ git diff HEAD^ <6>
+$ git commit -a --amend <7>
+$ git checkout master <8>
+$ git merge alsa-audio <9>
+$ git log --since='3 days ago' <10>
+$ git log v2.43.. curses/ <11>
+------------
++
+<1> create a new topic branch.
+<2> revert your botched changes in `curses/ux_audio_oss.c`.
+<3> you need to tell Git if you added a new file; removal and
+modification will be caught if you do `git commit -a` later.
+<4> to see what changes you are committing.
+<5> commit everything, as you have tested, with your sign-off.
+<6> look at all your changes including the previous commit.
+<7> amend the previous commit, adding all your new changes,
+using your original message.
+<8> switch to the master branch.
+<9> merge a topic branch into your master branch.
+<10> review commit logs; other forms to limit output can be
+combined and include `-10` (to show up to 10 commits),
+`--until=2005-12-10`, etc.
+<11> view only the changes that touch what's in `curses/`
+directory, since `v2.43` tag.
+
+
+Individual Developer (Participant)[[PARTICIPANT]]
+-------------------------------------------------
+
+A developer working as a participant in a group project needs to
+learn how to communicate with others, and uses these commands in
+addition to the ones needed by a standalone developer.
+
+  * linkgit:git-clone[1] from the upstream to prime your local
+    repository.
+
+  * linkgit:git-pull[1] and linkgit:git-fetch[1] from "origin"
+    to keep up-to-date with the upstream.
+
+  * linkgit:git-push[1] to shared repository, if you adopt CVS
+    style shared repository workflow.
+
+  * linkgit:git-format-patch[1] to prepare e-mail submission, if
+    you adopt Linux kernel-style public forum workflow.
+
+  * linkgit:git-send-email[1] to send your e-mail submission without
+    corruption by your MUA.
+
+  * linkgit:git-request-pull[1] to create a summary of changes
+    for your upstream to pull.
+
+
+Examples
+~~~~~~~~
+
+Clone the upstream and work on it.  Feed changes to upstream.::
++
+------------
+$ git clone git://git.kernel.org/pub/scm/.../torvalds/linux-2.6 my2.6
+$ cd my2.6
+$ git checkout -b mine master <1>
+$ edit/compile/test; git commit -a -s <2>
+$ git format-patch master <3>
+$ git send-email --to="person <email@example.com>" 00*.patch <4>
+$ git checkout master <5>
+$ git pull <6>
+$ git log -p ORIG_HEAD.. arch/i386 include/asm-i386 <7>
+$ git ls-remote --heads http://git.kernel.org/.../jgarzik/libata-dev.git <8>
+$ git pull git://git.kernel.org/pub/.../jgarzik/libata-dev.git ALL <9>
+$ git reset --hard ORIG_HEAD <10>
+$ git gc <11>
+------------
++
+<1> checkout a new branch `mine` from master.
+<2> repeat as needed.
+<3> extract patches from your branch, relative to master,
+<4> and email them.
+<5> return to `master`, ready to see what's new
+<6> `git pull` fetches from `origin` by default and merges into the
+current branch.
+<7> immediately after pulling, look at the changes done upstream
+since last time we checked, only in the
+area we are interested in.
+<8> check the branch names in an external repository (if not known).
+<9> fetch from a specific branch `ALL` from a specific repository
+and merge it.
+<10> revert the pull.
+<11> garbage collect leftover objects from reverted pull.
+
+
+Push into another repository.::
++
+------------
+satellite$ git clone mothership:frotz frotz <1>
+satellite$ cd frotz
+satellite$ git config --get-regexp '^(remote|branch)\.' <2>
+remote.origin.url mothership:frotz
+remote.origin.fetch refs/heads/*:refs/remotes/origin/*
+branch.master.remote origin
+branch.master.merge refs/heads/master
+satellite$ git config remote.origin.push \
+          +refs/heads/*:refs/remotes/satellite/* <3>
+satellite$ edit/compile/test/commit
+satellite$ git push origin <4>
+
+mothership$ cd frotz
+mothership$ git checkout master
+mothership$ git merge satellite/master <5>
+------------
++
+<1> mothership machine has a frotz repository under your home
+directory; clone from it to start a repository on the satellite
+machine.
+<2> clone sets these configuration variables by default.
+It arranges `git pull` to fetch and store the branches of mothership
+machine to local `remotes/origin/*` remote-tracking branches.
+<3> arrange `git push` to push all local branches to
+their corresponding branch of the mothership machine.
+<4> push will stash all our work away on `remotes/satellite/*`
+remote-tracking branches on the mothership machine.  You could use this
+as a back-up method. Likewise, you can pretend that mothership
+"fetched" from you (useful when access is one sided).
+<5> on mothership machine, merge the work done on the satellite
+machine into the master branch.
+
+Branch off of a specific tag.::
++
+------------
+$ git checkout -b private2.6.14 v2.6.14 <1>
+$ edit/compile/test; git commit -a
+$ git checkout master
+$ git cherry-pick v2.6.14..private2.6.14 <2>
+------------
++
+<1> create a private branch based on a well known (but somewhat behind)
+tag.
+<2> forward port all changes in `private2.6.14` branch to `master` branch
+without a formal "merging". Or longhand +
+`git format-patch -k -m --stdout v2.6.14..private2.6.14 |
+  git am -3 -k`
+
+An alternate participant submission mechanism is using the
+`git request-pull` or pull-request mechanisms (e.g as used on
+GitHub (www.github.com) to notify your upstream of your
+contribution.
+
+Integrator[[INTEGRATOR]]
+------------------------
+
+A fairly central person acting as the integrator in a group
+project receives changes made by others, reviews and integrates
+them and publishes the result for others to use, using these
+commands in addition to the ones needed by participants.
+
+This section can also be used by those who respond to `git
+request-pull` or pull-request on GitHub (www.github.com) to
+integrate the work of others into their history. An sub-area
+lieutenant for a repository will act both as a participant and
+as an integrator.
+
+
+  * linkgit:git-am[1] to apply patches e-mailed in from your
+    contributors.
+
+  * linkgit:git-pull[1] to merge from your trusted lieutenants.
+
+  * linkgit:git-format-patch[1] to prepare and send suggested
+    alternative to contributors.
+
+  * linkgit:git-revert[1] to undo botched commits.
+
+  * linkgit:git-push[1] to publish the bleeding edge.
+
+
+Examples
+~~~~~~~~
+
+A typical integrator's Git day.::
++
+------------
+$ git status <1>
+$ git branch --no-merged master <2>
+$ mailx <3>
+& s 2 3 4 5 ./+to-apply
+& s 7 8 ./+hold-linus
+& q
+$ git checkout -b topic/one master
+$ git am -3 -i -s ./+to-apply <4>
+$ compile/test
+$ git checkout -b hold/linus && git am -3 -i -s ./+hold-linus <5>
+$ git checkout topic/one && git rebase master <6>
+$ git checkout pu && git reset --hard next <7>
+$ git merge topic/one topic/two && git merge hold/linus <8>
+$ git checkout maint
+$ git cherry-pick master~4 <9>
+$ compile/test
+$ git tag -s -m "GIT 0.99.9x" v0.99.9x <10>
+$ git fetch ko && for branch in master maint next pu <11>
+    do
+       git show-branch ko/$branch $branch <12>
+    done
+$ git push --follow-tags ko <13>
+------------
++
+<1> see what you were in the middle of doing, if anything.
+<2> see which branches haven't been merged into `master` yet.
+Likewise for any other integration branches e.g. `maint`, `next`
+and `pu` (potential updates).
+<3> read mails, save ones that are applicable, and save others
+that are not quite ready (other mail readers are available).
+<4> apply them, interactively, with your sign-offs.
+<5> create topic branch as needed and apply, again with sign-offs.
+<6> rebase internal topic branch that has not been merged to the
+master or exposed as a part of a stable branch.
+<7> restart `pu` every time from the next.
+<8> and bundle topic branches still cooking.
+<9> backport a critical fix.
+<10> create a signed tag.
+<11> make sure master was not accidentally rewound beyond that
+already pushed out.  `ko` shorthand points at the Git maintainer's
+repository at kernel.org, and looks like this:
++
+------------
+(in .git/config)
+[remote "ko"]
+       url = kernel.org:/pub/scm/git/git.git
+       fetch = refs/heads/*:refs/remotes/ko/*
+       push = refs/heads/master
+       push = refs/heads/next
+       push = +refs/heads/pu
+       push = refs/heads/maint
+------------
++
+<12> In the output from `git show-branch`, `master` should have
+everything `ko/master` has, and `next` should have
+everything `ko/next` has, etc.
+<13> push out the bleeding edge, together with new tags that point
+into the pushed history.
+
+
+Repository Administration[[ADMINISTRATION]]
+-------------------------------------------
+
+A repository administrator uses the following tools to set up
+and maintain access to the repository by developers.
+
+  * linkgit:git-daemon[1] to allow anonymous download from
+    repository.
+
+  * linkgit:git-shell[1] can be used as a 'restricted login shell'
+    for shared central repository users.
+
+  * linkgit:git-http-backend[1] provides a server side implementation
+    of Git-over-HTTP ("Smart http") allowing both fetch and push services.
+
+  * linkgit:gitweb[1] provides a web front-end to Git repositories,
+    which can be set-up using the linkgit:git-instaweb[1] script.
+
+link:howto/update-hook-example.html[update hook howto] has a good
+example of managing a shared central repository.
+
+In addition there are a number of other widely deployed hosting, browsing
+and reviewing solutions such as:
+
+  * gitolite, gerrit code review, cgit and others.
+
+Examples
+~~~~~~~~
+We assume the following in /etc/services::
++
+------------
+$ grep 9418 /etc/services
+git            9418/tcp                # Git Version Control System
+------------
+
+Run git-daemon to serve /pub/scm from inetd.::
++
+------------
+$ grep git /etc/inetd.conf
+git    stream  tcp     nowait  nobody \
+  /usr/bin/git-daemon git-daemon --inetd --export-all /pub/scm
+------------
++
+The actual configuration line should be on one line.
+
+Run git-daemon to serve /pub/scm from xinetd.::
++
+------------
+$ cat /etc/xinetd.d/git-daemon
+# default: off
+# description: The Git server offers access to Git repositories
+service git
+{
+       disable = no
+       type            = UNLISTED
+       port            = 9418
+       socket_type     = stream
+       wait            = no
+       user            = nobody
+       server          = /usr/bin/git-daemon
+       server_args     = --inetd --export-all --base-path=/pub/scm
+       log_on_failure  += USERID
+}
+------------
++
+Check your xinetd(8) documentation and setup, this is from a Fedora system.
+Others might be different.
+
+Give push/pull only access to developers using git-over-ssh.::
+
+e.g. those using:
+`$ git push/pull ssh://host.xz/pub/scm/project`
++
+------------
+$ grep git /etc/passwd <1>
+alice:x:1000:1000::/home/alice:/usr/bin/git-shell
+bob:x:1001:1001::/home/bob:/usr/bin/git-shell
+cindy:x:1002:1002::/home/cindy:/usr/bin/git-shell
+david:x:1003:1003::/home/david:/usr/bin/git-shell
+$ grep git /etc/shells <2>
+/usr/bin/git-shell
+------------
++
+<1> log-in shell is set to /usr/bin/git-shell, which does not
+allow anything but `git push` and `git pull`.  The users require
+ssh access to the machine.
+<2> in many distributions /etc/shells needs to list what is used
+as the login shell.
+
+CVS-style shared repository.::
++
+------------
+$ grep git /etc/group <1>
+git:x:9418:alice,bob,cindy,david
+$ cd /home/devo.git
+$ ls -l <2>
+  lrwxrwxrwx   1 david git    17 Dec  4 22:40 HEAD -> refs/heads/master
+  drwxrwsr-x   2 david git  4096 Dec  4 22:40 branches
+  -rw-rw-r--   1 david git    84 Dec  4 22:40 config
+  -rw-rw-r--   1 david git    58 Dec  4 22:40 description
+  drwxrwsr-x   2 david git  4096 Dec  4 22:40 hooks
+  -rw-rw-r--   1 david git 37504 Dec  4 22:40 index
+  drwxrwsr-x   2 david git  4096 Dec  4 22:40 info
+  drwxrwsr-x   4 david git  4096 Dec  4 22:40 objects
+  drwxrwsr-x   4 david git  4096 Nov  7 14:58 refs
+  drwxrwsr-x   2 david git  4096 Dec  4 22:40 remotes
+$ ls -l hooks/update <3>
+  -r-xr-xr-x   1 david git  3536 Dec  4 22:40 update
+$ cat info/allowed-users <4>
+refs/heads/master      alice\|cindy
+refs/heads/doc-update  bob
+refs/tags/v[0-9]*      david
+------------
++
+<1> place the developers into the same git group.
+<2> and make the shared repository writable by the group.
+<3> use update-hook example by Carl from Documentation/howto/
+for branch policy control.
+<4> alice and cindy can push into master, only bob can push into doc-update.
+david is the release manager and is the only person who can
+create and push version tags.
+
+GIT
+---
+Part of the linkgit:git[1] suite
index e52de7dbb48ce84e3a82d84953a01bf0e6bfcdb4..212e254adc057fa3f67bc50cc23a995059a24585 100644 (file)
@@ -19,7 +19,7 @@ SEE ALSO
 linkgit:gittutorial[7],
 linkgit:gittutorial-2[7],
 linkgit:gitcvs-migration[7],
-link:everyday.html[Everyday Git],
+linkgit:giteveryday[7],
 link:user-manual.html[The Git User's Manual]
 
 GIT
index 3109ea8aade1ceb47de67823388d865a1505e616..f6fbf814fba14d230f623aa9b2e44a7bde88adbd 100644 (file)
@@ -403,7 +403,7 @@ What next?
 
 At this point you should know everything necessary to read the man
 pages for any of the git commands; one good place to start would be
-with the commands mentioned in link:everyday.html[Everyday Git].  You
+with the commands mentioned in linkgit:giteveryday[7].  You
 should be able to find any unknown jargon in linkgit:gitglossary[7].
 
 The link:user-manual.html[Git User's Manual] provides a more
@@ -427,7 +427,7 @@ linkgit:gitcvs-migration[7],
 linkgit:gitcore-tutorial[7],
 linkgit:gitglossary[7],
 linkgit:git-help[1],
-link:everyday.html[Everyday Git],
+linkgit:giteveryday[7],
 link:user-manual.html[The Git User's Manual]
 
 GIT
index 82621963189d1800087c8eca63add642c0743a96..af9f709ccf36b37ab4b143eaad218372af3e0ee4 100644 (file)
@@ -656,7 +656,7 @@ digressions that may be interesting at this point are:
   * linkgit:gitworkflows[7]: Gives an overview of recommended
     workflows.
 
-  * link:everyday.html[Everyday Git with 20 Commands Or So]
+  * linkgit:giteveryday[7]: Everyday Git with 20 Commands Or So.
 
   * linkgit:gitcvs-migration[7]: Git for CVS users.
 
@@ -668,7 +668,7 @@ linkgit:gitcore-tutorial[7],
 linkgit:gitglossary[7],
 linkgit:git-help[1],
 linkgit:gitworkflows[7],
-link:everyday.html[Everyday Git],
+linkgit:giteveryday[7],
 link:user-manual.html[The Git User's Manual]
 
 GIT
index eecc39dec99b3cab3da3e36440653ea46ac762b9..dcf7429a47c4853e18ea06c8b5af4df5ece5c0fa 100644 (file)
@@ -95,7 +95,7 @@ would show something like this:
 The author of fe6e0ee was Junio C Hamano, 23 hours ago
 The title was >>t4119: test autocomputing -p<n> for traditional diff input.<<
 
---------
+-------
 +
 The placeholders are:
 
index dd894043ae8b04269b3aa2108f96cb935217181d..93b5f23e4c8a1bb45dc26d5f9cec402df7f57ee4 100644 (file)
@@ -3,20 +3,132 @@ lockfile API
 
 The lockfile API serves two purposes:
 
-* Mutual exclusion.  When we write out a new index file, first
-  we create a new file `$GIT_DIR/index.lock`, write the new
-  contents into it, and rename it to the final destination
-  `$GIT_DIR/index`.  We try to create the `$GIT_DIR/index.lock`
-  file with O_EXCL so that we can notice and fail when somebody
-  else is already trying to update the index file.
-
-* Automatic cruft removal.  After we create the "lock" file, we
-  may decide to `die()`, and we would want to make sure that we
-  remove the file that has not been committed to its final
-  destination.  This is done by remembering the lockfiles we
-  created in a linked list and cleaning them up from an
-  `atexit(3)` handler.  Outstanding lockfiles are also removed
-  when the program dies on a signal.
+* Mutual exclusion and atomic file updates. When we want to change a
+  file, we create a lockfile `<filename>.lock`, write the new file
+  contents into it, and then rename the lockfile to its final
+  destination `<filename>`. We create the `<filename>.lock` file with
+  `O_CREAT|O_EXCL` so that we can notice and fail if somebody else has
+  already locked the file, then atomically rename the lockfile to its
+  final destination to commit the changes and unlock the file.
+
+* Automatic cruft removal. If the program exits after we lock a file
+  but before the changes have been committed, we want to make sure
+  that we remove the lockfile. This is done by remembering the
+  lockfiles we have created in a linked list and setting up an
+  `atexit(3)` handler and a signal handler that clean up the
+  lockfiles. This mechanism ensures that outstanding lockfiles are
+  cleaned up if the program exits (including when `die()` is called)
+  or if the program dies on a signal.
+
+Please note that lockfiles only block other writers. Readers do not
+block, but they are guaranteed to see either the old contents of the
+file or the new contents of the file (assuming that the filesystem
+implements `rename(2)` atomically).
+
+
+Calling sequence
+----------------
+
+The caller:
+
+* Allocates a `struct lock_file` either as a static variable or on the
+  heap, initialized to zeros. Once you use the structure to call the
+  `hold_lock_file_*` family of functions, it belongs to the lockfile
+  subsystem and its storage must remain valid throughout the life of
+  the program (i.e. you cannot use an on-stack variable to hold this
+  structure).
+
+* Attempts to create a lockfile by passing that variable and the path
+  of the final destination (e.g. `$GIT_DIR/index`) to
+  `hold_lock_file_for_update` or `hold_lock_file_for_append`.
+
+* Writes new content for the destination file by either:
+
+  * writing to the file descriptor returned by the `hold_lock_file_*`
+    functions (also available via `lock->fd`).
+
+  * calling `fdopen_lock_file` to get a `FILE` pointer for the open
+    file and writing to the file using stdio.
+
+When finished writing, the caller can:
+
+* Close the file descriptor and rename the lockfile to its final
+  destination by calling `commit_lock_file` or `commit_lock_file_to`.
+
+* Close the file descriptor and remove the lockfile by calling
+  `rollback_lock_file`.
+
+* Close the file descriptor without removing or renaming the lockfile
+  by calling `close_lock_file`, and later call `commit_lock_file`,
+  `commit_lock_file_to`, `rollback_lock_file`, or `reopen_lock_file`.
+
+Even after the lockfile is committed or rolled back, the `lock_file`
+object must not be freed or altered by the caller. However, it may be
+reused; just pass it to another call of `hold_lock_file_for_update` or
+`hold_lock_file_for_append`.
+
+If the program exits before you have called one of `commit_lock_file`,
+`commit_lock_file_to`, `rollback_lock_file`, or `close_lock_file`, an
+`atexit(3)` handler will close and remove the lockfile, rolling back
+any uncommitted changes.
+
+If you need to close the file descriptor you obtained from a
+`hold_lock_file_*` function yourself, do so by calling
+`close_lock_file`. You should never call `close(2)` or `fclose(3)`
+yourself! Otherwise the `struct lock_file` structure would still think
+that the file descriptor needs to be closed, and a commit or rollback
+would result in duplicate calls to `close(2)`. Worse yet, if you close
+and then later open another file descriptor for a completely different
+purpose, then a commit or rollback might close that unrelated file
+descriptor.
+
+
+Error handling
+--------------
+
+The `hold_lock_file_*` functions return a file descriptor on success
+or -1 on failure (unless `LOCK_DIE_ON_ERROR` is used; see below). On
+errors, `errno` describes the reason for failure. Errors can be
+reported by passing `errno` to one of the following helper functions:
+
+unable_to_lock_message::
+
+       Append an appropriate error message to a `strbuf`.
+
+unable_to_lock_error::
+
+       Emit an appropriate error message using `error()`.
+
+unable_to_lock_die::
+
+       Emit an appropriate error message and `die()`.
+
+Similarly, `commit_lock_file`, `commit_lock_file_to`, and
+`close_lock_file` return 0 on success. On failure they set `errno`
+appropriately, do their best to roll back the lockfile, and return -1.
+
+
+Flags
+-----
+
+The following flags can be passed to `hold_lock_file_for_update` or
+`hold_lock_file_for_append`:
+
+LOCK_NO_DEREF::
+
+       Usually symbolic links in the destination path are resolved
+       and the lockfile is created by adding ".lock" to the resolved
+       path. If `LOCK_NO_DEREF` is set, then the lockfile is created
+       by adding ".lock" to the path argument itself. This option is
+       used, for example, when locking a symbolic reference, which
+       for backwards-compatibility reasons can be a symbolic link
+       containing the name of the referred-to-reference.
+
+LOCK_DIE_ON_ERROR::
+
+       If a lock is already taken for the file, `die()` with an error
+       message. If this option is not specified, trying to lock a
+       file that is already locked returns -1 to the caller.
 
 
 The functions
@@ -24,51 +136,85 @@ The functions
 
 hold_lock_file_for_update::
 
-       Take a pointer to `struct lock_file`, the filename of
-       the final destination (e.g. `$GIT_DIR/index`) and a flag
-       `die_on_error`.  Attempt to create a lockfile for the
-       destination and return the file descriptor for writing
-       to the file.  If `die_on_error` flag is true, it dies if
-       a lock is already taken for the file; otherwise it
-       returns a negative integer to the caller on failure.
+       Take a pointer to `struct lock_file`, the path of the file to
+       be locked (e.g. `$GIT_DIR/index`) and a flags argument (see
+       above). Attempt to create a lockfile for the destination and
+       return the file descriptor for writing to the file.
+
+hold_lock_file_for_append::
+
+       Like `hold_lock_file_for_update`, but before returning copy
+       the existing contents of the file (if any) to the lockfile and
+       position its write pointer at the end of the file.
+
+fdopen_lock_file::
+
+       Associate a stdio stream with the lockfile. Return NULL
+       (*without* rolling back the lockfile) on error. The stream is
+       closed automatically when `close_lock_file` is called or when
+       the file is committed or rolled back.
+
+get_locked_file_path::
+
+       Return the path of the file that is locked by the specified
+       lock_file object. The caller must free the memory.
 
 commit_lock_file::
 
-       Take a pointer to the `struct lock_file` initialized
-       with an earlier call to `hold_lock_file_for_update()`,
-       close the file descriptor and rename the lockfile to its
-       final destination.  Returns 0 upon success, a negative
-       value on failure to close(2) or rename(2).
+       Take a pointer to the `struct lock_file` initialized with an
+       earlier call to `hold_lock_file_for_update` or
+       `hold_lock_file_for_append`, close the file descriptor, and
+       rename the lockfile to its final destination. Return 0 upon
+       success. On failure, roll back the lock file and return -1,
+       with `errno` set to the value from the failing call to
+       `close(2)` or `rename(2)`. It is a bug to call
+       `commit_lock_file` for a `lock_file` object that is not
+       currently locked.
+
+commit_lock_file_to::
+
+       Like `commit_lock_file()`, except that it takes an explicit
+       `path` argument to which the lockfile should be renamed. The
+       `path` must be on the same filesystem as the lock file.
 
 rollback_lock_file::
 
-       Take a pointer to the `struct lock_file` initialized
-       with an earlier call to `hold_lock_file_for_update()`,
-       close the file descriptor and remove the lockfile.
+       Take a pointer to the `struct lock_file` initialized with an
+       earlier call to `hold_lock_file_for_update` or
+       `hold_lock_file_for_append`, close the file descriptor and
+       remove the lockfile. It is a NOOP to call
+       `rollback_lock_file()` for a `lock_file` object that has
+       already been committed or rolled back.
 
 close_lock_file::
-       Take a pointer to the `struct lock_file` initialized
-       with an earlier call to `hold_lock_file_for_update()`,
-       and close the file descriptor.  Returns 0 upon success,
-       a negative value on failure to close(2).
-
-Because the structure is used in an `atexit(3)` handler, its
-storage has to stay throughout the life of the program.  It
-cannot be an auto variable allocated on the stack.
-
-Call `commit_lock_file()` or `rollback_lock_file()` when you are
-done writing to the file descriptor.  If you do not call either
-and simply `exit(3)` from the program, an `atexit(3)` handler
-will close and remove the lockfile.
-
-If you need to close the file descriptor you obtained from
-`hold_lock_file_for_update` function yourself, do so by calling
-`close_lock_file()`.  You should never call `close(2)` yourself!
-Otherwise the `struct
-lock_file` structure still remembers that the file descriptor
-needs to be closed, and a later call to `commit_lock_file()` or
-`rollback_lock_file()` will result in duplicate calls to
-`close(2)`.  Worse yet, if you `close(2)`, open another file
-descriptor for completely different purpose, and then call
-`commit_lock_file()` or `rollback_lock_file()`, they may close
-that unrelated file descriptor.
+
+       Take a pointer to the `struct lock_file` initialized with an
+       earlier call to `hold_lock_file_for_update` or
+       `hold_lock_file_for_append`. Close the file descriptor (and
+       the file pointer if it has been opened using
+       `fdopen_lock_file`). Return 0 upon success. On failure to
+       `close(2)`, return a negative value and roll back the lock
+       file. Usually `commit_lock_file`, `commit_lock_file_to`, or
+       `rollback_lock_file` should eventually be called if
+       `close_lock_file` succeeds.
+
+reopen_lock_file::
+
+       Re-open a lockfile that has been closed (using
+       `close_lock_file`) but not yet committed or rolled back. This
+       can be used to implement a sequence of operations like the
+       following:
+
+       * Lock file.
+
+       * Write new contents to lockfile, then `close_lock_file` to
+         cause the contents to be written to disk.
+
+       * Pass the name of the lockfile to another program to allow it
+         (and nobody else) to inspect the contents you wrote, while
+         still holding the lock yourself.
+
+       * `reopen_lock_file` to reopen the lockfile. Make further
+         updates to the contents.
+
+       * `commit_lock_file` to make the final version permanent.
index f34a2d4cb82a907c2a1a9a8d760cfd3a1788f6e3..356feb5c86023d00a41ac8bca7d44f9779c39ad0 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -568,6 +568,7 @@ TEST_PROGRAMS_NEED_X += test-revision-walking
 TEST_PROGRAMS_NEED_X += test-run-command
 TEST_PROGRAMS_NEED_X += test-scrap-cache-tree
 TEST_PROGRAMS_NEED_X += test-sha1
+TEST_PROGRAMS_NEED_X += test-sha1-array
 TEST_PROGRAMS_NEED_X += test-sigchain
 TEST_PROGRAMS_NEED_X += test-string-list
 TEST_PROGRAMS_NEED_X += test-subprocess
diff --git a/README b/README
index 15a8e235012a247e6f22abd2c298a2e43c940c61..1083735d1cddaba394eb5c99ce470a31050dad4b 100644 (file)
--- a/README
+++ b/README
@@ -27,7 +27,7 @@ Torvalds with help of a group of hackers around the net.
 Please read the file INSTALL for installation instructions.
 
 See Documentation/gittutorial.txt to get started, then see
-Documentation/everyday.txt for a useful minimum set of commands, and
+Documentation/giteveryday.txt for a useful minimum set of commands, and
 Documentation/git-commandname.txt for documentation of each command.
 If git has been correctly installed, then the tutorial can also be
 read with "man gittutorial" or "git help tutorial", and the
index df2f4c8a643796ee96a31185f2a49fa7e00ca991..0d1e6bd7542dd7c76d2f349de0d0238a8d1b55af 100644 (file)
@@ -192,7 +192,7 @@ static int write_extended_header(struct archiver_args *args,
        unsigned int mode;
        memset(&header, 0, sizeof(header));
        *header.typeflag = TYPEFLAG_EXT_HEADER;
-       mode = 0100666 & ~tar_umask;
+       mode = 0100666;
        sprintf(header.name, "%s.paxheader", sha1_to_hex(sha1));
        prepare_header(args, &header, mode, size);
        write_blocked(&header, sizeof(header));
@@ -300,7 +300,7 @@ static int write_global_extended_header(struct archiver_args *args)
        strbuf_append_ext_header(&ext_header, "comment", sha1_to_hex(sha1), 40);
        memset(&header, 0, sizeof(header));
        *header.typeflag = TYPEFLAG_GLOBAL_HEADER;
-       mode = 0100666 & ~tar_umask;
+       mode = 0100666;
        strcpy(header.name, "pax_global_header");
        prepare_header(args, &header, mode, ext_header.len);
        write_blocked(&header, sizeof(header));
index 352b85e8db19e1b4fa05ca37804f0c625e582912..ae6d3e262bcbb3dc57c0ddf146791380259b31be 100644 (file)
@@ -5,6 +5,7 @@
  */
 #include "cache.h"
 #include "builtin.h"
+#include "lockfile.h"
 #include "dir.h"
 #include "pathspec.h"
 #include "exec_cmd.h"
index 8714a887203acd84ad08f3e0917fc72b2c7a3138..6696ea4c3ffd4f7af04f3f56609a78a74a0a0b55 100644 (file)
@@ -7,6 +7,7 @@
  *
  */
 #include "cache.h"
+#include "lockfile.h"
 #include "cache-tree.h"
 #include "quote.h"
 #include "blob.h"
@@ -435,7 +436,7 @@ static unsigned long linelen(const char *buffer, unsigned long size)
 
 static int is_dev_null(const char *str)
 {
-       return !memcmp("/dev/null", str, 9) && isspace(str[9]);
+       return skip_prefix(str, "/dev/null", &str) && isspace(*str);
 }
 
 #define TERM_SPACE     1
index 9e4666f0c53164113ac211eee674ba838fb7ae72..67850975e7bebbf122ec961a527497c40c2c3f27 100644 (file)
@@ -81,14 +81,16 @@ static int parse_branch_color_slot(const char *var, int ofs)
 
 static int git_branch_config(const char *var, const char *value, void *cb)
 {
+       const char *slot_name;
+
        if (starts_with(var, "column."))
                return git_column_config(var, value, "branch", &colopts);
        if (!strcmp(var, "color.branch")) {
                branch_use_color = git_config_colorbool(var, value);
                return 0;
        }
-       if (starts_with(var, "color.branch.")) {
-               int slot = parse_branch_color_slot(var, 13);
+       if (skip_prefix(var, "color.branch.", &slot_name)) {
+               int slot = parse_branch_color_slot(var, slot_name - var);
                if (slot < 0)
                        return 0;
                if (!value)
@@ -335,20 +337,18 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,
        static struct {
                int kind;
                const char *prefix;
-               int pfxlen;
        } ref_kind[] = {
-               { REF_LOCAL_BRANCH, "refs/heads/", 11 },
-               { REF_REMOTE_BRANCH, "refs/remotes/", 13 },
+               { REF_LOCAL_BRANCH, "refs/heads/" },
+               { REF_REMOTE_BRANCH, "refs/remotes/" },
        };
 
        /* Detect kind */
        for (i = 0; i < ARRAY_SIZE(ref_kind); i++) {
                prefix = ref_kind[i].prefix;
-               if (strncmp(refname, prefix, ref_kind[i].pfxlen))
-                       continue;
-               kind = ref_kind[i].kind;
-               refname += ref_kind[i].pfxlen;
-               break;
+               if (skip_prefix(refname, prefix, &refname)) {
+                       kind = ref_kind[i].kind;
+                       break;
+               }
        }
        if (ARRAY_SIZE(ref_kind) <= i)
                return 0;
@@ -872,13 +872,10 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
        head = resolve_refdup("HEAD", head_sha1, 0, NULL);
        if (!head)
                die(_("Failed to resolve HEAD as a valid ref."));
-       if (!strcmp(head, "HEAD")) {
+       if (!strcmp(head, "HEAD"))
                detached = 1;
-       } else {
-               if (!starts_with(head, "refs/heads/"))
-                       die(_("HEAD not found below refs/heads!"));
-               head += 11;
-       }
+       else if (!skip_prefix(head, "refs/heads/", &head))
+               die(_("HEAD not found below refs/heads!"));
        hashcpy(merge_filter_ref, head_sha1);
 
 
index 707330499fad66a0bddbb5cf96ff0569e2fe3433..f8d81291b9913a769f79405720210aa4eaf6daee 100644 (file)
@@ -82,8 +82,9 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
                                enum object_type type;
                                unsigned long size;
                                char *buffer = read_sha1_file(sha1, &type, &size);
-                               if (memcmp(buffer, "object ", 7) ||
-                                   get_sha1_hex(buffer + 7, blob_sha1))
+                               const char *target;
+                               if (!skip_prefix(buffer, "object ", &target) ||
+                                   get_sha1_hex(target, blob_sha1))
                                        die("%s not a valid tag", sha1_to_hex(sha1));
                                free(buffer);
                        } else
index 05edd9e1df52e63a1644cddc0fb0e6a0d764d90b..383dccf93ef4eceb873eee4cd63e6781854b295c 100644 (file)
@@ -5,7 +5,7 @@
  *
  */
 #include "builtin.h"
-#include "cache.h"
+#include "lockfile.h"
 #include "quote.h"
 #include "cache-tree.h"
 #include "parse-options.h"
index 8afdf2b5c4bfbd53e7315afe9d8ae3d88f93dd57..b4decd5b19c6ec9399f80c7a063343331fe8fd38 100644 (file)
@@ -1,5 +1,5 @@
-#include "cache.h"
 #include "builtin.h"
+#include "lockfile.h"
 #include "parse-options.h"
 #include "refs.h"
 #include "commit.h"
@@ -1150,10 +1150,8 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
                const char *argv0 = argv[0];
                if (!argc || !strcmp(argv0, "--"))
                        die (_("--track needs a branch name"));
-               if (starts_with(argv0, "refs/"))
-                       argv0 += 5;
-               if (starts_with(argv0, "remotes/"))
-                       argv0 += 8;
+               skip_prefix(argv0, "refs/", &argv0);
+               skip_prefix(argv0, "remotes/", &argv0);
                argv0 = strchr(argv0, '/');
                if (!argv0 || !argv0[1])
                        die (_("Missing branch name; try -b"));
index 3beeea6ec0fdc3883f2456caf46f3e1c4dadc682..c35505ee6b4030eedc61861081fd21e655b2b3e4 100644 (file)
@@ -100,6 +100,8 @@ static int parse_clean_color_slot(const char *var)
 
 static int git_clean_config(const char *var, const char *value, void *cb)
 {
+       const char *slot_name;
+
        if (starts_with(var, "column."))
                return git_column_config(var, value, "clean", &colopts);
 
@@ -109,9 +111,8 @@ static int git_clean_config(const char *var, const char *value, void *cb)
                clean_use_color = git_config_colorbool(var, value);
                return 0;
        }
-       if (starts_with(var, "color.interactive.")) {
-               int slot = parse_clean_color_slot(var +
-                                                 strlen("color.interactive."));
+       if (skip_prefix(var, "color.interactive.", &slot_name)) {
+               int slot = parse_clean_color_slot(slot_name);
                if (slot < 0)
                        return 0;
                if (!value)
index 3927edfb6ede269929dc704cbb928a7516a8a0a7..d3bf9532d60fd52dfb440fc991e91544e8353fbe 100644 (file)
@@ -9,6 +9,7 @@
  */
 
 #include "builtin.h"
+#include "lockfile.h"
 #include "parse-options.h"
 #include "fetch-pack.h"
 #include "refs.h"
index b0fe7847d3cbebd2cef28611171924bf7440c467..81dc622a3b72040daca199f05d0a3322f316e6f6 100644 (file)
@@ -6,6 +6,7 @@
  */
 
 #include "cache.h"
+#include "lockfile.h"
 #include "cache-tree.h"
 #include "color.h"
 #include "dir.h"
@@ -315,8 +316,8 @@ static void refresh_cache_or_die(int refresh_flags)
                die_resolve_conflict("commit");
 }
 
-static char *prepare_index(int argc, const char **argv, const char *prefix,
-                          const struct commit *current_head, int is_status)
+static const char *prepare_index(int argc, const char **argv, const char *prefix,
+                                const struct commit *current_head, int is_status)
 {
        struct string_list partial;
        struct pathspec pathspec;
@@ -341,7 +342,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
                        die(_("unable to create temporary index"));
 
                old_index_env = getenv(INDEX_ENVIRONMENT);
-               setenv(INDEX_ENVIRONMENT, index_lock.filename, 1);
+               setenv(INDEX_ENVIRONMENT, index_lock.filename.buf, 1);
 
                if (interactive_add(argc, argv, prefix, patch_interactive) != 0)
                        die(_("interactive add failed"));
@@ -352,7 +353,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
                        unsetenv(INDEX_ENVIRONMENT);
 
                discard_cache();
-               read_cache_from(index_lock.filename);
+               read_cache_from(index_lock.filename.buf);
                if (update_main_cache_tree(WRITE_TREE_SILENT) == 0) {
                        if (reopen_lock_file(&index_lock) < 0)
                                die(_("unable to write index file"));
@@ -362,7 +363,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
                        warning(_("Failed to update main cache tree"));
 
                commit_style = COMMIT_NORMAL;
-               return index_lock.filename;
+               return index_lock.filename.buf;
        }
 
        /*
@@ -385,7 +386,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
                if (write_locked_index(&the_index, &index_lock, CLOSE_LOCK))
                        die(_("unable to write new_index file"));
                commit_style = COMMIT_NORMAL;
-               return index_lock.filename;
+               return index_lock.filename.buf;
        }
 
        /*
@@ -472,9 +473,9 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
                die(_("unable to write temporary index file"));
 
        discard_cache();
-       read_cache_from(false_lock.filename);
+       read_cache_from(false_lock.filename.buf);
 
-       return false_lock.filename;
+       return false_lock.filename.buf;
 }
 
 static int run_status(FILE *fp, const char *index_file, const char *prefix, int nowarn,
@@ -1294,6 +1295,7 @@ static int parse_status_slot(const char *var, int offset)
 static int git_status_config(const char *k, const char *v, void *cb)
 {
        struct wt_status *s = cb;
+       const char *slot_name;
 
        if (starts_with(k, "column."))
                return git_column_config(k, v, "status", &s->colopts);
@@ -1323,8 +1325,9 @@ static int git_status_config(const char *k, const char *v, void *cb)
                s->display_comment_prefix = git_config_bool(k, v);
                return 0;
        }
-       if (starts_with(k, "status.color.") || starts_with(k, "color.status.")) {
-               int slot = parse_status_slot(k, 13);
+       if (skip_prefix(k, "status.color.", &slot_name) ||
+           skip_prefix(k, "color.status.", &slot_name)) {
+               int slot = parse_status_slot(k, slot_name - k);
                if (slot < 0)
                        return 0;
                if (!v)
@@ -1513,13 +1516,11 @@ static void print_summary(const char *prefix, const unsigned char *sha1,
        diff_setup_done(&rev.diffopt);
 
        head = resolve_ref_unsafe("HEAD", junk_sha1, 0, NULL);
-       printf("[%s%s ",
-               starts_with(head, "refs/heads/") ?
-                       head + 11 :
-                       !strcmp(head, "HEAD") ?
-                               _("detached HEAD") :
-                               head,
-               initial_commit ? _(" (root-commit)") : "");
+       if (!strcmp(head, "HEAD"))
+               head = _("detached HEAD");
+       else
+               skip_prefix(head, "refs/heads/", &head);
+       printf("[%s%s ", head, initial_commit ? _(" (root-commit)") : "");
 
        if (!log_tree_commit(&rev, commit)) {
                rev.always_show_header = 1;
index ee6a3b998f2c22b1d131a180e77079117e598136..9103193b4f65dc9e224051fb1e19eda6d9c7ae6a 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "lockfile.h"
 #include "commit.h"
 #include "tag.h"
 #include "refs.h"
index 0f247d24008a4dc7ba5958e716c13f7582a820f1..4326fa56bfa2021c6518c225eaa3f89b8b852e11 100644 (file)
@@ -4,6 +4,7 @@
  * Copyright (c) 2006 Junio C Hamano
  */
 #include "cache.h"
+#include "lockfile.h"
 #include "color.h"
 #include "commit.h"
 #include "blob.h"
index ced1456e1e3b71af05e382fcd505cc269391bb88..005adbebea80a83a8d0dbb1de744cb50bf689de6 100644 (file)
@@ -11,7 +11,7 @@
  */
 
 #include "builtin.h"
-#include "cache.h"
+#include "lockfile.h"
 #include "parse-options.h"
 #include "run-command.h"
 #include "sigchain.h"
index aa72596083d4e7ad9b84058e8b23b09849d74d7c..6f4147ad02b98de298fb054f38fab8e6d10e7335 100644 (file)
@@ -19,6 +19,7 @@ int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix)
        char buffer[HEADERSIZE];
        struct ustar_header *header = (struct ustar_header *)buffer;
        char *content = buffer + RECORDSIZE;
+       const char *comment;
        ssize_t n;
 
        if (argc != 1)
@@ -29,10 +30,10 @@ int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix)
                die("git get-tar-commit-id: read error");
        if (header->typeflag[0] != 'g')
                return 1;
-       if (memcmp(content, "52 comment=", 11))
+       if (!skip_prefix(content, "52 comment=", &comment))
                return 1;
 
-       n = write_in_full(1, content + 11, 41);
+       n = write_in_full(1, comment, 41);
        if (n < 41)
                die_errno("git get-tar-commit-id: write error");
 
index 8343b4027d458d77a720f79d64c9a4c116208f84..b3c818ee01b6f64c7cf00f2e58d372f4dc8f0250 100644 (file)
@@ -421,6 +421,7 @@ static struct {
        const char *help;
 } common_guides[] = {
        { "attributes", N_("Defining attributes per path") },
+       { "everyday", N_("Everyday Git With 20 Commands Or So") },
        { "glossary", N_("A Git glossary") },
        { "ignore", N_("Specifies intentionally untracked files to ignore") },
        { "modules", N_("Defining submodule properties") },
index 2fb34c7de96a4236327d46bf1392d54fa882c17f..1202eba8b65c019662c5f6b82c13af947bd4d41c 100644 (file)
@@ -368,6 +368,8 @@ static int cmd_log_walk(struct rev_info *rev)
 
 static int git_log_config(const char *var, const char *value, void *cb)
 {
+       const char *slot_name;
+
        if (!strcmp(var, "format.pretty"))
                return git_config_string(&fmt_pretty, var, value);
        if (!strcmp(var, "format.subjectprefix"))
@@ -388,8 +390,8 @@ static int git_log_config(const char *var, const char *value, void *cb)
                default_show_root = git_config_bool(var, value);
                return 0;
        }
-       if (starts_with(var, "color.decorate."))
-               return parse_decorate_color_config(var, 15, value);
+       if (skip_prefix(var, "color.decorate.", &slot_name))
+               return parse_decorate_color_config(var, slot_name - var, value);
        if (!strcmp(var, "log.mailmap")) {
                use_mailmap_config = git_config_bool(var, value);
                return 0;
index 763cda098cf1e2ac2ccbae45d3602f8bb1093be0..8e02ea109ac8f9fd739c4d54b7a709916f88022a 100644 (file)
@@ -59,7 +59,6 @@ static int split_one(FILE *mbox, const char *name, int allow_bare)
        int is_bare = !is_from_line(buf.buf, buf.len);
 
        if (is_bare && !allow_bare) {
-               unlink(name);
                fprintf(stderr, "corrupt mailbox\n");
                exit(1);
        }
index dff043dac33ea88a8c5a05ea5ac3da71ca00c0d3..4513fadc5fc3c631591d1a9b65ec939ada5d2de3 100644 (file)
@@ -9,6 +9,7 @@
 #include "cache.h"
 #include "parse-options.h"
 #include "builtin.h"
+#include "lockfile.h"
 #include "run-command.h"
 #include "diff.h"
 #include "refs.h"
@@ -656,19 +657,18 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
                              struct commit_list *remoteheads,
                              struct commit *head, const char *head_arg)
 {
-       struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
+       static struct lock_file lock;
 
-       hold_locked_index(lock, 1);
+       hold_locked_index(&lock, 1);
        refresh_cache(REFRESH_QUIET);
        if (active_cache_changed &&
-           write_locked_index(&the_index, lock, COMMIT_LOCK))
+           write_locked_index(&the_index, &lock, COMMIT_LOCK))
                return error(_("Unable to write index."));
-       rollback_lock_file(lock);
+       rollback_lock_file(&lock);
 
        if (!strcmp(strategy, "recursive") || !strcmp(strategy, "subtree")) {
                int clean, x;
                struct commit *result;
-               struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
                struct commit_list *reversed = NULL;
                struct merge_options o;
                struct commit_list *j;
@@ -696,13 +696,13 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
                for (j = common; j; j = j->next)
                        commit_list_insert(j->item, &reversed);
 
-               hold_locked_index(lock, 1);
+               hold_locked_index(&lock, 1);
                clean = merge_recursive(&o, head,
                                remoteheads->item, reversed, &result);
                if (active_cache_changed &&
-                   write_locked_index(&the_index, lock, COMMIT_LOCK))
+                   write_locked_index(&the_index, &lock, COMMIT_LOCK))
                        die (_("unable to write %s"), get_index_file());
-               rollback_lock_file(lock);
+               rollback_lock_file(&lock);
                return clean ? 0 : 1;
        } else {
                return try_merge_command(strategy, xopts_nr, xopts,
index 8883baa903e92093cabcc3dbaac7ccec3eecd64a..563d05ba1af21c9ae73edceba060161969434c76 100644 (file)
@@ -3,8 +3,8 @@
  *
  * Copyright (C) 2006 Johannes Schindelin
  */
-#include "cache.h"
 #include "builtin.h"
+#include "lockfile.h"
 #include "dir.h"
 #include "cache-tree.h"
 #include "string-list.h"
index e7e1c33a7fb1f1eb7828f4d632fb492f128f66fe..43b47f72f1deffa8fa5e3fa5ac403d4c4a819355 100644 (file)
@@ -5,6 +5,7 @@
  */
 
 #include "cache.h"
+#include "lockfile.h"
 #include "object.h"
 #include "tree.h"
 #include "tree-walk.h"
index a01ac2096a70fcfbe4f206cca1b06ded1a1daffc..f2f6c67359cb5941c2d57b6692ce1fbbc86edccc 100644 (file)
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "lockfile.h"
 #include "pack.h"
 #include "refs.h"
 #include "pkt-line.h"
index e8a8fb13b9ffc8d3276048131e33e9874bc3bdea..b6388f75b0cffcce03b9eee03be966ce67806310 100644 (file)
@@ -1,5 +1,5 @@
-#include "cache.h"
 #include "builtin.h"
+#include "lockfile.h"
 #include "commit.h"
 #include "refs.h"
 #include "dir.h"
@@ -431,7 +431,7 @@ static int expire_reflog(const char *ref, const unsigned char *sha1, int unused,
                         write_str_in_full(lock->lock_fd, "\n") != 1 ||
                         close_ref(lock) < 0)) {
                        status |= error("Couldn't write %s",
-                               lock->lk->filename);
+                                       lock->lk->filename.buf);
                        unlink(newlog_path);
                } else if (rename(newlog_path, log_file)) {
                        status |= error("cannot rename %s to %s",
index d699d28e98c7e76e3c0a4943b58a8c88acede988..3b8c22cc75ed04eaf450f9d5a1e9e71b914339eb 100644 (file)
@@ -30,16 +30,14 @@ static char *strip_escapes(const char *str, const char *service,
        size_t rpos = 0;
        int escape = 0;
        char special = 0;
-       size_t psoff = 0;
+       const char *service_noprefix = service;
        struct strbuf ret = STRBUF_INIT;
 
-       /* Calculate prefix length for \s and lengths for \s and \S */
-       if (!strncmp(service, "git-", 4))
-               psoff = 4;
+       skip_prefix(service_noprefix, "git-", &service_noprefix);
 
        /* Pass the service to command. */
        setenv("GIT_EXT_SERVICE", service, 1);
-       setenv("GIT_EXT_SERVICE_NOPREFIX", service + psoff, 1);
+       setenv("GIT_EXT_SERVICE_NOPREFIX", service_noprefix, 1);
 
        /* Scan the length of argument. */
        while (str[rpos] && (escape || str[rpos] != ' ')) {
@@ -85,7 +83,7 @@ static char *strip_escapes(const char *str, const char *service,
                                strbuf_addch(&ret, str[rpos]);
                                break;
                        case 's':
-                               strbuf_addstr(&ret, service + psoff);
+                               strbuf_addstr(&ret, service_noprefix);
                                break;
                        case 'S':
                                strbuf_addstr(&ret, service);
index 855d478e3b9d2a815ecdcfbf39c261f98ad0994b..4c08ddc1cacc29f2098bb81b434d76f315346dd4 100644 (file)
@@ -8,6 +8,7 @@
  * Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano
  */
 #include "builtin.h"
+#include "lockfile.h"
 #include "tag.h"
 #include "object.h"
 #include "commit.h"
index 2b61d3bd41164286fcca3e5fe3c807387d946ff2..d8a9c86dd135e62583f4aeeb3885012da385960a 100644 (file)
@@ -3,8 +3,8 @@
  *
  * Copyright (C) Linus Torvalds 2006
  */
-#include "cache.h"
 #include "builtin.h"
+#include "lockfile.h"
 #include "dir.h"
 #include "cache-tree.h"
 #include "tree-walk.h"
index e8c7fd4d4957b83de42e7af2ef9f2676bfc294b2..b0e3dc91055ec7e7579fb5f1964879a99fd71606 100644 (file)
@@ -4,6 +4,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #include "cache.h"
+#include "lockfile.h"
 #include "quote.h"
 #include "cache-tree.h"
 #include "tree-walk.h"
@@ -942,7 +943,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
                if (newfd < 0) {
                        if (refresh_args.flags & REFRESH_QUIET)
                                exit(128);
-                       unable_to_lock_index_die(get_index_file(), lock_error);
+                       unable_to_lock_die(get_index_file(), lock_error);
                }
                if (write_locked_index(&the_index, lock_file, COMMIT_LOCK))
                        die("Unable to write new index file");
index 98e651c284254b3c96c59b4f444cbc0f54edd90e..0c4b8a7cad085fa1c7760e6290f21213830eda3d 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Copyright (c) 2011, Google Inc.
  */
+#include "cache.h"
 #include "bulk-checkin.h"
 #include "csum-file.h"
 #include "pack.h"
index 4f599f88414df22856e1a680e021dfe1170e5024..fbd40fc98c955c192a6de698a75b8d56af766f09 100644 (file)
@@ -4,8 +4,6 @@
 #ifndef BULK_CHECKIN_H
 #define BULK_CHECKIN_H
 
-#include "cache.h"
-
 extern int index_bulk_checkin(unsigned char sha1[],
                              int fd, size_t size, enum object_type type,
                              const char *path, unsigned flags);
index b2b89fe8628eb29b613754ee8e837fd56de185da..9a22ab5c02582fbdb3eb36f2142c03ce33bcfc95 100644 (file)
--- a/bundle.c
+++ b/bundle.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "lockfile.h"
 #include "bundle.h"
 #include "object.h"
 #include "commit.h"
@@ -209,26 +210,29 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs)
 {
        unsigned long size;
        enum object_type type;
-       char *buf, *line, *lineend;
+       char *buf = NULL, *line, *lineend;
        unsigned long date;
+       int result = 1;
 
        if (revs->max_age == -1 && revs->min_age == -1)
-               return 1;
+               goto out;
 
        buf = read_sha1_file(tag->sha1, &type, &size);
        if (!buf)
-               return 1;
+               goto out;
        line = memmem(buf, size, "\ntagger ", 8);
        if (!line++)
-               return 1;
+               goto out;
        lineend = memchr(line, '\n', buf + size - line);
        line = memchr(line, '>', lineend ? lineend - line : buf + size - line);
        if (!line++)
-               return 1;
+               goto out;
        date = strtoul(line, NULL, 10);
-       free(buf);
-       return (revs->max_age == -1 || revs->max_age < date) &&
+       result = (revs->max_age == -1 || revs->max_age < date) &&
                (revs->min_age == -1 || revs->min_age > date);
+out:
+       free(buf);
+       return result;
 }
 
 int create_bundle(struct bundle_header *header, const char *path,
index 75a54fdc7232e5693b042aa06540d51a99f01551..215202c42d2243ebf704ac083937d65aa8497929 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "lockfile.h"
 #include "tree.h"
 #include "tree-walk.h"
 #include "cache-tree.h"
diff --git a/cache.h b/cache.h
index 3e6a914dba74419c131f75b86459b4b7cea560ea..5b8606581563584c2ff274089ad16429a81a1742 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -570,29 +570,11 @@ extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);
 #define REFRESH_IN_PORCELAIN   0x0020  /* user friendly output, not "needs update" */
 extern int refresh_index(struct index_state *, unsigned int flags, const struct pathspec *pathspec, char *seen, const char *header_msg);
 
-struct lock_file {
-       struct lock_file *next;
-       int fd;
-       pid_t owner;
-       char on_list;
-       char filename[PATH_MAX];
-};
-#define LOCK_DIE_ON_ERROR 1
-#define LOCK_NODEREF 2
-extern int unable_to_lock_error(const char *path, int err);
-extern void unable_to_lock_message(const char *path, int err,
-                                  struct strbuf *buf);
-extern NORETURN void unable_to_lock_index_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 commit_lock_file(struct lock_file *);
-extern int reopen_lock_file(struct lock_file *);
 extern void update_index_if_able(struct index_state *, struct lock_file *);
 
 extern int hold_locked_index(struct lock_file *, int);
 extern void set_alternate_index_output(const char *);
-extern int close_lock_file(struct lock_file *);
-extern void rollback_lock_file(struct lock_file *);
+
 extern int delete_ref(const char *, const unsigned char *sha1, int delopt);
 
 /* Environment bits from configuration mechanism */
index 039647d247e0ac1e3a523800bbb90c86d89354de..15a298357796ffa80f7fb2258e55cf95be0b8895 100644 (file)
--- a/config.c
+++ b/config.c
@@ -6,6 +6,7 @@
  *
  */
 #include "cache.h"
+#include "lockfile.h"
 #include "exec_cmd.h"
 #include "strbuf.h"
 #include "quote.h"
@@ -2040,9 +2041,9 @@ int git_config_set_multivar_in_file(const char *config_filename,
                        MAP_PRIVATE, in_fd, 0);
                close(in_fd);
 
-               if (chmod(lock->filename, st.st_mode & 07777) < 0) {
+               if (chmod(lock->filename.buf, st.st_mode & 07777) < 0) {
                        error("chmod on %s failed: %s",
-                               lock->filename, strerror(errno));
+                               lock->filename.buf, strerror(errno));
                        ret = CONFIG_NO_WRITE;
                        goto out_free;
                }
@@ -2099,6 +2100,7 @@ int git_config_set_multivar_in_file(const char *config_filename,
        if (commit_lock_file(lock) < 0) {
                error("could not commit config file %s", config_filename);
                ret = CONFIG_NO_WRITE;
+               lock = NULL;
                goto out_free;
        }
 
@@ -2121,7 +2123,7 @@ int git_config_set_multivar_in_file(const char *config_filename,
        return ret;
 
 write_err_out:
-       ret = write_error(lock->filename);
+       ret = write_error(lock->filename.buf);
        goto out_free;
 
 }
@@ -2222,9 +2224,9 @@ int git_config_rename_section_in_file(const char *config_filename,
 
        fstat(fileno(config_file), &st);
 
-       if (chmod(lock->filename, st.st_mode & 07777) < 0) {
+       if (chmod(lock->filename.buf, st.st_mode & 07777) < 0) {
                ret = error("chmod on %s failed: %s",
-                               lock->filename, strerror(errno));
+                               lock->filename.buf, strerror(errno));
                goto out;
        }
 
@@ -2245,7 +2247,7 @@ int git_config_rename_section_in_file(const char *config_filename,
                                }
                                store.baselen = strlen(new_name);
                                if (!store_write_section(out_fd, new_name)) {
-                                       ret = write_error(lock->filename);
+                                       ret = write_error(lock->filename.buf);
                                        goto out;
                                }
                                /*
@@ -2271,7 +2273,7 @@ int git_config_rename_section_in_file(const char *config_filename,
                        continue;
                length = strlen(output);
                if (write_in_full(out_fd, output, length) != length) {
-                       ret = write_error(lock->filename);
+                       ret = write_error(lock->filename.buf);
                        goto out;
                }
        }
index 5ea5b82d2b6c54111c059a1c844c6e9f0b3d3a79..d548e99ebc213cc107b61acbdafa065bbb46dc30 100644 (file)
@@ -281,16 +281,12 @@ __gitcomp_file ()
 # argument, and using the options specified in the second argument.
 __git_ls_files_helper ()
 {
-       (
-               test -n "${CDPATH+set}" && unset CDPATH
-               cd "$1"
-               if [ "$2" == "--committable" ]; then
-                       git diff-index --name-only --relative HEAD
-               else
-                       # NOTE: $2 is not quoted in order to support multiple options
-                       git ls-files --exclude-standard $2
-               fi
-       ) 2>/dev/null
+       if [ "$2" == "--committable" ]; then
+               git -C "$1" diff-index --name-only --relative HEAD
+       else
+               # NOTE: $2 is not quoted in order to support multiple options
+               git -C "$1" ls-files --exclude-standard $2
+       fi 2>/dev/null
 }
 
 
@@ -522,7 +518,7 @@ __git_complete_index_file ()
                ;;
        esac
 
-       __gitcomp_file "$(__git_index_files "$1" "$pfx")" "$pfx" "$cur_"
+       __gitcomp_file "$(__git_index_files "$1" ${pfx:+"$pfx"})" "$pfx" "$cur_"
 }
 
 __git_complete_file ()
@@ -1467,6 +1463,7 @@ _git_log ()
                        --abbrev-commit --abbrev=
                        --relative-date --date=
                        --pretty= --format= --oneline
+                       --show-signature
                        --cherry-pick
                        --graph
                        --decorate --decorate=
@@ -2344,6 +2341,7 @@ _git_show ()
                ;;
        --*)
                __gitcomp "--pretty= --format= --abbrev-commit --oneline
+                       --show-signature
                        $__git_diff_common_options
                        "
                return
index f9146e576f82cd774f697420e2bb456f56ad65dd..d435514cbe29aa01d9cebadb947a6c6c8a1e2527 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "lockfile.h"
 #include "credential.h"
 #include "string-list.h"
 #include "parse-options.h"
index 4dcfff9352c8d034bfaec4efa0c36df41e7813a7..54a03bd527a81485b498e33225ed54c54c0dbff7 100644 (file)
--- a/daemon.c
+++ b/daemon.c
@@ -553,20 +553,21 @@ static void parse_host_arg(char *extra_args, int buflen)
                static char addrbuf[HOST_NAME_MAX + 1];
 
                hent = gethostbyname(hostname);
+               if (hent) {
+                       ap = hent->h_addr_list;
+                       memset(&sa, 0, sizeof sa);
+                       sa.sin_family = hent->h_addrtype;
+                       sa.sin_port = htons(0);
+                       memcpy(&sa.sin_addr, *ap, hent->h_length);
+
+                       inet_ntop(hent->h_addrtype, &sa.sin_addr,
+                                 addrbuf, sizeof(addrbuf));
 
-               ap = hent->h_addr_list;
-               memset(&sa, 0, sizeof sa);
-               sa.sin_family = hent->h_addrtype;
-               sa.sin_port = htons(0);
-               memcpy(&sa.sin_addr, *ap, hent->h_length);
-
-               inet_ntop(hent->h_addrtype, &sa.sin_addr,
-                         addrbuf, sizeof(addrbuf));
-
-               free(canon_hostname);
-               canon_hostname = xstrdup(hent->h_name);
-               free(ip_address);
-               ip_address = xstrdup(addrbuf);
+                       free(canon_hostname);
+                       canon_hostname = xstrdup(hent->h_name);
+                       free(ip_address);
+                       ip_address = xstrdup(addrbuf);
+               }
 #endif
        }
 }
@@ -814,7 +815,6 @@ static const char *ip2str(int family, struct sockaddr *sin, socklen_t len)
 static int setup_named_sock(char *listen_addr, int listen_port, struct socketlist *socklist)
 {
        int socknum = 0;
-       int maxfd = -1;
        char pbuf[NI_MAXSERV];
        struct addrinfo hints, *ai0, *ai;
        int gai;
@@ -882,9 +882,6 @@ static int setup_named_sock(char *listen_addr, int listen_port, struct socketlis
                ALLOC_GROW(socklist->list, socklist->nr + 1, socklist->alloc);
                socklist->list[socklist->nr++] = sockfd;
                socknum++;
-
-               if (maxfd < sockfd)
-                       maxfd = sockfd;
        }
 
        freeaddrinfo(ai0);
@@ -923,7 +920,7 @@ static int setup_named_sock(char *listen_addr, int listen_port, struct socketlis
        }
 
        if ( bind(sockfd, (struct sockaddr *)&sin, sizeof sin) < 0 ) {
-               logerror("Could not listen to %s: %s",
+               logerror("Could not bind to %s: %s",
                         ip2str(AF_INET, (struct sockaddr *)&sin, sizeof(sin)),
                         strerror(errno));
                close(sockfd);
index 96b0f4236a2083044e4ae1dfa3b8180e3e586ba1..fee7906e51792f4bfbfab0b1db2dec3082025edb 100644 (file)
@@ -153,6 +153,7 @@ Format of STDIN stream:
 
 #include "builtin.h"
 #include "cache.h"
+#include "lockfile.h"
 #include "object.h"
 #include "blob.h"
 #include "tree.h"
@@ -1793,20 +1794,18 @@ static void dump_marks_helper(FILE *f,
 static void dump_marks(void)
 {
        static struct lock_file mark_lock;
-       int mark_fd;
        FILE *f;
 
        if (!export_marks_file)
                return;
 
-       mark_fd = hold_lock_file_for_update(&mark_lock, export_marks_file, 0);
-       if (mark_fd < 0) {
+       if (hold_lock_file_for_update(&mark_lock, export_marks_file, 0) < 0) {
                failure |= error("Unable to write marks file %s: %s",
                        export_marks_file, strerror(errno));
                return;
        }
 
-       f = fdopen(mark_fd, "w");
+       f = fdopen_lock_file(&mark_lock, "w");
        if (!f) {
                int saved_errno = errno;
                rollback_lock_file(&mark_lock);
@@ -1815,27 +1814,10 @@ static void dump_marks(void)
                return;
        }
 
-       /*
-        * Since the lock file was fdopen()'ed, it should not be close()'ed.
-        * Assign -1 to the lock file descriptor so that commit_lock_file()
-        * won't try to close() it.
-        */
-       mark_lock.fd = -1;
-
        dump_marks_helper(f, 0, marks);
-       if (ferror(f) || fclose(f)) {
-               int saved_errno = errno;
-               rollback_lock_file(&mark_lock);
-               failure |= error("Unable to write marks file %s: %s",
-                       export_marks_file, strerror(saved_errno));
-               return;
-       }
-
        if (commit_lock_file(&mark_lock)) {
-               int saved_errno = errno;
-               rollback_lock_file(&mark_lock);
                failure |= error("Unable to commit marks file %s: %s",
-                       export_marks_file, strerror(saved_errno));
+                       export_marks_file, strerror(errno));
                return;
        }
 }
index 7487aa730630e8b45874e3487db8e71c05e1968c..655ee642564e3ada5b782dd6fa2d2c799f340978 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "lockfile.h"
 #include "refs.h"
 #include "pkt-line.h"
 #include "commit.h"
diff --git a/http.c b/http.c
index 0adcec4683f997044807a772713d476dd77cf105..040f362a6a299618288c9249588ceb7aed6f3011 100644 (file)
--- a/http.c
+++ b/http.c
@@ -1,3 +1,4 @@
+#include "git-compat-util.h"
 #include "http.h"
 #include "pack.h"
 #include "sideband.h"
index d34a96df4f859feeaa7597abba374128ff9dc598..d098adebf1454ea9c9204c9dd2fda4d51b63a1e5 100644 (file)
@@ -2,59 +2,61 @@
  * Copyright (c) 2005, Junio C Hamano
  */
 #include "cache.h"
+#include "lockfile.h"
 #include "sigchain.h"
 
-static struct lock_file *lock_file_list;
+static struct lock_file *volatile lock_file_list;
 
-static void remove_lock_file(void)
+static void remove_lock_files(int skip_fclose)
 {
        pid_t me = getpid();
 
        while (lock_file_list) {
-               if (lock_file_list->owner == me &&
-                   lock_file_list->filename[0]) {
-                       if (lock_file_list->fd >= 0)
-                               close(lock_file_list->fd);
-                       unlink_or_warn(lock_file_list->filename);
+               if (lock_file_list->owner == me) {
+                       /* fclose() is not safe to call in a signal handler */
+                       if (skip_fclose)
+                               lock_file_list->fp = NULL;
+                       rollback_lock_file(lock_file_list);
                }
                lock_file_list = lock_file_list->next;
        }
 }
 
-static void remove_lock_file_on_signal(int signo)
+static void remove_lock_files_on_exit(void)
 {
-       remove_lock_file();
+       remove_lock_files(0);
+}
+
+static void remove_lock_files_on_signal(int signo)
+{
+       remove_lock_files(1);
        sigchain_pop(signo);
        raise(signo);
 }
 
 /*
- * p = absolute or relative path name
+ * path = absolute or relative path name
  *
- * Return a pointer into p showing the beginning of the last path name
- * element.  If p is empty or the root directory ("/"), just return p.
+ * Remove the last path name element from path (leaving the preceding
+ * "/", if any).  If path is empty or the root directory ("/"), set
+ * path to the empty string.
  */
-static char *last_path_elm(char *p)
+static void trim_last_path_component(struct strbuf *path)
 {
-       /* r starts pointing to null at the end of the string */
-       char *r = strchr(p, '\0');
-
-       if (r == p)
-               return p; /* just return empty string */
-
-       r--; /* back up to last non-null character */
+       int i = path->len;
 
        /* back up past trailing slashes, if any */
-       while (r > p && *r == '/')
-               r--;
+       while (i && path->buf[i - 1] == '/')
+               i--;
 
        /*
-        * then go backwards until I hit a slash, or the beginning of
-        * the string
+        * then go backwards until a slash, or the beginning of the
+        * string
         */
-       while (r > p && *(r-1) != '/')
-               r--;
-       return r;
+       while (i && path->buf[i - 1] != '/')
+               i--;
+
+       strbuf_setlen(path, i);
 }
 
 
@@ -62,103 +64,88 @@ static char *last_path_elm(char *p)
 #define MAXDEPTH 5
 
 /*
- * p = path that may be a symlink
- * s = full size of p
+ * path contains a path that might be a symlink.
  *
- * If p is a symlink, attempt to overwrite p with a path to the real
- * file or directory (which may or may not exist), following a chain of
- * symlinks if necessary.  Otherwise, leave p unmodified.
+ * If path is a symlink, attempt to overwrite it with a path to the
+ * real file or directory (which may or may not exist), following a
+ * chain of symlinks if necessary.  Otherwise, leave path unmodified.
  *
- * This is a best-effort routine.  If an error occurs, p will either be
- * left unmodified or will name a different symlink in a symlink chain
- * that started with p's initial contents.
- *
- * Always returns p.
+ * This is a best-effort routine.  If an error occurs, path will
+ * either be left unmodified or will name a different symlink in a
+ * symlink chain that started with the original path.
  */
-
-static char *resolve_symlink(char *p, size_t s)
+static void resolve_symlink(struct strbuf *path)
 {
        int depth = MAXDEPTH;
+       static struct strbuf link = STRBUF_INIT;
 
        while (depth--) {
-               char link[PATH_MAX];
-               int link_len = readlink(p, link, sizeof(link));
-               if (link_len < 0) {
-                       /* not a symlink anymore */
-                       return p;
-               }
-               else if (link_len < sizeof(link))
-                       /* readlink() never null-terminates */
-                       link[link_len] = '\0';
-               else {
-                       warning("%s: symlink too long", p);
-                       return p;
-               }
+               if (strbuf_readlink(&link, path->buf, path->len) < 0)
+                       break;
 
-               if (is_absolute_path(link)) {
+               if (is_absolute_path(link.buf))
                        /* absolute path simply replaces p */
-                       if (link_len < s)
-                               strcpy(p, link);
-                       else {
-                               warning("%s: symlink too long", p);
-                               return p;
-                       }
-               } else {
+                       strbuf_reset(path);
+               else
                        /*
-                        * link is a relative path, so I must replace the
+                        * link is a relative path, so replace the
                         * last element of p with it.
                         */
-                       char *r = (char *)last_path_elm(p);
-                       if (r - p + link_len < s)
-                               strcpy(r, link);
-                       else {
-                               warning("%s: symlink too long", p);
-                               return p;
-                       }
-               }
+                       trim_last_path_component(path);
+
+               strbuf_addbuf(path, &link);
        }
-       return p;
+       strbuf_reset(&link);
 }
 
 /* Make sure errno contains a meaningful value on error */
 static int lock_file(struct lock_file *lk, const char *path, int flags)
 {
-       /*
-        * subtract 5 from size to make sure there's room for adding
-        * ".lock" for the lock file name
-        */
-       static const size_t max_path_len = sizeof(lk->filename) - 5;
+       size_t pathlen = strlen(path);
 
-       if (strlen(path) >= max_path_len) {
-               errno = ENAMETOOLONG;
+       if (!lock_file_list) {
+               /* One-time initialization */
+               sigchain_push_common(remove_lock_files_on_signal);
+               atexit(remove_lock_files_on_exit);
+       }
+
+       if (lk->active)
+               die("BUG: cannot lock_file(\"%s\") using active struct lock_file",
+                   path);
+       if (!lk->on_list) {
+               /* Initialize *lk and add it to lock_file_list: */
+               lk->fd = -1;
+               lk->fp = NULL;
+               lk->active = 0;
+               lk->owner = 0;
+               strbuf_init(&lk->filename, pathlen + LOCK_SUFFIX_LEN);
+               lk->next = lock_file_list;
+               lock_file_list = lk;
+               lk->on_list = 1;
+       } else if (lk->filename.len) {
+               /* This shouldn't happen, but better safe than sorry. */
+               die("BUG: lock_file(\"%s\") called with improperly-reset lock_file object",
+                   path);
+       }
+
+       strbuf_add(&lk->filename, path, pathlen);
+       if (!(flags & LOCK_NO_DEREF))
+               resolve_symlink(&lk->filename);
+       strbuf_addstr(&lk->filename, LOCK_SUFFIX);
+       lk->fd = open(lk->filename.buf, O_RDWR | O_CREAT | O_EXCL, 0666);
+       if (lk->fd < 0) {
+               strbuf_reset(&lk->filename);
                return -1;
        }
-       strcpy(lk->filename, path);
-       if (!(flags & LOCK_NODEREF))
-               resolve_symlink(lk->filename, max_path_len);
-       strcat(lk->filename, ".lock");
-       lk->fd = open(lk->filename, O_RDWR | O_CREAT | O_EXCL, 0666);
-       if (0 <= lk->fd) {
-               if (!lock_file_list) {
-                       sigchain_push_common(remove_lock_file_on_signal);
-                       atexit(remove_lock_file);
-               }
-               lk->owner = getpid();
-               if (!lk->on_list) {
-                       lk->next = lock_file_list;
-                       lock_file_list = lk;
-                       lk->on_list = 1;
-               }
-               if (adjust_shared_perm(lk->filename)) {
-                       int save_errno = errno;
-                       error("cannot fix permission bits on %s",
-                             lk->filename);
-                       errno = save_errno;
-                       return -1;
-               }
+       lk->owner = getpid();
+       lk->active = 1;
+       if (adjust_shared_perm(lk->filename.buf)) {
+               int save_errno = errno;
+               error("cannot fix permission bits on %s", lk->filename.buf);
+               rollback_lock_file(lk);
+               errno = save_errno;
+               return -1;
        }
-       else
-               lk->filename[0] = 0;
        return lk->fd;
 }
 
@@ -185,7 +172,7 @@ int unable_to_lock_error(const char *path, int err)
        return -1;
 }
 
-NORETURN void unable_to_lock_index_die(const char *path, int err)
+NORETURN void unable_to_lock_die(const char *path, int err)
 {
        struct strbuf buf = STRBUF_INIT;
 
@@ -198,7 +185,7 @@ int hold_lock_file_for_update(struct lock_file *lk, const char *path, int flags)
 {
        int fd = lock_file(lk, path, flags);
        if (fd < 0 && (flags & LOCK_DIE_ON_ERROR))
-               unable_to_lock_index_die(path, errno);
+               unable_to_lock_die(path, errno);
        return fd;
 }
 
@@ -209,23 +196,30 @@ int hold_lock_file_for_append(struct lock_file *lk, const char *path, int flags)
        fd = lock_file(lk, path, flags);
        if (fd < 0) {
                if (flags & LOCK_DIE_ON_ERROR)
-                       unable_to_lock_index_die(path, errno);
+                       unable_to_lock_die(path, errno);
                return fd;
        }
 
        orig_fd = open(path, O_RDONLY);
        if (orig_fd < 0) {
                if (errno != ENOENT) {
+                       int save_errno = errno;
+
                        if (flags & LOCK_DIE_ON_ERROR)
                                die("cannot open '%s' for copying", path);
-                       close(fd);
-                       return error("cannot open '%s' for copying", path);
+                       rollback_lock_file(lk);
+                       error("cannot open '%s' for copying", path);
+                       errno = save_errno;
+                       return -1;
                }
        } else if (copy_fd(orig_fd, fd)) {
+               int save_errno = errno;
+
                if (flags & LOCK_DIE_ON_ERROR)
                        exit(128);
                close(orig_fd);
-               close(fd);
+               rollback_lock_file(lk);
+               errno = save_errno;
                return -1;
        } else {
                close(orig_fd);
@@ -233,52 +227,116 @@ int hold_lock_file_for_append(struct lock_file *lk, const char *path, int flags)
        return fd;
 }
 
+FILE *fdopen_lock_file(struct lock_file *lk, const char *mode)
+{
+       if (!lk->active)
+               die("BUG: fdopen_lock_file() called for unlocked object");
+       if (lk->fp)
+               die("BUG: fdopen_lock_file() called twice for file '%s'", lk->filename.buf);
+
+       lk->fp = fdopen(lk->fd, mode);
+       return lk->fp;
+}
+
+char *get_locked_file_path(struct lock_file *lk)
+{
+       if (!lk->active)
+               die("BUG: get_locked_file_path() called for unlocked object");
+       if (lk->filename.len <= LOCK_SUFFIX_LEN)
+               die("BUG: get_locked_file_path() called for malformed lock object");
+       return xmemdupz(lk->filename.buf, lk->filename.len - LOCK_SUFFIX_LEN);
+}
+
 int close_lock_file(struct lock_file *lk)
 {
        int fd = lk->fd;
+       FILE *fp = lk->fp;
+       int err;
+
+       if (fd < 0)
+               return 0;
+
        lk->fd = -1;
-       return close(fd);
+       if (fp) {
+               lk->fp = NULL;
+
+               /*
+                * Note: no short-circuiting here; we want to fclose()
+                * in any case!
+                */
+               err = ferror(fp) | fclose(fp);
+       } else {
+               err = close(fd);
+       }
+
+       if (err) {
+               int save_errno = errno;
+               rollback_lock_file(lk);
+               errno = save_errno;
+               return -1;
+       }
+
+       return 0;
 }
 
 int reopen_lock_file(struct lock_file *lk)
 {
        if (0 <= lk->fd)
                die(_("BUG: reopen a lockfile that is still open"));
-       if (!lk->filename[0])
+       if (!lk->active)
                die(_("BUG: reopen a lockfile that has been committed"));
-       lk->fd = open(lk->filename, O_WRONLY);
+       lk->fd = open(lk->filename.buf, O_WRONLY);
        return lk->fd;
 }
 
-int commit_lock_file(struct lock_file *lk)
+int commit_lock_file_to(struct lock_file *lk, const char *path)
 {
-       char result_file[PATH_MAX];
-       size_t i;
-       if (lk->fd >= 0 && close_lock_file(lk))
+       if (!lk->active)
+               die("BUG: attempt to commit unlocked object to \"%s\"", path);
+
+       if (close_lock_file(lk))
                return -1;
-       strcpy(result_file, lk->filename);
-       i = strlen(result_file) - 5; /* .lock */
-       result_file[i] = 0;
-       if (rename(lk->filename, result_file))
+
+       if (rename(lk->filename.buf, path)) {
+               int save_errno = errno;
+               rollback_lock_file(lk);
+               errno = save_errno;
                return -1;
-       lk->filename[0] = 0;
+       }
+
+       lk->active = 0;
+       strbuf_reset(&lk->filename);
        return 0;
 }
 
-int hold_locked_index(struct lock_file *lk, int die_on_error)
+int commit_lock_file(struct lock_file *lk)
 {
-       return hold_lock_file_for_update(lk, get_index_file(),
-                                        die_on_error
-                                        ? LOCK_DIE_ON_ERROR
-                                        : 0);
+       static struct strbuf result_file = STRBUF_INIT;
+       int err;
+
+       if (!lk->active)
+               die("BUG: attempt to commit unlocked object");
+
+       if (lk->filename.len <= LOCK_SUFFIX_LEN ||
+           strcmp(lk->filename.buf + lk->filename.len - LOCK_SUFFIX_LEN, LOCK_SUFFIX))
+               die("BUG: lockfile filename corrupt");
+
+       /* remove ".lock": */
+       strbuf_add(&result_file, lk->filename.buf,
+                  lk->filename.len - LOCK_SUFFIX_LEN);
+       err = commit_lock_file_to(lk, result_file.buf);
+       strbuf_reset(&result_file);
+       return err;
 }
 
 void rollback_lock_file(struct lock_file *lk)
 {
-       if (lk->filename[0]) {
-               if (lk->fd >= 0)
-                       close(lk->fd);
-               unlink_or_warn(lk->filename);
+       if (!lk->active)
+               return;
+
+       if (!close_lock_file(lk)) {
+               unlink_or_warn(lk->filename.buf);
+               lk->active = 0;
+               strbuf_reset(&lk->filename);
        }
-       lk->filename[0] = 0;
 }
diff --git a/lockfile.h b/lockfile.h
new file mode 100644 (file)
index 0000000..dc066d1
--- /dev/null
@@ -0,0 +1,88 @@
+#ifndef LOCKFILE_H
+#define LOCKFILE_H
+
+/*
+ * File write-locks as used by Git.
+ *
+ * For an overview of how to use the lockfile API, please see
+ *
+ *     Documentation/technical/api-lockfile.txt
+ *
+ * This module keeps track of all locked files in lock_file_list for
+ * use at cleanup. This list and the lock_file objects that comprise
+ * it must be kept in self-consistent states at all time, because the
+ * program can be interrupted any time by a signal, in which case the
+ * signal handler will walk through the list attempting to clean up
+ * any open lock files.
+ *
+ * A lockfile is owned by the process that created it. The lock_file
+ * object has an "owner" field that records its owner. This field is
+ * used to prevent a forked process from closing a lockfile created by
+ * its parent.
+ *
+ * The possible states of a lock_file object are as follows:
+ *
+ * - Uninitialized.  In this state the object's on_list field must be
+ *   zero but the rest of its contents need not be initialized.  As
+ *   soon as the object is used in any way, it is irrevocably
+ *   registered in the lock_file_list, and on_list is set.
+ *
+ * - Locked, lockfile open (after hold_lock_file_for_update(),
+ *   hold_lock_file_for_append(), or reopen_lock_file()). In this
+ *   state:
+ *   - the lockfile exists
+ *   - active is set
+ *   - filename holds the filename of the lockfile
+ *   - fd holds a file descriptor open for writing to the lockfile
+ *   - fp holds a pointer to an open FILE object if and only if
+ *     fdopen_lock_file() has been called on the object
+ *   - owner holds the PID of the process that locked the file
+ *
+ * - Locked, lockfile closed (after successful close_lock_file()).
+ *   Same as the previous state, except that the lockfile is closed
+ *   and fd is -1.
+ *
+ * - Unlocked (after commit_lock_file(), commit_lock_file_to(),
+ *   rollback_lock_file(), a failed attempt to lock, or a failed
+ *   close_lock_file()).  In this state:
+ *   - active is unset
+ *   - filename is empty (usually, though there are transitory
+ *     states in which this condition doesn't hold). Client code should
+ *     *not* rely on the filename being empty in this state.
+ *   - fd is -1
+ *   - the object is left registered in the lock_file_list, and
+ *     on_list is set.
+ */
+
+struct lock_file {
+       struct lock_file *volatile next;
+       volatile sig_atomic_t active;
+       volatile int fd;
+       FILE *volatile fp;
+       volatile pid_t owner;
+       char on_list;
+       struct strbuf filename;
+};
+
+/* String appended to a filename to derive the lockfile name: */
+#define LOCK_SUFFIX ".lock"
+#define LOCK_SUFFIX_LEN 5
+
+#define LOCK_DIE_ON_ERROR 1
+#define LOCK_NO_DEREF 2
+
+extern int unable_to_lock_error(const char *path, int err);
+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 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);
+extern int commit_lock_file(struct lock_file *);
+extern int reopen_lock_file(struct lock_file *);
+extern int close_lock_file(struct lock_file *);
+extern void rollback_lock_file(struct lock_file *);
+
+#endif /* LOCKFILE_H */
index 8ad4be897d88c691d43c30afb698a1ae952b8596..fdb7d0f10ba471bcdff26dc87851d7df34fdc971 100644 (file)
@@ -3,8 +3,9 @@
  * Fredrik Kuivinen.
  * The thieves were Alex Riesen and Johannes Schindelin, in June/July 2006
  */
-#include "advice.h"
 #include "cache.h"
+#include "advice.h"
+#include "lockfile.h"
 #include "cache-tree.h"
 #include "commit.h"
 #include "blob.h"
diff --git a/merge.c b/merge.c
index 74ced7f70b5beec045c134b5719c926fc791f1e2..fcff632bd63a113ca78b0bd86da1e6af8bc6f7dc 100644 (file)
--- a/merge.c
+++ b/merge.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "lockfile.h"
 #include "commit.h"
 #include "run-command.h"
 #include "resolve-undo.h"
index 5fd9de6ce11da25b8ddf8ece9f718023394624e6..a181ac66875a158514bba48a21911adf9c5cd8be 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -73,10 +73,9 @@ static int git_pretty_formats_config(const char *var, const char *value, void *c
        if (git_config_string(&fmt, var, value))
                return -1;
 
-       if (starts_with(fmt, "format:") || starts_with(fmt, "tformat:")) {
-               commit_format->is_tformat = fmt[0] == 't';
-               fmt = strchr(fmt, ':') + 1;
-       } else if (strchr(fmt, '%'))
+       if (skip_prefix(fmt, "format:", &fmt))
+               commit_format->is_tformat = 0;
+       else if (skip_prefix(fmt, "tformat:", &fmt) || strchr(fmt, '%'))
                commit_format->is_tformat = 1;
        else
                commit_format->is_alias = 1;
@@ -157,12 +156,12 @@ void get_commit_format(const char *arg, struct rev_info *rev)
                rev->commit_format = CMIT_FMT_DEFAULT;
                return;
        }
-       if (starts_with(arg, "format:") || starts_with(arg, "tformat:")) {
-               save_user_format(rev, strchr(arg, ':') + 1, arg[0] == 't');
+       if (skip_prefix(arg, "format:", &arg)) {
+               save_user_format(rev, arg, 0);
                return;
        }
 
-       if (!*arg || strchr(arg, '%')) {
+       if (!*arg || skip_prefix(arg, "tformat:", &arg) || strchr(arg, '%')) {
                save_user_format(rev, arg, 1);
                return;
        }
@@ -809,18 +808,19 @@ static void parse_commit_header(struct format_commit_context *context)
        int i;
 
        for (i = 0; msg[i]; i++) {
+               const char *name;
                int eol;
                for (eol = i; msg[eol] && msg[eol] != '\n'; eol++)
                        ; /* do nothing */
 
                if (i == eol) {
                        break;
-               } else if (starts_with(msg + i, "author ")) {
-                       context->author.off = i + 7;
-                       context->author.len = eol - i - 7;
-               } else if (starts_with(msg + i, "committer ")) {
-                       context->committer.off = i + 10;
-                       context->committer.len = eol - i - 10;
+               } else if (skip_prefix(msg + i, "author ", &name)) {
+                       context->author.off = name - msg;
+                       context->author.len = msg + eol - name;
+               } else if (skip_prefix(msg + i, "committer ", &name)) {
+                       context->committer.off = name - msg;
+                       context->committer.len = msg + eol - name;
                }
                i = eol;
        }
@@ -951,6 +951,8 @@ static size_t parse_color(struct strbuf *sb, /* in UTF-8 */
                          const char *placeholder,
                          struct format_commit_context *c)
 {
+       const char *rest = placeholder;
+
        if (placeholder[1] == '(') {
                const char *begin = placeholder + 2;
                const char *end = strchr(begin, ')');
@@ -958,10 +960,9 @@ static size_t parse_color(struct strbuf *sb, /* in UTF-8 */
 
                if (!end)
                        return 0;
-               if (starts_with(begin, "auto,")) {
+               if (skip_prefix(begin, "auto,", &begin)) {
                        if (!want_color(c->pretty_ctx->color))
                                return end - placeholder + 1;
-                       begin += 5;
                }
                color_parse_mem(begin,
                                end - begin,
@@ -969,20 +970,15 @@ static size_t parse_color(struct strbuf *sb, /* in UTF-8 */
                strbuf_addstr(sb, color);
                return end - placeholder + 1;
        }
-       if (starts_with(placeholder + 1, "red")) {
+       if (skip_prefix(placeholder + 1, "red", &rest))
                strbuf_addstr(sb, GIT_COLOR_RED);
-               return 4;
-       } else if (starts_with(placeholder + 1, "green")) {
+       else if (skip_prefix(placeholder + 1, "green", &rest))
                strbuf_addstr(sb, GIT_COLOR_GREEN);
-               return 6;
-       } else if (starts_with(placeholder + 1, "blue")) {
+       else if (skip_prefix(placeholder + 1, "blue", &rest))
                strbuf_addstr(sb, GIT_COLOR_BLUE);
-               return 5;
-       } else if (starts_with(placeholder + 1, "reset")) {
+       else if (skip_prefix(placeholder + 1, "reset", &rest))
                strbuf_addstr(sb, GIT_COLOR_RESET);
-               return 6;
-       } else
-               return 0;
+       return rest - placeholder;
 }
 
 static size_t parse_padding_placeholder(struct strbuf *sb,
@@ -1522,7 +1518,7 @@ static void pp_header(struct pretty_print_context *pp,
        int parents_shown = 0;
 
        for (;;) {
-               const char *line = *msg_p;
+               const char *name, *line = *msg_p;
                int linelen = get_one_line(*msg_p);
 
                if (!linelen)
@@ -1557,14 +1553,14 @@ static void pp_header(struct pretty_print_context *pp,
                 * FULL shows both authors but not dates.
                 * FULLER shows both authors and dates.
                 */
-               if (starts_with(line, "author ")) {
+               if (skip_prefix(line, "author ", &name)) {
                        strbuf_grow(sb, linelen + 80);
-                       pp_user_info(pp, "Author", sb, line + 7, encoding);
+                       pp_user_info(pp, "Author", sb, name, encoding);
                }
-               if (starts_with(line, "committer ") &&
+               if (skip_prefix(line, "committer ", &name) &&
                    (pp->fmt == CMIT_FMT_FULL || pp->fmt == CMIT_FMT_FULLER)) {
                        strbuf_grow(sb, linelen + 80);
-                       pp_user_info(pp, "Commit", sb, line + 10, encoding);
+                       pp_user_info(pp, "Commit", sb, name, encoding);
                }
        }
 }
index 2fc1182f2267b3e9aed799eaf7df234cd36fefb9..8f3e9eb31498d708acf63bf3fc6de3d34562d42e 100644 (file)
@@ -5,6 +5,7 @@
  */
 #define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
+#include "lockfile.h"
 #include "cache-tree.h"
 #include "refs.h"
 #include "dir.h"
@@ -1367,6 +1368,14 @@ static int read_index_extension(struct index_state *istate,
        return 0;
 }
 
+int hold_locked_index(struct lock_file *lk, int die_on_error)
+{
+       return hold_lock_file_for_update(lk, get_index_file(),
+                                        die_on_error
+                                        ? LOCK_DIE_ON_ERROR
+                                        : 0);
+}
+
 int read_index(struct index_state *istate)
 {
        return read_index_from(istate, get_index_file());
@@ -2041,16 +2050,10 @@ void set_alternate_index_output(const char *name)
 
 static int commit_locked_index(struct lock_file *lk)
 {
-       if (alternate_index_output) {
-               if (lk->fd >= 0 && close_lock_file(lk))
-                       return -1;
-               if (rename(lk->filename, alternate_index_output))
-                       return -1;
-               lk->filename[0] = 0;
-               return 0;
-       } else {
+       if (alternate_index_output)
+               return commit_lock_file_to(lk, alternate_index_output);
+       else
                return commit_lock_file(lk);
-       }
 }
 
 static int do_write_locked_index(struct index_state *istate, struct lock_file *lock,
diff --git a/refs.c b/refs.c
index ffd45e92922ec52dccccfaecf1ceaf29f9231337..a77458f2f6eb108a90a1cf3d2cc4a771549c05f9 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "lockfile.h"
 #include "refs.h"
 #include "object.h"
 #include "tag.h"
@@ -79,7 +80,8 @@ static int check_refname_component(const char *refname, int flags)
                if (refname[1] == '\0')
                        return -1; /* Component equals ".". */
        }
-       if (cp - refname >= 5 && !memcmp(cp - 5, ".lock", 5))
+       if (cp - refname >= LOCK_SUFFIX_LEN &&
+           !memcmp(cp - LOCK_SUFFIX_LEN, LOCK_SUFFIX, LOCK_SUFFIX_LEN))
                return -1; /* Refname ends with ".lock". */
        return cp - refname;
 }
@@ -2191,7 +2193,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
        lflags = 0;
        if (flags & REF_NODEREF) {
                refname = orig_refname;
-               lflags |= LOCK_NODEREF;
+               lflags |= LOCK_NO_DEREF;
        }
        lock->ref_name = xstrdup(refname);
        lock->orig_ref_name = xstrdup(orig_refname);
@@ -2225,7 +2227,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
                         */
                        goto retry;
                else
-                       unable_to_lock_index_die(ref_file, errno);
+                       unable_to_lock_die(ref_file, errno);
        }
        return old_sha1 ? verify_lock(lock, old_sha1, mustexist) : lock;
 
@@ -2307,16 +2309,13 @@ int commit_packed_refs(void)
        if (!packed_ref_cache->lock)
                die("internal error: packed-refs not locked");
 
-       out = fdopen(packed_ref_cache->lock->fd, "w");
+       out = fdopen_lock_file(packed_ref_cache->lock, "w");
        if (!out)
                die_errno("unable to fdopen packed-refs descriptor");
 
        fprintf_or_die(out, "%s", PACKED_REFS_HEADER);
        do_for_each_entry_in_dir(get_packed_ref_dir(packed_ref_cache),
                                 0, write_packed_entry_fn, out);
-       if (fclose(out))
-               die_errno("write error");
-       packed_ref_cache->lock->fd = -1;
 
        if (commit_lock_file(packed_ref_cache->lock)) {
                save_errno = errno;
@@ -2601,12 +2600,13 @@ int repack_without_refs(const char **refnames, int n, struct strbuf *err)
 static int delete_ref_loose(struct ref_lock *lock, int flag)
 {
        if (!(flag & REF_ISPACKED) || flag & REF_ISSYMREF) {
-               /* loose */
-               int err, i = strlen(lock->lk->filename) - 5; /* .lock */
-
-               lock->lk->filename[i] = 0;
-               err = unlink_or_warn(lock->lk->filename);
-               lock->lk->filename[i] = '.';
+               /*
+                * loose.  The loose file name is the same as the
+                * lockfile name, minus ".lock":
+                */
+               char *loose_filename = get_locked_file_path(lock->lk);
+               int err = unlink_or_warn(loose_filename);
+               free(loose_filename);
                if (err && errno != ENOENT)
                        return 1;
        }
@@ -2968,7 +2968,7 @@ int write_ref_sha1(struct ref_lock *lock,
            write_in_full(lock->lock_fd, &term, 1) != 1 ||
            close_ref(lock) < 0) {
                int save_errno = errno;
-               error("Couldn't write %s", lock->lk->filename);
+               error("Couldn't write %s", lock->lk->filename.buf);
                unlock_ref(lock);
                errno = save_errno;
                return -1;
index 20b18add42d2551a227eaac8125fe806006d2856..1b0555f1a5a0233e931b13a088c052a56aef3977 100644 (file)
--- a/rerere.c
+++ b/rerere.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "lockfile.h"
 #include "string-list.h"
 #include "rerere.h"
 #include "xdiff-interface.h"
index 5e8a207474bc6971a0de4f9ff6160a5681ac7b6d..1b9a35e5875683c9bd6ae7dba8e849201fdc0a42 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "lockfile.h"
 #include "sequencer.h"
 #include "dir.h"
 #include "object.h"
index 2dd851598a9d1444fe479d149ee3c2cb93e8cba9..5f069214d9060da8ceb001e6c037607c1d0096bf 100644 (file)
@@ -84,8 +84,6 @@ int sha1_pos(const unsigned char *sha1, void *table, size_t nr,
                                die("BUG: assertion failed in binary search");
                        }
                }
-               if (18 <= ofs)
-                       die("cannot happen -- lo and hi are identical");
        }
 
        do {
index 6f18c22ab186ba2214b6bedcec0cddb92e750c51..83f77f01b6370589fb90c72f111b4e6e381f9189 100644 (file)
@@ -8,6 +8,7 @@
  */
 #include "cache.h"
 #include "string-list.h"
+#include "lockfile.h"
 #include "delta.h"
 #include "pack.h"
 #include "blob.h"
index 57f4afa6b40585c663d0df78494ce2108611ce4b..bd7569e815273b93b5862391c64694e141cc668d 100644 (file)
--- a/shallow.c
+++ b/shallow.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "lockfile.h"
 #include "commit.h"
 #include "tag.h"
 #include "pkt-line.h"
@@ -269,8 +270,8 @@ void setup_alternate_shallow(struct lock_file *shallow_lock,
        if (write_shallow_commits(&sb, 0, extra)) {
                if (write_in_full(fd, sb.buf, sb.len) != sb.len)
                        die_errno("failed to write to %s",
-                                 shallow_lock->filename);
-               *alternate_shallow_file = shallow_lock->filename;
+                                 shallow_lock->filename.buf);
+               *alternate_shallow_file = shallow_lock->filename.buf;
        } else
                /*
                 * is_repository_shallow() sees empty string as "no
@@ -316,7 +317,7 @@ void prune_shallow(int show_only)
        if (write_shallow_commits_1(&sb, 0, NULL, SEEN_ONLY)) {
                if (write_in_full(fd, sb.buf, sb.len) != sb.len)
                        die_errno("failed to write to %s",
-                                 shallow_lock.filename);
+                                 shallow_lock.filename.buf);
                commit_lock_file(&shallow_lock);
        } else {
                unlink(git_path("shallow"));
index 1118b99e57d3308f333c56f487329a8fef75a7df..faa375d5d8e7cf6bbba599034308028efaba1e0f 100644 (file)
@@ -1,5 +1,5 @@
-#include "sigchain.h"
 #include "cache.h"
+#include "sigchain.h"
 
 #define SIGCHAIN_MAX_SIGNALS 32
 
diff --git a/t/t0064-sha1-array.sh b/t/t0064-sha1-array.sh
new file mode 100755 (executable)
index 0000000..50b31ff
--- /dev/null
@@ -0,0 +1,94 @@
+#!/bin/sh
+
+test_description='basic tests for the SHA1 array implementation'
+. ./test-lib.sh
+
+echo20 () {
+       prefix="${1:+$1 }"
+       shift
+       while test $# -gt 0
+       do
+               echo "$prefix$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1"
+               shift
+       done
+}
+
+test_expect_success 'ordered enumeration' '
+       echo20 "" 44 55 88 aa >expect &&
+       {
+               echo20 append 88 44 aa 55 &&
+               echo for_each_unique
+       } | test-sha1-array >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'ordered enumeration with duplicate suppression' '
+       echo20 "" 44 55 88 aa >expect &&
+       {
+               echo20 append 88 44 aa 55 &&
+               echo20 append 88 44 aa 55 &&
+               echo for_each_unique
+       } | test-sha1-array >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'lookup' '
+       {
+               echo20 append 88 44 aa 55 &&
+               echo20 lookup 55
+       } | test-sha1-array >actual &&
+       n=$(cat actual) &&
+       test "$n" -eq 1
+'
+
+test_expect_success 'lookup non-existing entry' '
+       {
+               echo20 append 88 44 aa 55 &&
+               echo20 lookup 33
+       } | test-sha1-array >actual &&
+       n=$(cat actual) &&
+       test "$n" -lt 0
+'
+
+test_expect_success 'lookup with duplicates' '
+       {
+               echo20 append 88 44 aa 55 &&
+               echo20 append 88 44 aa 55 &&
+               echo20 lookup 55
+       } | test-sha1-array >actual &&
+       n=$(cat actual) &&
+       test "$n" -ge 2 &&
+       test "$n" -le 3
+'
+
+test_expect_success 'lookup non-existing entry with duplicates' '
+       {
+               echo20 append 88 44 aa 55 &&
+               echo20 append 88 44 aa 55 &&
+               echo20 lookup 66
+       } | test-sha1-array >actual &&
+       n=$(cat actual) &&
+       test "$n" -lt 0
+'
+
+test_expect_success 'lookup with almost duplicate values' '
+       {
+               echo "append 5555555555555555555555555555555555555555" &&
+               echo "append 555555555555555555555555555555555555555f" &&
+               echo20 lookup 55
+       } | test-sha1-array >actual &&
+       n=$(cat actual) &&
+       test "$n" -eq 0
+'
+
+test_expect_success 'lookup with single duplicate value' '
+       {
+               echo20 append 55 55 &&
+               echo20 lookup 55
+       } | test-sha1-array >actual &&
+       n=$(cat actual) &&
+       test "$n" -ge 0 &&
+       test "$n" -le 1
+'
+
+test_done
index f9648a86426470785159b5132305a256c80b5ca4..158cf4f03b63cf4eb61901dd1e178b3d1d08467a 100755 (executable)
@@ -22,7 +22,7 @@ generate_expected_cache_tree_rec () {
        # ls-files might have foo/bar, foo/bar/baz, and foo/bar/quux
        # We want to count only foo because it's the only direct child
        subtrees=$(git ls-files|grep /|cut -d / -f 1|uniq) &&
-       subtree_count=$(echo "$subtrees"|awk '$1 {++c} END {print c}') &&
+       subtree_count=$(echo "$subtrees"|awk -v c=0 '$1 {++c} END {print c}') &&
        entries=$(git ls-files|wc -l) &&
        printf "SHA $dir (%d entries, %d subtrees)\n" "$entries" "$subtree_count" &&
        for subtree in $subtrees
index 83d20c4ba9640fff27777917da0342940c33e0e3..305bcac6b765111106887d4d24d99657c0554b5b 100755 (executable)
@@ -113,9 +113,4 @@ test_expect_success 'archive empty subtree by direct pathspec' '
        check_dir extract sub
 '
 
-test_expect_success 'archive applies umask even for pax headers' '
-       git archive --format=tar HEAD >archive.tar &&
-       ! grep 0666 archive.tar
-'
-
 test_done
index 0366653088417a3d694856538bb1d1bd35d36cda..796e9f79eadfdf5b641d429e2083dd7d0c27332c 100755 (executable)
@@ -1460,7 +1460,7 @@ test_expect_success 'invalid sort parameter in configuratoin' '
 '
 
 run_with_limited_stack () {
-       (ulimit -s 64 && "$@")
+       (ulimit -s 128 && "$@")
 }
 
 test_lazy_prereq ULIMIT 'run_with_limited_stack true'
@@ -1469,7 +1469,7 @@ test_lazy_prereq ULIMIT 'run_with_limited_stack true'
 test_expect_success ULIMIT '--contains works in a deep repo' '
        >expect &&
        i=1 &&
-       while test $i -lt 4000
+       while test $i -lt 8000
        do
                echo "commit refs/heads/master
 committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200
index b5bfd54139fda811a30a4e56a7098bccba7039ce..0dc598ecdc2696af956b1c517166f9e28b37dc68 100644 (file)
@@ -1,4 +1,4 @@
-#include <git-compat-util.h>
+#include "git-compat-util.h"
 
 int main(int argc, char **argv)
 {
index 9ebcbca9d25150e9bfca77a73ca45d2a06423f49..6efee31a4867b4ff8493161376e5a9cfdd48fe44 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "lockfile.h"
 #include "tree.h"
 #include "cache-tree.h"
 
diff --git a/test-sha1-array.c b/test-sha1-array.c
new file mode 100644 (file)
index 0000000..ddc491e
--- /dev/null
@@ -0,0 +1,34 @@
+#include "cache.h"
+#include "sha1-array.h"
+
+static void print_sha1(const unsigned char sha1[20], void *data)
+{
+       puts(sha1_to_hex(sha1));
+}
+
+int main(int argc, char **argv)
+{
+       struct sha1_array array = SHA1_ARRAY_INIT;
+       struct strbuf line = STRBUF_INIT;
+
+       while (strbuf_getline(&line, stdin, '\n') != EOF) {
+               const char *arg;
+               unsigned char sha1[20];
+
+               if (skip_prefix(line.buf, "append ", &arg)) {
+                       if (get_sha1_hex(arg, sha1))
+                               die("not a hexadecimal SHA1: %s", arg);
+                       sha1_array_append(&array, sha1);
+               } else if (skip_prefix(line.buf, "lookup ", &arg)) {
+                       if (get_sha1_hex(arg, sha1))
+                               die("not a hexadecimal SHA1: %s", arg);
+                       printf("%d\n", sha1_array_lookup(&array, sha1));
+               } else if (!strcmp(line.buf, "clear"))
+                       sha1_array_clear(&array);
+               else if (!strcmp(line.buf, "for_each_unique"))
+                       sha1_array_for_each_unique(&array, print_sha1, NULL);
+               else
+                       die("unknown command: %s", line.buf);
+       }
+       return 0;
+}
index 42db234e871908514814c9b8dc50cc65d9b093cd..e499fce60ff50069ace6174ef9fa3ca4aff0cdc8 100644 (file)
@@ -1,5 +1,5 @@
-#include "sigchain.h"
 #include "cache.h"
+#include "sigchain.h"
 
 #define X(f) \
 static void f(int sig) { \
diff --git a/trace.c b/trace.c
index b6f25a23fdf8b6eec64181b5d6b56909bbe4ae7b..477860894196e32d7db990459cef47175277c441 100644 (file)
--- a/trace.c
+++ b/trace.c
@@ -385,7 +385,7 @@ static inline uint64_t gettimeofday_nanos(void)
  * Returns nanoseconds since the epoch (01/01/1970), for performance tracing
  * (i.e. favoring high precision over wall clock time accuracy).
  */
-inline uint64_t getnanotime(void)
+uint64_t getnanotime(void)
 {
        static uint64_t offset;
        if (offset > 1) {
index 4ed772949651005055dadd236cee8d5d5c8f2492..409c4977a1e3a3a72dcd1452b41abdcb5a42b665 100644 (file)
--- a/varint.c
+++ b/varint.c
@@ -1,3 +1,4 @@
+#include "git-compat-util.h"
 #include "varint.h"
 
 uintmax_t decode_varint(const unsigned char **bufp)
index 032119579694f6a82f3947bfafb05a801385cb5a..c1c44d9a6bde4853f55d6c8d7cd59ad159ef4abb 100644 (file)
--- a/varint.h
+++ b/varint.h
@@ -1,8 +1,6 @@
 #ifndef VARINT_H
 #define VARINT_H
 
-#include "git-compat-util.h"
-
 extern int encode_varint(uintmax_t, unsigned char *);
 extern uintmax_t decode_varint(const unsigned char **);