mirror of
https://github.com/git/git.git
synced 2024-11-07 01:32:58 +01:00
Mirror of https://github.com/git/git
b3f1280ec7
When we delete a ref that is packed, we rewrite the whole packed-refs file and simply omit the ref that no longer exists. However, we base the rewrite on whatever happens to be in our refs cache, not what is necessarily on disk. That opens us up to a race condition if another process is simultaneously packing the refs, as we will overwrite their newly-made pack-refs file with our potentially stale data, losing commits. You can demonstrate the race like this: # setup some repositories git init --bare parent && (cd parent && git config core.logallrefupdates true) && git clone parent child && (cd child && git commit --allow-empty -m base) # in one terminal, repack the refs repeatedly cd parent && while true; do git pack-refs --all done # in another terminal, simultaneously push updates to # master, and create and delete an unrelated ref cd child && while true; do git push origin HEAD:newbranch && git commit --allow-empty -m foo us=`git rev-parse master` && git push origin master && git push origin :newbranch && them=`git --git-dir=../parent rev-parse master` && if test "$them" != "$us"; then echo >&2 "$them" != "$us" exit 1 fi done In many cases the two processes will conflict over locking the packed-refs file, and the deletion of newbranch will simply fail. But eventually you will hit the race, which happens like this: 1. We push a new commit to master. It is already packed (from the looping pack-refs call). We write the new value (let us call it B) to $GIT_DIR/refs/heads/master, but the old value (call it A) remains in the packed-refs file. 2. We push the deletion of newbranch, spawning a receive-pack process. Receive-pack advertises all refs to the client, causing it to iterate over each ref; it caches the packed refs in memory, which points at the stale value A. 3. Meanwhile, a separate pack-refs process is running. It runs to completion, updating the packed-refs file to point master at B, and deleting $GIT_DIR/refs/heads/master which also pointed at B. 4. Back in the receive-pack process, we get the instruction to delete :newbranch. We take a lock on packed-refs (which works, as the other pack-refs process has already finished). We then rewrite the contents using the cached refs, which contain the stale value A. The resulting packed-refs file points master once again at A. The loose ref which would override it to point at B was deleted (rightfully) in step 3. As a result, master now points at A. The only trace that B ever existed in the parent is in the reflog: the final entry will show master moving from A to B, even though the ref still points at A (so you can detect this race after the fact, because the next reflog entry will move from A to C). We can fix this by invalidating the packed-refs cache after we have taken the lock. This means that we will re-read the packed-refs file, and since we have the lock, we will be sure that what we read will be atomically up-to-date when we write (it may be out of date with respect to loose refs, but that is OK, as loose refs take precedence). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com> |
||
---|---|---|
block-sha1 | ||
builtin | ||
compat | ||
contrib | ||
Documentation | ||
git-gui | ||
git_remote_helpers | ||
gitk-git | ||
gitweb | ||
mergetools | ||
perl | ||
po | ||
ppc | ||
t | ||
templates | ||
vcs-svn | ||
xdiff | ||
.gitattributes | ||
.gitignore | ||
.mailmap | ||
abspath.c | ||
aclocal.m4 | ||
advice.c | ||
advice.h | ||
alias.c | ||
alloc.c | ||
archive-tar.c | ||
archive-zip.c | ||
archive.c | ||
archive.h | ||
argv-array.c | ||
argv-array.h | ||
attr.c | ||
attr.h | ||
base85.c | ||
bisect.c | ||
bisect.h | ||
blob.c | ||
blob.h | ||
branch.c | ||
branch.h | ||
builtin.h | ||
bulk-checkin.c | ||
bulk-checkin.h | ||
bundle.c | ||
bundle.h | ||
cache-tree.c | ||
cache-tree.h | ||
cache.h | ||
check-builtins.sh | ||
check-racy.c | ||
check_bindir | ||
color.c | ||
color.h | ||
column.c | ||
column.h | ||
combine-diff.c | ||
command-list.txt | ||
commit.c | ||
commit.h | ||
config.c | ||
config.mak.in | ||
configure.ac | ||
connect.c | ||
connected.c | ||
connected.h | ||
convert.c | ||
convert.h | ||
copy.c | ||
COPYING | ||
credential-cache--daemon.c | ||
credential-cache.c | ||
credential-store.c | ||
credential.c | ||
credential.h | ||
csum-file.c | ||
csum-file.h | ||
ctype.c | ||
daemon.c | ||
date.c | ||
decorate.c | ||
decorate.h | ||
delta.h | ||
diff-delta.c | ||
diff-lib.c | ||
diff-no-index.c | ||
diff.c | ||
diff.h | ||
diffcore-break.c | ||
diffcore-delta.c | ||
diffcore-order.c | ||
diffcore-pickaxe.c | ||
diffcore-rename.c | ||
diffcore.h | ||
dir.c | ||
dir.h | ||
editor.c | ||
entry.c | ||
environment.c | ||
exec_cmd.c | ||
exec_cmd.h | ||
fast-import.c | ||
fetch-pack.h | ||
fixup-builtins | ||
fmt-merge-msg.h | ||
fsck.c | ||
fsck.h | ||
generate-cmdlist.sh | ||
gettext.c | ||
gettext.h | ||
git-add--interactive.perl | ||
git-am.sh | ||
git-archimport.perl | ||
git-bisect.sh | ||
git-compat-util.h | ||
git-cvsexportcommit.perl | ||
git-cvsimport.perl | ||
git-cvsserver.perl | ||
git-difftool--helper.sh | ||
git-difftool.perl | ||
git-filter-branch.sh | ||
git-instaweb.sh | ||
git-lost-found.sh | ||
git-merge-octopus.sh | ||
git-merge-one-file.sh | ||
git-merge-resolve.sh | ||
git-mergetool--lib.sh | ||
git-mergetool.sh | ||
git-p4.py | ||
git-parse-remote.sh | ||
git-pull.sh | ||
git-quiltimport.sh | ||
git-rebase--am.sh | ||
git-rebase--interactive.sh | ||
git-rebase--merge.sh | ||
git-rebase.sh | ||
git-relink.perl | ||
git-remote-testgit.py | ||
git-repack.sh | ||
git-request-pull.sh | ||
git-send-email.perl | ||
git-sh-i18n.sh | ||
git-sh-setup.sh | ||
git-stash.sh | ||
git-submodule.sh | ||
git-svn.perl | ||
GIT-VERSION-GEN | ||
git-web--browse.sh | ||
git.c | ||
git.spec.in | ||
gpg-interface.c | ||
gpg-interface.h | ||
graph.c | ||
graph.h | ||
grep.c | ||
grep.h | ||
hash.c | ||
hash.h | ||
help.c | ||
help.h | ||
hex.c | ||
http-backend.c | ||
http-fetch.c | ||
http-push.c | ||
http-walker.c | ||
http.c | ||
http.h | ||
ident.c | ||
imap-send.c | ||
INSTALL | ||
kwset.c | ||
kwset.h | ||
levenshtein.c | ||
levenshtein.h | ||
LGPL-2.1 | ||
list-objects.c | ||
list-objects.h | ||
ll-merge.c | ||
ll-merge.h | ||
lockfile.c | ||
log-tree.c | ||
log-tree.h | ||
mailmap.c | ||
mailmap.h | ||
Makefile | ||
match-trees.c | ||
merge-file.c | ||
merge-file.h | ||
merge-recursive.c | ||
merge-recursive.h | ||
mergesort.c | ||
mergesort.h | ||
name-hash.c | ||
notes-cache.c | ||
notes-cache.h | ||
notes-merge.c | ||
notes-merge.h | ||
notes.c | ||
notes.h | ||
object.c | ||
object.h | ||
pack-check.c | ||
pack-refs.c | ||
pack-refs.h | ||
pack-revindex.c | ||
pack-revindex.h | ||
pack-write.c | ||
pack.h | ||
pager.c | ||
parse-options-cb.c | ||
parse-options.c | ||
parse-options.h | ||
patch-delta.c | ||
patch-ids.c | ||
patch-ids.h | ||
path.c | ||
pkt-line.c | ||
pkt-line.h | ||
preload-index.c | ||
pretty.c | ||
progress.c | ||
progress.h | ||
prompt.c | ||
prompt.h | ||
quote.c | ||
quote.h | ||
reachable.c | ||
reachable.h | ||
read-cache.c | ||
README | ||
reflog-walk.c | ||
reflog-walk.h | ||
refs.c | ||
refs.h | ||
RelNotes | ||
remote-curl.c | ||
remote.c | ||
remote.h | ||
replace_object.c | ||
rerere.c | ||
rerere.h | ||
resolve-undo.c | ||
resolve-undo.h | ||
revision.c | ||
revision.h | ||
run-command.c | ||
run-command.h | ||
send-pack.h | ||
sequencer.c | ||
sequencer.h | ||
server-info.c | ||
setup.c | ||
sh-i18n--envsubst.c | ||
sha1-array.c | ||
sha1-array.h | ||
sha1-lookup.c | ||
sha1-lookup.h | ||
sha1_file.c | ||
sha1_name.c | ||
shallow.c | ||
shell.c | ||
shortlog.h | ||
show-index.c | ||
sideband.c | ||
sideband.h | ||
sigchain.c | ||
sigchain.h | ||
strbuf.c | ||
strbuf.h | ||
streaming.c | ||
streaming.h | ||
string-list.c | ||
string-list.h | ||
submodule.c | ||
submodule.h | ||
symlinks.c | ||
tag.c | ||
tag.h | ||
tar.h | ||
test-chmtime.c | ||
test-ctype.c | ||
test-date.c | ||
test-delta.c | ||
test-dump-cache-tree.c | ||
test-genrandom.c | ||
test-index-version.c | ||
test-line-buffer.c | ||
test-match-trees.c | ||
test-mergesort.c | ||
test-mktemp.c | ||
test-parse-options.c | ||
test-path-utils.c | ||
test-regex.c | ||
test-revision-walking.c | ||
test-run-command.c | ||
test-scrap-cache-tree.c | ||
test-sha1.c | ||
test-sha1.sh | ||
test-sigchain.c | ||
test-subprocess.c | ||
test-svn-fe.c | ||
thread-utils.c | ||
thread-utils.h | ||
trace.c | ||
transport-helper.c | ||
transport.c | ||
transport.h | ||
tree-diff.c | ||
tree-walk.c | ||
tree-walk.h | ||
tree.c | ||
tree.h | ||
unimplemented.sh | ||
unix-socket.c | ||
unix-socket.h | ||
unpack-trees.c | ||
unpack-trees.h | ||
upload-pack.c | ||
url.c | ||
url.h | ||
usage.c | ||
userdiff.c | ||
userdiff.h | ||
utf8.c | ||
utf8.h | ||
varint.c | ||
varint.h | ||
version.c | ||
version.h | ||
walker.c | ||
walker.h | ||
wrap-for-bin.sh | ||
wrapper.c | ||
write_or_die.c | ||
ws.c | ||
wt-status.c | ||
wt-status.h | ||
xdiff-interface.c | ||
xdiff-interface.h | ||
zlib.c |
//////////////////////////////////////////////////////////////// GIT - the stupid content tracker //////////////////////////////////////////////////////////////// "git" can mean anything, depending on your mood. - random three-letter combination that is pronounceable, and not actually used by any common UNIX command. The fact that it is a mispronunciation of "get" may or may not be relevant. - stupid. contemptible and despicable. simple. Take your pick from the dictionary of slang. - "global information tracker": you're in a good mood, and it actually works for you. Angels sing, and a light suddenly fills the room. - "goddamn idiotic truckload of sh*t": when it breaks Git is a fast, scalable, distributed revision control system with an unusually rich command set that provides both high-level operations and full access to internals. Git is an Open Source project covered by the GNU General Public License. It was originally written by Linus Torvalds with help of a group of hackers around the net. It is currently maintained by Junio C Hamano. 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/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 documentation of each command with "man git-commandname" or "git help commandname". CVS users may also want to read Documentation/gitcvs-migration.txt ("man gitcvs-migration" or "git help cvs-migration" if git is installed). Many Git online resources are accessible from http://git-scm.com/ including full documentation and Git related tools. The user discussion and development of Git take place on the Git mailing list -- everyone is welcome to post bug reports, feature requests, comments and patches to git@vger.kernel.org (read Documentation/SubmittingPatches for instructions on patch submission). To subscribe to the list, send an email with just "subscribe git" in the body to majordomo@vger.kernel.org. The mailing list archives are available at http://marc.theaimsgroup.com/?l=git and other archival sites. The messages titled "A note from the maintainer", "What's in git.git (stable)" and "What's cooking in git.git (topics)" and the discussion following them on the mailing list give a good reference for project status, development direction and remaining tasks.